@microsoft/omnichannel-chat-widget 1.8.1-main.20b15cc → 1.8.1-main.3ee330c

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 (47) hide show
  1. package/lib/cjs/common/facades/FacadeChatSDK.js +42 -0
  2. package/lib/cjs/common/telemetry/TelemetryConstants.js +4 -0
  3. package/lib/cjs/common/telemetry/TelemetryManager.js +4 -4
  4. package/lib/cjs/common/telemetry/loggers/appInsightsLogger.js +4 -5
  5. package/lib/cjs/common/utils/xssUtils.js +79 -0
  6. package/lib/cjs/common/utils.js +3 -0
  7. package/lib/cjs/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -3
  8. package/lib/cjs/components/errorboundary/ErrorBoundary.js +68 -0
  9. package/lib/cjs/components/livechatwidget/LiveChatWidget.js +15 -4
  10. package/lib/cjs/components/livechatwidget/common/liveChatConfigUtils.js +1 -1
  11. package/lib/cjs/components/livechatwidget/common/persistentChatHelper.js +12 -5
  12. package/lib/cjs/components/livechatwidget/common/reconnectChatHelper.js +4 -0
  13. package/lib/cjs/components/livechatwidget/common/startChat.js +3 -9
  14. package/lib/cjs/components/livechatwidget/common/startChatErrorHandler.js +30 -1
  15. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +31 -19
  16. package/lib/cjs/components/ooohpanestateful/OOOHPaneStateful.js +23 -2
  17. package/lib/cjs/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +14 -5
  18. package/lib/cjs/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.js +1 -0
  19. package/lib/esm/common/facades/FacadeChatSDK.js +42 -0
  20. package/lib/esm/common/telemetry/TelemetryConstants.js +4 -0
  21. package/lib/esm/common/telemetry/TelemetryManager.js +4 -4
  22. package/lib/esm/common/telemetry/loggers/appInsightsLogger.js +4 -5
  23. package/lib/esm/common/utils/xssUtils.js +72 -0
  24. package/lib/esm/common/utils.js +3 -0
  25. package/lib/esm/components/confirmationpanestateful/ConfirmationPaneStateful.js +7 -3
  26. package/lib/esm/components/errorboundary/ErrorBoundary.js +59 -0
  27. package/lib/esm/components/livechatwidget/LiveChatWidget.js +16 -5
  28. package/lib/esm/components/livechatwidget/common/liveChatConfigUtils.js +1 -1
  29. package/lib/esm/components/livechatwidget/common/persistentChatHelper.js +12 -5
  30. package/lib/esm/components/livechatwidget/common/reconnectChatHelper.js +4 -0
  31. package/lib/esm/components/livechatwidget/common/startChat.js +3 -9
  32. package/lib/esm/components/livechatwidget/common/startChatErrorHandler.js +28 -0
  33. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +31 -19
  34. package/lib/esm/components/ooohpanestateful/OOOHPaneStateful.js +23 -2
  35. package/lib/esm/components/postchatsurveypanestateful/PostChatSurveyPaneStateful.js +14 -5
  36. package/lib/esm/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.js +1 -0
  37. package/lib/types/common/facades/FacadeChatSDK.d.ts +1 -0
  38. package/lib/types/common/telemetry/TelemetryConstants.d.ts +4 -0
  39. package/lib/types/common/telemetry/loggers/appInsightsLogger.d.ts +1 -1
  40. package/lib/types/common/utils/xssUtils.d.ts +29 -0
  41. package/lib/types/components/errorboundary/ErrorBoundary.d.ts +14 -0
  42. package/lib/types/components/livechatwidget/common/liveChatConfigUtils.d.ts +1 -1
  43. package/lib/types/components/livechatwidget/common/persistentChatHelper.d.ts +2 -1
  44. package/lib/types/components/livechatwidget/common/startChatErrorHandler.d.ts +1 -0
  45. package/lib/types/components/postchatsurveypanestateful/enums/CustomerVoiceEvents.d.ts +2 -1
  46. package/lib/types/components/postchatsurveypanestateful/interfaces/IPostChatSurveyPaneStatefulProps.d.ts +1 -0
  47. package/package.json +2 -2
@@ -445,6 +445,48 @@ let FacadeChatSDK = /*#__PURE__*/function () {
445
445
  let optionalParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
446
446
  return this.validateAndExecuteCall("getAgentAvailability", () => this.chatSDK.getAgentAvailability(optionalParams));
447
447
  }
448
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
449
+ }, {
450
+ key: "getReconnectableChats",
451
+ value: async function getReconnectableChats() {
452
+ let reconnectableChatsParams = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
453
+ /**
454
+ *
455
+ * This is a particular case, we dont expose getReconnectableChats in the SDK,
456
+ * The only way to use is by tunneling directly from the SDK to OCSDK,
457
+ *
458
+ * In case of prechat, the function is called before any formal authentication is made,
459
+ * this is an specific case for persistent chats, to prevent the survey be loaded again for an on going chat,
460
+ *
461
+ * In this case, we check for existance of the token , otherwise we perform the authentication, error is propagated in case of issues.
462
+ *
463
+ * Once the token is obtained , this will be added to the params to call the function.
464
+ *
465
+ * This is a particular case, should not be taken as pattern.
466
+ *
467
+ */
468
+
469
+ if (this.token === null || this.token === "") {
470
+ // If token is not set, try to get it using tokenRing
471
+ const pingResponse = await this.tokenRing();
472
+ if (pingResponse.result === false) {
473
+ const errorMessage = `Authentication failed: Process to get a token failed for getReconnectableChats, ${pingResponse.message}`;
474
+ //telemetry is already logged in tokenRing, so no need to log again, just return the error and communicate to the console
475
+ console.error(errorMessage);
476
+ _omnichannelChatComponents.BroadcastService.postMessage({
477
+ eventName: _TelemetryConstants.BroadcastEvent.OnWidgetError,
478
+ payload: {
479
+ errorMessage: errorMessage
480
+ }
481
+ });
482
+ throw new Error(errorMessage);
483
+ }
484
+ }
485
+
486
+ // Always override the token in params regardless of how getReconnectableChats was called
487
+ reconnectableChatsParams.authenticatedUserToken = this.token;
488
+ return this.validateAndExecuteCall("getReconnectableChats", () => this.chatSDK.OCClient.getReconnectableChats(reconnectableChatsParams));
489
+ }
448
490
  }]);
449
491
  return FacadeChatSDK;
450
492
  }();
@@ -112,6 +112,8 @@ exports.TelemetryEvent = TelemetryEvent;
112
112
  TelemetryEvent["DisconnectEndChatSDKCallFailed"] = "DisconnectEndChatSDKCallFailed";
113
113
  TelemetryEvent["GetChatReconnectContextSDKCallStarted"] = "GetChatReconnectContextSDKCallStarted";
114
114
  TelemetryEvent["GetChatReconnectContextSDKCallFailed"] = "GetChatReconnectContextSDKCallFailed";
115
+ TelemetryEvent["CheckContactIdError"] = "checkContactIdError";
116
+ TelemetryEvent["GetChatReconnectContextSDKCallSucceeded"] = "GetChatReconnectContextSDKCallSucceeded";
115
117
  TelemetryEvent["ParseAdaptiveCardFailed"] = "ParseAdaptiveCardFailed";
116
118
  TelemetryEvent["ClientDataStoreProviderFailed"] = "ClientDataStoreProviderFailed";
117
119
  TelemetryEvent["InMemoryDataStoreFailed"] = "InMemoryDataStoreFailed";
@@ -179,6 +181,7 @@ exports.TelemetryEvent = TelemetryEvent;
179
181
  TelemetryEvent["CustomerVoiceResponsePageLoaded"] = "CustomerVoiceResponsePageLoaded";
180
182
  TelemetryEvent["CustomerVoiceFormResponseSubmitted"] = "CustomerVoiceFormResponseSubmitted";
181
183
  TelemetryEvent["CustomerVoiceFormResponseError"] = "CustomerVoiceFormResponseError";
184
+ TelemetryEvent["CustomerVoiceFormsError"] = "CustomerVoiceFormsError";
182
185
  TelemetryEvent["BotAuthActivityEmptySasUrl"] = "BotAuthActivityEmptySasUrl";
183
186
  TelemetryEvent["SetBotAuthProviderFetchConfig"] = "SetBotAuthProviderFetchConfig";
184
187
  TelemetryEvent["SetBotAuthProviderHideCard"] = "SetBotAuthProviderHideCard";
@@ -256,6 +259,7 @@ exports.TelemetryEvent = TelemetryEvent;
256
259
  TelemetryEvent["UXNotificationPaneCompleted"] = "UXNotificationPaneCompleted";
257
260
  TelemetryEvent["UXOutOfOfficeHoursPaneStart"] = "UXOutOfOfficeHoursPaneStart";
258
261
  TelemetryEvent["UXOutOfOfficeHoursPaneCompleted"] = "UXOutOfOfficeHoursPaneCompleted";
262
+ TelemetryEvent["XSSTextDetected"] = "XSSTextDetected";
259
263
  TelemetryEvent["UXPostChatLoadingPaneStart"] = "UXPostChatLoadingPaneStart";
260
264
  TelemetryEvent["UXPostChatLoadingPaneCompleted"] = "UXPostChatLoadingPaneCompleted";
261
265
  TelemetryEvent["UXPrechatPaneStart"] = "UXPrechatPaneStart";
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.disposeLoggers = exports.TelemetryTimers = exports.TelemetryManager = exports.RegisterLoggers = void 0;
7
7
  var _TelemetryConstants = require("./TelemetryConstants");
8
8
  var _omnichannelChatComponents = require("@microsoft/omnichannel-chat-components");
9
+ var _TelemetryHelper = require("./TelemetryHelper");
10
+ var _appInsightsLogger = require("./loggers/appInsightsLogger");
9
11
  var _ariaTelemetryLogger = require("./loggers/ariaTelemetryLogger");
10
12
  var _consoleLogger = require("./loggers/consoleLogger");
11
13
  var _defaultAriaConfig = require("./defaultConfigs/defaultAriaConfig");
12
- var _TelemetryHelper = require("./TelemetryHelper");
13
- var _appInsightsLogger = require("./loggers/appInsightsLogger");
14
14
  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); } }
15
15
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
16
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -64,8 +64,8 @@ const RegisterLoggers = () => {
64
64
  if (((_TelemetryManager$Int22 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int22 === void 0 ? void 0 : (_TelemetryManager$Int23 = _TelemetryManager$Int22.appInsightsConfig) === null || _TelemetryManager$Int23 === void 0 ? void 0 : _TelemetryManager$Int23.appInsightsDisabled) === false) {
65
65
  var _TelemetryManager$Int24;
66
66
  if ((_TelemetryManager$Int24 = TelemetryManager.InternalTelemetryData) !== null && _TelemetryManager$Int24 !== void 0 && _TelemetryManager$Int24.appInsightsConfig.appInsightsKey) {
67
- var _TelemetryManager$Int25, _TelemetryManager$Int26, _TelemetryManager$Int27;
68
- loggers.push((0, _appInsightsLogger.appInsightsLogger)((_TelemetryManager$Int25 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int25 === void 0 ? void 0 : _TelemetryManager$Int25.appInsightsConfig.appInsightsKey, ((_TelemetryManager$Int26 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int26 === void 0 ? void 0 : (_TelemetryManager$Int27 = _TelemetryManager$Int26.ariaConfig) === null || _TelemetryManager$Int27 === void 0 ? void 0 : _TelemetryManager$Int27.disableCookieUsage) ?? _defaultAriaConfig.defaultAriaConfig.disableCookieUsage));
67
+ var _TelemetryManager$Int25;
68
+ loggers.push((0, _appInsightsLogger.appInsightsLogger)((_TelemetryManager$Int25 = TelemetryManager.InternalTelemetryData) === null || _TelemetryManager$Int25 === void 0 ? void 0 : _TelemetryManager$Int25.appInsightsConfig.appInsightsKey));
69
69
  }
70
70
  }
71
71
  }
@@ -25,14 +25,14 @@ var AllowedKeys;
25
25
  AllowedKeys["ElapsedTimeInMilliseconds"] = "DurationInMilliseconds";
26
26
  })(AllowedKeys || (AllowedKeys = {}));
27
27
  let initializationPromise = null;
28
- const appInsightsLogger = (appInsightsKey, disableCookiesUsage) => {
28
+ const appInsightsLogger = appInsightsKey => {
29
29
  const isValidKey = key => {
30
30
  const INSTRUMENTATION_KEY_PATTERN = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
31
31
  const INSTRUMENTATION_KEY_REGEX = new RegExp(`^${INSTRUMENTATION_KEY_PATTERN}$`);
32
32
  const CONNECTION_STRING_REGEX = new RegExp(`^InstrumentationKey=${INSTRUMENTATION_KEY_PATTERN};IngestionEndpoint=https://[a-zA-Z0-9\\-\\.]+\\.applicationinsights\\.azure\\.com/.*`);
33
33
  return INSTRUMENTATION_KEY_REGEX.test(key) || CONNECTION_STRING_REGEX.test(key);
34
34
  };
35
- const initializeAppInsights = async (appInsightsKey, disableCookiesUsage) => {
35
+ const initializeAppInsights = async appInsightsKey => {
36
36
  if (!window.appInsights && appInsightsKey) {
37
37
  if (!isValidKey(appInsightsKey)) {
38
38
  _TelemetryHelper.TelemetryHelper.logActionEvent(_TelemetryConstants.LogLevel.ERROR, {
@@ -54,8 +54,7 @@ const appInsightsLogger = (appInsightsKey, disableCookiesUsage) => {
54
54
  connectionString: appInsightsKey
55
55
  } : {
56
56
  instrumentationKey: appInsightsKey
57
- }),
58
- disableCookiesUsage: disableCookiesUsage
57
+ })
59
58
  };
60
59
 
61
60
  // Initialize Application Insights instance
@@ -82,7 +81,7 @@ const appInsightsLogger = (appInsightsKey, disableCookiesUsage) => {
82
81
  };
83
82
  const logger = async () => {
84
83
  if (!initializationPromise) {
85
- initializationPromise = initializeAppInsights(appInsightsKey, disableCookiesUsage);
84
+ initializationPromise = initializeAppInsights(appInsightsKey);
86
85
  }
87
86
  await initializationPromise;
88
87
  return window.appInsights;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.detectAndCleanXSS = void 0;
7
+ var _dompurify = _interopRequireDefault(require("dompurify"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ /**
10
+ * Detects potential Cross-Site Scripting (XSS) attacks in text input and sanitizes the content.
11
+ *
12
+ * This function performs comprehensive XSS detection using pattern matching for common attack vectors
13
+ * and then sanitizes the input using DOMPurify with strict configuration. It's designed to protect
14
+ * against various XSS techniques including script injection, event handler injection, style-based
15
+ * attacks, and encoded payloads.
16
+ *
17
+ * Security patterns detected:
18
+ * - JavaScript protocol URLs (javascript:)
19
+ * - HTML event handlers (onmouseover, onclick, etc.)
20
+ * - Script tags (<script>)
21
+ * - CSS expression() functions
22
+ * - CSS url() functions
23
+ * - Position-based CSS attacks (position: fixed/absolute)
24
+ * - VBScript protocol URLs
25
+ * - Data URLs with HTML content
26
+ * - Fragment identifiers with escaped quotes
27
+ * - HTML entity-encoded angle brackets
28
+ *
29
+ * @param text - The input text to be analyzed and sanitized
30
+ * @returns An object containing:
31
+ * - cleanText: The sanitized version of the input text with all HTML tags and attributes removed
32
+ * - isXSSDetected: Boolean flag indicating whether potential XSS patterns were found in the original text
33
+ */
34
+ const detectAndCleanXSS = text => {
35
+ // Comprehensive array of regular expressions to detect common XSS attack patterns
36
+ const xssPatterns = [/javascript\s*:/gi,
37
+ // JavaScript protocol URLs (with optional spaces)
38
+ /vbscript\s*:/gi,
39
+ // VBScript protocol URLs (with optional spaces)
40
+ /on\w+\s*=/gi,
41
+ // HTML event handlers (onmouseover, onclick, onload, etc.)
42
+ /<\s*script/gi,
43
+ // Script tag opening (with optional spaces)
44
+ /expression\s*\(/gi,
45
+ // CSS expression() function (IE-specific)
46
+ /url\s*\(/gi,
47
+ // CSS url() function
48
+ /style\s*=.*position\s*:\s*fixed/gi,
49
+ // CSS position fixed attacks
50
+ /style\s*=.*position\s*:\s*absolute/gi,
51
+ // CSS position absolute attacks
52
+ /data\s*:\s*text\s*\/\s*html/gi,
53
+ // Data URLs containing HTML
54
+ /#.*\\"/gi,
55
+ // Fragment identifiers with escaped quotes
56
+ /&gt;.*&lt;/gi // HTML entity-encoded angle brackets indicating tag structure
57
+ ];
58
+
59
+ // Check if any XSS patterns are detected in the input text
60
+ const isXSSDetected = xssPatterns.some(pattern => pattern.test(text));
61
+
62
+ // Clean the text using DOMPurify with strict config
63
+ const cleanText = _dompurify.default.sanitize(text, {
64
+ ALLOWED_TAGS: [],
65
+ // No HTML tags allowed in title
66
+ ALLOWED_ATTR: [],
67
+ KEEP_CONTENT: true,
68
+ // Keep text content
69
+ ALLOW_DATA_ATTR: false,
70
+ ALLOW_UNKNOWN_PROTOCOLS: false,
71
+ SANITIZE_DOM: true,
72
+ FORCE_BODY: false
73
+ });
74
+ return {
75
+ cleanText,
76
+ isXSSDetected
77
+ };
78
+ };
79
+ exports.detectAndCleanXSS = detectAndCleanXSS;
@@ -421,6 +421,9 @@ const getConversationDetailsCall = async function (facadeChatSDK) {
421
421
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
422
422
  exports.getConversationDetailsCall = getConversationDetailsCall;
423
423
  const checkContactIdError = e => {
424
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.ERROR, {
425
+ Event: _TelemetryConstants.TelemetryEvent.CheckContactIdError
426
+ });
424
427
  if ((e === null || e === void 0 ? void 0 : e.message) === _omnichannelChatSdk.ChatSDKErrorName.AuthContactIdNotFoundFailure) {
425
428
  const contactIdNotFoundErrorEvent = {
426
429
  eventName: _TelemetryConstants.BroadcastEvent.ContactIdNotFound,
@@ -84,9 +84,13 @@ const ConfirmationPaneStateful = props => {
84
84
  (0, _react.useEffect)(() => {
85
85
  (0, _utils.preventFocusToMoveOutOfElement)(controlProps.id);
86
86
  const focusableElements = (0, _utils.findAllFocusableElement)(`#${controlProps.id}`);
87
- if (focusableElements) {
88
- focusableElements[0].focus();
89
- }
87
+ requestAnimationFrame(() => {
88
+ if (focusableElements && focusableElements.length > 0 && focusableElements[0]) {
89
+ focusableElements[0].focus({
90
+ preventScroll: true
91
+ });
92
+ }
93
+ });
90
94
  elements = (0, _utils.findParentFocusableElementsWithoutChildContainer)(controlProps.id);
91
95
  (0, _utils.setTabIndices)(elements, initialTabIndexMap, false);
92
96
  _TelemetryHelper.TelemetryHelper.logLoadingEvent(_TelemetryConstants.LogLevel.INFO, {
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
+ 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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
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
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
16
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
17
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
18
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
19
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
20
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
21
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
22
+ const RenderChildrenFunction = _ref => {
23
+ let {
24
+ children
25
+ } = _ref;
26
+ return typeof children === 'function' ? children() : children;
27
+ };
28
+ let ErrorBoundary = /*#__PURE__*/function (_Component) {
29
+ _inherits(ErrorBoundary, _Component);
30
+ var _super = _createSuper(ErrorBoundary);
31
+ function ErrorBoundary(props) {
32
+ var _this;
33
+ _classCallCheck(this, ErrorBoundary);
34
+ _this = _super.call(this, props);
35
+ _this.state = {
36
+ hasError: false
37
+ };
38
+ return _this;
39
+ }
40
+ _createClass(ErrorBoundary, [{
41
+ key: "componentDidCatch",
42
+ value: function componentDidCatch(error) {
43
+ const {
44
+ onError
45
+ } = this.props;
46
+ this.setState({
47
+ hasError: true
48
+ });
49
+ if (onError) {
50
+ onError(error);
51
+ }
52
+ }
53
+ }, {
54
+ key: "render",
55
+ value: function render() {
56
+ const {
57
+ children
58
+ } = this.props;
59
+ const {
60
+ hasError
61
+ } = this.state;
62
+ return !hasError && /*#__PURE__*/_react.default.createElement(RenderChildrenFunction, null, children);
63
+ }
64
+ }]);
65
+ return ErrorBoundary;
66
+ }(_react.Component);
67
+ var _default = ErrorBoundary;
68
+ exports.default = _default;
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
8
8
  var _ChatAdapterStore = require("../../contexts/ChatAdapterStore");
9
9
  var _ChatContextStore = require("../../contexts/ChatContextStore");
10
10
  var _ChatSDKStore = require("../../contexts/ChatSDKStore");
11
+ var _ErrorBoundary = _interopRequireDefault(require("../errorboundary/ErrorBoundary"));
11
12
  var _FacadeChatSDK = require("../../common/facades/FacadeChatSDK");
12
13
  var _FacadeChatSDKStore = require("../../contexts/FacadeChatSDKStore");
13
14
  var _LiveChatWidgetStateful = _interopRequireDefault(require("./livechatwidgetstateful/LiveChatWidgetStateful"));
@@ -15,12 +16,15 @@ var _createReducer = require("../../contexts/createReducer");
15
16
  var _LiveChatWidgetContextInitialState = require("../../contexts/common/LiveChatWidgetContextInitialState");
16
17
  var _getMockChatSDKIfApplicable = require("./common/getMockChatSDKIfApplicable");
17
18
  var _utils = require("../../common/utils");
19
+ var _liveChatConfigUtils = require("./common/liveChatConfigUtils");
20
+ var _startChatErrorHandler = require("./common/startChatErrorHandler");
18
21
  var _overridePropsOnMockIfApplicable = _interopRequireDefault(require("./common/overridePropsOnMockIfApplicable"));
22
+ var _registerTelemetryLoggers = require("./common/registerTelemetryLoggers");
19
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
24
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
21
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
22
26
  const LiveChatWidget = props => {
23
- var _props$mock, _props$featureConfigP, _props$chatConfig, _props$chatConfig$Liv;
27
+ var _props$mock, _props$featureConfigP, _props$chatConfig, _props$chatConfig$Liv, _props$chatConfig2, _props$chatConfig2$Li;
24
28
  const reducer = (0, _createReducer.createReducer)();
25
29
  const [state, dispatch] = (0, _react.useReducer)(reducer, (0, _LiveChatWidgetContextInitialState.getLiveChatWidgetContextInitialState)(props));
26
30
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -34,7 +38,7 @@ const LiveChatWidget = props => {
34
38
  }
35
39
 
36
40
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
- const isAuthenticatedChat = !!((_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);
41
+ const isAuthenticatedChat = !!((_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) || (0, _liveChatConfigUtils.isPersistentChatEnabled)((_props$chatConfig2 = props.chatConfig) === null || _props$chatConfig2 === void 0 ? void 0 : (_props$chatConfig2$Li = _props$chatConfig2.LiveWSAndLiveChatEngJoin) === null || _props$chatConfig2$Li === void 0 ? void 0 : _props$chatConfig2$Li.msdyn_conversationmode);
38
42
  if (!facadeChatSDK) {
39
43
  var _props$mock2;
40
44
  setFacadeChatSDK(new _FacadeChatSDK.FacadeChatSDK({
@@ -46,7 +50,14 @@ const LiveChatWidget = props => {
46
50
  "isSDKMocked": !(0, _utils.isNullOrUndefined)(props === null || props === void 0 ? void 0 : (_props$mock2 = props.mock) === null || _props$mock2 === void 0 ? void 0 : _props$mock2.type)
47
51
  }, disableReauthentication));
48
52
  }
49
- return /*#__PURE__*/_react.default.createElement(_FacadeChatSDKStore.FacadeChatSDKStore.Provider, {
53
+ (0, _react.useEffect)(() => {
54
+ (0, _registerTelemetryLoggers.registerTelemetryLoggers)(props, dispatch);
55
+ }, [dispatch]);
56
+ return /*#__PURE__*/_react.default.createElement(_ErrorBoundary.default, {
57
+ onError: error => {
58
+ (0, _startChatErrorHandler.logWidgetLoadWithUnexpectedError)(error);
59
+ }
60
+ }, /*#__PURE__*/_react.default.createElement(_FacadeChatSDKStore.FacadeChatSDKStore.Provider, {
50
61
  value: [facadeChatSDK, setFacadeChatSDK]
51
62
  }, /*#__PURE__*/_react.default.createElement(_ChatSDKStore.ChatSDKStore.Provider, {
52
63
  value: chatSDK
@@ -54,7 +65,7 @@ const LiveChatWidget = props => {
54
65
  value: [adapter, setAdapter]
55
66
  }, /*#__PURE__*/_react.default.createElement(_ChatContextStore.ChatContextStore.Provider, {
56
67
  value: [state, dispatch]
57
- }, /*#__PURE__*/_react.default.createElement(_LiveChatWidgetStateful.default, props)))));
68
+ }, /*#__PURE__*/_react.default.createElement(_LiveChatWidgetStateful.default, props))))));
58
69
  };
59
70
  exports.LiveChatWidget = LiveChatWidget;
60
71
  var _default = LiveChatWidget;
@@ -13,7 +13,7 @@ const isPostChatSurveyEnabled = async facadeChatSDK => {
13
13
  return postChatEnabled === "true";
14
14
  };
15
15
  exports.isPostChatSurveyEnabled = isPostChatSurveyEnabled;
16
- const isPersistentChatEnabled = async conversationMode => {
16
+ const isPersistentChatEnabled = conversationMode => {
17
17
  if ((0, _utils.isNullOrUndefined)(conversationMode)) {
18
18
  return false;
19
19
  }
@@ -6,16 +6,23 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.shouldSetPreChatIfPersistentChat = void 0;
7
7
  var _liveChatConfigUtils = require("./liveChatConfigUtils");
8
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
- const shouldSetPreChatIfPersistentChat = async (chatSDK, conversationMode, showPreChat) => {
10
- const persistentEnabled = await (0, _liveChatConfigUtils.isPersistentChatEnabled)(conversationMode);
9
+ const shouldSetPreChatIfPersistentChat = async (facadeChatSDK, conversationMode, showPreChat) => {
10
+ const persistentEnabled = (0, _liveChatConfigUtils.isPersistentChatEnabled)(conversationMode);
11
11
  let skipPreChat = false;
12
12
  if (persistentEnabled) {
13
+ // Access private properties using type assertions
14
+ const chatSDK = facadeChatSDK.getChatSDK();
15
+
16
+ // Use type assertion to bypass private access restriction
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ const sdkAsAny = chatSDK;
19
+ // most likely this is not set , the facade will take care of it
13
20
  const reconnectableChatsParams = {
14
- authenticatedUserToken: chatSDK.authenticatedUserToken,
15
- requestId: chatSDK.requestId
21
+ authenticatedUserToken: sdkAsAny.authenticatedUserToken,
22
+ requestId: sdkAsAny.requestId
16
23
  };
17
24
  try {
18
- const reconnectableChatsResponse = await chatSDK.OCClient.getReconnectableChats(reconnectableChatsParams);
25
+ const reconnectableChatsResponse = await facadeChatSDK.getReconnectableChats(reconnectableChatsParams);
19
26
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
20
27
  // Skip rendering prechat on existing persistent chat session
21
28
  skipPreChat = true;
@@ -73,6 +73,10 @@ const getChatReconnectContext = async (facadeChatSDK, chatConfig, props, isAuthe
73
73
  // AuthToken will be reset later at start chat
74
74
  (0, _authHelper.removeAuthTokenProvider)(facadeChatSDK.getChatSDK());
75
75
  }
76
+ _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
77
+ Event: _TelemetryConstants.TelemetryEvent.GetChatReconnectContextSDKCallSucceeded,
78
+ Description: "Reconnect context SDK call succeeded"
79
+ });
76
80
  return reconnectChatContext;
77
81
  }
78
82
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -75,7 +75,7 @@ const setPreChatAndInitiateChat = async (facadeChatSDK, dispatch, setAdapter, is
75
75
  const parseToJson = false;
76
76
  const preChatSurveyResponse = (props === null || props === void 0 ? void 0 : (_props$preChatSurveyP = props.preChatSurveyPaneProps) === null || _props$preChatSurveyP === void 0 ? void 0 : (_props$preChatSurveyP2 = _props$preChatSurveyP.controlProps) === null || _props$preChatSurveyP2 === void 0 ? void 0 : _props$preChatSurveyP2.payload) ?? (await facadeChatSDK.getPreChatSurvey(parseToJson));
77
77
  let showPrechat = isProactiveChat ? preChatSurveyResponse && proactiveChatEnablePrechatState : preChatSurveyResponse && !(props !== null && props !== void 0 && (_props$controlProps = props.controlProps) !== null && _props$controlProps !== void 0 && _props$controlProps.hidePreChatSurveyPane);
78
- showPrechat = await (0, _persistentChatHelper.shouldSetPreChatIfPersistentChat)(facadeChatSDK.getChatSDK(), state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_conversationmode, showPrechat);
78
+ showPrechat = await (0, _persistentChatHelper.shouldSetPreChatIfPersistentChat)(facadeChatSDK, state === null || state === void 0 ? void 0 : (_state$domainStates = state.domainStates) === null || _state$domainStates === void 0 ? void 0 : (_state$domainStates$l = _state$domainStates.liveChatConfig) === null || _state$domainStates$l === void 0 ? void 0 : (_state$domainStates$l2 = _state$domainStates$l.LiveWSAndLiveChatEngJoin) === null || _state$domainStates$l2 === void 0 ? void 0 : _state$domainStates$l2.msdyn_conversationmode, showPrechat);
79
79
  if (showPrechat) {
80
80
  var _state$domainStates2, _state$domainStates2$, _state$domainStates2$2, _state$domainStates2$3;
81
81
  const isOutOfOperatingHours = (state === null || state === void 0 ? void 0 : (_state$domainStates2 = state.domainStates) === null || _state$domainStates2 === void 0 ? void 0 : (_state$domainStates2$ = _state$domainStates2.liveChatConfig) === null || _state$domainStates2$ === void 0 ? void 0 : (_state$domainStates2$2 = _state$domainStates2$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates2$2 === void 0 ? void 0 : (_state$domainStates2$3 = _state$domainStates2$2.OutOfOperatingHours) === null || _state$domainStates2$3 === void 0 ? void 0 : _state$domainStates2$3.toString().toLowerCase()) === "true";
@@ -163,7 +163,7 @@ exports.setPreChatAndInitiateChat = setPreChatAndInitiateChat;
163
163
  const initStartChat = async (facadeChatSDK, dispatch, setAdapter, state, props, params, persistedState) => {
164
164
  var _state$domainStates7, _state$domainStates7$, _state$domainStates7$2;
165
165
  let isStartChatSuccessful = false;
166
- const persistentChatEnabled = await (0, _liveChatConfigUtils.isPersistentChatEnabled)(state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : (_state$domainStates7$ = _state$domainStates7.liveChatConfig) === null || _state$domainStates7$ === void 0 ? void 0 : (_state$domainStates7$2 = _state$domainStates7$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates7$2 === void 0 ? void 0 : _state$domainStates7$2.msdyn_conversationmode);
166
+ const persistentChatEnabled = (0, _liveChatConfigUtils.isPersistentChatEnabled)(state === null || state === void 0 ? void 0 : (_state$domainStates7 = state.domainStates) === null || _state$domainStates7 === void 0 ? void 0 : (_state$domainStates7$ = _state$domainStates7.liveChatConfig) === null || _state$domainStates7$ === void 0 ? void 0 : (_state$domainStates7$2 = _state$domainStates7$.LiveWSAndLiveChatEngJoin) === null || _state$domainStates7$2 === void 0 ? void 0 : _state$domainStates7$2.msdyn_conversationmode);
167
167
  if ((state === null || state === void 0 ? void 0 : state.appStates.conversationState) === _ConversationState.ConversationState.Closed) {
168
168
  // Preventive reset to avoid starting chat with previous requestId which could potentially cause problems
169
169
  (0, _endChat.chatSDKStateCleanUp)(facadeChatSDK.getChatSDK());
@@ -315,13 +315,7 @@ const canConnectToExistingChat = async (props, facadeChatSDK, state, dispatch, s
315
315
 
316
316
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
317
317
  const setCustomContextParams = async (state, props) => {
318
- var _props$chatConfig, _props$chatConfig$Liv, _state$domainStates8, _persistedState$domai8;
319
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
320
- 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;
321
- //Should not set custom context for auth chat
322
- if (isAuthenticatedChat) {
323
- return;
324
- }
318
+ var _state$domainStates8, _persistedState$domai8;
325
319
  if (state !== null && state !== void 0 && (_state$domainStates8 = state.domainStates) !== null && _state$domainStates8 !== void 0 && _state$domainStates8.customContext) {
326
320
  var _state$domainStates9;
327
321
  optionalParams = Object.assign({}, optionalParams, {
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.logWidgetLoadComplete = exports.handleStartChatError = void 0;
6
+ exports.logWidgetLoadWithUnexpectedError = exports.logWidgetLoadComplete = exports.handleStartChatError = void 0;
7
7
  var _omnichannelChatSdk = require("@microsoft/omnichannel-chat-sdk");
8
8
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
9
9
  var _Constants = require("../../../common/Constants");
@@ -148,8 +148,37 @@ const logWidgetLoadCompleteWithError = ex => {
148
148
  ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg3 = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg3 === void 0 ? void 0 : _TelemetryTimers$Widg3.milliSecondsElapsed
149
149
  });
150
150
  };
151
+ const logWidgetLoadWithUnexpectedError = ex => {
152
+ var _TelemetryTimers$Widg4;
153
+ // eslint-disable-line @typescript-eslint/no-explicit-any
154
+ const details = {
155
+ message: (ex === null || ex === void 0 ? void 0 : ex.message) || "An unexpected error occurred",
156
+ stack: (ex === null || ex === void 0 ? void 0 : ex.stack) || "No stack trace available"
157
+ };
158
+ let additionalDetails = "";
159
+ try {
160
+ additionalDetails = JSON.stringify(details);
161
+ } catch (error) {
162
+ additionalDetails = "Failed to stringify error details";
163
+ }
164
+
165
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
166
+ const exDetails = {
167
+ Exception: `Widget load with unexpected error: ${additionalDetails}`
168
+ };
169
+ if (ex !== null && ex !== void 0 && ex.httpResponseStatusCode) {
170
+ exDetails.HttpResponseStatusCode = ex.httpResponseStatusCode;
171
+ }
172
+ _TelemetryHelper.TelemetryHelper.logLoadingEventToAllTelemetry(_TelemetryConstants.LogLevel.ERROR, {
173
+ Event: _TelemetryConstants.TelemetryEvent.WidgetLoadFailed,
174
+ Description: "Widget load with unexpected error",
175
+ ExceptionDetails: exDetails,
176
+ ElapsedTimeInMilliseconds: _TelemetryManager.TelemetryTimers === null || _TelemetryManager.TelemetryTimers === void 0 ? void 0 : (_TelemetryTimers$Widg4 = _TelemetryManager.TelemetryTimers.WidgetLoadTimer) === null || _TelemetryTimers$Widg4 === void 0 ? void 0 : _TelemetryTimers$Widg4.milliSecondsElapsed
177
+ });
178
+ };
151
179
 
152
180
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
181
+ exports.logWidgetLoadWithUnexpectedError = logWidgetLoadWithUnexpectedError;
153
182
  const forceEndChat = facadeChatSDK => {
154
183
  _TelemetryHelper.TelemetryHelper.logSDKEvent(_TelemetryConstants.LogLevel.INFO, {
155
184
  Event: _TelemetryConstants.TelemetryEvent.PrepareEndChat,