@fyul/embed-sdk 2.7.54 → 2.7.56
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/modules/eventTypes.d.ts +1 -1
- package/dist/cjs/modules/events.d.ts +4 -0
- package/dist/cjs/modules/white-label/events.d.ts +4 -0
- package/dist/cjs/modules/white-label/events.js +2 -0
- package/dist/cjs/modules/white-label/types/data.types.d.ts +6 -0
- package/dist/cjs/modules/white-label/types/event/actionEventPayload.types.d.ts +2 -1
- package/dist/cjs/modules/white-label/types/event/resultEvent.types.d.ts +3 -2
- package/dist/cjs/modules/white-label/types/event/resultEventPayload.types.d.ts +5 -1
- package/dist/cjs/modules/white-label/whiteLabelModule.d.ts +2 -1
- package/dist/cjs/modules/white-label/whiteLabelModule.js +4 -0
- package/dist/cjs/services/broadcastEventDispatcher.d.ts +3 -1
- package/dist/cjs/services/broadcastEventDispatcher.js +5 -6
- package/dist/cjs/services/edm.js +2 -0
- package/dist/cjs/services/embedCommunicator.d.ts +11 -6
- package/dist/cjs/services/embedCommunicator.js +18 -12
- package/dist/cjs/services/embedStudio.js +2 -0
- package/dist/cjs/services/whiteLabel.d.ts +1 -0
- package/dist/cjs/services/whiteLabel.js +6 -0
- package/dist/cjs/types/event/broadcast/broadcastEventMap.d.ts +22 -5
- package/dist/cjs/types/event/broadcast/broadcastEventMap.js +16 -4
- package/dist/cjs/types/event/broadcast/broadcastEventPayload.types.d.ts +2 -1
- package/dist/cjs/types/module/module.types.d.ts +2 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/modules/eventTypes.d.ts +1 -1
- package/dist/esm/modules/events.d.ts +4 -0
- package/dist/esm/modules/white-label/events.d.ts +4 -0
- package/dist/esm/modules/white-label/events.js +2 -0
- package/dist/esm/modules/white-label/types/data.types.d.ts +6 -0
- package/dist/esm/modules/white-label/types/event/actionEventPayload.types.d.ts +2 -1
- package/dist/esm/modules/white-label/types/event/resultEvent.types.d.ts +3 -2
- package/dist/esm/modules/white-label/types/event/resultEventPayload.types.d.ts +5 -1
- package/dist/esm/modules/white-label/whiteLabelModule.d.ts +2 -1
- package/dist/esm/modules/white-label/whiteLabelModule.js +4 -0
- package/dist/esm/services/broadcastEventDispatcher.d.ts +3 -1
- package/dist/esm/services/broadcastEventDispatcher.js +5 -6
- package/dist/esm/services/edm.js +2 -0
- package/dist/esm/services/embedCommunicator.d.ts +11 -6
- package/dist/esm/services/embedCommunicator.js +19 -13
- package/dist/esm/services/embedStudio.js +2 -0
- package/dist/esm/services/whiteLabel.d.ts +1 -0
- package/dist/esm/services/whiteLabel.js +6 -0
- package/dist/esm/types/event/broadcast/broadcastEventMap.d.ts +22 -5
- package/dist/esm/types/event/broadcast/broadcastEventMap.js +19 -7
- package/dist/esm/types/event/broadcast/broadcastEventPayload.types.d.ts +2 -1
- package/dist/esm/types/module/module.types.d.ts +2 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -7,5 +7,5 @@ export declare const EVENT_TYPES: {
|
|
|
7
7
|
};
|
|
8
8
|
export declare function isAction(event: AnyEvent): event is import("./sdk/types").InitializeSdkAction | import("./sdk/types").LoadModuleAction | import("./mockup-generation/types").GetMockupsAction | import("./mockup-generation/types").GetMoreMockupsAction | import("./mockup-generation/types").AdjustMockupAction | import("./edm/types").InitializeEdmAction | import("./edm/types").SaveDesignAction | import("./edm/types").AddImageAction | import("./edm/types").NavigateStepAction | import("./white-label/types").InitializeWhiteLabelAction | import("./catalog/types").GetCatalogCategoriesAction | import("./catalog/types").GetCatalogProductsByIdsAction | import("./catalog/types").GetCatalogProductsAction | import("./catalog/types").GetSingleCatalogProductAction | import("./product-publish/types").DeleteProductsAction | import("./product-publish/types").GetSavedProductsAction | import("./product-publish/types").GetProductPublishAction | import("./embed-studio/types").InitializeEmbedStudioAction | import("./embed-studio/types").SaveDesignAction;
|
|
9
9
|
export declare function isNotification(event: AnyEvent): event is import("..").NotificationEvent;
|
|
10
|
-
export declare function isResult(event: AnyEvent): event is import("./catalog/types").GetCatalogProductsResult | import("./catalog/types").GetSingleCatalogProductResult | import("./catalog/types").GetCatalogCategoriesResult | import("./product-publish/types").GetProductPublishResult | import("./product-publish/types").GetSavedProductsResult | import("./product-publish/types").GetSavedProductMockupsResult | import("./product-publish/types").DeleteProductsResult | import("./edm/types").SaveDesignResultEvent | import("./edm/types").AddImageResultEvent | import("./edm/types").SetStyleResultEvent | import("./edm/types").NavigateStepResultEvent | import("./embed-studio/types").SaveDesignResultEvent | import("./mockup-generation/types").GetMockupsResultEvent | import("./mockup-generation/types").GetMoreMockupsResultEvent | import("./mockup-generation/types").AdjustMockupResultEvent | import("./white-label/types").GoToViewResultEvent;
|
|
10
|
+
export declare function isResult(event: AnyEvent): event is import("./catalog/types").GetCatalogProductsResult | import("./catalog/types").GetSingleCatalogProductResult | import("./catalog/types").GetCatalogCategoriesResult | import("./product-publish/types").GetProductPublishResult | import("./product-publish/types").GetSavedProductsResult | import("./product-publish/types").GetSavedProductMockupsResult | import("./product-publish/types").DeleteProductsResult | import("./edm/types").SaveDesignResultEvent | import("./edm/types").AddImageResultEvent | import("./edm/types").SetStyleResultEvent | import("./edm/types").NavigateStepResultEvent | import("./embed-studio/types").SaveDesignResultEvent | import("./mockup-generation/types").GetMockupsResultEvent | import("./mockup-generation/types").GetMoreMockupsResultEvent | import("./mockup-generation/types").AdjustMockupResultEvent | import("./white-label/types").GoToViewResultEvent | import("./white-label/types").GetAvailableRoutesResultEvent;
|
|
11
11
|
export declare function isBroadcast(event: AnyEvent): event is import("./edm/types/event/broadcastEvent.types").OnDesignStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnPricingStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnFilePickerRequestBroadcast | import("./edm/types/event/broadcastEvent.types").OnStepStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnErrorUpdateBroadcast | import("./white-label/types").OnShoppingCartUpdateBroadcast | import("./white-label/types").OnContentSizeChangeBroadcast;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const ALL_ACTION_EVENTS: {
|
|
2
2
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
3
3
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
4
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
4
5
|
readonly INITIALIZE_EMBED_STUDIO: "actionInitializeEdm";
|
|
5
6
|
readonly SAVE_DESIGN: "actionSaveDesign";
|
|
6
7
|
readonly INITIALIZE_EDM: "actionInitializeEdm";
|
|
@@ -45,6 +46,7 @@ export declare const ALL_NOTIFICATION_EVENTS: {
|
|
|
45
46
|
};
|
|
46
47
|
export declare const ALL_RESULT_EVENTS: {
|
|
47
48
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
49
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
48
50
|
readonly SAVE_DESIGN_RESULT: "resultSaveDesign";
|
|
49
51
|
readonly ADD_IMAGE_RESULT: "resultAddImage";
|
|
50
52
|
readonly SET_STYLE_RESULT: "resultSetStyle";
|
|
@@ -78,6 +80,7 @@ export declare const ALL_EVENTS: {
|
|
|
78
80
|
readonly ON_FILE_PICKER_REQUESTED: "onFilePickerRequested";
|
|
79
81
|
readonly ON_STEP_STATUS_UPDATE: "onStepStatusUpdate";
|
|
80
82
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
83
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
81
84
|
readonly SAVE_DESIGN_RESULT: "resultSaveDesign";
|
|
82
85
|
readonly ADD_IMAGE_RESULT: "resultAddImage";
|
|
83
86
|
readonly SET_STYLE_RESULT: "resultSetStyle";
|
|
@@ -114,6 +117,7 @@ export declare const ALL_EVENTS: {
|
|
|
114
117
|
readonly SDK_INITIALIZATION_SUCCESS: "notificationSdkInitializationSuccess";
|
|
115
118
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
116
119
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
120
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
117
121
|
readonly INITIALIZE_EMBED_STUDIO: "actionInitializeEdm";
|
|
118
122
|
readonly SAVE_DESIGN: "actionSaveDesign";
|
|
119
123
|
readonly INITIALIZE_EDM: "actionInitializeEdm";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const EVENTS_ACTION: {
|
|
2
2
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
3
3
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
4
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
4
5
|
};
|
|
5
6
|
export declare const EVENTS_NOTIFICATION: {
|
|
6
7
|
readonly WHITE_LABEL_INITIALIZATION_FAILURE: "notificationWhiteLabelInitializationFailure";
|
|
@@ -9,6 +10,7 @@ export declare const EVENTS_NOTIFICATION: {
|
|
|
9
10
|
};
|
|
10
11
|
export declare const EVENTS_RESULT: {
|
|
11
12
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
13
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
12
14
|
};
|
|
13
15
|
export declare const EVENT_BROADCAST: {
|
|
14
16
|
readonly ON_SHOPPING_CART_UPDATE: "onShoppingCartUpdate";
|
|
@@ -18,9 +20,11 @@ export declare const EVENTS: {
|
|
|
18
20
|
readonly ON_SHOPPING_CART_UPDATE: "onShoppingCartUpdate";
|
|
19
21
|
readonly ON_CONTENT_SIZE_CHANGE: "onContentSizeChange";
|
|
20
22
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
23
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
21
24
|
readonly WHITE_LABEL_INITIALIZATION_FAILURE: "notificationWhiteLabelInitializationFailure";
|
|
22
25
|
readonly WHITE_LABEL_INITIALIZATION_SUCCESS: "notificationWhiteLabelInitializationSuccess";
|
|
23
26
|
readonly GO_TO_VIEW_FAILURE: "actionGoToViewFailure";
|
|
24
27
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
25
28
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
29
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
26
30
|
};
|
|
@@ -4,6 +4,7 @@ exports.EVENTS = exports.EVENT_BROADCAST = exports.EVENTS_RESULT = exports.EVENT
|
|
|
4
4
|
exports.EVENTS_ACTION = {
|
|
5
5
|
INITIALIZE_WHITE_LABEL: 'actionInitializeWhiteLabel',
|
|
6
6
|
GO_TO_VIEW: 'actionGoToView',
|
|
7
|
+
GET_AVAILABLE_ROUTES: 'actionGetAvailableRoutes',
|
|
7
8
|
};
|
|
8
9
|
exports.EVENTS_NOTIFICATION = {
|
|
9
10
|
WHITE_LABEL_INITIALIZATION_FAILURE: 'notificationWhiteLabelInitializationFailure',
|
|
@@ -12,6 +13,7 @@ exports.EVENTS_NOTIFICATION = {
|
|
|
12
13
|
};
|
|
13
14
|
exports.EVENTS_RESULT = {
|
|
14
15
|
GO_TO_VIEW_RESULT: 'resultGoToView',
|
|
16
|
+
GET_AVAILABLE_ROUTES_RESULT: 'resultGetAvailableRoutes',
|
|
15
17
|
};
|
|
16
18
|
exports.EVENT_BROADCAST = {
|
|
17
19
|
ON_SHOPPING_CART_UPDATE: 'onShoppingCartUpdate',
|
|
@@ -12,6 +12,7 @@ export type WhiteLabelParams = ({
|
|
|
12
12
|
} & WhiteLabelCommonParams);
|
|
13
13
|
export interface WhiteLabelCommonParams {
|
|
14
14
|
jwt: string;
|
|
15
|
+
userFlow: 'd2c' | 'retail' | 'creator';
|
|
15
16
|
iframeClassName?: string;
|
|
16
17
|
debug?: boolean;
|
|
17
18
|
}
|
|
@@ -32,6 +33,11 @@ export interface OnShoppingCartUpdateEvent {
|
|
|
32
33
|
export interface OnContentSizeChangeEvent {
|
|
33
34
|
height: number;
|
|
34
35
|
}
|
|
36
|
+
export type AvailableRouteInfo = {
|
|
37
|
+
name: string;
|
|
38
|
+
title: string;
|
|
39
|
+
params: string[];
|
|
40
|
+
};
|
|
35
41
|
export interface JWTData {
|
|
36
42
|
tid: string;
|
|
37
43
|
nce: string;
|
|
@@ -3,6 +3,7 @@ export type InitializeWhiteLabelPayload = WhiteLabelConfig & WhiteLabelCommonPar
|
|
|
3
3
|
clientVersion: string;
|
|
4
4
|
};
|
|
5
5
|
export interface GoToViewPayload {
|
|
6
|
-
|
|
6
|
+
name: string;
|
|
7
|
+
params?: Record<string, string | number>;
|
|
7
8
|
}
|
|
8
9
|
export type ActionEventPayload = InitializeWhiteLabelPayload | GoToViewPayload;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseResultEvent } from '../../../../types/event/result/resultEvent.types';
|
|
2
2
|
import type { EVENTS_RESULT } from '../../../../modules/white-label/events';
|
|
3
|
-
import { GoToViewResultPayload } from '../../../../modules/white-label/types';
|
|
3
|
+
import { GetAvailableRoutesResultPayload, GoToViewResultPayload } from '../../../../modules/white-label/types';
|
|
4
4
|
export type GoToViewResultEvent = BaseResultEvent<typeof EVENTS_RESULT.GO_TO_VIEW_RESULT, GoToViewResultPayload>;
|
|
5
|
-
export type
|
|
5
|
+
export type GetAvailableRoutesResultEvent = BaseResultEvent<typeof EVENTS_RESULT.GET_AVAILABLE_ROUTES_RESULT, GetAvailableRoutesResultPayload>;
|
|
6
|
+
export type ResultEvent = GoToViewResultEvent | GetAvailableRoutesResultEvent;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { AvailableRouteInfo } from '../../../../modules/white-label/types/data.types';
|
|
1
2
|
export type SetupNotificationPayload = {
|
|
2
3
|
error: Error | null;
|
|
3
4
|
};
|
|
4
5
|
export type GoToViewResultPayload = {
|
|
5
6
|
success: boolean;
|
|
6
7
|
};
|
|
7
|
-
export type
|
|
8
|
+
export type GetAvailableRoutesResultPayload = {
|
|
9
|
+
routes: AvailableRouteInfo[];
|
|
10
|
+
};
|
|
11
|
+
export type WhiteLabelResultPayload = GoToViewResultPayload | GetAvailableRoutesResultPayload;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IWhiteLabelModule } from '../../types/module/module.types';
|
|
2
2
|
import { BaseModule } from '../../modules/baseModule';
|
|
3
|
-
import { InitializeWhiteLabelPayload, GoToViewPayload, GoToViewResultPayload, SetupNotificationPayload } from './types';
|
|
3
|
+
import { InitializeWhiteLabelPayload, GoToViewPayload, GoToViewResultPayload, GetAvailableRoutesResultPayload, SetupNotificationPayload } from './types';
|
|
4
4
|
import { PromisifyMethods, WithHandledResponses } from '../../helpers/typeHelper.types';
|
|
5
5
|
export declare class WhiteLabelModule extends BaseModule implements Omit<WithHandledResponses<IWhiteLabelModule>, 'setup'>, Pick<PromisifyMethods<IWhiteLabelModule>, 'setup'> {
|
|
6
6
|
constructor();
|
|
7
7
|
setup(payload: InitializeWhiteLabelPayload): Promise<SetupNotificationPayload>;
|
|
8
8
|
goToView(event: GoToViewPayload): Promise<import("../..").HandledResponse<GoToViewResultPayload, Error>>;
|
|
9
|
+
getAvailableRoutes(): Promise<import("../..").HandledResponse<GetAvailableRoutesResultPayload, Error>>;
|
|
9
10
|
}
|
|
@@ -20,5 +20,9 @@ class WhiteLabelModule extends baseModule_1.BaseModule {
|
|
|
20
20
|
const response = await this.sendRequest(events_1.EVENTS_ACTION.GO_TO_VIEW, event).catch((e) => e);
|
|
21
21
|
return (0, responseHandler_1.handleResponse)(response, 'Failed to navigate to view');
|
|
22
22
|
}
|
|
23
|
+
async getAvailableRoutes() {
|
|
24
|
+
const response = await this.sendRequest(events_1.EVENTS_ACTION.GET_AVAILABLE_ROUTES).catch((e) => e);
|
|
25
|
+
return (0, responseHandler_1.handleResponse)(response, 'Failed to get available routes');
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
exports.WhiteLabelModule = WhiteLabelModule;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
2
2
|
import { BroadcastEventPayload } from '../types/event/broadcast/broadcastEventPayload.types';
|
|
3
|
+
import { BaseBroadcastEventHandler } from '../types/event/broadcast/baseBroadcastEventHandler';
|
|
4
|
+
export type BroadcastEventMap = Record<string, new () => BaseBroadcastEventHandler>;
|
|
3
5
|
export declare class BroadcastEventDispatcher {
|
|
4
6
|
private eventHandlers;
|
|
5
|
-
constructor();
|
|
7
|
+
constructor(eventMap: BroadcastEventMap);
|
|
6
8
|
do(eventName: keyof typeof BROADCAST_EVENT_MAP, payload: BroadcastEventPayload): void;
|
|
7
9
|
private initHandlers;
|
|
8
10
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BroadcastEventDispatcher = void 0;
|
|
4
|
-
const broadcastEventMap_1 = require("../types/event/broadcast/broadcastEventMap");
|
|
5
4
|
class BroadcastEventDispatcher {
|
|
6
5
|
eventHandlers = new Map();
|
|
7
|
-
constructor() {
|
|
8
|
-
this.initHandlers();
|
|
6
|
+
constructor(eventMap) {
|
|
7
|
+
this.initHandlers(eventMap);
|
|
9
8
|
}
|
|
10
9
|
do(eventName, payload) {
|
|
11
10
|
const handler = this.eventHandlers.get(eventName);
|
|
@@ -14,9 +13,9 @@ class BroadcastEventDispatcher {
|
|
|
14
13
|
}
|
|
15
14
|
return handler.handle(payload);
|
|
16
15
|
}
|
|
17
|
-
// Initializes the event handlers by iterating over the
|
|
18
|
-
initHandlers() {
|
|
19
|
-
for (const [eventName, EventHandlerClass] of Object.entries(
|
|
16
|
+
// Initializes the event handlers by iterating over the provided map and creating instances of each handler.
|
|
17
|
+
initHandlers(eventMap) {
|
|
18
|
+
for (const [eventName, EventHandlerClass] of Object.entries(eventMap)) {
|
|
20
19
|
this.eventHandlers.set(eventName, new EventHandlerClass());
|
|
21
20
|
}
|
|
22
21
|
}
|
package/dist/cjs/services/edm.js
CHANGED
|
@@ -8,6 +8,7 @@ const messageLogger_1 = require("../helpers/messageLogger");
|
|
|
8
8
|
const moduleNames_1 = require("../modules/moduleNames");
|
|
9
9
|
const version_1 = require("../version");
|
|
10
10
|
const edmBroadcastModule_1 = require("../modules/edm/edmBroadcastModule");
|
|
11
|
+
const broadcastEventMap_1 = require("../types/event/broadcast/broadcastEventMap");
|
|
11
12
|
class EDM {
|
|
12
13
|
params;
|
|
13
14
|
config;
|
|
@@ -24,6 +25,7 @@ class EDM {
|
|
|
24
25
|
this.config = config;
|
|
25
26
|
this.nonce = params.nonce;
|
|
26
27
|
EDM.broadCastEventHandler = new edmBroadcastModule_1.EdmBroadcastModule(callbacks);
|
|
28
|
+
this.communicator.registerBroadcastDispatcher(moduleNames_1.MODULE_NAMES.EDM, broadcastEventMap_1.EDM_BROADCAST_EVENT_MAP);
|
|
27
29
|
(0, messageLogger_1.setLoggerState)(params?.debug ?? false, messageLogger_1.SOURCES.EDM);
|
|
28
30
|
}
|
|
29
31
|
async init() {
|
|
@@ -2,26 +2,31 @@ 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
4
|
import { BroadcastEvent } from '../types/event/broadcast/broadcastEvent.types';
|
|
5
|
+
import { BroadcastEventMap } from '../services/broadcastEventDispatcher';
|
|
5
6
|
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
7
|
+
type BroadcastModuleKey = typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL;
|
|
8
|
+
type ModuleKey = typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL;
|
|
6
9
|
export declare class EmbedCommunicator {
|
|
7
10
|
#private;
|
|
8
|
-
private
|
|
11
|
+
private readonly broadcastDispatchers;
|
|
9
12
|
private messageBroker;
|
|
10
13
|
private iFrameManagers;
|
|
11
14
|
private isListening;
|
|
12
15
|
private constructor();
|
|
13
16
|
static getInstance(): EmbedCommunicator;
|
|
14
|
-
sendCorrelatedRequest<TReturn>(eventName: ActionEventName, moduleType:
|
|
15
|
-
setIFrameManager(mainModule:
|
|
17
|
+
sendCorrelatedRequest<TReturn>(eventName: ActionEventName, moduleType: ModuleKey, payload?: ActionEventPayload): Promise<TReturn>;
|
|
18
|
+
setIFrameManager(mainModule: ModuleKey, iFrameManager: iFrameManager): void;
|
|
19
|
+
registerBroadcastDispatcher(key: BroadcastModuleKey, eventMap: BroadcastEventMap): void;
|
|
16
20
|
setupListener(): void;
|
|
17
21
|
private handleInboundMessageEvent;
|
|
18
22
|
private handleInboundEvent;
|
|
19
23
|
private handleInboundEventNotification;
|
|
20
|
-
private
|
|
24
|
+
private getSourceModule;
|
|
21
25
|
private isNotificationSuccess;
|
|
22
26
|
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/white-label/types").OnShoppingCartUpdateEvent | import("../modules/white-label/types").OnContentSizeChangeEvent | import("../modules/edm/types/event/broadcastEventPayload.types").OnPricingStatusUpdateEventPayload | undefined;
|
|
23
27
|
private resolveSuccessfulEvent;
|
|
24
|
-
handleBroadcastEvent(event: BroadcastEvent): void;
|
|
25
|
-
protected send(event: ActionEvent, moduleType:
|
|
28
|
+
handleBroadcastEvent(event: BroadcastEvent, moduleName: ModuleKey): void;
|
|
29
|
+
protected send(event: ActionEvent, moduleType: ModuleKey): void;
|
|
26
30
|
cleanup(): void;
|
|
27
31
|
}
|
|
32
|
+
export {};
|
|
@@ -9,7 +9,7 @@ const broadcastEventDispatcher_1 = require("../services/broadcastEventDispatcher
|
|
|
9
9
|
const moduleNames_1 = require("../modules/moduleNames");
|
|
10
10
|
class EmbedCommunicator {
|
|
11
11
|
static #instance;
|
|
12
|
-
|
|
12
|
+
broadcastDispatchers = {};
|
|
13
13
|
messageBroker = new messageBroker_1.MessageBroker();
|
|
14
14
|
iFrameManagers = {
|
|
15
15
|
[moduleNames_1.MODULE_NAMES.SDK]: null,
|
|
@@ -47,6 +47,9 @@ class EmbedCommunicator {
|
|
|
47
47
|
setIFrameManager(mainModule, iFrameManager) {
|
|
48
48
|
this.iFrameManagers[mainModule] = iFrameManager;
|
|
49
49
|
}
|
|
50
|
+
registerBroadcastDispatcher(key, eventMap) {
|
|
51
|
+
this.broadcastDispatchers[key] = new broadcastEventDispatcher_1.BroadcastEventDispatcher(eventMap);
|
|
52
|
+
}
|
|
50
53
|
setupListener() {
|
|
51
54
|
if (this.isListening) {
|
|
52
55
|
return;
|
|
@@ -61,16 +64,15 @@ class EmbedCommunicator {
|
|
|
61
64
|
message: ['Received message', event.data],
|
|
62
65
|
logType: messageLogger_1.LOG_TYPES.LOG,
|
|
63
66
|
});
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
if (!iframeManagerType?.isMessageFromIFrame(event)) {
|
|
67
|
+
const source = this.getSourceModule(event);
|
|
68
|
+
if (!source) {
|
|
67
69
|
return;
|
|
68
70
|
}
|
|
69
|
-
this.handleInboundEvent(event.data);
|
|
71
|
+
this.handleInboundEvent(event.data, source.moduleName);
|
|
70
72
|
}
|
|
71
|
-
handleInboundEvent(event) {
|
|
73
|
+
handleInboundEvent(event, moduleName) {
|
|
72
74
|
if ((0, eventTypes_1.isBroadcast)(event)) {
|
|
73
|
-
this.handleBroadcastEvent(event);
|
|
75
|
+
this.handleBroadcastEvent(event, moduleName);
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
76
78
|
// Some browser extensions will attach themselves to iframes and will call postMessage
|
|
@@ -102,10 +104,10 @@ class EmbedCommunicator {
|
|
|
102
104
|
// Error should always be provided on a notification with fail status
|
|
103
105
|
event.payload);
|
|
104
106
|
}
|
|
105
|
-
|
|
106
|
-
for (const manager of Object.
|
|
107
|
+
getSourceModule(event) {
|
|
108
|
+
for (const [moduleName, manager] of Object.entries(this.iFrameManagers)) {
|
|
107
109
|
if (manager?.isMessageFromIFrame(event)) {
|
|
108
|
-
return manager;
|
|
110
|
+
return { manager, moduleName };
|
|
109
111
|
}
|
|
110
112
|
}
|
|
111
113
|
return null;
|
|
@@ -125,11 +127,15 @@ class EmbedCommunicator {
|
|
|
125
127
|
}
|
|
126
128
|
this.messageBroker.resolveMessage(event.correlationId, event.payload);
|
|
127
129
|
}
|
|
128
|
-
handleBroadcastEvent(event) {
|
|
130
|
+
handleBroadcastEvent(event, moduleName) {
|
|
129
131
|
if (!this.isValidBroadcastEvent(event) || !event.payload) {
|
|
130
132
|
throw new Error(`Fail [handleInboundEvent (${event.name})]: Broadcast event payload missing`);
|
|
131
133
|
}
|
|
132
|
-
this.
|
|
134
|
+
const dispatcher = this.broadcastDispatchers[moduleName];
|
|
135
|
+
if (!dispatcher) {
|
|
136
|
+
throw new Error(`Fail [handleBroadcastEvent (${event.name})]: No broadcast dispatcher for module '${moduleName}'`);
|
|
137
|
+
}
|
|
138
|
+
dispatcher.do(event.name, event.payload);
|
|
133
139
|
}
|
|
134
140
|
send(event, moduleType) {
|
|
135
141
|
if (!this.iFrameManagers[moduleType]) {
|
|
@@ -8,6 +8,7 @@ const embedStudioBroadcastModule_1 = require("../modules/embed-studio/embedStudi
|
|
|
8
8
|
const moduleNames_1 = require("../modules/moduleNames");
|
|
9
9
|
const version_1 = require("../version");
|
|
10
10
|
const messageLogger_1 = require("../helpers/messageLogger");
|
|
11
|
+
const broadcastEventMap_1 = require("../types/event/broadcast/broadcastEventMap");
|
|
11
12
|
class EmbedStudio {
|
|
12
13
|
params;
|
|
13
14
|
config;
|
|
@@ -22,6 +23,7 @@ class EmbedStudio {
|
|
|
22
23
|
this.params = params;
|
|
23
24
|
this.config = config;
|
|
24
25
|
EmbedStudio.broadCastEventHandler = new embedStudioBroadcastModule_1.EmbedStudioBroadcastModule(callbacks);
|
|
26
|
+
this.communicator.registerBroadcastDispatcher(moduleNames_1.MODULE_NAMES.EMBED_STUDIO, broadcastEventMap_1.EMBED_STUDIO_BROADCAST_EVENT_MAP);
|
|
25
27
|
(0, messageLogger_1.setLoggerState)(params?.debug ?? false, messageLogger_1.SOURCES.EMBED_STUDIO);
|
|
26
28
|
}
|
|
27
29
|
async init() {
|
|
@@ -20,5 +20,6 @@ export declare class WhiteLabel {
|
|
|
20
20
|
}>;
|
|
21
21
|
destroy(): void;
|
|
22
22
|
goToView(payload: GoToViewPayload): Promise<import("..").HandledResponse<import("../modules/white-label/types").GoToViewResultPayload, Error>>;
|
|
23
|
+
getAvailableRoutes(): Promise<import("..").HandledResponse<import("../modules/white-label/types").GetAvailableRoutesResultPayload, Error>>;
|
|
23
24
|
static getBroadCastEventHandler(): WhiteLabelBroadcastModule;
|
|
24
25
|
}
|
|
@@ -9,6 +9,7 @@ const moduleNames_1 = require("../modules/moduleNames");
|
|
|
9
9
|
const version_1 = require("../version");
|
|
10
10
|
const whiteLabelBroadcastModule_1 = require("../modules/white-label/whiteLabelBroadcastModule");
|
|
11
11
|
const jwtDecoder_1 = require("../helpers/jwtDecoder");
|
|
12
|
+
const broadcastEventMap_1 = require("../types/event/broadcast/broadcastEventMap");
|
|
12
13
|
class WhiteLabel {
|
|
13
14
|
params;
|
|
14
15
|
config;
|
|
@@ -25,6 +26,7 @@ class WhiteLabel {
|
|
|
25
26
|
this.config = config;
|
|
26
27
|
this.jwt = params.jwt;
|
|
27
28
|
WhiteLabel.broadCastEventHandler = new whiteLabelBroadcastModule_1.WhiteLabelBroadcastModule(callbacks);
|
|
29
|
+
this.communicator.registerBroadcastDispatcher(moduleNames_1.MODULE_NAMES.WHITE_LABEL, broadcastEventMap_1.WHITE_LABEL_BROADCAST_EVENT_MAP);
|
|
28
30
|
(0, messageLogger_1.setLoggerState)(params?.debug ?? false, messageLogger_1.SOURCES.WHITE_LABEL);
|
|
29
31
|
}
|
|
30
32
|
async init() {
|
|
@@ -100,6 +102,10 @@ class WhiteLabel {
|
|
|
100
102
|
const whiteLabelModule = this.moduleLoader.getModule(moduleNames_1.MODULE_NAMES.WHITE_LABEL);
|
|
101
103
|
return whiteLabelModule.goToView(payload);
|
|
102
104
|
}
|
|
105
|
+
getAvailableRoutes() {
|
|
106
|
+
const whiteLabelModule = this.moduleLoader.getModule(moduleNames_1.MODULE_NAMES.WHITE_LABEL);
|
|
107
|
+
return whiteLabelModule.getAvailableRoutes();
|
|
108
|
+
}
|
|
103
109
|
static getBroadCastEventHandler() {
|
|
104
110
|
if (!WhiteLabel.broadCastEventHandler) {
|
|
105
111
|
throw new Error('No active WhiteLabelBroadcastModule instance');
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import { OnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
1
|
+
import { OnDesignStatusUpdate as EdmOnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
2
2
|
import { OnStepStatusUpdate } from '../../../modules/edm/broadcastEvents/onStepStatusUpdate';
|
|
3
3
|
import { OnPricingStatusUpdate } from '../../../modules/edm/broadcastEvents/onPricingStatusUpdate';
|
|
4
4
|
import { OnFilePickerRequested } from '../../../modules/edm/broadcastEvents/onFilePickerRequested';
|
|
5
|
-
import { OnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
5
|
+
import { OnErrorUpdate as EdmOnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
6
|
+
import { OnDesignStatusUpdate as EmbedStudioOnDesignStatusUpdate } from '../../../modules/embed-studio/broadcastEvents/onDesignStatusUpdate';
|
|
7
|
+
import { OnErrorUpdate as EmbedStudioOnErrorUpdate } from '../../../modules/embed-studio/broadcastEvents/onErrorUpdate';
|
|
6
8
|
import { OnShoppingCartUpdate } from '../../../modules/white-label/broadcastEvents/onShoppingCartUpdate';
|
|
7
9
|
import { OnContentSizeChange } from '../../../modules/white-label/broadcastEvents/onContentSizeChange';
|
|
8
|
-
export declare const
|
|
9
|
-
onDesignStatusUpdate: typeof
|
|
10
|
+
export declare const EDM_BROADCAST_EVENT_MAP: {
|
|
11
|
+
onDesignStatusUpdate: typeof EdmOnDesignStatusUpdate;
|
|
10
12
|
onFilePickerRequested: typeof OnFilePickerRequested;
|
|
11
13
|
onStepStatusUpdate: typeof OnStepStatusUpdate;
|
|
12
14
|
onPricingStatusUpdate: typeof OnPricingStatusUpdate;
|
|
13
|
-
onError: typeof
|
|
15
|
+
onError: typeof EdmOnErrorUpdate;
|
|
16
|
+
};
|
|
17
|
+
export declare const EMBED_STUDIO_BROADCAST_EVENT_MAP: {
|
|
18
|
+
onDesignStatusUpdate: typeof EmbedStudioOnDesignStatusUpdate;
|
|
19
|
+
onError: typeof EmbedStudioOnErrorUpdate;
|
|
20
|
+
};
|
|
21
|
+
export declare const WHITE_LABEL_BROADCAST_EVENT_MAP: {
|
|
22
|
+
onShoppingCartUpdate: typeof OnShoppingCartUpdate;
|
|
23
|
+
onContentSizeChange: typeof OnContentSizeChange;
|
|
24
|
+
};
|
|
25
|
+
export declare const BROADCAST_EVENT_MAP: {
|
|
14
26
|
onShoppingCartUpdate: typeof OnShoppingCartUpdate;
|
|
15
27
|
onContentSizeChange: typeof OnContentSizeChange;
|
|
28
|
+
onDesignStatusUpdate: typeof EmbedStudioOnDesignStatusUpdate;
|
|
29
|
+
onError: typeof EmbedStudioOnErrorUpdate;
|
|
30
|
+
onFilePickerRequested: typeof OnFilePickerRequested;
|
|
31
|
+
onStepStatusUpdate: typeof OnStepStatusUpdate;
|
|
32
|
+
onPricingStatusUpdate: typeof OnPricingStatusUpdate;
|
|
16
33
|
};
|
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BROADCAST_EVENT_MAP = void 0;
|
|
3
|
+
exports.BROADCAST_EVENT_MAP = exports.WHITE_LABEL_BROADCAST_EVENT_MAP = exports.EMBED_STUDIO_BROADCAST_EVENT_MAP = exports.EDM_BROADCAST_EVENT_MAP = void 0;
|
|
4
4
|
const events_1 = require("../../../modules/events");
|
|
5
5
|
const onDesignStatusUpdate_1 = require("../../../modules/edm/broadcastEvents/onDesignStatusUpdate");
|
|
6
6
|
const onStepStatusUpdate_1 = require("../../../modules/edm/broadcastEvents/onStepStatusUpdate");
|
|
7
7
|
const onPricingStatusUpdate_1 = require("../../../modules/edm/broadcastEvents/onPricingStatusUpdate");
|
|
8
8
|
const onFilePickerRequested_1 = require("../../../modules/edm/broadcastEvents/onFilePickerRequested");
|
|
9
9
|
const onErrorUpdate_1 = require("../../../modules/edm/broadcastEvents/onErrorUpdate");
|
|
10
|
+
const onDesignStatusUpdate_2 = require("../../../modules/embed-studio/broadcastEvents/onDesignStatusUpdate");
|
|
11
|
+
const onErrorUpdate_2 = require("../../../modules/embed-studio/broadcastEvents/onErrorUpdate");
|
|
10
12
|
const onShoppingCartUpdate_1 = require("../../../modules/white-label/broadcastEvents/onShoppingCartUpdate");
|
|
11
13
|
const onContentSizeChange_1 = require("../../../modules/white-label/broadcastEvents/onContentSizeChange");
|
|
12
|
-
exports.
|
|
13
|
-
// EDM
|
|
14
|
+
exports.EDM_BROADCAST_EVENT_MAP = {
|
|
14
15
|
[events_1.ALL_BROADCAST_EVENTS.ON_DESIGN_STATUS_UPDATE]: onDesignStatusUpdate_1.OnDesignStatusUpdate,
|
|
15
16
|
[events_1.ALL_BROADCAST_EVENTS.ON_FILE_PICKER_REQUESTED]: onFilePickerRequested_1.OnFilePickerRequested,
|
|
16
17
|
[events_1.ALL_BROADCAST_EVENTS.ON_STEP_STATUS_UPDATE]: onStepStatusUpdate_1.OnStepStatusUpdate,
|
|
17
18
|
[events_1.ALL_BROADCAST_EVENTS.ON_PRICING_STATUS_UPDATE]: onPricingStatusUpdate_1.OnPricingStatusUpdate,
|
|
18
19
|
[events_1.ALL_BROADCAST_EVENTS.ON_INTERNAL_ERROR]: onErrorUpdate_1.OnErrorUpdate,
|
|
19
|
-
|
|
20
|
+
};
|
|
21
|
+
exports.EMBED_STUDIO_BROADCAST_EVENT_MAP = {
|
|
22
|
+
[events_1.ALL_BROADCAST_EVENTS.ON_DESIGN_STATUS_UPDATE]: onDesignStatusUpdate_2.OnDesignStatusUpdate,
|
|
23
|
+
[events_1.ALL_BROADCAST_EVENTS.ON_INTERNAL_ERROR]: onErrorUpdate_2.OnErrorUpdate,
|
|
24
|
+
};
|
|
25
|
+
exports.WHITE_LABEL_BROADCAST_EVENT_MAP = {
|
|
20
26
|
[events_1.ALL_BROADCAST_EVENTS.ON_SHOPPING_CART_UPDATE]: onShoppingCartUpdate_1.OnShoppingCartUpdate,
|
|
21
27
|
[events_1.ALL_BROADCAST_EVENTS.ON_CONTENT_SIZE_CHANGE]: onContentSizeChange_1.OnContentSizeChange,
|
|
22
28
|
};
|
|
29
|
+
// Combined map for broadcast event validity checks across all modules
|
|
30
|
+
exports.BROADCAST_EVENT_MAP = {
|
|
31
|
+
...exports.EDM_BROADCAST_EVENT_MAP,
|
|
32
|
+
...exports.EMBED_STUDIO_BROADCAST_EVENT_MAP,
|
|
33
|
+
...exports.WHITE_LABEL_BROADCAST_EVENT_MAP,
|
|
34
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { BroadcastEventPayload as EdmBroadcastEventPayload } from '../../../modules/edm/types/event/broadcastEventPayload.types';
|
|
2
|
+
import { BroadcastEventPayload as EmbedStudioBroadcastEventPayload } from '../../../modules/embed-studio/types/event/broadcastEventPayload.types';
|
|
2
3
|
import { BroadcastEventPayload as WhiteLabelBroadcastEventPayload } from '../../../modules/white-label/types/event/broadcastEventPayload.types';
|
|
3
|
-
export type BroadcastEventPayload = EdmBroadcastEventPayload | WhiteLabelBroadcastEventPayload;
|
|
4
|
+
export type BroadcastEventPayload = EdmBroadcastEventPayload | EmbedStudioBroadcastEventPayload | WhiteLabelBroadcastEventPayload;
|
|
@@ -8,7 +8,7 @@ import { OnDesignStatusEventPayload, OnErrorEventPayload, OnFilePickerRequestedE
|
|
|
8
8
|
import { OnDesignStatusEventPayload as EmbedStudioOnDesignStatusEventPayload, OnErrorEventPayload as EmbedStudioOnErrorEventPayload } from '../../modules/embed-studio/types/event/broadcastEventPayload.types';
|
|
9
9
|
import { AddImagePayload, AddImageResultPayload, InitializeEdmPayload, NavigateStepPayload, NavigateStepResultPayload, SaveDesignResultPayload, SetStylePayload, SetStyleResultPayload } from '../../modules/edm/types';
|
|
10
10
|
import { InitializeEmbedStudioPayload, SaveDesignResultPayload as EmbedStudioSaveDesignResultPayload } from '../../modules/embed-studio/types';
|
|
11
|
-
import { InitializeWhiteLabelPayload, GoToViewResultPayload, GoToViewPayload, SetupNotificationPayload } from '../../modules/white-label/types';
|
|
11
|
+
import { InitializeWhiteLabelPayload, GoToViewResultPayload, GoToViewPayload, SetupNotificationPayload, GetAvailableRoutesResultPayload } from '../../modules/white-label/types';
|
|
12
12
|
import { OnShoppingCartUpdateEventPayload, OnContentSizeChangeEventPayload } from '../../modules/white-label/types/event/broadcastEventPayload.types';
|
|
13
13
|
/** This file ensures that Iframe and SDK has the same source of truth for return values */
|
|
14
14
|
export type ModuleName = (typeof MODULE_NAMES)[keyof typeof MODULE_NAMES];
|
|
@@ -55,6 +55,7 @@ export interface IEmbedStudioBroadcastModule {
|
|
|
55
55
|
export interface IWhiteLabelModule {
|
|
56
56
|
setup(config: InitializeWhiteLabelPayload): SetupNotificationPayload;
|
|
57
57
|
goToView(event: GoToViewPayload): GoToViewResultPayload;
|
|
58
|
+
getAvailableRoutes(): GetAvailableRoutesResultPayload;
|
|
58
59
|
}
|
|
59
60
|
export interface IWhiteLabelBroadcastModule {
|
|
60
61
|
onShoppingCartUpdate(event: OnShoppingCartUpdateEventPayload): void;
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION: "2.7.
|
|
1
|
+
export declare const VERSION: "2.7.56";
|
package/dist/cjs/version.js
CHANGED
|
@@ -7,5 +7,5 @@ export declare const EVENT_TYPES: {
|
|
|
7
7
|
};
|
|
8
8
|
export declare function isAction(event: AnyEvent): event is import("./sdk/types").InitializeSdkAction | import("./sdk/types").LoadModuleAction | import("./mockup-generation/types").GetMockupsAction | import("./mockup-generation/types").GetMoreMockupsAction | import("./mockup-generation/types").AdjustMockupAction | import("./edm/types").InitializeEdmAction | import("./edm/types").SaveDesignAction | import("./edm/types").AddImageAction | import("./edm/types").NavigateStepAction | import("./white-label/types").InitializeWhiteLabelAction | import("./catalog/types").GetCatalogCategoriesAction | import("./catalog/types").GetCatalogProductsByIdsAction | import("./catalog/types").GetCatalogProductsAction | import("./catalog/types").GetSingleCatalogProductAction | import("./product-publish/types").DeleteProductsAction | import("./product-publish/types").GetSavedProductsAction | import("./product-publish/types").GetProductPublishAction | import("./embed-studio/types").InitializeEmbedStudioAction | import("./embed-studio/types").SaveDesignAction;
|
|
9
9
|
export declare function isNotification(event: AnyEvent): event is import("..").NotificationEvent;
|
|
10
|
-
export declare function isResult(event: AnyEvent): event is import("./catalog/types").GetCatalogProductsResult | import("./catalog/types").GetSingleCatalogProductResult | import("./catalog/types").GetCatalogCategoriesResult | import("./product-publish/types").GetProductPublishResult | import("./product-publish/types").GetSavedProductsResult | import("./product-publish/types").GetSavedProductMockupsResult | import("./product-publish/types").DeleteProductsResult | import("./edm/types").SaveDesignResultEvent | import("./edm/types").AddImageResultEvent | import("./edm/types").SetStyleResultEvent | import("./edm/types").NavigateStepResultEvent | import("./embed-studio/types").SaveDesignResultEvent | import("./mockup-generation/types").GetMockupsResultEvent | import("./mockup-generation/types").GetMoreMockupsResultEvent | import("./mockup-generation/types").AdjustMockupResultEvent | import("./white-label/types").GoToViewResultEvent;
|
|
10
|
+
export declare function isResult(event: AnyEvent): event is import("./catalog/types").GetCatalogProductsResult | import("./catalog/types").GetSingleCatalogProductResult | import("./catalog/types").GetCatalogCategoriesResult | import("./product-publish/types").GetProductPublishResult | import("./product-publish/types").GetSavedProductsResult | import("./product-publish/types").GetSavedProductMockupsResult | import("./product-publish/types").DeleteProductsResult | import("./edm/types").SaveDesignResultEvent | import("./edm/types").AddImageResultEvent | import("./edm/types").SetStyleResultEvent | import("./edm/types").NavigateStepResultEvent | import("./embed-studio/types").SaveDesignResultEvent | import("./mockup-generation/types").GetMockupsResultEvent | import("./mockup-generation/types").GetMoreMockupsResultEvent | import("./mockup-generation/types").AdjustMockupResultEvent | import("./white-label/types").GoToViewResultEvent | import("./white-label/types").GetAvailableRoutesResultEvent;
|
|
11
11
|
export declare function isBroadcast(event: AnyEvent): event is import("./edm/types/event/broadcastEvent.types").OnDesignStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnPricingStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnFilePickerRequestBroadcast | import("./edm/types/event/broadcastEvent.types").OnStepStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnErrorUpdateBroadcast | import("./white-label/types").OnShoppingCartUpdateBroadcast | import("./white-label/types").OnContentSizeChangeBroadcast;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const ALL_ACTION_EVENTS: {
|
|
2
2
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
3
3
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
4
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
4
5
|
readonly INITIALIZE_EMBED_STUDIO: "actionInitializeEdm";
|
|
5
6
|
readonly SAVE_DESIGN: "actionSaveDesign";
|
|
6
7
|
readonly INITIALIZE_EDM: "actionInitializeEdm";
|
|
@@ -45,6 +46,7 @@ export declare const ALL_NOTIFICATION_EVENTS: {
|
|
|
45
46
|
};
|
|
46
47
|
export declare const ALL_RESULT_EVENTS: {
|
|
47
48
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
49
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
48
50
|
readonly SAVE_DESIGN_RESULT: "resultSaveDesign";
|
|
49
51
|
readonly ADD_IMAGE_RESULT: "resultAddImage";
|
|
50
52
|
readonly SET_STYLE_RESULT: "resultSetStyle";
|
|
@@ -78,6 +80,7 @@ export declare const ALL_EVENTS: {
|
|
|
78
80
|
readonly ON_FILE_PICKER_REQUESTED: "onFilePickerRequested";
|
|
79
81
|
readonly ON_STEP_STATUS_UPDATE: "onStepStatusUpdate";
|
|
80
82
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
83
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
81
84
|
readonly SAVE_DESIGN_RESULT: "resultSaveDesign";
|
|
82
85
|
readonly ADD_IMAGE_RESULT: "resultAddImage";
|
|
83
86
|
readonly SET_STYLE_RESULT: "resultSetStyle";
|
|
@@ -114,6 +117,7 @@ export declare const ALL_EVENTS: {
|
|
|
114
117
|
readonly SDK_INITIALIZATION_SUCCESS: "notificationSdkInitializationSuccess";
|
|
115
118
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
116
119
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
120
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
117
121
|
readonly INITIALIZE_EMBED_STUDIO: "actionInitializeEdm";
|
|
118
122
|
readonly SAVE_DESIGN: "actionSaveDesign";
|
|
119
123
|
readonly INITIALIZE_EDM: "actionInitializeEdm";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const EVENTS_ACTION: {
|
|
2
2
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
3
3
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
4
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
4
5
|
};
|
|
5
6
|
export declare const EVENTS_NOTIFICATION: {
|
|
6
7
|
readonly WHITE_LABEL_INITIALIZATION_FAILURE: "notificationWhiteLabelInitializationFailure";
|
|
@@ -9,6 +10,7 @@ export declare const EVENTS_NOTIFICATION: {
|
|
|
9
10
|
};
|
|
10
11
|
export declare const EVENTS_RESULT: {
|
|
11
12
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
13
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
12
14
|
};
|
|
13
15
|
export declare const EVENT_BROADCAST: {
|
|
14
16
|
readonly ON_SHOPPING_CART_UPDATE: "onShoppingCartUpdate";
|
|
@@ -18,9 +20,11 @@ export declare const EVENTS: {
|
|
|
18
20
|
readonly ON_SHOPPING_CART_UPDATE: "onShoppingCartUpdate";
|
|
19
21
|
readonly ON_CONTENT_SIZE_CHANGE: "onContentSizeChange";
|
|
20
22
|
readonly GO_TO_VIEW_RESULT: "resultGoToView";
|
|
23
|
+
readonly GET_AVAILABLE_ROUTES_RESULT: "resultGetAvailableRoutes";
|
|
21
24
|
readonly WHITE_LABEL_INITIALIZATION_FAILURE: "notificationWhiteLabelInitializationFailure";
|
|
22
25
|
readonly WHITE_LABEL_INITIALIZATION_SUCCESS: "notificationWhiteLabelInitializationSuccess";
|
|
23
26
|
readonly GO_TO_VIEW_FAILURE: "actionGoToViewFailure";
|
|
24
27
|
readonly INITIALIZE_WHITE_LABEL: "actionInitializeWhiteLabel";
|
|
25
28
|
readonly GO_TO_VIEW: "actionGoToView";
|
|
29
|
+
readonly GET_AVAILABLE_ROUTES: "actionGetAvailableRoutes";
|
|
26
30
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const EVENTS_ACTION = {
|
|
2
2
|
INITIALIZE_WHITE_LABEL: 'actionInitializeWhiteLabel',
|
|
3
3
|
GO_TO_VIEW: 'actionGoToView',
|
|
4
|
+
GET_AVAILABLE_ROUTES: 'actionGetAvailableRoutes',
|
|
4
5
|
};
|
|
5
6
|
export const EVENTS_NOTIFICATION = {
|
|
6
7
|
WHITE_LABEL_INITIALIZATION_FAILURE: 'notificationWhiteLabelInitializationFailure',
|
|
@@ -9,6 +10,7 @@ export const EVENTS_NOTIFICATION = {
|
|
|
9
10
|
};
|
|
10
11
|
export const EVENTS_RESULT = {
|
|
11
12
|
GO_TO_VIEW_RESULT: 'resultGoToView',
|
|
13
|
+
GET_AVAILABLE_ROUTES_RESULT: 'resultGetAvailableRoutes',
|
|
12
14
|
};
|
|
13
15
|
export const EVENT_BROADCAST = {
|
|
14
16
|
ON_SHOPPING_CART_UPDATE: 'onShoppingCartUpdate',
|
|
@@ -12,6 +12,7 @@ export type WhiteLabelParams = ({
|
|
|
12
12
|
} & WhiteLabelCommonParams);
|
|
13
13
|
export interface WhiteLabelCommonParams {
|
|
14
14
|
jwt: string;
|
|
15
|
+
userFlow: 'd2c' | 'retail' | 'creator';
|
|
15
16
|
iframeClassName?: string;
|
|
16
17
|
debug?: boolean;
|
|
17
18
|
}
|
|
@@ -32,6 +33,11 @@ export interface OnShoppingCartUpdateEvent {
|
|
|
32
33
|
export interface OnContentSizeChangeEvent {
|
|
33
34
|
height: number;
|
|
34
35
|
}
|
|
36
|
+
export type AvailableRouteInfo = {
|
|
37
|
+
name: string;
|
|
38
|
+
title: string;
|
|
39
|
+
params: string[];
|
|
40
|
+
};
|
|
35
41
|
export interface JWTData {
|
|
36
42
|
tid: string;
|
|
37
43
|
nce: string;
|
|
@@ -3,6 +3,7 @@ export type InitializeWhiteLabelPayload = WhiteLabelConfig & WhiteLabelCommonPar
|
|
|
3
3
|
clientVersion: string;
|
|
4
4
|
};
|
|
5
5
|
export interface GoToViewPayload {
|
|
6
|
-
|
|
6
|
+
name: string;
|
|
7
|
+
params?: Record<string, string | number>;
|
|
7
8
|
}
|
|
8
9
|
export type ActionEventPayload = InitializeWhiteLabelPayload | GoToViewPayload;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BaseResultEvent } from '../../../../types/event/result/resultEvent.types';
|
|
2
2
|
import type { EVENTS_RESULT } from '../../../../modules/white-label/events';
|
|
3
|
-
import { GoToViewResultPayload } from '../../../../modules/white-label/types';
|
|
3
|
+
import { GetAvailableRoutesResultPayload, GoToViewResultPayload } from '../../../../modules/white-label/types';
|
|
4
4
|
export type GoToViewResultEvent = BaseResultEvent<typeof EVENTS_RESULT.GO_TO_VIEW_RESULT, GoToViewResultPayload>;
|
|
5
|
-
export type
|
|
5
|
+
export type GetAvailableRoutesResultEvent = BaseResultEvent<typeof EVENTS_RESULT.GET_AVAILABLE_ROUTES_RESULT, GetAvailableRoutesResultPayload>;
|
|
6
|
+
export type ResultEvent = GoToViewResultEvent | GetAvailableRoutesResultEvent;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { AvailableRouteInfo } from '../../../../modules/white-label/types/data.types';
|
|
1
2
|
export type SetupNotificationPayload = {
|
|
2
3
|
error: Error | null;
|
|
3
4
|
};
|
|
4
5
|
export type GoToViewResultPayload = {
|
|
5
6
|
success: boolean;
|
|
6
7
|
};
|
|
7
|
-
export type
|
|
8
|
+
export type GetAvailableRoutesResultPayload = {
|
|
9
|
+
routes: AvailableRouteInfo[];
|
|
10
|
+
};
|
|
11
|
+
export type WhiteLabelResultPayload = GoToViewResultPayload | GetAvailableRoutesResultPayload;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { IWhiteLabelModule } from '../../types/module/module.types';
|
|
2
2
|
import { BaseModule } from '../../modules/baseModule';
|
|
3
|
-
import { InitializeWhiteLabelPayload, GoToViewPayload, GoToViewResultPayload, SetupNotificationPayload } from './types';
|
|
3
|
+
import { InitializeWhiteLabelPayload, GoToViewPayload, GoToViewResultPayload, GetAvailableRoutesResultPayload, SetupNotificationPayload } from './types';
|
|
4
4
|
import { PromisifyMethods, WithHandledResponses } from '../../helpers/typeHelper.types';
|
|
5
5
|
export declare class WhiteLabelModule extends BaseModule implements Omit<WithHandledResponses<IWhiteLabelModule>, 'setup'>, Pick<PromisifyMethods<IWhiteLabelModule>, 'setup'> {
|
|
6
6
|
constructor();
|
|
7
7
|
setup(payload: InitializeWhiteLabelPayload): Promise<SetupNotificationPayload>;
|
|
8
8
|
goToView(event: GoToViewPayload): Promise<import("../..").HandledResponse<GoToViewResultPayload, Error>>;
|
|
9
|
+
getAvailableRoutes(): Promise<import("../..").HandledResponse<GetAvailableRoutesResultPayload, Error>>;
|
|
9
10
|
}
|
|
@@ -17,4 +17,8 @@ export class WhiteLabelModule extends BaseModule {
|
|
|
17
17
|
const response = await this.sendRequest(EVENTS_ACTION.GO_TO_VIEW, event).catch((e) => e);
|
|
18
18
|
return handleResponse(response, 'Failed to navigate to view');
|
|
19
19
|
}
|
|
20
|
+
async getAvailableRoutes() {
|
|
21
|
+
const response = await this.sendRequest(EVENTS_ACTION.GET_AVAILABLE_ROUTES).catch((e) => e);
|
|
22
|
+
return handleResponse(response, 'Failed to get available routes');
|
|
23
|
+
}
|
|
20
24
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
2
2
|
import { BroadcastEventPayload } from '../types/event/broadcast/broadcastEventPayload.types';
|
|
3
|
+
import { BaseBroadcastEventHandler } from '../types/event/broadcast/baseBroadcastEventHandler';
|
|
4
|
+
export type BroadcastEventMap = Record<string, new () => BaseBroadcastEventHandler>;
|
|
3
5
|
export declare class BroadcastEventDispatcher {
|
|
4
6
|
private eventHandlers;
|
|
5
|
-
constructor();
|
|
7
|
+
constructor(eventMap: BroadcastEventMap);
|
|
6
8
|
do(eventName: keyof typeof BROADCAST_EVENT_MAP, payload: BroadcastEventPayload): void;
|
|
7
9
|
private initHandlers;
|
|
8
10
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
2
1
|
export class BroadcastEventDispatcher {
|
|
3
2
|
eventHandlers = new Map();
|
|
4
|
-
constructor() {
|
|
5
|
-
this.initHandlers();
|
|
3
|
+
constructor(eventMap) {
|
|
4
|
+
this.initHandlers(eventMap);
|
|
6
5
|
}
|
|
7
6
|
do(eventName, payload) {
|
|
8
7
|
const handler = this.eventHandlers.get(eventName);
|
|
@@ -11,9 +10,9 @@ export class BroadcastEventDispatcher {
|
|
|
11
10
|
}
|
|
12
11
|
return handler.handle(payload);
|
|
13
12
|
}
|
|
14
|
-
// Initializes the event handlers by iterating over the
|
|
15
|
-
initHandlers() {
|
|
16
|
-
for (const [eventName, EventHandlerClass] of Object.entries(
|
|
13
|
+
// Initializes the event handlers by iterating over the provided map and creating instances of each handler.
|
|
14
|
+
initHandlers(eventMap) {
|
|
15
|
+
for (const [eventName, EventHandlerClass] of Object.entries(eventMap)) {
|
|
17
16
|
this.eventHandlers.set(eventName, new EventHandlerClass());
|
|
18
17
|
}
|
|
19
18
|
}
|
package/dist/esm/services/edm.js
CHANGED
|
@@ -5,6 +5,7 @@ import { LOG_TYPES, logEmbedMessage, setLoggerState, SOURCES, } from '../helpers
|
|
|
5
5
|
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
6
6
|
import { VERSION } from '../version';
|
|
7
7
|
import { EdmBroadcastModule } from '../modules/edm/edmBroadcastModule';
|
|
8
|
+
import { EDM_BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
8
9
|
export class EDM {
|
|
9
10
|
params;
|
|
10
11
|
config;
|
|
@@ -21,6 +22,7 @@ export class EDM {
|
|
|
21
22
|
this.config = config;
|
|
22
23
|
this.nonce = params.nonce;
|
|
23
24
|
EDM.broadCastEventHandler = new EdmBroadcastModule(callbacks);
|
|
25
|
+
this.communicator.registerBroadcastDispatcher(MODULE_NAMES.EDM, EDM_BROADCAST_EVENT_MAP);
|
|
24
26
|
setLoggerState(params?.debug ?? false, SOURCES.EDM);
|
|
25
27
|
}
|
|
26
28
|
async init() {
|
|
@@ -2,26 +2,31 @@ 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
4
|
import { BroadcastEvent } from '../types/event/broadcast/broadcastEvent.types';
|
|
5
|
+
import { BroadcastEventMap } from '../services/broadcastEventDispatcher';
|
|
5
6
|
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
7
|
+
type BroadcastModuleKey = typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL;
|
|
8
|
+
type ModuleKey = typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL;
|
|
6
9
|
export declare class EmbedCommunicator {
|
|
7
10
|
#private;
|
|
8
|
-
private
|
|
11
|
+
private readonly broadcastDispatchers;
|
|
9
12
|
private messageBroker;
|
|
10
13
|
private iFrameManagers;
|
|
11
14
|
private isListening;
|
|
12
15
|
private constructor();
|
|
13
16
|
static getInstance(): EmbedCommunicator;
|
|
14
|
-
sendCorrelatedRequest<TReturn>(eventName: ActionEventName, moduleType:
|
|
15
|
-
setIFrameManager(mainModule:
|
|
17
|
+
sendCorrelatedRequest<TReturn>(eventName: ActionEventName, moduleType: ModuleKey, payload?: ActionEventPayload): Promise<TReturn>;
|
|
18
|
+
setIFrameManager(mainModule: ModuleKey, iFrameManager: iFrameManager): void;
|
|
19
|
+
registerBroadcastDispatcher(key: BroadcastModuleKey, eventMap: BroadcastEventMap): void;
|
|
16
20
|
setupListener(): void;
|
|
17
21
|
private handleInboundMessageEvent;
|
|
18
22
|
private handleInboundEvent;
|
|
19
23
|
private handleInboundEventNotification;
|
|
20
|
-
private
|
|
24
|
+
private getSourceModule;
|
|
21
25
|
private isNotificationSuccess;
|
|
22
26
|
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/white-label/types").OnShoppingCartUpdateEvent | import("../modules/white-label/types").OnContentSizeChangeEvent | import("../modules/edm/types/event/broadcastEventPayload.types").OnPricingStatusUpdateEventPayload | undefined;
|
|
23
27
|
private resolveSuccessfulEvent;
|
|
24
|
-
handleBroadcastEvent(event: BroadcastEvent): void;
|
|
25
|
-
protected send(event: ActionEvent, moduleType:
|
|
28
|
+
handleBroadcastEvent(event: BroadcastEvent, moduleName: ModuleKey): void;
|
|
29
|
+
protected send(event: ActionEvent, moduleType: ModuleKey): void;
|
|
26
30
|
cleanup(): void;
|
|
27
31
|
}
|
|
32
|
+
export {};
|
|
@@ -2,11 +2,11 @@ import { MessageBroker } from './messageBroker';
|
|
|
2
2
|
import { EVENT_TYPES, isBroadcast, isNotification, isResult, } from '../modules/eventTypes';
|
|
3
3
|
import { LOG_TYPES, logEmbedMessage } from '../helpers/messageLogger';
|
|
4
4
|
import { BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
5
|
-
import { BroadcastEventDispatcher } from '../services/broadcastEventDispatcher';
|
|
5
|
+
import { BroadcastEventDispatcher, } from '../services/broadcastEventDispatcher';
|
|
6
6
|
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
7
7
|
export class EmbedCommunicator {
|
|
8
8
|
static #instance;
|
|
9
|
-
|
|
9
|
+
broadcastDispatchers = {};
|
|
10
10
|
messageBroker = new MessageBroker();
|
|
11
11
|
iFrameManagers = {
|
|
12
12
|
[MODULE_NAMES.SDK]: null,
|
|
@@ -44,6 +44,9 @@ export class EmbedCommunicator {
|
|
|
44
44
|
setIFrameManager(mainModule, iFrameManager) {
|
|
45
45
|
this.iFrameManagers[mainModule] = iFrameManager;
|
|
46
46
|
}
|
|
47
|
+
registerBroadcastDispatcher(key, eventMap) {
|
|
48
|
+
this.broadcastDispatchers[key] = new BroadcastEventDispatcher(eventMap);
|
|
49
|
+
}
|
|
47
50
|
setupListener() {
|
|
48
51
|
if (this.isListening) {
|
|
49
52
|
return;
|
|
@@ -58,16 +61,15 @@ export class EmbedCommunicator {
|
|
|
58
61
|
message: ['Received message', event.data],
|
|
59
62
|
logType: LOG_TYPES.LOG,
|
|
60
63
|
});
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
if (!iframeManagerType?.isMessageFromIFrame(event)) {
|
|
64
|
+
const source = this.getSourceModule(event);
|
|
65
|
+
if (!source) {
|
|
64
66
|
return;
|
|
65
67
|
}
|
|
66
|
-
this.handleInboundEvent(event.data);
|
|
68
|
+
this.handleInboundEvent(event.data, source.moduleName);
|
|
67
69
|
}
|
|
68
|
-
handleInboundEvent(event) {
|
|
70
|
+
handleInboundEvent(event, moduleName) {
|
|
69
71
|
if (isBroadcast(event)) {
|
|
70
|
-
this.handleBroadcastEvent(event);
|
|
72
|
+
this.handleBroadcastEvent(event, moduleName);
|
|
71
73
|
return;
|
|
72
74
|
}
|
|
73
75
|
// Some browser extensions will attach themselves to iframes and will call postMessage
|
|
@@ -99,10 +101,10 @@ export class EmbedCommunicator {
|
|
|
99
101
|
// Error should always be provided on a notification with fail status
|
|
100
102
|
event.payload);
|
|
101
103
|
}
|
|
102
|
-
|
|
103
|
-
for (const manager of Object.
|
|
104
|
+
getSourceModule(event) {
|
|
105
|
+
for (const [moduleName, manager] of Object.entries(this.iFrameManagers)) {
|
|
104
106
|
if (manager?.isMessageFromIFrame(event)) {
|
|
105
|
-
return manager;
|
|
107
|
+
return { manager, moduleName };
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
return null;
|
|
@@ -122,11 +124,15 @@ export class EmbedCommunicator {
|
|
|
122
124
|
}
|
|
123
125
|
this.messageBroker.resolveMessage(event.correlationId, event.payload);
|
|
124
126
|
}
|
|
125
|
-
handleBroadcastEvent(event) {
|
|
127
|
+
handleBroadcastEvent(event, moduleName) {
|
|
126
128
|
if (!this.isValidBroadcastEvent(event) || !event.payload) {
|
|
127
129
|
throw new Error(`Fail [handleInboundEvent (${event.name})]: Broadcast event payload missing`);
|
|
128
130
|
}
|
|
129
|
-
this.
|
|
131
|
+
const dispatcher = this.broadcastDispatchers[moduleName];
|
|
132
|
+
if (!dispatcher) {
|
|
133
|
+
throw new Error(`Fail [handleBroadcastEvent (${event.name})]: No broadcast dispatcher for module '${moduleName}'`);
|
|
134
|
+
}
|
|
135
|
+
dispatcher.do(event.name, event.payload);
|
|
130
136
|
}
|
|
131
137
|
send(event, moduleType) {
|
|
132
138
|
if (!this.iFrameManagers[moduleType]) {
|
|
@@ -5,6 +5,7 @@ import { EmbedStudioBroadcastModule } from '../modules/embed-studio/embedStudioB
|
|
|
5
5
|
import { MODULE_NAMES } from '../modules/moduleNames';
|
|
6
6
|
import { VERSION } from '../version';
|
|
7
7
|
import { LOG_TYPES, logEmbedMessage, setLoggerState, SOURCES, } from '../helpers/messageLogger';
|
|
8
|
+
import { EMBED_STUDIO_BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
8
9
|
export class EmbedStudio {
|
|
9
10
|
params;
|
|
10
11
|
config;
|
|
@@ -19,6 +20,7 @@ export class EmbedStudio {
|
|
|
19
20
|
this.params = params;
|
|
20
21
|
this.config = config;
|
|
21
22
|
EmbedStudio.broadCastEventHandler = new EmbedStudioBroadcastModule(callbacks);
|
|
23
|
+
this.communicator.registerBroadcastDispatcher(MODULE_NAMES.EMBED_STUDIO, EMBED_STUDIO_BROADCAST_EVENT_MAP);
|
|
22
24
|
setLoggerState(params?.debug ?? false, SOURCES.EMBED_STUDIO);
|
|
23
25
|
}
|
|
24
26
|
async init() {
|
|
@@ -20,5 +20,6 @@ export declare class WhiteLabel {
|
|
|
20
20
|
}>;
|
|
21
21
|
destroy(): void;
|
|
22
22
|
goToView(payload: GoToViewPayload): Promise<import("..").HandledResponse<import("../modules/white-label/types").GoToViewResultPayload, Error>>;
|
|
23
|
+
getAvailableRoutes(): Promise<import("..").HandledResponse<import("../modules/white-label/types").GetAvailableRoutesResultPayload, Error>>;
|
|
23
24
|
static getBroadCastEventHandler(): WhiteLabelBroadcastModule;
|
|
24
25
|
}
|
|
@@ -6,6 +6,7 @@ import { MODULE_NAMES } from '../modules/moduleNames';
|
|
|
6
6
|
import { VERSION } from '../version';
|
|
7
7
|
import { WhiteLabelBroadcastModule } from '../modules/white-label/whiteLabelBroadcastModule';
|
|
8
8
|
import { parseJwt } from '../helpers/jwtDecoder';
|
|
9
|
+
import { WHITE_LABEL_BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
|
|
9
10
|
export class WhiteLabel {
|
|
10
11
|
params;
|
|
11
12
|
config;
|
|
@@ -22,6 +23,7 @@ export class WhiteLabel {
|
|
|
22
23
|
this.config = config;
|
|
23
24
|
this.jwt = params.jwt;
|
|
24
25
|
WhiteLabel.broadCastEventHandler = new WhiteLabelBroadcastModule(callbacks);
|
|
26
|
+
this.communicator.registerBroadcastDispatcher(MODULE_NAMES.WHITE_LABEL, WHITE_LABEL_BROADCAST_EVENT_MAP);
|
|
25
27
|
setLoggerState(params?.debug ?? false, SOURCES.WHITE_LABEL);
|
|
26
28
|
}
|
|
27
29
|
async init() {
|
|
@@ -97,6 +99,10 @@ export class WhiteLabel {
|
|
|
97
99
|
const whiteLabelModule = this.moduleLoader.getModule(MODULE_NAMES.WHITE_LABEL);
|
|
98
100
|
return whiteLabelModule.goToView(payload);
|
|
99
101
|
}
|
|
102
|
+
getAvailableRoutes() {
|
|
103
|
+
const whiteLabelModule = this.moduleLoader.getModule(MODULE_NAMES.WHITE_LABEL);
|
|
104
|
+
return whiteLabelModule.getAvailableRoutes();
|
|
105
|
+
}
|
|
100
106
|
static getBroadCastEventHandler() {
|
|
101
107
|
if (!WhiteLabel.broadCastEventHandler) {
|
|
102
108
|
throw new Error('No active WhiteLabelBroadcastModule instance');
|
|
@@ -1,16 +1,33 @@
|
|
|
1
|
-
import { OnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
1
|
+
import { OnDesignStatusUpdate as EdmOnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
2
2
|
import { OnStepStatusUpdate } from '../../../modules/edm/broadcastEvents/onStepStatusUpdate';
|
|
3
3
|
import { OnPricingStatusUpdate } from '../../../modules/edm/broadcastEvents/onPricingStatusUpdate';
|
|
4
4
|
import { OnFilePickerRequested } from '../../../modules/edm/broadcastEvents/onFilePickerRequested';
|
|
5
|
-
import { OnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
5
|
+
import { OnErrorUpdate as EdmOnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
6
|
+
import { OnDesignStatusUpdate as EmbedStudioOnDesignStatusUpdate } from '../../../modules/embed-studio/broadcastEvents/onDesignStatusUpdate';
|
|
7
|
+
import { OnErrorUpdate as EmbedStudioOnErrorUpdate } from '../../../modules/embed-studio/broadcastEvents/onErrorUpdate';
|
|
6
8
|
import { OnShoppingCartUpdate } from '../../../modules/white-label/broadcastEvents/onShoppingCartUpdate';
|
|
7
9
|
import { OnContentSizeChange } from '../../../modules/white-label/broadcastEvents/onContentSizeChange';
|
|
8
|
-
export declare const
|
|
9
|
-
onDesignStatusUpdate: typeof
|
|
10
|
+
export declare const EDM_BROADCAST_EVENT_MAP: {
|
|
11
|
+
onDesignStatusUpdate: typeof EdmOnDesignStatusUpdate;
|
|
10
12
|
onFilePickerRequested: typeof OnFilePickerRequested;
|
|
11
13
|
onStepStatusUpdate: typeof OnStepStatusUpdate;
|
|
12
14
|
onPricingStatusUpdate: typeof OnPricingStatusUpdate;
|
|
13
|
-
onError: typeof
|
|
15
|
+
onError: typeof EdmOnErrorUpdate;
|
|
16
|
+
};
|
|
17
|
+
export declare const EMBED_STUDIO_BROADCAST_EVENT_MAP: {
|
|
18
|
+
onDesignStatusUpdate: typeof EmbedStudioOnDesignStatusUpdate;
|
|
19
|
+
onError: typeof EmbedStudioOnErrorUpdate;
|
|
20
|
+
};
|
|
21
|
+
export declare const WHITE_LABEL_BROADCAST_EVENT_MAP: {
|
|
22
|
+
onShoppingCartUpdate: typeof OnShoppingCartUpdate;
|
|
23
|
+
onContentSizeChange: typeof OnContentSizeChange;
|
|
24
|
+
};
|
|
25
|
+
export declare const BROADCAST_EVENT_MAP: {
|
|
14
26
|
onShoppingCartUpdate: typeof OnShoppingCartUpdate;
|
|
15
27
|
onContentSizeChange: typeof OnContentSizeChange;
|
|
28
|
+
onDesignStatusUpdate: typeof EmbedStudioOnDesignStatusUpdate;
|
|
29
|
+
onError: typeof EmbedStudioOnErrorUpdate;
|
|
30
|
+
onFilePickerRequested: typeof OnFilePickerRequested;
|
|
31
|
+
onStepStatusUpdate: typeof OnStepStatusUpdate;
|
|
32
|
+
onPricingStatusUpdate: typeof OnPricingStatusUpdate;
|
|
16
33
|
};
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
import { ALL_BROADCAST_EVENTS } from '../../../modules/events';
|
|
2
|
-
import { OnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
2
|
+
import { OnDesignStatusUpdate as EdmOnDesignStatusUpdate } from '../../../modules/edm/broadcastEvents/onDesignStatusUpdate';
|
|
3
3
|
import { OnStepStatusUpdate } from '../../../modules/edm/broadcastEvents/onStepStatusUpdate';
|
|
4
4
|
import { OnPricingStatusUpdate } from '../../../modules/edm/broadcastEvents/onPricingStatusUpdate';
|
|
5
5
|
import { OnFilePickerRequested } from '../../../modules/edm/broadcastEvents/onFilePickerRequested';
|
|
6
|
-
import { OnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
6
|
+
import { OnErrorUpdate as EdmOnErrorUpdate } from '../../../modules/edm/broadcastEvents/onErrorUpdate';
|
|
7
|
+
import { OnDesignStatusUpdate as EmbedStudioOnDesignStatusUpdate } from '../../../modules/embed-studio/broadcastEvents/onDesignStatusUpdate';
|
|
8
|
+
import { OnErrorUpdate as EmbedStudioOnErrorUpdate } from '../../../modules/embed-studio/broadcastEvents/onErrorUpdate';
|
|
7
9
|
import { OnShoppingCartUpdate } from '../../../modules/white-label/broadcastEvents/onShoppingCartUpdate';
|
|
8
10
|
import { OnContentSizeChange } from '../../../modules/white-label/broadcastEvents/onContentSizeChange';
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
[ALL_BROADCAST_EVENTS.ON_DESIGN_STATUS_UPDATE]: OnDesignStatusUpdate,
|
|
11
|
+
export const EDM_BROADCAST_EVENT_MAP = {
|
|
12
|
+
[ALL_BROADCAST_EVENTS.ON_DESIGN_STATUS_UPDATE]: EdmOnDesignStatusUpdate,
|
|
12
13
|
[ALL_BROADCAST_EVENTS.ON_FILE_PICKER_REQUESTED]: OnFilePickerRequested,
|
|
13
14
|
[ALL_BROADCAST_EVENTS.ON_STEP_STATUS_UPDATE]: OnStepStatusUpdate,
|
|
14
15
|
[ALL_BROADCAST_EVENTS.ON_PRICING_STATUS_UPDATE]: OnPricingStatusUpdate,
|
|
15
|
-
[ALL_BROADCAST_EVENTS.ON_INTERNAL_ERROR]:
|
|
16
|
-
|
|
16
|
+
[ALL_BROADCAST_EVENTS.ON_INTERNAL_ERROR]: EdmOnErrorUpdate,
|
|
17
|
+
};
|
|
18
|
+
export const EMBED_STUDIO_BROADCAST_EVENT_MAP = {
|
|
19
|
+
[ALL_BROADCAST_EVENTS.ON_DESIGN_STATUS_UPDATE]: EmbedStudioOnDesignStatusUpdate,
|
|
20
|
+
[ALL_BROADCAST_EVENTS.ON_INTERNAL_ERROR]: EmbedStudioOnErrorUpdate,
|
|
21
|
+
};
|
|
22
|
+
export const WHITE_LABEL_BROADCAST_EVENT_MAP = {
|
|
17
23
|
[ALL_BROADCAST_EVENTS.ON_SHOPPING_CART_UPDATE]: OnShoppingCartUpdate,
|
|
18
24
|
[ALL_BROADCAST_EVENTS.ON_CONTENT_SIZE_CHANGE]: OnContentSizeChange,
|
|
19
25
|
};
|
|
26
|
+
// Combined map for broadcast event validity checks across all modules
|
|
27
|
+
export const BROADCAST_EVENT_MAP = {
|
|
28
|
+
...EDM_BROADCAST_EVENT_MAP,
|
|
29
|
+
...EMBED_STUDIO_BROADCAST_EVENT_MAP,
|
|
30
|
+
...WHITE_LABEL_BROADCAST_EVENT_MAP,
|
|
31
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { BroadcastEventPayload as EdmBroadcastEventPayload } from '../../../modules/edm/types/event/broadcastEventPayload.types';
|
|
2
|
+
import { BroadcastEventPayload as EmbedStudioBroadcastEventPayload } from '../../../modules/embed-studio/types/event/broadcastEventPayload.types';
|
|
2
3
|
import { BroadcastEventPayload as WhiteLabelBroadcastEventPayload } from '../../../modules/white-label/types/event/broadcastEventPayload.types';
|
|
3
|
-
export type BroadcastEventPayload = EdmBroadcastEventPayload | WhiteLabelBroadcastEventPayload;
|
|
4
|
+
export type BroadcastEventPayload = EdmBroadcastEventPayload | EmbedStudioBroadcastEventPayload | WhiteLabelBroadcastEventPayload;
|
|
@@ -8,7 +8,7 @@ import { OnDesignStatusEventPayload, OnErrorEventPayload, OnFilePickerRequestedE
|
|
|
8
8
|
import { OnDesignStatusEventPayload as EmbedStudioOnDesignStatusEventPayload, OnErrorEventPayload as EmbedStudioOnErrorEventPayload } from '../../modules/embed-studio/types/event/broadcastEventPayload.types';
|
|
9
9
|
import { AddImagePayload, AddImageResultPayload, InitializeEdmPayload, NavigateStepPayload, NavigateStepResultPayload, SaveDesignResultPayload, SetStylePayload, SetStyleResultPayload } from '../../modules/edm/types';
|
|
10
10
|
import { InitializeEmbedStudioPayload, SaveDesignResultPayload as EmbedStudioSaveDesignResultPayload } from '../../modules/embed-studio/types';
|
|
11
|
-
import { InitializeWhiteLabelPayload, GoToViewResultPayload, GoToViewPayload, SetupNotificationPayload } from '../../modules/white-label/types';
|
|
11
|
+
import { InitializeWhiteLabelPayload, GoToViewResultPayload, GoToViewPayload, SetupNotificationPayload, GetAvailableRoutesResultPayload } from '../../modules/white-label/types';
|
|
12
12
|
import { OnShoppingCartUpdateEventPayload, OnContentSizeChangeEventPayload } from '../../modules/white-label/types/event/broadcastEventPayload.types';
|
|
13
13
|
/** This file ensures that Iframe and SDK has the same source of truth for return values */
|
|
14
14
|
export type ModuleName = (typeof MODULE_NAMES)[keyof typeof MODULE_NAMES];
|
|
@@ -55,6 +55,7 @@ export interface IEmbedStudioBroadcastModule {
|
|
|
55
55
|
export interface IWhiteLabelModule {
|
|
56
56
|
setup(config: InitializeWhiteLabelPayload): SetupNotificationPayload;
|
|
57
57
|
goToView(event: GoToViewPayload): GoToViewResultPayload;
|
|
58
|
+
getAvailableRoutes(): GetAvailableRoutesResultPayload;
|
|
58
59
|
}
|
|
59
60
|
export interface IWhiteLabelBroadcastModule {
|
|
60
61
|
onShoppingCartUpdate(event: OnShoppingCartUpdateEventPayload): void;
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION: "2.7.
|
|
1
|
+
export declare const VERSION: "2.7.56";
|
package/dist/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// AUTO-GENERATED
|
|
2
|
-
export const VERSION = '2.7.
|
|
2
|
+
export const VERSION = '2.7.56';
|