import type { HostConnection, NamedEvent, CrossRealmObject, GuestApis } from "@adobe/uix-core"; import { Emitter } from "@adobe/uix-core"; /** * @public */ export type GuestEvent> = NamedEvent & { guest: Guest; }>; /** * @public */ export type AppConnection = { outgoing: GuestApis; incoming: GuestApis; sharedContext: Record; }; /** * @public */ export type GuestEventContextChange = GuestEvent<"contextchange", { context: Record; }>; /** @public */ export type GuestEventBeforeConnect = GuestEvent<"beforeconnect">; /** @public */ export type GuestEventConnected = GuestEvent<"connected">; /** @public */ export type GuestEventError = GuestEvent<"error", { error: Error; }>; /** * @public */ export type GuestEvents = GuestEventContextChange | GuestEventBeforeConnect | GuestEventConnected | GuestEventError; /** * @public */ export interface GuestConfig { /** * String slug identifying extension. This may need to use IDs from an * external system in the future. */ id: string; /** * Set debug flags on all libraries that have them, and add loggers to SDK * objects. Log a lot to the console. */ debug?: boolean; /** * Time out and stop trying to reach the host after this many milliseconds */ timeout?: number; } /** * A `Map` representing the {@link @adobe/uix-host#HostConfig.sharedContext} * object. * * @remarks While the Host object is a plain JavaScript object. the `sharedContext` in the Guest object implements the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | Map} interface. * * @example * In the host app window, the Host object shares context: * ```javascript *host.shareContext({ * someAuthToken: 'abc' *}); * ``` * * After the `contentchange` event has fired in the guest window: * ```javascript * guest.sharedContext.get('someAuthToken') === 'abc' * ``` * @public */ export declare class SharedContext { private _map; constructor(values: T); private reset; /** * @public * Retrieve a copy of a value from the {@link @adobe/uix-host#HostConfig.sharedContext} object. *Note that this is not a reference to any actual objects from the parent. If the parent updates an "inner object" inside the SharedContext, that change will not be reflected in the Guest!* */ get(key: Extract): T[keyof T]; } /** * Generic Guest object, with methods shared by all types of Guest. * @internal */ export declare class Guest extends Emitter { /** * Shared context has been set or updated. * @eventProperty */ contextchange: GuestEventContextChange; /** * About to attempt connection to the host. * @eventProperty */ beforeconnect: GuestEventBeforeConnect; /** * Host connection has been established. * @eventProperty */ connected: GuestEventConnected; /** * Host connection has failed. * @eventProperty */ error: GuestEventError; /** * {@inheritdoc SharedContext} */ sharedContext: SharedContext; /** * A guest (extension) configuration */ configuration?: Record; logger: Console; /** * @param config - Initializer for guest object, including ID. */ constructor(config: GuestConfig); /** * Proxy object for calling methods on the host. * * @remarks Any APIs exposed to the extension via {@link @adobe/uix-host#Port.provide} * can be called on this object. Because these methods are called with RPC, * they are all asynchronous, The return types of all Host methods will be * Promises which resolve to the value the Host method returns. * @public */ host: App["incoming"]; /** * @internal */ private invokeChecker; /** * @internal */ private invokeAwaiter; private timeout; protected hostConnectionPromise: Promise>; protected hostConnection: CrossRealmObject; /** @internal */ protected getLocalMethods(): { emit: (type: "contextchange" | "beforeconnect" | "connected" | "error", detail: ({ context: Record; } & Record & { guest: Guest; }) | (Record & { guest: Guest; }) | ({ error: Error; } & Record & { guest: Guest; })) => void; }; /** * Accept a connection from the Host. * @returns A Promise that resolves when the Host has established a connection. * @deprecated It is preferable to use {@link register} for primary frames, * and {@link attach} for UI frames and other secondary frames, than to * instantiate a Guest and then call `.connect()` on it. The latter style * returns an object that cannot be used until it is connected, and therefore * risks errors. * @public */ connect(): Promise; /** * @internal */ _connect(): Promise; } //# sourceMappingURL=guest.d.ts.map