0.1.14 • Published 4 months ago

mappconnect-sdk v0.1.14

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

mAppConnectSDK

A TypeScript SDK for facilitating type-safe communication between a parent application and an iframe mini-app. yay!

Installation

bun add mappconnect-sdk

or

npm install mappconnect-sdk

Features

  • Type-safe communication between parent app and iframe mini-app
  • Promise-based API
  • Simple to use
  • Debug mode for development

Usage

In the parent application

import MAppConnectSDK from 'mappconnect-sdk';

// Initialize the SDK in parent mode
const sdk = new MAppConnectSDK(true, { debug: true });

// Set the iframe element once it's available
const iframe = document.getElementById('mini-app-iframe') as HTMLIFrameElement;
sdk.setIframe(iframe);

// The SDK will automatically handle incoming messages from the mini-app

In the mini-app (iframe)

import MAppConnectSDK from 'mappconnect-sdk';

// Initialize the SDK in mini-app mode
const sdk = new MAppConnectSDK(false, { debug: true });

// Call methods on the SDK
async function testSDK() {
  try {
    // Create a hosted shortener
    const shortened = await sdk.createHostedShortener('https://example.com/very-long-url');
    console.log('Shortened URL:', shortened);

    // Get source URL
    const sourceUrl = await sdk.getSourceURL();
    console.log('Source URL:', sourceUrl);

    // Get user profile
    const userProfile = await sdk.getUserProfile();
    console.log('User Profile:', userProfile);
  } catch (error) {
    console.error('Error:', error);
  }
}

testSDK();

API Reference

Constructor

new MAppConnectSDK(isParent: boolean, config?: SDKConfig)
  • isParent: Whether this instance is running in the parent app (true) or mini-app (false)
  • config: Configuration options
    • debug: Enable debug logging (default: false)

Methods

Parent App Methods

  • setIframe(iframe: HTMLIFrameElement): void - Set the iframe element for communication

Mini-App Methods

  • createHostedShortener(url: string): Promise<string> - Create a hosted shortener for the given URL
  • getSourceURL(): Promise<string> - Get the source URL
  • getUserProfile(): Promise<UserProfile> - Get the user profile

Types

interface UserProfile {
  username: string;
  email: string;
  FID: string;
}

License

MIT

0.1.14

4 months ago

0.1.13

4 months ago

0.1.12

4 months ago

0.1.10

4 months ago

0.1.9

4 months ago

0.1.8

4 months ago

0.1.7

4 months ago

0.1.6

4 months ago

0.1.5

4 months ago

0.1.4

4 months ago

0.1.3

4 months ago