import { CoreSDKConfig, HandshakeConfig } from './types'; /** * PostMessageBridge handles the communication between host and client applications * through the postMessage API. It provides: * - Type-safe message passing * - Request/response handling with timeouts * - Event emission and subscription * - Origin validation * - Handshake protocol for secure initialization */ export declare class PostMessageBridge { private config; private eventEmitter; private handshakeManager; /** * Stores pending requests with their resolve/reject handlers and timeout references. * The type parameter R represents the expected response type for each request. */ private pendingRequests; private requestHandlers; private bufferedMessages; private initialized; private source; private connected; private listenerMode; private sessionId?; private sdkType; constructor(config: CoreSDKConfig); /** * Sets or updates the target window for postMessage communication. * This is useful for host applications that need to establish the iframe * target after the SDK is already initialized. * * @param target - The target window to communicate with (typically iframe.contentWindow) */ setTarget(target: Window): void; /** * Prefixes an error's message with the current SDK type (if available). * For example, errors will be transformed into "[client SDK] ". * @param error - The error to format. * @returns The updated error. */ private formatError; /** * Initializes the bridge with basic configuration. * This only sets up the event listeners and basic configuration but doesn't perform the handshake yet. * * @param handshakeConfig - Configuration for the handshake */ initialize(handshakeConfig: HandshakeConfig): void; /** * Connects the bridge by performing the handshake process. * For the client, this sends the handshake init message. * For the host, the connection is considered complete once a handshake init message is received and responded to. * * @returns A promise that resolves when the connection is established. */ connect(): Promise; /** * Sends a request to the other side and waits for a response. * @param action - The action to perform * @param payload - Optional data to send with the request * @returns Promise that resolves with the response data */ request(action: string, payload?: T): Promise; /** * Emits an event to the other side. * @param event - Event name * @param payload - Data to send with the event */ emit(event: string, payload: T): void; /** * Subscribes to events from the other side. * @param event - Event name to listen for * @param handler - Callback to handle the event data * @returns Function to unsubscribe from the event */ on(event: string, handler: (data: T) => void): () => void; /** * Cleans up all resources used by the bridge. * Should be called when the bridge is no longer needed. */ destroy(): void; /** * Handles incoming postMessage events. * Validates origin and routes messages to appropriate handlers. */ private handleMessage; private isValidOrigin; /** * Processes a message after origin validation. * * @param message - The message to process * @param origin - The origin the message came from */ private processMessage; /** * Handles response messages by resolving their corresponding pending requests. */ private handleResponse; /** * Handles event messages by emitting them through the event emitter. */ private handleEvent; /** * Handles incoming request messages by invoking the corresponding registered handler and sending back a response. * If no handler is registered, sends an error response. * @param message - The received request message. */ private handleRequest; /** * Sends a message to the other side through postMessage. */ private postMessage; private isNullOrEmpty; /** * Generates a unique message ID. */ private generateId; /** * Ensures the bridge is initialized and connected before allowing operations. * @throws {CoreError} If the bridge is not initialized or connected */ private ensureConnected; /** * Registers a request handler for incoming requests. * @param action - The action to register the handler for * @param handler - The handler function to register */ onRequest(action: string, handler: (payload: T) => Promise | R): void; /** * Checks if the bridge is connected. * @returns True if the bridge is connected, false otherwise. */ isConnected(): boolean; /** * Checks if the bridge is in listener mode (no target set). * @returns True if in listener mode, false otherwise */ isInListenerMode(): boolean; } //# sourceMappingURL=post-message.d.ts.map