@fyul/embed-sdk 2.7.55 → 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.
@@ -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 BROADCAST_EVENT_MAP and creating instances of each handler.
18
- initHandlers() {
19
- for (const [eventName, EventHandlerClass] of Object.entries(broadcastEventMap_1.BROADCAST_EVENT_MAP)) {
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
  }
@@ -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 broadcastEventHandler;
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: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL, payload?: ActionEventPayload): Promise<TReturn>;
15
- setIFrameManager(mainModule: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL, iFrameManager: iFrameManager): void;
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 getIframeManagerByMainModule;
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: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL): void;
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
- broadcastEventHandler = new broadcastEventDispatcher_1.BroadcastEventDispatcher();
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 iframeManagerType = this.getIframeManagerByMainModule(event);
65
- // Only process messages from our iframe and let cross iframe communication fail silently
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
- getIframeManagerByMainModule(event) {
106
- for (const manager of Object.values(this.iFrameManagers)) {
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.broadcastEventHandler.do(event.name, event.payload);
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() {
@@ -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() {
@@ -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 BROADCAST_EVENT_MAP: {
9
- onDesignStatusUpdate: typeof OnDesignStatusUpdate;
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 OnErrorUpdate;
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.BROADCAST_EVENT_MAP = {
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
- // EWL
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;
@@ -1 +1 @@
1
- export declare const VERSION: "2.7.55";
1
+ export declare const VERSION: "2.7.56";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // AUTO-GENERATED
5
- exports.VERSION = '2.7.55';
5
+ exports.VERSION = '2.7.56';
@@ -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 BROADCAST_EVENT_MAP and creating instances of each handler.
15
- initHandlers() {
16
- for (const [eventName, EventHandlerClass] of Object.entries(BROADCAST_EVENT_MAP)) {
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
  }
@@ -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 broadcastEventHandler;
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: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL, payload?: ActionEventPayload): Promise<TReturn>;
15
- setIFrameManager(mainModule: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL, iFrameManager: iFrameManager): void;
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 getIframeManagerByMainModule;
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: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL): void;
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
- broadcastEventHandler = new BroadcastEventDispatcher();
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 iframeManagerType = this.getIframeManagerByMainModule(event);
62
- // Only process messages from our iframe and let cross iframe communication fail silently
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
- getIframeManagerByMainModule(event) {
103
- for (const manager of Object.values(this.iFrameManagers)) {
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.broadcastEventHandler.do(event.name, event.payload);
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() {
@@ -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() {
@@ -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 BROADCAST_EVENT_MAP: {
9
- onDesignStatusUpdate: typeof OnDesignStatusUpdate;
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 OnErrorUpdate;
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 BROADCAST_EVENT_MAP = {
10
- // EDM
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]: OnErrorUpdate,
16
- // EWL
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;
@@ -1 +1 @@
1
- export declare const VERSION: "2.7.55";
1
+ export declare const VERSION: "2.7.56";
@@ -1,2 +1,2 @@
1
1
  // AUTO-GENERATED
2
- export const VERSION = '2.7.55';
2
+ export const VERSION = '2.7.56';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fyul/embed-sdk",
3
- "version": "2.7.55",
3
+ "version": "2.7.56",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",