import type { EmbeddedRequest, EmbeddedResponse } from "../types"; export interface PostMessageHandlerCallbacks { onEvent?: (event: { name: string; payload: unknown; }) => void; onError?: (error: { message: string; code?: string; details?: unknown; }) => void; /** * Default timeout in milliseconds for postMessage requests. * @default 10000 */ requestTimeout?: number; } export declare class PostMessageHandler { private pendingRequests; private messageListener; private iframe; private isReady; private _protocolVersion; private static readonly SUPPORTED_PROTOCOL_VERSION; private readonly requestTimeout; private callbacks; constructor(iframe: HTMLIFrameElement, callbacks?: PostMessageHandlerCallbacks); private setupMessageListener; private handleEvent; private handleResponse; destroy(): void; /** * Update callbacks after construction */ updateCallbacks(callbacks: PostMessageHandlerCallbacks): void; /** * Whether the iframe has signaled it is ready to receive postMessages */ get ready(): boolean; /** * The protocol version reported by the iframe in its 'embedded.ready' event, * or null if the version was not included in the ready payload. */ get protocolVersion(): string | null; /** * Wait for the iframe to signal readiness via the 'embedded.ready' event. * @param timeout - Optional timeout in milliseconds (default: 30000ms) */ waitForReady(timeout?: number): Promise; /** * Sends a postMessage to the iframe and returns a Promise that resolves with the response. * @param message - The message to send * @param timeout - Optional timeout in milliseconds. Defaults to the requestTimeout set at construction. */ postMessage(message: Omit, timeout?: number): Promise; private static generateRequestId; /** * Derive the trusted origin from the iframe src (constructed from baseURL). * Returns null if it cannot be determined. */ private getTrustedOrigin; }