0.1.14 • Published 4 months ago
mappconnect-sdk v0.1.14
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 optionsdebug
: 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 URLgetSourceURL(): Promise<string>
- Get the source URLgetUserProfile(): Promise<UserProfile>
- Get the user profile
Types
interface UserProfile {
username: string;
email: string;
FID: string;
}
License
MIT