@adobe/uix-host 0.6.4 → 0.6.5-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js CHANGED
@@ -159,9 +159,12 @@ var Port = class extends Emitter {
159
159
  try {
160
160
  methodCallee = this.getHostMethodCallee(address, privateMethods);
161
161
  } catch (e) {
162
- methodCallee = this.getHostMethodCallee(address, this.hostApis);
162
+ this.debugLogger.warn("Private method not found!", address);
163
163
  }
164
164
  }
165
+ if (!methodCallee) {
166
+ methodCallee = this.getHostMethodCallee(address, this.hostApis);
167
+ }
165
168
  const method = methodCallee[name];
166
169
  this.emit("beforecallhostmethod", { guestPort: this, name, path, args });
167
170
  return method.apply(methodCallee, [
@@ -403,6 +406,20 @@ function combineExtensionsFromProviders(...providers) {
403
406
  );
404
407
  }
405
408
 
406
- export { Host, Port, combineExtensionsFromProviders, createExtensionRegistryProvider };
409
+ // src/extensions-provider/mute.ts
410
+ function mutedProvider(provider) {
411
+ return async () => {
412
+ try {
413
+ return await provider();
414
+ } catch (error) {
415
+ console.error(`Extension provider has failed: ${error.message}`, {
416
+ error
417
+ });
418
+ return {};
419
+ }
420
+ };
421
+ }
422
+
423
+ export { Host, Port, combineExtensionsFromProviders, createExtensionRegistryProvider, mutedProvider };
407
424
  //# sourceMappingURL=out.js.map
408
425
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/host.ts","../../src/port.ts","../../src/debug-host.ts","../../src/extensions-provider/extension-registry.ts","../../src/extensions-provider/composition.ts"],"names":["Emitter","log","event","host","window"],"mappings":";AAoBA,SAAS,WAAAA,UAAS,oBAAoB;;;ACCtC,SAAS,eAAe;AACxB,SAAqB,sBAA+B;AA4FpD,IAAM,iBAAiB;AAAA,EACrB,SAAS;AAAA,EACT,OAAO;AACT;AAsBO,IAAM,OAAN,cACG,QAEV;AAAA,EA6CE,YAAY,QAiBT;AACD,UAAM,OAAO,EAAE;AAvDj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AG,MAA2B;AACxC,UAAI,EAAE,WAAW,aAAa;AAC5B,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL,GAAG;AAAA,QAEH,CAAC,EAAE,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG;AAAA,MAC5C;AAAA,IACF,GAAG,CAAC,CAAC;AAAA,EACP;AAEA,SAAO,QAAQ,QAAQ,CAAC,CAAC;AAC3B;AAMO,SAAS,gCACd,QACoB;AACpB,SAAO,WAAY;AACjB,WAAO,oCAAoC,MAAM;AAAA,EACnD;AACF;;;ACnIO,SAAS,kCACX,WACiB;AACpB,SAAO,MACL,QAAQ,IAAI,UAAU,IAAI,CAAC,OAA2B,GAAG,CAAC,CAAC,EAAE;AAAA,IAC3D,CAAC,sBAAkD;AACjD,aAAO,OAAO,OAAO,CAAC,GAAG,GAAG,iBAAiB;AAAA,IAC/C;AAAA,EACF;AACJ","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Extension,\n GuestConnection,\n NamedEvent,\n Emits,\n GuestApis,\n} from \"@adobe/uix-core\";\nimport type { CapabilitySpec } from \"./port.js\";\nimport { Emitter, quietConsole } from \"@adobe/uix-core\";\nimport { Port, PortOptions } from \"./port.js\";\nimport { debugHost } from \"./debug-host.js\";\n\n/**\n * Dictionary of {@link Port} objects by extension ID.\n * @public\n */\nexport type PortMap = Map<string, GuestConnection>;\n\n/** @public */\nexport type HostEvent<\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<Type, Detail & Record<string, unknown> & { host: Host }>;\n/** @public */\ntype HostGuestEvent<Type extends string> = HostEvent<\n `guest${Type}`,\n { guest: GuestConnection }\n>;\n\n/**\n * All guests requested by host have been loaded and connected.\n * @public\n */\nexport type HostEventLoadAllGuests = HostEvent<\n \"loadallguests\",\n { failed: GuestConnection[]; loaded: GuestConnection[] }\n>;\n\n/**\n * Shared context has been set or updated; all guests receive this event too.\n * @public\n */\n\nexport type HostEventContextChange = HostEvent<\n \"contextchange\",\n { context: SharedContextValues }\n>;\n\n/**\n * An error has occurred during loading or unloading of guests.\n * @public\n */\nexport type HostEventError = HostEvent<\"error\", { error: Error }>;\n\n/** @public */\nexport type HostEvents =\n | HostGuestEvent<\"beforeload\">\n | HostGuestEvent<\"load\">\n | HostEvent<\"beforeunload\">\n | HostEvent<\"unload\">\n | HostEventLoadAllGuests\n | HostEventContextChange\n | HostEventError;\n\n/** @public */\nexport type InstalledExtensions = Record<Extension[\"id\"], Extension[\"url\"]>;\n/** @public */\nexport type ExtensionsProvider = () => Promise<InstalledExtensions>;\n\n/**\n * Values for shared context. Must be a plain object, serializable to JSON.\n * @public\n */\nexport type SharedContextValues = Record<string, unknown>;\n\n/** @public */\nexport interface HostConfig {\n /**\n * Human-readable \"slug\" name of the extensible area--often an entire app.\n * This string serves as a namespace for extension points within the area.\n */\n hostName: string;\n /**\n * A DOM element _outside_ of the React root. This is necessary to preserve\n * the lifetime of the iframes which are running extension objects; if they\n * live inside the React root, then React could unexpectedly re-render the\n * iframe tags themselves at any time, causing a reload of the frame.\n */\n runtimeContainer?: HTMLElement;\n /**\n * Copiously log lifecycle events.\n */\n debug?: boolean;\n /**\n * Default options to use for every guest Port.\n *\n * If `config.debug` is true, then the guest options will have `debug: true`\n * unless `debug: false` is explicitly passed in `guestOptions`.\n */\n guestOptions?: PortOptions;\n /**\n * A read-only dictionary of values that the host will supply to all the\n * guests.\n */\n sharedContext?: SharedContextValues;\n}\n\n/**\n * Callback to use to filter the list returned from {@link Host.(getLoadedGuests:2)}\n * @public\n */\ntype GuestFilter = (item: GuestConnection) => boolean;\n\nconst passAllGuests = () => true;\n\n/**\n * Manager object for connecting to {@link @adobe/uix-guest#GuestServer |\n * GuestServers} and {@link @adobe/uix-guest#GuestUI | GuestUIs}, providing and\n * receiving their APIs, and providing them to the app for interacting with UI.\n *\n * @remarks\n * The Host object is the main connection manager for all UIX Guests.\n * Making an app extensible requires creating a Host object.\n *\n * The extensible app using the Hostis responsible for providing a list of\n * extension references to the Host object. Use {@link\n * createExtensionRegistryProvider} for that purpose. Once you have retrieved a\n * list of extensions available to the host app, pass it to {@link Host.load}.\n *\n * When a Host creates a Guest, it must create an `<iframe>` element to contain\n * the Guest's main {@link @adobe/uix-guest#GuestServer} runtime, which runs\n * invisibly in the background. To do this, the Host creates a hidden container\n * in the body of the document. It is a `<div>` element with the attribute\n * `data-uix-guest-container`. Loaded GuestServers will be injected into this\n * hidden element and removed as necessary. When {@link Host.unload} is called,\n * the Host removes the hidden container from the document after unloading.\n *\n * @public\n */\nexport class Host extends Emitter<HostEvents> {\n /**\n * {@inheritDoc HostEventLoadAllGuests}\n * @eventProperty\n */\n public loadallguests: HostEventLoadAllGuests;\n\n /**\n * One guest has loaded.\n * @eventProperty\n */\n public guestload: HostGuestEvent<\"load\">;\n\n /**\n * About to attempt to load and connect to a Guest.\n * @eventProperty\n */\n public guestbeforeload: HostGuestEvent<\"beforeload\">;\n\n /**\n * About to unload a guest and remove its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestbeforeunload: HostGuestEvent<\"beforeunload\">;\n\n /**\n * Unloaded a guest and removed its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestunload: HostGuestEvent<\"unload\">;\n\n /**\n * {@inheritDoc HostEventContextChange}\n * @eventProperty\n */\n public contextchange: HostEventContextChange;\n\n /**\n * {@inheritDoc HostEventError}\n * @eventProperty\n */\n public error: HostEventError;\n\n private static containerStyle = {\n position: \"fixed\",\n width: \"1px\",\n height: \"1px\",\n pointerEvents: \"none\",\n opacity: 0,\n top: 0,\n left: \"-1px\",\n };\n /**\n * Unique string identifying the Host object.\n */\n hostName: string;\n /**\n * `true` if any extension in {@link Host.guests} has created a {@link\n * @adobe/uix-guest#GuestServer}, but the Guest has not yet loaded.\n */\n loading = false;\n /**\n * A Map of of the loaded guests.\n */\n guests: PortMap = new Map();\n private cachedCapabilityLists: WeakMap<object, GuestConnection[]> =\n new WeakMap();\n private runtimeContainer: HTMLElement;\n private guestOptions: PortOptions;\n private debugLogger: Console = quietConsole;\n private sharedContext: SharedContextValues;\n constructor(config: HostConfig) {\n super(config.hostName);\n const { guestOptions = {} } = config;\n this.guestOptions = {\n ...guestOptions,\n debug: guestOptions.debug === false ? false : !!config.debug,\n };\n this.hostName = config.hostName;\n this.sharedContext = config.sharedContext || {};\n this.runtimeContainer = config.runtimeContainer;\n if (config.debug) {\n this.debugLogger = debugHost(this);\n }\n }\n /**\n * Return all loaded guests.\n */\n getLoadedGuests(): GuestConnection[];\n /**\n * Return loaded guests which satisfy the passed test function.\n */\n getLoadedGuests(filter: GuestFilter): GuestConnection[];\n /**\n * Return loaded guests which expose the provided {@link CapabilitySpec}.\n */\n getLoadedGuests<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ): GuestConnection[];\n getLoadedGuests<Apis extends GuestApis = never>(\n filterOrCapabilities?: CapabilitySpec<Apis> | GuestFilter\n ): GuestConnection[] {\n if (typeof filterOrCapabilities === \"object\") {\n return this.getLoadedGuestsWith<Apis>(filterOrCapabilities);\n }\n const filter = filterOrCapabilities || passAllGuests;\n const result = [];\n for (const guest of this.guests.values()) {\n if (guest.isReady() && filter(guest)) {\n result.push(guest);\n }\n }\n return result;\n }\n /**\n * Set the object of shared values that all Guests can access via {@link @adobe/uix-guest#GuestServer.sharedContext}.\n * This overwrites any previous object.\n *\n * @example Exposes `authToken` to all Guests. Guests can call `this.sharedContext.get('authToken')` to retrieve this value.\n * ```javascript\n * host.shareContext({\n * authToken: '82ba19b'\n * });\n * ```\n *\n * @example Overwrites the previous sharedContext, deleting `authToken` and providing `secret` and `auth` instead.\n * ```javascript\n * host.shareContext({\n * secret: 'squirrel',\n * auth: false\n * });\n * ```\n */\n shareContext(context: SharedContextValues): void;\n /**\n * Update the object of shared values that all Guests can access via {@link\n * @adobe/uix-guest#GuestServer.sharedContext}. This method takes a callback\n * which receives the previous context and may return an entirely new context,\n * or new values merged with the old context.\n *\n * @remarks This callback pattern allows the shared context values to be\n * mutable while the internal context object references are immutable, which\n * is important for synchronizing. with guests.\n *\n * @example Overwrites a context object based on the previous one.\n * ```javascript\n * host.shareContext(oldContext => ({\n * counter: oldContext.counter + 1\n * }))\n * ```\n *\n * @example Updates a context while preserving other existing values.\n * ```javascript\n * host.shareContext(oldContext => ({\n * ...oldContext,\n * counter: oldContext.counter + 1\n * }))\n * ```\n */\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setterOrContext:\n | ((context: SharedContextValues) => SharedContextValues)\n | SharedContextValues\n ) {\n if (typeof setterOrContext === \"function\") {\n this.sharedContext = setterOrContext(this.sharedContext);\n } else {\n this.sharedContext = setterOrContext;\n }\n this.emit(\"contextchange\", {\n host: this,\n context: this.sharedContext,\n });\n }\n /**\n * Load extension into host application from provided extension description.\n * Returned promise resolves when all extensions are loaded and registered.\n *\n * @param extensions - List of extension descriptors. Normally, the Host should receive this value from an {@link ExtensionsProvider}.\n * @param options - Custom options to be used as defaults for each {@link Port} object created for each guest.\n * @returns Promise which resolves when all guests have been loaded.\n */\n async load(\n extensions: InstalledExtensions,\n options?: PortOptions\n ): Promise<void> {\n this.runtimeContainer =\n this.runtimeContainer || this.createRuntimeContainer(window);\n const failed: GuestConnection[] = [];\n const loaded: GuestConnection[] = [];\n this.loading = true;\n await Promise.all(\n Object.entries(extensions).map(async ([id, url]) => {\n const port = await this.loadOneGuest(id, url, options);\n (port.error ? failed : loaded).push(port);\n })\n );\n this.loading = false;\n this.emit(\"loadallguests\", { host: this, failed, loaded });\n }\n /**\n * Unload all extensions and remove their frames/workers. Use this to unmount\n * a UI or when switching to a different extensible UI.\n */\n async unload(): Promise<void> {\n this.emit(\"beforeunload\", { host: this });\n await Promise.all([...this.guests.values()].map((guest) => guest.unload()));\n this.guests.clear();\n this.runtimeContainer.parentElement.removeChild(this.runtimeContainer);\n this.emit(\"unload\", { host: this });\n }\n private createRuntimeContainer(window: Window) {\n const { document } = window;\n const container = document.createElement(\"div\");\n container.setAttribute(\"data-uix-guest-container\", this.hostName);\n Object.assign(container.style, Host.containerStyle);\n document.body.appendChild(container);\n return container;\n }\n private async loadOneGuest(\n id: string,\n urlString: string,\n options: PortOptions = {}\n ): Promise<GuestConnection> {\n let guest = this.guests.get(id);\n if (!guest) {\n const url = new URL(urlString);\n guest = new Port({\n owner: this.hostName,\n id,\n url,\n runtimeContainer: this.runtimeContainer,\n options: {\n ...this.guestOptions,\n ...options,\n },\n debugLogger: this.debugLogger,\n sharedContext: this.sharedContext,\n events: this as Emits,\n });\n this.guests.set(id, guest);\n }\n this.emit(\"guestbeforeload\", { guest, host: this });\n try {\n await guest.load();\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n this.emit(\"error\", { host: this, guest, error });\n console.warn(\"Failed to load extension at endpoint %s\", guest.url);\n return guest;\n }\n // this new guest might have new capabilities, so the identities of the\n // cached capability sets will need to change, to alert subscribers\n this.cachedCapabilityLists = new WeakMap();\n this.emit(\"guestload\", { guest, host: this });\n return guest;\n }\n private getLoadedGuestsWith<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ) {\n if (this.cachedCapabilityLists.has(capabilities)) {\n return this.cachedCapabilityLists.get(capabilities);\n }\n const guestsWithCapabilities = this.getLoadedGuests((guest) =>\n guest.hasCapabilities(capabilities)\n );\n this.cachedCapabilityLists.set(capabilities, guestsWithCapabilities);\n return guestsWithCapabilities;\n }\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Emits,\n GuestConnection,\n HostMethodAddress,\n NamedEvent,\n RemoteHostApis,\n GuestApis,\n Unsubscriber,\n} from \"@adobe/uix-core\";\nimport { Emitter } from \"@adobe/uix-core\";\nimport { Connection, connectToChild, Methods } from \"penpal\";\n\n/**\n * A specifier for methods to be expected on a remote interface.\n *\n * @remarks\n * A CapabilitySpec is a description of an interface, like a very simplified\n * type definition. It specifies an object structure and the paths in that\n * structure that must be functions. (It doesn't specify anything about the\n * signatures or return values of those functions.)\n *\n * Use CapabilitySpec objects as queries, or filters, to get a subset of\n * installed extensions which have registered methods which match the spec.\n *\n * @example\n * As an extensible app developer, you are making an extension point for spell\n * check. Your code expects extensions to register an API `spellCheck` with\n * methods called `spellCheck.correct(text)` and `spellCheck.suggest(text)`.\n *\n * ```javascript\n * async function correctText(text) {\n * const spellCheckers = host.getLoadedGuests({\n * spellCheck: [\n * 'correct',\n * 'suggest'\n * ]\n * });\n * let correcting = text;\n * for (const checker of spellCheckers) {\n * correcting = await checker.apis.spellCheck.correct(correcting);\n * }\n * return Promise.all(checkers.map(checker =>\n * checker.apis.spellCheck.suggest(correcting)\n * ));\n * }\n * ```\n *\n * @public\n */\nexport type CapabilitySpec<T extends GuestApis> = {\n [Name in keyof T]: (keyof T[Name])[];\n};\n\n/**\n * Interface for decoupling of guest Penpal object\n * @internal\n */\ninterface GuestProxyWrapper {\n /**\n * Methods from guest\n */\n apis: RemoteHostApis;\n /**\n * Emit an event in the guest frame\n */\n emit(type: string, detail: unknown): Promise<void>;\n}\n\n/** @public */\ntype PortEvent<\n GuestApi,\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<\n Type,\n Detail &\n Record<string, unknown> & {\n guestPort: Port<GuestApi>;\n }\n>;\n\n/** @public */\nexport type PortEvents<\n GuestApi,\n HostApi extends Record<string, unknown> = Record<string, unknown>\n> =\n | PortEvent<GuestApi, \"hostprovide\">\n | PortEvent<GuestApi, \"unload\">\n | PortEvent<GuestApi, \"beforecallhostmethod\", HostMethodAddress<HostApi>>;\n\n/** @public */\nexport type PortOptions = {\n /**\n * Time in milliseconds to wait for the guest to connect before throwing.\n */\n timeout?: number;\n /**\n * Set true to log copiously in the console.\n */\n debug?: boolean;\n};\n\nconst defaultOptions = {\n timeout: 10000,\n debug: false,\n};\n\n/**\n * A Port is the Host-maintained object representing an extension running as a\n * guest. It exposes methods registered by the Guest, and can provide Host\n * methods back to the guest.\n *\n * @remarks\n * When the Host object loads extensions via {@link Host.load}, it creates a\n * Port object for each extension. When retrieving and filtering extensions\n * via {@link Host.(getLoadedGuests:2)}, a list of Port objects is returned. From\n * the point of view of the extensible app using the Host object, extensions\n * are always Port objects, which expose the methods registered by the\n * extension at the {@link Port.apis} property.\n *\n * @privateRemarks\n * We've gone through several possible names for this object. GuestProxy,\n * GuestInterface, GuestConnection, etc. \"Port\" is not ideal, but it conflicted\n * the least with other types we defined in early drafts. It's definitely\n * something we should review.\n * @public\n */\nexport class Port<GuestApi>\n extends Emitter<PortEvents<GuestApi>>\n implements GuestConnection\n{\n // #region Properties (15)\n\n private connection: Connection<RemoteHostApis<GuestApi>>;\n private debug: boolean;\n private debugLogger?: Console;\n private frame: HTMLIFrameElement;\n private guest: GuestProxyWrapper;\n private hostApis: RemoteHostApis = {};\n private isLoaded = false;\n private runtimeContainer: HTMLElement;\n private sharedContext: Record<string, unknown>;\n private subscriptions: Unsubscriber[] = [];\n private timeout: number;\n\n /**\n * Dictionary of namespaced methods that were registered by this guest at the\n * time of connection, using {@link @adobe/uix-guest#register}.\n *\n * @remarks\n * These methods are proxy methods; you can only pass serializable objects to\n * them, not class instances, methods or callbacks.\n * @public\n */\n public apis: RemoteHostApis;\n /**\n * If any errors occurred during the loading of guests, this property will\n * contain the error that was raised.\n * @public\n */\n error?: Error;\n private uiConnections: Map<string, Connection<RemoteHostApis<GuestApi>>> =\n new Map();\n /**\n * The URL of the guest provided by the extension registry. The Host will\n * load this URL in the background, in the invisible the bootstrap frame, so\n * this URL must point to a page that calls {@link @adobe/uix-guest#register}\n * when it loads.\n */\n url: URL;\n\n // #endregion Properties (15)\n\n // #region Constructors (1)\n\n constructor(config: {\n owner: string;\n id: string;\n url: URL;\n /**\n * An alternate DOM element to use for invisible iframes. Will create its\n * own if this option is not populated with a DOM element.\n */\n runtimeContainer: HTMLElement;\n options: PortOptions;\n debugLogger?: Console;\n /**\n * Initial object to populate the shared context with. Once the guest\n * connects, it will be able to access these properties.\n */\n sharedContext: Record<string, unknown>;\n events: Emits;\n }) {\n super(config.id);\n const { timeout, debug } = { ...defaultOptions, ...(config.options || {}) };\n this.timeout = timeout;\n this.debug = debug;\n this.id = config.id;\n this.url = config.url;\n this.runtimeContainer = config.runtimeContainer;\n this.sharedContext = config.sharedContext;\n this.subscriptions.push(\n config.events.addEventListener(\"contextchange\", async (event) => {\n this.sharedContext = (\n (event as CustomEvent).detail as unknown as Record<string, unknown>\n ).context as Record<string, unknown>;\n await this.connect();\n await this.guest.emit(\"contextchange\", { context: this.sharedContext });\n })\n );\n }\n\n // #endregion Constructors (1)\n\n // #region Public Methods (6)\n\n /**\n * Connect an iframe element which is displaying another page in the extension\n * with the extension's bootstrap frame, so they can share context and events.\n */\n public attachUI(iframe: HTMLIFrameElement) {\n const uniqueId = Math.random().toString(36);\n const uiConnection = this.attachFrame(iframe);\n this.uiConnections.set(uniqueId, uiConnection);\n return uiConnection;\n }\n\n /**\n * Returns true if the guest has registered methods matching the provided\n * capability spec. A capability spec is simply an object whose properties are\n * declared in an array of keys, description the names of the functions and\n * methods that the Port will expose.\n */\n public hasCapabilities(requiredMethods: CapabilitySpec<GuestApis>) {\n this.assertReady();\n return Object.keys(requiredMethods).every((key) => {\n if (!Reflect.has(this.apis, key)) {\n return false;\n }\n const api = this.apis[key];\n const methodList = requiredMethods[\n key as keyof typeof requiredMethods\n ] as string[];\n return methodList.every(\n (methodName: string) =>\n Reflect.has(api, methodName) &&\n typeof api[methodName as keyof typeof api] === \"function\"\n );\n });\n }\n\n /**\n * True when al extensions have loaded.\n */\n public isReady(): boolean {\n return this.isLoaded && !this.error;\n }\n\n /**\n * Loads the extension. Returns a promise which resolves when the extension\n * has loaded. The Host calls this method after retrieving extensions.\n */\n public async load() {\n try {\n if (!this.apis) {\n await this.connect();\n }\n return this.apis;\n } catch (e) {\n this.apis = null;\n this.guest = null;\n this.error = e instanceof Error ? e : new Error(String(e));\n throw e;\n }\n }\n\n /**\n * The host-side equivalent of {@link @adobe/uix-guest#register}. Pass a set\n * of methods down to the guest as proxies.\n */\n public provide(apis: RemoteHostApis) {\n Object.assign(this.hostApis, apis);\n this.emit(\"hostprovide\", { guestPort: this, apis });\n }\n\n /**\n * Disconnect from the extension.\n */\n public async unload(): Promise<void> {\n if (this.connection) {\n await this.connection.destroy();\n }\n for (const connection of this.uiConnections.values()) {\n await connection.destroy();\n }\n if (this.frame && this.frame.parentElement) {\n this.frame.parentElement.removeChild(this.frame);\n this.frame = undefined;\n }\n this.emit(\"unload\", { guestPort: this });\n }\n\n // #endregion Public Methods (6)\n\n // #region Private Methods (6)\n\n private assert(\n condition: boolean,\n errorMessage: () => string\n ): asserts condition {\n if (!condition) {\n throw new Error(\n `Error in guest extension \"${this.id}\": ${errorMessage()}`\n );\n }\n }\n\n private assertReady() {\n this.assert(this.isReady(), () => \"Attempted to interact before loaded\");\n }\n\n private attachFrame(iframe: HTMLIFrameElement) {\n return connectToChild<RemoteHostApis<GuestApi>>({\n iframe,\n debug: this.debug,\n childOrigin: this.url.origin,\n timeout: this.timeout,\n methods: {\n getSharedContext: () => this.sharedContext,\n invokeHostMethod: (address: HostMethodAddress) =>\n this.invokeHostMethod(address),\n },\n });\n }\n\n private async connect() {\n this.frame = this.runtimeContainer.ownerDocument.createElement(\"iframe\");\n this.frame.setAttribute(\"src\", this.url.href);\n this.frame.setAttribute(\"data-uix-guest\", \"true\");\n this.runtimeContainer.appendChild(this.frame);\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} attached iframe of ${this.url.href}`,\n this\n );\n }\n this.connection = this.attachFrame(this.frame);\n this.guest = (await this.connection\n .promise) as unknown as GuestProxyWrapper;\n this.apis = this.guest.apis || {};\n this.isLoaded = true;\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} established connection, received methods`,\n this.apis,\n this\n );\n }\n }\n\n private getHostMethodCallee<T = unknown>(\n { name, path }: HostMethodAddress,\n methodSource: RemoteHostApis\n ): Methods {\n const dots = (level: number) =>\n `uix.host.${path.slice(0, level).join(\".\")}`;\n const methodCallee = path.reduce((current, prop, level) => {\n this.assert(\n Reflect.has(current, prop),\n () => `${dots(level)} has no property \"${prop}\"`\n );\n const next = current[prop];\n this.assert(\n typeof next === \"object\",\n () =>\n `${dots(\n level\n )}.${prop} is not an object; namespaces must be objects with methods`\n );\n return next as RemoteHostApis<GuestApi>;\n }, methodSource);\n this.assert(\n typeof methodCallee[name] === \"function\" &&\n Reflect.has(methodCallee, name),\n () => `\"${dots(path.length - 1)}.${name}\" is not a function`\n );\n return methodCallee;\n }\n\n private invokeHostMethod<T = unknown>(\n address: HostMethodAddress,\n privateMethods?: RemoteHostApis\n ): T {\n const { name, path, args = [] } = address;\n this.assert(name && typeof name === \"string\", () => \"Method name required\");\n this.assert(\n path.length > 0,\n () =>\n `Cannot call a method directly on the host; \".${name}()\" must be in a namespace.`\n );\n let methodCallee;\n if (privateMethods) {\n try {\n methodCallee = this.getHostMethodCallee(address, privateMethods);\n } catch (e) {\n methodCallee = this.getHostMethodCallee(address, this.hostApis);\n }\n }\n const method = methodCallee[name] as (...args: unknown[]) => T;\n this.emit(\"beforecallhostmethod\", { guestPort: this, name, path, args });\n return method.apply(methodCallee, [\n { id: this.id, url: this.url },\n ...args,\n ]) as T;\n }\n\n // #endregion Private Methods (6)\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/**\n * Adapter to attach console logging listeners to a Host running in an app\n * @hidden\n */\nimport {\n debugEmitter,\n EmitterDebugLogger,\n Emits,\n GuestConnection,\n} from \"@adobe/uix-core\";\nimport type { PortEvents } from \"./port.js\";\nimport type { HostEventLoadAllGuests, HostEvents } from \"./host.js\";\n\ntype GenericPortEvents = PortEvents<Record<string, unknown>>;\n\ntype Portlike = GuestConnection & Emits<GenericPortEvents>;\n\nexport function debugHost(host: Emits<HostEvents>): EmitterDebugLogger {\n const hostLogger = debugEmitter(host, {\n theme: \"blue medium\",\n type: \"Host\",\n });\n hostLogger\n .listen(\"guestbeforeload\", (log, event) => {\n const { detail } = event;\n const guest = detail.guest as Portlike;\n log.info(event, `Guest ID ${guest.id}`);\n const portLogger = debugEmitter(guest, {\n theme: \"green medium\",\n type: \"Port\",\n id: `${host.id} ➔ ${guest.id}`,\n });\n portLogger\n .listen(\"hostprovide\", (log, event) => {\n log.info(\"received APIs\", event.detail.apis);\n })\n .listen(\"beforecallhostmethod\", (log, event) => {\n log.info(event.detail);\n })\n .listen(\"unload\", (log, event) => {\n log.info(event.detail);\n log.detach();\n });\n })\n .listen(\"guestload\", (log, e) => {\n log.info(e.detail.guest.id, e.detail.guest);\n })\n .listen(\"error\", (log, e) => {\n log.error(`Error: ${e.detail.error.message}`, e);\n })\n .listen(\n \"loadallguests\",\n (log, { detail: { failed, loaded, host } }: HostEventLoadAllGuests) => {\n if (failed.length > 0) {\n log.error(\"%d guests failed to load!\", failed.length);\n }\n log.info(\"%d guests loaded\", loaded.length, host);\n }\n )\n .listen(\"unload\", (log) => {\n log.info(\"Unloaded guest and container.\");\n log.detach();\n });\n return hostLogger;\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\ninterface ExtensionDefinition {\n name: string;\n title: string;\n description: string;\n icon: string;\n publisher: string;\n endpoints: Record<string, EndpointDefinition>;\n xrInfo: ExtensionInfo;\n status: string;\n}\n\ntype EndpointDefinition = Record<string, Array<OperationDefinition>>;\n\ninterface ExtensionInfo {\n supportEmail: string;\n appId: string;\n}\n\ninterface OperationDefinition {\n href: string;\n metadata: OperationMetadata;\n}\n\ninterface OperationMetadata {\n services: Array<object>;\n profile: OperationProfile;\n}\n\ninterface OperationProfile {\n client_id: string;\n scope: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryEndpointRegistration {\n service: string;\n extensionPoint: string;\n version: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryExtensionRegistration\n extends ExtensionRegistryEndpointRegistration {\n imsOrg: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryConnection {\n baseUrl?: string;\n apiKey: string;\n auth: {\n schema: \"Basic\" | \"Bearer\";\n imsToken: string;\n };\n}\n\n/** @public */\nexport interface ExtensionRegistryConfig\n extends ExtensionRegistryExtensionRegistration,\n ExtensionRegistryConnection {}\n\nfunction buildEndpointPath(\n config: ExtensionRegistryEndpointRegistration\n): string {\n return `${config.service}/${config.extensionPoint}/${config.version}`;\n}\n\nfunction ensureProtocolSpecified(url: string) {\n if (url.startsWith(\"https://\")) {\n return url;\n }\n if (url.startsWith(\"http://\")) {\n return url;\n }\n return `https://${url}`;\n}\n\nasync function fetchExtensionsFromRegistry(\n config: ExtensionRegistryConfig\n): Promise<Array<ExtensionDefinition>> {\n const resp = await fetch(\n `${ensureProtocolSpecified(\n config.baseUrl || \"appregistry.adobe.io\"\n )}/myxchng/v1/org/${encodeURIComponent(\n config.imsOrg\n )}/xtn/${buildEndpointPath(config)}?auth=true`,\n {\n headers: {\n Accept: \"application/json\",\n Authorization: `${config.auth.schema} ${config.auth.imsToken}`, // todo: check if auth schema needed (initial implementation was without it)\n \"X-Api-Key\": config.apiKey,\n },\n }\n );\n\n if (resp.status != 200) {\n throw new Error(\n `extension registry returned non-200 response (${\n resp.status\n }): ${await resp.text()}`\n );\n }\n\n return await resp.json();\n}\n\nfunction extensionRegistryExtensionsProvider(\n config: ExtensionRegistryConfig\n): Promise<InstalledExtensions> {\n const erEndpoint = buildEndpointPath(config);\n return fetchExtensionsFromRegistry(config).then((out) =>\n out.reduce((a, e: ExtensionDefinition) => {\n if (e.status !== \"PUBLISHED\") {\n return a;\n }\n\n return {\n ...a,\n // todo: make safer way to extract href\n [e.name]: e.endpoints[erEndpoint].view[0].href,\n };\n }, {})\n );\n\n return Promise.resolve({});\n}\n\n/**\n * Create a callback that fetches extensions from the registry.\n * @public\n */\nexport function createExtensionRegistryProvider(\n config: ExtensionRegistryConfig\n): ExtensionsProvider {\n return function () {\n return extensionRegistryExtensionsProvider(config);\n };\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\n/**\n * Combine multiple {@link @adobe/uix-host#ExtensionsProvider} callbacks into a\n * single callback, which aggregates and dedupes all extensions from all\n * providers into one namespaced object.\n * @public\n */\nexport function combineExtensionsFromProviders(\n ...providers: Array<ExtensionsProvider>\n): ExtensionsProvider {\n return () =>\n Promise.all(providers.map((ep: ExtensionsProvider) => ep())).then(\n (extensionsBatches: Array<InstalledExtensions>) => {\n return Object.assign({}, ...extensionsBatches);\n }\n );\n}\n"]}
1
+ {"version":3,"sources":["../../src/host.ts","../../src/port.ts","../../src/debug-host.ts","../../src/extensions-provider/extension-registry.ts","../../src/extensions-provider/composition.ts","../../src/extensions-provider/mute.ts"],"names":["Emitter","log","event","host","window"],"mappings":";AAoBA,SAAS,WAAAA,UAAS,oBAAoB;;;ACCtC,SAAS,eAAe;AACxB,SAAqB,sBAA+B;AA4FpD,IAAM,iBAAiB;AAAA,EACrB,SAAS;AAAA,EACT,OAAO;AACT;AAsBO,IAAM,OAAN,cACG,QAEV;AAAA,EA6CE,YAAY,QAiBT;AACD,UAAM,OAAO,EAAE;AAvDjB,SAAQ,WAA2B,CAAC;AACpC,SAAQ,WAAW;AAGnB,SAAQ,gBAAgC,CAAC;AAmBzC,SAAQ,gBACN,oBAAI,IAAI;AAgCR,UAAM,EAAE,SAAS,MAAM,IAAI,EAAE,GAAG,gBAAgB,GAAI,OAAO,WAAW,CAAC,EAAG;AAC1E,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,SAAK,KAAK,OAAO;AACjB,SAAK,MAAM,OAAO;AAClB,SAAK,mBAAmB,OAAO;AAC/B,SAAK,gBAAgB,OAAO;AAC5B,SAAK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,QACoB;AACpB,SAAO,WAAY;AACjB,WAAO,oCAAoC,MAAM;AAAA,EACnD;AACF;;;ACnIO,SAAS,kCACX,WACiB;AACpB,SAAO,MACL,QAAQ,IAAI,UAAU,IAAI,CAAC,OAA2B,GAAG,CAAC,CAAC,EAAE;AAAA,IAC3D,CAAC,sBAAkD;AACjD,aAAO,OAAO,OAAO,CAAC,GAAG,GAAG,iBAAiB;AAAA,IAC/C;AAAA,EACF;AACJ;;;ACTO,SAAS,cACd,UACoB;AACpB,SAAO,YAAY;AACjB,QAAI;AACF,aAAO,MAAM,SAAS;AAAA,IACxB,SAAS,OAAP;AACA,cAAQ,MAAM,kCAAkC,MAAM,WAAW;AAAA,QAC/D;AAAA,MACF,CAAC;AACD,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Extension,\n GuestConnection,\n NamedEvent,\n Emits,\n GuestApis,\n} from \"@adobe/uix-core\";\nimport type { CapabilitySpec } from \"./port.js\";\nimport { Emitter, quietConsole } from \"@adobe/uix-core\";\nimport { Port, PortOptions } from \"./port.js\";\nimport { debugHost } from \"./debug-host.js\";\n\n/**\n * Dictionary of {@link Port} objects by extension ID.\n * @public\n */\nexport type PortMap = Map<string, GuestConnection>;\n\n/** @public */\nexport type HostEvent<\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<Type, Detail & Record<string, unknown> & { host: Host }>;\n/** @public */\ntype HostGuestEvent<Type extends string> = HostEvent<\n `guest${Type}`,\n { guest: GuestConnection }\n>;\n\n/**\n * All guests requested by host have been loaded and connected.\n * @public\n */\nexport type HostEventLoadAllGuests = HostEvent<\n \"loadallguests\",\n { failed: GuestConnection[]; loaded: GuestConnection[] }\n>;\n\n/**\n * Shared context has been set or updated; all guests receive this event too.\n * @public\n */\n\nexport type HostEventContextChange = HostEvent<\n \"contextchange\",\n { context: SharedContextValues }\n>;\n\n/**\n * An error has occurred during loading or unloading of guests.\n * @public\n */\nexport type HostEventError = HostEvent<\"error\", { error: Error }>;\n\n/** @public */\nexport type HostEvents =\n | HostGuestEvent<\"beforeload\">\n | HostGuestEvent<\"load\">\n | HostEvent<\"beforeunload\">\n | HostEvent<\"unload\">\n | HostEventLoadAllGuests\n | HostEventContextChange\n | HostEventError;\n\n/** @public */\nexport type InstalledExtensions = Record<Extension[\"id\"], Extension[\"url\"]>;\n/** @public */\nexport type ExtensionsProvider = () => Promise<InstalledExtensions>;\n\n/**\n * Values for shared context. Must be a plain object, serializable to JSON.\n * @public\n */\nexport type SharedContextValues = Record<string, unknown>;\n\n/** @public */\nexport interface HostConfig {\n /**\n * Human-readable \"slug\" name of the extensible area--often an entire app.\n * This string serves as a namespace for extension points within the area.\n */\n hostName: string;\n /**\n * A DOM element _outside_ of the React root. This is necessary to preserve\n * the lifetime of the iframes which are running extension objects; if they\n * live inside the React root, then React could unexpectedly re-render the\n * iframe tags themselves at any time, causing a reload of the frame.\n */\n runtimeContainer?: HTMLElement;\n /**\n * Copiously log lifecycle events.\n */\n debug?: boolean;\n /**\n * Default options to use for every guest Port.\n *\n * If `config.debug` is true, then the guest options will have `debug: true`\n * unless `debug: false` is explicitly passed in `guestOptions`.\n */\n guestOptions?: PortOptions;\n /**\n * A read-only dictionary of values that the host will supply to all the\n * guests.\n */\n sharedContext?: SharedContextValues;\n}\n\n/**\n * Callback to use to filter the list returned from {@link Host.(getLoadedGuests:2)}\n * @public\n */\ntype GuestFilter = (item: GuestConnection) => boolean;\n\nconst passAllGuests = () => true;\n\n/**\n * Manager object for connecting to {@link @adobe/uix-guest#GuestServer |\n * GuestServers} and {@link @adobe/uix-guest#GuestUI | GuestUIs}, providing and\n * receiving their APIs, and providing them to the app for interacting with UI.\n *\n * @remarks\n * The Host object is the main connection manager for all UIX Guests.\n * Making an app extensible requires creating a Host object.\n *\n * The extensible app using the Hostis responsible for providing a list of\n * extension references to the Host object. Use {@link\n * createExtensionRegistryProvider} for that purpose. Once you have retrieved a\n * list of extensions available to the host app, pass it to {@link Host.load}.\n *\n * When a Host creates a Guest, it must create an `<iframe>` element to contain\n * the Guest's main {@link @adobe/uix-guest#GuestServer} runtime, which runs\n * invisibly in the background. To do this, the Host creates a hidden container\n * in the body of the document. It is a `<div>` element with the attribute\n * `data-uix-guest-container`. Loaded GuestServers will be injected into this\n * hidden element and removed as necessary. When {@link Host.unload} is called,\n * the Host removes the hidden container from the document after unloading.\n *\n * @public\n */\nexport class Host extends Emitter<HostEvents> {\n /**\n * {@inheritDoc HostEventLoadAllGuests}\n * @eventProperty\n */\n public loadallguests: HostEventLoadAllGuests;\n\n /**\n * One guest has loaded.\n * @eventProperty\n */\n public guestload: HostGuestEvent<\"load\">;\n\n /**\n * About to attempt to load and connect to a Guest.\n * @eventProperty\n */\n public guestbeforeload: HostGuestEvent<\"beforeload\">;\n\n /**\n * About to unload a guest and remove its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestbeforeunload: HostGuestEvent<\"beforeunload\">;\n\n /**\n * Unloaded a guest and removed its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestunload: HostGuestEvent<\"unload\">;\n\n /**\n * {@inheritDoc HostEventContextChange}\n * @eventProperty\n */\n public contextchange: HostEventContextChange;\n\n /**\n * {@inheritDoc HostEventError}\n * @eventProperty\n */\n public error: HostEventError;\n\n private static containerStyle = {\n position: \"fixed\",\n width: \"1px\",\n height: \"1px\",\n pointerEvents: \"none\",\n opacity: 0,\n top: 0,\n left: \"-1px\",\n };\n /**\n * Unique string identifying the Host object.\n */\n hostName: string;\n /**\n * `true` if any extension in {@link Host.guests} has created a {@link\n * @adobe/uix-guest#GuestServer}, but the Guest has not yet loaded.\n */\n loading = false;\n /**\n * A Map of of the loaded guests.\n */\n guests: PortMap = new Map();\n private cachedCapabilityLists: WeakMap<object, GuestConnection[]> =\n new WeakMap();\n private runtimeContainer: HTMLElement;\n private guestOptions: PortOptions;\n private debugLogger: Console = quietConsole;\n private sharedContext: SharedContextValues;\n constructor(config: HostConfig) {\n super(config.hostName);\n const { guestOptions = {} } = config;\n this.guestOptions = {\n ...guestOptions,\n debug: guestOptions.debug === false ? false : !!config.debug,\n };\n this.hostName = config.hostName;\n this.sharedContext = config.sharedContext || {};\n this.runtimeContainer = config.runtimeContainer;\n if (config.debug) {\n this.debugLogger = debugHost(this);\n }\n }\n /**\n * Return all loaded guests.\n */\n getLoadedGuests(): GuestConnection[];\n /**\n * Return loaded guests which satisfy the passed test function.\n */\n getLoadedGuests(filter: GuestFilter): GuestConnection[];\n /**\n * Return loaded guests which expose the provided {@link CapabilitySpec}.\n */\n getLoadedGuests<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ): GuestConnection[];\n getLoadedGuests<Apis extends GuestApis = never>(\n filterOrCapabilities?: CapabilitySpec<Apis> | GuestFilter\n ): GuestConnection[] {\n if (typeof filterOrCapabilities === \"object\") {\n return this.getLoadedGuestsWith<Apis>(filterOrCapabilities);\n }\n const filter = filterOrCapabilities || passAllGuests;\n const result = [];\n for (const guest of this.guests.values()) {\n if (guest.isReady() && filter(guest)) {\n result.push(guest);\n }\n }\n return result;\n }\n /**\n * Set the object of shared values that all Guests can access via {@link @adobe/uix-guest#GuestServer.sharedContext}.\n * This overwrites any previous object.\n *\n * @example Exposes `authToken` to all Guests. Guests can call `this.sharedContext.get('authToken')` to retrieve this value.\n * ```javascript\n * host.shareContext({\n * authToken: '82ba19b'\n * });\n * ```\n *\n * @example Overwrites the previous sharedContext, deleting `authToken` and providing `secret` and `auth` instead.\n * ```javascript\n * host.shareContext({\n * secret: 'squirrel',\n * auth: false\n * });\n * ```\n */\n shareContext(context: SharedContextValues): void;\n /**\n * Update the object of shared values that all Guests can access via {@link\n * @adobe/uix-guest#GuestServer.sharedContext}. This method takes a callback\n * which receives the previous context and may return an entirely new context,\n * or new values merged with the old context.\n *\n * @remarks This callback pattern allows the shared context values to be\n * mutable while the internal context object references are immutable, which\n * is important for synchronizing. with guests.\n *\n * @example Overwrites a context object based on the previous one.\n * ```javascript\n * host.shareContext(oldContext => ({\n * counter: oldContext.counter + 1\n * }))\n * ```\n *\n * @example Updates a context while preserving other existing values.\n * ```javascript\n * host.shareContext(oldContext => ({\n * ...oldContext,\n * counter: oldContext.counter + 1\n * }))\n * ```\n */\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setterOrContext:\n | ((context: SharedContextValues) => SharedContextValues)\n | SharedContextValues\n ) {\n if (typeof setterOrContext === \"function\") {\n this.sharedContext = setterOrContext(this.sharedContext);\n } else {\n this.sharedContext = setterOrContext;\n }\n this.emit(\"contextchange\", {\n host: this,\n context: this.sharedContext,\n });\n }\n /**\n * Load extension into host application from provided extension description.\n * Returned promise resolves when all extensions are loaded and registered.\n *\n * @param extensions - List of extension descriptors. Normally, the Host should receive this value from an {@link ExtensionsProvider}.\n * @param options - Custom options to be used as defaults for each {@link Port} object created for each guest.\n * @returns Promise which resolves when all guests have been loaded.\n */\n async load(\n extensions: InstalledExtensions,\n options?: PortOptions\n ): Promise<void> {\n this.runtimeContainer =\n this.runtimeContainer || this.createRuntimeContainer(window);\n const failed: GuestConnection[] = [];\n const loaded: GuestConnection[] = [];\n this.loading = true;\n await Promise.all(\n Object.entries(extensions).map(async ([id, url]) => {\n const port = await this.loadOneGuest(id, url, options);\n (port.error ? failed : loaded).push(port);\n })\n );\n this.loading = false;\n this.emit(\"loadallguests\", { host: this, failed, loaded });\n }\n /**\n * Unload all extensions and remove their frames/workers. Use this to unmount\n * a UI or when switching to a different extensible UI.\n */\n async unload(): Promise<void> {\n this.emit(\"beforeunload\", { host: this });\n await Promise.all([...this.guests.values()].map((guest) => guest.unload()));\n this.guests.clear();\n this.runtimeContainer.parentElement.removeChild(this.runtimeContainer);\n this.emit(\"unload\", { host: this });\n }\n private createRuntimeContainer(window: Window) {\n const { document } = window;\n const container = document.createElement(\"div\");\n container.setAttribute(\"data-uix-guest-container\", this.hostName);\n Object.assign(container.style, Host.containerStyle);\n document.body.appendChild(container);\n return container;\n }\n private async loadOneGuest(\n id: string,\n urlString: string,\n options: PortOptions = {}\n ): Promise<GuestConnection> {\n let guest = this.guests.get(id);\n if (!guest) {\n const url = new URL(urlString);\n guest = new Port({\n owner: this.hostName,\n id,\n url,\n runtimeContainer: this.runtimeContainer,\n options: {\n ...this.guestOptions,\n ...options,\n },\n debugLogger: this.debugLogger,\n sharedContext: this.sharedContext,\n events: this as Emits,\n });\n this.guests.set(id, guest);\n }\n this.emit(\"guestbeforeload\", { guest, host: this });\n try {\n await guest.load();\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n this.emit(\"error\", { host: this, guest, error });\n console.warn(\"Failed to load extension at endpoint %s\", guest.url);\n return guest;\n }\n // this new guest might have new capabilities, so the identities of the\n // cached capability sets will need to change, to alert subscribers\n this.cachedCapabilityLists = new WeakMap();\n this.emit(\"guestload\", { guest, host: this });\n return guest;\n }\n private getLoadedGuestsWith<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ) {\n if (this.cachedCapabilityLists.has(capabilities)) {\n return this.cachedCapabilityLists.get(capabilities);\n }\n const guestsWithCapabilities = this.getLoadedGuests((guest) =>\n guest.hasCapabilities(capabilities)\n );\n this.cachedCapabilityLists.set(capabilities, guestsWithCapabilities);\n return guestsWithCapabilities;\n }\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Emits,\n GuestConnection,\n HostMethodAddress,\n NamedEvent,\n RemoteHostApis,\n GuestApis,\n Unsubscriber,\n} from \"@adobe/uix-core\";\nimport { Emitter } from \"@adobe/uix-core\";\nimport { Connection, connectToChild, Methods } from \"penpal\";\n\n/**\n * A specifier for methods to be expected on a remote interface.\n *\n * @remarks\n * A CapabilitySpec is a description of an interface, like a very simplified\n * type definition. It specifies an object structure and the paths in that\n * structure that must be functions. (It doesn't specify anything about the\n * signatures or return values of those functions.)\n *\n * Use CapabilitySpec objects as queries, or filters, to get a subset of\n * installed extensions which have registered methods which match the spec.\n *\n * @example\n * As an extensible app developer, you are making an extension point for spell\n * check. Your code expects extensions to register an API `spellCheck` with\n * methods called `spellCheck.correct(text)` and `spellCheck.suggest(text)`.\n *\n * ```javascript\n * async function correctText(text) {\n * const spellCheckers = host.getLoadedGuests({\n * spellCheck: [\n * 'correct',\n * 'suggest'\n * ]\n * });\n * let correcting = text;\n * for (const checker of spellCheckers) {\n * correcting = await checker.apis.spellCheck.correct(correcting);\n * }\n * return Promise.all(checkers.map(checker =>\n * checker.apis.spellCheck.suggest(correcting)\n * ));\n * }\n * ```\n *\n * @public\n */\nexport type CapabilitySpec<T extends GuestApis> = {\n [Name in keyof T]: (keyof T[Name])[];\n};\n\n/**\n * Interface for decoupling of guest Penpal object\n * @internal\n */\ninterface GuestProxyWrapper {\n /**\n * Methods from guest\n */\n apis: RemoteHostApis;\n /**\n * Emit an event in the guest frame\n */\n emit(type: string, detail: unknown): Promise<void>;\n}\n\n/** @public */\ntype PortEvent<\n GuestApi,\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<\n Type,\n Detail &\n Record<string, unknown> & {\n guestPort: Port<GuestApi>;\n }\n>;\n\n/** @public */\nexport type PortEvents<\n GuestApi,\n HostApi extends Record<string, unknown> = Record<string, unknown>\n> =\n | PortEvent<GuestApi, \"hostprovide\">\n | PortEvent<GuestApi, \"unload\">\n | PortEvent<GuestApi, \"beforecallhostmethod\", HostMethodAddress<HostApi>>;\n\n/** @public */\nexport type PortOptions = {\n /**\n * Time in milliseconds to wait for the guest to connect before throwing.\n */\n timeout?: number;\n /**\n * Set true to log copiously in the console.\n */\n debug?: boolean;\n};\n\nconst defaultOptions = {\n timeout: 10000,\n debug: false,\n};\n\n/**\n * A Port is the Host-maintained object representing an extension running as a\n * guest. It exposes methods registered by the Guest, and can provide Host\n * methods back to the guest.\n *\n * @remarks\n * When the Host object loads extensions via {@link Host.load}, it creates a\n * Port object for each extension. When retrieving and filtering extensions\n * via {@link Host.(getLoadedGuests:2)}, a list of Port objects is returned. From\n * the point of view of the extensible app using the Host object, extensions\n * are always Port objects, which expose the methods registered by the\n * extension at the {@link Port.apis} property.\n *\n * @privateRemarks\n * We've gone through several possible names for this object. GuestProxy,\n * GuestInterface, GuestConnection, etc. \"Port\" is not ideal, but it conflicted\n * the least with other types we defined in early drafts. It's definitely\n * something we should review.\n * @public\n */\nexport class Port<GuestApi>\n extends Emitter<PortEvents<GuestApi>>\n implements GuestConnection\n{\n // #region Properties (15)\n\n private connection: Connection<RemoteHostApis<GuestApi>>;\n private debug: boolean;\n private debugLogger?: Console;\n private frame: HTMLIFrameElement;\n private guest: GuestProxyWrapper;\n private hostApis: RemoteHostApis = {};\n private isLoaded = false;\n private runtimeContainer: HTMLElement;\n private sharedContext: Record<string, unknown>;\n private subscriptions: Unsubscriber[] = [];\n private timeout: number;\n\n /**\n * Dictionary of namespaced methods that were registered by this guest at the\n * time of connection, using {@link @adobe/uix-guest#register}.\n *\n * @remarks\n * These methods are proxy methods; you can only pass serializable objects to\n * them, not class instances, methods or callbacks.\n * @public\n */\n public apis: RemoteHostApis;\n /**\n * If any errors occurred during the loading of guests, this property will\n * contain the error that was raised.\n * @public\n */\n error?: Error;\n private uiConnections: Map<string, Connection<RemoteHostApis<GuestApi>>> =\n new Map();\n /**\n * The URL of the guest provided by the extension registry. The Host will\n * load this URL in the background, in the invisible the bootstrap frame, so\n * this URL must point to a page that calls {@link @adobe/uix-guest#register}\n * when it loads.\n */\n url: URL;\n\n // #endregion Properties (15)\n\n // #region Constructors (1)\n\n constructor(config: {\n owner: string;\n id: string;\n url: URL;\n /**\n * An alternate DOM element to use for invisible iframes. Will create its\n * own if this option is not populated with a DOM element.\n */\n runtimeContainer: HTMLElement;\n options: PortOptions;\n debugLogger?: Console;\n /**\n * Initial object to populate the shared context with. Once the guest\n * connects, it will be able to access these properties.\n */\n sharedContext: Record<string, unknown>;\n events: Emits;\n }) {\n super(config.id);\n const { timeout, debug } = { ...defaultOptions, ...(config.options || {}) };\n this.timeout = timeout;\n this.debug = debug;\n this.id = config.id;\n this.url = config.url;\n this.runtimeContainer = config.runtimeContainer;\n this.sharedContext = config.sharedContext;\n this.subscriptions.push(\n config.events.addEventListener(\"contextchange\", async (event) => {\n this.sharedContext = (\n (event as CustomEvent).detail as unknown as Record<string, unknown>\n ).context as Record<string, unknown>;\n await this.connect();\n await this.guest.emit(\"contextchange\", { context: this.sharedContext });\n })\n );\n }\n\n // #endregion Constructors (1)\n\n // #region Public Methods (6)\n\n /**\n * Connect an iframe element which is displaying another page in the extension\n * with the extension's bootstrap frame, so they can share context and events.\n */\n public attachUI(iframe: HTMLIFrameElement) {\n const uniqueId = Math.random().toString(36);\n const uiConnection = this.attachFrame(iframe);\n this.uiConnections.set(uniqueId, uiConnection);\n return uiConnection;\n }\n\n /**\n * Returns true if the guest has registered methods matching the provided\n * capability spec. A capability spec is simply an object whose properties are\n * declared in an array of keys, description the names of the functions and\n * methods that the Port will expose.\n */\n public hasCapabilities(requiredMethods: CapabilitySpec<GuestApis>) {\n this.assertReady();\n return Object.keys(requiredMethods).every((key) => {\n if (!Reflect.has(this.apis, key)) {\n return false;\n }\n const api = this.apis[key];\n const methodList = requiredMethods[\n key as keyof typeof requiredMethods\n ] as string[];\n return methodList.every(\n (methodName: string) =>\n Reflect.has(api, methodName) &&\n typeof api[methodName as keyof typeof api] === \"function\"\n );\n });\n }\n\n /**\n * True when al extensions have loaded.\n */\n public isReady(): boolean {\n return this.isLoaded && !this.error;\n }\n\n /**\n * Loads the extension. Returns a promise which resolves when the extension\n * has loaded. The Host calls this method after retrieving extensions.\n */\n public async load() {\n try {\n if (!this.apis) {\n await this.connect();\n }\n return this.apis;\n } catch (e) {\n this.apis = null;\n this.guest = null;\n this.error = e instanceof Error ? e : new Error(String(e));\n throw e;\n }\n }\n\n /**\n * The host-side equivalent of {@link @adobe/uix-guest#register}. Pass a set\n * of methods down to the guest as proxies.\n */\n public provide(apis: RemoteHostApis) {\n Object.assign(this.hostApis, apis);\n this.emit(\"hostprovide\", { guestPort: this, apis });\n }\n\n /**\n * Disconnect from the extension.\n */\n public async unload(): Promise<void> {\n if (this.connection) {\n await this.connection.destroy();\n }\n for (const connection of this.uiConnections.values()) {\n await connection.destroy();\n }\n if (this.frame && this.frame.parentElement) {\n this.frame.parentElement.removeChild(this.frame);\n this.frame = undefined;\n }\n this.emit(\"unload\", { guestPort: this });\n }\n\n // #endregion Public Methods (6)\n\n // #region Private Methods (6)\n\n private assert(\n condition: boolean,\n errorMessage: () => string\n ): asserts condition {\n if (!condition) {\n throw new Error(\n `Error in guest extension \"${this.id}\": ${errorMessage()}`\n );\n }\n }\n\n private assertReady() {\n this.assert(this.isReady(), () => \"Attempted to interact before loaded\");\n }\n\n private attachFrame(iframe: HTMLIFrameElement) {\n return connectToChild<RemoteHostApis<GuestApi>>({\n iframe,\n debug: this.debug,\n childOrigin: this.url.origin,\n timeout: this.timeout,\n methods: {\n getSharedContext: () => this.sharedContext,\n invokeHostMethod: (address: HostMethodAddress) =>\n this.invokeHostMethod(address),\n },\n });\n }\n\n private async connect() {\n this.frame = this.runtimeContainer.ownerDocument.createElement(\"iframe\");\n this.frame.setAttribute(\"src\", this.url.href);\n this.frame.setAttribute(\"data-uix-guest\", \"true\");\n this.runtimeContainer.appendChild(this.frame);\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} attached iframe of ${this.url.href}`,\n this\n );\n }\n this.connection = this.attachFrame(this.frame);\n this.guest = (await this.connection\n .promise) as unknown as GuestProxyWrapper;\n this.apis = this.guest.apis || {};\n this.isLoaded = true;\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} established connection, received methods`,\n this.apis,\n this\n );\n }\n }\n\n private getHostMethodCallee<T = unknown>(\n { name, path }: HostMethodAddress,\n methodSource: RemoteHostApis\n ): Methods {\n const dots = (level: number) =>\n `uix.host.${path.slice(0, level).join(\".\")}`;\n const methodCallee = path.reduce((current, prop, level) => {\n this.assert(\n Reflect.has(current, prop),\n () => `${dots(level)} has no property \"${prop}\"`\n );\n const next = current[prop];\n this.assert(\n typeof next === \"object\",\n () =>\n `${dots(\n level\n )}.${prop} is not an object; namespaces must be objects with methods`\n );\n return next as RemoteHostApis<GuestApi>;\n }, methodSource);\n this.assert(\n typeof methodCallee[name] === \"function\" &&\n Reflect.has(methodCallee, name),\n () => `\"${dots(path.length - 1)}.${name}\" is not a function`\n );\n return methodCallee;\n }\n\n private invokeHostMethod<T = unknown>(\n address: HostMethodAddress,\n privateMethods?: RemoteHostApis\n ): T {\n const { name, path, args = [] } = address;\n this.assert(name && typeof name === \"string\", () => \"Method name required\");\n this.assert(\n path.length > 0,\n () =>\n `Cannot call a method directly on the host; \".${name}()\" must be in a namespace.`\n );\n let methodCallee;\n if (privateMethods) {\n try {\n methodCallee = this.getHostMethodCallee(address, privateMethods);\n } catch (e) {\n this.debugLogger.warn(\"Private method not found!\", address);\n }\n }\n if (!methodCallee) {\n methodCallee = this.getHostMethodCallee(address, this.hostApis);\n }\n const method = methodCallee[name] as (...args: unknown[]) => T;\n this.emit(\"beforecallhostmethod\", { guestPort: this, name, path, args });\n return method.apply(methodCallee, [\n { id: this.id, url: this.url },\n ...args,\n ]) as T;\n }\n\n // #endregion Private Methods (6)\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/**\n * Adapter to attach console logging listeners to a Host running in an app\n * @hidden\n */\nimport {\n debugEmitter,\n EmitterDebugLogger,\n Emits,\n GuestConnection,\n} from \"@adobe/uix-core\";\nimport type { PortEvents } from \"./port.js\";\nimport type { HostEventLoadAllGuests, HostEvents } from \"./host.js\";\n\ntype GenericPortEvents = PortEvents<Record<string, unknown>>;\n\ntype Portlike = GuestConnection & Emits<GenericPortEvents>;\n\nexport function debugHost(host: Emits<HostEvents>): EmitterDebugLogger {\n const hostLogger = debugEmitter(host, {\n theme: \"blue medium\",\n type: \"Host\",\n });\n hostLogger\n .listen(\"guestbeforeload\", (log, event) => {\n const { detail } = event;\n const guest = detail.guest as Portlike;\n log.info(event, `Guest ID ${guest.id}`);\n const portLogger = debugEmitter(guest, {\n theme: \"green medium\",\n type: \"Port\",\n id: `${host.id} ➔ ${guest.id}`,\n });\n portLogger\n .listen(\"hostprovide\", (log, event) => {\n log.info(\"received APIs\", event.detail.apis);\n })\n .listen(\"beforecallhostmethod\", (log, event) => {\n log.info(event.detail);\n })\n .listen(\"unload\", (log, event) => {\n log.info(event.detail);\n log.detach();\n });\n })\n .listen(\"guestload\", (log, e) => {\n log.info(e.detail.guest.id, e.detail.guest);\n })\n .listen(\"error\", (log, e) => {\n log.error(`Error: ${e.detail.error.message}`, e);\n })\n .listen(\n \"loadallguests\",\n (log, { detail: { failed, loaded, host } }: HostEventLoadAllGuests) => {\n if (failed.length > 0) {\n log.error(\"%d guests failed to load!\", failed.length);\n }\n log.info(\"%d guests loaded\", loaded.length, host);\n }\n )\n .listen(\"unload\", (log) => {\n log.info(\"Unloaded guest and container.\");\n log.detach();\n });\n return hostLogger;\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\ninterface ExtensionDefinition {\n name: string;\n title: string;\n description: string;\n icon: string;\n publisher: string;\n endpoints: Record<string, EndpointDefinition>;\n xrInfo: ExtensionInfo;\n status: string;\n}\n\ntype EndpointDefinition = Record<string, Array<OperationDefinition>>;\n\ninterface ExtensionInfo {\n supportEmail: string;\n appId: string;\n}\n\ninterface OperationDefinition {\n href: string;\n metadata: OperationMetadata;\n}\n\ninterface OperationMetadata {\n services: Array<object>;\n profile: OperationProfile;\n}\n\ninterface OperationProfile {\n client_id: string;\n scope: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryEndpointRegistration {\n service: string;\n extensionPoint: string;\n version: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryExtensionRegistration\n extends ExtensionRegistryEndpointRegistration {\n imsOrg: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryConnection {\n baseUrl?: string;\n apiKey: string;\n auth: {\n schema: \"Basic\" | \"Bearer\";\n imsToken: string;\n };\n}\n\n/** @public */\nexport interface ExtensionRegistryConfig\n extends ExtensionRegistryExtensionRegistration,\n ExtensionRegistryConnection {}\n\nfunction buildEndpointPath(\n config: ExtensionRegistryEndpointRegistration\n): string {\n return `${config.service}/${config.extensionPoint}/${config.version}`;\n}\n\nfunction ensureProtocolSpecified(url: string) {\n if (url.startsWith(\"https://\")) {\n return url;\n }\n if (url.startsWith(\"http://\")) {\n return url;\n }\n return `https://${url}`;\n}\n\nasync function fetchExtensionsFromRegistry(\n config: ExtensionRegistryConfig\n): Promise<Array<ExtensionDefinition>> {\n const resp = await fetch(\n `${ensureProtocolSpecified(\n config.baseUrl || \"appregistry.adobe.io\"\n )}/myxchng/v1/org/${encodeURIComponent(\n config.imsOrg\n )}/xtn/${buildEndpointPath(config)}?auth=true`,\n {\n headers: {\n Accept: \"application/json\",\n Authorization: `${config.auth.schema} ${config.auth.imsToken}`, // todo: check if auth schema needed (initial implementation was without it)\n \"X-Api-Key\": config.apiKey,\n },\n }\n );\n\n if (resp.status != 200) {\n throw new Error(\n `extension registry returned non-200 response (${\n resp.status\n }): ${await resp.text()}`\n );\n }\n\n return await resp.json();\n}\n\nfunction extensionRegistryExtensionsProvider(\n config: ExtensionRegistryConfig\n): Promise<InstalledExtensions> {\n const erEndpoint = buildEndpointPath(config);\n return fetchExtensionsFromRegistry(config).then((out) =>\n out.reduce((a, e: ExtensionDefinition) => {\n if (e.status !== \"PUBLISHED\") {\n return a;\n }\n\n return {\n ...a,\n // todo: make safer way to extract href\n [e.name]: e.endpoints[erEndpoint].view[0].href,\n };\n }, {})\n );\n\n return Promise.resolve({});\n}\n\n/**\n * Create a callback that fetches extensions from the registry.\n * @public\n */\nexport function createExtensionRegistryProvider(\n config: ExtensionRegistryConfig\n): ExtensionsProvider {\n return function () {\n return extensionRegistryExtensionsProvider(config);\n };\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\n/**\n * Combine multiple {@link @adobe/uix-host#ExtensionsProvider} callbacks into a\n * single callback, which aggregates and dedupes all extensions from all\n * providers into one namespaced object.\n * @public\n */\nexport function combineExtensionsFromProviders(\n ...providers: Array<ExtensionsProvider>\n): ExtensionsProvider {\n return () =>\n Promise.all(providers.map((ep: ExtensionsProvider) => ep())).then(\n (extensionsBatches: Array<InstalledExtensions>) => {\n return Object.assign({}, ...extensionsBatches);\n }\n );\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ExtensionsProvider } from \"../host.js\";\n\n/**\n * Mute any errors produced by provider.\n * This function would execute given provider and return its results as is, if any error occurs this provider will log it\n * any return an empty array of extensions.\n * @public\n */\nexport function mutedProvider(\n provider: ExtensionsProvider\n): ExtensionsProvider {\n return async () => {\n try {\n return await provider();\n } catch (error) {\n console.error(`Extension provider has failed: ${error.message}`, {\n error,\n });\n return {};\n }\n };\n}\n"]}
@@ -1,3 +1,4 @@
1
1
  export * from "./extension-registry.js";
2
2
  export * from "./composition.js";
3
+ export * from "./mute.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions-provider/index.ts"],"names":[],"mappings":"AAYA,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/extensions-provider/index.ts"],"names":[],"mappings":"AAYA,cAAc,yBAAyB,CAAC;AACxC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ExtensionsProvider } from "../host.js";
2
+ /**
3
+ * Mute any errors produced by provider.
4
+ * This function would execute given provider and return its results as is, if any error occurs this provider will log it
5
+ * any return an empty array of extensions.
6
+ * @public
7
+ */
8
+ export declare function mutedProvider(provider: ExtensionsProvider): ExtensionsProvider;
9
+ //# sourceMappingURL=mute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mute.d.ts","sourceRoot":"","sources":["../../src/extensions-provider/mute.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,kBAAkB,GAC3B,kBAAkB,CAWpB"}
package/dist/index.js CHANGED
@@ -161,9 +161,12 @@ var Port = class extends uixCore.Emitter {
161
161
  try {
162
162
  methodCallee = this.getHostMethodCallee(address, privateMethods);
163
163
  } catch (e) {
164
- methodCallee = this.getHostMethodCallee(address, this.hostApis);
164
+ this.debugLogger.warn("Private method not found!", address);
165
165
  }
166
166
  }
167
+ if (!methodCallee) {
168
+ methodCallee = this.getHostMethodCallee(address, this.hostApis);
169
+ }
167
170
  const method = methodCallee[name];
168
171
  this.emit("beforecallhostmethod", { guestPort: this, name, path, args });
169
172
  return method.apply(methodCallee, [
@@ -405,9 +408,24 @@ function combineExtensionsFromProviders(...providers) {
405
408
  );
406
409
  }
407
410
 
411
+ // src/extensions-provider/mute.ts
412
+ function mutedProvider(provider) {
413
+ return async () => {
414
+ try {
415
+ return await provider();
416
+ } catch (error) {
417
+ console.error(`Extension provider has failed: ${error.message}`, {
418
+ error
419
+ });
420
+ return {};
421
+ }
422
+ };
423
+ }
424
+
408
425
  exports.Host = Host;
409
426
  exports.Port = Port;
410
427
  exports.combineExtensionsFromProviders = combineExtensionsFromProviders;
411
428
  exports.createExtensionRegistryProvider = createExtensionRegistryProvider;
429
+ exports.mutedProvider = mutedProvider;
412
430
  //# sourceMappingURL=out.js.map
413
431
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/host.ts","../src/port.ts","../src/debug-host.ts","../src/extensions-provider/extension-registry.ts","../src/extensions-provider/composition.ts"],"names":["Emitter","log","event","host","window"],"mappings":";AAoBA,SAAS,WAAAA,UAAS,oBAAoB;;;ACCtC,SAAS,eAAe;AACxB,SAAqB,sBAA+B;AA4FpD,IAAM,iBAAiB;AAAA,EACrB,SAAS;AAAA,EACT,OAAO;AACT;AAsBO,IAAM,OAAN,cACG,QAEV;AAAA,EA6CE,YAAY,QAiBT;AACD,UAAM,OAAO,EAAE;AAvDjB,SAAQ,WAA2B,CAAC;AACpC,SAAQ,WAAW;AAGnB,SAAQ,gBAAgC,CAAC;AAmBzC,SAAQ,gBACN,oBAAI,IAAI;AAgCR,UAAM,EAAE,SAAS,MAAM,IAAI,EAAE,GAAG,gBAAgB,GAAI,OAAO,WAAW,CAAC,EAAG;AAC1E,SAAK,UAAU;AACf,SAAK,QAAQ;AACb,SAAK,KAAK,OAAO;AACjB,SAAK,MAAM,OAAO;AAClB,SAAK,mBAAmB,OAAO;AAC/B,SAAK,gBAAgB,OAAO;AAC5B,SAAK,cAAc;AAAA,MACjB,OAAO,OAAO,iBAAiB,iBAAiB,OAAO,UAAU;AAC/D,aAAK,gBACF,MAAsB,OACvB;AACF,cAAM,KAAK,QAAQ;AACnB,cAAM,KAAK,MAAM,KAAK,iBAAiB,EAAE,SAAS,KAAK,cAAc,CAAC;AAAA,MACxE,CAAC;AAAA,IACH;AAAA,EACF;AAAA,EAUO,SAAS,QAA2B;AACzC,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ensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Extension,\n GuestConnection,\n NamedEvent,\n Emits,\n GuestApis,\n} from \"@adobe/uix-core\";\nimport type { CapabilitySpec } from \"./port.js\";\nimport { Emitter, quietConsole } from \"@adobe/uix-core\";\nimport { Port, PortOptions } from \"./port.js\";\nimport { debugHost } from \"./debug-host.js\";\n\n/**\n * Dictionary of {@link Port} objects by extension ID.\n * @public\n */\nexport type PortMap = Map<string, GuestConnection>;\n\n/** @public */\nexport type HostEvent<\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<Type, Detail & Record<string, unknown> & { host: Host }>;\n/** @public */\ntype HostGuestEvent<Type extends string> = HostEvent<\n `guest${Type}`,\n { guest: GuestConnection }\n>;\n\n/**\n * All guests requested by host have been loaded and connected.\n * @public\n */\nexport type HostEventLoadAllGuests = HostEvent<\n \"loadallguests\",\n { failed: GuestConnection[]; loaded: GuestConnection[] }\n>;\n\n/**\n * Shared context has been set or updated; all guests receive this event too.\n * @public\n */\n\nexport type HostEventContextChange = HostEvent<\n \"contextchange\",\n { context: SharedContextValues }\n>;\n\n/**\n * An error has occurred during loading or unloading of guests.\n * @public\n */\nexport type HostEventError = HostEvent<\"error\", { error: Error }>;\n\n/** @public */\nexport type HostEvents =\n | HostGuestEvent<\"beforeload\">\n | HostGuestEvent<\"load\">\n | HostEvent<\"beforeunload\">\n | HostEvent<\"unload\">\n | HostEventLoadAllGuests\n | HostEventContextChange\n | HostEventError;\n\n/** @public */\nexport type InstalledExtensions = Record<Extension[\"id\"], Extension[\"url\"]>;\n/** @public */\nexport type ExtensionsProvider = () => Promise<InstalledExtensions>;\n\n/**\n * Values for shared context. Must be a plain object, serializable to JSON.\n * @public\n */\nexport type SharedContextValues = Record<string, unknown>;\n\n/** @public */\nexport interface HostConfig {\n /**\n * Human-readable \"slug\" name of the extensible area--often an entire app.\n * This string serves as a namespace for extension points within the area.\n */\n hostName: string;\n /**\n * A DOM element _outside_ of the React root. This is necessary to preserve\n * the lifetime of the iframes which are running extension objects; if they\n * live inside the React root, then React could unexpectedly re-render the\n * iframe tags themselves at any time, causing a reload of the frame.\n */\n runtimeContainer?: HTMLElement;\n /**\n * Copiously log lifecycle events.\n */\n debug?: boolean;\n /**\n * Default options to use for every guest Port.\n *\n * If `config.debug` is true, then the guest options will have `debug: true`\n * unless `debug: false` is explicitly passed in `guestOptions`.\n */\n guestOptions?: PortOptions;\n /**\n * A read-only dictionary of values that the host will supply to all the\n * guests.\n */\n sharedContext?: SharedContextValues;\n}\n\n/**\n * Callback to use to filter the list returned from {@link Host.(getLoadedGuests:2)}\n * @public\n */\ntype GuestFilter = (item: GuestConnection) => boolean;\n\nconst passAllGuests = () => true;\n\n/**\n * Manager object for connecting to {@link @adobe/uix-guest#GuestServer |\n * GuestServers} and {@link @adobe/uix-guest#GuestUI | GuestUIs}, providing and\n * receiving their APIs, and providing them to the app for interacting with UI.\n *\n * @remarks\n * The Host object is the main connection manager for all UIX Guests.\n * Making an app extensible requires creating a Host object.\n *\n * The extensible app using the Hostis responsible for providing a list of\n * extension references to the Host object. Use {@link\n * createExtensionRegistryProvider} for that purpose. Once you have retrieved a\n * list of extensions available to the host app, pass it to {@link Host.load}.\n *\n * When a Host creates a Guest, it must create an `<iframe>` element to contain\n * the Guest's main {@link @adobe/uix-guest#GuestServer} runtime, which runs\n * invisibly in the background. To do this, the Host creates a hidden container\n * in the body of the document. It is a `<div>` element with the attribute\n * `data-uix-guest-container`. Loaded GuestServers will be injected into this\n * hidden element and removed as necessary. When {@link Host.unload} is called,\n * the Host removes the hidden container from the document after unloading.\n *\n * @public\n */\nexport class Host extends Emitter<HostEvents> {\n /**\n * {@inheritDoc HostEventLoadAllGuests}\n * @eventProperty\n */\n public loadallguests: HostEventLoadAllGuests;\n\n /**\n * One guest has loaded.\n * @eventProperty\n */\n public guestload: HostGuestEvent<\"load\">;\n\n /**\n * About to attempt to load and connect to a Guest.\n * @eventProperty\n */\n public guestbeforeload: HostGuestEvent<\"beforeload\">;\n\n /**\n * About to unload a guest and remove its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestbeforeunload: HostGuestEvent<\"beforeunload\">;\n\n /**\n * Unloaded a guest and removed its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestunload: HostGuestEvent<\"unload\">;\n\n /**\n * {@inheritDoc HostEventContextChange}\n * @eventProperty\n */\n public contextchange: HostEventContextChange;\n\n /**\n * {@inheritDoc HostEventError}\n * @eventProperty\n */\n public error: HostEventError;\n\n private static containerStyle = {\n position: \"fixed\",\n width: \"1px\",\n height: \"1px\",\n pointerEvents: \"none\",\n opacity: 0,\n top: 0,\n left: \"-1px\",\n };\n /**\n * Unique string identifying the Host object.\n */\n hostName: string;\n /**\n * `true` if any extension in {@link Host.guests} has created a {@link\n * @adobe/uix-guest#GuestServer}, but the Guest has not yet loaded.\n */\n loading = false;\n /**\n * A Map of of the loaded guests.\n */\n guests: PortMap = new Map();\n private cachedCapabilityLists: WeakMap<object, GuestConnection[]> =\n new WeakMap();\n private runtimeContainer: HTMLElement;\n private guestOptions: PortOptions;\n private debugLogger: Console = quietConsole;\n private sharedContext: SharedContextValues;\n constructor(config: HostConfig) {\n super(config.hostName);\n const { guestOptions = {} } = config;\n this.guestOptions = {\n ...guestOptions,\n debug: guestOptions.debug === false ? false : !!config.debug,\n };\n this.hostName = config.hostName;\n this.sharedContext = config.sharedContext || {};\n this.runtimeContainer = config.runtimeContainer;\n if (config.debug) {\n this.debugLogger = debugHost(this);\n }\n }\n /**\n * Return all loaded guests.\n */\n getLoadedGuests(): GuestConnection[];\n /**\n * Return loaded guests which satisfy the passed test function.\n */\n getLoadedGuests(filter: GuestFilter): GuestConnection[];\n /**\n * Return loaded guests which expose the provided {@link CapabilitySpec}.\n */\n getLoadedGuests<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ): GuestConnection[];\n getLoadedGuests<Apis extends GuestApis = never>(\n filterOrCapabilities?: CapabilitySpec<Apis> | GuestFilter\n ): GuestConnection[] {\n if (typeof filterOrCapabilities === \"object\") {\n return this.getLoadedGuestsWith<Apis>(filterOrCapabilities);\n }\n const filter = filterOrCapabilities || passAllGuests;\n const result = [];\n for (const guest of this.guests.values()) {\n if (guest.isReady() && filter(guest)) {\n result.push(guest);\n }\n }\n return result;\n }\n /**\n * Set the object of shared values that all Guests can access via {@link @adobe/uix-guest#GuestServer.sharedContext}.\n * This overwrites any previous object.\n *\n * @example Exposes `authToken` to all Guests. Guests can call `this.sharedContext.get('authToken')` to retrieve this value.\n * ```javascript\n * host.shareContext({\n * authToken: '82ba19b'\n * });\n * ```\n *\n * @example Overwrites the previous sharedContext, deleting `authToken` and providing `secret` and `auth` instead.\n * ```javascript\n * host.shareContext({\n * secret: 'squirrel',\n * auth: false\n * });\n * ```\n */\n shareContext(context: SharedContextValues): void;\n /**\n * Update the object of shared values that all Guests can access via {@link\n * @adobe/uix-guest#GuestServer.sharedContext}. This method takes a callback\n * which receives the previous context and may return an entirely new context,\n * or new values merged with the old context.\n *\n * @remarks This callback pattern allows the shared context values to be\n * mutable while the internal context object references are immutable, which\n * is important for synchronizing. with guests.\n *\n * @example Overwrites a context object based on the previous one.\n * ```javascript\n * host.shareContext(oldContext => ({\n * counter: oldContext.counter + 1\n * }))\n * ```\n *\n * @example Updates a context while preserving other existing values.\n * ```javascript\n * host.shareContext(oldContext => ({\n * ...oldContext,\n * counter: oldContext.counter + 1\n * }))\n * ```\n */\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setterOrContext:\n | ((context: SharedContextValues) => SharedContextValues)\n | SharedContextValues\n ) {\n if (typeof setterOrContext === \"function\") {\n this.sharedContext = setterOrContext(this.sharedContext);\n } else {\n this.sharedContext = setterOrContext;\n }\n this.emit(\"contextchange\", {\n host: this,\n context: this.sharedContext,\n });\n }\n /**\n * Load extension into host application from provided extension description.\n * Returned promise resolves when all extensions are loaded and registered.\n *\n * @param extensions - List of extension descriptors. Normally, the Host should receive this value from an {@link ExtensionsProvider}.\n * @param options - Custom options to be used as defaults for each {@link Port} object created for each guest.\n * @returns Promise which resolves when all guests have been loaded.\n */\n async load(\n extensions: InstalledExtensions,\n options?: PortOptions\n ): Promise<void> {\n this.runtimeContainer =\n this.runtimeContainer || this.createRuntimeContainer(window);\n const failed: GuestConnection[] = [];\n const loaded: GuestConnection[] = [];\n this.loading = true;\n await Promise.all(\n Object.entries(extensions).map(async ([id, url]) => {\n const port = await this.loadOneGuest(id, url, options);\n (port.error ? failed : loaded).push(port);\n })\n );\n this.loading = false;\n this.emit(\"loadallguests\", { host: this, failed, loaded });\n }\n /**\n * Unload all extensions and remove their frames/workers. Use this to unmount\n * a UI or when switching to a different extensible UI.\n */\n async unload(): Promise<void> {\n this.emit(\"beforeunload\", { host: this });\n await Promise.all([...this.guests.values()].map((guest) => guest.unload()));\n this.guests.clear();\n this.runtimeContainer.parentElement.removeChild(this.runtimeContainer);\n this.emit(\"unload\", { host: this });\n }\n private createRuntimeContainer(window: Window) {\n const { document } = window;\n const container = document.createElement(\"div\");\n container.setAttribute(\"data-uix-guest-container\", this.hostName);\n Object.assign(container.style, Host.containerStyle);\n document.body.appendChild(container);\n return container;\n }\n private async loadOneGuest(\n id: string,\n urlString: string,\n options: PortOptions = {}\n ): Promise<GuestConnection> {\n let guest = this.guests.get(id);\n if (!guest) {\n const url = new URL(urlString);\n guest = new Port({\n owner: this.hostName,\n id,\n url,\n runtimeContainer: this.runtimeContainer,\n options: {\n ...this.guestOptions,\n ...options,\n },\n debugLogger: this.debugLogger,\n sharedContext: this.sharedContext,\n events: this as Emits,\n });\n this.guests.set(id, guest);\n }\n this.emit(\"guestbeforeload\", { guest, host: this });\n try {\n await guest.load();\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n this.emit(\"error\", { host: this, guest, error });\n console.warn(\"Failed to load extension at endpoint %s\", guest.url);\n return guest;\n }\n // this new guest might have new capabilities, so the identities of the\n // cached capability sets will need to change, to alert subscribers\n this.cachedCapabilityLists = new WeakMap();\n this.emit(\"guestload\", { guest, host: this });\n return guest;\n }\n private getLoadedGuestsWith<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ) {\n if (this.cachedCapabilityLists.has(capabilities)) {\n return this.cachedCapabilityLists.get(capabilities);\n }\n const guestsWithCapabilities = this.getLoadedGuests((guest) =>\n guest.hasCapabilities(capabilities)\n );\n this.cachedCapabilityLists.set(capabilities, guestsWithCapabilities);\n return guestsWithCapabilities;\n }\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Emits,\n GuestConnection,\n HostMethodAddress,\n NamedEvent,\n RemoteHostApis,\n GuestApis,\n Unsubscriber,\n} from \"@adobe/uix-core\";\nimport { Emitter } from \"@adobe/uix-core\";\nimport { Connection, connectToChild, Methods } from \"penpal\";\n\n/**\n * A specifier for methods to be expected on a remote interface.\n *\n * @remarks\n * A CapabilitySpec is a description of an interface, like a very simplified\n * type definition. It specifies an object structure and the paths in that\n * structure that must be functions. (It doesn't specify anything about the\n * signatures or return values of those functions.)\n *\n * Use CapabilitySpec objects as queries, or filters, to get a subset of\n * installed extensions which have registered methods which match the spec.\n *\n * @example\n * As an extensible app developer, you are making an extension point for spell\n * check. Your code expects extensions to register an API `spellCheck` with\n * methods called `spellCheck.correct(text)` and `spellCheck.suggest(text)`.\n *\n * ```javascript\n * async function correctText(text) {\n * const spellCheckers = host.getLoadedGuests({\n * spellCheck: [\n * 'correct',\n * 'suggest'\n * ]\n * });\n * let correcting = text;\n * for (const checker of spellCheckers) {\n * correcting = await checker.apis.spellCheck.correct(correcting);\n * }\n * return Promise.all(checkers.map(checker =>\n * checker.apis.spellCheck.suggest(correcting)\n * ));\n * }\n * ```\n *\n * @public\n */\nexport type CapabilitySpec<T extends GuestApis> = {\n [Name in keyof T]: (keyof T[Name])[];\n};\n\n/**\n * Interface for decoupling of guest Penpal object\n * @internal\n */\ninterface GuestProxyWrapper {\n /**\n * Methods from guest\n */\n apis: RemoteHostApis;\n /**\n * Emit an event in the guest frame\n */\n emit(type: string, detail: unknown): Promise<void>;\n}\n\n/** @public */\ntype PortEvent<\n GuestApi,\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<\n Type,\n Detail &\n Record<string, unknown> & {\n guestPort: Port<GuestApi>;\n }\n>;\n\n/** @public */\nexport type PortEvents<\n GuestApi,\n HostApi extends Record<string, unknown> = Record<string, unknown>\n> =\n | PortEvent<GuestApi, \"hostprovide\">\n | PortEvent<GuestApi, \"unload\">\n | PortEvent<GuestApi, \"beforecallhostmethod\", HostMethodAddress<HostApi>>;\n\n/** @public */\nexport type PortOptions = {\n /**\n * Time in milliseconds to wait for the guest to connect before throwing.\n */\n timeout?: number;\n /**\n * Set true to log copiously in the console.\n */\n debug?: boolean;\n};\n\nconst defaultOptions = {\n timeout: 10000,\n debug: false,\n};\n\n/**\n * A Port is the Host-maintained object representing an extension running as a\n * guest. It exposes methods registered by the Guest, and can provide Host\n * methods back to the guest.\n *\n * @remarks\n * When the Host object loads extensions via {@link Host.load}, it creates a\n * Port object for each extension. When retrieving and filtering extensions\n * via {@link Host.(getLoadedGuests:2)}, a list of Port objects is returned. From\n * the point of view of the extensible app using the Host object, extensions\n * are always Port objects, which expose the methods registered by the\n * extension at the {@link Port.apis} property.\n *\n * @privateRemarks\n * We've gone through several possible names for this object. GuestProxy,\n * GuestInterface, GuestConnection, etc. \"Port\" is not ideal, but it conflicted\n * the least with other types we defined in early drafts. It's definitely\n * something we should review.\n * @public\n */\nexport class Port<GuestApi>\n extends Emitter<PortEvents<GuestApi>>\n implements GuestConnection\n{\n // #region Properties (15)\n\n private connection: Connection<RemoteHostApis<GuestApi>>;\n private debug: boolean;\n private debugLogger?: Console;\n private frame: HTMLIFrameElement;\n private guest: GuestProxyWrapper;\n private hostApis: RemoteHostApis = {};\n private isLoaded = false;\n private runtimeContainer: HTMLElement;\n private sharedContext: Record<string, unknown>;\n private subscriptions: Unsubscriber[] = [];\n private timeout: number;\n\n /**\n * Dictionary of namespaced methods that were registered by this guest at the\n * time of connection, using {@link @adobe/uix-guest#register}.\n *\n * @remarks\n * These methods are proxy methods; you can only pass serializable objects to\n * them, not class instances, methods or callbacks.\n * @public\n */\n public apis: RemoteHostApis;\n /**\n * If any errors occurred during the loading of guests, this property will\n * contain the error that was raised.\n * @public\n */\n error?: Error;\n private uiConnections: Map<string, Connection<RemoteHostApis<GuestApi>>> =\n new Map();\n /**\n * The URL of the guest provided by the extension registry. The Host will\n * load this URL in the background, in the invisible the bootstrap frame, so\n * this URL must point to a page that calls {@link @adobe/uix-guest#register}\n * when it loads.\n */\n url: URL;\n\n // #endregion Properties (15)\n\n // #region Constructors (1)\n\n constructor(config: {\n owner: string;\n id: string;\n url: URL;\n /**\n * An alternate DOM element to use for invisible iframes. Will create its\n * own if this option is not populated with a DOM element.\n */\n runtimeContainer: HTMLElement;\n options: PortOptions;\n debugLogger?: Console;\n /**\n * Initial object to populate the shared context with. Once the guest\n * connects, it will be able to access these properties.\n */\n sharedContext: Record<string, unknown>;\n events: Emits;\n }) {\n super(config.id);\n const { timeout, debug } = { ...defaultOptions, ...(config.options || {}) };\n this.timeout = timeout;\n this.debug = debug;\n this.id = config.id;\n this.url = config.url;\n this.runtimeContainer = config.runtimeContainer;\n this.sharedContext = config.sharedContext;\n this.subscriptions.push(\n config.events.addEventListener(\"contextchange\", async (event) => {\n this.sharedContext = (\n (event as CustomEvent).detail as unknown as Record<string, unknown>\n ).context as Record<string, unknown>;\n await this.connect();\n await this.guest.emit(\"contextchange\", { context: this.sharedContext });\n })\n );\n }\n\n // #endregion Constructors (1)\n\n // #region Public Methods (6)\n\n /**\n * Connect an iframe element which is displaying another page in the extension\n * with the extension's bootstrap frame, so they can share context and events.\n */\n public attachUI(iframe: HTMLIFrameElement) {\n const uniqueId = Math.random().toString(36);\n const uiConnection = this.attachFrame(iframe);\n this.uiConnections.set(uniqueId, uiConnection);\n return uiConnection;\n }\n\n /**\n * Returns true if the guest has registered methods matching the provided\n * capability spec. A capability spec is simply an object whose properties are\n * declared in an array of keys, description the names of the functions and\n * methods that the Port will expose.\n */\n public hasCapabilities(requiredMethods: CapabilitySpec<GuestApis>) {\n this.assertReady();\n return Object.keys(requiredMethods).every((key) => {\n if (!Reflect.has(this.apis, key)) {\n return false;\n }\n const api = this.apis[key];\n const methodList = requiredMethods[\n key as keyof typeof requiredMethods\n ] as string[];\n return methodList.every(\n (methodName: string) =>\n Reflect.has(api, methodName) &&\n typeof api[methodName as keyof typeof api] === \"function\"\n );\n });\n }\n\n /**\n * True when al extensions have loaded.\n */\n public isReady(): boolean {\n return this.isLoaded && !this.error;\n }\n\n /**\n * Loads the extension. Returns a promise which resolves when the extension\n * has loaded. The Host calls this method after retrieving extensions.\n */\n public async load() {\n try {\n if (!this.apis) {\n await this.connect();\n }\n return this.apis;\n } catch (e) {\n this.apis = null;\n this.guest = null;\n this.error = e instanceof Error ? e : new Error(String(e));\n throw e;\n }\n }\n\n /**\n * The host-side equivalent of {@link @adobe/uix-guest#register}. Pass a set\n * of methods down to the guest as proxies.\n */\n public provide(apis: RemoteHostApis) {\n Object.assign(this.hostApis, apis);\n this.emit(\"hostprovide\", { guestPort: this, apis });\n }\n\n /**\n * Disconnect from the extension.\n */\n public async unload(): Promise<void> {\n if (this.connection) {\n await this.connection.destroy();\n }\n for (const connection of this.uiConnections.values()) {\n await connection.destroy();\n }\n if (this.frame && this.frame.parentElement) {\n this.frame.parentElement.removeChild(this.frame);\n this.frame = undefined;\n }\n this.emit(\"unload\", { guestPort: this });\n }\n\n // #endregion Public Methods (6)\n\n // #region Private Methods (6)\n\n private assert(\n condition: boolean,\n errorMessage: () => string\n ): asserts condition {\n if (!condition) {\n throw new Error(\n `Error in guest extension \"${this.id}\": ${errorMessage()}`\n );\n }\n }\n\n private assertReady() {\n this.assert(this.isReady(), () => \"Attempted to interact before loaded\");\n }\n\n private attachFrame(iframe: HTMLIFrameElement) {\n return connectToChild<RemoteHostApis<GuestApi>>({\n iframe,\n debug: this.debug,\n childOrigin: this.url.origin,\n timeout: this.timeout,\n methods: {\n getSharedContext: () => this.sharedContext,\n invokeHostMethod: (address: HostMethodAddress) =>\n this.invokeHostMethod(address),\n },\n });\n }\n\n private async connect() {\n this.frame = this.runtimeContainer.ownerDocument.createElement(\"iframe\");\n this.frame.setAttribute(\"src\", this.url.href);\n this.frame.setAttribute(\"data-uix-guest\", \"true\");\n this.runtimeContainer.appendChild(this.frame);\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} attached iframe of ${this.url.href}`,\n this\n );\n }\n this.connection = this.attachFrame(this.frame);\n this.guest = (await this.connection\n .promise) as unknown as GuestProxyWrapper;\n this.apis = this.guest.apis || {};\n this.isLoaded = true;\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} established connection, received methods`,\n this.apis,\n this\n );\n }\n }\n\n private getHostMethodCallee<T = unknown>(\n { name, path }: HostMethodAddress,\n methodSource: RemoteHostApis\n ): Methods {\n const dots = (level: number) =>\n `uix.host.${path.slice(0, level).join(\".\")}`;\n const methodCallee = path.reduce((current, prop, level) => {\n this.assert(\n Reflect.has(current, prop),\n () => `${dots(level)} has no property \"${prop}\"`\n );\n const next = current[prop];\n this.assert(\n typeof next === \"object\",\n () =>\n `${dots(\n level\n )}.${prop} is not an object; namespaces must be objects with methods`\n );\n return next as RemoteHostApis<GuestApi>;\n }, methodSource);\n this.assert(\n typeof methodCallee[name] === \"function\" &&\n Reflect.has(methodCallee, name),\n () => `\"${dots(path.length - 1)}.${name}\" is not a function`\n );\n return methodCallee;\n }\n\n private invokeHostMethod<T = unknown>(\n address: HostMethodAddress,\n privateMethods?: RemoteHostApis\n ): T {\n const { name, path, args = [] } = address;\n this.assert(name && typeof name === \"string\", () => \"Method name required\");\n this.assert(\n path.length > 0,\n () =>\n `Cannot call a method directly on the host; \".${name}()\" must be in a namespace.`\n );\n let methodCallee;\n if (privateMethods) {\n try {\n methodCallee = this.getHostMethodCallee(address, privateMethods);\n } catch (e) {\n methodCallee = this.getHostMethodCallee(address, this.hostApis);\n }\n }\n const method = methodCallee[name] as (...args: unknown[]) => T;\n this.emit(\"beforecallhostmethod\", { guestPort: this, name, path, args });\n return method.apply(methodCallee, [\n { id: this.id, url: this.url },\n ...args,\n ]) as T;\n }\n\n // #endregion Private Methods (6)\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/**\n * Adapter to attach console logging listeners to a Host running in an app\n * @hidden\n */\nimport {\n debugEmitter,\n EmitterDebugLogger,\n Emits,\n GuestConnection,\n} from \"@adobe/uix-core\";\nimport type { PortEvents } from \"./port.js\";\nimport type { HostEventLoadAllGuests, HostEvents } from \"./host.js\";\n\ntype GenericPortEvents = PortEvents<Record<string, unknown>>;\n\ntype Portlike = GuestConnection & Emits<GenericPortEvents>;\n\nexport function debugHost(host: Emits<HostEvents>): EmitterDebugLogger {\n const hostLogger = debugEmitter(host, {\n theme: \"blue medium\",\n type: \"Host\",\n });\n hostLogger\n .listen(\"guestbeforeload\", (log, event) => {\n const { detail } = event;\n const guest = detail.guest as Portlike;\n log.info(event, `Guest ID ${guest.id}`);\n const portLogger = debugEmitter(guest, {\n theme: \"green medium\",\n type: \"Port\",\n id: `${host.id} ➔ ${guest.id}`,\n });\n portLogger\n .listen(\"hostprovide\", (log, event) => {\n log.info(\"received APIs\", event.detail.apis);\n })\n .listen(\"beforecallhostmethod\", (log, event) => {\n log.info(event.detail);\n })\n .listen(\"unload\", (log, event) => {\n log.info(event.detail);\n log.detach();\n });\n })\n .listen(\"guestload\", (log, e) => {\n log.info(e.detail.guest.id, e.detail.guest);\n })\n .listen(\"error\", (log, e) => {\n log.error(`Error: ${e.detail.error.message}`, e);\n })\n .listen(\n \"loadallguests\",\n (log, { detail: { failed, loaded, host } }: HostEventLoadAllGuests) => {\n if (failed.length > 0) {\n log.error(\"%d guests failed to load!\", failed.length);\n }\n log.info(\"%d guests loaded\", loaded.length, host);\n }\n )\n .listen(\"unload\", (log) => {\n log.info(\"Unloaded guest and container.\");\n log.detach();\n });\n return hostLogger;\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\ninterface ExtensionDefinition {\n name: string;\n title: string;\n description: string;\n icon: string;\n publisher: string;\n endpoints: Record<string, EndpointDefinition>;\n xrInfo: ExtensionInfo;\n status: string;\n}\n\ntype EndpointDefinition = Record<string, Array<OperationDefinition>>;\n\ninterface ExtensionInfo {\n supportEmail: string;\n appId: string;\n}\n\ninterface OperationDefinition {\n href: string;\n metadata: OperationMetadata;\n}\n\ninterface OperationMetadata {\n services: Array<object>;\n profile: OperationProfile;\n}\n\ninterface OperationProfile {\n client_id: string;\n scope: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryEndpointRegistration {\n service: string;\n extensionPoint: string;\n version: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryExtensionRegistration\n extends ExtensionRegistryEndpointRegistration {\n imsOrg: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryConnection {\n baseUrl?: string;\n apiKey: string;\n auth: {\n schema: \"Basic\" | \"Bearer\";\n imsToken: string;\n };\n}\n\n/** @public */\nexport interface ExtensionRegistryConfig\n extends ExtensionRegistryExtensionRegistration,\n ExtensionRegistryConnection {}\n\nfunction buildEndpointPath(\n config: ExtensionRegistryEndpointRegistration\n): string {\n return `${config.service}/${config.extensionPoint}/${config.version}`;\n}\n\nfunction ensureProtocolSpecified(url: string) {\n if (url.startsWith(\"https://\")) {\n return url;\n }\n if (url.startsWith(\"http://\")) {\n return url;\n }\n return `https://${url}`;\n}\n\nasync function fetchExtensionsFromRegistry(\n config: ExtensionRegistryConfig\n): Promise<Array<ExtensionDefinition>> {\n const resp = await fetch(\n `${ensureProtocolSpecified(\n config.baseUrl || \"appregistry.adobe.io\"\n )}/myxchng/v1/org/${encodeURIComponent(\n config.imsOrg\n )}/xtn/${buildEndpointPath(config)}?auth=true`,\n {\n headers: {\n Accept: \"application/json\",\n Authorization: `${config.auth.schema} ${config.auth.imsToken}`, // todo: check if auth schema needed (initial implementation was without it)\n \"X-Api-Key\": config.apiKey,\n },\n }\n );\n\n if (resp.status != 200) {\n throw new Error(\n `extension registry returned non-200 response (${\n resp.status\n }): ${await resp.text()}`\n );\n }\n\n return await resp.json();\n}\n\nfunction extensionRegistryExtensionsProvider(\n config: ExtensionRegistryConfig\n): Promise<InstalledExtensions> {\n const erEndpoint = buildEndpointPath(config);\n return fetchExtensionsFromRegistry(config).then((out) =>\n out.reduce((a, e: ExtensionDefinition) => {\n if (e.status !== \"PUBLISHED\") {\n return a;\n }\n\n return {\n ...a,\n // todo: make safer way to extract href\n [e.name]: e.endpoints[erEndpoint].view[0].href,\n };\n }, {})\n );\n\n return Promise.resolve({});\n}\n\n/**\n * Create a callback that fetches extensions from the registry.\n * @public\n */\nexport function createExtensionRegistryProvider(\n config: ExtensionRegistryConfig\n): ExtensionsProvider {\n return function () {\n return extensionRegistryExtensionsProvider(config);\n };\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\n/**\n * Combine multiple {@link @adobe/uix-host#ExtensionsProvider} callbacks into a\n * single callback, which aggregates and dedupes all extensions from all\n * providers into one namespaced object.\n * @public\n */\nexport function combineExtensionsFromProviders(\n ...providers: Array<ExtensionsProvider>\n): ExtensionsProvider {\n return () =>\n Promise.all(providers.map((ep: ExtensionsProvider) => ep())).then(\n (extensionsBatches: Array<InstalledExtensions>) => {\n return Object.assign({}, ...extensionsBatches);\n }\n );\n}\n"]}
1
+ {"version":3,"sources":["../src/host.ts","../src/port.ts","../src/debug-host.ts","../src/extensions-provider/extension-registry.ts","../src/extensions-provider/composition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KAAK;AAAA,QACpD,aAAa,OAAO;AAAA,MACtB;AAAA,IACF;AAAA,EACF;AAEA,MAAI,KAAK,UAAU,KAAK;AACtB,UAAM,IAAI;AAAA,MACR,iDACE,KAAK,YACD,MAAM,KAAK,KAAK;AAAA,IACxB;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,KAAK;AACzB;AAEA,SAAS,oCACP,QAC8B;AAC9B,QAAM,aAAa,kBAAkB,MAAM;AAC3C,SAAO,4BAA4B,MAAM,EAAE;AAAA,IAAK,CAAC,QAC/C,IAAI,OAAO,CAAC,GAAG,MAA2B;AACxC,UAAI,EAAE,WAAW,aAAa;AAC5B,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL,GAAG;AAAA,QAEH,CAAC,EAAE,OAAO,EAAE,UAAU,YAAY,KAAK,GAAG;AAAA,MAC5C;AAAA,IACF,GAAG,CAAC,CAAC;AAAA,EACP;AAEA,SAAO,QAAQ,QAAQ,CAAC,CAAC;AAC3B;AAMO,SAAS,gCACd,QACoB;AACpB,SAAO,WAAY;AACjB,WAAO,oCAAoC,MAAM;AAAA,EACnD;AACF;;;ACnIO,SAAS,kCACX,WACiB;AACpB,SAAO,MACL,QAAQ,IAAI,UAAU,IAAI,CAAC,OAA2B,GAAG,CAAC,CAAC,EAAE;AAAA,IAC3D,CAAC,sBAAkD;AACjD,aAAO,OAAO,OAAO,CAAC,GAAG,GAAG,iBAAiB;AAAA,IAC/C;AAAA,EACF;AACJ;;;ACTO,SAAS,cACd,UACoB;AACpB,SAAO,YAAY;AACjB,QAAI;AACF,aAAO,MAAM,SAAS;AAAA,IACxB,SAAS,OAAP;AACA,cAAQ,MAAM,kCAAkC,MAAM,WAAW;AAAA,QAC/D;AAAA,MACF,CAAC;AACD,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AACF","sourcesContent":["/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Extension,\n GuestConnection,\n NamedEvent,\n Emits,\n GuestApis,\n} from \"@adobe/uix-core\";\nimport type { CapabilitySpec } from \"./port.js\";\nimport { Emitter, quietConsole } from \"@adobe/uix-core\";\nimport { Port, PortOptions } from \"./port.js\";\nimport { debugHost } from \"./debug-host.js\";\n\n/**\n * Dictionary of {@link Port} objects by extension ID.\n * @public\n */\nexport type PortMap = Map<string, GuestConnection>;\n\n/** @public */\nexport type HostEvent<\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<Type, Detail & Record<string, unknown> & { host: Host }>;\n/** @public */\ntype HostGuestEvent<Type extends string> = HostEvent<\n `guest${Type}`,\n { guest: GuestConnection }\n>;\n\n/**\n * All guests requested by host have been loaded and connected.\n * @public\n */\nexport type HostEventLoadAllGuests = HostEvent<\n \"loadallguests\",\n { failed: GuestConnection[]; loaded: GuestConnection[] }\n>;\n\n/**\n * Shared context has been set or updated; all guests receive this event too.\n * @public\n */\n\nexport type HostEventContextChange = HostEvent<\n \"contextchange\",\n { context: SharedContextValues }\n>;\n\n/**\n * An error has occurred during loading or unloading of guests.\n * @public\n */\nexport type HostEventError = HostEvent<\"error\", { error: Error }>;\n\n/** @public */\nexport type HostEvents =\n | HostGuestEvent<\"beforeload\">\n | HostGuestEvent<\"load\">\n | HostEvent<\"beforeunload\">\n | HostEvent<\"unload\">\n | HostEventLoadAllGuests\n | HostEventContextChange\n | HostEventError;\n\n/** @public */\nexport type InstalledExtensions = Record<Extension[\"id\"], Extension[\"url\"]>;\n/** @public */\nexport type ExtensionsProvider = () => Promise<InstalledExtensions>;\n\n/**\n * Values for shared context. Must be a plain object, serializable to JSON.\n * @public\n */\nexport type SharedContextValues = Record<string, unknown>;\n\n/** @public */\nexport interface HostConfig {\n /**\n * Human-readable \"slug\" name of the extensible area--often an entire app.\n * This string serves as a namespace for extension points within the area.\n */\n hostName: string;\n /**\n * A DOM element _outside_ of the React root. This is necessary to preserve\n * the lifetime of the iframes which are running extension objects; if they\n * live inside the React root, then React could unexpectedly re-render the\n * iframe tags themselves at any time, causing a reload of the frame.\n */\n runtimeContainer?: HTMLElement;\n /**\n * Copiously log lifecycle events.\n */\n debug?: boolean;\n /**\n * Default options to use for every guest Port.\n *\n * If `config.debug` is true, then the guest options will have `debug: true`\n * unless `debug: false` is explicitly passed in `guestOptions`.\n */\n guestOptions?: PortOptions;\n /**\n * A read-only dictionary of values that the host will supply to all the\n * guests.\n */\n sharedContext?: SharedContextValues;\n}\n\n/**\n * Callback to use to filter the list returned from {@link Host.(getLoadedGuests:2)}\n * @public\n */\ntype GuestFilter = (item: GuestConnection) => boolean;\n\nconst passAllGuests = () => true;\n\n/**\n * Manager object for connecting to {@link @adobe/uix-guest#GuestServer |\n * GuestServers} and {@link @adobe/uix-guest#GuestUI | GuestUIs}, providing and\n * receiving their APIs, and providing them to the app for interacting with UI.\n *\n * @remarks\n * The Host object is the main connection manager for all UIX Guests.\n * Making an app extensible requires creating a Host object.\n *\n * The extensible app using the Hostis responsible for providing a list of\n * extension references to the Host object. Use {@link\n * createExtensionRegistryProvider} for that purpose. Once you have retrieved a\n * list of extensions available to the host app, pass it to {@link Host.load}.\n *\n * When a Host creates a Guest, it must create an `<iframe>` element to contain\n * the Guest's main {@link @adobe/uix-guest#GuestServer} runtime, which runs\n * invisibly in the background. To do this, the Host creates a hidden container\n * in the body of the document. It is a `<div>` element with the attribute\n * `data-uix-guest-container`. Loaded GuestServers will be injected into this\n * hidden element and removed as necessary. When {@link Host.unload} is called,\n * the Host removes the hidden container from the document after unloading.\n *\n * @public\n */\nexport class Host extends Emitter<HostEvents> {\n /**\n * {@inheritDoc HostEventLoadAllGuests}\n * @eventProperty\n */\n public loadallguests: HostEventLoadAllGuests;\n\n /**\n * One guest has loaded.\n * @eventProperty\n */\n public guestload: HostGuestEvent<\"load\">;\n\n /**\n * About to attempt to load and connect to a Guest.\n * @eventProperty\n */\n public guestbeforeload: HostGuestEvent<\"beforeload\">;\n\n /**\n * About to unload a guest and remove its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestbeforeunload: HostGuestEvent<\"beforeunload\">;\n\n /**\n * Unloaded a guest and removed its {@link @adobe/uix-guest#GuestServer}\n * instance as well as all its {@link @adobe/uix-guest#GuestUI} instances.\n * @eventProperty\n */\n public guestunload: HostGuestEvent<\"unload\">;\n\n /**\n * {@inheritDoc HostEventContextChange}\n * @eventProperty\n */\n public contextchange: HostEventContextChange;\n\n /**\n * {@inheritDoc HostEventError}\n * @eventProperty\n */\n public error: HostEventError;\n\n private static containerStyle = {\n position: \"fixed\",\n width: \"1px\",\n height: \"1px\",\n pointerEvents: \"none\",\n opacity: 0,\n top: 0,\n left: \"-1px\",\n };\n /**\n * Unique string identifying the Host object.\n */\n hostName: string;\n /**\n * `true` if any extension in {@link Host.guests} has created a {@link\n * @adobe/uix-guest#GuestServer}, but the Guest has not yet loaded.\n */\n loading = false;\n /**\n * A Map of of the loaded guests.\n */\n guests: PortMap = new Map();\n private cachedCapabilityLists: WeakMap<object, GuestConnection[]> =\n new WeakMap();\n private runtimeContainer: HTMLElement;\n private guestOptions: PortOptions;\n private debugLogger: Console = quietConsole;\n private sharedContext: SharedContextValues;\n constructor(config: HostConfig) {\n super(config.hostName);\n const { guestOptions = {} } = config;\n this.guestOptions = {\n ...guestOptions,\n debug: guestOptions.debug === false ? false : !!config.debug,\n };\n this.hostName = config.hostName;\n this.sharedContext = config.sharedContext || {};\n this.runtimeContainer = config.runtimeContainer;\n if (config.debug) {\n this.debugLogger = debugHost(this);\n }\n }\n /**\n * Return all loaded guests.\n */\n getLoadedGuests(): GuestConnection[];\n /**\n * Return loaded guests which satisfy the passed test function.\n */\n getLoadedGuests(filter: GuestFilter): GuestConnection[];\n /**\n * Return loaded guests which expose the provided {@link CapabilitySpec}.\n */\n getLoadedGuests<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ): GuestConnection[];\n getLoadedGuests<Apis extends GuestApis = never>(\n filterOrCapabilities?: CapabilitySpec<Apis> | GuestFilter\n ): GuestConnection[] {\n if (typeof filterOrCapabilities === \"object\") {\n return this.getLoadedGuestsWith<Apis>(filterOrCapabilities);\n }\n const filter = filterOrCapabilities || passAllGuests;\n const result = [];\n for (const guest of this.guests.values()) {\n if (guest.isReady() && filter(guest)) {\n result.push(guest);\n }\n }\n return result;\n }\n /**\n * Set the object of shared values that all Guests can access via {@link @adobe/uix-guest#GuestServer.sharedContext}.\n * This overwrites any previous object.\n *\n * @example Exposes `authToken` to all Guests. Guests can call `this.sharedContext.get('authToken')` to retrieve this value.\n * ```javascript\n * host.shareContext({\n * authToken: '82ba19b'\n * });\n * ```\n *\n * @example Overwrites the previous sharedContext, deleting `authToken` and providing `secret` and `auth` instead.\n * ```javascript\n * host.shareContext({\n * secret: 'squirrel',\n * auth: false\n * });\n * ```\n */\n shareContext(context: SharedContextValues): void;\n /**\n * Update the object of shared values that all Guests can access via {@link\n * @adobe/uix-guest#GuestServer.sharedContext}. This method takes a callback\n * which receives the previous context and may return an entirely new context,\n * or new values merged with the old context.\n *\n * @remarks This callback pattern allows the shared context values to be\n * mutable while the internal context object references are immutable, which\n * is important for synchronizing. with guests.\n *\n * @example Overwrites a context object based on the previous one.\n * ```javascript\n * host.shareContext(oldContext => ({\n * counter: oldContext.counter + 1\n * }))\n * ```\n *\n * @example Updates a context while preserving other existing values.\n * ```javascript\n * host.shareContext(oldContext => ({\n * ...oldContext,\n * counter: oldContext.counter + 1\n * }))\n * ```\n */\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setter: (context: SharedContextValues) => SharedContextValues\n ): void;\n shareContext(\n setterOrContext:\n | ((context: SharedContextValues) => SharedContextValues)\n | SharedContextValues\n ) {\n if (typeof setterOrContext === \"function\") {\n this.sharedContext = setterOrContext(this.sharedContext);\n } else {\n this.sharedContext = setterOrContext;\n }\n this.emit(\"contextchange\", {\n host: this,\n context: this.sharedContext,\n });\n }\n /**\n * Load extension into host application from provided extension description.\n * Returned promise resolves when all extensions are loaded and registered.\n *\n * @param extensions - List of extension descriptors. Normally, the Host should receive this value from an {@link ExtensionsProvider}.\n * @param options - Custom options to be used as defaults for each {@link Port} object created for each guest.\n * @returns Promise which resolves when all guests have been loaded.\n */\n async load(\n extensions: InstalledExtensions,\n options?: PortOptions\n ): Promise<void> {\n this.runtimeContainer =\n this.runtimeContainer || this.createRuntimeContainer(window);\n const failed: GuestConnection[] = [];\n const loaded: GuestConnection[] = [];\n this.loading = true;\n await Promise.all(\n Object.entries(extensions).map(async ([id, url]) => {\n const port = await this.loadOneGuest(id, url, options);\n (port.error ? failed : loaded).push(port);\n })\n );\n this.loading = false;\n this.emit(\"loadallguests\", { host: this, failed, loaded });\n }\n /**\n * Unload all extensions and remove their frames/workers. Use this to unmount\n * a UI or when switching to a different extensible UI.\n */\n async unload(): Promise<void> {\n this.emit(\"beforeunload\", { host: this });\n await Promise.all([...this.guests.values()].map((guest) => guest.unload()));\n this.guests.clear();\n this.runtimeContainer.parentElement.removeChild(this.runtimeContainer);\n this.emit(\"unload\", { host: this });\n }\n private createRuntimeContainer(window: Window) {\n const { document } = window;\n const container = document.createElement(\"div\");\n container.setAttribute(\"data-uix-guest-container\", this.hostName);\n Object.assign(container.style, Host.containerStyle);\n document.body.appendChild(container);\n return container;\n }\n private async loadOneGuest(\n id: string,\n urlString: string,\n options: PortOptions = {}\n ): Promise<GuestConnection> {\n let guest = this.guests.get(id);\n if (!guest) {\n const url = new URL(urlString);\n guest = new Port({\n owner: this.hostName,\n id,\n url,\n runtimeContainer: this.runtimeContainer,\n options: {\n ...this.guestOptions,\n ...options,\n },\n debugLogger: this.debugLogger,\n sharedContext: this.sharedContext,\n events: this as Emits,\n });\n this.guests.set(id, guest);\n }\n this.emit(\"guestbeforeload\", { guest, host: this });\n try {\n await guest.load();\n } catch (e: unknown) {\n const error = e instanceof Error ? e : new Error(String(e));\n this.emit(\"error\", { host: this, guest, error });\n console.warn(\"Failed to load extension at endpoint %s\", guest.url);\n return guest;\n }\n // this new guest might have new capabilities, so the identities of the\n // cached capability sets will need to change, to alert subscribers\n this.cachedCapabilityLists = new WeakMap();\n this.emit(\"guestload\", { guest, host: this });\n return guest;\n }\n private getLoadedGuestsWith<Apis extends GuestApis>(\n capabilities: CapabilitySpec<Apis>\n ) {\n if (this.cachedCapabilityLists.has(capabilities)) {\n return this.cachedCapabilityLists.get(capabilities);\n }\n const guestsWithCapabilities = this.getLoadedGuests((guest) =>\n guest.hasCapabilities(capabilities)\n );\n this.cachedCapabilityLists.set(capabilities, guestsWithCapabilities);\n return guestsWithCapabilities;\n }\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport type {\n Emits,\n GuestConnection,\n HostMethodAddress,\n NamedEvent,\n RemoteHostApis,\n GuestApis,\n Unsubscriber,\n} from \"@adobe/uix-core\";\nimport { Emitter } from \"@adobe/uix-core\";\nimport { Connection, connectToChild, Methods } from \"penpal\";\n\n/**\n * A specifier for methods to be expected on a remote interface.\n *\n * @remarks\n * A CapabilitySpec is a description of an interface, like a very simplified\n * type definition. It specifies an object structure and the paths in that\n * structure that must be functions. (It doesn't specify anything about the\n * signatures or return values of those functions.)\n *\n * Use CapabilitySpec objects as queries, or filters, to get a subset of\n * installed extensions which have registered methods which match the spec.\n *\n * @example\n * As an extensible app developer, you are making an extension point for spell\n * check. Your code expects extensions to register an API `spellCheck` with\n * methods called `spellCheck.correct(text)` and `spellCheck.suggest(text)`.\n *\n * ```javascript\n * async function correctText(text) {\n * const spellCheckers = host.getLoadedGuests({\n * spellCheck: [\n * 'correct',\n * 'suggest'\n * ]\n * });\n * let correcting = text;\n * for (const checker of spellCheckers) {\n * correcting = await checker.apis.spellCheck.correct(correcting);\n * }\n * return Promise.all(checkers.map(checker =>\n * checker.apis.spellCheck.suggest(correcting)\n * ));\n * }\n * ```\n *\n * @public\n */\nexport type CapabilitySpec<T extends GuestApis> = {\n [Name in keyof T]: (keyof T[Name])[];\n};\n\n/**\n * Interface for decoupling of guest Penpal object\n * @internal\n */\ninterface GuestProxyWrapper {\n /**\n * Methods from guest\n */\n apis: RemoteHostApis;\n /**\n * Emit an event in the guest frame\n */\n emit(type: string, detail: unknown): Promise<void>;\n}\n\n/** @public */\ntype PortEvent<\n GuestApi,\n Type extends string = string,\n Detail = Record<string, unknown>\n> = NamedEvent<\n Type,\n Detail &\n Record<string, unknown> & {\n guestPort: Port<GuestApi>;\n }\n>;\n\n/** @public */\nexport type PortEvents<\n GuestApi,\n HostApi extends Record<string, unknown> = Record<string, unknown>\n> =\n | PortEvent<GuestApi, \"hostprovide\">\n | PortEvent<GuestApi, \"unload\">\n | PortEvent<GuestApi, \"beforecallhostmethod\", HostMethodAddress<HostApi>>;\n\n/** @public */\nexport type PortOptions = {\n /**\n * Time in milliseconds to wait for the guest to connect before throwing.\n */\n timeout?: number;\n /**\n * Set true to log copiously in the console.\n */\n debug?: boolean;\n};\n\nconst defaultOptions = {\n timeout: 10000,\n debug: false,\n};\n\n/**\n * A Port is the Host-maintained object representing an extension running as a\n * guest. It exposes methods registered by the Guest, and can provide Host\n * methods back to the guest.\n *\n * @remarks\n * When the Host object loads extensions via {@link Host.load}, it creates a\n * Port object for each extension. When retrieving and filtering extensions\n * via {@link Host.(getLoadedGuests:2)}, a list of Port objects is returned. From\n * the point of view of the extensible app using the Host object, extensions\n * are always Port objects, which expose the methods registered by the\n * extension at the {@link Port.apis} property.\n *\n * @privateRemarks\n * We've gone through several possible names for this object. GuestProxy,\n * GuestInterface, GuestConnection, etc. \"Port\" is not ideal, but it conflicted\n * the least with other types we defined in early drafts. It's definitely\n * something we should review.\n * @public\n */\nexport class Port<GuestApi>\n extends Emitter<PortEvents<GuestApi>>\n implements GuestConnection\n{\n // #region Properties (15)\n\n private connection: Connection<RemoteHostApis<GuestApi>>;\n private debug: boolean;\n private debugLogger?: Console;\n private frame: HTMLIFrameElement;\n private guest: GuestProxyWrapper;\n private hostApis: RemoteHostApis = {};\n private isLoaded = false;\n private runtimeContainer: HTMLElement;\n private sharedContext: Record<string, unknown>;\n private subscriptions: Unsubscriber[] = [];\n private timeout: number;\n\n /**\n * Dictionary of namespaced methods that were registered by this guest at the\n * time of connection, using {@link @adobe/uix-guest#register}.\n *\n * @remarks\n * These methods are proxy methods; you can only pass serializable objects to\n * them, not class instances, methods or callbacks.\n * @public\n */\n public apis: RemoteHostApis;\n /**\n * If any errors occurred during the loading of guests, this property will\n * contain the error that was raised.\n * @public\n */\n error?: Error;\n private uiConnections: Map<string, Connection<RemoteHostApis<GuestApi>>> =\n new Map();\n /**\n * The URL of the guest provided by the extension registry. The Host will\n * load this URL in the background, in the invisible the bootstrap frame, so\n * this URL must point to a page that calls {@link @adobe/uix-guest#register}\n * when it loads.\n */\n url: URL;\n\n // #endregion Properties (15)\n\n // #region Constructors (1)\n\n constructor(config: {\n owner: string;\n id: string;\n url: URL;\n /**\n * An alternate DOM element to use for invisible iframes. Will create its\n * own if this option is not populated with a DOM element.\n */\n runtimeContainer: HTMLElement;\n options: PortOptions;\n debugLogger?: Console;\n /**\n * Initial object to populate the shared context with. Once the guest\n * connects, it will be able to access these properties.\n */\n sharedContext: Record<string, unknown>;\n events: Emits;\n }) {\n super(config.id);\n const { timeout, debug } = { ...defaultOptions, ...(config.options || {}) };\n this.timeout = timeout;\n this.debug = debug;\n this.id = config.id;\n this.url = config.url;\n this.runtimeContainer = config.runtimeContainer;\n this.sharedContext = config.sharedContext;\n this.subscriptions.push(\n config.events.addEventListener(\"contextchange\", async (event) => {\n this.sharedContext = (\n (event as CustomEvent).detail as unknown as Record<string, unknown>\n ).context as Record<string, unknown>;\n await this.connect();\n await this.guest.emit(\"contextchange\", { context: this.sharedContext });\n })\n );\n }\n\n // #endregion Constructors (1)\n\n // #region Public Methods (6)\n\n /**\n * Connect an iframe element which is displaying another page in the extension\n * with the extension's bootstrap frame, so they can share context and events.\n */\n public attachUI(iframe: HTMLIFrameElement) {\n const uniqueId = Math.random().toString(36);\n const uiConnection = this.attachFrame(iframe);\n this.uiConnections.set(uniqueId, uiConnection);\n return uiConnection;\n }\n\n /**\n * Returns true if the guest has registered methods matching the provided\n * capability spec. A capability spec is simply an object whose properties are\n * declared in an array of keys, description the names of the functions and\n * methods that the Port will expose.\n */\n public hasCapabilities(requiredMethods: CapabilitySpec<GuestApis>) {\n this.assertReady();\n return Object.keys(requiredMethods).every((key) => {\n if (!Reflect.has(this.apis, key)) {\n return false;\n }\n const api = this.apis[key];\n const methodList = requiredMethods[\n key as keyof typeof requiredMethods\n ] as string[];\n return methodList.every(\n (methodName: string) =>\n Reflect.has(api, methodName) &&\n typeof api[methodName as keyof typeof api] === \"function\"\n );\n });\n }\n\n /**\n * True when al extensions have loaded.\n */\n public isReady(): boolean {\n return this.isLoaded && !this.error;\n }\n\n /**\n * Loads the extension. Returns a promise which resolves when the extension\n * has loaded. The Host calls this method after retrieving extensions.\n */\n public async load() {\n try {\n if (!this.apis) {\n await this.connect();\n }\n return this.apis;\n } catch (e) {\n this.apis = null;\n this.guest = null;\n this.error = e instanceof Error ? e : new Error(String(e));\n throw e;\n }\n }\n\n /**\n * The host-side equivalent of {@link @adobe/uix-guest#register}. Pass a set\n * of methods down to the guest as proxies.\n */\n public provide(apis: RemoteHostApis) {\n Object.assign(this.hostApis, apis);\n this.emit(\"hostprovide\", { guestPort: this, apis });\n }\n\n /**\n * Disconnect from the extension.\n */\n public async unload(): Promise<void> {\n if (this.connection) {\n await this.connection.destroy();\n }\n for (const connection of this.uiConnections.values()) {\n await connection.destroy();\n }\n if (this.frame && this.frame.parentElement) {\n this.frame.parentElement.removeChild(this.frame);\n this.frame = undefined;\n }\n this.emit(\"unload\", { guestPort: this });\n }\n\n // #endregion Public Methods (6)\n\n // #region Private Methods (6)\n\n private assert(\n condition: boolean,\n errorMessage: () => string\n ): asserts condition {\n if (!condition) {\n throw new Error(\n `Error in guest extension \"${this.id}\": ${errorMessage()}`\n );\n }\n }\n\n private assertReady() {\n this.assert(this.isReady(), () => \"Attempted to interact before loaded\");\n }\n\n private attachFrame(iframe: HTMLIFrameElement) {\n return connectToChild<RemoteHostApis<GuestApi>>({\n iframe,\n debug: this.debug,\n childOrigin: this.url.origin,\n timeout: this.timeout,\n methods: {\n getSharedContext: () => this.sharedContext,\n invokeHostMethod: (address: HostMethodAddress) =>\n this.invokeHostMethod(address),\n },\n });\n }\n\n private async connect() {\n this.frame = this.runtimeContainer.ownerDocument.createElement(\"iframe\");\n this.frame.setAttribute(\"src\", this.url.href);\n this.frame.setAttribute(\"data-uix-guest\", \"true\");\n this.runtimeContainer.appendChild(this.frame);\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} attached iframe of ${this.url.href}`,\n this\n );\n }\n this.connection = this.attachFrame(this.frame);\n this.guest = (await this.connection\n .promise) as unknown as GuestProxyWrapper;\n this.apis = this.guest.apis || {};\n this.isLoaded = true;\n if (this.debugLogger) {\n this.debugLogger.info(\n `Guest ${this.id} established connection, received methods`,\n this.apis,\n this\n );\n }\n }\n\n private getHostMethodCallee<T = unknown>(\n { name, path }: HostMethodAddress,\n methodSource: RemoteHostApis\n ): Methods {\n const dots = (level: number) =>\n `uix.host.${path.slice(0, level).join(\".\")}`;\n const methodCallee = path.reduce((current, prop, level) => {\n this.assert(\n Reflect.has(current, prop),\n () => `${dots(level)} has no property \"${prop}\"`\n );\n const next = current[prop];\n this.assert(\n typeof next === \"object\",\n () =>\n `${dots(\n level\n )}.${prop} is not an object; namespaces must be objects with methods`\n );\n return next as RemoteHostApis<GuestApi>;\n }, methodSource);\n this.assert(\n typeof methodCallee[name] === \"function\" &&\n Reflect.has(methodCallee, name),\n () => `\"${dots(path.length - 1)}.${name}\" is not a function`\n );\n return methodCallee;\n }\n\n private invokeHostMethod<T = unknown>(\n address: HostMethodAddress,\n privateMethods?: RemoteHostApis\n ): T {\n const { name, path, args = [] } = address;\n this.assert(name && typeof name === \"string\", () => \"Method name required\");\n this.assert(\n path.length > 0,\n () =>\n `Cannot call a method directly on the host; \".${name}()\" must be in a namespace.`\n );\n let methodCallee;\n if (privateMethods) {\n try {\n methodCallee = this.getHostMethodCallee(address, privateMethods);\n } catch (e) {\n this.debugLogger.warn(\"Private method not found!\", address);\n }\n }\n if (!methodCallee) {\n methodCallee = this.getHostMethodCallee(address, this.hostApis);\n }\n const method = methodCallee[name] as (...args: unknown[]) => T;\n this.emit(\"beforecallhostmethod\", { guestPort: this, name, path, args });\n return method.apply(methodCallee, [\n { id: this.id, url: this.url },\n ...args,\n ]) as T;\n }\n\n // #endregion Private Methods (6)\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\n/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/**\n * Adapter to attach console logging listeners to a Host running in an app\n * @hidden\n */\nimport {\n debugEmitter,\n EmitterDebugLogger,\n Emits,\n GuestConnection,\n} from \"@adobe/uix-core\";\nimport type { PortEvents } from \"./port.js\";\nimport type { HostEventLoadAllGuests, HostEvents } from \"./host.js\";\n\ntype GenericPortEvents = PortEvents<Record<string, unknown>>;\n\ntype Portlike = GuestConnection & Emits<GenericPortEvents>;\n\nexport function debugHost(host: Emits<HostEvents>): EmitterDebugLogger {\n const hostLogger = debugEmitter(host, {\n theme: \"blue medium\",\n type: \"Host\",\n });\n hostLogger\n .listen(\"guestbeforeload\", (log, event) => {\n const { detail } = event;\n const guest = detail.guest as Portlike;\n log.info(event, `Guest ID ${guest.id}`);\n const portLogger = debugEmitter(guest, {\n theme: \"green medium\",\n type: \"Port\",\n id: `${host.id} ➔ ${guest.id}`,\n });\n portLogger\n .listen(\"hostprovide\", (log, event) => {\n log.info(\"received APIs\", event.detail.apis);\n })\n .listen(\"beforecallhostmethod\", (log, event) => {\n log.info(event.detail);\n })\n .listen(\"unload\", (log, event) => {\n log.info(event.detail);\n log.detach();\n });\n })\n .listen(\"guestload\", (log, e) => {\n log.info(e.detail.guest.id, e.detail.guest);\n })\n .listen(\"error\", (log, e) => {\n log.error(`Error: ${e.detail.error.message}`, e);\n })\n .listen(\n \"loadallguests\",\n (log, { detail: { failed, loaded, host } }: HostEventLoadAllGuests) => {\n if (failed.length > 0) {\n log.error(\"%d guests failed to load!\", failed.length);\n }\n log.info(\"%d guests loaded\", loaded.length, host);\n }\n )\n .listen(\"unload\", (log) => {\n log.info(\"Unloaded guest and container.\");\n log.detach();\n });\n return hostLogger;\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\ninterface ExtensionDefinition {\n name: string;\n title: string;\n description: string;\n icon: string;\n publisher: string;\n endpoints: Record<string, EndpointDefinition>;\n xrInfo: ExtensionInfo;\n status: string;\n}\n\ntype EndpointDefinition = Record<string, Array<OperationDefinition>>;\n\ninterface ExtensionInfo {\n supportEmail: string;\n appId: string;\n}\n\ninterface OperationDefinition {\n href: string;\n metadata: OperationMetadata;\n}\n\ninterface OperationMetadata {\n services: Array<object>;\n profile: OperationProfile;\n}\n\ninterface OperationProfile {\n client_id: string;\n scope: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryEndpointRegistration {\n service: string;\n extensionPoint: string;\n version: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryExtensionRegistration\n extends ExtensionRegistryEndpointRegistration {\n imsOrg: string;\n}\n\n/** @public */\nexport interface ExtensionRegistryConnection {\n baseUrl?: string;\n apiKey: string;\n auth: {\n schema: \"Basic\" | \"Bearer\";\n imsToken: string;\n };\n}\n\n/** @public */\nexport interface ExtensionRegistryConfig\n extends ExtensionRegistryExtensionRegistration,\n ExtensionRegistryConnection {}\n\nfunction buildEndpointPath(\n config: ExtensionRegistryEndpointRegistration\n): string {\n return `${config.service}/${config.extensionPoint}/${config.version}`;\n}\n\nfunction ensureProtocolSpecified(url: string) {\n if (url.startsWith(\"https://\")) {\n return url;\n }\n if (url.startsWith(\"http://\")) {\n return url;\n }\n return `https://${url}`;\n}\n\nasync function fetchExtensionsFromRegistry(\n config: ExtensionRegistryConfig\n): Promise<Array<ExtensionDefinition>> {\n const resp = await fetch(\n `${ensureProtocolSpecified(\n config.baseUrl || \"appregistry.adobe.io\"\n )}/myxchng/v1/org/${encodeURIComponent(\n config.imsOrg\n )}/xtn/${buildEndpointPath(config)}?auth=true`,\n {\n headers: {\n Accept: \"application/json\",\n Authorization: `${config.auth.schema} ${config.auth.imsToken}`, // todo: check if auth schema needed (initial implementation was without it)\n \"X-Api-Key\": config.apiKey,\n },\n }\n );\n\n if (resp.status != 200) {\n throw new Error(\n `extension registry returned non-200 response (${\n resp.status\n }): ${await resp.text()}`\n );\n }\n\n return await resp.json();\n}\n\nfunction extensionRegistryExtensionsProvider(\n config: ExtensionRegistryConfig\n): Promise<InstalledExtensions> {\n const erEndpoint = buildEndpointPath(config);\n return fetchExtensionsFromRegistry(config).then((out) =>\n out.reduce((a, e: ExtensionDefinition) => {\n if (e.status !== \"PUBLISHED\") {\n return a;\n }\n\n return {\n ...a,\n // todo: make safer way to extract href\n [e.name]: e.endpoints[erEndpoint].view[0].href,\n };\n }, {})\n );\n\n return Promise.resolve({});\n}\n\n/**\n * Create a callback that fetches extensions from the registry.\n * @public\n */\nexport function createExtensionRegistryProvider(\n config: ExtensionRegistryConfig\n): ExtensionsProvider {\n return function () {\n return extensionRegistryExtensionsProvider(config);\n };\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { InstalledExtensions, ExtensionsProvider } from \"../host.js\";\n\n/**\n * Combine multiple {@link @adobe/uix-host#ExtensionsProvider} callbacks into a\n * single callback, which aggregates and dedupes all extensions from all\n * providers into one namespaced object.\n * @public\n */\nexport function combineExtensionsFromProviders(\n ...providers: Array<ExtensionsProvider>\n): ExtensionsProvider {\n return () =>\n Promise.all(providers.map((ep: ExtensionsProvider) => ep())).then(\n (extensionsBatches: Array<InstalledExtensions>) => {\n return Object.assign({}, ...extensionsBatches);\n }\n );\n}\n","/*\nCopyright 2022 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport { ExtensionsProvider } from \"../host.js\";\n\n/**\n * Mute any errors produced by provider.\n * This function would execute given provider and return its results as is, if any error occurs this provider will log it\n * any return an empty array of extensions.\n * @public\n */\nexport function mutedProvider(\n provider: ExtensionsProvider\n): ExtensionsProvider {\n return async () => {\n try {\n return await provider();\n } catch (error) {\n console.error(`Extension provider has failed: ${error.message}`, {\n error,\n });\n return {};\n }\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"port.d.ts","sourceRoot":"","sources":["../src/port.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,KAAK,EACL,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,SAAS,EAEV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAA2B,MAAM,QAAQ,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,oBAAY,cAAc,CAAC,CAAC,SAAS,SAAS,IAAI;KAC/C,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE;CACrC,CAAC;AAiBF,cAAc;AACd,aAAK,SAAS,CACZ,QAAQ,EACR,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC9B,UAAU,CACZ,IAAI,EACJ,MAAM,GACJ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IACxB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;CAC3B,CACJ,CAAC;AAEF,cAAc;AAC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,CAAC;IACd,OAAO,CAAC,aAAa,CACT;IACZ;;;;;OAKG;IACH,GAAG,EAAE,GAAG,CAAC;gBAMG,MAAM,EAAE;QAClB,KAAK,EAAE,MAAM,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,GAAG,EAAE,GAAG,CAAC;QACT;;;WAGG;QACH,gBAAgB,EAAE,WAAW,CAAC;QAC9B,OAAO,EAAE,WAAW,CAAC;QACrB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB;;;WAGG;QACH,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACvC,MAAM,EAAE,KAAK,CAAC;KACf;IAwBD;;;OAGG;IACI,QAAQ,CAAC,MAAM,EAAE,iBAAiB;IAOzC;;;;;OAKG;IACI,eAAe,CAAC,eAAe,EAAE,cAAc,CAAC,SAAS,CAAC;IAkBjE;;OAEG;IACI,OAAO,IAAI,OAAO;IAIzB;;;OAGG;IACU,IAAI;IAcjB;;;OAGG;IACI,OAAO,CAAC,IAAI,EAAE,cAAc;IAKnC;;OAEG;IACU,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBpC,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;YAcL,OAAO;IAyBrB,OAAO,CAAC,mBAAmB;IA6B3B,OAAO,CAAC,gBAAgB;CA+BzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/uix-host",
3
- "version": "0.6.4",
3
+ "version": "0.6.5-0",
4
4
  "description": "Tools for embedding UIX Extensions into Adobe apps",
5
5
  "author": "Adobe, Inc,",
6
6
  "type": "module",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "bugs": "https://github.com/adobe/uix-sdk/issues",
22
22
  "dependencies": {
23
- "@adobe/uix-core": "^0.6.4",
23
+ "@adobe/uix-core": "^0.6.5-0",
24
24
  "penpal": "~6.2.2"
25
25
  },
26
26
  "files": [
@@ -12,3 +12,4 @@ governing permissions and limitations under the License.
12
12
 
13
13
  export * from "./extension-registry.js";
14
14
  export * from "./composition.js";
15
+ export * from "./mute.js";
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import { ExtensionsProvider } from "../host.js";
14
+
15
+ /**
16
+ * Mute any errors produced by provider.
17
+ * This function would execute given provider and return its results as is, if any error occurs this provider will log it
18
+ * any return an empty array of extensions.
19
+ * @public
20
+ */
21
+ export function mutedProvider(
22
+ provider: ExtensionsProvider
23
+ ): ExtensionsProvider {
24
+ return async () => {
25
+ try {
26
+ return await provider();
27
+ } catch (error) {
28
+ console.error(`Extension provider has failed: ${error.message}`, {
29
+ error,
30
+ });
31
+ return {};
32
+ }
33
+ };
34
+ }
package/src/port.ts CHANGED
@@ -415,9 +415,12 @@ export class Port<GuestApi>
415
415
  try {
416
416
  methodCallee = this.getHostMethodCallee(address, privateMethods);
417
417
  } catch (e) {
418
- methodCallee = this.getHostMethodCallee(address, this.hostApis);
418
+ this.debugLogger.warn("Private method not found!", address);
419
419
  }
420
420
  }
421
+ if (!methodCallee) {
422
+ methodCallee = this.getHostMethodCallee(address, this.hostApis);
423
+ }
421
424
  const method = methodCallee[name] as (...args: unknown[]) => T;
422
425
  this.emit("beforecallhostmethod", { guestPort: this, name, path, args });
423
426
  return method.apply(methodCallee, [