import { Observable, Subscription } from 'rxjs'; import { Maybe } from 'maybe-not'; import type { ResponseCallback, TectonMessageSuccessResponse } from '../types/response'; import type { Protocol } from '../types/message-bus'; /** * Low-level function to send a message to another window via postMessage. * Handles the Tecton message format including protocol, type, and status. * * @param recipient - The target window to send the message to * @param type - The message type identifier (e.g., 'navigateTo', 'getAuthToken') * @param protocol - The communication protocol to use * @param message - The message payload wrapped in a Maybe * @param guid - Optional unique identifier for request/response correlation * @param status - The message status ('success' or 'error') * * @internal */ export declare function _sendMessage(recipient: Window, type: string, protocol: Protocol, message: Maybe, guid?: number | null, status?: 'success' | 'error'): void; /** * Sends a one-way message to the parent window. * Used for notifications that don't require a response. * * @param method - The message type identifier * @param message - The message payload wrapped in a Maybe * * @example * ```typescript * sendMessage('userAction', Maybe.just(JSON.stringify({ action: 'click' }))); * ``` */ export declare function sendMessage(method: string, message: Maybe): void; /** * Broadcasts a message to all outlets (iframes) in the current window. * Used for notifications that should reach all child features, such as * platform scroll or size changes. * * @param method - The broadcast message type identifier * @param message - The message payload wrapped in a Maybe * * @example * ```typescript * sendBroadcast('platformScrollChanged', Maybe.just(JSON.stringify({ scrollTop: 100 }))); * ``` */ export declare function sendBroadcast(method: string, message: Maybe): void; /** * Core message bus implementation for inter-window communication in Tecton. * Uses RxJS observables to handle asynchronous message passing via postMessage. * Supports request/response patterns, one-way messages, and broadcasts. * * @example * ```typescript * const messageBus = new MessageBus(); * * // Listen for messages * messageBus.onMessage('userData').subscribe(response => { * console.log('Received user data:', response.value); * }); * * // Send a request and wait for response * const authToken = await messageBus.sendRequest('getAuthToken', Maybe.nothing()); * * // Register a response handler * messageBus.sendResponse('myCapability', async (data) => { * return { result: 'processed' }; * }); * ``` */ export default class MessageBus { /** Observable stream of all incoming Tecton messages */ protected firehose$: Observable; /** Counter for generating unique message GUIDs */ private messageNum; /** * Creates a new MessageBus instance and sets up the message listener. * Filters incoming messages to only process those with the `tectonic: true` flag. */ constructor(); /** * Subscribes to messages of a specific type and protocol. * * @typeParam T - The expected type of the message value * @param type - The message type to listen for * @param protocol - The protocol to filter on (defaults to 'MESSAGE') * @param guid - Optional GUID to match specific messages * @returns An observable that emits when matching messages are received */ onMessage(type: string, protocol?: Protocol, guid?: number | null): Observable>; /** * Sends a request to the platform and waits for a response. * Automatically generates a unique GUID for request/response correlation. * * @typeParam R - The expected type of the response value * @param type - The request type identifier (e.g., 'getAuthToken', 'navigateTo') * @param message - The request payload wrapped in a Maybe * @param options - Optional configuration including timeout * @returns A promise that resolves with the response or rejects on timeout */ sendRequest(type: string, message: Maybe, options?: { timeout?: number; }): Promise>; /** * Registers a handler to respond to incoming requests of a specific type. * The handler receives the request data and should return a response. * * @typeParam T - The type of incoming request data * @typeParam R - The type of response data to send back * @param type - The request type to handle * @param generateResponse - Callback that receives request data and returns response data. * Return null to skip sending a response. * @returns A subscription that can be unsubscribed to stop handling requests */ sendResponse(type: string, generateResponse: ResponseCallback): Subscription; /** * Generates the next unique message number for request/response correlation. * @returns The next sequential message number */ private getNextMessageNumber; } //# sourceMappingURL=message-bus.d.ts.map