/** * @oxpulse/chat-widget — typed iframe ↔ parent postMessage protocol. * * All messages carry a "oxpulse-chat" namespace prefix to avoid collisions. * Type guards (isParentMessage / isIframeMessage) reject malformed payloads. * * Security (M1 + M2): * M1: sendToParent() requires an explicit parent origin set via setParentOrigin(). * Messages are never sent with '*'. Unset → warn + drop. * M2: onParentMessage() reads ?origin= from iframe URL and rejects events whose * event.origin does not match. */ import type { ParentMessage, IframeMessage } from './types.js'; /** * Set (or clear) the expected parent origin for sendToParent(). * Called from the iframe entry once the origin query param is read. */ export declare function setParentOrigin(origin: string | null): void; /** * Type guard: check that a raw postMessage event data is a well-formed ParentMessage. * Returns false for any malformed or unrelated message. */ export declare function isParentMessage(data: unknown): data is ParentMessage; /** * Type guard: check that a raw postMessage event data is a well-formed IframeMessage. * Returns false for any malformed or unrelated message. */ export declare function isIframeMessage(data: unknown): data is IframeMessage; /** * Send a token-refresh message from the parent to a specific iframe. * * M1 security: requires an EXPLICIT, CONCRETE target origin (the resolved widget * baseUrl). A bearer JWT must never be posted to the '*' wildcard — which * Window.postMessage treats as "any origin" — so an empty OR literal-'*' origin * is dropped with a warning, mirroring sendToParent()'s "never send with '*'" * discipline. There is no '*' fallback. */ /** @internal Not part of the package's public API surface; not re-exported from index.ts. Kept exported for cross-file use within the package. */ export declare function sendRefreshTokenToIframe(iframe: HTMLIFrameElement, jwt: string, targetOrigin: string): void; /** * Send an IframeMessage from the iframe to the parent window. * Used inside the iframe entry (iframe.ts). * * M1 security: requires expectedParentOrigin to be set via setParentOrigin(). * If not set, logs a warning and drops the message (never targets '*'). */ export declare function sendToParent(msg: IframeMessage): void; /** * Listen for ParentMessages sent to the current window (iframe-side listener). * Returns an unsubscribe function. * * M2 security: reads ?origin= from the iframe's URL at call time and rejects * messages whose event.origin does not match. * If ?origin= is absent, ALL non-namespace-matched messages are rejected (fail-closed). */ export declare function onParentMessage(handler: (msg: ParentMessage) => void): () => void; /** * Listen for IframeMessages from the iframe (parent-side listener). * Returns an unsubscribe function. */ export declare function onIframeMessage(iframe: HTMLIFrameElement, handler: (msg: IframeMessage) => void): () => void; //# sourceMappingURL=postmessage.d.ts.map