@wix/editor-platform-environment-api 1.0.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/README.md ADDED
@@ -0,0 +1 @@
1
+ tbd
@@ -0,0 +1,492 @@
1
+ 'use strict';
2
+
3
+ var publicEditorPlatformEvents = require('@wix/public-editor-platform-events');
4
+ var editorPlatformContexts = require('@wix/editor-platform-contexts');
5
+ var publicEditorPlatformErrors = require('@wix/public-editor-platform-errors');
6
+ var publicEditorPlatformInterfaces = require('@wix/public-editor-platform-interfaces');
7
+ var editorPlatformTransport = require('@wix/editor-platform-transport');
8
+
9
+ class ApplicationEventsBridge {
10
+ constructor(platformAppEvents) {
11
+ this.platformAppEvents = platformAppEvents;
12
+ }
13
+ /**
14
+ * Notify by event from Worker Manager (platform infrastructure)
15
+ */
16
+ notify(event) {
17
+ switch (event.type) {
18
+ case publicEditorPlatformEvents.PlatformLifecycleEvent.EditorReady:
19
+ this.platformAppEvents.notify({
20
+ ...event,
21
+ // @ts-expect-error TODO: fix me
22
+ type: publicEditorPlatformEvents.PlatformAppEvent.EditorReady
23
+ });
24
+ break;
25
+ case publicEditorPlatformEvents.PlatformPrivateEvent.HostEvent:
26
+ this.platformAppEvents.notify({
27
+ ...event,
28
+ type: publicEditorPlatformEvents.PlatformAppEvent.HostEvent
29
+ });
30
+ break;
31
+ }
32
+ }
33
+ /**
34
+ * Subscribe to Worker (Application) event
35
+ */
36
+ subscribe(cb) {
37
+ this.platformAppEvents.subscribe((event) => {
38
+ cb(event);
39
+ });
40
+ }
41
+ }
42
+
43
+ var PlatformConsumerEnvironmentAPIType = /* @__PURE__ */ ((PlatformConsumerEnvironmentAPIType2) => {
44
+ PlatformConsumerEnvironmentAPIType2["Frame"] = "PLATFORM_FRAME_API";
45
+ PlatformConsumerEnvironmentAPIType2["Worker"] = "PLATFORM_WORKER_API";
46
+ return PlatformConsumerEnvironmentAPIType2;
47
+ })(PlatformConsumerEnvironmentAPIType || {});
48
+ class AbstractEnvironmentAPI {
49
+ constructor(type, envType) {
50
+ this.type = type;
51
+ this.envType = envType;
52
+ }
53
+ async injectEnvironmentContext({
54
+ events,
55
+ privateApi
56
+ }) {
57
+ await editorPlatformContexts.EnvironmentContext.inject({
58
+ environment: this.envType,
59
+ events,
60
+ privateApi,
61
+ applicationAPIs: {}
62
+ });
63
+ }
64
+ async injectApplicationContext({
65
+ appDefinitionId
66
+ }) {
67
+ await editorPlatformContexts.ApplicationContext.inject({
68
+ appDefinitionId,
69
+ // ?
70
+ // anyway, it is not used atm
71
+ appDefinitionName: ""
72
+ });
73
+ }
74
+ }
75
+
76
+ const DESIGN_SYSTEM_STYLES_MAP = {
77
+ classic: "https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css",
78
+ studio: "https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css"
79
+ };
80
+ class PlatformFrameAPI extends AbstractEnvironmentAPI {
81
+ #events = new publicEditorPlatformEvents.PlatformAppEventEmitter();
82
+ #eventsBridge = new ApplicationEventsBridge(this.#events);
83
+ #privateAPI;
84
+ #applicationPrivateAPI;
85
+ constructor() {
86
+ super(PlatformConsumerEnvironmentAPIType.Frame, editorPlatformContexts.PlatformEnvironment.Frame);
87
+ this.#injectGlobalCSSTokens();
88
+ }
89
+ #injectGlobalCSSTokens() {
90
+ if (typeof globalThis?.document?.head?.prepend === "function") {
91
+ const params = new URL(globalThis.location.href).searchParams;
92
+ const host = params.get("editorType") === "CLASSIC" ? "classic" : "studio";
93
+ const url = DESIGN_SYSTEM_STYLES_MAP[host];
94
+ const isAlreadyLoaded = url && !!document.querySelectorAll(`link[type="text/css"][href="${url}"]`)?.length;
95
+ if (url && !isAlreadyLoaded) {
96
+ const link = document.createElement("link");
97
+ link.setAttribute("rel", "stylesheet");
98
+ link.setAttribute("type", "text/css");
99
+ link.setAttribute("href", url);
100
+ globalThis.document.head.prepend(link);
101
+ }
102
+ }
103
+ }
104
+ async initEnvironment(props) {
105
+ const { applicationPrivateAPI, privateAPI, appDefinitionId } = props;
106
+ this.#applicationPrivateAPI = applicationPrivateAPI;
107
+ this.#privateAPI = privateAPI;
108
+ await this.injectEnvironmentContext({
109
+ privateApi: privateAPI,
110
+ events: this.#events,
111
+ applicationAPIs: {
112
+ [appDefinitionId]: this.#applicationPrivateAPI
113
+ }
114
+ });
115
+ await this.injectApplicationContext({
116
+ appDefinitionId
117
+ });
118
+ }
119
+ notify(event) {
120
+ this.#eventsBridge.notify(event);
121
+ }
122
+ subscribe(cb) {
123
+ this.#eventsBridge.subscribe(cb);
124
+ }
125
+ }
126
+
127
+ var EditorPlatformApplicationContainerErrorCode = /* @__PURE__ */ ((EditorPlatformApplicationContainerErrorCode2) => {
128
+ EditorPlatformApplicationContainerErrorCode2["ApplicationLoadError"] = "ApplicationLoadError";
129
+ EditorPlatformApplicationContainerErrorCode2["ApplicationFetchError"] = "ApplicationFetchError";
130
+ EditorPlatformApplicationContainerErrorCode2["ApplicationExecuteError"] = "ApplicationExecuteError";
131
+ return EditorPlatformApplicationContainerErrorCode2;
132
+ })(EditorPlatformApplicationContainerErrorCode || {});
133
+ class EditorPlatformApplicationContainerError extends publicEditorPlatformErrors.BaseError {
134
+ state = {};
135
+ constructor(message, code) {
136
+ super(message, code, "EP Application Container Error");
137
+ }
138
+ withUrl(url) {
139
+ this.state = { ...this.state, url };
140
+ return this;
141
+ }
142
+ withAppDefinitionId(appDefinitionId) {
143
+ this.state = { ...this.state, appDefinitionId };
144
+ return this;
145
+ }
146
+ withApiMethod(apiMethod) {
147
+ this.state = { ...this.state, apiMethod };
148
+ return this;
149
+ }
150
+ withApiType(apiType) {
151
+ this.state = { ...this.state, apiType };
152
+ return this;
153
+ }
154
+ }
155
+ const createEditorPlatformApplicationContainerError = publicEditorPlatformErrors.createErrorBuilder(EditorPlatformApplicationContainerError);
156
+
157
+ const APPLICATION_REGISTRY_KEY = "__APPLICATION_REGISTRY_KEY";
158
+ async function executeApplication(events, spec, bundle) {
159
+ const executable = new Function(
160
+ editorPlatformContexts.APPLICATION_CONTEXT_KEY,
161
+ APPLICATION_REGISTRY_KEY,
162
+ bundle
163
+ );
164
+ let instance;
165
+ const applicationRegistryCallback = (_instance) => {
166
+ if (instance) {
167
+ throw createEditorPlatformApplicationContainerError(
168
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
169
+ "Application registry called more than once"
170
+ ).withAppDefinitionId(spec.appDefinitionId);
171
+ }
172
+ if (_instance.type !== spec.type) {
173
+ throw createEditorPlatformApplicationContainerError(
174
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
175
+ "Application has different type"
176
+ ).withMessage("expected type", spec.type).withMessage("received type", _instance.type);
177
+ }
178
+ instance = _instance;
179
+ };
180
+ try {
181
+ const context = { ...spec };
182
+ executable.call(
183
+ null,
184
+ new editorPlatformContexts.ApplicationContext(context, await editorPlatformContexts.EnvironmentContext.getInstance()),
185
+ applicationRegistryCallback
186
+ );
187
+ } catch (e) {
188
+ throw createEditorPlatformApplicationContainerError(
189
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
190
+ e.message
191
+ ).withAppDefinitionId(spec.appDefinitionId).withParentError(e);
192
+ }
193
+ return new Promise((resolve, reject) => {
194
+ const unsubscribe = events.subscribe((event) => {
195
+ const timeoutId = setTimeout(() => {
196
+ clearTimeout(timeoutId);
197
+ unsubscribe();
198
+ if (!instance) {
199
+ reject(
200
+ createEditorPlatformApplicationContainerError(
201
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
202
+ "Application registry was not called, threw by timeout"
203
+ ).withAppDefinitionId(spec.appDefinitionId)
204
+ );
205
+ }
206
+ }, 5e3);
207
+ if (event.type === publicEditorPlatformEvents.PlatformAppEvent.ApplicationInit && event.meta.appDefinitionId === spec.appDefinitionId) {
208
+ clearTimeout(timeoutId);
209
+ unsubscribe();
210
+ if (!instance) {
211
+ reject(
212
+ createEditorPlatformApplicationContainerError(
213
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
214
+ "Application registry was not called"
215
+ ).withAppDefinitionId(spec.appDefinitionId)
216
+ );
217
+ }
218
+ resolve({ instance });
219
+ }
220
+ });
221
+ });
222
+ }
223
+
224
+ class PlatformApplicationContainer {
225
+ #apps = {};
226
+ #privateAPI;
227
+ #events;
228
+ constructor(privateApi, events) {
229
+ this.#privateAPI = privateApi;
230
+ this.#events = events;
231
+ this.#events.subscribe((event) => {
232
+ switch (event.type) {
233
+ case publicEditorPlatformEvents.PlatformAppEvent.HostEvent: {
234
+ if (event.payload.type === publicEditorPlatformInterfaces.EventType.removeAppCompleted) {
235
+ void this.#events.withEvent(
236
+ this.#events.factories.createApplicationRemovedEvent(
237
+ event.payload.appDefinitionId
238
+ ),
239
+ () => {
240
+ return this.removeApplication(event.payload.appDefinitionId);
241
+ }
242
+ );
243
+ }
244
+ break;
245
+ }
246
+ }
247
+ });
248
+ }
249
+ async runApplication(appSpec) {
250
+ const bundle = await this.loadApplication(appSpec);
251
+ const instance = await this.executeApplication(appSpec, bundle);
252
+ this.setApplication(appSpec.appDefinitionId, instance);
253
+ return instance;
254
+ }
255
+ setApplication(appDefId, instance) {
256
+ this.#apps[appDefId] = instance;
257
+ void this.#events.withEvent(
258
+ this.#events.factories.createApplicationApiInitEvent(
259
+ appDefId,
260
+ // TODO: both types are set here...
261
+ // @ts-expect-error TODO: fix me
262
+ instance?.api?.private ? "private" : "public"
263
+ ),
264
+ () => {
265
+ this.#privateAPI.applicationManager.setApplication(instance);
266
+ }
267
+ );
268
+ }
269
+ getApplication(appDefId) {
270
+ return this.#apps[appDefId];
271
+ }
272
+ getAppDefinitionIds() {
273
+ return Object.keys(this.#apps);
274
+ }
275
+ removeApplication(appDefinitionId) {
276
+ delete this.#apps[appDefinitionId];
277
+ }
278
+ async loadApplication(appSpec) {
279
+ const url = appSpec.url;
280
+ return this.#events.withEvent(
281
+ this.#events.factories.createApplicationLoadEvent(appSpec, url),
282
+ async () => {
283
+ try {
284
+ return await this.loadApplicationBundle(url);
285
+ } catch (e) {
286
+ throw createEditorPlatformApplicationContainerError(
287
+ EditorPlatformApplicationContainerErrorCode.ApplicationLoadError
288
+ ).withUrl(url).withAppDefinitionId(appSpec.appDefinitionId).withParentError(e);
289
+ }
290
+ }
291
+ );
292
+ }
293
+ async loadApplicationBundle(url) {
294
+ const res = await fetch(url, {
295
+ method: "GET"
296
+ });
297
+ const isSuccessfulResponse = res.status >= 200 && res.status <= 299;
298
+ if (!isSuccessfulResponse) {
299
+ throw createEditorPlatformApplicationContainerError(
300
+ EditorPlatformApplicationContainerErrorCode.ApplicationFetchError
301
+ ).withUrl(url);
302
+ }
303
+ return res.text();
304
+ }
305
+ async executeApplication(appSpec, bundle) {
306
+ return this.#events.withEvent(
307
+ this.#events.factories.createApplicationExecuteEvent(
308
+ appSpec,
309
+ appSpec.url
310
+ ),
311
+ async () => {
312
+ const { instance } = await executeApplication(
313
+ this.#events,
314
+ appSpec,
315
+ bundle
316
+ );
317
+ return instance;
318
+ }
319
+ );
320
+ }
321
+ }
322
+
323
+ class PlatformWorkerAPI extends AbstractEnvironmentAPI {
324
+ #events = new publicEditorPlatformEvents.PlatformAppEventEmitter();
325
+ #eventsBridge = new ApplicationEventsBridge(this.#events);
326
+ #container = null;
327
+ #privateAPI;
328
+ #pendingWaiters = [];
329
+ constructor() {
330
+ super(
331
+ PlatformConsumerEnvironmentAPIType.Worker,
332
+ editorPlatformContexts.PlatformEnvironment.Worker
333
+ );
334
+ }
335
+ create() {
336
+ }
337
+ async initEnvironment(props) {
338
+ const { buildPrivateAPI } = props;
339
+ this.#privateAPI = await buildPrivateAPI({
340
+ // TODO: should be per application (within the container before app execution)
341
+ type: "EDITOR_ADDON"
342
+ });
343
+ await this.injectEnvironmentContext({
344
+ events: this.#events,
345
+ privateApi: this.#privateAPI,
346
+ applicationAPIs: {}
347
+ });
348
+ this.#container = new PlatformApplicationContainer(
349
+ this.#privateAPI,
350
+ this.#events
351
+ );
352
+ this.#pendingWaiters.forEach((res) => res(this));
353
+ }
354
+ async notify(event) {
355
+ await this.waitReady();
356
+ this.#eventsBridge.notify(event);
357
+ }
358
+ subscribe(cb) {
359
+ this.#eventsBridge.subscribe(cb);
360
+ }
361
+ async runApplication(app) {
362
+ await this.waitReady();
363
+ await this.#container.runApplication(app);
364
+ }
365
+ // TODO: should not be any waiters here
366
+ // or should be implemented inside the events instances
367
+ // collect queue until app is not ready
368
+ waitReady() {
369
+ return new Promise((res) => {
370
+ if (this.#privateAPI) {
371
+ return res(this);
372
+ }
373
+ this.#pendingWaiters.push(res);
374
+ });
375
+ }
376
+ }
377
+
378
+ const GUARD_PROP = "$_EP_TRANSPORT_ENV_CONTEXT_GUARD";
379
+ class EditorPlatformContextEnvironment {
380
+ isEnvironmentApiExposed() {
381
+ return !!globalThis[GUARD_PROP];
382
+ }
383
+ async getContexts() {
384
+ const [environmentContext, applicationContext] = await Promise.all([
385
+ editorPlatformContexts.EnvironmentContext.getInstance(),
386
+ editorPlatformContexts.ApplicationContext.getInstance()
387
+ ]);
388
+ return {
389
+ environmentContext,
390
+ applicationContext
391
+ };
392
+ }
393
+ expose() {
394
+ if (this.isEnvironmentApiExposed()) {
395
+ return;
396
+ }
397
+ const isWorker = typeof importScripts === "function";
398
+ if (isWorker) {
399
+ this.#exposeWorkerAPI();
400
+ } else {
401
+ this.#exposeFrameAPI();
402
+ }
403
+ globalThis[GUARD_PROP] = true;
404
+ }
405
+ #exposeWorkerAPI() {
406
+ editorPlatformTransport.WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());
407
+ }
408
+ #exposeFrameAPI() {
409
+ editorPlatformTransport.IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());
410
+ }
411
+ }
412
+
413
+ var EditorPlatformEnvironmentAPIErrorErrorCode = /* @__PURE__ */ ((EditorPlatformEnvironmentAPIErrorErrorCode2) => {
414
+ EditorPlatformEnvironmentAPIErrorErrorCode2["ProxyEnvironmentConnectTimeout"] = "ProxyEnvironmentConnectTimeout";
415
+ EditorPlatformEnvironmentAPIErrorErrorCode2["ProxyWaitAPITimeout"] = "ProxyWaitAPITimeout";
416
+ EditorPlatformEnvironmentAPIErrorErrorCode2["ProxyContextsError"] = "ProxyContextsError";
417
+ return EditorPlatformEnvironmentAPIErrorErrorCode2;
418
+ })(EditorPlatformEnvironmentAPIErrorErrorCode || {});
419
+ class EditorPlatformEnvironmentAPIError extends publicEditorPlatformErrors.BaseError {
420
+ state = {};
421
+ constructor(message, code) {
422
+ super(message, code, "EP EnvironmentAPI Error");
423
+ }
424
+ withUrl(url) {
425
+ this.state = { ...this.state, url };
426
+ return this;
427
+ }
428
+ withAppDefinitionId(appDefinitionId) {
429
+ this.state = { ...this.state, appDefinitionId };
430
+ return this;
431
+ }
432
+ }
433
+ const createEditorPlatformEnvironmentAPIError = publicEditorPlatformErrors.createErrorBuilder(EditorPlatformEnvironmentAPIError);
434
+
435
+ class EditorPlatformEnvironmentProxy {
436
+ async iframe() {
437
+ throw publicEditorPlatformErrors.createEditorPlatformInternalError(
438
+ publicEditorPlatformErrors.EditorPlatformInternalErrorCode.UnexpectedError,
439
+ "not supported"
440
+ );
441
+ }
442
+ async worker(worker) {
443
+ const environment = new EditorPlatformContextEnvironment();
444
+ if (!environment.isEnvironmentApiExposed()) {
445
+ environment.expose();
446
+ }
447
+ const connectTimeoutId = setTimeout(() => {
448
+ console.info(
449
+ createEditorPlatformEnvironmentAPIError(
450
+ EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,
451
+ "probably worker environment does not expose platform API or any SDK function is never used"
452
+ )
453
+ );
454
+ }, 2e3);
455
+ editorPlatformTransport.WorkerHostEndpoint.connect(worker, async (transport) => {
456
+ clearTimeout(connectTimeoutId);
457
+ const waitAPITimeoutId = setTimeout(() => {
458
+ console.error(
459
+ createEditorPlatformEnvironmentAPIError(
460
+ EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout
461
+ )
462
+ );
463
+ }, 2e3);
464
+ const workerApi = await transport.waitAPI(
465
+ PlatformConsumerEnvironmentAPIType.Worker
466
+ );
467
+ clearTimeout(waitAPITimeoutId);
468
+ try {
469
+ const contexts = await environment.getContexts();
470
+ await workerApi.injectEnvironmentContext({
471
+ events: contexts.environmentContext.getEvents(),
472
+ privateApi: contexts.environmentContext.getPrivateAPI(),
473
+ applicationAPIs: contexts.environmentContext.getApplicationAPIs()
474
+ });
475
+ await workerApi.injectApplicationContext({
476
+ appDefinitionId: contexts.applicationContext.getAppDefinitionId()
477
+ });
478
+ } catch (e) {
479
+ throw createEditorPlatformEnvironmentAPIError(
480
+ EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError
481
+ ).withParentError(e);
482
+ }
483
+ });
484
+ }
485
+ }
486
+
487
+ exports.EditorPlatformContextEnvironment = EditorPlatformContextEnvironment;
488
+ exports.EditorPlatformEnvironmentProxy = EditorPlatformEnvironmentProxy;
489
+ exports.PlatformConsumerEnvironmentAPIType = PlatformConsumerEnvironmentAPIType;
490
+ exports.PlatformFrameAPI = PlatformFrameAPI;
491
+ exports.PlatformWorkerAPI = PlatformWorkerAPI;
492
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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';\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\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 } else {\n this.#exposeFrameAPI();\n }\n\n globalThis[GUARD_PROP] = true;\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}\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,SACxB,CAAA,CAAA;AACD,QAAA,MAAA;AAAA,MACF,KAAKC,+CAAqB,CAAA,SAAA;AACxB,QAAA,IAAA,CAAK,kBAAkB,MAAO,CAAA;AAAA,UAC5B,GAAG,KAAA;AAAA,UACH,MAAMD,2CAAiB,CAAA,SAAA;AAAA,SACxB,CAAA,CAAA;AACD,QAAA,MAAA;AAAA,KACJ;AAAA,GACF;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,EAAwC,EAAA;AACvD,IAAK,IAAA,CAAA,iBAAA,CAAkB,SAAU,CAAA,CAAC,KAAU,KAAA;AAC1C,MAAA,EAAA,CAAG,KAAK,CAAA,CAAA;AAAA,KACT,CAAA,CAAA;AAAA,GACH;AACF;;ACrCY,IAAA,kCAAA,qBAAAE,mCAAL,KAAA;AACL,EAAAA,oCAAA,OAAQ,CAA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AM,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;;;;;;;;"}
@@ -0,0 +1,486 @@
1
+ import { PlatformPrivateEvent, PlatformAppEvent, PlatformLifecycleEvent, PlatformAppEventEmitter } from '@wix/public-editor-platform-events';
2
+ import { EnvironmentContext, ApplicationContext, PlatformEnvironment, APPLICATION_CONTEXT_KEY } from '@wix/editor-platform-contexts';
3
+ import { createErrorBuilder, BaseError, createEditorPlatformInternalError, EditorPlatformInternalErrorCode } from '@wix/public-editor-platform-errors';
4
+ import { EventType } from '@wix/public-editor-platform-interfaces';
5
+ import { WorkerConsumerEndpoint, IFrameConsumerEndpoint, WorkerHostEndpoint } from '@wix/editor-platform-transport';
6
+
7
+ class ApplicationEventsBridge {
8
+ constructor(platformAppEvents) {
9
+ this.platformAppEvents = platformAppEvents;
10
+ }
11
+ /**
12
+ * Notify by event from Worker Manager (platform infrastructure)
13
+ */
14
+ notify(event) {
15
+ switch (event.type) {
16
+ case PlatformLifecycleEvent.EditorReady:
17
+ this.platformAppEvents.notify({
18
+ ...event,
19
+ // @ts-expect-error TODO: fix me
20
+ type: PlatformAppEvent.EditorReady
21
+ });
22
+ break;
23
+ case PlatformPrivateEvent.HostEvent:
24
+ this.platformAppEvents.notify({
25
+ ...event,
26
+ type: PlatformAppEvent.HostEvent
27
+ });
28
+ break;
29
+ }
30
+ }
31
+ /**
32
+ * Subscribe to Worker (Application) event
33
+ */
34
+ subscribe(cb) {
35
+ this.platformAppEvents.subscribe((event) => {
36
+ cb(event);
37
+ });
38
+ }
39
+ }
40
+
41
+ var PlatformConsumerEnvironmentAPIType = /* @__PURE__ */ ((PlatformConsumerEnvironmentAPIType2) => {
42
+ PlatformConsumerEnvironmentAPIType2["Frame"] = "PLATFORM_FRAME_API";
43
+ PlatformConsumerEnvironmentAPIType2["Worker"] = "PLATFORM_WORKER_API";
44
+ return PlatformConsumerEnvironmentAPIType2;
45
+ })(PlatformConsumerEnvironmentAPIType || {});
46
+ class AbstractEnvironmentAPI {
47
+ constructor(type, envType) {
48
+ this.type = type;
49
+ this.envType = envType;
50
+ }
51
+ async injectEnvironmentContext({
52
+ events,
53
+ privateApi
54
+ }) {
55
+ await EnvironmentContext.inject({
56
+ environment: this.envType,
57
+ events,
58
+ privateApi,
59
+ applicationAPIs: {}
60
+ });
61
+ }
62
+ async injectApplicationContext({
63
+ appDefinitionId
64
+ }) {
65
+ await ApplicationContext.inject({
66
+ appDefinitionId,
67
+ // ?
68
+ // anyway, it is not used atm
69
+ appDefinitionName: ""
70
+ });
71
+ }
72
+ }
73
+
74
+ const DESIGN_SYSTEM_STYLES_MAP = {
75
+ classic: "https://www.unpkg.com/@wix/design-system/dist/statics/tokens-default.global.css",
76
+ studio: "https://www.unpkg.com/@wix/design-system/dist/statics/tokens-studio.global.css"
77
+ };
78
+ class PlatformFrameAPI extends AbstractEnvironmentAPI {
79
+ #events = new PlatformAppEventEmitter();
80
+ #eventsBridge = new ApplicationEventsBridge(this.#events);
81
+ #privateAPI;
82
+ #applicationPrivateAPI;
83
+ constructor() {
84
+ super(PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame);
85
+ this.#injectGlobalCSSTokens();
86
+ }
87
+ #injectGlobalCSSTokens() {
88
+ if (typeof globalThis?.document?.head?.prepend === "function") {
89
+ const params = new URL(globalThis.location.href).searchParams;
90
+ const host = params.get("editorType") === "CLASSIC" ? "classic" : "studio";
91
+ const url = DESIGN_SYSTEM_STYLES_MAP[host];
92
+ const isAlreadyLoaded = url && !!document.querySelectorAll(`link[type="text/css"][href="${url}"]`)?.length;
93
+ if (url && !isAlreadyLoaded) {
94
+ const link = document.createElement("link");
95
+ link.setAttribute("rel", "stylesheet");
96
+ link.setAttribute("type", "text/css");
97
+ link.setAttribute("href", url);
98
+ globalThis.document.head.prepend(link);
99
+ }
100
+ }
101
+ }
102
+ async initEnvironment(props) {
103
+ const { applicationPrivateAPI, privateAPI, appDefinitionId } = props;
104
+ this.#applicationPrivateAPI = applicationPrivateAPI;
105
+ this.#privateAPI = privateAPI;
106
+ await this.injectEnvironmentContext({
107
+ privateApi: privateAPI,
108
+ events: this.#events,
109
+ applicationAPIs: {
110
+ [appDefinitionId]: this.#applicationPrivateAPI
111
+ }
112
+ });
113
+ await this.injectApplicationContext({
114
+ appDefinitionId
115
+ });
116
+ }
117
+ notify(event) {
118
+ this.#eventsBridge.notify(event);
119
+ }
120
+ subscribe(cb) {
121
+ this.#eventsBridge.subscribe(cb);
122
+ }
123
+ }
124
+
125
+ var EditorPlatformApplicationContainerErrorCode = /* @__PURE__ */ ((EditorPlatformApplicationContainerErrorCode2) => {
126
+ EditorPlatformApplicationContainerErrorCode2["ApplicationLoadError"] = "ApplicationLoadError";
127
+ EditorPlatformApplicationContainerErrorCode2["ApplicationFetchError"] = "ApplicationFetchError";
128
+ EditorPlatformApplicationContainerErrorCode2["ApplicationExecuteError"] = "ApplicationExecuteError";
129
+ return EditorPlatformApplicationContainerErrorCode2;
130
+ })(EditorPlatformApplicationContainerErrorCode || {});
131
+ class EditorPlatformApplicationContainerError extends BaseError {
132
+ state = {};
133
+ constructor(message, code) {
134
+ super(message, code, "EP Application Container Error");
135
+ }
136
+ withUrl(url) {
137
+ this.state = { ...this.state, url };
138
+ return this;
139
+ }
140
+ withAppDefinitionId(appDefinitionId) {
141
+ this.state = { ...this.state, appDefinitionId };
142
+ return this;
143
+ }
144
+ withApiMethod(apiMethod) {
145
+ this.state = { ...this.state, apiMethod };
146
+ return this;
147
+ }
148
+ withApiType(apiType) {
149
+ this.state = { ...this.state, apiType };
150
+ return this;
151
+ }
152
+ }
153
+ const createEditorPlatformApplicationContainerError = createErrorBuilder(EditorPlatformApplicationContainerError);
154
+
155
+ const APPLICATION_REGISTRY_KEY = "__APPLICATION_REGISTRY_KEY";
156
+ async function executeApplication(events, spec, bundle) {
157
+ const executable = new Function(
158
+ APPLICATION_CONTEXT_KEY,
159
+ APPLICATION_REGISTRY_KEY,
160
+ bundle
161
+ );
162
+ let instance;
163
+ const applicationRegistryCallback = (_instance) => {
164
+ if (instance) {
165
+ throw createEditorPlatformApplicationContainerError(
166
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
167
+ "Application registry called more than once"
168
+ ).withAppDefinitionId(spec.appDefinitionId);
169
+ }
170
+ if (_instance.type !== spec.type) {
171
+ throw createEditorPlatformApplicationContainerError(
172
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
173
+ "Application has different type"
174
+ ).withMessage("expected type", spec.type).withMessage("received type", _instance.type);
175
+ }
176
+ instance = _instance;
177
+ };
178
+ try {
179
+ const context = { ...spec };
180
+ executable.call(
181
+ null,
182
+ new ApplicationContext(context, await EnvironmentContext.getInstance()),
183
+ applicationRegistryCallback
184
+ );
185
+ } catch (e) {
186
+ throw createEditorPlatformApplicationContainerError(
187
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
188
+ e.message
189
+ ).withAppDefinitionId(spec.appDefinitionId).withParentError(e);
190
+ }
191
+ return new Promise((resolve, reject) => {
192
+ const unsubscribe = events.subscribe((event) => {
193
+ const timeoutId = setTimeout(() => {
194
+ clearTimeout(timeoutId);
195
+ unsubscribe();
196
+ if (!instance) {
197
+ reject(
198
+ createEditorPlatformApplicationContainerError(
199
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
200
+ "Application registry was not called, threw by timeout"
201
+ ).withAppDefinitionId(spec.appDefinitionId)
202
+ );
203
+ }
204
+ }, 5e3);
205
+ if (event.type === PlatformAppEvent.ApplicationInit && event.meta.appDefinitionId === spec.appDefinitionId) {
206
+ clearTimeout(timeoutId);
207
+ unsubscribe();
208
+ if (!instance) {
209
+ reject(
210
+ createEditorPlatformApplicationContainerError(
211
+ EditorPlatformApplicationContainerErrorCode.ApplicationExecuteError,
212
+ "Application registry was not called"
213
+ ).withAppDefinitionId(spec.appDefinitionId)
214
+ );
215
+ }
216
+ resolve({ instance });
217
+ }
218
+ });
219
+ });
220
+ }
221
+
222
+ class PlatformApplicationContainer {
223
+ #apps = {};
224
+ #privateAPI;
225
+ #events;
226
+ constructor(privateApi, events) {
227
+ this.#privateAPI = privateApi;
228
+ this.#events = events;
229
+ this.#events.subscribe((event) => {
230
+ switch (event.type) {
231
+ case PlatformAppEvent.HostEvent: {
232
+ if (event.payload.type === EventType.removeAppCompleted) {
233
+ void this.#events.withEvent(
234
+ this.#events.factories.createApplicationRemovedEvent(
235
+ event.payload.appDefinitionId
236
+ ),
237
+ () => {
238
+ return this.removeApplication(event.payload.appDefinitionId);
239
+ }
240
+ );
241
+ }
242
+ break;
243
+ }
244
+ }
245
+ });
246
+ }
247
+ async runApplication(appSpec) {
248
+ const bundle = await this.loadApplication(appSpec);
249
+ const instance = await this.executeApplication(appSpec, bundle);
250
+ this.setApplication(appSpec.appDefinitionId, instance);
251
+ return instance;
252
+ }
253
+ setApplication(appDefId, instance) {
254
+ this.#apps[appDefId] = instance;
255
+ void this.#events.withEvent(
256
+ this.#events.factories.createApplicationApiInitEvent(
257
+ appDefId,
258
+ // TODO: both types are set here...
259
+ // @ts-expect-error TODO: fix me
260
+ instance?.api?.private ? "private" : "public"
261
+ ),
262
+ () => {
263
+ this.#privateAPI.applicationManager.setApplication(instance);
264
+ }
265
+ );
266
+ }
267
+ getApplication(appDefId) {
268
+ return this.#apps[appDefId];
269
+ }
270
+ getAppDefinitionIds() {
271
+ return Object.keys(this.#apps);
272
+ }
273
+ removeApplication(appDefinitionId) {
274
+ delete this.#apps[appDefinitionId];
275
+ }
276
+ async loadApplication(appSpec) {
277
+ const url = appSpec.url;
278
+ return this.#events.withEvent(
279
+ this.#events.factories.createApplicationLoadEvent(appSpec, url),
280
+ async () => {
281
+ try {
282
+ return await this.loadApplicationBundle(url);
283
+ } catch (e) {
284
+ throw createEditorPlatformApplicationContainerError(
285
+ EditorPlatformApplicationContainerErrorCode.ApplicationLoadError
286
+ ).withUrl(url).withAppDefinitionId(appSpec.appDefinitionId).withParentError(e);
287
+ }
288
+ }
289
+ );
290
+ }
291
+ async loadApplicationBundle(url) {
292
+ const res = await fetch(url, {
293
+ method: "GET"
294
+ });
295
+ const isSuccessfulResponse = res.status >= 200 && res.status <= 299;
296
+ if (!isSuccessfulResponse) {
297
+ throw createEditorPlatformApplicationContainerError(
298
+ EditorPlatformApplicationContainerErrorCode.ApplicationFetchError
299
+ ).withUrl(url);
300
+ }
301
+ return res.text();
302
+ }
303
+ async executeApplication(appSpec, bundle) {
304
+ return this.#events.withEvent(
305
+ this.#events.factories.createApplicationExecuteEvent(
306
+ appSpec,
307
+ appSpec.url
308
+ ),
309
+ async () => {
310
+ const { instance } = await executeApplication(
311
+ this.#events,
312
+ appSpec,
313
+ bundle
314
+ );
315
+ return instance;
316
+ }
317
+ );
318
+ }
319
+ }
320
+
321
+ class PlatformWorkerAPI extends AbstractEnvironmentAPI {
322
+ #events = new PlatformAppEventEmitter();
323
+ #eventsBridge = new ApplicationEventsBridge(this.#events);
324
+ #container = null;
325
+ #privateAPI;
326
+ #pendingWaiters = [];
327
+ constructor() {
328
+ super(
329
+ PlatformConsumerEnvironmentAPIType.Worker,
330
+ PlatformEnvironment.Worker
331
+ );
332
+ }
333
+ create() {
334
+ }
335
+ async initEnvironment(props) {
336
+ const { buildPrivateAPI } = props;
337
+ this.#privateAPI = await buildPrivateAPI({
338
+ // TODO: should be per application (within the container before app execution)
339
+ type: "EDITOR_ADDON"
340
+ });
341
+ await this.injectEnvironmentContext({
342
+ events: this.#events,
343
+ privateApi: this.#privateAPI,
344
+ applicationAPIs: {}
345
+ });
346
+ this.#container = new PlatformApplicationContainer(
347
+ this.#privateAPI,
348
+ this.#events
349
+ );
350
+ this.#pendingWaiters.forEach((res) => res(this));
351
+ }
352
+ async notify(event) {
353
+ await this.waitReady();
354
+ this.#eventsBridge.notify(event);
355
+ }
356
+ subscribe(cb) {
357
+ this.#eventsBridge.subscribe(cb);
358
+ }
359
+ async runApplication(app) {
360
+ await this.waitReady();
361
+ await this.#container.runApplication(app);
362
+ }
363
+ // TODO: should not be any waiters here
364
+ // or should be implemented inside the events instances
365
+ // collect queue until app is not ready
366
+ waitReady() {
367
+ return new Promise((res) => {
368
+ if (this.#privateAPI) {
369
+ return res(this);
370
+ }
371
+ this.#pendingWaiters.push(res);
372
+ });
373
+ }
374
+ }
375
+
376
+ const GUARD_PROP = "$_EP_TRANSPORT_ENV_CONTEXT_GUARD";
377
+ class EditorPlatformContextEnvironment {
378
+ isEnvironmentApiExposed() {
379
+ return !!globalThis[GUARD_PROP];
380
+ }
381
+ async getContexts() {
382
+ const [environmentContext, applicationContext] = await Promise.all([
383
+ EnvironmentContext.getInstance(),
384
+ ApplicationContext.getInstance()
385
+ ]);
386
+ return {
387
+ environmentContext,
388
+ applicationContext
389
+ };
390
+ }
391
+ expose() {
392
+ if (this.isEnvironmentApiExposed()) {
393
+ return;
394
+ }
395
+ const isWorker = typeof importScripts === "function";
396
+ if (isWorker) {
397
+ this.#exposeWorkerAPI();
398
+ } else {
399
+ this.#exposeFrameAPI();
400
+ }
401
+ globalThis[GUARD_PROP] = true;
402
+ }
403
+ #exposeWorkerAPI() {
404
+ WorkerConsumerEndpoint.exposeAPI(new PlatformWorkerAPI());
405
+ }
406
+ #exposeFrameAPI() {
407
+ IFrameConsumerEndpoint.exposeAPI(new PlatformFrameAPI());
408
+ }
409
+ }
410
+
411
+ var EditorPlatformEnvironmentAPIErrorErrorCode = /* @__PURE__ */ ((EditorPlatformEnvironmentAPIErrorErrorCode2) => {
412
+ EditorPlatformEnvironmentAPIErrorErrorCode2["ProxyEnvironmentConnectTimeout"] = "ProxyEnvironmentConnectTimeout";
413
+ EditorPlatformEnvironmentAPIErrorErrorCode2["ProxyWaitAPITimeout"] = "ProxyWaitAPITimeout";
414
+ EditorPlatformEnvironmentAPIErrorErrorCode2["ProxyContextsError"] = "ProxyContextsError";
415
+ return EditorPlatformEnvironmentAPIErrorErrorCode2;
416
+ })(EditorPlatformEnvironmentAPIErrorErrorCode || {});
417
+ class EditorPlatformEnvironmentAPIError extends BaseError {
418
+ state = {};
419
+ constructor(message, code) {
420
+ super(message, code, "EP EnvironmentAPI Error");
421
+ }
422
+ withUrl(url) {
423
+ this.state = { ...this.state, url };
424
+ return this;
425
+ }
426
+ withAppDefinitionId(appDefinitionId) {
427
+ this.state = { ...this.state, appDefinitionId };
428
+ return this;
429
+ }
430
+ }
431
+ const createEditorPlatformEnvironmentAPIError = createErrorBuilder(EditorPlatformEnvironmentAPIError);
432
+
433
+ class EditorPlatformEnvironmentProxy {
434
+ async iframe() {
435
+ throw createEditorPlatformInternalError(
436
+ EditorPlatformInternalErrorCode.UnexpectedError,
437
+ "not supported"
438
+ );
439
+ }
440
+ async worker(worker) {
441
+ const environment = new EditorPlatformContextEnvironment();
442
+ if (!environment.isEnvironmentApiExposed()) {
443
+ environment.expose();
444
+ }
445
+ const connectTimeoutId = setTimeout(() => {
446
+ console.info(
447
+ createEditorPlatformEnvironmentAPIError(
448
+ EditorPlatformEnvironmentAPIErrorErrorCode.ProxyEnvironmentConnectTimeout,
449
+ "probably worker environment does not expose platform API or any SDK function is never used"
450
+ )
451
+ );
452
+ }, 2e3);
453
+ WorkerHostEndpoint.connect(worker, async (transport) => {
454
+ clearTimeout(connectTimeoutId);
455
+ const waitAPITimeoutId = setTimeout(() => {
456
+ console.error(
457
+ createEditorPlatformEnvironmentAPIError(
458
+ EditorPlatformEnvironmentAPIErrorErrorCode.ProxyWaitAPITimeout
459
+ )
460
+ );
461
+ }, 2e3);
462
+ const workerApi = await transport.waitAPI(
463
+ PlatformConsumerEnvironmentAPIType.Worker
464
+ );
465
+ clearTimeout(waitAPITimeoutId);
466
+ try {
467
+ const contexts = await environment.getContexts();
468
+ await workerApi.injectEnvironmentContext({
469
+ events: contexts.environmentContext.getEvents(),
470
+ privateApi: contexts.environmentContext.getPrivateAPI(),
471
+ applicationAPIs: contexts.environmentContext.getApplicationAPIs()
472
+ });
473
+ await workerApi.injectApplicationContext({
474
+ appDefinitionId: contexts.applicationContext.getAppDefinitionId()
475
+ });
476
+ } catch (e) {
477
+ throw createEditorPlatformEnvironmentAPIError(
478
+ EditorPlatformEnvironmentAPIErrorErrorCode.ProxyContextsError
479
+ ).withParentError(e);
480
+ }
481
+ });
482
+ }
483
+ }
484
+
485
+ export { EditorPlatformContextEnvironment, EditorPlatformEnvironmentProxy, PlatformConsumerEnvironmentAPIType, PlatformFrameAPI, PlatformWorkerAPI };
486
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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';\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\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 } else {\n this.#exposeFrameAPI();\n }\n\n globalThis[GUARD_PROP] = true;\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}\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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AAA,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;;;;"}
@@ -0,0 +1,74 @@
1
+ import { PlatformAppEventEmitter, IPlatformPrivateEvent, IPlatformAppEvent } from '@wix/public-editor-platform-events';
2
+ import * as _wix_editor_platform_contexts from '@wix/editor-platform-contexts';
3
+ import { PlatformEnvironment, EnvironmentContext, ApplicationContext } from '@wix/editor-platform-contexts';
4
+
5
+ type IPrivateAPIFixMe = any;
6
+ type IApplicationSpec = any;
7
+
8
+ declare enum PlatformConsumerEnvironmentAPIType {
9
+ Frame = "PLATFORM_FRAME_API",
10
+ Worker = "PLATFORM_WORKER_API"
11
+ }
12
+ /**
13
+ * rename these entities -> API to Env
14
+ */
15
+ declare abstract class AbstractEnvironmentAPI<TApiType extends PlatformConsumerEnvironmentAPIType, TEnv extends PlatformEnvironment> {
16
+ type: TApiType;
17
+ envType: TEnv;
18
+ protected constructor(type: TApiType, envType: TEnv);
19
+ abstract initEnvironment(props: unknown): void;
20
+ injectEnvironmentContext({ events, privateApi, }: {
21
+ events: PlatformAppEventEmitter;
22
+ privateApi: IPrivateAPIFixMe;
23
+ applicationAPIs?: Record<string, any>;
24
+ }): Promise<void>;
25
+ injectApplicationContext({ appDefinitionId, }: {
26
+ appDefinitionId: string;
27
+ }): Promise<void>;
28
+ }
29
+
30
+ declare class PlatformFrameAPI extends AbstractEnvironmentAPI<PlatformConsumerEnvironmentAPIType.Frame, PlatformEnvironment.Frame> {
31
+ #private;
32
+ constructor();
33
+ initEnvironment(props: {
34
+ appDefinitionId: string;
35
+ privateAPI: IPrivateAPIFixMe;
36
+ applicationPrivateAPI: any;
37
+ }): Promise<void>;
38
+ notify(event: IPlatformPrivateEvent): void;
39
+ subscribe(cb: (event: IPlatformAppEvent) => void): void;
40
+ }
41
+
42
+ declare class PlatformWorkerAPI extends AbstractEnvironmentAPI<PlatformConsumerEnvironmentAPIType.Worker, PlatformEnvironment.Worker> {
43
+ #private;
44
+ constructor();
45
+ create(): void;
46
+ initEnvironment(props: {
47
+ buildPrivateAPI: (config: any) => IPrivateAPIFixMe;
48
+ }): Promise<void>;
49
+ notify(event: IPlatformPrivateEvent): Promise<void>;
50
+ subscribe(cb: (event: IPlatformAppEvent) => void): void;
51
+ runApplication(app: IApplicationSpec): Promise<void>;
52
+ waitReady(): Promise<this>;
53
+ }
54
+
55
+ declare class EditorPlatformEnvironmentProxy {
56
+ iframe(): Promise<void>;
57
+ worker(worker: Worker): Promise<void>;
58
+ }
59
+
60
+ declare global {
61
+ var $_EP_TRANSPORT_ENV_CONTEXT_GUARD: boolean;
62
+ }
63
+ declare class EditorPlatformContextEnvironment {
64
+ #private;
65
+ isEnvironmentApiExposed(): boolean;
66
+ getContexts(): Promise<{
67
+ environmentContext: EnvironmentContext;
68
+ applicationContext: ApplicationContext<_wix_editor_platform_contexts.IApplicationContext>;
69
+ }>;
70
+ expose(): void;
71
+ }
72
+
73
+ export { EditorPlatformContextEnvironment, EditorPlatformEnvironmentProxy, PlatformConsumerEnvironmentAPIType, PlatformFrameAPI, PlatformWorkerAPI };
74
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@wix/editor-platform-environment-api",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "scripts": {
9
+ "start": "exit 0",
10
+ "build": "yarn typecheck && rollup -c",
11
+ "test": "exit 0",
12
+ "lint": "prettier --check ./src",
13
+ "lint:fix": "prettier --write ./src",
14
+ "typecheck": "tsc --noEmit"
15
+ },
16
+ "keywords": [],
17
+ "files": [
18
+ "dist/cjs",
19
+ "dist/esm",
20
+ "dist/types"
21
+ ],
22
+ "author": {
23
+ "name": "Editor Platform <editor-platform-dev@wix.com>",
24
+ "email": "editor-platform-dev@wix.com"
25
+ },
26
+ "license": "UNLICENSED",
27
+ "devDependencies": {
28
+ "esbuild": "^0.24.2",
29
+ "eslint": "^8.57.1",
30
+ "prettier": "^3.4.2",
31
+ "rollup": "^3.29.5",
32
+ "rollup-plugin-dts": "^6.1.1",
33
+ "rollup-plugin-esbuild": "^5.0.0",
34
+ "typescript": "^5.7.2"
35
+ },
36
+ "dependencies": {
37
+ "@wix/editor-application": "1.0.0",
38
+ "@wix/editor-platform-contexts": "1.0.0",
39
+ "@wix/editor-platform-transport": "1.11.0",
40
+ "@wix/public-editor-platform-errors": "1.8.0",
41
+ "@wix/public-editor-platform-events": "1.304.0",
42
+ "@wix/public-editor-platform-interfaces": "1.15.0"
43
+ },
44
+ "publishConfig": {
45
+ "registry": "https://registry.npmjs.org/",
46
+ "access": "public"
47
+ },
48
+ "unpkg": true,
49
+ "lint-staged": {
50
+ "*.{js,ts}": "yarn run lint"
51
+ },
52
+ "wix": {
53
+ "artifact": {
54
+ "groupId": "com.wixpress",
55
+ "artifactId": "editor-platform-environment-api",
56
+ "targets": {
57
+ "static": true
58
+ }
59
+ },
60
+ "validations": {
61
+ "postDependenciesBuild": [
62
+ "lint"
63
+ ]
64
+ }
65
+ },
66
+ "falconPackageHash": "70f869d52955c90df5f149499e3bc3d41c29c76c2676b3407e450af0"
67
+ }