@microsoft/omnichannel-chat-widget 0.1.0-main.c461296 → 0.1.0-main.cda7a31

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 (179) hide show
  1. package/README.md +35 -11
  2. package/lib/cjs/common/Constants.js +50 -6
  3. package/lib/cjs/common/storage/default/defaultCacheManager.js +34 -0
  4. package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +114 -0
  5. package/lib/cjs/common/storage/default/defaultInMemoryDataStore.js +86 -0
  6. package/lib/cjs/common/telemetry/TelemetryConstants.js +51 -3
  7. package/lib/cjs/common/telemetry/TelemetryHelper.js +13 -0
  8. package/lib/cjs/common/telemetry/TelemetryManager.js +16 -5
  9. package/lib/cjs/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  10. package/lib/cjs/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  11. package/lib/cjs/common/telemetry/loggers/ariaTelemetryLogger.js +54 -21
  12. package/lib/cjs/common/telemetry/loggers/consoleLogger.js +6 -5
  13. package/lib/cjs/common/utils.js +89 -2
  14. package/lib/cjs/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  15. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +20 -4
  16. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -44
  17. package/lib/cjs/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
  18. package/lib/cjs/components/footerstateful/FooterStateful.js +6 -15
  19. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -2
  20. package/lib/cjs/components/headerstateful/HeaderStateful.js +15 -14
  21. package/lib/cjs/components/livechatwidget/common/ActivityStreamHandler.js +44 -0
  22. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +23 -0
  23. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  24. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +39 -0
  25. package/lib/cjs/components/livechatwidget/common/ChatAdapterShim.js +70 -0
  26. package/lib/cjs/components/livechatwidget/common/Deferred.js +42 -0
  27. package/lib/cjs/components/livechatwidget/common/authHelper.js +65 -0
  28. package/lib/cjs/components/livechatwidget/common/createAdapter.js +13 -1
  29. package/lib/cjs/components/livechatwidget/common/createFooter.js +7 -16
  30. package/lib/cjs/components/livechatwidget/common/createInternetConnectionChangeHandler.js +12 -0
  31. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +31 -30
  32. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +36 -20
  33. package/lib/cjs/components/livechatwidget/common/endChat.js +93 -10
  34. package/lib/cjs/components/livechatwidget/common/initCallingSdk.js +1 -1
  35. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +27 -3
  36. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +144 -39
  37. package/lib/cjs/components/livechatwidget/common/registerTelemetryLoggers.js +6 -17
  38. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  39. package/lib/cjs/components/livechatwidget/common/shareObservable.js +45 -0
  40. package/lib/cjs/components/livechatwidget/common/startChat.js +166 -50
  41. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +310 -73
  42. package/lib/cjs/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +8 -0
  43. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +6 -4
  44. package/lib/cjs/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.js +1 -0
  45. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -10
  46. package/lib/cjs/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  47. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +98 -2
  48. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +4 -1
  49. package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +11 -0
  50. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  51. package/lib/cjs/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
  52. package/lib/cjs/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  53. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +14 -0
  54. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  55. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
  56. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +52 -0
  57. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +98 -0
  58. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +10 -0
  59. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +117 -0
  60. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +45 -0
  61. package/lib/cjs/contexts/common/ConversationState.js +3 -2
  62. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +11 -8
  63. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +15 -6
  64. package/lib/cjs/contexts/createReducer.js +26 -12
  65. package/lib/cjs/controller/componentController.js +3 -3
  66. package/lib/cjs/plugins/newMessageEventHandler.js +10 -13
  67. package/lib/esm/common/Constants.js +46 -5
  68. package/lib/esm/common/storage/default/defaultCacheManager.js +19 -0
  69. package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +102 -0
  70. package/lib/esm/common/storage/default/defaultInMemoryDataStore.js +71 -0
  71. package/lib/esm/common/telemetry/TelemetryConstants.js +51 -3
  72. package/lib/esm/common/telemetry/TelemetryHelper.js +13 -1
  73. package/lib/esm/common/telemetry/TelemetryManager.js +14 -5
  74. package/lib/esm/common/telemetry/defaultConfigs/defaultAriaConfig.js +1 -1
  75. package/lib/esm/common/telemetry/defaultConfigs/defaultTelemetryConfiguration.js +4 -1
  76. package/lib/esm/common/telemetry/loggers/ariaTelemetryLogger.js +55 -17
  77. package/lib/esm/common/telemetry/loggers/consoleLogger.js +6 -5
  78. package/lib/esm/common/utils.js +64 -1
  79. package/lib/esm/components/callingcontainerstateful/CallingContainerStateful.js +14 -0
  80. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +22 -7
  81. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +11 -42
  82. package/lib/esm/components/emailtranscriptpanestateful/EmailTranscriptPaneStateful.js +4 -4
  83. package/lib/esm/components/footerstateful/FooterStateful.js +6 -15
  84. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +9 -3
  85. package/lib/esm/components/headerstateful/HeaderStateful.js +15 -14
  86. package/lib/esm/components/livechatwidget/common/ActivityStreamHandler.js +34 -0
  87. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +14 -0
  88. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.js +1 -0
  89. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +29 -0
  90. package/lib/esm/components/livechatwidget/common/ChatAdapterShim.js +59 -0
  91. package/lib/esm/components/livechatwidget/common/Deferred.js +33 -0
  92. package/lib/esm/components/livechatwidget/common/authHelper.js +50 -0
  93. package/lib/esm/components/livechatwidget/common/createAdapter.js +12 -2
  94. package/lib/esm/components/livechatwidget/common/createFooter.js +4 -15
  95. package/lib/esm/components/livechatwidget/common/createInternetConnectionChangeHandler.js +8 -0
  96. package/lib/esm/components/livechatwidget/common/createMarkdown.js +31 -30
  97. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +36 -21
  98. package/lib/esm/components/livechatwidget/common/endChat.js +89 -11
  99. package/lib/esm/components/livechatwidget/common/initCallingSdk.js +1 -1
  100. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +25 -5
  101. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +134 -41
  102. package/lib/esm/components/livechatwidget/common/registerTelemetryLoggers.js +5 -14
  103. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +0 -4
  104. package/lib/esm/components/livechatwidget/common/shareObservable.js +38 -0
  105. package/lib/esm/components/livechatwidget/common/startChat.js +161 -53
  106. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +298 -78
  107. package/lib/esm/components/postchatloadingpanestateful/PostChatLoadingPaneStateful.js +6 -0
  108. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +5 -4
  109. package/lib/esm/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.js +1 -0
  110. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +7 -11
  111. package/lib/esm/components/proactivechatpanestateful/ProactiveChatPaneStateful.js +17 -1
  112. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +87 -2
  113. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +3 -1
  114. package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.js +4 -0
  115. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +2 -0
  116. package/lib/esm/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.js +1 -0
  117. package/lib/esm/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.js +1 -0
  118. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.js +5 -0
  119. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityMiddleware.js +16 -2
  120. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.js +2 -1
  121. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.js +41 -0
  122. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.js +94 -0
  123. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.js +3 -0
  124. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.js +107 -0
  125. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +32 -0
  126. package/lib/esm/contexts/common/ConversationState.js +3 -2
  127. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +11 -8
  128. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +13 -6
  129. package/lib/esm/contexts/createReducer.js +26 -11
  130. package/lib/esm/controller/componentController.js +3 -3
  131. package/lib/esm/plugins/newMessageEventHandler.js +10 -12
  132. package/lib/types/common/Constants.d.ts +25 -2
  133. package/lib/types/common/interfaces/IContextDataStore.d.ts +2 -2
  134. package/lib/types/common/storage/default/defaultCacheManager.d.ts +4 -0
  135. package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -0
  136. package/lib/types/common/storage/default/defaultInMemoryDataStore.d.ts +6 -0
  137. package/lib/types/common/telemetry/TelemetryConstants.d.ts +36 -5
  138. package/lib/types/common/telemetry/TelemetryHelper.d.ts +2 -0
  139. package/lib/types/common/telemetry/definitions/Payload.d.ts +12 -9
  140. package/lib/types/common/telemetry/interfaces/ITelemetryConfig.d.ts +3 -3
  141. package/lib/types/common/utils.d.ts +8 -1
  142. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +4 -4
  143. package/lib/types/components/footerstateful/audionotificationstateful/interfaces/IAudioNotificationStatefulParams.d.ts +0 -1
  144. package/lib/types/components/headerstateful/interfaces/IHeaderStatefulParams.d.ts +2 -1
  145. package/lib/types/components/livechatwidget/common/ActivityStreamHandler.d.ts +14 -0
  146. package/lib/types/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.d.ts +5 -0
  147. package/lib/types/components/livechatwidget/common/ActivitySubscriber/IActivitySubscriber.d.ts +6 -0
  148. package/lib/types/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.d.ts +7 -0
  149. package/lib/types/components/livechatwidget/common/ChatAdapterShim.d.ts +7 -0
  150. package/lib/types/components/livechatwidget/common/Deferred.d.ts +9 -0
  151. package/lib/types/components/livechatwidget/common/authHelper.d.ts +5 -0
  152. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -1
  153. package/lib/types/components/livechatwidget/common/reconnectChatHelper.d.ts +6 -2
  154. package/lib/types/components/livechatwidget/common/shareObservable.d.ts +1 -0
  155. package/lib/types/components/livechatwidget/common/startChat.d.ts +4 -2
  156. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetComponentOverrides.d.ts +1 -0
  157. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetControlProps.d.ts +1 -0
  158. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +4 -3
  159. package/lib/types/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.d.ts +2 -2
  160. package/lib/types/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +4 -0
  161. package/lib/types/components/reconnectchatpanestateful/interfaces/IReconnectChatPaneStatefulProps.d.ts +1 -1
  162. package/lib/types/components/webchatcontainerstateful/common/defaultStyles/defaultAdaptiveCardStyles.d.ts +2 -0
  163. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +1 -0
  164. package/lib/types/components/webchatcontainerstateful/interfaces/IAdaptiveCardStyles.d.ts +4 -0
  165. package/lib/types/components/webchatcontainerstateful/interfaces/IBotMagicCodeConfig.d.ts +4 -0
  166. package/lib/types/components/webchatcontainerstateful/interfaces/IRenderingMiddlewareProps.d.ts +2 -1
  167. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +4 -0
  168. package/lib/types/components/webchatcontainerstateful/webchatcontroller/BotMagicCodeStore.d.ts +3 -0
  169. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/activityStatusMiddleware.d.ts +1 -1
  170. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.d.ts +2 -0
  171. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/cardActionMiddleware.spec.d.ts +1 -0
  172. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/defaultStyles/defaultReceivedMessageAnchorStyles.d.ts +2 -0
  173. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/messageTimestampMiddleware.d.ts +5 -0
  174. package/lib/types/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.d.ts +1 -0
  175. package/lib/types/contexts/common/ConversationState.d.ts +3 -2
  176. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +4 -2
  177. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +12 -9
  178. package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +1 -2
  179. package/package.json +9 -9
@@ -15,6 +15,7 @@ exports.ConversationState = ConversationState;
15
15
  ConversationState[ConversationState["ProactiveChat"] = 4] = "ProactiveChat";
16
16
  ConversationState[ConversationState["Active"] = 5] = "Active";
17
17
  ConversationState[ConversationState["InActive"] = 6] = "InActive";
18
- ConversationState[ConversationState["Postchat"] = 7] = "Postchat";
19
- ConversationState[ConversationState["Closed"] = 8] = "Closed";
18
+ ConversationState[ConversationState["PostchatLoading"] = 7] = "PostchatLoading";
19
+ ConversationState[ConversationState["Postchat"] = 8] = "Postchat";
20
+ ConversationState[ConversationState["Closed"] = 9] = "Closed";
20
21
  })(ConversationState || (exports.ConversationState = ConversationState = {}));
@@ -14,16 +14,16 @@ exports.LiveChatWidgetActionType = LiveChatWidgetActionType;
14
14
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_GLOBAL_DIR"] = 3] = "SET_GLOBAL_DIR";
15
15
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_MINIMIZED"] = 4] = "SET_MINIMIZED";
16
16
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CONVERSATION_STATE"] = 5] = "SET_CONVERSATION_STATE";
17
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PREVIOUS_FOCUSED_ELEMENT"] = 6] = "SET_PREVIOUS_FOCUSED_ELEMENT";
17
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PREVIOUS_FOCUSED_ELEMENT_ID"] = 6] = "SET_PREVIOUS_FOCUSED_ELEMENT_ID";
18
18
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_OUTSIDE_OPERATING_HOURS"] = 7] = "SET_OUTSIDE_OPERATING_HOURS";
19
19
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PRE_CHAT_SURVEY_RESPONSE"] = 8] = "SET_PRE_CHAT_SURVEY_RESPONSE";
20
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_CONFIRMATION"] = 9] = "SET_SHOW_CONFIRMATION";
21
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_EMAIL_TRANSCRIPT_PANE"] = 10] = "SET_SHOW_EMAIL_TRANSCRIPT_PANE";
22
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PRECHAT_RESPONSE_EMAIL"] = 11] = "SET_PRECHAT_RESPONSE_EMAIL";
23
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_AUDIO_NOTIFICATION"] = 12] = "SET_AUDIO_NOTIFICATION";
24
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_E2VV_ENABLED"] = 13] = "SET_E2VV_ENABLED";
25
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_POST_CHAT_CONTEXT"] = 14] = "SET_POST_CHAT_CONTEXT";
26
- LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOULD_SHOW_POST_CHAT"] = 15] = "SET_SHOULD_SHOW_POST_CHAT";
20
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CUSTOM_CONTEXT"] = 9] = "SET_CUSTOM_CONTEXT";
21
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_CONFIRMATION"] = 10] = "SET_SHOW_CONFIRMATION";
22
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_SHOW_EMAIL_TRANSCRIPT_PANE"] = 11] = "SET_SHOW_EMAIL_TRANSCRIPT_PANE";
23
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_PRECHAT_RESPONSE_EMAIL"] = 12] = "SET_PRECHAT_RESPONSE_EMAIL";
24
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_AUDIO_NOTIFICATION"] = 13] = "SET_AUDIO_NOTIFICATION";
25
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_E2VV_ENABLED"] = 14] = "SET_E2VV_ENABLED";
26
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_POST_CHAT_CONTEXT"] = 15] = "SET_POST_CHAT_CONTEXT";
27
27
  LiveChatWidgetActionType[LiveChatWidgetActionType["SHOW_CALLING_CONTAINER"] = 16] = "SHOW_CALLING_CONTAINER";
28
28
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_INCOMING_CALL"] = 17] = "SET_INCOMING_CALL";
29
29
  LiveChatWidgetActionType[LiveChatWidgetActionType["DISABLE_VIDEO_CALL"] = 18] = "DISABLE_VIDEO_CALL";
@@ -39,4 +39,7 @@ exports.LiveChatWidgetActionType = LiveChatWidgetActionType;
39
39
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_CONVERSATION_ENDED_BY_AGENT"] = 28] = "SET_CONVERSATION_ENDED_BY_AGENT";
40
40
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_STATE"] = 29] = "SET_WIDGET_STATE";
41
41
  LiveChatWidgetActionType[LiveChatWidgetActionType["SET_LIVE_CHAT_CONTEXT"] = 30] = "SET_LIVE_CHAT_CONTEXT";
42
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_BOT_OAUTH_SIGNIN_ID"] = 31] = "SET_BOT_OAUTH_SIGNIN_ID";
43
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_SIZE"] = 32] = "SET_WIDGET_SIZE";
44
+ LiveChatWidgetActionType[LiveChatWidgetActionType["SET_WIDGET_INSTANCE_ID"] = 33] = "SET_WIDGET_INSTANCE_ID";
42
45
  })(LiveChatWidgetActionType || (exports.LiveChatWidgetActionType = LiveChatWidgetActionType = {}));
@@ -9,11 +9,18 @@ var _ConversationState = require("./ConversationState");
9
9
 
10
10
  var _defaultMiddlewareLocalizedTexts = require("../../components/webchatcontainerstateful/common/defaultProps/defaultMiddlewareLocalizedTexts");
11
11
 
12
+ var _utils = require("../../common/utils");
13
+
14
+ var _defaultClientDataStoreProvider = require("../../common/storage/default/defaultClientDataStoreProvider");
15
+
12
16
  const getLiveChatWidgetContextInitialState = props => {
13
- var _props$webChatContain;
17
+ var _props$chatSDK, _props$chatSDK$omnich, _props$chatSDK2, _props$chatSDK2$omnic, _props$controlProps, _props$webChatContain;
18
+
19
+ const widgetCacheId = (0, _utils.getWidgetCacheId)(props === null || props === void 0 ? void 0 : (_props$chatSDK = props.chatSDK) === null || _props$chatSDK === void 0 ? void 0 : (_props$chatSDK$omnich = _props$chatSDK.omnichannelConfig) === null || _props$chatSDK$omnich === void 0 ? void 0 : _props$chatSDK$omnich.orgId, props === null || props === void 0 ? void 0 : (_props$chatSDK2 = props.chatSDK) === null || _props$chatSDK2 === void 0 ? void 0 : (_props$chatSDK2$omnic = _props$chatSDK2.omnichannelConfig) === null || _props$chatSDK2$omnic === void 0 ? void 0 : _props$chatSDK2$omnic.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId) ?? "");
20
+ const initialState = (0, _defaultClientDataStoreProvider.defaultClientDataStoreProvider)().getData(widgetCacheId, "localStorage");
14
21
 
15
- if (props !== null && props !== void 0 && props.liveChatContextFromCache) {
16
- return props === null || props === void 0 ? void 0 : props.liveChatContextFromCache;
22
+ if (!(0, _utils.isNullOrUndefined)(initialState)) {
23
+ return JSON.parse(initialState);
17
24
  }
18
25
 
19
26
  const LiveChatWidgetContextInitialState = {
@@ -27,14 +34,16 @@ const getLiveChatWidgetContextInitialState = props => {
27
34
  postChatContext: undefined,
28
35
  telemetryInternalData: {},
29
36
  globalDir: "ltr",
30
- liveChatContext: undefined
37
+ liveChatContext: undefined,
38
+ customContext: undefined,
39
+ widgetSize: undefined,
40
+ widgetInstanceId: ""
31
41
  },
32
42
  appStates: {
33
43
  conversationState: _ConversationState.ConversationState.Closed,
34
44
  isMinimized: false,
35
- previousElementOnFocusBeforeModalOpen: null,
45
+ previousElementIdOnFocusBeforeModalOpen: null,
36
46
  outsideOperatingHours: false,
37
- shouldShowPostChat: false,
38
47
  preChatResponseEmail: "",
39
48
  isAudioMuted: null,
40
49
  newMessage: false,
@@ -7,8 +7,6 @@ exports.createReducer = void 0;
7
7
 
8
8
  var _LiveChatWidgetActionType = require("./common/LiveChatWidgetActionType");
9
9
 
10
- var _TelemetryManager = require("../common/telemetry/TelemetryManager");
11
-
12
10
  /* eslint-disable indent */
13
11
  const createReducer = () => {
14
12
  const reducer = (state, action) => {
@@ -71,10 +69,18 @@ const createReducer = () => {
71
69
  }
72
70
  };
73
71
 
74
- case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PREVIOUS_FOCUSED_ELEMENT:
72
+ case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CUSTOM_CONTEXT:
73
+ return { ...state,
74
+ domainStates: { ...state.domainStates,
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ customContext: action.payload
77
+ }
78
+ };
79
+
80
+ case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_PREVIOUS_FOCUSED_ELEMENT_ID:
75
81
  return { ...state,
76
82
  appStates: { ...state.appStates,
77
- previousElementOnFocusBeforeModalOpen: action.payload
83
+ previousElementIdOnFocusBeforeModalOpen: action.payload
78
84
  }
79
85
  };
80
86
 
@@ -93,13 +99,6 @@ const createReducer = () => {
93
99
  }
94
100
  };
95
101
 
96
- case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_SHOULD_SHOW_POST_CHAT:
97
- return { ...state,
98
- appStates: { ...state.appStates,
99
- shouldShowPostChat: action.payload
100
- }
101
- };
102
-
103
102
  case _LiveChatWidgetActionType.LiveChatWidgetActionType.SHOW_CALLING_CONTAINER:
104
103
  return { ...state,
105
104
  uiStates: { ...state.uiStates,
@@ -197,7 +196,6 @@ const createReducer = () => {
197
196
  };
198
197
 
199
198
  case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_TELEMETRY_DATA:
200
- _TelemetryManager.TelemetryManager.InternalTelemetryData = action.payload;
201
199
  return { ...state,
202
200
  domainStates: { ...state.domainStates,
203
201
  telemetryInternalData: action.payload
@@ -237,6 +235,22 @@ const createReducer = () => {
237
235
  }
238
236
  };
239
237
 
238
+ case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_SIZE:
239
+ return { ...state,
240
+ domainStates: { ...state.domainStates,
241
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
242
+ widgetSize: action.payload
243
+ }
244
+ };
245
+
246
+ case _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_INSTANCE_ID:
247
+ return { ...state,
248
+ domainStates: { ...state.domainStates,
249
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
+ widgetInstanceId: action.payload
251
+ }
252
+ };
253
+
240
254
  default:
241
255
  return state;
242
256
  }
@@ -8,7 +8,7 @@ exports.shouldShowWebChatContainer = exports.shouldShowReconnectChatPane = expor
8
8
  var _ConversationState = require("../contexts/common/ConversationState");
9
9
 
10
10
  const shouldShowChatButton = state => {
11
- return state.appStates.isMinimized || state.appStates.conversationState === _ConversationState.ConversationState.Closed;
11
+ return (state.appStates.isMinimized || state.appStates.conversationState === _ConversationState.ConversationState.Closed) && state.appStates.skipChatButtonRendering == false; // Do not show chat button in case of popout
12
12
  };
13
13
 
14
14
  exports.shouldShowChatButton = shouldShowChatButton;
@@ -44,7 +44,7 @@ const shouldShowWebChatContainer = state => {
44
44
  exports.shouldShowWebChatContainer = shouldShowWebChatContainer;
45
45
 
46
46
  const shouldShowLoadingPane = state => {
47
- return !state.appStates.isMinimized && !state.appStates.shouldShowPostChat && state.appStates.conversationState === _ConversationState.ConversationState.Loading;
47
+ return !state.appStates.isMinimized && state.appStates.conversationState === _ConversationState.ConversationState.Loading;
48
48
  };
49
49
 
50
50
  exports.shouldShowLoadingPane = shouldShowLoadingPane;
@@ -56,7 +56,7 @@ const shouldShowReconnectChatPane = state => {
56
56
  exports.shouldShowReconnectChatPane = shouldShowReconnectChatPane;
57
57
 
58
58
  const shouldShowPostChatLoadingPane = state => {
59
- return !state.appStates.isMinimized && state.appStates.shouldShowPostChat && state.appStates.conversationState === _ConversationState.ConversationState.Loading;
59
+ return !state.appStates.isMinimized && state.appStates.conversationState === _ConversationState.ConversationState.PostchatLoading;
60
60
  };
61
61
 
62
62
  exports.shouldShowPostChatLoadingPane = shouldShowPostChatLoadingPane;
@@ -13,8 +13,6 @@ var _Constants = require("../common/Constants");
13
13
 
14
14
  var _TelemetryHelper = require("../common/telemetry/TelemetryHelper");
15
15
 
16
- var _TelemetryManager = require("../common/telemetry/TelemetryManager");
17
-
18
16
  const createOnNewAdapterActivityHandler = (chatId, userId) => {
19
17
  const onNewAdapterActivityHandler = activity => {
20
18
  var _activity$channelData, _activity$channelData2, _activity$channelData3;
@@ -29,18 +27,16 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
29
27
 
30
28
  const raiseMessageEvent = activity => {
31
29
  if ((activity === null || activity === void 0 ? void 0 : activity.type) === _Constants.Constants.message) {
32
- var _TelemetryManager$Int, _activity$from;
30
+ var _text, _text2, _activity$channelData4, _activity$from;
33
31
 
34
32
  const payload = {
33
+ // To identify hidden contents vs empty content
35
34
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
- text: activity === null || activity === void 0 ? void 0 : activity.text,
37
- id: activity === null || activity === void 0 ? void 0 : activity.id,
35
+ text: (activity === null || activity === void 0 ? void 0 : (_text = activity.text) === null || _text === void 0 ? void 0 : _text.length) >= 1 ? `*contents hidden (${activity === null || activity === void 0 ? void 0 : (_text2 = activity.text) === null || _text2 === void 0 ? void 0 : _text2.length} chars)*` : "",
38
36
  type: activity === null || activity === void 0 ? void 0 : activity.type,
39
37
  timestamp: activity === null || activity === void 0 ? void 0 : activity.timestamp,
40
- chatId: chatId,
41
38
  userId: userId,
42
- conversationId: ((_TelemetryManager$Int = _TelemetryManager.TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int === void 0 ? void 0 : _TelemetryManager$Int.conversationId) ?? "",
43
- channelData: activity === null || activity === void 0 ? void 0 : activity.channelData,
39
+ tags: activity === null || activity === void 0 ? void 0 : (_activity$channelData4 = activity.channelData) === null || _activity$channelData4 === void 0 ? void 0 : _activity$channelData4.tags,
44
40
  messageType: ""
45
41
  };
46
42
 
@@ -59,18 +55,18 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
59
55
  Description: "New message sent"
60
56
  });
61
57
  } else {
62
- var _activity$channelData4, _activity$channelData5;
58
+ var _activity$channelData5, _activity$channelData6;
63
59
 
64
- if (activity !== null && activity !== void 0 && (_activity$channelData4 = activity.channelData) !== null && _activity$channelData4 !== void 0 && (_activity$channelData5 = _activity$channelData4.tags) !== null && _activity$channelData5 !== void 0 && _activity$channelData5.includes(_Constants.Constants.systemMessageTag)) {
60
+ if (activity !== null && activity !== void 0 && (_activity$channelData5 = activity.channelData) !== null && _activity$channelData5 !== void 0 && (_activity$channelData6 = _activity$channelData5.tags) !== null && _activity$channelData6 !== void 0 && _activity$channelData6.includes(_Constants.Constants.systemMessageTag)) {
65
61
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
62
  payload.messageType = _Constants.Constants.systemMessageTag;
67
63
  } else {
68
- var _activity$channelData6, _activity$channelData7, _activity$channelData8;
64
+ var _activity$channelData7, _activity$channelData8, _activity$channelData9;
69
65
 
70
66
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
67
  const messageHasNoText = !(activity !== null && activity !== void 0 && activity.text); // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
68
 
73
- const messageHasNoTags = !(activity !== null && activity !== void 0 && activity.channelData) || !(activity !== null && activity !== void 0 && (_activity$channelData6 = activity.channelData) !== null && _activity$channelData6 !== void 0 && _activity$channelData6.tags) || (activity === null || activity === void 0 ? void 0 : (_activity$channelData7 = activity.channelData) === null || _activity$channelData7 === void 0 ? void 0 : (_activity$channelData8 = _activity$channelData7.tags) === null || _activity$channelData8 === void 0 ? void 0 : _activity$channelData8.length) === 0; // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ const messageHasNoTags = !(activity !== null && activity !== void 0 && activity.channelData) || !(activity !== null && activity !== void 0 && (_activity$channelData7 = activity.channelData) !== null && _activity$channelData7 !== void 0 && _activity$channelData7.tags) || (activity === null || activity === void 0 ? void 0 : (_activity$channelData8 = activity.channelData) === null || _activity$channelData8 === void 0 ? void 0 : (_activity$channelData9 = _activity$channelData8.tags) === null || _activity$channelData9 === void 0 ? void 0 : _activity$channelData9.length) === 0; // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
70
 
75
71
  const messageHasNoAttachments = !(activity !== null && activity !== void 0 && activity.attachments) || (activity === null || activity === void 0 ? void 0 : activity.attachments.length) === 0;
76
72
 
@@ -90,7 +86,8 @@ const createOnNewAdapterActivityHandler = (chatId, userId) => {
90
86
 
91
87
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.INFO, {
92
88
  Event: _TelemetryConstants.TelemetryEvent.MessageReceived,
93
- Description: "New message received"
89
+ Description: "New message received",
90
+ Data: payload
94
91
  });
95
92
  }
96
93
  }
@@ -4,6 +4,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
4
4
 
5
5
  export class Constants {}
6
6
 
7
+ _defineProperty(Constants, "magicCodeBroadcastChannel", "MagicCodeChannel");
8
+
9
+ _defineProperty(Constants, "magicCodeResponseBroadcastChannel", "MagicCodeResponseChannel");
10
+
7
11
  _defineProperty(Constants, "systemMessageTag", "system");
8
12
 
9
13
  _defineProperty(Constants, "userMessageTag", "user");
@@ -36,8 +40,6 @@ _defineProperty(Constants, "false", "false");
36
40
 
37
41
  _defineProperty(Constants, "maximumUnreadMessageCount", 99);
38
42
 
39
- _defineProperty(Constants, "widgetStateDataKey", "LcwChatWidgetState");
40
-
41
43
  _defineProperty(Constants, "channelIdKey", "ChannelId-");
42
44
 
43
45
  _defineProperty(Constants, "ChannelId", "lcw");
@@ -72,6 +74,14 @@ _defineProperty(Constants, "averageWaitTimeMessageTag", "averagewaittime");
72
74
 
73
75
  _defineProperty(Constants, "message", "message");
74
76
 
77
+ _defineProperty(Constants, "hiddenTag", "Hidden");
78
+
79
+ _defineProperty(Constants, "prefixTimestampTag", "ServerMessageTimestamp_");
80
+
81
+ _defineProperty(Constants, "acsChannel", "ACS_CHANNEL");
82
+
83
+ _defineProperty(Constants, "publicMessageTag", "public");
84
+
75
85
  _defineProperty(Constants, "supportedAdaptiveCardContentTypes", ["application/vnd.microsoft.card.adaptive", "application/vnd.microsoft.card.audio", "application/vnd.microsoft.card.hero", "application/vnd.microsoft.card.receipt", "application/vnd.microsoft.card.thumbnail", "application/vnd.microsoft.card.signin", "application/vnd.microsoft.card.oauth"]);
76
86
 
77
87
  _defineProperty(Constants, "maxUploadFileSize", "500000");
@@ -122,8 +132,6 @@ _defineProperty(Constants, "InputSubmit", "InputSubmit");
122
132
 
123
133
  _defineProperty(Constants, "ReconnectIdAttributeName", "oc.reconnectid");
124
134
 
125
- _defineProperty(Constants, "redirectPageRequest", "redirectPageRequest");
126
-
127
135
  _defineProperty(Constants, "LiveChatWidget", "LiveChatWidgetNew");
128
136
 
129
137
  _defineProperty(Constants, "GuidPattern", "xx-x-4m-ym-xxx");
@@ -148,6 +156,12 @@ _defineProperty(Constants, "internetConnectionTestUrl", "https://ocsdk-prod.azur
148
156
 
149
157
  _defineProperty(Constants, "internetConnectionTestUrlText", "Omnichannel Connect Test");
150
158
 
159
+ _defineProperty(Constants, "ChatWidgetStateChangedPrefix", "ChatWidgetStateChanged");
160
+
161
+ _defineProperty(Constants, "PostChatLoadingDurationInMs", 2000);
162
+
163
+ _defineProperty(Constants, "BrowserUnloadConfirmationMessage", "Do you want to leave chat?");
164
+
151
165
  export const Regex = (_class = class Regex {}, _defineProperty(_class, "EmailRegex", "(?:[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])"), _class);
152
166
  export class HtmlIdNames {}
153
167
 
@@ -257,6 +271,15 @@ export let ChatSDKError;
257
271
  ChatSDKError["WidgetUseOutsideOperatingHour"] = "WidgetUseOutsideOperatingHour";
258
272
  })(ChatSDKError || (ChatSDKError = {}));
259
273
 
274
+ export let EnvironmentVersion;
275
+
276
+ (function (EnvironmentVersion) {
277
+ EnvironmentVersion["prod"] = "prod";
278
+ EnvironmentVersion["dogfood"] = "df";
279
+ EnvironmentVersion["int"] = "int";
280
+ EnvironmentVersion["test"] = "test";
281
+ })(EnvironmentVersion || (EnvironmentVersion = {}));
282
+
260
283
  export class TranscriptConstants {}
261
284
 
262
285
  _defineProperty(TranscriptConstants, "ChatTranscriptsBodyColor", "#F5F5F5");
@@ -277,4 +300,22 @@ _defineProperty(TranscriptConstants, "InternalMode", "internal");
277
300
 
278
301
  _defineProperty(TranscriptConstants, "AgentDialogColor", "#2266E3");
279
302
 
280
- _defineProperty(TranscriptConstants, "AgentFontColor", "white");
303
+ _defineProperty(TranscriptConstants, "AgentFontColor", "white");
304
+
305
+ export class AriaTelemetryConstants {}
306
+
307
+ _defineProperty(AriaTelemetryConstants, "GERMANY_ENDPOINT", "https://de.pipe.aria.microsoft.com/Collector/3.0/");
308
+
309
+ _defineProperty(AriaTelemetryConstants, "GCCH_ENDPOINT", "https://tb.pipe.aria.microsoft.com/Collector/3.0/");
310
+
311
+ _defineProperty(AriaTelemetryConstants, "DOD_ENDPOINT", "https://pf.pipe.aria.microsoft.com/Collector/3.0");
312
+
313
+ _defineProperty(AriaTelemetryConstants, "EUROPE_ENDPOINT", "https://eu-mobile.events.data.microsoft.com/Collector/3.0/");
314
+
315
+ _defineProperty(AriaTelemetryConstants, "MOONCAKE_ENDPOINT", "");
316
+
317
+ _defineProperty(AriaTelemetryConstants, "Public", "Public");
318
+
319
+ _defineProperty(AriaTelemetryConstants, "EU", "Europe");
320
+
321
+ _defineProperty(AriaTelemetryConstants, "lcwEUDomainNames", ["crm4.omnichannelengagementhub.com", "crm12.omnichannelengagementhub.com", "crm16.omnichannelengagementhub.com", "crm17.omnichannelengagementhub.com", "crm19.omnichannelengagementhub.com"]);
@@ -0,0 +1,19 @@
1
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+
3
+ import { BroadcastService } from "@microsoft/omnichannel-chat-components";
4
+ import { getWidgetCacheId } from "../../utils";
5
+ import { defaultClientDataStoreProvider } from "./defaultClientDataStoreProvider";
6
+ export class defaultCacheManager {}
7
+
8
+ _defineProperty(defaultCacheManager, "InternalCache", {});
9
+
10
+ export const registerBroadcastServiceForLocalStorage = (orgid, widgetId, widgetInstanceId) => {
11
+ const widgetCacheId = getWidgetCacheId(orgid, widgetId, widgetInstanceId);
12
+ BroadcastService.getMessageByEventName(widgetCacheId).subscribe(msg => {
13
+ try {
14
+ defaultClientDataStoreProvider().setData(widgetCacheId, JSON.stringify(msg.payload), "localStorage");
15
+ } catch (error) {
16
+ console.error("Error in setting data to localstorage", error);
17
+ }
18
+ });
19
+ };
@@ -0,0 +1,102 @@
1
+ import { inMemoryDataStore } from "./defaultInMemoryDataStore";
2
+ import { TelemetryHelper } from "../../telemetry/TelemetryHelper";
3
+ import { LogLevel, TelemetryEvent } from "../../telemetry/TelemetryConstants";
4
+ export const defaultClientDataStoreProvider = () => {
5
+ const isCookieAllowed = () => {
6
+ try {
7
+ localStorage;
8
+ sessionStorage;
9
+ return true;
10
+ } catch (error) {
11
+ console.error("Third party cookie blocked");
12
+ return false;
13
+ }
14
+ };
15
+
16
+ const TtlInMs = 15 * 60 * 1000; // 15 mins
17
+
18
+ const dataStoreProvider = {
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ setData: (key, data, type) => {
21
+ if (isCookieAllowed()) {
22
+ try {
23
+ if (key) {
24
+ const now = new Date();
25
+ const item = {
26
+ data: data,
27
+ expiry: now.getTime() + TtlInMs
28
+ };
29
+ const strItem = JSON.stringify(item);
30
+
31
+ if (type === "localStorage") {
32
+ localStorage.setItem(key, strItem);
33
+ } else {
34
+ sessionStorage.setItem(key, strItem);
35
+ }
36
+ }
37
+ } catch (error) {
38
+ TelemetryHelper.logConfigDataEvent(LogLevel.ERROR, {
39
+ Event: TelemetryEvent.ClientDataStoreProviderFailed,
40
+ ExceptionDetails: error,
41
+ Description: "Unable to store data in localStorage."
42
+ });
43
+ }
44
+ } else {
45
+ const dataToCache = {
46
+ key: key,
47
+ data: data,
48
+ type: type
49
+ };
50
+ parent.postMessage(dataToCache, "*");
51
+ }
52
+ },
53
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
+ getData: (key, type) => {
55
+ if (isCookieAllowed()) {
56
+ let item;
57
+
58
+ if (type === "localStorage") {
59
+ item = localStorage.getItem(key);
60
+ } else {
61
+ item = sessionStorage.getItem(key);
62
+ } //Return item if not expired
63
+
64
+
65
+ let itemInJson = undefined;
66
+
67
+ if (item !== null) {
68
+ itemInJson = JSON.parse(item);
69
+ const now = new Date(); // compare the expiry time of the item with the current time
70
+
71
+ if (now.getTime() > itemInJson.expiry) {
72
+ // If the item is expired, delete the item from storage
73
+ // and return null
74
+ localStorage.removeItem(key);
75
+ return null;
76
+ }
77
+
78
+ return itemInJson.data;
79
+ }
80
+ } else {
81
+ // get data from in memory db when cookie is disabled
82
+ return inMemoryDataStore().getData(key);
83
+ }
84
+ },
85
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
86
+ removeData: (key, type) => {
87
+ if (isCookieAllowed()) {
88
+ if (key) {
89
+ if (type === "localStorage") {
90
+ return localStorage.removeItem(key);
91
+ } else {
92
+ return sessionStorage.removeItem(key);
93
+ }
94
+ }
95
+ } else {
96
+ // get data from in memory db when cookie is disabled
97
+ return inMemoryDataStore().removeData(key);
98
+ }
99
+ }
100
+ };
101
+ return dataStoreProvider;
102
+ };
@@ -0,0 +1,71 @@
1
+ import { LogLevel, TelemetryEvent } from "../../telemetry/TelemetryConstants";
2
+ import { TelemetryHelper } from "../../telemetry/TelemetryHelper";
3
+ import { defaultCacheManager } from "./defaultCacheManager";
4
+ export const defaultInitializeInMemoryDataStore = widgetId => {
5
+ try {
6
+ localStorage;
7
+ } catch (error) {
8
+ // Register below events when localStorage is not accessible
9
+ // Listening to event raised from client browser
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ window.addEventListener("message", function (e) {
12
+ try {
13
+ if (e.data.key) {
14
+ const browserData = e.data;
15
+
16
+ if (defaultCacheManager.InternalCache[browserData.key]) {
17
+ delete defaultCacheManager.InternalCache[browserData.key];
18
+ }
19
+
20
+ defaultCacheManager.InternalCache[browserData.key] = browserData.data;
21
+ }
22
+ } catch (error) {
23
+ TelemetryHelper.logConfigDataEvent(LogLevel.ERROR, {
24
+ Event: TelemetryEvent.InMemoryDataStoreFailed,
25
+ ExceptionDetails: error,
26
+ Description: "Unable to register default in-memory cache."
27
+ });
28
+ }
29
+ }); // send cache initialize message to client
30
+
31
+ if (defaultCacheManager.InternalCache === undefined || {}) {
32
+ parent.postMessage({
33
+ data: "cacheinitialize",
34
+ widgetId: widgetId
35
+ }, "*");
36
+ }
37
+ }
38
+ };
39
+ export const inMemoryDataStore = () => {
40
+ const dataStoreProvider = {
41
+ getData: key => {
42
+ if (defaultCacheManager.InternalCache && defaultCacheManager.InternalCache[key]) {
43
+ return defaultCacheManager.InternalCache[key];
44
+ }
45
+ },
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ setData: (key, data) => {
48
+ try {
49
+ defaultCacheManager.InternalCache[key] = data;
50
+ } catch (error) {
51
+ TelemetryHelper.logConfigDataEvent(LogLevel.ERROR, {
52
+ Event: TelemetryEvent.InMemoryDataStoreFailed,
53
+ ExceptionDetails: error,
54
+ Description: "Unable to set data in default in-memory cache."
55
+ });
56
+ }
57
+ },
58
+ removeData: key => {
59
+ try {
60
+ defaultCacheManager.InternalCache[key] = {};
61
+ } catch (error) {
62
+ TelemetryHelper.logConfigDataEvent(LogLevel.ERROR, {
63
+ Event: TelemetryEvent.InMemoryDataStoreFailed,
64
+ ExceptionDetails: error,
65
+ Description: "Unable to remove data from default in-memory cache."
66
+ });
67
+ }
68
+ }
69
+ };
70
+ return dataStoreProvider;
71
+ };