@microsoft/omnichannel-chat-widget 1.8.3 → 1.8.4-main.7bdb634

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.
Files changed (89) hide show
  1. package/lib/cjs/common/Constants.js +4 -0
  2. package/lib/cjs/common/facades/FacadeChatSDK.js +6 -0
  3. package/lib/cjs/common/telemetry/TelemetryConstants.js +31 -0
  4. package/lib/cjs/common/utils/SecureEventBus.js +307 -0
  5. package/lib/cjs/common/utils/dispatchCustomEvent.js +25 -0
  6. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +127 -0
  7. package/lib/cjs/components/livechatwidget/common/ChatWidgetEvents.js +15 -0
  8. package/lib/cjs/components/livechatwidget/common/PersistentConversationHandler.js +284 -0
  9. package/lib/cjs/components/livechatwidget/common/createAdapter.js +2 -0
  10. package/lib/cjs/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +18 -0
  11. package/lib/cjs/components/livechatwidget/common/endChat.js +7 -1
  12. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +7 -5
  13. package/lib/cjs/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
  14. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +31 -5
  15. package/lib/cjs/components/webchatcontainerstateful/common/activities/botActivity.js +14 -0
  16. package/lib/cjs/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +17 -0
  17. package/lib/cjs/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +97 -0
  18. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  19. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +1 -1
  20. package/lib/cjs/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +59 -0
  21. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +122 -0
  22. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +10 -0
  23. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +18 -0
  24. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1038 -0
  25. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +34 -0
  26. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +44 -0
  27. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +16 -2
  28. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +20 -0
  29. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +2 -2
  30. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +59 -0
  31. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +4 -3
  32. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +2 -2
  33. package/lib/esm/common/Constants.js +4 -0
  34. package/lib/esm/common/facades/FacadeChatSDK.js +6 -0
  35. package/lib/esm/common/telemetry/TelemetryConstants.js +31 -0
  36. package/lib/esm/common/utils/SecureEventBus.js +328 -0
  37. package/lib/esm/common/utils/dispatchCustomEvent.js +18 -0
  38. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.js +120 -0
  39. package/lib/esm/components/livechatwidget/common/ChatWidgetEvents.js +8 -0
  40. package/lib/esm/components/livechatwidget/common/PersistentConversationHandler.js +277 -0
  41. package/lib/esm/components/livechatwidget/common/createAdapter.js +2 -0
  42. package/lib/esm/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.js +11 -0
  43. package/lib/esm/components/livechatwidget/common/endChat.js +7 -1
  44. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +7 -5
  45. package/lib/esm/components/livechatwidget/interfaces/IPersistentChatHistoryProps.js +1 -0
  46. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +34 -5
  47. package/lib/esm/components/webchatcontainerstateful/common/activities/botActivity.js +7 -0
  48. package/lib/esm/components/webchatcontainerstateful/common/activities/conversationDividerActivity.js +9 -0
  49. package/lib/esm/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.js +90 -0
  50. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts.js +2 -1
  51. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatStatefulProps.js +2 -2
  52. package/lib/esm/components/webchatcontainerstateful/hooks/usePersistentChatHistory.js +51 -0
  53. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.js +115 -0
  54. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.js +3 -0
  55. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.js +10 -0
  56. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.js +1060 -0
  57. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.js +25 -0
  58. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +42 -0
  59. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +13 -0
  60. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.js +13 -0
  61. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +1 -1
  62. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.js +52 -0
  63. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/NotDeliveredTimestamp.js +2 -2
  64. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/SendingTimestamp.js +1 -1
  65. package/lib/types/common/Constants.d.ts +3 -0
  66. package/lib/types/common/facades/FacadeChatSDK.d.ts +3 -1
  67. package/lib/types/common/telemetry/TelemetryConstants.d.ts +30 -2
  68. package/lib/types/common/utils/SecureEventBus.d.ts +159 -0
  69. package/lib/types/common/utils/dispatchCustomEvent.d.ts +2 -0
  70. package/lib/types/components/livechatwidget/common/ActivitySubscriber/AddActivitySubscriber.d.ts +45 -0
  71. package/lib/types/components/livechatwidget/common/ChatWidgetEvents.d.ts +7 -0
  72. package/lib/types/components/livechatwidget/common/PersistentConversationHandler.d.ts +28 -0
  73. package/lib/types/components/livechatwidget/common/defaultProps/defaultPersistentChatHistoryProps.d.ts +2 -0
  74. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +2 -0
  75. package/lib/types/components/livechatwidget/interfaces/IPersistentChatHistoryProps.d.ts +7 -0
  76. package/lib/types/components/webchatcontainerstateful/common/activities/botActivity.d.ts +7 -0
  77. package/lib/types/components/webchatcontainerstateful/common/activities/conversationDividerActivity.d.ts +10 -0
  78. package/lib/types/components/webchatcontainerstateful/common/activityConverters/convertPersistentChatHistoryMessageToActivity.d.ts +2 -0
  79. package/lib/types/components/webchatcontainerstateful/hooks/usePersistentChatHistory.d.ts +4 -0
  80. package/lib/types/components/webchatcontainerstateful/webchatcontroller/WebChatEventSubscribers.d.ts +7 -0
  81. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/Constants.d.ts +3 -0
  82. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/ConversationDividerActivity.d.ts +4 -0
  83. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LazyLoadActivity.d.ts +326 -0
  84. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activities/LoadInlineBannerActivity.d.ts +8 -0
  85. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -0
  86. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultInLineBannerStyle.d.ts +2 -0
  87. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/HistoryMessageTimestamp.d.ts +2 -0
  88. package/lib/types/contexts/common/ILiveChatWidgetLocalizedTexts.d.ts +1 -0
  89. package/package.json +2 -2
@@ -45,6 +45,10 @@ _defineProperty(Constants, "botParticipantTypeTag", "Bot");
45
45
  _defineProperty(Constants, "channelIdKey", "ChannelId-");
46
46
  _defineProperty(Constants, "ChannelId", "lcw");
47
47
  _defineProperty(Constants, "CustomerTag", "FromCustomer");
48
+ // LCW only tags (Only applicable on client-side for additional processing, not recognized by service)
49
+ _defineProperty(Constants, "persistentChatHistoryMessageTag", "PersistentChatHistory");
50
+ _defineProperty(Constants, "persistentChatHistoryMessagePullTriggerTag", "PersistentChatHistoryMessagePullTrigger");
51
+ _defineProperty(Constants, "conversationDividerTag", "ConversationDivider");
48
52
  // gifUploadMiddleware
49
53
  _defineProperty(Constants, "GifContentType", "image/gif");
50
54
  // htmlPlayerMiddleware
@@ -487,6 +487,12 @@ let FacadeChatSDK = /*#__PURE__*/function () {
487
487
  reconnectableChatsParams.authenticatedUserToken = this.token;
488
488
  return this.validateAndExecuteCall("getReconnectableChats", () => this.chatSDK.OCClient.getReconnectableChats(reconnectableChatsParams));
489
489
  }
490
+ }, {
491
+ key: "fetchPersistentConversationHistory",
492
+ value: async function fetchPersistentConversationHistory() {
493
+ let getPersistentChatHistoryOptionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
494
+ return this.validateAndExecuteCall("getPersistentChatHistory", () => this.chatSDK.getPersistentChatHistory(getPersistentChatHistoryOptionalParams));
495
+ }
490
496
  }]);
491
497
  return FacadeChatSDK;
492
498
  }();
@@ -73,10 +73,12 @@ exports.BroadcastEvent = BroadcastEvent;
73
73
  BroadcastEvent["OnWidgetError"] = "OnWidgetError";
74
74
  BroadcastEvent["FMLTrackingCompletedAck"] = "FMLTrackingCompletedAck";
75
75
  BroadcastEvent["FMLTrackingCompleted"] = "FMLTrackingCompleted";
76
+ BroadcastEvent["PersistentConversationReset"] = "PersistentConversationReset";
76
77
  })(BroadcastEvent || (exports.BroadcastEvent = BroadcastEvent = {}));
77
78
  let TelemetryEvent;
78
79
  exports.TelemetryEvent = TelemetryEvent;
79
80
  (function (TelemetryEvent) {
81
+ TelemetryEvent["FetchPersistentChatHistoryFailed"] = "FetchPersistentChatHistoryFailed";
80
82
  TelemetryEvent["CallAdded"] = "CallAdded";
81
83
  TelemetryEvent["LocalVideoStreamAdded"] = "LocalVideoStreamAdded";
82
84
  TelemetryEvent["LocalVideoStreamRemoved"] = "LocalVideoStreamRemoved";
@@ -288,6 +290,32 @@ exports.TelemetryEvent = TelemetryEvent;
288
290
  TelemetryEvent["UXLiveChatWidgetCompleted"] = "UXLiveChatWidgetCompleted";
289
291
  TelemetryEvent["AppInsightsInitialized"] = "AppInsightsInitialized";
290
292
  TelemetryEvent["AppInsightsInitFailed"] = "AppInsightsInitFailed";
293
+ TelemetryEvent["ConvertPersistentChatHistoryMessageToActivityFailed"] = "ConvertPersistentChatHistoryMessageToActivityFailed";
294
+ TelemetryEvent["UXLCWPersistentChatHistoryInitialized"] = "UXLCWPersistentChatHistoryInitialized";
295
+ TelemetryEvent["LCWPersistentChatHistoryFetchStarted"] = "LCWPersistentChatHistoryFetchStarted";
296
+ TelemetryEvent["LCWPersistentChatHistoryFetchCompleted"] = "LCWPersistentChatHistoryFetchCompleted";
297
+ TelemetryEvent["LCWPersistentChatHistoryFetchFailed"] = "LCWPersistentChatHistoryFetchFailed";
298
+ TelemetryEvent["LCWWebChatStorePollingStarted"] = "LCWWebChatStorePollingStarted";
299
+ TelemetryEvent["LCWWebChatStoreReady"] = "LCWWebChatStoreReady";
300
+ TelemetryEvent["LCWWebChatConnected"] = "LCWWebChatConnected";
301
+ TelemetryEvent["LCWWebChatDisconnected"] = "LCWWebChatDisconnected";
302
+ TelemetryEvent["LCWWebChatConnectionCheckFailed"] = "LCWWebChatConnectionCheckFailed";
303
+ TelemetryEvent["LCWPersistentConversationHandlerInitialized"] = "LCWPersistentConversationHandlerInitialized";
304
+ TelemetryEvent["LCWPersistentHistoryPullBlocked"] = "LCWPersistentHistoryPullBlocked";
305
+ TelemetryEvent["LCWPersistentHistoryPullCompleted"] = "LCWPersistentHistoryPullCompleted";
306
+ TelemetryEvent["LCWLazyLoadInitializationStarted"] = "LCWLazyLoadInitializationStarted";
307
+ TelemetryEvent["LCWLazyLoadContainerNotFound"] = "LCWLazyLoadContainerNotFound";
308
+ TelemetryEvent["LCWLazyLoadInitializationCompleted"] = "LCWLazyLoadInitializationCompleted";
309
+ TelemetryEvent["LCWLazyLoadSessionMetrics"] = "LCWLazyLoadSessionMetrics";
310
+ TelemetryEvent["LCWLazyLoadTargetElementNotFound"] = "LCWLazyLoadTargetElementNotFound";
311
+ TelemetryEvent["LCWLazyLoadScrollFailed"] = "LCWLazyLoadScrollFailed";
312
+ TelemetryEvent["LCWLazyLoadActivityMounted"] = "LCWLazyLoadActivityMounted";
313
+ TelemetryEvent["LCWLazyLoadReset"] = "LCWLazyLoadReset";
314
+ TelemetryEvent["LCWLazyLoadNoMoreHistory"] = "LCWLazyLoadNoMoreHistory";
315
+ TelemetryEvent["LCWLazyLoadDestroyed"] = "LCWLazyLoadDestroyed";
316
+ TelemetryEvent["SecureEventBusUnauthorizedDispatch"] = "SecureEventBusUnauthorizedDispatch";
317
+ TelemetryEvent["SecureEventBusListenerError"] = "SecureEventBusListenerError";
318
+ TelemetryEvent["SecureEventBusDispatchError"] = "SecureEventBusDispatchError";
291
319
  })(TelemetryEvent || (exports.TelemetryEvent = TelemetryEvent = {}));
292
320
  let TelemetryConstants = /*#__PURE__*/function () {
293
321
  function TelemetryConstants() {
@@ -355,6 +383,9 @@ let TelemetryConstants = /*#__PURE__*/function () {
355
383
  case TelemetryEvent.PostChatWorkflowFromAgent:
356
384
  case TelemetryEvent.PostChatWorkflowFromBot:
357
385
  case TelemetryEvent.AppStatesException:
386
+ case TelemetryEvent.SecureEventBusUnauthorizedDispatch:
387
+ case TelemetryEvent.SecureEventBusListenerError:
388
+ case TelemetryEvent.SecureEventBusDispatchError:
358
389
  return ScenarioType.ACTIONS;
359
390
  case TelemetryEvent.StartChatSDKCall:
360
391
  case TelemetryEvent.StartChatEventReceived:
@@ -0,0 +1,307 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _TelemetryHelper = require("../telemetry/TelemetryHelper");
8
+ var _TelemetryConstants = require("../telemetry/TelemetryConstants");
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
11
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
15
+ /**
16
+ * SecureEventBus class implementing the singleton pattern for secure event communication.
17
+ * Provides authentication-based event dispatching to prevent unauthorized external access.
18
+ */
19
+ let SecureEventBus = /*#__PURE__*/function () {
20
+ /**
21
+ * Private constructor to enforce singleton pattern.
22
+ * Generates a unique authentication token for this session.
23
+ */
24
+ function SecureEventBus() {
25
+ _classCallCheck(this, SecureEventBus);
26
+ _defineProperty(this, "listeners", new Map());
27
+ _defineProperty(this, "authToken", void 0);
28
+ _defineProperty(this, "eventCounter", 0);
29
+ // Generate a secure, unique token for this session
30
+ this.authToken = this.generateAuthToken();
31
+ }
32
+
33
+ /**
34
+ * Get the singleton instance of SecureEventBus.
35
+ * Creates a new instance if one doesn't exist.
36
+ *
37
+ * @returns The singleton instance of SecureEventBus
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const eventBus = SecureEventBus.getInstance();
42
+ * ```
43
+ */
44
+ _createClass(SecureEventBus, [{
45
+ key: "generateAuthToken",
46
+ value:
47
+ /**
48
+ * Generate a cryptographically secure authentication token.
49
+ * Uses crypto.getRandomValues when available, falls back to Math.random.
50
+ *
51
+ * @private
52
+ * @returns A 64-character hexadecimal string representing the authentication token
53
+ */
54
+ function generateAuthToken() {
55
+ const array = new Uint8Array(32);
56
+ if (typeof crypto !== "undefined" && crypto.getRandomValues) {
57
+ crypto.getRandomValues(array);
58
+ } else {
59
+ // Fallback for environments without crypto.getRandomValues
60
+ for (let i = 0; i < array.length; i++) {
61
+ array[i] = Math.floor(Math.random() * 256);
62
+ }
63
+ }
64
+ return Array.from(array, byte => byte.toString(16).padStart(2, "0")).join("");
65
+ }
66
+
67
+ /**
68
+ * Get the authentication token for this SecureEventBus instance.
69
+ * This token is required for dispatching events and should only be used internally.
70
+ *
71
+ * @returns The authentication token string
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * const eventBus = SecureEventBus.getInstance();
76
+ * const token = eventBus.getAuthToken();
77
+ * eventBus.dispatch('myEvent', { data: 'value' }, token);
78
+ * ```
79
+ */
80
+ }, {
81
+ key: "getAuthToken",
82
+ value: function getAuthToken() {
83
+ return this.authToken;
84
+ }
85
+
86
+ /**
87
+ * Dispatch an event with authentication to all registered listeners.
88
+ * Verifies the authentication token before dispatching to prevent unauthorized access.
89
+ *
90
+ * @param eventName - The name of the event to dispatch
91
+ * @param payload - The data to send with the event (optional)
92
+ * @param token - Authentication token (must match the internal token)
93
+ * @returns true if event was successfully dispatched, false if unauthorized or error occurred
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * const eventBus = SecureEventBus.getInstance();
98
+ * const token = eventBus.getAuthToken();
99
+ *
100
+ * // Dispatch with payload
101
+ * const success = eventBus.dispatch('userAction', { action: 'click', target: 'button' }, token);
102
+ *
103
+ * // Dispatch without payload
104
+ * eventBus.dispatch('windowClosed', undefined, token);
105
+ * ```
106
+ */
107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
+ }, {
109
+ key: "dispatch",
110
+ value: function dispatch(eventName, payload, token) {
111
+ // Verify authentication token
112
+ if (token !== this.authToken) {
113
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
114
+ Event: _TelemetryConstants.TelemetryEvent.SecureEventBusUnauthorizedDispatch,
115
+ Description: `Unauthorized event dispatch attempt blocked: ${eventName}`,
116
+ ExceptionDetails: {
117
+ eventName,
118
+ providedToken: token ? "provided" : "missing",
119
+ expectedToken: "secured"
120
+ }
121
+ });
122
+ return false;
123
+ }
124
+ const listeners = this.listeners.get(eventName);
125
+ if (!listeners || listeners.length === 0) {
126
+ return true; // No listeners, but not an error
127
+ }
128
+
129
+ // Dispatch to all registered listeners
130
+ try {
131
+ listeners.forEach(listener => {
132
+ try {
133
+ listener.callback(payload);
134
+ } catch (error) {
135
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
136
+ Event: _TelemetryConstants.TelemetryEvent.SecureEventBusListenerError,
137
+ Description: `Error in event listener for event: ${eventName}`,
138
+ ExceptionDetails: error
139
+ });
140
+ }
141
+ });
142
+ return true;
143
+ } catch (error) {
144
+ _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
145
+ Event: _TelemetryConstants.TelemetryEvent.SecureEventBusDispatchError,
146
+ Description: `Error dispatching event: ${eventName}`,
147
+ ExceptionDetails: error
148
+ });
149
+ return false;
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Subscribe to an event with a callback function.
155
+ * The callback will be executed whenever the specified event is dispatched.
156
+ *
157
+ * @param eventName - The name of the event to listen for
158
+ * @param callback - The function to execute when the event is fired
159
+ * @returns A function that can be called to unsubscribe from the event
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const eventBus = SecureEventBus.getInstance();
164
+ *
165
+ * // Subscribe to an event
166
+ * const unsubscribe = eventBus.subscribe('chatMessage', (message) => {
167
+ * console.log('New message:', message.text);
168
+ * console.log('From user:', message.userId);
169
+ * });
170
+ *
171
+ * // Later, unsubscribe
172
+ * unsubscribe();
173
+ * ```
174
+ */
175
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
+ }, {
177
+ key: "subscribe",
178
+ value: function subscribe(eventName, callback) {
179
+ const listenerId = `listener_${++this.eventCounter}`;
180
+ if (!this.listeners.has(eventName)) {
181
+ this.listeners.set(eventName, []);
182
+ }
183
+ const listeners = this.listeners.get(eventName);
184
+ if (!listeners) {
185
+ throw new Error(`Listeners for event "${eventName}" not found.`);
186
+ }
187
+ const listener = {
188
+ callback,
189
+ id: listenerId
190
+ };
191
+ listeners.push(listener);
192
+
193
+ // Return unsubscribe function
194
+ return () => {
195
+ const currentListeners = this.listeners.get(eventName);
196
+ if (currentListeners) {
197
+ const index = currentListeners.findIndex(l => l.id === listenerId);
198
+ if (index !== -1) {
199
+ currentListeners.splice(index, 1);
200
+ }
201
+
202
+ // Clean up empty listener arrays
203
+ if (currentListeners.length === 0) {
204
+ this.listeners.delete(eventName);
205
+ }
206
+ }
207
+ };
208
+ }
209
+
210
+ /**
211
+ * Remove all listeners for a specific event.
212
+ * This completely removes the event from the internal listeners map.
213
+ *
214
+ * @param eventName - The name of the event to remove all listeners for
215
+ *
216
+ * @example
217
+ * ```typescript
218
+ * const eventBus = SecureEventBus.getInstance();
219
+ *
220
+ * // Remove all listeners for 'chatClosed' event
221
+ * eventBus.removeAllListeners('chatClosed');
222
+ * ```
223
+ */
224
+ }, {
225
+ key: "removeAllListeners",
226
+ value: function removeAllListeners(eventName) {
227
+ this.listeners.delete(eventName);
228
+ }
229
+
230
+ /**
231
+ * Clear all listeners for all events.
232
+ * This resets the entire event bus to its initial state.
233
+ * Useful for cleanup during application shutdown or testing.
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * const eventBus = SecureEventBus.getInstance();
238
+ *
239
+ * // Clear all event listeners
240
+ * eventBus.clear();
241
+ * ```
242
+ */
243
+ }, {
244
+ key: "clear",
245
+ value: function clear() {
246
+ this.listeners.clear();
247
+ }
248
+
249
+ /**
250
+ * Get the number of listeners for a specific event.
251
+ * Useful for debugging and monitoring purposes.
252
+ *
253
+ * @param eventName - The name of the event to count listeners for
254
+ * @returns The number of listeners registered for the event
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * const eventBus = SecureEventBus.getInstance();
259
+ *
260
+ * // Check how many listeners are registered for 'userAction'
261
+ * const count = eventBus.getListenerCount('userAction');
262
+ * console.log(`${count} listeners registered for userAction`);
263
+ * ```
264
+ */
265
+ }, {
266
+ key: "getListenerCount",
267
+ value: function getListenerCount(eventName) {
268
+ var _this$listeners$get;
269
+ return ((_this$listeners$get = this.listeners.get(eventName)) === null || _this$listeners$get === void 0 ? void 0 : _this$listeners$get.length) || 0;
270
+ }
271
+
272
+ /**
273
+ * Get all registered event names.
274
+ * Returns an array of event names that currently have listeners.
275
+ * Useful for debugging and monitoring purposes.
276
+ *
277
+ * @returns An array of event names that have registered listeners
278
+ *
279
+ * @example
280
+ * ```typescript
281
+ * const eventBus = SecureEventBus.getInstance();
282
+ *
283
+ * // Get all registered events
284
+ * const events = eventBus.getRegisteredEvents();
285
+ * console.log('Active events:', events);
286
+ * // Output: ['userAction', 'chatMessage', 'windowResize']
287
+ * ```
288
+ */
289
+ }, {
290
+ key: "getRegisteredEvents",
291
+ value: function getRegisteredEvents() {
292
+ return Array.from(this.listeners.keys());
293
+ }
294
+ }], [{
295
+ key: "getInstance",
296
+ value: function getInstance() {
297
+ if (!SecureEventBus.instance) {
298
+ SecureEventBus.instance = new SecureEventBus();
299
+ }
300
+ return SecureEventBus.instance;
301
+ }
302
+ }]);
303
+ return SecureEventBus;
304
+ }();
305
+ _defineProperty(SecureEventBus, "instance", null);
306
+ var _default = SecureEventBus;
307
+ exports.default = _default;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _SecureEventBus = _interopRequireDefault(require("./SecureEventBus"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ const dispatchCustomEvent = (name, payload) => {
11
+ try {
12
+ const eventBus = _SecureEventBus.default.getInstance();
13
+ const authToken = eventBus.getAuthToken();
14
+
15
+ // Dispatch through the secure event bus instead of global window
16
+ const success = eventBus.dispatch(name, payload, authToken);
17
+ if (!success) {
18
+ console.error("Failed to dispatch secure event:", name);
19
+ }
20
+ } catch (error) {
21
+ console.error("Error dispatching secure custom event:", name, payload, error);
22
+ }
23
+ };
24
+ var _default = dispatchCustomEvent;
25
+ exports.default = _default;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AddActivitySubscriber = void 0;
7
+ var _TelemetryConstants = require("../../../../common/telemetry/TelemetryConstants");
8
+ var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
9
+ var _ChatWidgetEvents = _interopRequireDefault(require("../ChatWidgetEvents"));
10
+ var _SecureEventBus = _interopRequireDefault(require("../../../../common/utils/SecureEventBus"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
13
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
14
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
15
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
17
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
+ /**
19
+ * The `AddActivitySubscriber` class is responsible for subscribing to the `ADD_ACTIVITY` event
20
+ * from the `ChatWidgetEvents` and notifying an observer when a new activity is added.
21
+ *
22
+ * This class implements the `IActivitySubscriber` interface and acts as a bridge between
23
+ * the event system and the observer pattern.
24
+ */
25
+ let AddActivitySubscriber = /*#__PURE__*/function () {
26
+ /**
27
+ * The observer that will be notified when a new activity is added.
28
+ * This is expected to be an object with a `next` method, such as an RxJS `Observer`.
29
+ */
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+
32
+ /**
33
+ * Set to track processed activity IDs to prevent duplicate processing.
34
+ */
35
+
36
+ /**
37
+ * Unsubscribe function for the secure event listener
38
+ */
39
+
40
+ /**
41
+ * Subscription for PersistentConversationReset event
42
+ */
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+
45
+ /**
46
+ * Constructor initializes the `AddActivitySubscriber` and sets up a secure event listener
47
+ * for the `ChatWidgetEvents.ADD_ACTIVITY` event. When the event is triggered, it checks
48
+ * if the event payload contains an `activity` and notifies the observer.
49
+ */
50
+ function AddActivitySubscriber() {
51
+ _classCallCheck(this, AddActivitySubscriber);
52
+ _defineProperty(this, "observer", void 0);
53
+ _defineProperty(this, "processedActivityIds", new Set());
54
+ _defineProperty(this, "unsubscribeFromSecureEvent", null);
55
+ _defineProperty(this, "resetEventListener", void 0);
56
+ const eventBus = _SecureEventBus.default.getInstance();
57
+
58
+ // Subscribe to the secure event bus instead of global window events
59
+ this.unsubscribeFromSecureEvent = eventBus.subscribe(_ChatWidgetEvents.default.ADD_ACTIVITY, payload => {
60
+ if (payload !== null && payload !== void 0 && payload.activity) {
61
+ var _this$observer;
62
+ const activity = payload.activity;
63
+ const activityId = activity.id;
64
+ if (activity.identifier) {
65
+ if (this.processedActivityIds.has(activity === null || activity === void 0 ? void 0 : activity.identifier)) {
66
+ return; // Skip processing if already handled
67
+ }
68
+ // Add the activity ID to the processed set
69
+ this.processedActivityIds.add(activity === null || activity === void 0 ? void 0 : activity.identifier);
70
+ }
71
+
72
+ // Check if activity has an ID and if it has already been processed
73
+ if (activityId) {
74
+ if (this.processedActivityIds.has(activityId)) {
75
+ return; // Skip processing if already handled
76
+ }
77
+
78
+ // Add the activity ID to the processed set
79
+ this.processedActivityIds.add(activityId);
80
+ }
81
+
82
+ // Notify the observer with the new activity
83
+ (_this$observer = this.observer) === null || _this$observer === void 0 ? void 0 : _this$observer.next(activity);
84
+ }
85
+ });
86
+
87
+ // Subscribe to reset events for cleanup
88
+ this.resetEventListener = _omnichannelChatComponents.BroadcastService.getMessageByEventName(_TelemetryConstants.BroadcastEvent.PersistentConversationReset).subscribe(() => {
89
+ this.reset();
90
+ // Clean up the secure event listener when conversation resets
91
+ if (this.unsubscribeFromSecureEvent) {
92
+ this.unsubscribeFromSecureEvent();
93
+ this.unsubscribeFromSecureEvent = null;
94
+ }
95
+ // Unsubscribe from the reset event to prevent accumulation
96
+ if (this.resetEventListener) {
97
+ this.resetEventListener.unsubscribe();
98
+ }
99
+ });
100
+ }
101
+
102
+ /**
103
+ * The `next` method is a placeholder for processing the activity.
104
+ * This method can be overridden or extended as needed.
105
+ *
106
+ * @param activity - The activity object to process.
107
+ * @returns The activity object (asynchronously).
108
+ */
109
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
110
+ _createClass(AddActivitySubscriber, [{
111
+ key: "next",
112
+ value: async function next(activity) {
113
+ return activity;
114
+ }
115
+
116
+ /**
117
+ * Reset the processed activity IDs when a conversation resets
118
+ */
119
+ }, {
120
+ key: "reset",
121
+ value: function reset() {
122
+ this.processedActivityIds.clear();
123
+ }
124
+ }]);
125
+ return AddActivitySubscriber;
126
+ }();
127
+ exports.AddActivitySubscriber = AddActivitySubscriber;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var ChatWidgetEvents;
8
+ (function (ChatWidgetEvents) {
9
+ ChatWidgetEvents["ADD_ACTIVITY"] = "CHAT_WIDGET/ADD_ACTIVITY";
10
+ ChatWidgetEvents["FETCH_PERSISTENT_CHAT_HISTORY"] = "CHAT_WIDGET/FETCH_PERSISTENT_CHAT_HISTORY";
11
+ ChatWidgetEvents["NO_MORE_HISTORY_AVAILABLE"] = "CHAT_WIDGET/NO_MORE_HISTORY_AVAILABLE";
12
+ ChatWidgetEvents["HIDE_LOADING_BANNER"] = "CHAT_WIDGET/HIDE_LOADING_BANNER";
13
+ })(ChatWidgetEvents || (ChatWidgetEvents = {}));
14
+ var _default = ChatWidgetEvents;
15
+ exports.default = _default;