/** * @license * Copyright 2024 Boxo pte. ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type { SDKConfig, CustomEventHandler } from './types'; /** * Appboxo Web SDK for Desktop * Handles communication between Desktop App and miniapps */ declare class AppboxoWebSDK { private config; private iframeRef; private eventHandlers; private lifecycleHandlers; private requestResolvers; private baseUrl; private isInitialized; private authCode; private authTokens; private networkService; private messageListener; private isMounted; private mountPromise; private instanceId; constructor(config: SDKConfig); /** * Initialize the SDK and start listening for events */ initialize(): void; /** * Set the iframe reference for miniapp communication */ setIframe(iframe: HTMLIFrameElement): void; /** * Mount miniapp to container (helper method) * Creates iframe, sets reference, and initializes SDK * * @param config Configuration object with container, optional url (will fetch from API if not provided), and optional className * @returns The created iframe element */ mount(config: { container: string | HTMLElement; url?: string; className?: string; }): Promise; /** * Internal mount implementation */ private _doMount; /** * Get miniapp URL from API settings endpoint (public method) * This allows users to manually set the URL on their own iframe element * @returns The miniapp URL * @throws Error if API call fails or URL is not found */ getMiniappUrl(): Promise; /** * Fetch miniapp URL from API settings endpoint * @returns The miniapp URL * @throws Error if API call fails or URL is not found */ private fetchMiniappUrl; /** * Register custom event handler */ onEvent(eventType: string, handler: CustomEventHandler): void; /** * Remove event handler */ offEvent(eventType: string): void; /** * Register callback for when authentication is needed (lifecycle hook) * Similar to Android/iOS/Flutter SDK's onAuth pattern * Host app should request tokens from backend and call setAuthTokens() in this callback */ onAuth(callback: () => void | Promise): void; /** * Register callback for when login completes */ onLoginComplete(callback: (success: boolean, data?: any) => void): void; /** * Register callback for when payment completes */ onPaymentComplete(callback: (success: boolean, data?: any) => void): void; /** * Set auth code explicitly (like React Native SDK pattern) */ setAuthCode(authCode: string): void; /** * Set auth tokens directly (Boxo Connect Direct) * Host App should call Boxo Dashboard connect endpoint to get miniapp tokens first, * then call this method with the obtained tokens before miniapp calls login() */ setAuthTokens(token: string, refreshToken?: string): void; /** * Set locale/language code (e.g., 'en', 'en-US', 'ru', 'zh-CN') * This will be passed to the miniapp via InitData on the next request * Note: The locale will be included in the InitData response when the miniapp requests it. * If the miniapp has already loaded, you may need to reload it or wait for the next InitData request. */ setLocale(locale: string): void; /** * Set theme/color scheme preference ('dark' | 'light' | 'system') * This will be passed to the miniapp via InitData on the next request * Note: The theme will be included in the InitData response when the miniapp requests it. * If the miniapp has already loaded, SDK will automatically notify miniapp about the theme change. * * @param theme - Theme preference: 'dark' for dark mode, 'light' for light mode, 'system' for system preference */ setTheme(theme: 'dark' | 'light' | 'system'): void; /** * Setup event listeners for miniapp communication */ private setupEventListeners; /** * Handle incoming events from miniapp */ private handleMiniappEvent; /** * Send response back to miniapp */ private sendResponseToMiniapp; /** * Send error response to miniapp */ private sendErrorResponse; /** * Logging utility */ private log; /** * Logout and clear SDK state. * * Clears the SDK's internal auth data and notifies the miniapp to clear its own * auth-specific storage (token, refresh_token). The host app's localStorage and * sessionStorage are intentionally left untouched — the SDK does not own that data. */ logout(): void; /** * Cleanup resources */ destroy(): void; } export { AppboxoWebSDK }; export default AppboxoWebSDK; export type { SDKConfig, MiniappEvent, HostAppResponse, LoginRequest, PaymentRequest, InitDataRequest, LoginResponse, PaymentResponse, PaymentStatus, InitDataResponse, CustomEventHandler, LifecycleEventHandler, } from './types'; export * from './utils'; export * from './constants'; //# sourceMappingURL=index.d.ts.map