@microsoft/omnichannel-chat-widget 1.0.3-main.527b216 → 1.0.3-main.87088f3

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 (95) hide show
  1. package/lib/cjs/common/Constants.js +54 -1
  2. package/lib/cjs/common/storage/default/defaultCacheManager.js +7 -6
  3. package/lib/cjs/common/storage/default/defaultClientDataStoreProvider.js +9 -7
  4. package/lib/cjs/common/telemetry/TelemetryConstants.js +7 -1
  5. package/lib/cjs/common/utils.js +27 -5
  6. package/lib/cjs/components/chatbuttonstateful/ChatButtonStateful.js +1 -10
  7. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
  8. package/lib/cjs/components/footerstateful/FooterStateful.js +1 -1
  9. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +12 -1
  10. package/lib/cjs/components/headerstateful/HeaderStateful.js +14 -13
  11. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
  12. package/lib/cjs/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
  13. package/lib/cjs/components/livechatwidget/common/Deferred.js +2 -3
  14. package/lib/cjs/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -2
  15. package/lib/cjs/components/livechatwidget/common/endChat.js +197 -99
  16. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +32 -27
  17. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +11 -8
  18. package/lib/cjs/components/livechatwidget/common/renderSurveyHelpers.js +139 -0
  19. package/lib/cjs/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +2 -255
  20. package/lib/cjs/components/livechatwidget/common/startChat.js +85 -69
  21. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +162 -100
  22. package/lib/cjs/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
  23. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +18 -8
  24. package/lib/cjs/components/postchatsurveypanestateful/common/defaultStyleProps/defaultgeneralPostChatSurveyPaneStyleProps.js +1 -2
  25. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
  26. package/lib/cjs/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
  27. package/lib/cjs/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
  28. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
  29. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
  30. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
  31. package/lib/cjs/contexts/common/LiveChatWidgetActionType.js +2 -0
  32. package/lib/cjs/contexts/common/LiveChatWidgetContextInitialState.js +16 -13
  33. package/lib/cjs/contexts/createReducer.js +13 -23
  34. package/lib/cjs/controller/componentController.js +2 -1
  35. package/lib/cjs/index.js +20 -0
  36. package/lib/esm/common/Constants.js +49 -0
  37. package/lib/esm/common/storage/default/defaultCacheManager.js +5 -4
  38. package/lib/esm/common/storage/default/defaultClientDataStoreProvider.js +9 -7
  39. package/lib/esm/common/telemetry/TelemetryConstants.js +7 -1
  40. package/lib/esm/common/utils.js +25 -4
  41. package/lib/esm/components/chatbuttonstateful/ChatButtonStateful.js +4 -13
  42. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +8 -6
  43. package/lib/esm/components/footerstateful/FooterStateful.js +1 -1
  44. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +11 -1
  45. package/lib/esm/components/headerstateful/HeaderStateful.js +14 -13
  46. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/DefaultActivitySubscriber.js +1 -0
  47. package/lib/esm/components/livechatwidget/common/ActivitySubscriber/PauseActivitySubscriber.js +1 -0
  48. package/lib/esm/components/livechatwidget/common/Deferred.js +2 -3
  49. package/lib/esm/components/livechatwidget/common/defaultProps/dummyDefaultProps.js +9 -2
  50. package/lib/esm/components/livechatwidget/common/endChat.js +196 -99
  51. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +32 -27
  52. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +11 -8
  53. package/lib/esm/components/livechatwidget/common/renderSurveyHelpers.js +130 -0
  54. package/lib/esm/components/livechatwidget/common/setPostChatContextAndLoadSurvey.js +3 -255
  55. package/lib/esm/components/livechatwidget/common/startChat.js +86 -70
  56. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +164 -102
  57. package/lib/esm/components/loadingpanestateful/LoadingPaneStateful.js +2 -2
  58. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +18 -8
  59. package/lib/esm/components/postchatsurveypanestateful/common/defaultStyleProps/defaultgeneralPostChatSurveyPaneStyleProps.js +1 -2
  60. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +5 -4
  61. package/lib/esm/components/reconnectchatpanestateful/ReconnectChatPaneStateful.js +4 -1
  62. package/lib/esm/components/webchatcontainerstateful/common/mockchatsdk.js +6 -1
  63. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/WebChatStoreLoader.js +1 -0
  64. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/conversationEndMiddleware.js +8 -6
  65. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/webchattelemetry/WebChatLogger.js +7 -1
  66. package/lib/esm/contexts/common/LiveChatWidgetActionType.js +2 -0
  67. package/lib/esm/contexts/common/LiveChatWidgetContextInitialState.js +18 -15
  68. package/lib/esm/contexts/createReducer.js +13 -23
  69. package/lib/esm/controller/componentController.js +2 -1
  70. package/lib/esm/index.js +4 -1
  71. package/lib/types/common/Constants.d.ts +21 -0
  72. package/lib/types/common/interfaces/IContextDataStore.d.ts +3 -3
  73. package/lib/types/common/storage/default/defaultCacheManager.d.ts +2 -1
  74. package/lib/types/common/storage/default/defaultClientDataStoreProvider.d.ts +2 -1
  75. package/lib/types/common/telemetry/TelemetryConstants.d.ts +7 -1
  76. package/lib/types/common/utils.d.ts +3 -2
  77. package/lib/types/components/confirmationpanestateful/interfaces/IConfirmationPaneStatefulParams.d.ts +6 -0
  78. package/lib/types/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.d.ts +2 -1
  79. package/lib/types/components/livechatwidget/common/endChat.d.ts +4 -3
  80. package/lib/types/components/livechatwidget/common/initWebChatComposer.d.ts +1 -1
  81. package/lib/types/components/livechatwidget/common/renderSurveyHelpers.d.ts +9 -0
  82. package/lib/types/components/livechatwidget/common/setPostChatContextAndLoadSurvey.d.ts +1 -6
  83. package/lib/types/components/livechatwidget/interfaces/ILiveChatWidgetProps.d.ts +3 -1
  84. package/lib/types/components/webchatcontainerstateful/common/mockchatsdk.d.ts +4 -0
  85. package/lib/types/contexts/common/ILiveChatWidgetContext.d.ts +8 -7
  86. package/lib/types/contexts/common/LiveChatWidgetActionType.d.ts +3 -1
  87. package/lib/types/contexts/common/LiveChatWidgetContextInitialState.d.ts +2 -1
  88. package/lib/types/index.d.ts +3 -0
  89. package/package.json +2 -1
  90. package/lib/cjs/components/livechatwidget/common/agentEndConversationHelper.js +0 -36
  91. package/lib/cjs/contexts/common/ConversationEndEntity.js +0 -12
  92. package/lib/esm/components/livechatwidget/common/agentEndConversationHelper.js +0 -30
  93. package/lib/esm/contexts/common/ConversationEndEntity.js +0 -5
  94. package/lib/types/components/livechatwidget/common/agentEndConversationHelper.d.ts +0 -6
  95. package/lib/types/contexts/common/ConversationEndEntity.d.ts +0 -4
@@ -25,21 +25,26 @@ var _updateSessionDataForTelemetry = require("./updateSessionDataForTelemetry");
25
25
  let optionalParams = {};
26
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
27
  let widgetInstanceId;
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ let popoutWidgetInstanceId;
28
30
 
29
31
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
32
  const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) => {
31
- var _props$controlProps;
32
33
  optionalParams = {}; //Resetting to ensure no stale values
33
- widgetInstanceId = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.widgetInstanceId;
34
+ widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
34
35
 
35
36
  // reconnect > chat from cache
36
37
  await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
37
-
38
38
  // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
39
39
  if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
40
40
  return;
41
41
  }
42
42
 
43
+ // Check if there is any active popout chats in cache
44
+ if (await canStartPopoutChat(props)) {
45
+ return;
46
+ }
47
+
43
48
  // Can connect to existing chat session
44
49
  if (await canConnectToExistingChat(props, chatSDK, state, dispatch, setAdapter)) {
45
50
  return;
@@ -50,20 +55,13 @@ const prepareStartChat = async (props, chatSDK, state, dispatch, setAdapter) =>
50
55
  const isPreChatEnabledInProactiveChat = state.appStates.proactiveChatStates.proactiveChatEnablePrechat;
51
56
 
52
57
  //Setting PreChat and intiate chat
53
- setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, undefined, props);
58
+ await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, isProactiveChat, isPreChatEnabledInProactiveChat, undefined, props);
54
59
  };
55
60
 
56
61
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
62
  exports.prepareStartChat = prepareStartChat;
58
63
  const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProactiveChat, proactiveChatEnablePrechatState, state, props) => {
59
64
  //Handle reconnect scenario
60
- if (state) {
61
- await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, initStartChat, state);
62
- // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
63
- if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
64
- return;
65
- }
66
- }
67
65
 
68
66
  // Getting prechat Survey Context
69
67
  const parseToJson = false;
@@ -95,11 +93,11 @@ const setPreChatAndInitiateChat = async (chatSDK, dispatch, setAdapter, isProact
95
93
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
94
  exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
97
95
  const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persistedState) => {
98
- var _props$controlProps2;
96
+ var _props$controlProps;
99
97
  let isStartChatSuccessful = false;
100
98
  const chatConfig = props === null || props === void 0 ? void 0 : props.chatConfig;
101
99
  const getAuthToken = props === null || props === void 0 ? void 0 : props.getAuthToken;
102
- const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps2 = props.controlProps) === null || _props$controlProps2 === void 0 ? void 0 : _props$controlProps2.hideErrorUIPane;
100
+ const hideErrorUIPane = props === null || props === void 0 ? void 0 : (_props$controlProps = props.controlProps) === null || _props$controlProps === void 0 ? void 0 : _props$controlProps.hideErrorUIPane;
103
101
  try {
104
102
  var _newAdapter$activity$, _TelemetryTimers$Widg;
105
103
  //Start widget load timer
@@ -113,11 +111,8 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
113
111
  // set auth token to chat sdk before start chat
114
112
  const authSuccess = await (0, _authHelper.handleAuthentication)(chatSDK, chatConfig, getAuthToken);
115
113
  if (!authSuccess) {
116
- dispatch({
117
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
118
- payload: _ConversationState.ConversationState.Closed
119
- });
120
- return;
114
+ // Replacing with error ui
115
+ throw new Error("Authentication was not successful");
121
116
  }
122
117
  }
123
118
 
@@ -135,7 +130,7 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
135
130
  try {
136
131
  var _window$Microsoft, _window$Microsoft$Dyn, _window$Microsoft$Dyn2, _window$Microsoft$Dyn3;
137
132
  // Set custom context params
138
- setCustomContextParams(chatSDK);
133
+ setCustomContextParams(props);
139
134
  const defaultOptionalParams = {
140
135
  sendDefaultInitContext: true,
141
136
  isProactiveChat: !!(params !== null && params !== void 0 && params.isProactiveChat),
@@ -164,21 +159,6 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
164
159
  payload: chatToken
165
160
  });
166
161
  newAdapter === null || newAdapter === void 0 ? void 0 : (_newAdapter$activity$ = newAdapter.activity$) === null || _newAdapter$activity$ === void 0 ? void 0 : _newAdapter$activity$.subscribe((0, _newMessageEventHandler.createOnNewAdapterActivityHandler)(chatToken === null || chatToken === void 0 ? void 0 : chatToken.chatId, chatToken === null || chatToken === void 0 ? void 0 : chatToken.visitorId));
167
- if (persistedState) {
168
- dispatch({
169
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
170
- payload: persistedState
171
- });
172
- (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
173
- return;
174
- }
175
-
176
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
177
- const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
178
- dispatch({
179
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
180
- payload: liveChatContext
181
- });
182
162
 
183
163
  // Set app state to Active
184
164
  if (isStartChatSuccessful) {
@@ -193,14 +173,30 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
193
173
  payload: _ConversationState.ConversationState.Active
194
174
  });
195
175
  }
176
+ if (persistedState) {
177
+ dispatch({
178
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_WIDGET_STATE,
179
+ payload: persistedState
180
+ });
181
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch, true);
182
+ return;
183
+ }
184
+
185
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
+ const liveChatContext = await (chatSDK === null || chatSDK === void 0 ? void 0 : chatSDK.getCurrentLiveChatContext());
187
+ dispatch({
188
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
189
+ payload: liveChatContext
190
+ });
196
191
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
197
192
  Event: _TelemetryConstants.TelemetryEvent.WidgetLoadComplete,
198
193
  Description: "Widget load complete",
199
194
  ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg === void 0 ? void 0 : _TelemetryTimers$Widg.milliSecondsElapsed
200
195
  });
201
196
 
202
- // Set post chat context in state, no survey load
203
- (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
197
+ // Set post chat context in state
198
+ // Commenting this for now as post chat context is fetched during end chat
199
+ await (0, _setPostChatContextAndLoadSurvey.setPostChatContextAndLoadSurvey)(chatSDK, dispatch);
204
200
 
205
201
  // Updating chat session detail for telemetry
206
202
  await (0, _updateSessionDataForTelemetry.updateSessionDataForTelemetry)(chatSDK, dispatch);
@@ -224,12 +220,12 @@ const initStartChat = async (chatSDK, dispatch, setAdapter, props, params, persi
224
220
  });
225
221
  return;
226
222
  }
223
+ dispatch({
224
+ type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
225
+ payload: true
226
+ });
227
227
  if (!hideErrorUIPane) {
228
228
  // Set app state to failing start chat if hideErrorUI is not turned on
229
- dispatch({
230
- type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_START_CHAT_FAILING,
231
- payload: true
232
- });
233
229
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
234
230
  Event: _TelemetryConstants.TelemetryEvent.ErrorUIPaneLoaded,
235
231
  Description: "Error UI Pane Loaded"
@@ -266,15 +262,15 @@ const forceEndChat = async chatSDK => {
266
262
 
267
263
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
268
264
  const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdapter) => {
269
- var _chatSDK$omnichannelC, _chatSDK$omnichannelC2, _props$controlProps3, _persistedState$domai6;
265
+ var _state$appStates, _persistedState$domai6, _persistedState$appSt;
270
266
  // By pass this function in case of popout chat
271
- if (state.appStates.hideStartChatButton === true) {
267
+ if ((state === null || state === void 0 ? void 0 : (_state$appStates = state.appStates) === null || _state$appStates === void 0 ? void 0 : _state$appStates.hideStartChatButton) === true) {
272
268
  return false;
273
269
  }
274
- const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC === void 0 ? void 0 : _chatSDK$omnichannelC.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC2 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC2 === void 0 ? void 0 : _chatSDK$omnichannelC2.widgetId, (props === null || props === void 0 ? void 0 : (_props$controlProps3 = props.controlProps) === null || _props$controlProps3 === void 0 ? void 0 : _props$controlProps3.widgetInstanceId) ?? "");
270
+ const persistedState = (0, _utils.getStateFromCache)((0, _utils.getWidgetCacheIdfromProps)(props));
275
271
 
276
272
  //Connect to only active chat session
277
- if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext)) {
273
+ if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai6 = persistedState.domainStates) === null || _persistedState$domai6 === void 0 ? void 0 : _persistedState$domai6.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt = persistedState.appStates) === null || _persistedState$appSt === void 0 ? void 0 : _persistedState$appSt.conversationState) === _ConversationState.ConversationState.Active) {
278
274
  var _persistedState$domai7;
279
275
  dispatch({
280
276
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_CONVERSATION_STATE,
@@ -285,52 +281,72 @@ const canConnectToExistingChat = async (props, chatSDK, state, dispatch, setAdap
285
281
  };
286
282
  await initStartChat(chatSDK, dispatch, setAdapter, props, optionalParams, persistedState);
287
283
  return true;
288
- } else {
289
- return false;
290
284
  }
285
+ return false;
291
286
  };
292
287
 
293
288
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
294
- const setCustomContextParams = chatSDK => {
295
- var _chatSDK$omnichannelC3, _chatSDK$omnichannelC4, _persistedState$domai8;
289
+ const setCustomContextParams = props => {
290
+ var _props$chatConfig, _props$chatConfig$Liv, _persistedState$domai8;
291
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
+ const isAuthenticatedChat = props !== null && props !== void 0 && (_props$chatConfig = props.chatConfig) !== null && _props$chatConfig !== void 0 && (_props$chatConfig$Liv = _props$chatConfig.LiveChatConfigAuthSettings) !== null && _props$chatConfig$Liv !== void 0 && _props$chatConfig$Liv.msdyn_javascriptclientfunction ? true : false;
293
+ //Should not set custom context for auth chat
294
+ if (isAuthenticatedChat) {
295
+ return;
296
+ }
297
+ if ((0, _utils.isNullOrEmptyString)(widgetInstanceId)) {
298
+ widgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props);
299
+ }
296
300
  // Add custom context only for unauthenticated chat
297
- const persistedState = (0, _utils.getStateFromCache)(chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC3 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC3 === void 0 ? void 0 : _chatSDK$omnichannelC3.orgId, chatSDK === null || chatSDK === void 0 ? void 0 : (_chatSDK$omnichannelC4 = chatSDK.omnichannelConfig) === null || _chatSDK$omnichannelC4 === void 0 ? void 0 : _chatSDK$omnichannelC4.widgetId, widgetInstanceId ?? "");
301
+ const persistedState = (0, _utils.getStateFromCache)(widgetInstanceId);
298
302
  if (!(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai8 = persistedState.domainStates) === null || _persistedState$domai8 === void 0 ? void 0 : _persistedState$domai8.customContext)) {
299
- var _persistedState$domai9, _persistedState$domai10;
300
- if (persistedState !== null && persistedState !== void 0 && (_persistedState$domai9 = persistedState.domainStates.liveChatConfig) !== null && _persistedState$domai9 !== void 0 && _persistedState$domai9.LiveChatConfigAuthSettings) {
301
- const errorMessage = "Use of custom context with authenticated chat is deprecated. The chat would not go through.";
302
- _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.WARN, {
303
- Event: _TelemetryConstants.TelemetryEvent.StartChatMethodException,
304
- ExceptionDetails: {
305
- exception: errorMessage
306
- }
307
- });
308
- throw new Error(errorMessage);
309
- }
303
+ var _persistedState$domai9;
304
+ _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
305
+ Event: _TelemetryConstants.TelemetryEvent.SetCustomContext,
306
+ Description: "Setting custom context for unauthenicated chat"
307
+ });
310
308
  optionalParams = Object.assign({}, optionalParams, {
311
- customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.customContext
309
+ customContext: persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai9 = persistedState.domainStates) === null || _persistedState$domai9 === void 0 ? void 0 : _persistedState$domai9.customContext
312
310
  });
313
311
  }
314
312
  };
313
+ const canStartPopoutChat = async props => {
314
+ if (props.allowSdkChatSupport === false) {
315
+ return false;
316
+ }
317
+ popoutWidgetInstanceId = (0, _utils.getWidgetCacheIdfromProps)(props, true);
318
+ if (!(0, _utils.isNullOrEmptyString)(popoutWidgetInstanceId)) {
319
+ var _persistedState$domai10, _persistedState$appSt2;
320
+ const persistedState = (0, _utils.getStateFromCache)(popoutWidgetInstanceId);
321
+ if (persistedState && !(0, _utils.isUndefinedOrEmpty)(persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$domai10 = persistedState.domainStates) === null || _persistedState$domai10 === void 0 ? void 0 : _persistedState$domai10.liveChatContext) && (persistedState === null || persistedState === void 0 ? void 0 : (_persistedState$appSt2 = persistedState.appStates) === null || _persistedState$appSt2 === void 0 ? void 0 : _persistedState$appSt2.conversationState) === _ConversationState.ConversationState.Active) {
322
+ // Initiate popout chat
323
+ _omnichannelChatComponents.BroadcastService.postMessage({
324
+ eventName: _TelemetryConstants.BroadcastEvent.InitiateStartChatInPopoutMode
325
+ });
326
+ return true;
327
+ }
328
+ }
329
+ return false;
330
+ };
315
331
 
316
332
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
333
  const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
318
334
  var _state$domainStates, _state$domainStates$l;
319
- const requestId = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
335
+ const requestIdFromCache = (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatContext) === null || _state$domainStates$l === void 0 ? void 0 : _state$domainStates$l.requestId;
320
336
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
337
  let conversationDetails = undefined;
322
338
 
323
- //Preserve old requestId
324
- const oldRequestId = chatSDK.requestId ?? "";
339
+ //Preserve current requestId
340
+ const currentRequestId = chatSDK.requestId ?? "";
325
341
  dispatch({
326
342
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_INITIAL_CHAT_SDK_REQUEST_ID,
327
- payload: oldRequestId
343
+ payload: currentRequestId
328
344
  });
329
345
  try {
330
- chatSDK.requestId = requestId;
346
+ chatSDK.requestId = requestIdFromCache;
331
347
  conversationDetails = await chatSDK.getConversationDetails();
332
348
  if (Object.keys(conversationDetails).length === 0) {
333
- chatSDK.requestId = oldRequestId;
349
+ chatSDK.requestId = currentRequestId;
334
350
  return false;
335
351
  }
336
352
  if (conversationDetails.state === _Constants.LiveWorkItemState.Closed || conversationDetails.state === _Constants.LiveWorkItemState.WrapUp) {
@@ -338,7 +354,7 @@ const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
338
354
  type: _LiveChatWidgetActionType.LiveChatWidgetActionType.SET_LIVE_CHAT_CONTEXT,
339
355
  payload: undefined
340
356
  });
341
- chatSDK.requestId = oldRequestId;
357
+ chatSDK.requestId = currentRequestId;
342
358
  return false;
343
359
  }
344
360
  return true;
@@ -349,7 +365,7 @@ const checkIfConversationStillValid = async (chatSDK, dispatch, state) => {
349
365
  exception: `Conversation is not valid: ${erorr}`
350
366
  }
351
367
  });
352
- chatSDK.requestId = oldRequestId;
368
+ chatSDK.requestId = currentRequestId;
353
369
  return false;
354
370
  }
355
371
  };