@wix/editor-platform-environment-api 1.63.0 → 1.65.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/cjs/index.js +19 -19
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +19 -19
- package/dist/esm/index.js.map +1 -1
- package/dist/types/index.d.ts +10 -7
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/cjs/index.js
CHANGED
|
@@ -61,15 +61,8 @@ class AbstractEnvironmentAPI {
|
|
|
61
61
|
applicationAPIs: {}
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
async injectApplicationContext({
|
|
65
|
-
|
|
66
|
-
}) {
|
|
67
|
-
await editorPlatformContexts.ApplicationContext.inject({
|
|
68
|
-
appDefinitionId,
|
|
69
|
-
// ?
|
|
70
|
-
// anyway, it is not used atm
|
|
71
|
-
appDefinitionName: ""
|
|
72
|
-
});
|
|
64
|
+
async injectApplicationContext(context) {
|
|
65
|
+
await editorPlatformContexts.ApplicationContext.inject(context);
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
68
|
|
|
@@ -101,20 +94,27 @@ class PlatformFrameAPI extends AbstractEnvironmentAPI {
|
|
|
101
94
|
}
|
|
102
95
|
}
|
|
103
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* We need to introduce context versions
|
|
100
|
+
* to simplify handling the backward compatibility issues
|
|
101
|
+
*/
|
|
104
102
|
async initEnvironment(props) {
|
|
105
|
-
const { applicationPrivateAPI, privateAPI,
|
|
103
|
+
const { applicationPrivateAPI, privateAPI, context } = props;
|
|
104
|
+
const _appDefinitionId = props.context?.appDefinitionId ?? props.appDefinitionId;
|
|
105
|
+
const _context = props.context ? props.context : {
|
|
106
|
+
appDefinitionId: _appDefinitionId
|
|
107
|
+
};
|
|
106
108
|
this.#applicationPrivateAPI = applicationPrivateAPI;
|
|
107
109
|
this.#privateAPI = privateAPI;
|
|
108
110
|
await this.injectEnvironmentContext({
|
|
109
111
|
privateApi: privateAPI,
|
|
110
112
|
events: this.#events,
|
|
111
|
-
applicationAPIs: {
|
|
112
|
-
[
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
await this.injectApplicationContext({
|
|
116
|
-
appDefinitionId
|
|
113
|
+
applicationAPIs: _appDefinitionId ? {
|
|
114
|
+
[_appDefinitionId]: this.#applicationPrivateAPI
|
|
115
|
+
} : {}
|
|
117
116
|
});
|
|
117
|
+
await this.injectApplicationContext(_context);
|
|
118
118
|
}
|
|
119
119
|
notify(event) {
|
|
120
120
|
this.#eventsBridge.notify(event);
|
|
@@ -475,9 +475,9 @@ class EditorPlatformEnvironmentProxy {
|
|
|
475
475
|
privateApi: contexts.environmentContext.getPrivateAPI(),
|
|
476
476
|
applicationAPIs: contexts.environmentContext.getApplicationAPIs()
|
|
477
477
|
});
|
|
478
|
-
await workerApi.injectApplicationContext(
|
|
479
|
-
|
|
480
|
-
|
|
478
|
+
await workerApi.injectApplicationContext(
|
|
479
|
+
contexts.applicationContext.getContext()
|
|
480
|
+
);
|
|
481
481
|
} catch (e) {
|
|
482
482
|
throw createEditorPlatformEnvironmentAPIError(
|
|
483
483
|
EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/api/ApplicationEventsBridge/WorkerEventsBridge.ts","../../src/api/AbstractEnvironmentAPI.ts","../../src/api/PlatformFrameAPI/PlatformFrameAPI.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/errors.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/executeApplication.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/PlatformApplicationContainer.ts","../../src/api/PlatformWorkerAPI/PlatformWorkerAPI.ts","../../src/EditorPlatformContextEnvironment.ts","../../src/errors.ts","../../src/EditorPlatformEnvironmentProxy.ts"],"sourcesContent":["import {\n IPlatformPrivateEvent,\n PlatformLifecycleEvent,\n PlatformPrivateEvent,\n // --\n IPlatformAppEvent,\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\n\n/**\n * The events bridge between platform events (private) and app events\n */\nexport class ApplicationEventsBridge {\n constructor(private platformAppEvents: PlatformAppEventEmitter) {}\n\n /**\n * Notify by event from Worker Manager (platform infrastructure)\n */\n public notify(event: IPlatformPrivateEvent) {\n switch (event.type) {\n case PlatformLifecycleEvent.EditorReady:\n this.platformAppEvents.notify({\n ...event,\n // @ts-expect-error TODO: fix me\n type: PlatformAppEvent.EditorReady,\n });\n break;\n case PlatformPrivateEvent.HostEvent:\n this.platformAppEvents.notify({\n ...event,\n type: PlatformAppEvent.HostEvent,\n });\n break;\n }\n }\n\n /**\n * Subscribe to Worker (Application) event\n */\n public subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.platformAppEvents.subscribe((event) => {\n cb(event);\n });\n }\n}\n","import {\n ApplicationContext,\n EnvironmentContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\nimport { PlatformAppEventEmitter } from '@wix/public-editor-platform-events';\nimport { IPrivateAPIFixMe } from './types';\n\nexport enum PlatformConsumerEnvironmentAPIType {\n Frame = 'PLATFORM_FRAME_API',\n Worker = 'PLATFORM_WORKER_API',\n}\n\n/**\n * rename these entities -> API to Env\n */\nexport abstract class AbstractEnvironmentAPI<\n TApiType extends PlatformConsumerEnvironmentAPIType,\n TEnv extends PlatformEnvironment,\n> {\n protected constructor(\n public type: TApiType,\n public envType: TEnv,\n ) {}\n\n abstract initEnvironment(props: unknown): void;\n\n async injectEnvironmentContext({\n events,\n privateApi,\n }: {\n events: PlatformAppEventEmitter;\n privateApi: IPrivateAPIFixMe;\n applicationAPIs?: Record<string, any>;\n }) {\n await EnvironmentContext.inject({\n environment: this.envType,\n events,\n privateApi,\n applicationAPIs: {},\n });\n }\n\n async injectApplicationContext({\n appDefinitionId,\n }: {\n appDefinitionId: string;\n }) {\n await ApplicationContext.inject({\n appDefinitionId,\n // ?\n // anyway, it is not used atm\n appDefinitionName: '',\n });\n }\n}\n","import {\n IPlatformAppEvent,\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\nimport { IPrivateAPIFixMe } from '../types';\n\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nconst DESIGN_SYSTEM_STYLES_MAP = {\n classic:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css',\n studio:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css',\n};\n\nexport class PlatformFrameAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Frame,\n PlatformEnvironment.Frame\n> {\n #events = new PlatformAppEventEmitter();\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #privateAPI: IPrivateAPIFixMe;\n #applicationPrivateAPI: any;\n\n constructor() {\n super(PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame);\n\n this.#injectGlobalCSSTokens();\n }\n\n #injectGlobalCSSTokens() {\n if (typeof globalThis?.document?.head?.prepend === 'function') {\n const params = new URL(globalThis.location.href).searchParams;\n\n // TODO: check all possible editorType values\n const host =\n params.get('editorType') === 'CLASSIC' ? 'classic' : 'studio';\n\n const url = DESIGN_SYSTEM_STYLES_MAP[host];\n\n const isAlreadyLoaded =\n url &&\n !!document.querySelectorAll(`link[type=\"text/css\"][href=\"${url}\"]`)\n ?.length;\n\n if (url && !isAlreadyLoaded) {\n const link: HTMLLinkElement = document.createElement('link');\n\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('type', 'text/css');\n link.setAttribute('href', url);\n\n globalThis.document.head.prepend(link);\n }\n }\n }\n\n async initEnvironment(props: {\n appDefinitionId: string;\n privateAPI: IPrivateAPIFixMe;\n applicationPrivateAPI: any;\n }) {\n const { applicationPrivateAPI, privateAPI, appDefinitionId } = props;\n\n this.#applicationPrivateAPI = applicationPrivateAPI;\n this.#privateAPI = privateAPI;\n\n await this.injectEnvironmentContext({\n privateApi: privateAPI,\n events: this.#events,\n applicationAPIs: {\n [appDefinitionId]: this.#applicationPrivateAPI,\n },\n });\n\n await this.injectApplicationContext({\n appDefinitionId,\n });\n }\n\n notify(event: IPlatformPrivateEvent) {\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformApplicationContainerErrorCode {\n ApplicationLoadError = 'ApplicationLoadError',\n ApplicationFetchError = 'ApplicationFetchError',\n ApplicationExecuteError = 'ApplicationExecuteError',\n}\n\nclass EditorPlatformApplicationContainerError extends BaseError<EditorPlatformApplicationContainerErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n apiMethod: string;\n apiType: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformApplicationContainerErrorCode,\n ) {\n super(message, code, 'EP Application Container Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n\n withApiMethod(apiMethod: string) {\n this.state = { ...this.state, apiMethod };\n return this;\n }\n\n withApiType(apiType: string) {\n this.state = { ...this.state, apiType };\n return this;\n }\n}\n\nexport const createEditorPlatformApplicationContainerError = createErrorBuilder<\n EditorPlatformApplicationContainerErrorCode,\n EditorPlatformApplicationContainerError\n>(EditorPlatformApplicationContainerError);\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport {\n APPLICATION_CONTEXT_KEY,\n EnvironmentContext,\n ApplicationContext,\n} from '@wix/editor-platform-contexts';\n\nimport type { EditorPlatformApplication } from '@wix/editor-application';\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { IApplicationSpec } from '../../types';\n\nexport const APPLICATION_REGISTRY_KEY = '__APPLICATION_REGISTRY_KEY';\n\nexport type IApplicationRegistry = (\n _instance: EditorPlatformApplication,\n) => void;\n\nexport async function executeApplication(\n events: PlatformAppEventEmitter,\n spec: IApplicationSpec,\n bundle: string,\n): Promise<{\n instance: EditorPlatformApplication;\n}> {\n // eslint-disable-next-line no-new-func\n const executable = new Function(\n APPLICATION_CONTEXT_KEY,\n APPLICATION_REGISTRY_KEY,\n bundle,\n );\n\n let instance: EditorPlatformApplication | undefined;\n\n const applicationRegistryCallback: IApplicationRegistry = (_instance) => {\n if (instance) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry called more than once',\n ).withAppDefinitionId(spec.appDefinitionId);\n }\n\n if (_instance.type !== spec.type) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application has different type',\n )\n .withMessage('expected type', spec.type)\n .withMessage('received type', _instance.type);\n }\n\n instance = _instance;\n };\n\n try {\n const context = { ...spec };\n\n executable.call(\n null,\n new ApplicationContext(context, await EnvironmentContext.getInstance()),\n applicationRegistryCallback,\n );\n } catch (e: unknown) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n (e as Error).message,\n )\n .withAppDefinitionId(spec.appDefinitionId)\n .withParentError(e as Error);\n }\n\n return new Promise((resolve, reject) => {\n const unsubscribe = events.subscribe((event) => {\n const timeoutId = setTimeout(() => {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called, threw by timeout',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n }, 5000);\n\n if (\n event.type === PlatformAppEvent.ApplicationInit &&\n event.meta.appDefinitionId === spec.appDefinitionId\n ) {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n\n resolve({ instance: instance! });\n }\n });\n });\n}\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { EventType } from '@wix/public-editor-platform-interfaces';\n\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { EditorPlatformApplication } from '@wix/editor-application';\nimport { type IApplicationSpec, type IPrivateAPIFixMe } from '../../types';\nimport { executeApplication } from './executeApplication';\n\nexport class PlatformApplicationContainer {\n #apps: Record<string, EditorPlatformApplication> = {};\n\n readonly #privateAPI: IPrivateAPIFixMe;\n readonly #events: PlatformAppEventEmitter;\n\n constructor(privateApi: IPrivateAPIFixMe, events: PlatformAppEventEmitter) {\n this.#privateAPI = privateApi;\n this.#events = events;\n\n this.#events.subscribe((event) => {\n switch (event.type) {\n case PlatformAppEvent.HostEvent: {\n if (event.payload.type === EventType.removeAppCompleted) {\n void this.#events.withEvent(\n this.#events.factories.createApplicationRemovedEvent(\n event.payload.appDefinitionId!,\n ),\n () => {\n return this.removeApplication(event.payload.appDefinitionId!);\n },\n );\n }\n break;\n }\n }\n });\n }\n\n public async runApplication(appSpec: IApplicationSpec) {\n const bundle = await this.loadApplication(appSpec);\n const instance = await this.executeApplication(appSpec, bundle);\n\n this.setApplication(appSpec.appDefinitionId, instance);\n\n return instance;\n }\n\n private setApplication(\n appDefId: string,\n instance: EditorPlatformApplication,\n ) {\n this.#apps[appDefId] = instance;\n\n void this.#events.withEvent(\n this.#events.factories.createApplicationApiInitEvent(\n appDefId,\n // TODO: both types are set here...\n // @ts-expect-error TODO: fix me\n instance?.api?.private ? 'private' : 'public',\n ),\n () => {\n // NOTE: sometimes I saw this method was called while application was not executed\n this.#privateAPI.applicationManager.setApplication(instance);\n },\n );\n }\n\n public getApplication(appDefId: string) {\n return this.#apps[appDefId];\n }\n\n public getAppDefinitionIds() {\n return Object.keys(this.#apps);\n }\n\n private removeApplication(appDefinitionId: string) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#apps[appDefinitionId];\n }\n\n private async loadApplication(appSpec: IApplicationSpec) {\n const url = appSpec.url;\n\n return this.#events.withEvent(\n this.#events.factories.createApplicationLoadEvent(appSpec, url),\n\n async () => {\n try {\n return await this.loadApplicationBundle(url);\n } catch (e) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationLoadError,\n )\n .withUrl(url)\n .withAppDefinitionId(appSpec.appDefinitionId)\n .withParentError(e as any);\n }\n },\n );\n }\n\n private async loadApplicationBundle(url: string) {\n /**\n * NOTE: we don't use wix http client here\n * because this code is public, while http client is private\n */\n const res = await fetch(url, {\n method: 'GET',\n });\n\n const isSuccessfulResponse = res.status >= 200 && res.status <= 299;\n\n if (!isSuccessfulResponse) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationFetchError,\n ).withUrl(url);\n }\n\n return res.text();\n }\n\n private async executeApplication(appSpec: IApplicationSpec, bundle: string) {\n return this.#events.withEvent(\n this.#events.factories.createApplicationExecuteEvent(\n appSpec,\n appSpec.url,\n ),\n async () => {\n const { instance } = await executeApplication(\n this.#events,\n appSpec,\n bundle,\n );\n return instance;\n },\n );\n }\n}\n","import { IApplicationSpec, IPrivateAPIFixMe } from '../types';\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\n\nimport { PlatformApplicationContainer } from './PlatformApplicationContainer';\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nexport class PlatformWorkerAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker\n> {\n #events = new PlatformAppEventEmitter();\n\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #container: PlatformApplicationContainer | null = null;\n #privateAPI: IPrivateAPIFixMe;\n\n #pendingWaiters: ((value: this) => void)[] = [];\n\n constructor() {\n super(\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker,\n );\n }\n\n create() {}\n\n async initEnvironment(props: {\n // TODO: should be Promise response in types\n buildPrivateAPI: (config: any) => IPrivateAPIFixMe;\n }) {\n const { buildPrivateAPI } = props;\n this.#privateAPI = await buildPrivateAPI({\n // TODO: should be per application (within the container before app execution)\n type: 'EDITOR_ADDON',\n });\n\n await this.injectEnvironmentContext({\n events: this.#events,\n privateApi: this.#privateAPI,\n applicationAPIs: {},\n });\n\n this.#container = new PlatformApplicationContainer(\n this.#privateAPI,\n this.#events,\n );\n\n this.#pendingWaiters.forEach((res) => res(this));\n }\n\n async notify(event: IPlatformPrivateEvent) {\n await this.waitReady();\n\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n\n async runApplication(app: IApplicationSpec) {\n await this.waitReady();\n\n await this.#container!.runApplication(app);\n }\n\n // TODO: should not be any waiters here\n // or should be implemented inside the events instances\n // collect queue until app is not ready\n public waitReady(): Promise<this> {\n return new Promise((res) => {\n if (this.#privateAPI) {\n return res(this);\n }\n\n this.#pendingWaiters.push(res);\n });\n }\n}\n","import {\n IFrameConsumerEndpoint,\n WorkerConsumerEndpoint,\n} from '@wix/editor-platform-transport';\n\nimport {\n ApplicationContext,\n EnvironmentContext,\n} from '@wix/editor-platform-contexts';\nimport { PlatformWorkerAPI, PlatformFrameAPI } from './api';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\n\nconst GUARD_PROP = '$_EP_TRANSPORT_ENV_CONTEXT_GUARD';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var $_EP_TRANSPORT_ENV_CONTEXT_GUARD: boolean;\n}\n\nexport class EditorPlatformContextEnvironment {\n isEnvironmentApiExposed() {\n return !!globalThis[GUARD_PROP];\n }\n\n async getContexts() {\n const [environmentContext, applicationContext] = await Promise.all([\n EnvironmentContext.getInstance(),\n ApplicationContext.getInstance(),\n ]);\n\n return {\n environmentContext,\n applicationContext,\n };\n }\n\n expose() {\n if (this.isEnvironmentApiExposed()) {\n return;\n }\n\n const isWorker = typeof importScripts === 'function';\n const isIframe =\n globalThis.self && globalThis.top && globalThis.self !== globalThis.top;\n\n /**\n * TODO: we can try to split this code somehow\n * and load the only API according to the current env.\n */\n if (isWorker) {\n this.#exposeWorkerAPI();\n globalThis[GUARD_PROP] = true;\n } else if (isIframe) {\n this.#exposeFrameAPI();\n globalThis[GUARD_PROP] = true;\n } else {\n /**\n * we expose env APIs only from worker or frame\n * but we have some cases when our code runs in the main thread\n * for example – builder component panels.\n */\n // if (!shouldPreventErrorLogs) {\n // console.error(\n // createEditorPlatformEnvironmentAPIError(\n // EditorPlatformEnvironmentAPIErrorErrorCode.IncorrectExpose,\n // 'seems current code is running in the main thread, while it is expected to be in iframe or worker',\n // ),\n // );\n // }\n }\n }\n\n #exposeWorkerAPI() {\n WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());\n }\n\n #exposeFrameAPI() {\n IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformEnvironmentAPIErrorErrorCode {\n ProxyEnvironmentConnectTimeout = 'ProxyEnvironmentConnectTimeout',\n ProxyWaitAPITimeout = 'ProxyWaitAPITimeout',\n ProxyContextsError = 'ProxyContextsError',\n IncorrectExpose = 'IncorrectExpose',\n}\n\nclass EditorPlatformEnvironmentAPIError extends BaseError<EditorPlatformEnvironmentAPIErrorErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformEnvironmentAPIErrorErrorCode,\n ) {\n super(message, code, 'EP EnvironmentAPI Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n}\n\nexport const createEditorPlatformEnvironmentAPIError = createErrorBuilder<\n EditorPlatformEnvironmentAPIErrorErrorCode,\n EditorPlatformEnvironmentAPIError\n>(EditorPlatformEnvironmentAPIError);\n","import { WorkerHostEndpoint } from '@wix/editor-platform-transport';\nimport { EditorPlatformContextEnvironment } from './EditorPlatformContextEnvironment';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\nimport {\n createEditorPlatformInternalError,\n EditorPlatformInternalErrorCode,\n} from '@wix/public-editor-platform-errors';\nimport { PlatformConsumerEnvironmentAPIType } from './api';\n\nexport class EditorPlatformEnvironmentProxy {\n async iframe() {\n throw createEditorPlatformInternalError(\n EditorPlatformInternalErrorCode.UnexpectedError,\n 'not supported',\n );\n }\n\n async worker(worker: Worker) {\n const environment = new EditorPlatformContextEnvironment();\n\n if (!environment.isEnvironmentApiExposed()) {\n environment.expose();\n }\n\n const connectTimeoutId = setTimeout(() => {\n console.info(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,\n 'probably worker environment does not expose platform API or any SDK function is never used',\n ),\n );\n }, 2_000);\n\n WorkerHostEndpoint.connect(worker, async (transport) => {\n clearTimeout(connectTimeoutId);\n\n const waitAPITimeoutId = setTimeout(() => {\n console.error(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout,\n ),\n );\n }, 2_000);\n\n const workerApi = await transport.waitAPI(\n PlatformConsumerEnvironmentAPIType.Worker,\n );\n\n clearTimeout(waitAPITimeoutId);\n\n try {\n const contexts = await environment.getContexts();\n\n await workerApi.injectEnvironmentContext({\n events: contexts.environmentContext.getEvents(),\n privateApi: contexts.environmentContext.getPrivateAPI(),\n applicationAPIs: contexts.environmentContext.getApplicationAPIs(),\n });\n\n await workerApi.injectApplicationContext({\n appDefinitionId: contexts.applicationContext.getAppDefinitionId(),\n });\n } catch (e: any) {\n throw createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError,\n ).withParentError(e);\n }\n });\n }\n}\n"],"names":["PlatformLifecycleEvent","PlatformAppEvent","PlatformPrivateEvent","PlatformConsumerEnvironmentAPIType","EnvironmentContext","ApplicationContext","PlatformAppEventEmitter","PlatformEnvironment","EditorPlatformApplicationContainerErrorCode","BaseError","createErrorBuilder","APPLICATION_CONTEXT_KEY","EventType","WorkerConsumerEndpoint","IFrameConsumerEndpoint","EditorPlatformEnvironmentAPIErrorErrorCode","createEditorPlatformInternalError","EditorPlatformInternalErrorCode","WorkerHostEndpoint"],"mappings":";;;;;;;;AAaO,MAAM,uBAAwB,CAAA;AAAA,EACnC,YAAoB,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA;AAAA;AAAA;AAAA,EAK1D,OAAO,KAA8B,EAAA;AAC1C,IAAA,QAAQ,MAAM,IAAM;AAAA,MAClB,KAAKA,iDAAuB,CAAA,WAAA;AAC1B,QAAA,IAAA,CAAK,kBAAkB,MAAO,CAAA;AAAA,UAC5B,GAAG,KAAA;AAAA;AAAA,UAEH,MAAMC,2CAAiB,CAAA,WAAA;AAAA,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A,OAAO,SAAc,KAAA;AACtD,MAAA,YAAA,CAAa,gBAAgB,CAAA,CAAA;AAE7B,MAAM,MAAA,gBAAA,GAAmB,WAAW,MAAM;AACxC,QAAQ,OAAA,CAAA,KAAA;AAAA,UACN,uCAAA;AAAA,YACE,0CAA2C,CAAA,mBAAA;AAAA,WAC7C;AAAA,SACF,CAAA;AAAA,SACC,GAAK,CAAA,CAAA;AAER,MAAM,MAAA,SAAA,GAAY,MAAM,SAAU,CAAA,OAAA;AAAA,QAChC,kCAAmC,CAAA,MAAA;AAAA,OACrC,CAAA;AAEA,MAAA,YAAA,CAAa,gBAAgB,CAAA,CAAA;AAE7B,MAAI,IAAA;AACF,QAAM,MAAA,QAAA,GAAW,MAAM,WAAA,CAAY,WAAY,EAAA,CAAA;AAE/C,QAAA,MAAM,UAAU,wBAAyB,CAAA;AAAA,UACvC,MAAA,EAAQ,QAAS,CAAA,kBAAA,CAAmB,SAAU,EAAA;AAAA,UAC9C,UAAA,EAAY,QAAS,CAAA,kBAAA,CAAmB,aAAc,EAAA;AAAA,UACtD,eAAA,EAAiB,QAAS,CAAA,kBAAA,CAAmB,kBAAmB,EAAA;AAAA,SACjE,CAAA,CAAA;AAED,QAAA,MAAM,UAAU,wBAAyB,CAAA;AAAA,UACvC,eAAA,EAAiB,QAAS,CAAA,kBAAA,CAAmB,kBAAmB,EAAA;AAAA,SACjE,CAAA,CAAA;AAAA,eACM,CAAQ,EAAA;AACf,QAAM,MAAA,uCAAA;AAAA,UACJ,0CAA2C,CAAA,kBAAA;AAAA,SAC7C,CAAE,gBAAgB,CAAC,CAAA,CAAA;AAAA,OACrB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/api/ApplicationEventsBridge/WorkerEventsBridge.ts","../../src/api/AbstractEnvironmentAPI.ts","../../src/api/PlatformFrameAPI/PlatformFrameAPI.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/errors.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/executeApplication.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/PlatformApplicationContainer.ts","../../src/api/PlatformWorkerAPI/PlatformWorkerAPI.ts","../../src/EditorPlatformContextEnvironment.ts","../../src/errors.ts","../../src/EditorPlatformEnvironmentProxy.ts"],"sourcesContent":["import {\n IPlatformPrivateEvent,\n PlatformLifecycleEvent,\n PlatformPrivateEvent,\n // --\n IPlatformAppEvent,\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\n\n/**\n * The events bridge between platform events (private) and app events\n */\nexport class ApplicationEventsBridge {\n constructor(private platformAppEvents: PlatformAppEventEmitter) {}\n\n /**\n * Notify by event from Worker Manager (platform infrastructure)\n */\n public notify(event: IPlatformPrivateEvent) {\n switch (event.type) {\n case PlatformLifecycleEvent.EditorReady:\n this.platformAppEvents.notify({\n ...event,\n // @ts-expect-error TODO: fix me\n type: PlatformAppEvent.EditorReady,\n });\n break;\n case PlatformPrivateEvent.HostEvent:\n this.platformAppEvents.notify({\n ...event,\n type: PlatformAppEvent.HostEvent,\n });\n break;\n }\n }\n\n /**\n * Subscribe to Worker (Application) event\n */\n public subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.platformAppEvents.subscribe((event) => {\n cb(event);\n });\n }\n}\n","import {\n ApplicationContext,\n EnvironmentContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\nimport { PlatformAppEventEmitter } from '@wix/public-editor-platform-events';\nimport { IPrivateAPIFixMe } from './types';\nimport { IPlatformSDKContext } from '@wix/editor-platform-contexts';\n\nexport enum PlatformConsumerEnvironmentAPIType {\n Frame = 'PLATFORM_FRAME_API',\n Worker = 'PLATFORM_WORKER_API',\n}\n\n/**\n * rename these entities -> API to Env\n */\nexport abstract class AbstractEnvironmentAPI<\n TApiType extends PlatformConsumerEnvironmentAPIType,\n TEnv extends PlatformEnvironment,\n> {\n protected constructor(\n public type: TApiType,\n public envType: TEnv,\n ) {}\n\n abstract initEnvironment(props: unknown): void;\n\n async injectEnvironmentContext({\n events,\n privateApi,\n }: {\n events: PlatformAppEventEmitter;\n privateApi: IPrivateAPIFixMe;\n applicationAPIs?: Record<string, any>;\n }) {\n await EnvironmentContext.inject({\n environment: this.envType,\n events,\n privateApi,\n applicationAPIs: {},\n });\n }\n\n async injectApplicationContext(context: IPlatformSDKContext) {\n await ApplicationContext.inject(context);\n }\n}\n","import {\n IPlatformAppEvent,\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport {\n IPlatformSDKContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\nimport { IPrivateAPIFixMe } from '../types';\n\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nconst DESIGN_SYSTEM_STYLES_MAP = {\n classic:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css',\n studio:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css',\n};\n\nexport class PlatformFrameAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Frame,\n PlatformEnvironment.Frame\n> {\n #events = new PlatformAppEventEmitter();\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #privateAPI: IPrivateAPIFixMe;\n #applicationPrivateAPI: any;\n\n constructor() {\n super(PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame);\n\n this.#injectGlobalCSSTokens();\n }\n\n #injectGlobalCSSTokens() {\n if (typeof globalThis?.document?.head?.prepend === 'function') {\n const params = new URL(globalThis.location.href).searchParams;\n\n // TODO: check all possible editorType values\n const host =\n params.get('editorType') === 'CLASSIC' ? 'classic' : 'studio';\n\n const url = DESIGN_SYSTEM_STYLES_MAP[host];\n\n const isAlreadyLoaded =\n url &&\n !!document.querySelectorAll(`link[type=\"text/css\"][href=\"${url}\"]`)\n ?.length;\n\n if (url && !isAlreadyLoaded) {\n const link: HTMLLinkElement = document.createElement('link');\n\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('type', 'text/css');\n link.setAttribute('href', url);\n\n globalThis.document.head.prepend(link);\n }\n }\n }\n\n /**\n *\n * We need to introduce context versions\n * to simplify handling the backward compatibility issues\n */\n async initEnvironment(props: {\n // backward-compatibility\n appDefinitionId?: string;\n context: IPlatformSDKContext;\n privateAPI: IPrivateAPIFixMe;\n applicationPrivateAPI: any;\n }) {\n const { applicationPrivateAPI, privateAPI, context } = props;\n\n /**\n * backward-compatibility\n */\n const _appDefinitionId =\n props.context?.appDefinitionId ?? props.appDefinitionId;\n\n const _context = props.context\n ? props.context\n : {\n appDefinitionId: _appDefinitionId,\n };\n\n this.#applicationPrivateAPI = applicationPrivateAPI;\n this.#privateAPI = privateAPI;\n\n await this.injectEnvironmentContext({\n privateApi: privateAPI,\n events: this.#events,\n applicationAPIs: _appDefinitionId\n ? {\n [_appDefinitionId]: this.#applicationPrivateAPI,\n }\n : {},\n });\n\n await this.injectApplicationContext(_context);\n }\n\n notify(event: IPlatformPrivateEvent) {\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformApplicationContainerErrorCode {\n ApplicationLoadError = 'ApplicationLoadError',\n ApplicationFetchError = 'ApplicationFetchError',\n ApplicationExecuteError = 'ApplicationExecuteError',\n}\n\nclass EditorPlatformApplicationContainerError extends BaseError<EditorPlatformApplicationContainerErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n apiMethod: string;\n apiType: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformApplicationContainerErrorCode,\n ) {\n super(message, code, 'EP Application Container Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n\n withApiMethod(apiMethod: string) {\n this.state = { ...this.state, apiMethod };\n return this;\n }\n\n withApiType(apiType: string) {\n this.state = { ...this.state, apiType };\n return this;\n }\n}\n\nexport const createEditorPlatformApplicationContainerError = createErrorBuilder<\n EditorPlatformApplicationContainerErrorCode,\n EditorPlatformApplicationContainerError\n>(EditorPlatformApplicationContainerError);\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport {\n APPLICATION_CONTEXT_KEY,\n EnvironmentContext,\n ApplicationContext,\n} from '@wix/editor-platform-contexts';\n\nimport type { EditorPlatformApplication } from '@wix/editor-application';\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { IApplicationSpec } from '../../types';\n\nexport const APPLICATION_REGISTRY_KEY = '__APPLICATION_REGISTRY_KEY';\n\nexport type IApplicationRegistry = (\n _instance: EditorPlatformApplication,\n) => void;\n\nexport async function executeApplication(\n events: PlatformAppEventEmitter,\n spec: IApplicationSpec,\n bundle: string,\n): Promise<{\n instance: EditorPlatformApplication;\n}> {\n // eslint-disable-next-line no-new-func\n const executable = new Function(\n APPLICATION_CONTEXT_KEY,\n APPLICATION_REGISTRY_KEY,\n bundle,\n );\n\n let instance: EditorPlatformApplication | undefined;\n\n const applicationRegistryCallback: IApplicationRegistry = (_instance) => {\n if (instance) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry called more than once',\n ).withAppDefinitionId(spec.appDefinitionId);\n }\n\n if (_instance.type !== spec.type) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application has different type',\n )\n .withMessage('expected type', spec.type)\n .withMessage('received type', _instance.type);\n }\n\n instance = _instance;\n };\n\n try {\n const context = { ...spec };\n\n executable.call(\n null,\n new ApplicationContext(context, await EnvironmentContext.getInstance()),\n applicationRegistryCallback,\n );\n } catch (e: unknown) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n (e as Error).message,\n )\n .withAppDefinitionId(spec.appDefinitionId)\n .withParentError(e as Error);\n }\n\n return new Promise((resolve, reject) => {\n const unsubscribe = events.subscribe((event) => {\n const timeoutId = setTimeout(() => {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called, threw by timeout',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n }, 5000);\n\n if (\n event.type === PlatformAppEvent.ApplicationInit &&\n event.meta.appDefinitionId === spec.appDefinitionId\n ) {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n\n resolve({ instance: instance! });\n }\n });\n });\n}\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { EventType } from '@wix/public-editor-platform-interfaces';\n\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { EditorPlatformApplication } from '@wix/editor-application';\nimport { type IApplicationSpec, type IPrivateAPIFixMe } from '../../types';\nimport { executeApplication } from './executeApplication';\n\nexport class PlatformApplicationContainer {\n #apps: Record<string, EditorPlatformApplication> = {};\n\n readonly #privateAPI: IPrivateAPIFixMe;\n readonly #events: PlatformAppEventEmitter;\n\n constructor(privateApi: IPrivateAPIFixMe, events: PlatformAppEventEmitter) {\n this.#privateAPI = privateApi;\n this.#events = events;\n\n this.#events.subscribe((event) => {\n switch (event.type) {\n case PlatformAppEvent.HostEvent: {\n if (event.payload.type === EventType.removeAppCompleted) {\n void this.#events.withEvent(\n this.#events.factories.createApplicationRemovedEvent(\n event.payload.appDefinitionId!,\n ),\n () => {\n return this.removeApplication(event.payload.appDefinitionId!);\n },\n );\n }\n break;\n }\n }\n });\n }\n\n public async runApplication(appSpec: IApplicationSpec) {\n const bundle = await this.loadApplication(appSpec);\n const instance = await this.executeApplication(appSpec, bundle);\n\n this.setApplication(appSpec.appDefinitionId, instance);\n\n return instance;\n }\n\n private setApplication(\n appDefId: string,\n instance: EditorPlatformApplication,\n ) {\n this.#apps[appDefId] = instance;\n\n void this.#events.withEvent(\n this.#events.factories.createApplicationApiInitEvent(\n appDefId,\n // TODO: both types are set here...\n // @ts-expect-error TODO: fix me\n instance?.api?.private ? 'private' : 'public',\n ),\n () => {\n // NOTE: sometimes I saw this method was called while application was not executed\n this.#privateAPI.applicationManager.setApplication(instance);\n },\n );\n }\n\n public getApplication(appDefId: string) {\n return this.#apps[appDefId];\n }\n\n public getAppDefinitionIds() {\n return Object.keys(this.#apps);\n }\n\n private removeApplication(appDefinitionId: string) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#apps[appDefinitionId];\n }\n\n private async loadApplication(appSpec: IApplicationSpec) {\n const url = appSpec.url;\n\n return this.#events.withEvent(\n this.#events.factories.createApplicationLoadEvent(appSpec, url),\n\n async () => {\n try {\n return await this.loadApplicationBundle(url);\n } catch (e) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationLoadError,\n )\n .withUrl(url)\n .withAppDefinitionId(appSpec.appDefinitionId)\n .withParentError(e as any);\n }\n },\n );\n }\n\n private async loadApplicationBundle(url: string) {\n /**\n * NOTE: we don't use wix http client here\n * because this code is public, while http client is private\n */\n const res = await fetch(url, {\n method: 'GET',\n });\n\n const isSuccessfulResponse = res.status >= 200 && res.status <= 299;\n\n if (!isSuccessfulResponse) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationFetchError,\n ).withUrl(url);\n }\n\n return res.text();\n }\n\n private async executeApplication(appSpec: IApplicationSpec, bundle: string) {\n return this.#events.withEvent(\n this.#events.factories.createApplicationExecuteEvent(\n appSpec,\n appSpec.url,\n ),\n async () => {\n const { instance } = await executeApplication(\n this.#events,\n appSpec,\n bundle,\n );\n return instance;\n },\n );\n }\n}\n","import { IApplicationSpec, IPrivateAPIFixMe } from '../types';\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\n\nimport { PlatformApplicationContainer } from './PlatformApplicationContainer';\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nexport class PlatformWorkerAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker\n> {\n #events = new PlatformAppEventEmitter();\n\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #container: PlatformApplicationContainer | null = null;\n #privateAPI: IPrivateAPIFixMe;\n\n #pendingWaiters: ((value: this) => void)[] = [];\n\n constructor() {\n super(\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker,\n );\n }\n\n create() {}\n\n async initEnvironment(props: {\n // TODO: should be Promise response in types\n buildPrivateAPI: (config: any) => IPrivateAPIFixMe;\n }) {\n const { buildPrivateAPI } = props;\n this.#privateAPI = await buildPrivateAPI({\n // TODO: should be per application (within the container before app execution)\n type: 'EDITOR_ADDON',\n });\n\n await this.injectEnvironmentContext({\n events: this.#events,\n privateApi: this.#privateAPI,\n applicationAPIs: {},\n });\n\n this.#container = new PlatformApplicationContainer(\n this.#privateAPI,\n this.#events,\n );\n\n this.#pendingWaiters.forEach((res) => res(this));\n }\n\n async notify(event: IPlatformPrivateEvent) {\n await this.waitReady();\n\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n\n async runApplication(app: IApplicationSpec) {\n await this.waitReady();\n\n await this.#container!.runApplication(app);\n }\n\n // TODO: should not be any waiters here\n // or should be implemented inside the events instances\n // collect queue until app is not ready\n public waitReady(): Promise<this> {\n return new Promise((res) => {\n if (this.#privateAPI) {\n return res(this);\n }\n\n this.#pendingWaiters.push(res);\n });\n }\n}\n","import {\n IFrameConsumerEndpoint,\n WorkerConsumerEndpoint,\n} from '@wix/editor-platform-transport';\n\nimport {\n ApplicationContext,\n EnvironmentContext,\n} from '@wix/editor-platform-contexts';\nimport { PlatformWorkerAPI, PlatformFrameAPI } from './api';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\n\nconst GUARD_PROP = '$_EP_TRANSPORT_ENV_CONTEXT_GUARD';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var $_EP_TRANSPORT_ENV_CONTEXT_GUARD: boolean;\n}\n\nexport class EditorPlatformContextEnvironment {\n isEnvironmentApiExposed() {\n return !!globalThis[GUARD_PROP];\n }\n\n async getContexts() {\n const [environmentContext, applicationContext] = await Promise.all([\n EnvironmentContext.getInstance(),\n ApplicationContext.getInstance(),\n ]);\n\n return {\n environmentContext,\n applicationContext,\n };\n }\n\n expose() {\n if (this.isEnvironmentApiExposed()) {\n return;\n }\n\n const isWorker = typeof importScripts === 'function';\n const isIframe =\n globalThis.self && globalThis.top && globalThis.self !== globalThis.top;\n\n /**\n * TODO: we can try to split this code somehow\n * and load the only API according to the current env.\n */\n if (isWorker) {\n this.#exposeWorkerAPI();\n globalThis[GUARD_PROP] = true;\n } else if (isIframe) {\n this.#exposeFrameAPI();\n globalThis[GUARD_PROP] = true;\n } else {\n /**\n * we expose env APIs only from worker or frame\n * but we have some cases when our code runs in the main thread\n * for example – builder component panels.\n */\n // if (!shouldPreventErrorLogs) {\n // console.error(\n // createEditorPlatformEnvironmentAPIError(\n // EditorPlatformEnvironmentAPIErrorErrorCode.IncorrectExpose,\n // 'seems current code is running in the main thread, while it is expected to be in iframe or worker',\n // ),\n // );\n // }\n }\n }\n\n #exposeWorkerAPI() {\n WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());\n }\n\n #exposeFrameAPI() {\n IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformEnvironmentAPIErrorErrorCode {\n ProxyEnvironmentConnectTimeout = 'ProxyEnvironmentConnectTimeout',\n ProxyWaitAPITimeout = 'ProxyWaitAPITimeout',\n ProxyContextsError = 'ProxyContextsError',\n IncorrectExpose = 'IncorrectExpose',\n}\n\nclass EditorPlatformEnvironmentAPIError extends BaseError<EditorPlatformEnvironmentAPIErrorErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformEnvironmentAPIErrorErrorCode,\n ) {\n super(message, code, 'EP EnvironmentAPI Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n}\n\nexport const createEditorPlatformEnvironmentAPIError = createErrorBuilder<\n EditorPlatformEnvironmentAPIErrorErrorCode,\n EditorPlatformEnvironmentAPIError\n>(EditorPlatformEnvironmentAPIError);\n","import { WorkerHostEndpoint } from '@wix/editor-platform-transport';\nimport { EditorPlatformContextEnvironment } from './EditorPlatformContextEnvironment';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\nimport {\n createEditorPlatformInternalError,\n EditorPlatformInternalErrorCode,\n} from '@wix/public-editor-platform-errors';\nimport { PlatformConsumerEnvironmentAPIType } from './api';\n\nexport class EditorPlatformEnvironmentProxy {\n async iframe() {\n throw createEditorPlatformInternalError(\n EditorPlatformInternalErrorCode.UnexpectedError,\n 'not supported',\n );\n }\n\n async worker(worker: Worker) {\n const environment = new EditorPlatformContextEnvironment();\n\n if (!environment.isEnvironmentApiExposed()) {\n environment.expose();\n }\n\n const connectTimeoutId = setTimeout(() => {\n console.info(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,\n 'probably worker environment does not expose platform API or any SDK function is never used',\n ),\n );\n }, 2_000);\n\n WorkerHostEndpoint.connect(worker, async (transport) => {\n clearTimeout(connectTimeoutId);\n\n const waitAPITimeoutId = setTimeout(() => {\n console.error(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout,\n ),\n );\n }, 2_000);\n\n const workerApi = await transport.waitAPI(\n PlatformConsumerEnvironmentAPIType.Worker,\n );\n\n clearTimeout(waitAPITimeoutId);\n\n try {\n const contexts = await environment.getContexts();\n\n await workerApi.injectEnvironmentContext({\n events: contexts.environmentContext.getEvents(),\n privateApi: contexts.environmentContext.getPrivateAPI(),\n applicationAPIs: contexts.environmentContext.getApplicationAPIs(),\n });\n\n await workerApi.injectApplicationContext(\n contexts.applicationContext.getContext(),\n );\n } catch (e: any) {\n throw createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError,\n ).withParentError(e);\n }\n });\n }\n}\n"],"names":["PlatformLifecycleEvent","PlatformAppEvent","PlatformPrivateEvent","PlatformConsumerEnvironmentAPIType","EnvironmentContext","ApplicationContext","PlatformAppEventEmitter","PlatformEnvironment","EditorPlatformApplicationContainerErrorCode","BaseError","createErrorBuilder","APPLICATION_CONTEXT_KEY","EventType","WorkerConsumerEndpoint","IFrameConsumerEndpoint","EditorPlatformEnvironmentAPIErrorErrorCode","createEditorPlatformInternalError","EditorPlatformInternalErrorCode","WorkerHostEnd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kBAAA,CAAmB,kBAAmB,EAAA;AAAA,SACjE,CAAA,CAAA;AAED,QAAA,MAAM,SAAU,CAAA,wBAAA;AAAA,UACd,QAAA,CAAS,mBAAmB,UAAW,EAAA;AAAA,SACzC,CAAA;AAAA,eACO,CAAQ,EAAA;AACf,QAAM,MAAA,uCAAA;AAAA,UACJ,0CAA2C,CAAA,kBAAA;AAAA,SAC7C,CAAE,gBAAgB,CAAC,CAAA,CAAA;AAAA,OACrB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF;;;;;;;;"}
|
package/dist/esm/index.js
CHANGED
|
@@ -59,15 +59,8 @@ class AbstractEnvironmentAPI {
|
|
|
59
59
|
applicationAPIs: {}
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
|
-
async injectApplicationContext({
|
|
63
|
-
|
|
64
|
-
}) {
|
|
65
|
-
await ApplicationContext.inject({
|
|
66
|
-
appDefinitionId,
|
|
67
|
-
// ?
|
|
68
|
-
// anyway, it is not used atm
|
|
69
|
-
appDefinitionName: ""
|
|
70
|
-
});
|
|
62
|
+
async injectApplicationContext(context) {
|
|
63
|
+
await ApplicationContext.inject(context);
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
66
|
|
|
@@ -99,20 +92,27 @@ class PlatformFrameAPI extends AbstractEnvironmentAPI {
|
|
|
99
92
|
}
|
|
100
93
|
}
|
|
101
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* We need to introduce context versions
|
|
98
|
+
* to simplify handling the backward compatibility issues
|
|
99
|
+
*/
|
|
102
100
|
async initEnvironment(props) {
|
|
103
|
-
const { applicationPrivateAPI, privateAPI,
|
|
101
|
+
const { applicationPrivateAPI, privateAPI, context } = props;
|
|
102
|
+
const _appDefinitionId = props.context?.appDefinitionId ?? props.appDefinitionId;
|
|
103
|
+
const _context = props.context ? props.context : {
|
|
104
|
+
appDefinitionId: _appDefinitionId
|
|
105
|
+
};
|
|
104
106
|
this.#applicationPrivateAPI = applicationPrivateAPI;
|
|
105
107
|
this.#privateAPI = privateAPI;
|
|
106
108
|
await this.injectEnvironmentContext({
|
|
107
109
|
privateApi: privateAPI,
|
|
108
110
|
events: this.#events,
|
|
109
|
-
applicationAPIs: {
|
|
110
|
-
[
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
await this.injectApplicationContext({
|
|
114
|
-
appDefinitionId
|
|
111
|
+
applicationAPIs: _appDefinitionId ? {
|
|
112
|
+
[_appDefinitionId]: this.#applicationPrivateAPI
|
|
113
|
+
} : {}
|
|
115
114
|
});
|
|
115
|
+
await this.injectApplicationContext(_context);
|
|
116
116
|
}
|
|
117
117
|
notify(event) {
|
|
118
118
|
this.#eventsBridge.notify(event);
|
|
@@ -473,9 +473,9 @@ class EditorPlatformEnvironmentProxy {
|
|
|
473
473
|
privateApi: contexts.environmentContext.getPrivateAPI(),
|
|
474
474
|
applicationAPIs: contexts.environmentContext.getApplicationAPIs()
|
|
475
475
|
});
|
|
476
|
-
await workerApi.injectApplicationContext(
|
|
477
|
-
|
|
478
|
-
|
|
476
|
+
await workerApi.injectApplicationContext(
|
|
477
|
+
contexts.applicationContext.getContext()
|
|
478
|
+
);
|
|
479
479
|
} catch (e) {
|
|
480
480
|
throw createEditorPlatformEnvironmentAPIError(
|
|
481
481
|
EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/api/ApplicationEventsBridge/WorkerEventsBridge.ts","../../src/api/AbstractEnvironmentAPI.ts","../../src/api/PlatformFrameAPI/PlatformFrameAPI.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/errors.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/executeApplication.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/PlatformApplicationContainer.ts","../../src/api/PlatformWorkerAPI/PlatformWorkerAPI.ts","../../src/EditorPlatformContextEnvironment.ts","../../src/errors.ts","../../src/EditorPlatformEnvironmentProxy.ts"],"sourcesContent":["import {\n IPlatformPrivateEvent,\n PlatformLifecycleEvent,\n PlatformPrivateEvent,\n // --\n IPlatformAppEvent,\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\n\n/**\n * The events bridge between platform events (private) and app events\n */\nexport class ApplicationEventsBridge {\n constructor(private platformAppEvents: PlatformAppEventEmitter) {}\n\n /**\n * Notify by event from Worker Manager (platform infrastructure)\n */\n public notify(event: IPlatformPrivateEvent) {\n switch (event.type) {\n case PlatformLifecycleEvent.EditorReady:\n this.platformAppEvents.notify({\n ...event,\n // @ts-expect-error TODO: fix me\n type: PlatformAppEvent.EditorReady,\n });\n break;\n case PlatformPrivateEvent.HostEvent:\n this.platformAppEvents.notify({\n ...event,\n type: PlatformAppEvent.HostEvent,\n });\n break;\n }\n }\n\n /**\n * Subscribe to Worker (Application) event\n */\n public subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.platformAppEvents.subscribe((event) => {\n cb(event);\n });\n }\n}\n","import {\n ApplicationContext,\n EnvironmentContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\nimport { PlatformAppEventEmitter } from '@wix/public-editor-platform-events';\nimport { IPrivateAPIFixMe } from './types';\n\nexport enum PlatformConsumerEnvironmentAPIType {\n Frame = 'PLATFORM_FRAME_API',\n Worker = 'PLATFORM_WORKER_API',\n}\n\n/**\n * rename these entities -> API to Env\n */\nexport abstract class AbstractEnvironmentAPI<\n TApiType extends PlatformConsumerEnvironmentAPIType,\n TEnv extends PlatformEnvironment,\n> {\n protected constructor(\n public type: TApiType,\n public envType: TEnv,\n ) {}\n\n abstract initEnvironment(props: unknown): void;\n\n async injectEnvironmentContext({\n events,\n privateApi,\n }: {\n events: PlatformAppEventEmitter;\n privateApi: IPrivateAPIFixMe;\n applicationAPIs?: Record<string, any>;\n }) {\n await EnvironmentContext.inject({\n environment: this.envType,\n events,\n privateApi,\n applicationAPIs: {},\n });\n }\n\n async injectApplicationContext({\n appDefinitionId,\n }: {\n appDefinitionId: string;\n }) {\n await ApplicationContext.inject({\n appDefinitionId,\n // ?\n // anyway, it is not used atm\n appDefinitionName: '',\n });\n }\n}\n","import {\n IPlatformAppEvent,\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\nimport { IPrivateAPIFixMe } from '../types';\n\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nconst DESIGN_SYSTEM_STYLES_MAP = {\n classic:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css',\n studio:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css',\n};\n\nexport class PlatformFrameAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Frame,\n PlatformEnvironment.Frame\n> {\n #events = new PlatformAppEventEmitter();\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #privateAPI: IPrivateAPIFixMe;\n #applicationPrivateAPI: any;\n\n constructor() {\n super(PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame);\n\n this.#injectGlobalCSSTokens();\n }\n\n #injectGlobalCSSTokens() {\n if (typeof globalThis?.document?.head?.prepend === 'function') {\n const params = new URL(globalThis.location.href).searchParams;\n\n // TODO: check all possible editorType values\n const host =\n params.get('editorType') === 'CLASSIC' ? 'classic' : 'studio';\n\n const url = DESIGN_SYSTEM_STYLES_MAP[host];\n\n const isAlreadyLoaded =\n url &&\n !!document.querySelectorAll(`link[type=\"text/css\"][href=\"${url}\"]`)\n ?.length;\n\n if (url && !isAlreadyLoaded) {\n const link: HTMLLinkElement = document.createElement('link');\n\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('type', 'text/css');\n link.setAttribute('href', url);\n\n globalThis.document.head.prepend(link);\n }\n }\n }\n\n async initEnvironment(props: {\n appDefinitionId: string;\n privateAPI: IPrivateAPIFixMe;\n applicationPrivateAPI: any;\n }) {\n const { applicationPrivateAPI, privateAPI, appDefinitionId } = props;\n\n this.#applicationPrivateAPI = applicationPrivateAPI;\n this.#privateAPI = privateAPI;\n\n await this.injectEnvironmentContext({\n privateApi: privateAPI,\n events: this.#events,\n applicationAPIs: {\n [appDefinitionId]: this.#applicationPrivateAPI,\n },\n });\n\n await this.injectApplicationContext({\n appDefinitionId,\n });\n }\n\n notify(event: IPlatformPrivateEvent) {\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformApplicationContainerErrorCode {\n ApplicationLoadError = 'ApplicationLoadError',\n ApplicationFetchError = 'ApplicationFetchError',\n ApplicationExecuteError = 'ApplicationExecuteError',\n}\n\nclass EditorPlatformApplicationContainerError extends BaseError<EditorPlatformApplicationContainerErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n apiMethod: string;\n apiType: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformApplicationContainerErrorCode,\n ) {\n super(message, code, 'EP Application Container Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n\n withApiMethod(apiMethod: string) {\n this.state = { ...this.state, apiMethod };\n return this;\n }\n\n withApiType(apiType: string) {\n this.state = { ...this.state, apiType };\n return this;\n }\n}\n\nexport const createEditorPlatformApplicationContainerError = createErrorBuilder<\n EditorPlatformApplicationContainerErrorCode,\n EditorPlatformApplicationContainerError\n>(EditorPlatformApplicationContainerError);\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport {\n APPLICATION_CONTEXT_KEY,\n EnvironmentContext,\n ApplicationContext,\n} from '@wix/editor-platform-contexts';\n\nimport type { EditorPlatformApplication } from '@wix/editor-application';\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { IApplicationSpec } from '../../types';\n\nexport const APPLICATION_REGISTRY_KEY = '__APPLICATION_REGISTRY_KEY';\n\nexport type IApplicationRegistry = (\n _instance: EditorPlatformApplication,\n) => void;\n\nexport async function executeApplication(\n events: PlatformAppEventEmitter,\n spec: IApplicationSpec,\n bundle: string,\n): Promise<{\n instance: EditorPlatformApplication;\n}> {\n // eslint-disable-next-line no-new-func\n const executable = new Function(\n APPLICATION_CONTEXT_KEY,\n APPLICATION_REGISTRY_KEY,\n bundle,\n );\n\n let instance: EditorPlatformApplication | undefined;\n\n const applicationRegistryCallback: IApplicationRegistry = (_instance) => {\n if (instance) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry called more than once',\n ).withAppDefinitionId(spec.appDefinitionId);\n }\n\n if (_instance.type !== spec.type) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application has different type',\n )\n .withMessage('expected type', spec.type)\n .withMessage('received type', _instance.type);\n }\n\n instance = _instance;\n };\n\n try {\n const context = { ...spec };\n\n executable.call(\n null,\n new ApplicationContext(context, await EnvironmentContext.getInstance()),\n applicationRegistryCallback,\n );\n } catch (e: unknown) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n (e as Error).message,\n )\n .withAppDefinitionId(spec.appDefinitionId)\n .withParentError(e as Error);\n }\n\n return new Promise((resolve, reject) => {\n const unsubscribe = events.subscribe((event) => {\n const timeoutId = setTimeout(() => {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called, threw by timeout',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n }, 5000);\n\n if (\n event.type === PlatformAppEvent.ApplicationInit &&\n event.meta.appDefinitionId === spec.appDefinitionId\n ) {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n\n resolve({ instance: instance! });\n }\n });\n });\n}\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { EventType } from '@wix/public-editor-platform-interfaces';\n\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { EditorPlatformApplication } from '@wix/editor-application';\nimport { type IApplicationSpec, type IPrivateAPIFixMe } from '../../types';\nimport { executeApplication } from './executeApplication';\n\nexport class PlatformApplicationContainer {\n #apps: Record<string, EditorPlatformApplication> = {};\n\n readonly #privateAPI: IPrivateAPIFixMe;\n readonly #events: PlatformAppEventEmitter;\n\n constructor(privateApi: IPrivateAPIFixMe, events: PlatformAppEventEmitter) {\n this.#privateAPI = privateApi;\n this.#events = events;\n\n this.#events.subscribe((event) => {\n switch (event.type) {\n case PlatformAppEvent.HostEvent: {\n if (event.payload.type === EventType.removeAppCompleted) {\n void this.#events.withEvent(\n this.#events.factories.createApplicationRemovedEvent(\n event.payload.appDefinitionId!,\n ),\n () => {\n return this.removeApplication(event.payload.appDefinitionId!);\n },\n );\n }\n break;\n }\n }\n });\n }\n\n public async runApplication(appSpec: IApplicationSpec) {\n const bundle = await this.loadApplication(appSpec);\n const instance = await this.executeApplication(appSpec, bundle);\n\n this.setApplication(appSpec.appDefinitionId, instance);\n\n return instance;\n }\n\n private setApplication(\n appDefId: string,\n instance: EditorPlatformApplication,\n ) {\n this.#apps[appDefId] = instance;\n\n void this.#events.withEvent(\n this.#events.factories.createApplicationApiInitEvent(\n appDefId,\n // TODO: both types are set here...\n // @ts-expect-error TODO: fix me\n instance?.api?.private ? 'private' : 'public',\n ),\n () => {\n // NOTE: sometimes I saw this method was called while application was not executed\n this.#privateAPI.applicationManager.setApplication(instance);\n },\n );\n }\n\n public getApplication(appDefId: string) {\n return this.#apps[appDefId];\n }\n\n public getAppDefinitionIds() {\n return Object.keys(this.#apps);\n }\n\n private removeApplication(appDefinitionId: string) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#apps[appDefinitionId];\n }\n\n private async loadApplication(appSpec: IApplicationSpec) {\n const url = appSpec.url;\n\n return this.#events.withEvent(\n this.#events.factories.createApplicationLoadEvent(appSpec, url),\n\n async () => {\n try {\n return await this.loadApplicationBundle(url);\n } catch (e) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationLoadError,\n )\n .withUrl(url)\n .withAppDefinitionId(appSpec.appDefinitionId)\n .withParentError(e as any);\n }\n },\n );\n }\n\n private async loadApplicationBundle(url: string) {\n /**\n * NOTE: we don't use wix http client here\n * because this code is public, while http client is private\n */\n const res = await fetch(url, {\n method: 'GET',\n });\n\n const isSuccessfulResponse = res.status >= 200 && res.status <= 299;\n\n if (!isSuccessfulResponse) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationFetchError,\n ).withUrl(url);\n }\n\n return res.text();\n }\n\n private async executeApplication(appSpec: IApplicationSpec, bundle: string) {\n return this.#events.withEvent(\n this.#events.factories.createApplicationExecuteEvent(\n appSpec,\n appSpec.url,\n ),\n async () => {\n const { instance } = await executeApplication(\n this.#events,\n appSpec,\n bundle,\n );\n return instance;\n },\n );\n }\n}\n","import { IApplicationSpec, IPrivateAPIFixMe } from '../types';\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\n\nimport { PlatformApplicationContainer } from './PlatformApplicationContainer';\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nexport class PlatformWorkerAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker\n> {\n #events = new PlatformAppEventEmitter();\n\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #container: PlatformApplicationContainer | null = null;\n #privateAPI: IPrivateAPIFixMe;\n\n #pendingWaiters: ((value: this) => void)[] = [];\n\n constructor() {\n super(\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker,\n );\n }\n\n create() {}\n\n async initEnvironment(props: {\n // TODO: should be Promise response in types\n buildPrivateAPI: (config: any) => IPrivateAPIFixMe;\n }) {\n const { buildPrivateAPI } = props;\n this.#privateAPI = await buildPrivateAPI({\n // TODO: should be per application (within the container before app execution)\n type: 'EDITOR_ADDON',\n });\n\n await this.injectEnvironmentContext({\n events: this.#events,\n privateApi: this.#privateAPI,\n applicationAPIs: {},\n });\n\n this.#container = new PlatformApplicationContainer(\n this.#privateAPI,\n this.#events,\n );\n\n this.#pendingWaiters.forEach((res) => res(this));\n }\n\n async notify(event: IPlatformPrivateEvent) {\n await this.waitReady();\n\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n\n async runApplication(app: IApplicationSpec) {\n await this.waitReady();\n\n await this.#container!.runApplication(app);\n }\n\n // TODO: should not be any waiters here\n // or should be implemented inside the events instances\n // collect queue until app is not ready\n public waitReady(): Promise<this> {\n return new Promise((res) => {\n if (this.#privateAPI) {\n return res(this);\n }\n\n this.#pendingWaiters.push(res);\n });\n }\n}\n","import {\n IFrameConsumerEndpoint,\n WorkerConsumerEndpoint,\n} from '@wix/editor-platform-transport';\n\nimport {\n ApplicationContext,\n EnvironmentContext,\n} from '@wix/editor-platform-contexts';\nimport { PlatformWorkerAPI, PlatformFrameAPI } from './api';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\n\nconst GUARD_PROP = '$_EP_TRANSPORT_ENV_CONTEXT_GUARD';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var $_EP_TRANSPORT_ENV_CONTEXT_GUARD: boolean;\n}\n\nexport class EditorPlatformContextEnvironment {\n isEnvironmentApiExposed() {\n return !!globalThis[GUARD_PROP];\n }\n\n async getContexts() {\n const [environmentContext, applicationContext] = await Promise.all([\n EnvironmentContext.getInstance(),\n ApplicationContext.getInstance(),\n ]);\n\n return {\n environmentContext,\n applicationContext,\n };\n }\n\n expose() {\n if (this.isEnvironmentApiExposed()) {\n return;\n }\n\n const isWorker = typeof importScripts === 'function';\n const isIframe =\n globalThis.self && globalThis.top && globalThis.self !== globalThis.top;\n\n /**\n * TODO: we can try to split this code somehow\n * and load the only API according to the current env.\n */\n if (isWorker) {\n this.#exposeWorkerAPI();\n globalThis[GUARD_PROP] = true;\n } else if (isIframe) {\n this.#exposeFrameAPI();\n globalThis[GUARD_PROP] = true;\n } else {\n /**\n * we expose env APIs only from worker or frame\n * but we have some cases when our code runs in the main thread\n * for example – builder component panels.\n */\n // if (!shouldPreventErrorLogs) {\n // console.error(\n // createEditorPlatformEnvironmentAPIError(\n // EditorPlatformEnvironmentAPIErrorErrorCode.IncorrectExpose,\n // 'seems current code is running in the main thread, while it is expected to be in iframe or worker',\n // ),\n // );\n // }\n }\n }\n\n #exposeWorkerAPI() {\n WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());\n }\n\n #exposeFrameAPI() {\n IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformEnvironmentAPIErrorErrorCode {\n ProxyEnvironmentConnectTimeout = 'ProxyEnvironmentConnectTimeout',\n ProxyWaitAPITimeout = 'ProxyWaitAPITimeout',\n ProxyContextsError = 'ProxyContextsError',\n IncorrectExpose = 'IncorrectExpose',\n}\n\nclass EditorPlatformEnvironmentAPIError extends BaseError<EditorPlatformEnvironmentAPIErrorErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformEnvironmentAPIErrorErrorCode,\n ) {\n super(message, code, 'EP EnvironmentAPI Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n}\n\nexport const createEditorPlatformEnvironmentAPIError = createErrorBuilder<\n EditorPlatformEnvironmentAPIErrorErrorCode,\n EditorPlatformEnvironmentAPIError\n>(EditorPlatformEnvironmentAPIError);\n","import { WorkerHostEndpoint } from '@wix/editor-platform-transport';\nimport { EditorPlatformContextEnvironment } from './EditorPlatformContextEnvironment';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\nimport {\n createEditorPlatformInternalError,\n EditorPlatformInternalErrorCode,\n} from '@wix/public-editor-platform-errors';\nimport { PlatformConsumerEnvironmentAPIType } from './api';\n\nexport class EditorPlatformEnvironmentProxy {\n async iframe() {\n throw createEditorPlatformInternalError(\n EditorPlatformInternalErrorCode.UnexpectedError,\n 'not supported',\n );\n }\n\n async worker(worker: Worker) {\n const environment = new EditorPlatformContextEnvironment();\n\n if (!environment.isEnvironmentApiExposed()) {\n environment.expose();\n }\n\n const connectTimeoutId = setTimeout(() => {\n console.info(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,\n 'probably worker environment does not expose platform API or any SDK function is never used',\n ),\n );\n }, 2_000);\n\n WorkerHostEndpoint.connect(worker, async (transport) => {\n clearTimeout(connectTimeoutId);\n\n const waitAPITimeoutId = setTimeout(() => {\n console.error(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout,\n ),\n );\n }, 2_000);\n\n const workerApi = await transport.waitAPI(\n PlatformConsumerEnvironmentAPIType.Worker,\n );\n\n clearTimeout(waitAPITimeoutId);\n\n try {\n const contexts = await environment.getContexts();\n\n await workerApi.injectEnvironmentContext({\n events: contexts.environmentContext.getEvents(),\n privateApi: contexts.environmentContext.getPrivateAPI(),\n applicationAPIs: contexts.environmentContext.getApplicationAPIs(),\n });\n\n await workerApi.injectApplicationContext({\n appDefinitionId: contexts.applicationContext.getAppDefinitionId(),\n });\n } catch (e: any) {\n throw createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError,\n ).withParentError(e);\n }\n });\n }\n}\n"],"names":["PlatformConsumerEnvironmentAPIType","EditorPlatformApplicationContainerErrorCode","EditorPlatformEnvironmentAPIErrorErrorCode"],"mappings":";;;;;;AAaO,MAAM,uBAAwB,CAAA;AAAA,EACnC,YAAoB,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA;AAAA;AAAA;AAAA,EAK1D,OAAO,KAA8B,EAAA;AAC1C,IAAA,QAAQ,MAAM,IAAM;AAAA,MAClB,KAAK,sBAAuB,CAAA,WAAA;AAC1B,QAAA,IAAA,CAAK,kBAAkB,MAAO,CAAA;AAAA,UAC5B,GAAG,KAAA;AAAA;AAAA,UAEH,MAAM,gBAAiB,CAAA,WAAA;AAAA,SACxB,CAAA,CAAA;AACD,QAAA,MAAA;AAAA,MACF,KAAK,oBAAqB,CAAA,SAAA;AACxB,QAAA,IAAA,CAAK,kBAAkB,MAAO,CAAA;AAAA,UAC5B,GAAG,KAAA;AAAA,UACH,MAAM,gBAAiB,CAAA,SAAA;AA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F,CAAA;AAAA,SACC,GAAK,CAAA,CAAA;AAER,MAAM,MAAA,SAAA,GAAY,MAAM,SAAU,CAAA,OAAA;AAAA,QAChC,kCAAmC,CAAA,MAAA;AAAA,OACrC,CAAA;AAEA,MAAA,YAAA,CAAa,gBAAgB,CAAA,CAAA;AAE7B,MAAI,IAAA;AACF,QAAM,MAAA,QAAA,GAAW,MAAM,WAAA,CAAY,WAAY,EAAA,CAAA;AAE/C,QAAA,MAAM,UAAU,wBAAyB,CAAA;AAAA,UACvC,MAAA,EAAQ,QAAS,CAAA,kBAAA,CAAmB,SAAU,EAAA;AAAA,UAC9C,UAAA,EAAY,QAAS,CAAA,kBAAA,CAAmB,aAAc,EAAA;AAAA,UACtD,eAAA,EAAiB,QAAS,CAAA,kBAAA,CAAmB,kBAAmB,EAAA;AAAA,SACjE,CAAA,CAAA;AAED,QAAA,MAAM,UAAU,wBAAyB,CAAA;AAAA,UACvC,eAAA,EAAiB,QAAS,CAAA,kBAAA,CAAmB,kBAAmB,EAAA;AAAA,SACjE,CAAA,CAAA;AAAA,eACM,CAAQ,EAAA;AACf,QAAM,MAAA,uCAAA;AAAA,UACJ,0CAA2C,CAAA,kBAAA;AAAA,SAC7C,CAAE,gBAAgB,CAAC,CAAA,CAAA;AAAA,OACrB;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/api/ApplicationEventsBridge/WorkerEventsBridge.ts","../../src/api/AbstractEnvironmentAPI.ts","../../src/api/PlatformFrameAPI/PlatformFrameAPI.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/errors.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/executeApplication.ts","../../src/api/PlatformWorkerAPI/PlatformApplicationContainer/PlatformApplicationContainer.ts","../../src/api/PlatformWorkerAPI/PlatformWorkerAPI.ts","../../src/EditorPlatformContextEnvironment.ts","../../src/errors.ts","../../src/EditorPlatformEnvironmentProxy.ts"],"sourcesContent":["import {\n IPlatformPrivateEvent,\n PlatformLifecycleEvent,\n PlatformPrivateEvent,\n // --\n IPlatformAppEvent,\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\n\n/**\n * The events bridge between platform events (private) and app events\n */\nexport class ApplicationEventsBridge {\n constructor(private platformAppEvents: PlatformAppEventEmitter) {}\n\n /**\n * Notify by event from Worker Manager (platform infrastructure)\n */\n public notify(event: IPlatformPrivateEvent) {\n switch (event.type) {\n case PlatformLifecycleEvent.EditorReady:\n this.platformAppEvents.notify({\n ...event,\n // @ts-expect-error TODO: fix me\n type: PlatformAppEvent.EditorReady,\n });\n break;\n case PlatformPrivateEvent.HostEvent:\n this.platformAppEvents.notify({\n ...event,\n type: PlatformAppEvent.HostEvent,\n });\n break;\n }\n }\n\n /**\n * Subscribe to Worker (Application) event\n */\n public subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.platformAppEvents.subscribe((event) => {\n cb(event);\n });\n }\n}\n","import {\n ApplicationContext,\n EnvironmentContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\nimport { PlatformAppEventEmitter } from '@wix/public-editor-platform-events';\nimport { IPrivateAPIFixMe } from './types';\nimport { IPlatformSDKContext } from '@wix/editor-platform-contexts';\n\nexport enum PlatformConsumerEnvironmentAPIType {\n Frame = 'PLATFORM_FRAME_API',\n Worker = 'PLATFORM_WORKER_API',\n}\n\n/**\n * rename these entities -> API to Env\n */\nexport abstract class AbstractEnvironmentAPI<\n TApiType extends PlatformConsumerEnvironmentAPIType,\n TEnv extends PlatformEnvironment,\n> {\n protected constructor(\n public type: TApiType,\n public envType: TEnv,\n ) {}\n\n abstract initEnvironment(props: unknown): void;\n\n async injectEnvironmentContext({\n events,\n privateApi,\n }: {\n events: PlatformAppEventEmitter;\n privateApi: IPrivateAPIFixMe;\n applicationAPIs?: Record<string, any>;\n }) {\n await EnvironmentContext.inject({\n environment: this.envType,\n events,\n privateApi,\n applicationAPIs: {},\n });\n }\n\n async injectApplicationContext(context: IPlatformSDKContext) {\n await ApplicationContext.inject(context);\n }\n}\n","import {\n IPlatformAppEvent,\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport {\n IPlatformSDKContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\nimport { IPrivateAPIFixMe } from '../types';\n\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nconst DESIGN_SYSTEM_STYLES_MAP = {\n classic:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css',\n studio:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css',\n};\n\nexport class PlatformFrameAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Frame,\n PlatformEnvironment.Frame\n> {\n #events = new PlatformAppEventEmitter();\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #privateAPI: IPrivateAPIFixMe;\n #applicationPrivateAPI: any;\n\n constructor() {\n super(PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame);\n\n this.#injectGlobalCSSTokens();\n }\n\n #injectGlobalCSSTokens() {\n if (typeof globalThis?.document?.head?.prepend === 'function') {\n const params = new URL(globalThis.location.href).searchParams;\n\n // TODO: check all possible editorType values\n const host =\n params.get('editorType') === 'CLASSIC' ? 'classic' : 'studio';\n\n const url = DESIGN_SYSTEM_STYLES_MAP[host];\n\n const isAlreadyLoaded =\n url &&\n !!document.querySelectorAll(`link[type=\"text/css\"][href=\"${url}\"]`)\n ?.length;\n\n if (url && !isAlreadyLoaded) {\n const link: HTMLLinkElement = document.createElement('link');\n\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('type', 'text/css');\n link.setAttribute('href', url);\n\n globalThis.document.head.prepend(link);\n }\n }\n }\n\n /**\n *\n * We need to introduce context versions\n * to simplify handling the backward compatibility issues\n */\n async initEnvironment(props: {\n // backward-compatibility\n appDefinitionId?: string;\n context: IPlatformSDKContext;\n privateAPI: IPrivateAPIFixMe;\n applicationPrivateAPI: any;\n }) {\n const { applicationPrivateAPI, privateAPI, context } = props;\n\n /**\n * backward-compatibility\n */\n const _appDefinitionId =\n props.context?.appDefinitionId ?? props.appDefinitionId;\n\n const _context = props.context\n ? props.context\n : {\n appDefinitionId: _appDefinitionId,\n };\n\n this.#applicationPrivateAPI = applicationPrivateAPI;\n this.#privateAPI = privateAPI;\n\n await this.injectEnvironmentContext({\n privateApi: privateAPI,\n events: this.#events,\n applicationAPIs: _appDefinitionId\n ? {\n [_appDefinitionId]: this.#applicationPrivateAPI,\n }\n : {},\n });\n\n await this.injectApplicationContext(_context);\n }\n\n notify(event: IPlatformPrivateEvent) {\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformApplicationContainerErrorCode {\n ApplicationLoadError = 'ApplicationLoadError',\n ApplicationFetchError = 'ApplicationFetchError',\n ApplicationExecuteError = 'ApplicationExecuteError',\n}\n\nclass EditorPlatformApplicationContainerError extends BaseError<EditorPlatformApplicationContainerErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n apiMethod: string;\n apiType: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformApplicationContainerErrorCode,\n ) {\n super(message, code, 'EP Application Container Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n\n withApiMethod(apiMethod: string) {\n this.state = { ...this.state, apiMethod };\n return this;\n }\n\n withApiType(apiType: string) {\n this.state = { ...this.state, apiType };\n return this;\n }\n}\n\nexport const createEditorPlatformApplicationContainerError = createErrorBuilder<\n EditorPlatformApplicationContainerErrorCode,\n EditorPlatformApplicationContainerError\n>(EditorPlatformApplicationContainerError);\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport {\n APPLICATION_CONTEXT_KEY,\n EnvironmentContext,\n ApplicationContext,\n} from '@wix/editor-platform-contexts';\n\nimport type { EditorPlatformApplication } from '@wix/editor-application';\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { IApplicationSpec } from '../../types';\n\nexport const APPLICATION_REGISTRY_KEY = '__APPLICATION_REGISTRY_KEY';\n\nexport type IApplicationRegistry = (\n _instance: EditorPlatformApplication,\n) => void;\n\nexport async function executeApplication(\n events: PlatformAppEventEmitter,\n spec: IApplicationSpec,\n bundle: string,\n): Promise<{\n instance: EditorPlatformApplication;\n}> {\n // eslint-disable-next-line no-new-func\n const executable = new Function(\n APPLICATION_CONTEXT_KEY,\n APPLICATION_REGISTRY_KEY,\n bundle,\n );\n\n let instance: EditorPlatformApplication | undefined;\n\n const applicationRegistryCallback: IApplicationRegistry = (_instance) => {\n if (instance) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry called more than once',\n ).withAppDefinitionId(spec.appDefinitionId);\n }\n\n if (_instance.type !== spec.type) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application has different type',\n )\n .withMessage('expected type', spec.type)\n .withMessage('received type', _instance.type);\n }\n\n instance = _instance;\n };\n\n try {\n const context = { ...spec };\n\n executable.call(\n null,\n new ApplicationContext(context, await EnvironmentContext.getInstance()),\n applicationRegistryCallback,\n );\n } catch (e: unknown) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n (e as Error).message,\n )\n .withAppDefinitionId(spec.appDefinitionId)\n .withParentError(e as Error);\n }\n\n return new Promise((resolve, reject) => {\n const unsubscribe = events.subscribe((event) => {\n const timeoutId = setTimeout(() => {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called, threw by timeout',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n }, 5000);\n\n if (\n event.type === PlatformAppEvent.ApplicationInit &&\n event.meta.appDefinitionId === spec.appDefinitionId\n ) {\n clearTimeout(timeoutId);\n unsubscribe();\n\n if (!instance) {\n reject(\n createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,\n 'Application registry was not called',\n ).withAppDefinitionId(spec.appDefinitionId),\n );\n }\n\n resolve({ instance: instance! });\n }\n });\n });\n}\n","import {\n PlatformAppEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { EventType } from '@wix/public-editor-platform-interfaces';\n\nimport {\n createEditorPlatformApplicationContainerError,\n EditorPlatformApplicationContainerErrorCode,\n} from './errors';\nimport { EditorPlatformApplication } from '@wix/editor-application';\nimport { type IApplicationSpec, type IPrivateAPIFixMe } from '../../types';\nimport { executeApplication } from './executeApplication';\n\nexport class PlatformApplicationContainer {\n #apps: Record<string, EditorPlatformApplication> = {};\n\n readonly #privateAPI: IPrivateAPIFixMe;\n readonly #events: PlatformAppEventEmitter;\n\n constructor(privateApi: IPrivateAPIFixMe, events: PlatformAppEventEmitter) {\n this.#privateAPI = privateApi;\n this.#events = events;\n\n this.#events.subscribe((event) => {\n switch (event.type) {\n case PlatformAppEvent.HostEvent: {\n if (event.payload.type === EventType.removeAppCompleted) {\n void this.#events.withEvent(\n this.#events.factories.createApplicationRemovedEvent(\n event.payload.appDefinitionId!,\n ),\n () => {\n return this.removeApplication(event.payload.appDefinitionId!);\n },\n );\n }\n break;\n }\n }\n });\n }\n\n public async runApplication(appSpec: IApplicationSpec) {\n const bundle = await this.loadApplication(appSpec);\n const instance = await this.executeApplication(appSpec, bundle);\n\n this.setApplication(appSpec.appDefinitionId, instance);\n\n return instance;\n }\n\n private setApplication(\n appDefId: string,\n instance: EditorPlatformApplication,\n ) {\n this.#apps[appDefId] = instance;\n\n void this.#events.withEvent(\n this.#events.factories.createApplicationApiInitEvent(\n appDefId,\n // TODO: both types are set here...\n // @ts-expect-error TODO: fix me\n instance?.api?.private ? 'private' : 'public',\n ),\n () => {\n // NOTE: sometimes I saw this method was called while application was not executed\n this.#privateAPI.applicationManager.setApplication(instance);\n },\n );\n }\n\n public getApplication(appDefId: string) {\n return this.#apps[appDefId];\n }\n\n public getAppDefinitionIds() {\n return Object.keys(this.#apps);\n }\n\n private removeApplication(appDefinitionId: string) {\n // eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n delete this.#apps[appDefinitionId];\n }\n\n private async loadApplication(appSpec: IApplicationSpec) {\n const url = appSpec.url;\n\n return this.#events.withEvent(\n this.#events.factories.createApplicationLoadEvent(appSpec, url),\n\n async () => {\n try {\n return await this.loadApplicationBundle(url);\n } catch (e) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationLoadError,\n )\n .withUrl(url)\n .withAppDefinitionId(appSpec.appDefinitionId)\n .withParentError(e as any);\n }\n },\n );\n }\n\n private async loadApplicationBundle(url: string) {\n /**\n * NOTE: we don't use wix http client here\n * because this code is public, while http client is private\n */\n const res = await fetch(url, {\n method: 'GET',\n });\n\n const isSuccessfulResponse = res.status >= 200 && res.status <= 299;\n\n if (!isSuccessfulResponse) {\n throw createEditorPlatformApplicationContainerError(\n EditorPlatformApplicationContainerErrorCode.ApplicationFetchError,\n ).withUrl(url);\n }\n\n return res.text();\n }\n\n private async executeApplication(appSpec: IApplicationSpec, bundle: string) {\n return this.#events.withEvent(\n this.#events.factories.createApplicationExecuteEvent(\n appSpec,\n appSpec.url,\n ),\n async () => {\n const { instance } = await executeApplication(\n this.#events,\n appSpec,\n bundle,\n );\n return instance;\n },\n );\n }\n}\n","import { IApplicationSpec, IPrivateAPIFixMe } from '../types';\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\n\nimport { PlatformApplicationContainer } from './PlatformApplicationContainer';\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nexport class PlatformWorkerAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker\n> {\n #events = new PlatformAppEventEmitter();\n\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #container: PlatformApplicationContainer | null = null;\n #privateAPI: IPrivateAPIFixMe;\n\n #pendingWaiters: ((value: this) => void)[] = [];\n\n constructor() {\n super(\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker,\n );\n }\n\n create() {}\n\n async initEnvironment(props: {\n // TODO: should be Promise response in types\n buildPrivateAPI: (config: any) => IPrivateAPIFixMe;\n }) {\n const { buildPrivateAPI } = props;\n this.#privateAPI = await buildPrivateAPI({\n // TODO: should be per application (within the container before app execution)\n type: 'EDITOR_ADDON',\n });\n\n await this.injectEnvironmentContext({\n events: this.#events,\n privateApi: this.#privateAPI,\n applicationAPIs: {},\n });\n\n this.#container = new PlatformApplicationContainer(\n this.#privateAPI,\n this.#events,\n );\n\n this.#pendingWaiters.forEach((res) => res(this));\n }\n\n async notify(event: IPlatformPrivateEvent) {\n await this.waitReady();\n\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n\n async runApplication(app: IApplicationSpec) {\n await this.waitReady();\n\n await this.#container!.runApplication(app);\n }\n\n // TODO: should not be any waiters here\n // or should be implemented inside the events instances\n // collect queue until app is not ready\n public waitReady(): Promise<this> {\n return new Promise((res) => {\n if (this.#privateAPI) {\n return res(this);\n }\n\n this.#pendingWaiters.push(res);\n });\n }\n}\n","import {\n IFrameConsumerEndpoint,\n WorkerConsumerEndpoint,\n} from '@wix/editor-platform-transport';\n\nimport {\n ApplicationContext,\n EnvironmentContext,\n} from '@wix/editor-platform-contexts';\nimport { PlatformWorkerAPI, PlatformFrameAPI } from './api';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\n\nconst GUARD_PROP = '$_EP_TRANSPORT_ENV_CONTEXT_GUARD';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var $_EP_TRANSPORT_ENV_CONTEXT_GUARD: boolean;\n}\n\nexport class EditorPlatformContextEnvironment {\n isEnvironmentApiExposed() {\n return !!globalThis[GUARD_PROP];\n }\n\n async getContexts() {\n const [environmentContext, applicationContext] = await Promise.all([\n EnvironmentContext.getInstance(),\n ApplicationContext.getInstance(),\n ]);\n\n return {\n environmentContext,\n applicationContext,\n };\n }\n\n expose() {\n if (this.isEnvironmentApiExposed()) {\n return;\n }\n\n const isWorker = typeof importScripts === 'function';\n const isIframe =\n globalThis.self && globalThis.top && globalThis.self !== globalThis.top;\n\n /**\n * TODO: we can try to split this code somehow\n * and load the only API according to the current env.\n */\n if (isWorker) {\n this.#exposeWorkerAPI();\n globalThis[GUARD_PROP] = true;\n } else if (isIframe) {\n this.#exposeFrameAPI();\n globalThis[GUARD_PROP] = true;\n } else {\n /**\n * we expose env APIs only from worker or frame\n * but we have some cases when our code runs in the main thread\n * for example – builder component panels.\n */\n // if (!shouldPreventErrorLogs) {\n // console.error(\n // createEditorPlatformEnvironmentAPIError(\n // EditorPlatformEnvironmentAPIErrorErrorCode.IncorrectExpose,\n // 'seems current code is running in the main thread, while it is expected to be in iframe or worker',\n // ),\n // );\n // }\n }\n }\n\n #exposeWorkerAPI() {\n WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());\n }\n\n #exposeFrameAPI() {\n IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());\n }\n}\n","import {\n BaseError,\n createErrorBuilder,\n} from '@wix/public-editor-platform-errors';\n\nexport enum EditorPlatformEnvironmentAPIErrorErrorCode {\n ProxyEnvironmentConnectTimeout = 'ProxyEnvironmentConnectTimeout',\n ProxyWaitAPITimeout = 'ProxyWaitAPITimeout',\n ProxyContextsError = 'ProxyContextsError',\n IncorrectExpose = 'IncorrectExpose',\n}\n\nclass EditorPlatformEnvironmentAPIError extends BaseError<EditorPlatformEnvironmentAPIErrorErrorCode> {\n state: Partial<{\n url: string;\n appDefinitionId: string;\n }> = {};\n\n constructor(\n message: string,\n code: EditorPlatformEnvironmentAPIErrorErrorCode,\n ) {\n super(message, code, 'EP EnvironmentAPI Error');\n }\n\n withUrl(url: string) {\n this.state = { ...this.state, url };\n return this;\n }\n\n withAppDefinitionId(appDefinitionId: string) {\n this.state = { ...this.state, appDefinitionId };\n return this;\n }\n}\n\nexport const createEditorPlatformEnvironmentAPIError = createErrorBuilder<\n EditorPlatformEnvironmentAPIErrorErrorCode,\n EditorPlatformEnvironmentAPIError\n>(EditorPlatformEnvironmentAPIError);\n","import { WorkerHostEndpoint } from '@wix/editor-platform-transport';\nimport { EditorPlatformContextEnvironment } from './EditorPlatformContextEnvironment';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\nimport {\n createEditorPlatformInternalError,\n EditorPlatformInternalErrorCode,\n} from '@wix/public-editor-platform-errors';\nimport { PlatformConsumerEnvironmentAPIType } from './api';\n\nexport class EditorPlatformEnvironmentProxy {\n async iframe() {\n throw createEditorPlatformInternalError(\n EditorPlatformInternalErrorCode.UnexpectedError,\n 'not supported',\n );\n }\n\n async worker(worker: Worker) {\n const environment = new EditorPlatformContextEnvironment();\n\n if (!environment.isEnvironmentApiExposed()) {\n environment.expose();\n }\n\n const connectTimeoutId = setTimeout(() => {\n console.info(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,\n 'probably worker environment does not expose platform API or any SDK function is never used',\n ),\n );\n }, 2_000);\n\n WorkerHostEndpoint.connect(worker, async (transport) => {\n clearTimeout(connectTimeoutId);\n\n const waitAPITimeoutId = setTimeout(() => {\n console.error(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout,\n ),\n );\n }, 2_000);\n\n const workerApi = await transport.waitAPI(\n PlatformConsumerEnvironmentAPIType.Worker,\n );\n\n clearTimeout(waitAPITimeoutId);\n\n try {\n const contexts = await environment.getContexts();\n\n await workerApi.injectEnvironmentContext({\n events: contexts.environmentContext.getEvents(),\n privateApi: contexts.environmentContext.getPrivateAPI(),\n applicationAPIs: contexts.environmentContext.getApplicationAPIs(),\n });\n\n await workerApi.injectApplicationContext(\n contexts.applicationContext.getContext(),\n );\n } catch (e: any) {\n throw createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError,\n ).withParentError(e);\n }\n });\n }\n}\n"],"names":["PlatformConsumerEnvironmentAPIType","EditorPlatformApplicationContainerErrorCode","EditorPlatformEnvironmentAPIErrorErrorCode"],"mappings":";;;;;;AAaO,MAAM,uBAAwB,CAAA;AAAA,EACnC,YAAoB,iBAA4C,EAAA;AAA5C,IAAA,IAAA,CAAA,iBAAA,GAAA,iBAAA,CAAA;AAAA,GAA6C;AAAA;AAAA;AAAA;AAAA,EAK1D,OAAO,KAA8B,EAAA;AAC1C,IAAA,QAAQ,MAAM,IAAM;AAAA,MAClB,KAAK,sBAAuB,CAAA,WAAA;AAC1B,QAAA,IAAA,CAAK,kBAAkB,MAAO,CAAA;AAAA,UAC5B,GAAG,KAAA;AAAA;AAAA,UAEH,MAAM,gBAAiB,CAAA,WAAA;AAAA,SACxB,CAAA,CAAA;AACD,QAAA,MAAA;AAAA,MACF,KA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|
-
import
|
|
3
|
-
import { PlatformEnvironment, EnvironmentContext, ApplicationContext } from '@wix/editor-platform-contexts';
|
|
2
|
+
import { PlatformEnvironment, IPlatformSDKContext, EnvironmentContext, ApplicationContext } from '@wix/editor-platform-contexts';
|
|
4
3
|
|
|
5
4
|
type IPrivateAPIFixMe = any;
|
|
6
5
|
type IApplicationSpec = any;
|
|
@@ -22,16 +21,20 @@ declare abstract class AbstractEnvironmentAPI<TApiType extends PlatformConsumerE
|
|
|
22
21
|
privateApi: IPrivateAPIFixMe;
|
|
23
22
|
applicationAPIs?: Record<string, any>;
|
|
24
23
|
}): Promise<void>;
|
|
25
|
-
injectApplicationContext(
|
|
26
|
-
appDefinitionId: string;
|
|
27
|
-
}): Promise<void>;
|
|
24
|
+
injectApplicationContext(context: IPlatformSDKContext): Promise<void>;
|
|
28
25
|
}
|
|
29
26
|
|
|
30
27
|
declare class PlatformFrameAPI extends AbstractEnvironmentAPI<PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame> {
|
|
31
28
|
#private;
|
|
32
29
|
constructor();
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* We need to introduce context versions
|
|
33
|
+
* to simplify handling the backward compatibility issues
|
|
34
|
+
*/
|
|
33
35
|
initEnvironment(props: {
|
|
34
|
-
appDefinitionId
|
|
36
|
+
appDefinitionId?: string;
|
|
37
|
+
context: IPlatformSDKContext;
|
|
35
38
|
privateAPI: IPrivateAPIFixMe;
|
|
36
39
|
applicationPrivateAPI: any;
|
|
37
40
|
}): Promise<void>;
|
|
@@ -65,7 +68,7 @@ declare class EditorPlatformContextEnvironment {
|
|
|
65
68
|
isEnvironmentApiExposed(): boolean;
|
|
66
69
|
getContexts(): Promise<{
|
|
67
70
|
environmentContext: EnvironmentContext;
|
|
68
|
-
applicationContext: ApplicationContext
|
|
71
|
+
applicationContext: ApplicationContext;
|
|
69
72
|
}>;
|
|
70
73
|
expose(): void;
|
|
71
74
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":["../../src/api/types.ts","../../src/api/AbstractEnvironmentAPI.ts","../../src/api/PlatformFrameAPI/PlatformFrameAPI.ts","../../src/api/PlatformWorkerAPI/PlatformWorkerAPI.ts","../../src/EditorPlatformEnvironmentProxy.ts","../../src/EditorPlatformContextEnvironment.ts"],"sourcesContent":["// TODO: replace with the real type WrappedPrivateAPI\nexport type IPrivateAPIFixMe = any;\n// TODO: fix any\nexport type IApplicationSpec = any;\n","import {\n ApplicationContext,\n EnvironmentContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\nimport { PlatformAppEventEmitter } from '@wix/public-editor-platform-events';\nimport { IPrivateAPIFixMe } from './types';\n\nexport enum PlatformConsumerEnvironmentAPIType {\n Frame = 'PLATFORM_FRAME_API',\n Worker = 'PLATFORM_WORKER_API',\n}\n\n/**\n * rename these entities -> API to Env\n */\nexport abstract class AbstractEnvironmentAPI<\n TApiType extends PlatformConsumerEnvironmentAPIType,\n TEnv extends PlatformEnvironment,\n> {\n protected constructor(\n public type: TApiType,\n public envType: TEnv,\n ) {}\n\n abstract initEnvironment(props: unknown): void;\n\n async injectEnvironmentContext({\n events,\n privateApi,\n }: {\n events: PlatformAppEventEmitter;\n privateApi: IPrivateAPIFixMe;\n applicationAPIs?: Record<string, any>;\n }) {\n await EnvironmentContext.inject({\n environment: this.envType,\n events,\n privateApi,\n applicationAPIs: {},\n });\n }\n\n async injectApplicationContext({\n appDefinitionId,\n }: {\n appDefinitionId: string;\n }) {\n await ApplicationContext.inject({\n appDefinitionId,\n // ?\n // anyway, it is not used atm\n appDefinitionName: '',\n });\n }\n}\n","import {\n IPlatformAppEvent,\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\nimport { IPrivateAPIFixMe } from '../types';\n\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nconst DESIGN_SYSTEM_STYLES_MAP = {\n classic:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css',\n studio:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css',\n};\n\nexport class PlatformFrameAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Frame,\n PlatformEnvironment.Frame\n> {\n #events = new PlatformAppEventEmitter();\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #privateAPI: IPrivateAPIFixMe;\n #applicationPrivateAPI: any;\n\n constructor() {\n super(PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame);\n\n this.#injectGlobalCSSTokens();\n }\n\n #injectGlobalCSSTokens() {\n if (typeof globalThis?.document?.head?.prepend === 'function') {\n const params = new URL(globalThis.location.href).searchParams;\n\n // TODO: check all possible editorType values\n const host =\n params.get('editorType') === 'CLASSIC' ? 'classic' : 'studio';\n\n const url = DESIGN_SYSTEM_STYLES_MAP[host];\n\n const isAlreadyLoaded =\n url &&\n !!document.querySelectorAll(`link[type=\"text/css\"][href=\"${url}\"]`)\n ?.length;\n\n if (url && !isAlreadyLoaded) {\n const link: HTMLLinkElement = document.createElement('link');\n\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('type', 'text/css');\n link.setAttribute('href', url);\n\n globalThis.document.head.prepend(link);\n }\n }\n }\n\n async initEnvironment(props: {\n appDefinitionId: string;\n privateAPI: IPrivateAPIFixMe;\n applicationPrivateAPI: any;\n }) {\n const { applicationPrivateAPI, privateAPI, appDefinitionId } = props;\n\n this.#applicationPrivateAPI = applicationPrivateAPI;\n this.#privateAPI = privateAPI;\n\n await this.injectEnvironmentContext({\n privateApi: privateAPI,\n events: this.#events,\n applicationAPIs: {\n [appDefinitionId]: this.#applicationPrivateAPI,\n },\n });\n\n await this.injectApplicationContext({\n appDefinitionId,\n });\n }\n\n notify(event: IPlatformPrivateEvent) {\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n}\n","import { IApplicationSpec, IPrivateAPIFixMe } from '../types';\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\n\nimport { PlatformApplicationContainer } from './PlatformApplicationContainer';\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nexport class PlatformWorkerAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker\n> {\n #events = new PlatformAppEventEmitter();\n\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #container: PlatformApplicationContainer | null = null;\n #privateAPI: IPrivateAPIFixMe;\n\n #pendingWaiters: ((value: this) => void)[] = [];\n\n constructor() {\n super(\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker,\n );\n }\n\n create() {}\n\n async initEnvironment(props: {\n // TODO: should be Promise response in types\n buildPrivateAPI: (config: any) => IPrivateAPIFixMe;\n }) {\n const { buildPrivateAPI } = props;\n this.#privateAPI = await buildPrivateAPI({\n // TODO: should be per application (within the container before app execution)\n type: 'EDITOR_ADDON',\n });\n\n await this.injectEnvironmentContext({\n events: this.#events,\n privateApi: this.#privateAPI,\n applicationAPIs: {},\n });\n\n this.#container = new PlatformApplicationContainer(\n this.#privateAPI,\n this.#events,\n );\n\n this.#pendingWaiters.forEach((res) => res(this));\n }\n\n async notify(event: IPlatformPrivateEvent) {\n await this.waitReady();\n\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n\n async runApplication(app: IApplicationSpec) {\n await this.waitReady();\n\n await this.#container!.runApplication(app);\n }\n\n // TODO: should not be any waiters here\n // or should be implemented inside the events instances\n // collect queue until app is not ready\n public waitReady(): Promise<this> {\n return new Promise((res) => {\n if (this.#privateAPI) {\n return res(this);\n }\n\n this.#pendingWaiters.push(res);\n });\n }\n}\n","import { WorkerHostEndpoint } from '@wix/editor-platform-transport';\nimport { EditorPlatformContextEnvironment } from './EditorPlatformContextEnvironment';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\nimport {\n createEditorPlatformInternalError,\n EditorPlatformInternalErrorCode,\n} from '@wix/public-editor-platform-errors';\nimport { PlatformConsumerEnvironmentAPIType } from './api';\n\nexport class EditorPlatformEnvironmentProxy {\n async iframe() {\n throw createEditorPlatformInternalError(\n EditorPlatformInternalErrorCode.UnexpectedError,\n 'not supported',\n );\n }\n\n async worker(worker: Worker) {\n const environment = new EditorPlatformContextEnvironment();\n\n if (!environment.isEnvironmentApiExposed()) {\n environment.expose();\n }\n\n const connectTimeoutId = setTimeout(() => {\n console.info(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,\n 'probably worker environment does not expose platform API or any SDK function is never used',\n ),\n );\n }, 2_000);\n\n WorkerHostEndpoint.connect(worker, async (transport) => {\n clearTimeout(connectTimeoutId);\n\n const waitAPITimeoutId = setTimeout(() => {\n console.error(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout,\n ),\n );\n }, 2_000);\n\n const workerApi = await transport.waitAPI(\n PlatformConsumerEnvironmentAPIType.Worker,\n );\n\n clearTimeout(waitAPITimeoutId);\n\n try {\n const contexts = await environment.getContexts();\n\n await workerApi.injectEnvironmentContext({\n events: contexts.environmentContext.getEvents(),\n privateApi: contexts.environmentContext.getPrivateAPI(),\n applicationAPIs: contexts.environmentContext.getApplicationAPIs(),\n });\n\n await workerApi.injectApplicationContext({\n appDefinitionId: contexts.applicationContext.getAppDefinitionId(),\n });\n } catch (e: any) {\n throw createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError,\n ).withParentError(e);\n }\n });\n }\n}\n","import {\n IFrameConsumerEndpoint,\n WorkerConsumerEndpoint,\n} from '@wix/editor-platform-transport';\n\nimport {\n ApplicationContext,\n EnvironmentContext,\n} from '@wix/editor-platform-contexts';\nimport { PlatformWorkerAPI, PlatformFrameAPI } from './api';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\n\nconst GUARD_PROP = '$_EP_TRANSPORT_ENV_CONTEXT_GUARD';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var $_EP_TRANSPORT_ENV_CONTEXT_GUARD: boolean;\n}\n\nexport class EditorPlatformContextEnvironment {\n isEnvironmentApiExposed() {\n return !!globalThis[GUARD_PROP];\n }\n\n async getContexts() {\n const [environmentContext, applicationContext] = await Promise.all([\n EnvironmentContext.getInstance(),\n ApplicationContext.getInstance(),\n ]);\n\n return {\n environmentContext,\n applicationContext,\n };\n }\n\n expose() {\n if (this.isEnvironmentApiExposed()) {\n return;\n }\n\n const isWorker = typeof importScripts === 'function';\n const isIframe =\n globalThis.self && globalThis.top && globalThis.self !== globalThis.top;\n\n /**\n * TODO: we can try to split this code somehow\n * and load the only API according to the current env.\n */\n if (isWorker) {\n this.#exposeWorkerAPI();\n globalThis[GUARD_PROP] = true;\n } else if (isIframe) {\n this.#exposeFrameAPI();\n globalThis[GUARD_PROP] = true;\n } else {\n /**\n * we expose env APIs only from worker or frame\n * but we have some cases when our code runs in the main thread\n * for example – builder component panels.\n */\n // if (!shouldPreventErrorLogs) {\n // console.error(\n // createEditorPlatformEnvironmentAPIError(\n // EditorPlatformEnvironmentAPIErrorErrorCode.IncorrectExpose,\n // 'seems current code is running in the main thread, while it is expected to be in iframe or worker',\n // ),\n // );\n // }\n }\n }\n\n #exposeWorkerAPI() {\n WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());\n }\n\n #exposeFrameAPI() {\n IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());\n }\n}\n"],"names":[],"mappings":";;;;AAAO;AACA;;ACEA;AACP;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACnBO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACVO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACfO;AACP;AACA;AACA;;ACFA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sources":["../../src/api/types.ts","../../src/api/AbstractEnvironmentAPI.ts","../../src/api/PlatformFrameAPI/PlatformFrameAPI.ts","../../src/api/PlatformWorkerAPI/PlatformWorkerAPI.ts","../../src/EditorPlatformEnvironmentProxy.ts","../../src/EditorPlatformContextEnvironment.ts"],"sourcesContent":["// TODO: replace with the real type WrappedPrivateAPI\nexport type IPrivateAPIFixMe = any;\n// TODO: fix any\nexport type IApplicationSpec = any;\n","import {\n ApplicationContext,\n EnvironmentContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\nimport { PlatformAppEventEmitter } from '@wix/public-editor-platform-events';\nimport { IPrivateAPIFixMe } from './types';\nimport { IPlatformSDKContext } from '@wix/editor-platform-contexts';\n\nexport enum PlatformConsumerEnvironmentAPIType {\n Frame = 'PLATFORM_FRAME_API',\n Worker = 'PLATFORM_WORKER_API',\n}\n\n/**\n * rename these entities -> API to Env\n */\nexport abstract class AbstractEnvironmentAPI<\n TApiType extends PlatformConsumerEnvironmentAPIType,\n TEnv extends PlatformEnvironment,\n> {\n protected constructor(\n public type: TApiType,\n public envType: TEnv,\n ) {}\n\n abstract initEnvironment(props: unknown): void;\n\n async injectEnvironmentContext({\n events,\n privateApi,\n }: {\n events: PlatformAppEventEmitter;\n privateApi: IPrivateAPIFixMe;\n applicationAPIs?: Record<string, any>;\n }) {\n await EnvironmentContext.inject({\n environment: this.envType,\n events,\n privateApi,\n applicationAPIs: {},\n });\n }\n\n async injectApplicationContext(context: IPlatformSDKContext) {\n await ApplicationContext.inject(context);\n }\n}\n","import {\n IPlatformAppEvent,\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n} from '@wix/public-editor-platform-events';\nimport {\n IPlatformSDKContext,\n PlatformEnvironment,\n} from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\nimport { IPrivateAPIFixMe } from '../types';\n\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nconst DESIGN_SYSTEM_STYLES_MAP = {\n classic:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css',\n studio:\n 'https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css',\n};\n\nexport class PlatformFrameAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Frame,\n PlatformEnvironment.Frame\n> {\n #events = new PlatformAppEventEmitter();\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #privateAPI: IPrivateAPIFixMe;\n #applicationPrivateAPI: any;\n\n constructor() {\n super(PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame);\n\n this.#injectGlobalCSSTokens();\n }\n\n #injectGlobalCSSTokens() {\n if (typeof globalThis?.document?.head?.prepend === 'function') {\n const params = new URL(globalThis.location.href).searchParams;\n\n // TODO: check all possible editorType values\n const host =\n params.get('editorType') === 'CLASSIC' ? 'classic' : 'studio';\n\n const url = DESIGN_SYSTEM_STYLES_MAP[host];\n\n const isAlreadyLoaded =\n url &&\n !!document.querySelectorAll(`link[type=\"text/css\"][href=\"${url}\"]`)\n ?.length;\n\n if (url && !isAlreadyLoaded) {\n const link: HTMLLinkElement = document.createElement('link');\n\n link.setAttribute('rel', 'stylesheet');\n link.setAttribute('type', 'text/css');\n link.setAttribute('href', url);\n\n globalThis.document.head.prepend(link);\n }\n }\n }\n\n /**\n *\n * We need to introduce context versions\n * to simplify handling the backward compatibility issues\n */\n async initEnvironment(props: {\n // backward-compatibility\n appDefinitionId?: string;\n context: IPlatformSDKContext;\n privateAPI: IPrivateAPIFixMe;\n applicationPrivateAPI: any;\n }) {\n const { applicationPrivateAPI, privateAPI, context } = props;\n\n /**\n * backward-compatibility\n */\n const _appDefinitionId =\n props.context?.appDefinitionId ?? props.appDefinitionId;\n\n const _context = props.context\n ? props.context\n : {\n appDefinitionId: _appDefinitionId,\n };\n\n this.#applicationPrivateAPI = applicationPrivateAPI;\n this.#privateAPI = privateAPI;\n\n await this.injectEnvironmentContext({\n privateApi: privateAPI,\n events: this.#events,\n applicationAPIs: _appDefinitionId\n ? {\n [_appDefinitionId]: this.#applicationPrivateAPI,\n }\n : {},\n });\n\n await this.injectApplicationContext(_context);\n }\n\n notify(event: IPlatformPrivateEvent) {\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n}\n","import { IApplicationSpec, IPrivateAPIFixMe } from '../types';\nimport {\n IPlatformPrivateEvent,\n PlatformAppEventEmitter,\n IPlatformAppEvent,\n} from '@wix/public-editor-platform-events';\nimport { PlatformEnvironment } from '@wix/editor-platform-contexts';\n\nimport { ApplicationEventsBridge } from '../ApplicationEventsBridge';\n\nimport { PlatformApplicationContainer } from './PlatformApplicationContainer';\nimport {\n AbstractEnvironmentAPI,\n PlatformConsumerEnvironmentAPIType,\n} from '../AbstractEnvironmentAPI';\n\nexport class PlatformWorkerAPI extends AbstractEnvironmentAPI<\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker\n> {\n #events = new PlatformAppEventEmitter();\n\n #eventsBridge = new ApplicationEventsBridge(this.#events);\n #container: PlatformApplicationContainer | null = null;\n #privateAPI: IPrivateAPIFixMe;\n\n #pendingWaiters: ((value: this) => void)[] = [];\n\n constructor() {\n super(\n PlatformConsumerEnvironmentAPIType.Worker,\n PlatformEnvironment.Worker,\n );\n }\n\n create() {}\n\n async initEnvironment(props: {\n // TODO: should be Promise response in types\n buildPrivateAPI: (config: any) => IPrivateAPIFixMe;\n }) {\n const { buildPrivateAPI } = props;\n this.#privateAPI = await buildPrivateAPI({\n // TODO: should be per application (within the container before app execution)\n type: 'EDITOR_ADDON',\n });\n\n await this.injectEnvironmentContext({\n events: this.#events,\n privateApi: this.#privateAPI,\n applicationAPIs: {},\n });\n\n this.#container = new PlatformApplicationContainer(\n this.#privateAPI,\n this.#events,\n );\n\n this.#pendingWaiters.forEach((res) => res(this));\n }\n\n async notify(event: IPlatformPrivateEvent) {\n await this.waitReady();\n\n this.#eventsBridge.notify(event);\n }\n\n subscribe(cb: (event: IPlatformAppEvent) => void) {\n this.#eventsBridge.subscribe(cb);\n }\n\n async runApplication(app: IApplicationSpec) {\n await this.waitReady();\n\n await this.#container!.runApplication(app);\n }\n\n // TODO: should not be any waiters here\n // or should be implemented inside the events instances\n // collect queue until app is not ready\n public waitReady(): Promise<this> {\n return new Promise((res) => {\n if (this.#privateAPI) {\n return res(this);\n }\n\n this.#pendingWaiters.push(res);\n });\n }\n}\n","import { WorkerHostEndpoint } from '@wix/editor-platform-transport';\nimport { EditorPlatformContextEnvironment } from './EditorPlatformContextEnvironment';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\nimport {\n createEditorPlatformInternalError,\n EditorPlatformInternalErrorCode,\n} from '@wix/public-editor-platform-errors';\nimport { PlatformConsumerEnvironmentAPIType } from './api';\n\nexport class EditorPlatformEnvironmentProxy {\n async iframe() {\n throw createEditorPlatformInternalError(\n EditorPlatformInternalErrorCode.UnexpectedError,\n 'not supported',\n );\n }\n\n async worker(worker: Worker) {\n const environment = new EditorPlatformContextEnvironment();\n\n if (!environment.isEnvironmentApiExposed()) {\n environment.expose();\n }\n\n const connectTimeoutId = setTimeout(() => {\n console.info(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,\n 'probably worker environment does not expose platform API or any SDK function is never used',\n ),\n );\n }, 2_000);\n\n WorkerHostEndpoint.connect(worker, async (transport) => {\n clearTimeout(connectTimeoutId);\n\n const waitAPITimeoutId = setTimeout(() => {\n console.error(\n createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout,\n ),\n );\n }, 2_000);\n\n const workerApi = await transport.waitAPI(\n PlatformConsumerEnvironmentAPIType.Worker,\n );\n\n clearTimeout(waitAPITimeoutId);\n\n try {\n const contexts = await environment.getContexts();\n\n await workerApi.injectEnvironmentContext({\n events: contexts.environmentContext.getEvents(),\n privateApi: contexts.environmentContext.getPrivateAPI(),\n applicationAPIs: contexts.environmentContext.getApplicationAPIs(),\n });\n\n await workerApi.injectApplicationContext(\n contexts.applicationContext.getContext(),\n );\n } catch (e: any) {\n throw createEditorPlatformEnvironmentAPIError(\n EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError,\n ).withParentError(e);\n }\n });\n }\n}\n","import {\n IFrameConsumerEndpoint,\n WorkerConsumerEndpoint,\n} from '@wix/editor-platform-transport';\n\nimport {\n ApplicationContext,\n EnvironmentContext,\n} from '@wix/editor-platform-contexts';\nimport { PlatformWorkerAPI, PlatformFrameAPI } from './api';\nimport {\n createEditorPlatformEnvironmentAPIError,\n EditorPlatformEnvironmentAPIErrorErrorCode,\n} from './errors';\n\nconst GUARD_PROP = '$_EP_TRANSPORT_ENV_CONTEXT_GUARD';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var $_EP_TRANSPORT_ENV_CONTEXT_GUARD: boolean;\n}\n\nexport class EditorPlatformContextEnvironment {\n isEnvironmentApiExposed() {\n return !!globalThis[GUARD_PROP];\n }\n\n async getContexts() {\n const [environmentContext, applicationContext] = await Promise.all([\n EnvironmentContext.getInstance(),\n ApplicationContext.getInstance(),\n ]);\n\n return {\n environmentContext,\n applicationContext,\n };\n }\n\n expose() {\n if (this.isEnvironmentApiExposed()) {\n return;\n }\n\n const isWorker = typeof importScripts === 'function';\n const isIframe =\n globalThis.self && globalThis.top && globalThis.self !== globalThis.top;\n\n /**\n * TODO: we can try to split this code somehow\n * and load the only API according to the current env.\n */\n if (isWorker) {\n this.#exposeWorkerAPI();\n globalThis[GUARD_PROP] = true;\n } else if (isIframe) {\n this.#exposeFrameAPI();\n globalThis[GUARD_PROP] = true;\n } else {\n /**\n * we expose env APIs only from worker or frame\n * but we have some cases when our code runs in the main thread\n * for example – builder component panels.\n */\n // if (!shouldPreventErrorLogs) {\n // console.error(\n // createEditorPlatformEnvironmentAPIError(\n // EditorPlatformEnvironmentAPIErrorErrorCode.IncorrectExpose,\n // 'seems current code is running in the main thread, while it is expected to be in iframe or worker',\n // ),\n // );\n // }\n }\n }\n\n #exposeWorkerAPI() {\n WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());\n }\n\n #exposeFrameAPI() {\n IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());\n }\n}\n"],"names":[],"mappings":";;;AAAO;AACA;;ACGA;AACP;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClBO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChBO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACfO;AACP;AACA;AACA;;ACFA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/editor-platform-environment-api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.65.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "UNLICENSED",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"esbuild": "^0.25.
|
|
28
|
+
"esbuild": "^0.25.4",
|
|
29
29
|
"eslint": "^8.57.1",
|
|
30
30
|
"prettier": "^3.5.3",
|
|
31
31
|
"rollup": "^3.29.5",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"typescript": "^5.8.3"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@wix/editor-application": "1.
|
|
38
|
-
"@wix/editor-platform-contexts": "1.
|
|
37
|
+
"@wix/editor-application": "1.65.0",
|
|
38
|
+
"@wix/editor-platform-contexts": "1.65.0",
|
|
39
39
|
"@wix/editor-platform-transport": "1.14.0",
|
|
40
40
|
"@wix/public-editor-platform-errors": "1.8.0",
|
|
41
41
|
"@wix/public-editor-platform-events": "1.313.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
]
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
"falconPackageHash": "
|
|
66
|
+
"falconPackageHash": "edfa6adf06478d53601a546a9e0ea849d61e5bad11b013bb8a5168d2"
|
|
67
67
|
}
|