@fyul/embed-sdk 2.2.0 → 2.3.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/helpers/messageLogger.d.ts +1 -0
- package/dist/cjs/helpers/messageLogger.js +2 -0
- package/dist/cjs/index.d.ts +3 -19
- package/dist/cjs/index.js +21 -86
- package/dist/cjs/modules/baseModule.d.ts +3 -0
- package/dist/cjs/modules/baseModule.js +5 -1
- package/dist/cjs/modules/catalog/catalogModule.d.ts +1 -0
- package/dist/cjs/modules/catalog/catalogModule.js +4 -0
- package/dist/cjs/modules/edm/broadcastEvents/baseEdmBroadcastEvent.d.ts +5 -0
- package/dist/cjs/modules/edm/broadcastEvents/baseEdmBroadcastEvent.js +10 -0
- package/dist/cjs/modules/edm/broadcastEvents/onDesignStatusUpdate.d.ts +5 -0
- package/dist/cjs/modules/edm/broadcastEvents/onDesignStatusUpdate.js +10 -0
- package/dist/cjs/modules/edm/broadcastEvents/onErrorUpdate.d.ts +5 -0
- package/dist/cjs/modules/edm/broadcastEvents/onErrorUpdate.js +10 -0
- package/dist/cjs/modules/edm/broadcastEvents/onFilePickerRequested.d.ts +5 -0
- package/dist/cjs/modules/edm/broadcastEvents/onFilePickerRequested.js +10 -0
- package/dist/cjs/modules/edm/broadcastEvents/onPricingStatusUpdate.d.ts +5 -0
- package/dist/cjs/modules/edm/broadcastEvents/onPricingStatusUpdate.js +10 -0
- package/dist/cjs/modules/edm/broadcastEvents/onStepStatusUpdate.d.ts +5 -0
- package/dist/cjs/modules/edm/broadcastEvents/onStepStatusUpdate.js +10 -0
- package/dist/cjs/modules/edm/edmBroadcastModule.d.ts +12 -0
- package/dist/cjs/modules/edm/edmBroadcastModule.js +35 -0
- package/dist/cjs/modules/edm/edmModule.d.ts +13 -0
- package/dist/cjs/modules/edm/edmModule.js +33 -0
- package/dist/cjs/modules/edm/events.d.ts +48 -0
- package/dist/cjs/modules/edm/events.js +36 -0
- package/dist/cjs/modules/edm/types/data.types.d.ts +204 -0
- package/dist/cjs/modules/edm/types/data.types.js +8 -0
- package/dist/cjs/modules/edm/types/event/actionEvent.types.d.ts +8 -0
- package/dist/cjs/modules/edm/types/event/actionEvent.types.js +2 -0
- package/dist/cjs/modules/edm/types/event/actionEventPayload.types.d.ts +15 -0
- package/dist/cjs/modules/edm/types/event/actionEventPayload.types.js +2 -0
- package/dist/cjs/modules/edm/types/event/broadcastEvent.types.d.ts +12 -0
- package/dist/cjs/modules/edm/types/event/broadcastEvent.types.js +2 -0
- package/dist/cjs/modules/edm/types/event/broadcastEventPayload.types.d.ts +9 -0
- package/dist/cjs/modules/edm/types/event/broadcastEventPayload.types.js +2 -0
- package/dist/cjs/modules/edm/types/event/resultEvent.types.d.ts +8 -0
- package/dist/cjs/modules/edm/types/event/resultEvent.types.js +2 -0
- package/dist/cjs/modules/edm/types/event/resultEventPayload.types.d.ts +17 -0
- package/dist/cjs/modules/edm/types/event/resultEventPayload.types.js +2 -0
- package/dist/cjs/modules/edm/types/index.d.ts +6 -0
- package/dist/cjs/modules/edm/types/index.js +25 -0
- package/dist/cjs/modules/eventTypes.d.ts +4 -2
- package/dist/cjs/modules/eventTypes.js +5 -0
- package/dist/cjs/modules/events.d.ts +40 -0
- package/dist/cjs/modules/events.js +9 -1
- package/dist/cjs/modules/mockup-generation/mockupGenerationModule.d.ts +1 -0
- package/dist/cjs/modules/mockup-generation/mockupGenerationModule.js +4 -0
- package/dist/cjs/modules/moduleNames.d.ts +7 -0
- package/dist/cjs/modules/moduleNames.js +10 -0
- package/dist/cjs/modules/modules.d.ts +11 -6
- package/dist/cjs/modules/modules.js +16 -11
- package/dist/cjs/modules/product-publish/productPublishModule.d.ts +1 -0
- package/dist/cjs/modules/product-publish/productPublishModule.js +4 -0
- package/dist/cjs/modules/product-publish/types/event/resultEventPayload.types.d.ts +5 -0
- package/dist/cjs/modules/sdk/sdkModule.d.ts +1 -0
- package/dist/cjs/modules/sdk/sdkModule.js +4 -0
- package/dist/cjs/services/broadcastEventDispatcher.d.ts +8 -0
- package/dist/cjs/services/broadcastEventDispatcher.js +24 -0
- package/dist/cjs/services/edm.d.ts +23 -0
- package/dist/cjs/services/edm.js +102 -0
- package/dist/cjs/services/embed.d.ts +19 -0
- package/dist/cjs/services/embed.js +83 -0
- package/dist/cjs/services/embedCommunicator.d.ts +10 -4
- package/dist/cjs/services/embedCommunicator.js +42 -10
- package/dist/cjs/services/iFrameManager.d.ts +3 -1
- package/dist/cjs/services/iFrameManager.js +6 -9
- package/dist/cjs/services/moduleLoaderService.d.ts +1 -2
- package/dist/cjs/services/moduleLoaderService.js +2 -1
- package/dist/cjs/types/event/action/actionEvent.types.d.ts +2 -1
- package/dist/cjs/types/event/action/actionEventPayload.types.d.ts +2 -1
- package/dist/cjs/types/event/broadcast/broadcastEvent.types.d.ts +8 -0
- package/dist/cjs/types/event/broadcast/broadcastEvent.types.js +2 -0
- package/dist/cjs/types/event/broadcast/broadcastEventHandler.d.ts +5 -0
- package/dist/cjs/types/event/broadcast/broadcastEventHandler.js +2 -0
- package/dist/cjs/types/event/broadcast/broadcastEventMap.d.ts +12 -0
- package/dist/cjs/types/event/broadcast/broadcastEventMap.js +16 -0
- package/dist/cjs/types/event/broadcast/broadcastEventPayload.types.d.ts +2 -0
- package/dist/cjs/types/event/broadcast/broadcastEventPayload.types.js +2 -0
- package/dist/cjs/types/event/event.types.d.ts +3 -2
- package/dist/cjs/types/event/eventPayload.types.d.ts +2 -1
- package/dist/cjs/types/event/result/resultEvent.types.d.ts +2 -1
- package/dist/cjs/types/event/result/resultEventPayload.types.d.ts +2 -1
- package/dist/cjs/types/module/module.types.d.ts +16 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/helpers/messageLogger.d.ts +1 -0
- package/dist/esm/helpers/messageLogger.js +2 -0
- package/dist/esm/index.d.ts +3 -19
- package/dist/esm/index.js +3 -69
- package/dist/esm/modules/baseModule.d.ts +3 -0
- package/dist/esm/modules/baseModule.js +5 -1
- package/dist/esm/modules/catalog/catalogModule.d.ts +1 -0
- package/dist/esm/modules/catalog/catalogModule.js +4 -0
- package/dist/esm/modules/edm/broadcastEvents/baseEdmBroadcastEvent.d.ts +5 -0
- package/dist/esm/modules/edm/broadcastEvents/baseEdmBroadcastEvent.js +6 -0
- package/dist/esm/modules/edm/broadcastEvents/onDesignStatusUpdate.d.ts +5 -0
- package/dist/esm/modules/edm/broadcastEvents/onDesignStatusUpdate.js +6 -0
- package/dist/esm/modules/edm/broadcastEvents/onErrorUpdate.d.ts +5 -0
- package/dist/esm/modules/edm/broadcastEvents/onErrorUpdate.js +6 -0
- package/dist/esm/modules/edm/broadcastEvents/onFilePickerRequested.d.ts +5 -0
- package/dist/esm/modules/edm/broadcastEvents/onFilePickerRequested.js +6 -0
- package/dist/esm/modules/edm/broadcastEvents/onPricingStatusUpdate.d.ts +5 -0
- package/dist/esm/modules/edm/broadcastEvents/onPricingStatusUpdate.js +6 -0
- package/dist/esm/modules/edm/broadcastEvents/onStepStatusUpdate.d.ts +5 -0
- package/dist/esm/modules/edm/broadcastEvents/onStepStatusUpdate.js +6 -0
- package/dist/esm/modules/edm/edmBroadcastModule.d.ts +12 -0
- package/dist/esm/modules/edm/edmBroadcastModule.js +31 -0
- package/dist/esm/modules/edm/edmModule.d.ts +13 -0
- package/dist/esm/modules/edm/edmModule.js +29 -0
- package/dist/esm/modules/edm/events.d.ts +48 -0
- package/dist/esm/modules/edm/events.js +33 -0
- package/dist/esm/modules/edm/types/data.types.d.ts +204 -0
- package/dist/esm/modules/edm/types/data.types.js +5 -0
- package/dist/esm/modules/edm/types/event/actionEvent.types.d.ts +8 -0
- package/dist/esm/modules/edm/types/event/actionEvent.types.js +1 -0
- package/dist/esm/modules/edm/types/event/actionEventPayload.types.d.ts +15 -0
- package/dist/esm/modules/edm/types/event/actionEventPayload.types.js +1 -0
- package/dist/esm/modules/edm/types/event/broadcastEvent.types.d.ts +12 -0
- package/dist/esm/modules/edm/types/event/broadcastEvent.types.js +1 -0
- package/dist/esm/modules/edm/types/event/broadcastEventPayload.types.d.ts +9 -0
- package/dist/esm/modules/edm/types/event/broadcastEventPayload.types.js +1 -0
- package/dist/esm/modules/edm/types/event/resultEvent.types.d.ts +8 -0
- package/dist/esm/modules/edm/types/event/resultEvent.types.js +1 -0
- package/dist/esm/modules/edm/types/event/resultEventPayload.types.d.ts +17 -0
- package/dist/esm/modules/edm/types/event/resultEventPayload.types.js +1 -0
- package/dist/esm/modules/edm/types/index.d.ts +6 -0
- package/dist/esm/modules/edm/types/index.js +9 -0
- package/dist/esm/modules/eventTypes.d.ts +4 -2
- package/dist/esm/modules/eventTypes.js +4 -0
- package/dist/esm/modules/events.d.ts +40 -0
- package/dist/esm/modules/events.js +8 -0
- package/dist/esm/modules/mockup-generation/mockupGenerationModule.d.ts +1 -0
- package/dist/esm/modules/mockup-generation/mockupGenerationModule.js +4 -0
- package/dist/esm/modules/moduleNames.d.ts +7 -0
- package/dist/esm/modules/moduleNames.js +7 -0
- package/dist/esm/modules/modules.d.ts +11 -6
- package/dist/esm/modules/modules.js +11 -6
- package/dist/esm/modules/product-publish/productPublishModule.d.ts +1 -0
- package/dist/esm/modules/product-publish/productPublishModule.js +4 -0
- package/dist/esm/modules/product-publish/types/event/resultEventPayload.types.d.ts +5 -0
- package/dist/esm/modules/sdk/sdkModule.d.ts +1 -0
- package/dist/esm/modules/sdk/sdkModule.js +4 -0
- package/dist/esm/services/broadcastEventDispatcher.d.ts +8 -0
- package/dist/esm/services/broadcastEventDispatcher.js +20 -0
- package/dist/esm/services/edm.d.ts +23 -0
- package/dist/esm/services/edm.js +98 -0
- package/dist/esm/services/embed.d.ts +19 -0
- package/dist/esm/services/embed.js +79 -0
- package/dist/esm/services/embedCommunicator.d.ts +10 -4
- package/dist/esm/services/embedCommunicator.js +43 -11
- package/dist/esm/services/iFrameManager.d.ts +3 -1
- package/dist/esm/services/iFrameManager.js +6 -9
- package/dist/esm/services/moduleLoaderService.d.ts +1 -2
- package/dist/esm/services/moduleLoaderService.js +3 -2
- package/dist/esm/types/event/action/actionEvent.types.d.ts +2 -1
- package/dist/esm/types/event/action/actionEventPayload.types.d.ts +2 -1
- package/dist/esm/types/event/broadcast/broadcastEvent.types.d.ts +8 -0
- package/dist/esm/types/event/broadcast/broadcastEvent.types.js +1 -0
- package/dist/esm/types/event/broadcast/broadcastEventHandler.d.ts +5 -0
- package/dist/esm/types/event/broadcast/broadcastEventHandler.js +1 -0
- package/dist/esm/types/event/broadcast/broadcastEventMap.d.ts +12 -0
- package/dist/esm/types/event/broadcast/broadcastEventMap.js +13 -0
- package/dist/esm/types/event/broadcast/broadcastEventPayload.types.d.ts +2 -0
- package/dist/esm/types/event/broadcast/broadcastEventPayload.types.js +1 -0
- package/dist/esm/types/event/event.types.d.ts +3 -2
- package/dist/esm/types/event/eventPayload.types.d.ts +2 -1
- package/dist/esm/types/event/result/resultEvent.types.d.ts +2 -1
- package/dist/esm/types/event/result/resultEventPayload.types.d.ts +2 -1
- package/dist/esm/types/module/module.types.d.ts +16 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
2
|
+
export class BroadcastEventDispatcher {
|
|
3
|
+
eventHandlers = new Map();
|
|
4
|
+
constructor() {
|
|
5
|
+
this.initHandlers();
|
|
6
|
+
}
|
|
7
|
+
do(eventName, payload) {
|
|
8
|
+
const handler = this.eventHandlers.get(eventName);
|
|
9
|
+
if (!handler) {
|
|
10
|
+
throw new Error(`Fail [do]: No event handler for '${eventName}'!`);
|
|
11
|
+
}
|
|
12
|
+
return handler.handle(payload);
|
|
13
|
+
}
|
|
14
|
+
// Initializes the event handlers by iterating over the BROADCAST_EVENT_MAP and creating instances of each handler.
|
|
15
|
+
initHandlers() {
|
|
16
|
+
for (const [eventName, EventHandlerClass] of Object.entries(BROADCAST_EVENT_MAP)) {
|
|
17
|
+
this.eventHandlers.set(eventName, new EventHandlerClass());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EDMConfig, EDMParams } from '../modules/edm/types/data.types';
|
|
2
|
+
import { EdmBroadcastModule } from '../modules/edm/edmBroadcastModule';
|
|
3
|
+
import { BroadcastListeners } from '../modules/edm/types/event/broadcastEvent.types';
|
|
4
|
+
import type { AddImagePayload, NavigateStepPayload, SetStylePayload } from '../modules/edm/types';
|
|
5
|
+
export declare class EDM {
|
|
6
|
+
private params;
|
|
7
|
+
private config?;
|
|
8
|
+
static BASE_URL: string;
|
|
9
|
+
static broadCastEventHandler: EdmBroadcastModule | null;
|
|
10
|
+
private nonce;
|
|
11
|
+
private iFrameManager;
|
|
12
|
+
private communicator;
|
|
13
|
+
private moduleLoader;
|
|
14
|
+
private initialized;
|
|
15
|
+
constructor(params: EDMParams, config?: EDMConfig | undefined, callbacks?: Partial<BroadcastListeners>);
|
|
16
|
+
init(): Promise<void>;
|
|
17
|
+
saveDesign(): Promise<import("..").HandledResponse<import("../modules/edm/types").SaveDesignResultPayload, Error>>;
|
|
18
|
+
setStyle(payload: SetStylePayload): Promise<import("..").HandledResponse<import("../modules/edm/types").SetStyleResultPayload, Error>>;
|
|
19
|
+
addImage(payload: AddImagePayload): Promise<import("..").HandledResponse<import("../modules/edm/types").AddImageResultPayload, Error>>;
|
|
20
|
+
navigateStep(payload: NavigateStepPayload): Promise<import("..").HandledResponse<import("../modules/edm/types").NavigateStepResultPayload, Error>>;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
static getBroadCastEventHandler(): EdmBroadcastModule;
|
|
23
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { iFrameManager } from '../services/iFrameManager';
|
|
2
|
+
import { EmbedCommunicator } from '../services/embedCommunicator';
|
|
3
|
+
import { ModuleLoaderService } from '../services/moduleLoaderService';
|
|
4
|
+
import { LOG_TYPES, logEmbedMessage, setLoggerState, SOURCES, } from '../helpers/messageLogger';
|
|
5
|
+
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
6
|
+
import { VERSION } from '../version';
|
|
7
|
+
import { EdmBroadcastModule } from '../modules/edm/edmBroadcastModule';
|
|
8
|
+
export class EDM {
|
|
9
|
+
params;
|
|
10
|
+
config;
|
|
11
|
+
static BASE_URL = 'https://www.printful.com/embedded-designer';
|
|
12
|
+
static broadCastEventHandler;
|
|
13
|
+
nonce;
|
|
14
|
+
iFrameManager = null;
|
|
15
|
+
communicator = EmbedCommunicator.getInstance();
|
|
16
|
+
moduleLoader = ModuleLoaderService.getInstance();
|
|
17
|
+
initialized = false;
|
|
18
|
+
constructor(params, config, callbacks) {
|
|
19
|
+
this.params = params;
|
|
20
|
+
this.config = config;
|
|
21
|
+
this.nonce = params.nonce;
|
|
22
|
+
EDM.broadCastEventHandler = new EdmBroadcastModule(callbacks);
|
|
23
|
+
setLoggerState(params?.debug ?? false, SOURCES.EDM);
|
|
24
|
+
}
|
|
25
|
+
async init() {
|
|
26
|
+
if (this.initialized) {
|
|
27
|
+
logEmbedMessage({
|
|
28
|
+
message: 'EDM already initialized',
|
|
29
|
+
logType: LOG_TYPES.WARN,
|
|
30
|
+
});
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const elementToBindTo = this.params.element ?? document.getElementById(this.params.elementId);
|
|
34
|
+
if (!elementToBindTo) {
|
|
35
|
+
logEmbedMessage({
|
|
36
|
+
message: 'Cant find element for EDM',
|
|
37
|
+
logType: LOG_TYPES.ERROR,
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.iFrameManager = new iFrameManager({
|
|
42
|
+
baseUrl: EDM.BASE_URL,
|
|
43
|
+
urlParams: {
|
|
44
|
+
nonce: this.nonce,
|
|
45
|
+
sdkMode: true,
|
|
46
|
+
locale: this.config?.locale ?? '',
|
|
47
|
+
},
|
|
48
|
+
class: this.params.iframeClassName,
|
|
49
|
+
elementToAppendTo: elementToBindTo,
|
|
50
|
+
});
|
|
51
|
+
await this.iFrameManager.create();
|
|
52
|
+
this.communicator.setIFrameManager(MODULE_NAMES.EDM, this.iFrameManager);
|
|
53
|
+
this.communicator.setupListener();
|
|
54
|
+
const edmModule = this.moduleLoader.getModule(MODULE_NAMES.EDM);
|
|
55
|
+
const notification = await edmModule.setup({
|
|
56
|
+
...this.config,
|
|
57
|
+
...this.params,
|
|
58
|
+
clientVersion: VERSION,
|
|
59
|
+
});
|
|
60
|
+
logEmbedMessage({
|
|
61
|
+
message: ['EDM setup notification', notification],
|
|
62
|
+
logType: LOG_TYPES.LOG,
|
|
63
|
+
});
|
|
64
|
+
this.initialized = true;
|
|
65
|
+
}
|
|
66
|
+
saveDesign() {
|
|
67
|
+
const edmModule = this.moduleLoader.getModule(MODULE_NAMES.EDM);
|
|
68
|
+
return edmModule.saveDesign();
|
|
69
|
+
}
|
|
70
|
+
setStyle(payload) {
|
|
71
|
+
const edmModule = this.moduleLoader.getModule(MODULE_NAMES.EDM);
|
|
72
|
+
return edmModule.setStyle(payload);
|
|
73
|
+
}
|
|
74
|
+
addImage(payload) {
|
|
75
|
+
const edmModule = this.moduleLoader.getModule(MODULE_NAMES.EDM);
|
|
76
|
+
return edmModule.addImage(payload);
|
|
77
|
+
}
|
|
78
|
+
navigateStep(payload) {
|
|
79
|
+
const edmModule = this.moduleLoader.getModule(MODULE_NAMES.EDM);
|
|
80
|
+
return edmModule.navigateStep(payload);
|
|
81
|
+
}
|
|
82
|
+
destroy() {
|
|
83
|
+
if (this.iFrameManager) {
|
|
84
|
+
this.iFrameManager.destroy();
|
|
85
|
+
this.iFrameManager = null;
|
|
86
|
+
}
|
|
87
|
+
this.communicator.cleanup();
|
|
88
|
+
this.moduleLoader.clearCache();
|
|
89
|
+
this.initialized = false;
|
|
90
|
+
EDM.broadCastEventHandler = null;
|
|
91
|
+
}
|
|
92
|
+
static getBroadCastEventHandler() {
|
|
93
|
+
if (!EDM.broadCastEventHandler) {
|
|
94
|
+
throw new Error('No active EdmBroadcastModule instance');
|
|
95
|
+
}
|
|
96
|
+
return EDM.broadCastEventHandler;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CatalogService } from '../modules/catalog/catalogService';
|
|
2
|
+
import { MockupService } from '../modules/mockup-generation/mockupService';
|
|
3
|
+
import { ProductPublishService } from '../modules/product-publish/productPublishService';
|
|
4
|
+
import { SdkConfig } from '../modules/sdk/types';
|
|
5
|
+
export declare class Embed {
|
|
6
|
+
private config?;
|
|
7
|
+
static BASE_URL: string;
|
|
8
|
+
private nonce;
|
|
9
|
+
private iFrameManager;
|
|
10
|
+
private communicator;
|
|
11
|
+
private moduleLoader;
|
|
12
|
+
private initialized;
|
|
13
|
+
readonly catalog: CatalogService;
|
|
14
|
+
readonly mockup: MockupService;
|
|
15
|
+
readonly publish: ProductPublishService;
|
|
16
|
+
constructor(nonce: string, config?: SdkConfig | undefined);
|
|
17
|
+
init(): Promise<void>;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { iFrameManager } from '../services/iFrameManager';
|
|
2
|
+
import { EmbedCommunicator } from '../services/embedCommunicator';
|
|
3
|
+
import { ModuleLoaderService } from '../services/moduleLoaderService';
|
|
4
|
+
import { CatalogService } from '../modules/catalog/catalogService';
|
|
5
|
+
import { MockupService } from '../modules/mockup-generation/mockupService';
|
|
6
|
+
import { ProductPublishService } from '../modules/product-publish/productPublishService';
|
|
7
|
+
import { LOG_TYPES, logEmbedMessage, setLoggerState, SOURCES, } from '../helpers/messageLogger';
|
|
8
|
+
import { MODULE_NAMES } from '../modules/modules';
|
|
9
|
+
import { VERSION } from '../version';
|
|
10
|
+
export class Embed {
|
|
11
|
+
config;
|
|
12
|
+
static BASE_URL = 'https://www.printful.com/embed-sdk';
|
|
13
|
+
nonce;
|
|
14
|
+
iFrameManager = null;
|
|
15
|
+
communicator = EmbedCommunicator.getInstance();
|
|
16
|
+
moduleLoader = ModuleLoaderService.getInstance();
|
|
17
|
+
initialized = false;
|
|
18
|
+
// Service composition
|
|
19
|
+
catalog;
|
|
20
|
+
mockup;
|
|
21
|
+
publish;
|
|
22
|
+
constructor(nonce, config) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.nonce = nonce;
|
|
25
|
+
setLoggerState(config?.debug ?? false, SOURCES.SDK);
|
|
26
|
+
// Initialize services
|
|
27
|
+
this.catalog = new CatalogService();
|
|
28
|
+
this.mockup = new MockupService();
|
|
29
|
+
this.publish = new ProductPublishService();
|
|
30
|
+
}
|
|
31
|
+
async init() {
|
|
32
|
+
if (this.initialized) {
|
|
33
|
+
logEmbedMessage({
|
|
34
|
+
message: 'Embed SDK already initialized',
|
|
35
|
+
logType: LOG_TYPES.WARN,
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Client mode: Create iframe and setup communication
|
|
40
|
+
this.iFrameManager = new iFrameManager({
|
|
41
|
+
baseUrl: Embed.BASE_URL,
|
|
42
|
+
urlParams: {
|
|
43
|
+
nonce: this.nonce,
|
|
44
|
+
},
|
|
45
|
+
style: {
|
|
46
|
+
display: 'none',
|
|
47
|
+
position: 'fixed',
|
|
48
|
+
width: '0',
|
|
49
|
+
height: '0',
|
|
50
|
+
border: 'none',
|
|
51
|
+
},
|
|
52
|
+
elementToAppendTo: document.body,
|
|
53
|
+
});
|
|
54
|
+
await this.iFrameManager.create();
|
|
55
|
+
// Setup communicator with iframe manager
|
|
56
|
+
this.communicator.setIFrameManager(MODULE_NAMES.SDK, this.iFrameManager);
|
|
57
|
+
this.communicator.setupListener();
|
|
58
|
+
// Get SDK module and setup
|
|
59
|
+
const sdkModule = this.moduleLoader.getModule(MODULE_NAMES.SDK);
|
|
60
|
+
const notification = await sdkModule.setup({
|
|
61
|
+
...this.config,
|
|
62
|
+
clientVersion: VERSION,
|
|
63
|
+
});
|
|
64
|
+
logEmbedMessage({
|
|
65
|
+
message: ['SDK (Main) module setup notification', notification],
|
|
66
|
+
logType: LOG_TYPES.LOG,
|
|
67
|
+
});
|
|
68
|
+
this.initialized = true;
|
|
69
|
+
}
|
|
70
|
+
destroy() {
|
|
71
|
+
if (this.iFrameManager) {
|
|
72
|
+
this.iFrameManager.destroy();
|
|
73
|
+
this.iFrameManager = null;
|
|
74
|
+
}
|
|
75
|
+
this.communicator.cleanup();
|
|
76
|
+
this.moduleLoader.clearCache();
|
|
77
|
+
this.initialized = false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import { iFrameManager } from './iFrameManager';
|
|
2
2
|
import { ActionEvent, ActionEventName } from '../types/event/action/actionEvent.types';
|
|
3
3
|
import { ActionEventPayload } from '../types/event/action/actionEventPayload.types';
|
|
4
|
+
import { BroadcastEvent } from '../types/event/broadcast/broadcastEvent.types';
|
|
5
|
+
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
4
6
|
export declare class EmbedCommunicator {
|
|
5
7
|
#private;
|
|
8
|
+
private broadcastEventHandler;
|
|
6
9
|
private messageBroker;
|
|
7
|
-
private
|
|
10
|
+
private iFrameManagers;
|
|
8
11
|
private isListening;
|
|
9
12
|
private constructor();
|
|
10
13
|
static getInstance(): EmbedCommunicator;
|
|
11
|
-
sendCorrelatedRequest<TReturn>(eventName: ActionEventName, payload?: ActionEventPayload): Promise<TReturn>;
|
|
12
|
-
setIFrameManager(iFrameManager: iFrameManager): void;
|
|
14
|
+
sendCorrelatedRequest<TReturn>(eventName: ActionEventName, moduleType: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM, payload?: ActionEventPayload): Promise<TReturn>;
|
|
15
|
+
setIFrameManager(mainModule: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM, iFrameManager: iFrameManager): void;
|
|
13
16
|
setupListener(): void;
|
|
14
17
|
private handleInboundMessageEvent;
|
|
15
18
|
private handleInboundEvent;
|
|
16
19
|
private handleInboundEventNotification;
|
|
20
|
+
private getIframeManagerByMainModule;
|
|
17
21
|
private isNotificationSuccess;
|
|
22
|
+
isValidBroadcastEvent(event: BroadcastEvent): false | import("../modules/edm/types").OnDesignStatusEvent | import("../modules/edm/types").OnErrorEvent | import("../modules/edm/types").OnFilePickerRequestedEvent | import("../modules/edm/types").StepResponse | import("../modules/edm/types/event/broadcastEventPayload.types").OnPricingStatusUpdateEventPayload | undefined;
|
|
18
23
|
private resolveSuccessfulEvent;
|
|
19
|
-
|
|
24
|
+
handleBroadcastEvent(event: BroadcastEvent): void;
|
|
25
|
+
protected send(event: ActionEvent, moduleType: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM): void;
|
|
20
26
|
cleanup(): void;
|
|
21
27
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { MessageBroker } from './messageBroker';
|
|
2
|
-
import { EVENT_TYPES, isNotification, isResult } from '../modules/eventTypes';
|
|
2
|
+
import { EVENT_TYPES, isBroadcast, isNotification, isResult, } from '../modules/eventTypes';
|
|
3
3
|
import { LOG_TYPES, logEmbedMessage } from '../helpers/messageLogger';
|
|
4
|
+
import { BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
5
|
+
import { BroadcastEventDispatcher } from '../services/broadcastEventDispatcher';
|
|
6
|
+
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
4
7
|
export class EmbedCommunicator {
|
|
5
8
|
static #instance;
|
|
9
|
+
broadcastEventHandler = new BroadcastEventDispatcher();
|
|
6
10
|
messageBroker = new MessageBroker();
|
|
7
|
-
|
|
11
|
+
iFrameManagers = { [MODULE_NAMES.SDK]: null, [MODULE_NAMES.EDM]: null };
|
|
8
12
|
isListening = false;
|
|
9
13
|
constructor() { }
|
|
10
14
|
static getInstance() {
|
|
@@ -13,7 +17,7 @@ export class EmbedCommunicator {
|
|
|
13
17
|
}
|
|
14
18
|
return EmbedCommunicator.#instance;
|
|
15
19
|
}
|
|
16
|
-
async sendCorrelatedRequest(eventName, payload) {
|
|
20
|
+
async sendCorrelatedRequest(eventName, moduleType, payload) {
|
|
17
21
|
if (!this.isListening) {
|
|
18
22
|
logEmbedMessage({
|
|
19
23
|
message: 'Warn [sendCorrelatedRequest]: Communicator is not listening, response may be ignored!',
|
|
@@ -29,11 +33,11 @@ export class EmbedCommunicator {
|
|
|
29
33
|
payload,
|
|
30
34
|
correlationId,
|
|
31
35
|
};
|
|
32
|
-
this.send(actionEvent);
|
|
36
|
+
this.send(actionEvent, moduleType);
|
|
33
37
|
return pendingMessagePromise;
|
|
34
38
|
}
|
|
35
|
-
setIFrameManager(iFrameManager) {
|
|
36
|
-
this.
|
|
39
|
+
setIFrameManager(mainModule, iFrameManager) {
|
|
40
|
+
this.iFrameManagers[mainModule] = iFrameManager;
|
|
37
41
|
}
|
|
38
42
|
setupListener() {
|
|
39
43
|
if (this.isListening) {
|
|
@@ -49,16 +53,21 @@ export class EmbedCommunicator {
|
|
|
49
53
|
message: ['Received message', event.data],
|
|
50
54
|
logType: LOG_TYPES.LOG,
|
|
51
55
|
});
|
|
52
|
-
|
|
56
|
+
const iframeManagerType = this.getIframeManagerByMainModule(event);
|
|
57
|
+
if (!iframeManagerType) {
|
|
53
58
|
throw new Error('iFrameManager not set');
|
|
54
59
|
}
|
|
55
60
|
// Only process messages from our iframe
|
|
56
|
-
if (!
|
|
61
|
+
if (!iframeManagerType.isMessageFromIFrame(event)) {
|
|
57
62
|
return;
|
|
58
63
|
}
|
|
59
64
|
this.handleInboundEvent(event.data);
|
|
60
65
|
}
|
|
61
66
|
handleInboundEvent(event) {
|
|
67
|
+
if (isBroadcast(event)) {
|
|
68
|
+
this.handleBroadcastEvent(event);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
62
71
|
if (!event.correlationId) {
|
|
63
72
|
throw new Error(`Fail [handleInboundEvent (${event.name})]: correlationId missing`);
|
|
64
73
|
}
|
|
@@ -75,6 +84,9 @@ export class EmbedCommunicator {
|
|
|
75
84
|
throw new Error('Fail [handleInboundEvent]: Unsupported event type received!');
|
|
76
85
|
}
|
|
77
86
|
handleInboundEventNotification(event) {
|
|
87
|
+
if (!event.correlationId) {
|
|
88
|
+
throw new Error(`Fail [handleInboundEventNotification (${event.name})]: correlationId missing`);
|
|
89
|
+
}
|
|
78
90
|
if (this.isNotificationSuccess(event)) {
|
|
79
91
|
this.resolveSuccessfulEvent(event);
|
|
80
92
|
return;
|
|
@@ -83,20 +95,40 @@ export class EmbedCommunicator {
|
|
|
83
95
|
// Error should always be provided on a notification with fail status
|
|
84
96
|
event.payload);
|
|
85
97
|
}
|
|
98
|
+
getIframeManagerByMainModule(event) {
|
|
99
|
+
for (const manager of Object.values(this.iFrameManagers)) {
|
|
100
|
+
if (manager?.isMessageFromIFrame(event)) {
|
|
101
|
+
return manager;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
86
106
|
isNotificationSuccess(event) {
|
|
87
107
|
if (!event.payload) {
|
|
88
108
|
throw new Error(`Fail [handleNotification (${event.name})] Payload missing!`);
|
|
89
109
|
}
|
|
90
110
|
return event.payload.status === 'success';
|
|
91
111
|
}
|
|
112
|
+
isValidBroadcastEvent(event) {
|
|
113
|
+
return event.name in BROADCAST_EVENT_MAP && event.payload;
|
|
114
|
+
}
|
|
92
115
|
resolveSuccessfulEvent(event) {
|
|
116
|
+
if (!event.correlationId) {
|
|
117
|
+
throw new Error(`Fail [resolveSuccessfulEvent (${event.name})]: correlationId missing`);
|
|
118
|
+
}
|
|
93
119
|
this.messageBroker.resolveMessage(event.correlationId, event.payload);
|
|
94
120
|
}
|
|
95
|
-
|
|
96
|
-
if (!this.
|
|
121
|
+
handleBroadcastEvent(event) {
|
|
122
|
+
if (!this.isValidBroadcastEvent(event) || !event.payload) {
|
|
123
|
+
throw new Error(`Fail [handleInboundEvent (${event.name})]: Broadcast event payload missing`);
|
|
124
|
+
}
|
|
125
|
+
this.broadcastEventHandler.do(event.name, event.payload);
|
|
126
|
+
}
|
|
127
|
+
send(event, moduleType) {
|
|
128
|
+
if (!this.iFrameManagers[moduleType]) {
|
|
97
129
|
throw new Error('iFrameManager not set');
|
|
98
130
|
}
|
|
99
|
-
this.
|
|
131
|
+
this.iFrameManagers[moduleType].postMessage(event);
|
|
100
132
|
}
|
|
101
133
|
cleanup() {
|
|
102
134
|
this.messageBroker.clearAll();
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
export interface IFrameConfig {
|
|
2
2
|
baseUrl: string;
|
|
3
|
-
nonce: string;
|
|
4
3
|
style?: Partial<CSSStyleDeclaration>;
|
|
4
|
+
urlParams: Record<string, string | number | boolean>;
|
|
5
|
+
class?: string;
|
|
6
|
+
elementToAppendTo: HTMLElement;
|
|
5
7
|
}
|
|
6
8
|
export declare class iFrameManager {
|
|
7
9
|
private config;
|
|
@@ -10,17 +10,14 @@ export class iFrameManager {
|
|
|
10
10
|
return new Promise((resolve, reject) => {
|
|
11
11
|
this.destroy();
|
|
12
12
|
const iFrame = document.createElement('iframe');
|
|
13
|
-
// Apply default styles
|
|
14
|
-
iFrame.style.display = 'none';
|
|
15
|
-
iFrame.style.position = 'fixed';
|
|
16
|
-
iFrame.style.width = '0';
|
|
17
|
-
iFrame.style.height = '0';
|
|
18
|
-
iFrame.style.border = 'none';
|
|
19
|
-
// Apply custom styles if provided
|
|
20
13
|
if (this.config.style) {
|
|
21
14
|
Object.assign(iFrame.style, this.config.style);
|
|
22
15
|
}
|
|
23
|
-
|
|
16
|
+
if (this.config.class) {
|
|
17
|
+
iFrame.setAttribute('class', this.config.class);
|
|
18
|
+
}
|
|
19
|
+
const convertedUrlParams = Object.entries(this.config.urlParams).map(([k, v]) => [k, String(v)]);
|
|
20
|
+
iFrame.src = `${this.config.baseUrl}?${new URLSearchParams(convertedUrlParams).toString()}`;
|
|
24
21
|
let settled = false;
|
|
25
22
|
const cleanup = () => {
|
|
26
23
|
settled = true;
|
|
@@ -43,7 +40,7 @@ export class iFrameManager {
|
|
|
43
40
|
};
|
|
44
41
|
iFrame.addEventListener('load', onLoad);
|
|
45
42
|
iFrame.addEventListener('error', onError);
|
|
46
|
-
|
|
43
|
+
this.config.elementToAppendTo.appendChild(iFrame);
|
|
47
44
|
});
|
|
48
45
|
}
|
|
49
46
|
destroy() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModuleName } from '../types/module/module.types';
|
|
2
2
|
import { MODULES } from '../modules/modules';
|
|
3
3
|
import { ModuleConfig, ModuleConfigData } from '../types/module/moduleConfig.types';
|
|
4
|
-
type ModuleInstance = InstanceType<(typeof MODULES)[keyof typeof MODULES]>;
|
|
4
|
+
export type ModuleInstance = InstanceType<(typeof MODULES)[keyof typeof MODULES]>;
|
|
5
5
|
export declare class ModuleLoaderService {
|
|
6
6
|
private static instance;
|
|
7
7
|
private communicator;
|
|
@@ -13,4 +13,3 @@ export declare class ModuleLoaderService {
|
|
|
13
13
|
clearCache(): void;
|
|
14
14
|
isModuleLoaded(moduleName: ModuleName): boolean;
|
|
15
15
|
}
|
|
16
|
-
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EmbedCommunicator } from './embedCommunicator';
|
|
2
|
-
import { MODULES } from '../modules/modules';
|
|
2
|
+
import { MODULE_DEPENDENCY_MAP, MODULES } from '../modules/modules';
|
|
3
3
|
import { EVENTS_ACTION } from '../modules/sdk/types';
|
|
4
4
|
import { LOG_TYPES, logEmbedMessage } from '../helpers/messageLogger';
|
|
5
5
|
export class ModuleLoaderService {
|
|
@@ -20,7 +20,8 @@ export class ModuleLoaderService {
|
|
|
20
20
|
return this.moduleCache.get(moduleName);
|
|
21
21
|
}
|
|
22
22
|
async loadModule(config) {
|
|
23
|
-
const
|
|
23
|
+
const mainModule = MODULE_DEPENDENCY_MAP[config.name];
|
|
24
|
+
const notification = await this.communicator.sendCorrelatedRequest(EVENTS_ACTION.LOAD_MODULE, mainModule, config);
|
|
24
25
|
logEmbedMessage({
|
|
25
26
|
message: ['Loaded module', notification],
|
|
26
27
|
logType: LOG_TYPES.LOG,
|
|
@@ -2,10 +2,11 @@ import { ActionEvent as SdkActionEvent } from '../../../modules/sdk/types/event/
|
|
|
2
2
|
import { ActionEvent as CatalogActionEvent } from '../../../modules/catalog/types/event/actionEvent.types';
|
|
3
3
|
import { ActionEvent as MockupGenerationActionEvent } from '../../../modules/mockup-generation/types/event/actionEvent.types';
|
|
4
4
|
import { ActionEvent as ProductPublishActionEvent } from '../../../modules/product-publish/types/event/actionEvent.types';
|
|
5
|
+
import { ActionEvent as EdmActionEvent } from '../../../modules/edm/types/event/actionEvent.types';
|
|
5
6
|
import { ALL_ACTION_EVENTS } from '../../../modules/events';
|
|
6
7
|
import { Event } from '../../../types/event/event.types';
|
|
7
8
|
import { EVENT_TYPES } from '../../../modules/eventTypes';
|
|
8
9
|
import { ActionEventPayload } from './actionEventPayload.types';
|
|
9
10
|
export type ActionEventName = (typeof ALL_ACTION_EVENTS)[keyof typeof ALL_ACTION_EVENTS];
|
|
10
11
|
export type BaseActionEvent<TName extends ActionEventName, TPayload extends ActionEventPayload> = Event<TName, typeof EVENT_TYPES.ACTION, TPayload>;
|
|
11
|
-
export type ActionEvent = MockupGenerationActionEvent | CatalogActionEvent | ProductPublishActionEvent | SdkActionEvent;
|
|
12
|
+
export type ActionEvent = MockupGenerationActionEvent | CatalogActionEvent | ProductPublishActionEvent | SdkActionEvent | EdmActionEvent;
|
|
@@ -2,4 +2,5 @@ import { ActionEventPayload as SdkEventPayload, LoadModulePayload } from '../../
|
|
|
2
2
|
import { ActionEventPayload as CatalogEventPayload } from '../../../modules/catalog/types/event/actionEventPayload.types';
|
|
3
3
|
import { ActionEventPayload as MockupGenerationEventPayload } from '../../../modules/mockup-generation/types/event/actionEventPayload.types';
|
|
4
4
|
import { ActionEventPayload as ProductPublishEventPayload } from '../../../modules/product-publish/types/event/actionEventPayload.types';
|
|
5
|
-
|
|
5
|
+
import { ActionEventPayload as EdmEventPayload } from '../../../modules/edm/types/event/actionEventPayload.types';
|
|
6
|
+
export type ActionEventPayload = LoadModulePayload | MockupGenerationEventPayload | CatalogEventPayload | SdkEventPayload | ProductPublishEventPayload | EdmEventPayload | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ALL_BROADCAST_EVENTS } from '../../../modules/events';
|
|
2
|
+
import { Event } from '../../../types/event/event.types';
|
|
3
|
+
import { EVENT_TYPES } from '../../../modules/eventTypes';
|
|
4
|
+
import { BroadcastEventPayload } from '../../../types/event/broadcast/broadcastEventPayload.types';
|
|
5
|
+
import { BroadcastEvent as EdmBroadcastEvent } from '../../../modules/edm/types/event/broadcastEvent.types';
|
|
6
|
+
export type BroadcastEventName = (typeof ALL_BROADCAST_EVENTS)[keyof typeof ALL_BROADCAST_EVENTS];
|
|
7
|
+
export type BaseBroadcastEvent<TName extends BroadcastEventName, TPayload extends BroadcastEventPayload> = Event<TName, typeof EVENT_TYPES.BROADCAST, TPayload>;
|
|
8
|
+
export type BroadcastEvent = EdmBroadcastEvent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BroadcastEventPayload } from '../../../types/event/broadcast/broadcastEventPayload.types';
|
|
2
|
+
import { BROADCAST_EVENT_MAP } from '../../../types/event/broadcast/broadcastEventMap';
|
|
3
|
+
export interface BroadcastEventHandler {
|
|
4
|
+
handle(payload?: BroadcastEventPayload): typeof BROADCAST_EVENT_MAP;
|
|
5
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
2
|
+
import { OnStepStatusUpdate } from '../../../modules/edm/broadcastEvents/onStepStatusUpdate';
|
|
3
|
+
import { OnPricingStatusUpdate } from '../../../modules/edm/broadcastEvents/onPricingStatusUpdate';
|
|
4
|
+
import { OnFilePickerRequested } from '../../../modules/edm/broadcastEvents/onFilePickerRequested';
|
|
5
|
+
import { OnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
6
|
+
export declare const BROADCAST_EVENT_MAP: {
|
|
7
|
+
onDesignStatusUpdate: typeof OnDesignStatusUpdate;
|
|
8
|
+
onFilePickerRequested: typeof OnFilePickerRequested;
|
|
9
|
+
onStepStatusUpdate: typeof OnStepStatusUpdate;
|
|
10
|
+
onPricingStatusUpdate: typeof OnPricingStatusUpdate;
|
|
11
|
+
onError: typeof OnErrorUpdate;
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ALL_BROADCAST_EVENTS } from '../../../modules/events';
|
|
2
|
+
import { OnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
3
|
+
import { OnStepStatusUpdate } from '../../../modules/edm/broadcastEvents/onStepStatusUpdate';
|
|
4
|
+
import { OnPricingStatusUpdate } from '../../../modules/edm/broadcastEvents/onPricingStatusUpdate';
|
|
5
|
+
import { OnFilePickerRequested } from '../../../modules/edm/broadcastEvents/onFilePickerRequested';
|
|
6
|
+
import { OnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
7
|
+
export const BROADCAST_EVENT_MAP = {
|
|
8
|
+
[ALL_BROADCAST_EVENTS.ON_DESIGN_STATUS_UPDATE]: OnDesignStatusUpdate,
|
|
9
|
+
[ALL_BROADCAST_EVENTS.ON_FILE_PICKER_REQUESTED]: OnFilePickerRequested,
|
|
10
|
+
[ALL_BROADCAST_EVENTS.ON_STEP_STATUS_UPDATE]: OnStepStatusUpdate,
|
|
11
|
+
[ALL_BROADCAST_EVENTS.ON_PRICING_STATUS_UPDATE]: OnPricingStatusUpdate,
|
|
12
|
+
[ALL_BROADCAST_EVENTS.ON_INTERNAL_ERROR]: OnErrorUpdate,
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,12 +4,13 @@ import type { NotificationEvent } from './notification/notificationEvent.types';
|
|
|
4
4
|
import type { ResultEvent } from './result/resultEvent.types';
|
|
5
5
|
import { EVENT_TYPES } from '../../modules/eventTypes';
|
|
6
6
|
import { EventPayload } from './eventPayload.types';
|
|
7
|
+
import { BroadcastEvent } from '../../types/event/broadcast/broadcastEvent.types';
|
|
7
8
|
export type EventName = (typeof ALL_EVENTS)[keyof typeof ALL_EVENTS];
|
|
8
9
|
export type EventTypeName = (typeof EVENT_TYPES)[keyof typeof EVENT_TYPES];
|
|
9
10
|
export interface Event<TName extends EventName, TType extends EventTypeName, TPayload extends EventPayload> {
|
|
10
11
|
name: TName;
|
|
11
12
|
type: TType;
|
|
12
13
|
payload?: TPayload;
|
|
13
|
-
correlationId
|
|
14
|
+
correlationId?: string;
|
|
14
15
|
}
|
|
15
|
-
export type AnyEvent = ActionEvent | NotificationEvent | ResultEvent;
|
|
16
|
+
export type AnyEvent = ActionEvent | NotificationEvent | ResultEvent | BroadcastEvent;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ActionEventPayload } from './action/actionEventPayload.types';
|
|
2
2
|
import type { NotificationEventPayload } from './notification/notificationEventPayload.types';
|
|
3
3
|
import { ResultEventPayload } from './result/resultEventPayload.types';
|
|
4
|
-
|
|
4
|
+
import { BroadcastEventPayload } from '../../types/event/broadcast/broadcastEventPayload.types';
|
|
5
|
+
export type EventPayload = ActionEventPayload | NotificationEventPayload | ResultEventPayload | BroadcastEventPayload | undefined;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { ResultEvent as CatalogResultEvent } from '../../../modules/catalog/types/event/resultEvent.types';
|
|
2
2
|
import { ResultEvent as MockupGenerationResultEvent } from '../../../modules/mockup-generation/types/event/resultEvent.types';
|
|
3
3
|
import { ResultEvent as ProductPublishResultEvent } from '../../../modules/product-publish/types/event/resultEvent.types';
|
|
4
|
+
import { ResultEvent as EdmResultPayload } from '../../../modules/edm/types/event/resultEvent.types';
|
|
4
5
|
import { ResultEventPayload } from './resultEventPayload.types';
|
|
5
6
|
import { EVENT_TYPES } from '../../../modules/eventTypes';
|
|
6
7
|
import { Event } from '../../../types/event/event.types';
|
|
7
8
|
import { ALL_RESULT_EVENTS } from '../../../modules/events';
|
|
8
9
|
export type ResultEventName = (typeof ALL_RESULT_EVENTS)[keyof typeof ALL_RESULT_EVENTS];
|
|
9
10
|
export type BaseResultEvent<TName extends ResultEventName, TPayload extends ResultEventPayload> = Event<TName, typeof EVENT_TYPES.RESULT, TPayload>;
|
|
10
|
-
export type ResultEvent = MockupGenerationResultEvent | CatalogResultEvent | ProductPublishResultEvent;
|
|
11
|
+
export type ResultEvent = MockupGenerationResultEvent | CatalogResultEvent | ProductPublishResultEvent | EdmResultPayload;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { CatalogResultPayload } from '../../../modules/catalog/types';
|
|
2
2
|
import type { MockupGenerationResultPayload } from '../../../modules/mockup-generation/types';
|
|
3
3
|
import type { ProductPublishResultPayload } from '../../../modules/product-publish/types';
|
|
4
|
-
|
|
4
|
+
import type { EdmResultPayload } from '../../../modules/edm/types/event/resultEventPayload.types';
|
|
5
|
+
export type ResultEventPayload = MockupGenerationResultPayload | CatalogResultPayload | ProductPublishResultPayload | EdmResultPayload;
|
|
5
6
|
export type HandledResponse<T, K extends Error> = {
|
|
6
7
|
data: T;
|
|
7
8
|
error: null;
|
|
@@ -4,6 +4,8 @@ import { SdkModuleConfigData } from '../../modules/sdk/types';
|
|
|
4
4
|
import { GetCatalogCategoriesResultPayload, GetCatalogProductsByIdsPayload, GetCatalogProductsPayload, GetCatalogProductsResultPayload, GetSingleCatalogProductPayload, GetSingleCatalogProductResultPayload } from '../../modules/catalog/types';
|
|
5
5
|
import { NotificationEventPayload } from '../../types/event/notification/notificationEventPayload.types';
|
|
6
6
|
import { GetProductPublishPayload, ProductPublishData } from '../../modules/product-publish/types';
|
|
7
|
+
import { OnDesignStatusEventPayload, OnErrorEventPayload, OnFilePickerRequestedEventPayload, OnPricingStatusUpdateEventPayload, OnStepStatusUpdateEventPayload } from '../../modules/edm/types/event/broadcastEventPayload.types';
|
|
8
|
+
import { AddImagePayload, AddImageResultPayload, InitializeEdmPayload, NavigateStepPayload, NavigateStepResultPayload, SaveDesignResultPayload, SetStylePayload, SetStyleResultPayload } from '../../modules/edm/types';
|
|
7
9
|
/** This file ensures that Iframe and SDK has the same source of truth for return values */
|
|
8
10
|
export type ModuleName = (typeof MODULE_NAMES)[keyof typeof MODULE_NAMES];
|
|
9
11
|
export interface ISdkModule {
|
|
@@ -22,3 +24,17 @@ export interface IMockupGenerationModule {
|
|
|
22
24
|
export interface IProductPublishModule {
|
|
23
25
|
productPublish(data: GetProductPublishPayload): ProductPublishData;
|
|
24
26
|
}
|
|
27
|
+
export interface IEdmModule {
|
|
28
|
+
setup(config?: InitializeEdmPayload): NotificationEventPayload | void;
|
|
29
|
+
saveDesign(): SaveDesignResultPayload;
|
|
30
|
+
addImage(payload: AddImagePayload): AddImageResultPayload;
|
|
31
|
+
setStyle(payload: SetStylePayload): SetStyleResultPayload;
|
|
32
|
+
navigateStep(payload: NavigateStepPayload): NavigateStepResultPayload;
|
|
33
|
+
}
|
|
34
|
+
export interface IEdmBroadcastModule {
|
|
35
|
+
onDesignStatusUpdate(event: OnDesignStatusEventPayload): void;
|
|
36
|
+
onFilePickerRequested(event: OnFilePickerRequestedEventPayload): void;
|
|
37
|
+
onPricingStatusUpdate(event: OnPricingStatusUpdateEventPayload): void;
|
|
38
|
+
onStepStatusUpdate(event: OnStepStatusUpdateEventPayload): void;
|
|
39
|
+
onErrorUpdate(event: OnErrorEventPayload): void;
|
|
40
|
+
}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION: "2.
|
|
1
|
+
export declare const VERSION: "2.3.0";
|
package/dist/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// AUTO-GENERATED
|
|
2
|
-
export const VERSION = '2.
|
|
2
|
+
export const VERSION = '2.3.0';
|