/*! * Copyright (c) 2026-present, Okta, Inc. and/or its affiliates. All rights reserved. * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (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 MessageBus } from "../tools/createMessageBus.js"; import { type MessageChannel } from "./createMessageChannel.js"; /** * What actually crosses `window.postMessage`. The message is wrapped so a subscriber can tell which channel and which protocol version it belongs to before trusting its shape. */ export type BrowserMessageEnvelope = { channelName: string; message: Message; protocolVersion: number; }; export type CreateBrowserMessageBusArgs = { /** * The channel to publish and subscribe on, from `createMessageChannel`. */ messageChannel: MessageChannel; /** * The window to publish on and listen to. * @default the top window from `getTopMessageWindow` */ messageWindow?: Window; /** * The window this code runs in. When it unloads, its listeners on `messageWindow` are removed, so an iframe that reloads never leaves a listener behind on the top window. * @default window */ ownerWindow?: Window; }; /** * The window every bundle on the page publishes and listens on: the top window when it's on the same origin, otherwise this window. * * An app rendered in a same-origin iframe then reaches Unified UI Shell in the page around it. A cross-origin top window can't be listened on, so an app in a cross-origin iframe stays on its own window. */ export declare const getTopMessageWindow: ({ ownerWindow, }?: { ownerWindow?: Window; }) => Window; /** * Create a message bus that sends messages through the browser's `window.postMessage`. * * Use it instead of `createMessageBus` when the publisher and subscriber may come from separate bundles, such as an app and Unified UI Shell each loading their own copy of Odyssey. A bus from `createMessageBus` only reaches subscribers that share the same JavaScript object, but every bundle on the page shares the same top window. * * Messages arrive asynchronously, and a publisher receives its own messages. Only messages from the page's own origin, on the same channel, at the same protocol version, and passing the channel's check are delivered. * * `postMessage` copies each message with the structured clone algorithm, so a message can't contain functions, symbols, or DOM elements. Each subscriber receives a copy made in its own window. */ export declare const createBrowserMessageBus: ({ messageChannel: { channelName, isMessage, protocolVersion }, ownerWindow, messageWindow, }: CreateBrowserMessageBusArgs) => MessageBus; //# sourceMappingURL=createBrowserMessageBus.d.ts.map