@microsoft/omnichannel-chat-sdk 1.11.6-main.b982edb → 1.11.7-main.14ece7b

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 (33) hide show
  1. package/lib/OmnichannelChatSDK.d.ts +22 -1
  2. package/lib/OmnichannelChatSDK.js +320 -219
  3. package/lib/OmnichannelChatSDK.js.map +1 -1
  4. package/lib/config/settings.d.ts +3 -2
  5. package/lib/config/settings.js +4 -2
  6. package/lib/config/settings.js.map +1 -1
  7. package/lib/core/ChatSDKError.d.ts +3 -1
  8. package/lib/core/ChatSDKError.js +2 -0
  9. package/lib/core/ChatSDKError.js.map +1 -1
  10. package/lib/core/GetPersistentChatHistoryOptionalParams.d.ts +10 -0
  11. package/lib/core/GetPersistentChatHistoryOptionalParams.js +3 -0
  12. package/lib/core/GetPersistentChatHistoryOptionalParams.js.map +1 -0
  13. package/lib/core/messaging/OmnichannelMessage.d.ts +6 -0
  14. package/lib/index.d.ts +2 -2
  15. package/lib/index.js.map +1 -1
  16. package/lib/telemetry/TelemetryEvent.d.ts +2 -1
  17. package/lib/telemetry/TelemetryEvent.js +1 -0
  18. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  19. package/lib/tsconfig.tsbuildinfo +1 -1
  20. package/lib/utils/createOcSDKConfiguration.d.ts +2 -2
  21. package/lib/utils/createOcSDKConfiguration.js +16 -2
  22. package/lib/utils/createOcSDKConfiguration.js.map +1 -1
  23. package/lib/utils/createOmnichannelMessage.js +9 -0
  24. package/lib/utils/createOmnichannelMessage.js.map +1 -1
  25. package/lib/utils/exceptionThrowers.d.ts +6 -0
  26. package/lib/utils/exceptionThrowers.js +8 -2
  27. package/lib/utils/exceptionThrowers.js.map +1 -1
  28. package/lib/utils/setOcUserAgent.js +2 -1
  29. package/lib/utils/setOcUserAgent.js.map +1 -1
  30. package/lib/utils/version.d.ts +9 -0
  31. package/lib/utils/version.js +28 -0
  32. package/lib/utils/version.js.map +1 -0
  33. package/package.json +3 -3
@@ -105,7 +105,6 @@ var loggerUtils_1 = require("./utils/loggerUtils");
105
105
  var parsers_1 = require("./utils/parsers");
106
106
  var platform_1 = require("./utils/platform");
107
107
  var retrieveCollectorUri_1 = require("./telemetry/retrieveCollectorUri");
108
- var setOcUserAgent_1 = require("./utils/setOcUserAgent");
109
108
  var startPolling_1 = require("./commands/startPolling");
110
109
  var stopPolling_1 = require("./commands/stopPolling");
111
110
  var urlResolvers_1 = require("./utils/urlResolvers");
@@ -118,6 +117,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
118
117
  this.ACSClient = null;
119
118
  this.AMSClient = null;
120
119
  this.sessionId = null;
120
+ // Operation queue for serializing chat operations
121
+ this.chatOperationInProgress = false;
122
+ this.pendingOperations = [];
121
123
  this.unqServicesOrgUrl = null;
122
124
  this.coreServicesOrgUrl = null;
123
125
  this.dynamicsLocationCode = null;
@@ -147,6 +149,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
147
149
  this.debugAMS = false;
148
150
  this.debugACS = false;
149
151
  this.detailedDebugEnabled = false;
152
+ this.regexCompiledForDataMasking = [];
150
153
  this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
151
154
  requestOptionalParams.initContext.locale = (0, locale_1.getLocaleStringFromId)(_this.localeId);
152
155
  if (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.customContext) {
@@ -254,6 +257,59 @@ var OmnichannelChatSDK = /** @class */ (function () {
254
257
  }
255
258
  loggerUtils_1.default.setRequestId(this.requestId, this.ocSdkLogger, this.acsClientLogger, this.acsAdapterLogger, this.callingSdkLogger, this.amsClientLogger, this.ic3ClientLogger);
256
259
  }
260
+ /**
261
+ * Executes an operation with mutual exclusion to prevent race conditions
262
+ * between startChat and endChat operations
263
+ */
264
+ OmnichannelChatSDK.prototype.executeWithLock = function (operation) {
265
+ return __awaiter(this, void 0, void 0, function () {
266
+ var _this = this;
267
+ return __generator(this, function (_a) {
268
+ return [2 /*return*/, new Promise(function (resolve, reject) {
269
+ var wrappedOperation = function () { return __awaiter(_this, void 0, void 0, function () {
270
+ var result, error_1;
271
+ return __generator(this, function (_a) {
272
+ switch (_a.label) {
273
+ case 0:
274
+ _a.trys.push([0, 2, 3, 4]);
275
+ return [4 /*yield*/, operation()];
276
+ case 1:
277
+ result = _a.sent();
278
+ resolve(result);
279
+ return [3 /*break*/, 4];
280
+ case 2:
281
+ error_1 = _a.sent();
282
+ reject(error_1);
283
+ return [3 /*break*/, 4];
284
+ case 3:
285
+ this.chatOperationInProgress = false;
286
+ this.processNextOperation();
287
+ return [7 /*endfinally*/];
288
+ case 4: return [2 /*return*/];
289
+ }
290
+ });
291
+ }); };
292
+ if (_this.chatOperationInProgress) {
293
+ _this.pendingOperations.push(wrappedOperation);
294
+ }
295
+ else {
296
+ _this.chatOperationInProgress = true;
297
+ wrappedOperation();
298
+ }
299
+ })];
300
+ });
301
+ });
302
+ };
303
+ /**
304
+ * Processes the next pending operation in the queue
305
+ */
306
+ OmnichannelChatSDK.prototype.processNextOperation = function () {
307
+ if (this.pendingOperations.length > 0) {
308
+ this.chatOperationInProgress = true;
309
+ var nextOperation = this.pendingOperations.shift();
310
+ nextOperation();
311
+ }
312
+ };
257
313
  /**
258
314
  *
259
315
  * @param flag Flag to enable/disable debug log telemetry, will be applied to all components
@@ -441,7 +497,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
441
497
  };
442
498
  OmnichannelChatSDK.prototype.parallelInitialization = function () {
443
499
  return __awaiter(this, arguments, void 0, function (optionalParams) {
444
- var error_1, telemetryData;
500
+ var error_2, telemetryData;
445
501
  if (optionalParams === void 0) { optionalParams = {}; }
446
502
  return __generator(this, function (_a) {
447
503
  switch (_a.label) {
@@ -462,13 +518,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
462
518
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDKParallel);
463
519
  return [3 /*break*/, 3];
464
520
  case 2:
465
- error_1 = _a.sent();
521
+ error_2 = _a.sent();
466
522
  telemetryData = {
467
523
  RequestId: this.requestId,
468
- ExceptionDetails: (error_1 instanceof ChatSDKError_1.ChatSDKError) ? JSON.stringify(error_1.exceptionDetails) : "".concat(error_1)
524
+ ExceptionDetails: (error_2 instanceof ChatSDKError_1.ChatSDKError) ? JSON.stringify(error_2.exceptionDetails) : "".concat(error_2)
469
525
  };
470
526
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDKParallel, telemetryData);
471
- throw error_1;
527
+ throw error_2;
472
528
  case 3: return [2 /*return*/, this.liveChatConfig];
473
529
  }
474
530
  });
@@ -495,10 +551,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
495
551
  _j.trys.push([1, 3, , 4]);
496
552
  this.OCSDKProvider = ocsdk_1.SDKProvider;
497
553
  _a = this;
498
- return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices), this.ocSdkLogger)];
554
+ return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices, (_d = this.chatSDKConfig) === null || _d === void 0 ? void 0 : _d.ocUserAgent), this.ocSdkLogger)];
499
555
  case 2:
500
556
  _a.OCClient = _j.sent();
501
- (0, setOcUserAgent_1.default)(this.OCClient, (_d = this.chatSDKConfig) === null || _d === void 0 ? void 0 : _d.ocUserAgent);
502
557
  return [3 /*break*/, 4];
503
558
  case 3:
504
559
  e_2 = _j.sent();
@@ -601,8 +656,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
601
656
  useCoreServices = (0, CoreServicesUtils_1.isCoreServicesOrgUrl)(this.omnichannelConfig.orgUrl);
602
657
  try {
603
658
  this.OCSDKProvider = ocsdk_1.SDKProvider;
604
- this.OCClient = ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices), this.ocSdkLogger);
605
- (0, setOcUserAgent_1.default)(this.OCClient, (_a = this.chatSDKConfig) === null || _a === void 0 ? void 0 : _a.ocUserAgent);
659
+ this.OCClient = ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices, (_a = this.chatSDKConfig) === null || _a === void 0 ? void 0 : _a.ocUserAgent), this.ocSdkLogger);
606
660
  }
607
661
  catch (e) {
608
662
  exceptionThrowers_1.default.throwOmnichannelClientInitializationFailure(e, this.scenarioMarker, TelemetryEvent_1.default.InitializeLoadChatConfig);
@@ -628,7 +682,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
628
682
  };
629
683
  OmnichannelChatSDK.prototype.getChatReconnectContextWithAuthToken = function () {
630
684
  return __awaiter(this, void 0, void 0, function () {
631
- var context, reconnectableChatsParams, reconnectableChatsResponse, error_2, exceptionDetails, telemetryData;
685
+ var context, reconnectableChatsParams, reconnectableChatsResponse, error_3, exceptionDetails, telemetryData;
632
686
  return __generator(this, function (_a) {
633
687
  switch (_a.label) {
634
688
  case 0:
@@ -659,7 +713,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
659
713
  });
660
714
  return [3 /*break*/, 4];
661
715
  case 3:
662
- error_2 = _a.sent();
716
+ error_3 = _a.sent();
663
717
  exceptionDetails = {
664
718
  response: "OCClientGetReconnectableChatsFailed"
665
719
  };
@@ -668,11 +722,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
668
722
  ChatId: this.chatToken.chatId,
669
723
  ExceptionDetails: JSON.stringify(exceptionDetails)
670
724
  };
671
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_2)) {
672
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_2, this.scenarioMarker, TelemetryEvent_1.default.GetChatReconnectContextWithAuthToken, telemetryData);
725
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_3)) {
726
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_3, this.scenarioMarker, TelemetryEvent_1.default.GetChatReconnectContextWithAuthToken, telemetryData);
673
727
  }
674
728
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetChatReconnectContextWithAuthToken, telemetryData);
675
- console.error("OmnichannelChatSDK/GetChatReconnectContextWithAuthToken/error ".concat(error_2));
729
+ console.error("OmnichannelChatSDK/GetChatReconnectContextWithAuthToken/error ".concat(error_3));
676
730
  return [3 /*break*/, 4];
677
731
  case 4: return [2 /*return*/, context];
678
732
  }
@@ -681,7 +735,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
681
735
  };
682
736
  OmnichannelChatSDK.prototype.getChatReconnectContextWithReconnectId = function () {
683
737
  return __awaiter(this, arguments, void 0, function (optionalParams) {
684
- var context, reconnectAvailabilityResponse, error_3, exceptionDetails;
738
+ var context, reconnectAvailabilityResponse, error_4, exceptionDetails;
685
739
  if (optionalParams === void 0) { optionalParams = {}; }
686
740
  return __generator(this, function (_a) {
687
741
  switch (_a.label) {
@@ -716,7 +770,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
716
770
  });
717
771
  return [3 /*break*/, 4];
718
772
  case 3:
719
- error_3 = _a.sent();
773
+ error_4 = _a.sent();
720
774
  exceptionDetails = {
721
775
  response: "OCClientGetReconnectAvailabilityFailed"
722
776
  };
@@ -725,7 +779,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
725
779
  ChatId: this.chatToken.chatId,
726
780
  ExceptionDetails: JSON.stringify(exceptionDetails)
727
781
  });
728
- console.error("OmnichannelChatSDK/GetChatReconnectContextWithReconnectId/error ".concat(error_3));
782
+ console.error("OmnichannelChatSDK/GetChatReconnectContextWithReconnectId/error ".concat(error_4));
729
783
  return [3 /*break*/, 4];
730
784
  case 4:
731
785
  //here the context contains recconnectionId if valid, or redirectionURL if not valid
@@ -780,7 +834,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
780
834
  };
781
835
  OmnichannelChatSDK.prototype.startChat = function () {
782
836
  return __awaiter(this, arguments, void 0, function (optionalParams) {
783
- var shouldReinitIC3Client, _a, reconnectableChatsParams, reconnectableChatsResponse, e_6, telemetryData, conversationDetails, telemetryData, telemetryData, e_7, telemetryData, sessionInitOptionalParams, location_2, sessionInitPromise, createConversationPromise, messagingClientPromise, attachmentClientPromise, error_4;
837
+ var _this = this;
838
+ if (optionalParams === void 0) { optionalParams = {}; }
839
+ return __generator(this, function (_a) {
840
+ return [2 /*return*/, this.executeWithLock(function () { return _this.internalStartChat(optionalParams); })];
841
+ });
842
+ });
843
+ };
844
+ OmnichannelChatSDK.prototype.internalStartChat = function () {
845
+ return __awaiter(this, arguments, void 0, function (optionalParams) {
846
+ var shouldReinitIC3Client, _a, reconnectableChatsParams, reconnectableChatsResponse, e_6, telemetryData, conversationDetails, telemetryData, telemetryData, e_7, telemetryData, sessionInitOptionalParams, location_2, sessionInitPromise, createConversationPromise, messagingClientPromise, attachmentClientPromise, error_5;
784
847
  var _this = this;
785
848
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
786
849
  if (optionalParams === void 0) { optionalParams = {}; }
@@ -919,7 +982,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
919
982
  _o.label = 18;
920
983
  case 18:
921
984
  sessionInitPromise = function () { return __awaiter(_this, void 0, void 0, function () {
922
- var error_5, telemetryData;
985
+ var error_6, telemetryData;
923
986
  var _a, _b, _c;
924
987
  return __generator(this, function (_d) {
925
988
  switch (_d.label) {
@@ -933,23 +996,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
933
996
  _d.sent();
934
997
  return [3 /*break*/, 4];
935
998
  case 3:
936
- error_5 = _d.sent();
999
+ error_6 = _d.sent();
937
1000
  telemetryData = {
938
1001
  RequestId: this.requestId,
939
1002
  ChatId: this.chatToken.chatId,
940
1003
  };
941
1004
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
942
- if ((error_5 === null || error_5 === void 0 ? void 0 : error_5.isAxiosError) && ((_c = (_b = (_a = error_5.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.errorcode) === null || _c === void 0 ? void 0 : _c.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
943
- exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1005
+ if ((error_6 === null || error_6 === void 0 ? void 0 : error_6.isAxiosError) && ((_c = (_b = (_a = error_6.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.errorcode) === null || _c === void 0 ? void 0 : _c.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
1006
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
944
1007
  }
945
- exceptionThrowers_1.default.throwConversationInitializationFailure(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1008
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
946
1009
  return [3 /*break*/, 4];
947
1010
  case 4: return [2 /*return*/];
948
1011
  }
949
1012
  });
950
1013
  }); };
951
1014
  createConversationPromise = function () { return __awaiter(_this, void 0, void 0, function () {
952
- var chatToken, error_6, telemetryData;
1015
+ var chatToken, error_7, telemetryData;
953
1016
  var _a, _b, _c;
954
1017
  return __generator(this, function (_d) {
955
1018
  switch (_d.label) {
@@ -967,23 +1030,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
967
1030
  }
968
1031
  return [3 /*break*/, 4];
969
1032
  case 3:
970
- error_6 = _d.sent();
1033
+ error_7 = _d.sent();
971
1034
  telemetryData = {
972
1035
  RequestId: this.requestId,
973
1036
  ChatId: this.chatToken.chatId,
974
1037
  };
975
1038
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
976
- if ((error_6 === null || error_6 === void 0 ? void 0 : error_6.isAxiosError) && ((_c = (_b = (_a = error_6.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.errorcode) === null || _c === void 0 ? void 0 : _c.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
977
- exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1039
+ if ((error_7 === null || error_7 === void 0 ? void 0 : error_7.isAxiosError) && ((_c = (_b = (_a = error_7.response) === null || _a === void 0 ? void 0 : _a.headers) === null || _b === void 0 ? void 0 : _b.errorcode) === null || _c === void 0 ? void 0 : _c.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
1040
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
978
1041
  }
979
- exceptionThrowers_1.default.throwConversationInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1042
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
980
1043
  return [3 /*break*/, 4];
981
1044
  case 4: return [2 /*return*/];
982
1045
  }
983
1046
  });
984
1047
  }); };
985
1048
  messagingClientPromise = function () { return __awaiter(_this, void 0, void 0, function () {
986
- var chatAdapterConfig, error_7, telemetryData, _a, error_8, telemetryData, error_9, telemetryData, _b, error_10, telemetryData;
1049
+ var chatAdapterConfig, error_8, telemetryData, _a, error_9, telemetryData, error_10, telemetryData, _b, error_11, telemetryData;
987
1050
  var _c, _d;
988
1051
  return __generator(this, function (_e) {
989
1052
  switch (_e.label) {
@@ -1007,12 +1070,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1007
1070
  _e.sent();
1008
1071
  return [3 /*break*/, 4];
1009
1072
  case 3:
1010
- error_7 = _e.sent();
1073
+ error_8 = _e.sent();
1011
1074
  telemetryData = {
1012
1075
  RequestId: this.requestId,
1013
1076
  ChatId: this.chatToken.chatId,
1014
1077
  };
1015
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1078
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1016
1079
  return [3 /*break*/, 4];
1017
1080
  case 4:
1018
1081
  _e.trys.push([4, 6, , 7]);
@@ -1030,12 +1093,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1030
1093
  });
1031
1094
  return [3 /*break*/, 7];
1032
1095
  case 6:
1033
- error_8 = _e.sent();
1096
+ error_9 = _e.sent();
1034
1097
  telemetryData = {
1035
1098
  RequestId: this.requestId,
1036
1099
  ChatId: this.chatToken.chatId,
1037
1100
  };
1038
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1101
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_9, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1039
1102
  return [3 /*break*/, 7];
1040
1103
  case 7: return [3 /*break*/, 14];
1041
1104
  case 8:
@@ -1049,12 +1112,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1049
1112
  _e.sent();
1050
1113
  return [3 /*break*/, 11];
1051
1114
  case 10:
1052
- error_9 = _e.sent();
1115
+ error_10 = _e.sent();
1053
1116
  telemetryData = {
1054
1117
  RequestId: this.requestId,
1055
1118
  ChatId: this.chatToken.chatId,
1056
1119
  };
1057
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_9, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1120
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_10, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1058
1121
  return [3 /*break*/, 11];
1059
1122
  case 11:
1060
1123
  _e.trys.push([11, 13, , 14]);
@@ -1068,19 +1131,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
1068
1131
  });
1069
1132
  return [3 /*break*/, 14];
1070
1133
  case 13:
1071
- error_10 = _e.sent();
1134
+ error_11 = _e.sent();
1072
1135
  telemetryData = {
1073
1136
  RequestId: this.requestId,
1074
1137
  ChatId: this.chatToken.chatId,
1075
1138
  };
1076
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_10, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1139
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_11, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1077
1140
  return [3 /*break*/, 14];
1078
1141
  case 14: return [2 /*return*/];
1079
1142
  }
1080
1143
  });
1081
1144
  }); };
1082
1145
  attachmentClientPromise = function () { return __awaiter(_this, void 0, void 0, function () {
1083
- var amsClient, error_11, telemetryData;
1146
+ var amsClient, error_12, telemetryData;
1084
1147
  return __generator(this, function (_a) {
1085
1148
  switch (_a.label) {
1086
1149
  case 0:
@@ -1100,7 +1163,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1100
1163
  _a.label = 3;
1101
1164
  case 3: return [3 /*break*/, 5];
1102
1165
  case 4:
1103
- error_11 = _a.sent();
1166
+ error_12 = _a.sent();
1104
1167
  telemetryData = {
1105
1168
  RequestId: this.requestId,
1106
1169
  ChatId: this.chatToken.chatId,
@@ -1127,25 +1190,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1127
1190
  _o.sent();
1128
1191
  return [3 /*break*/, 26];
1129
1192
  case 24:
1130
- error_4 = _o.sent();
1193
+ error_5 = _o.sent();
1131
1194
  // If conversation joining fails after conversation was created, clean up the conversation
1132
1195
  // Only cleanup conversations that were freshly created (not existing ones being reconnected to)
1133
- return [4 /*yield*/, this.handleConversationJoinFailure(error_4, optionalParams)];
1196
+ return [4 /*yield*/, this.handleConversationJoinFailure(error_5, optionalParams)];
1134
1197
  case 25:
1135
1198
  // If conversation joining fails after conversation was created, clean up the conversation
1136
1199
  // Only cleanup conversations that were freshly created (not existing ones being reconnected to)
1137
1200
  _o.sent();
1138
- throw error_4; // Re-throw the original error
1201
+ throw error_5; // Re-throw the original error
1139
1202
  case 26:
1140
1203
  if (this.isPersistentChat && !((_l = this.chatSDKConfig.persistentChat) === null || _l === void 0 ? void 0 : _l.disable)) {
1141
1204
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
1205
+ var error_13;
1142
1206
  return __generator(this, function (_a) {
1143
1207
  switch (_a.label) {
1144
- case 0: return [4 /*yield*/, this.getChatToken(false)];
1208
+ case 0:
1209
+ _a.trys.push([0, 2, , 3]);
1210
+ return [4 /*yield*/, this.getChatToken(false)];
1145
1211
  case 1:
1146
1212
  _a.sent();
1147
1213
  this.updateChatToken(this.chatToken.token, this.chatToken.regionGTMS);
1148
- return [2 /*return*/];
1214
+ return [3 /*break*/, 3];
1215
+ case 2:
1216
+ error_13 = _a.sent();
1217
+ if (this.refreshTokenTimer !== null) {
1218
+ clearInterval(this.refreshTokenTimer);
1219
+ this.refreshTokenTimer = null;
1220
+ }
1221
+ return [3 /*break*/, 3];
1222
+ case 3: return [2 /*return*/];
1149
1223
  }
1150
1224
  });
1151
1225
  }); }, (_m = this.chatSDKConfig.persistentChat) === null || _m === void 0 ? void 0 : _m.tokenUpdateTime);
@@ -1157,7 +1231,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1157
1231
  };
1158
1232
  OmnichannelChatSDK.prototype.closeChat = function (endChatOptionalParams) {
1159
1233
  return __awaiter(this, void 0, void 0, function () {
1160
- var cleanupMetadata, sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_12;
1234
+ var cleanupMetadata, sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_14;
1161
1235
  var _a, _b;
1162
1236
  return __generator(this, function (_c) {
1163
1237
  switch (_c.label) {
@@ -1192,8 +1266,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1192
1266
  _c.sent();
1193
1267
  return [3 /*break*/, 4];
1194
1268
  case 3:
1195
- error_12 = _c.sent();
1196
- exceptionThrowers_1.default.throwConversationClosureFailure(error_12, this.scenarioMarker, TelemetryEvent_1.default.CloseChatSession, __assign(__assign({}, cleanupMetadata), { isSessionEnded: String(!(endChatOptionalParams === null || endChatOptionalParams === void 0 ? void 0 : endChatOptionalParams.isSessionEnded)) }));
1269
+ error_14 = _c.sent();
1270
+ exceptionThrowers_1.default.throwConversationClosureFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.CloseChatSession, __assign(__assign({}, cleanupMetadata), { isSessionEnded: String(!(endChatOptionalParams === null || endChatOptionalParams === void 0 ? void 0 : endChatOptionalParams.isSessionEnded)) }));
1197
1271
  return [3 /*break*/, 4];
1198
1272
  case 4:
1199
1273
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CloseChatSession, cleanupMetadata);
@@ -1205,7 +1279,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1205
1279
  };
1206
1280
  OmnichannelChatSDK.prototype.endChat = function () {
1207
1281
  return __awaiter(this, arguments, void 0, function (endChatOptionalParams) {
1208
- var cleanupMetadata, error_13, telemetryData;
1282
+ var _this = this;
1283
+ if (endChatOptionalParams === void 0) { endChatOptionalParams = {}; }
1284
+ return __generator(this, function (_a) {
1285
+ return [2 /*return*/, this.executeWithLock(function () { return _this.internalEndChat(endChatOptionalParams); })];
1286
+ });
1287
+ });
1288
+ };
1289
+ OmnichannelChatSDK.prototype.internalEndChat = function () {
1290
+ return __awaiter(this, arguments, void 0, function (endChatOptionalParams) {
1291
+ var cleanupMetadata, error_15, telemetryData;
1209
1292
  var _a;
1210
1293
  if (endChatOptionalParams === void 0) { endChatOptionalParams = {}; }
1211
1294
  return __generator(this, function (_b) {
@@ -1255,15 +1338,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1255
1338
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, cleanupMetadata);
1256
1339
  return [3 /*break*/, 7];
1257
1340
  case 6:
1258
- error_13 = _b.sent();
1341
+ error_15 = _b.sent();
1259
1342
  telemetryData = {
1260
1343
  RequestId: this.requestId,
1261
1344
  ChatId: this.chatToken.chatId
1262
1345
  };
1263
- if (error_13 instanceof ChatSDKError_1.ChatSDKError) {
1264
- exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_13.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1346
+ if (error_15 instanceof ChatSDKError_1.ChatSDKError) {
1347
+ exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_15.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1265
1348
  }
1266
- exceptionThrowers_1.default.throwConversationClosureFailure(error_13, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1349
+ exceptionThrowers_1.default.throwConversationClosureFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1267
1350
  return [3 /*break*/, 7];
1268
1351
  case 7: return [2 /*return*/];
1269
1352
  }
@@ -1310,7 +1393,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1310
1393
  };
1311
1394
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
1312
1395
  return __awaiter(this, arguments, void 0, function (optionalParams) {
1313
- var requestId, chatToken, chatId, reconnectId, sessionId, getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_14, telemetryData;
1396
+ var requestId, chatToken, chatId, reconnectId, sessionId, getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_16, telemetryData;
1314
1397
  var _a, _b, _c, _d;
1315
1398
  if (optionalParams === void 0) { optionalParams = {}; }
1316
1399
  return __generator(this, function (_e) {
@@ -1383,15 +1466,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1383
1466
  });
1384
1467
  return [2 /*return*/, liveWorkItemDetails];
1385
1468
  case 3:
1386
- error_14 = _e.sent();
1469
+ error_16 = _e.sent();
1387
1470
  telemetryData = {
1388
1471
  RequestId: requestId,
1389
1472
  ChatId: chatId
1390
1473
  };
1391
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_14)) {
1392
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1474
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_16)) {
1475
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_16, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1393
1476
  }
1394
- exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1477
+ exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(error_16, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1395
1478
  return [3 /*break*/, 4];
1396
1479
  case 4: return [2 /*return*/, {}];
1397
1480
  }
@@ -1432,7 +1515,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1432
1515
  };
1433
1516
  OmnichannelChatSDK.prototype.getChatToken = function () {
1434
1517
  return __awaiter(this, arguments, void 0, function (cached, optionalParams) {
1435
- var getChatTokenOptionalParams, chatToken, error_15, telemetryData;
1518
+ var getChatTokenOptionalParams, chatToken, error_17, telemetryData;
1436
1519
  var _a, _b, _c;
1437
1520
  if (cached === void 0) { cached = true; }
1438
1521
  return __generator(this, function (_d) {
@@ -1474,16 +1557,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1474
1557
  });
1475
1558
  return [3 /*break*/, 4];
1476
1559
  case 3:
1477
- error_15 = _d.sent();
1560
+ error_17 = _d.sent();
1478
1561
  telemetryData = {
1479
1562
  RequestId: this.requestId,
1480
1563
  ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId,
1481
1564
  };
1482
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_15)) {
1483
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1565
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_17)) {
1566
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_17, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1484
1567
  }
1485
1568
  else {
1486
- exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1569
+ exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_17, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1487
1570
  }
1488
1571
  return [3 /*break*/, 4];
1489
1572
  case 4: return [3 /*break*/, 6];
@@ -1613,21 +1696,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1613
1696
  }
1614
1697
  var content = message.content;
1615
1698
  var match;
1616
- for (var _i = 0, _a = this.dataMaskingRules.rules; _i < _a.length; _i++) {
1617
- var maskingRule = _a[_i];
1618
- var regex = new RegExp(maskingRule.regex, 'g');
1619
- while ((match = regex.exec(content)) !== null) {
1620
- var replaceStr = match[0].replace(/./g, this.maskingCharacter);
1621
- content = content.replace(match[0], replaceStr);
1699
+ if (this.regexCompiledForDataMasking.length === 0) {
1700
+ return message;
1701
+ }
1702
+ for (var _i = 0, _a = this.regexCompiledForDataMasking; _i < _a.length; _i++) {
1703
+ var regex = _a[_i];
1704
+ try {
1705
+ var lastIndex = -1;
1706
+ while ((match = regex.exec(content)) !== null) {
1707
+ // Prevent infinite loop from zero-width matches
1708
+ if (regex.lastIndex === lastIndex) {
1709
+ this.debug && console.warn("[OmnichannelChatSDK][transformMessage] Data masking regex caused zero-width match, skipping rule ".concat(regex));
1710
+ break;
1711
+ }
1712
+ lastIndex = regex.lastIndex;
1713
+ var replaceStr = match[0].replace(/./g, this.maskingCharacter);
1714
+ content = content.replace(match[0], replaceStr);
1715
+ }
1716
+ match = null;
1717
+ }
1718
+ catch (error) {
1719
+ // Log error for invalid regex but continue processing other rules
1720
+ this.debug && console.error("[OmnichannelChatSDK][transformMessage] Data masking regex failed for rule ".concat(regex, ": ").concat(error));
1622
1721
  }
1623
- match = null;
1624
1722
  }
1625
1723
  message.content = content;
1626
1724
  return message;
1627
1725
  };
1628
1726
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
1629
1727
  return __awaiter(this, void 0, void 0, function () {
1630
- var sendMessageRequest, chatMessage, error_16, exceptionDetails, messageToSend, error_17, exceptionDetails;
1728
+ var sendMessageRequest, chatMessage, error_18, exceptionDetails;
1631
1729
  var _a;
1632
1730
  return __generator(this, function (_b) {
1633
1731
  switch (_b.label) {
@@ -1640,7 +1738,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
1640
1738
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.SendMessages);
1641
1739
  }
1642
1740
  this.transformMessage(message);
1643
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
1644
1741
  sendMessageRequest = {
1645
1742
  content: message.content,
1646
1743
  };
@@ -1663,10 +1760,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1663
1760
  });
1664
1761
  return [2 /*return*/, chatMessage];
1665
1762
  case 3:
1666
- error_16 = _b.sent();
1763
+ error_18 = _b.sent();
1667
1764
  exceptionDetails = {
1668
1765
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1669
- errorObject: "".concat(error_16)
1766
+ errorObject: "".concat(error_18)
1670
1767
  };
1671
1768
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1672
1769
  RequestId: this.requestId,
@@ -1675,54 +1772,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1675
1772
  });
1676
1773
  throw new ChatSDKError_1.ChatSDKError(ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed, undefined, {
1677
1774
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1678
- errorObject: "".concat(error_16)
1679
- });
1680
- case 4: return [3 /*break*/, 9];
1681
- case 5:
1682
- messageToSend = {
1683
- content: message.content,
1684
- timestamp: new Date(),
1685
- contentType: MessageContentType_1.default.Text,
1686
- deliveryMode: DeliveryMode_1.default.Bridged,
1687
- messageType: MessageType_1.default.UserMessage,
1688
- properties: undefined,
1689
- tags: __spreadArray([], MessageTags_1.defaultMessageTags, true),
1690
- sender: {
1691
- displayName: "Customer",
1692
- id: "customer",
1693
- type: PersonType_1.default.User
1694
- }
1695
- };
1696
- if (message.tags) {
1697
- messageToSend.tags = message.tags;
1698
- }
1699
- if (message.timestamp) {
1700
- messageToSend.timestamp = message.timestamp;
1701
- }
1702
- _b.label = 6;
1703
- case 6:
1704
- _b.trys.push([6, 8, , 9]);
1705
- return [4 /*yield*/, this.conversation.sendMessage(messageToSend)];
1706
- case 7:
1707
- _b.sent();
1708
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
1709
- RequestId: this.requestId,
1710
- ChatId: this.chatToken.chatId
1711
- });
1712
- return [3 /*break*/, 9];
1713
- case 8:
1714
- error_17 = _b.sent();
1715
- exceptionDetails = {
1716
- response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1717
- errorObject: "".concat(error_17)
1718
- };
1719
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1720
- RequestId: this.requestId,
1721
- ChatId: this.chatToken.chatId,
1722
- ExceptionDetails: JSON.stringify(exceptionDetails)
1775
+ errorObject: "".concat(error_18)
1723
1776
  });
1724
- throw new Error(ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed);
1725
- case 9: return [2 /*return*/];
1777
+ case 4: return [2 /*return*/];
1726
1778
  }
1727
1779
  });
1728
1780
  });
@@ -1773,12 +1825,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1773
1825
  }
1774
1826
  (_b = this.conversation) === null || _b === void 0 ? void 0 : _b.registerOnNewMessage(function (event) {
1775
1827
  var id = event.id;
1828
+ var isChatMessageEditedEvent = Object.keys(event).includes("editedOn");
1829
+ console.log("[OmnichannelChatSDK][onNewMessage] New message received", event);
1830
+ console.log("[OmnichannelChatSDK][onNewMessage] isChatMessageEditedEvent=>", isChatMessageEditedEvent);
1776
1831
  var omnichannelMessage = (0, createOmnichannelMessage_1.default)(event, {
1777
1832
  liveChatVersion: _this.liveChatVersion,
1778
1833
  debug: (_this.detailedDebugEnabled ? _this.debugACS : _this.debug),
1779
1834
  });
1780
- if (!postedMessages_1.has(id)) {
1835
+ // send callback for new messages or edited existent messages
1836
+ if (!postedMessages_1.has(id) || isChatMessageEditedEvent) {
1781
1837
  onNewMessageCallback(omnichannelMessage);
1838
+ console.log("[OmnichannelChatSDK][onNewMessage] Message posted");
1782
1839
  postedMessages_1.add(id);
1783
1840
  }
1784
1841
  }, registerOnNewMessageOptionalParams);
@@ -1801,7 +1858,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1801
1858
  };
1802
1859
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
1803
1860
  return __awaiter(this, void 0, void 0, function () {
1804
- var error_18;
1861
+ var error_19;
1805
1862
  return __generator(this, function (_a) {
1806
1863
  switch (_a.label) {
1807
1864
  case 0:
@@ -1830,7 +1887,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1830
1887
  });
1831
1888
  return [3 /*break*/, 5];
1832
1889
  case 4:
1833
- error_18 = _a.sent();
1890
+ error_19 = _a.sent();
1834
1891
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1835
1892
  RequestId: this.requestId,
1836
1893
  ChatId: this.chatToken.chatId
@@ -1898,8 +1955,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1898
1955
  OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
1899
1956
  return __awaiter(this, void 0, void 0, function () {
1900
1957
  var _this = this;
1901
- var _a;
1902
- return __generator(this, function (_b) {
1958
+ return __generator(this, function (_a) {
1903
1959
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1904
1960
  RequestId: this.requestId,
1905
1961
  ChatId: this.chatToken.chatId
@@ -1907,59 +1963,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
1907
1963
  if (!this.isInitialized) {
1908
1964
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.OnAgentEndSession);
1909
1965
  }
1910
- if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
1911
- try {
1912
- this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
1913
- var liveWorkItemDetails;
1914
- return __generator(this, function (_a) {
1915
- switch (_a.label) {
1916
- case 0: return [4 /*yield*/, this.getConversationDetails()];
1917
- case 1:
1918
- liveWorkItemDetails = _a.sent();
1919
- if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
1920
- onAgentEndSessionCallback(event);
1921
- this.stopPolling();
1922
- }
1923
- return [2 /*return*/];
1924
- }
1925
- });
1926
- }); });
1927
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1928
- RequestId: this.requestId,
1929
- ChatId: this.chatToken.chatId
1930
- });
1931
- }
1932
- catch (error) {
1933
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1934
- RequestId: this.requestId,
1935
- ChatId: this.chatToken.chatId
1936
- });
1937
- }
1938
- }
1939
- else {
1940
- try {
1941
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
1942
- var members = message.members;
1943
- // Agent ending conversation would have 1 member left in the chat thread
1944
- if (members.length === 1) {
1945
- onAgentEndSessionCallback(message);
1946
- if (_this.refreshTokenTimer !== null) {
1947
- clearInterval(_this.refreshTokenTimer);
1948
- _this.refreshTokenTimer = null;
1949
- }
1966
+ try {
1967
+ this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
1968
+ var liveWorkItemDetails;
1969
+ return __generator(this, function (_a) {
1970
+ switch (_a.label) {
1971
+ case 0: return [4 /*yield*/, this.getConversationDetails()];
1972
+ case 1:
1973
+ liveWorkItemDetails = _a.sent();
1974
+ if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
1975
+ onAgentEndSessionCallback(event);
1976
+ this.stopPolling();
1977
+ }
1978
+ return [2 /*return*/];
1950
1979
  }
1951
1980
  });
1952
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1953
- RequestId: this.requestId,
1954
- ChatId: this.chatToken.chatId
1955
- });
1956
- }
1957
- catch (error) {
1958
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1959
- RequestId: this.requestId,
1960
- ChatId: this.chatToken.chatId
1961
- });
1962
- }
1981
+ }); });
1982
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1983
+ RequestId: this.requestId,
1984
+ ChatId: this.chatToken.chatId
1985
+ });
1986
+ }
1987
+ catch (error) {
1988
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1989
+ RequestId: this.requestId,
1990
+ ChatId: this.chatToken.chatId
1991
+ });
1963
1992
  }
1964
1993
  return [2 /*return*/];
1965
1994
  });
@@ -1967,7 +1996,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1967
1996
  };
1968
1997
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
1969
1998
  return __awaiter(this, void 0, void 0, function () {
1970
- var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_19, fileMetadata, messageToSend, error_20;
1999
+ var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_20, fileMetadata, messageToSend, error_21;
1971
2000
  var _a, _b;
1972
2001
  return __generator(this, function (_c) {
1973
2002
  switch (_c.label) {
@@ -2036,7 +2065,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2036
2065
  });
2037
2066
  return [2 /*return*/, messageToSend];
2038
2067
  case 6:
2039
- error_19 = _c.sent();
2068
+ error_20 = _c.sent();
2040
2069
  console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
2041
2070
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2042
2071
  RequestId: this.requestId,
@@ -2082,8 +2111,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2082
2111
  });
2083
2112
  return [2 /*return*/, messageToSend];
2084
2113
  case 15:
2085
- error_20 = _c.sent();
2086
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_20));
2114
+ error_21 = _c.sent();
2115
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_21));
2087
2116
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2088
2117
  RequestId: this.requestId,
2089
2118
  ChatId: this.chatToken.chatId
@@ -2096,7 +2125,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2096
2125
  };
2097
2126
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
2098
2127
  return __awaiter(this, void 0, void 0, function () {
2099
- var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
2128
+ var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_22;
2100
2129
  return __generator(this, function (_b) {
2101
2130
  switch (_b.label) {
2102
2131
  case 0:
@@ -2156,8 +2185,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2156
2185
  });
2157
2186
  return [2 /*return*/, downloadedFile];
2158
2187
  case 9:
2159
- error_21 = _b.sent();
2160
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_21));
2188
+ error_22 = _b.sent();
2189
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_22));
2161
2190
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2162
2191
  RequestId: this.requestId,
2163
2192
  ChatId: this.chatToken.chatId
@@ -2170,7 +2199,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2170
2199
  };
2171
2200
  OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
2172
2201
  return __awaiter(this, arguments, void 0, function (body, optionalParams) {
2173
- var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_22;
2202
+ var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_23;
2174
2203
  var _a;
2175
2204
  if (optionalParams === void 0) { optionalParams = {}; }
2176
2205
  return __generator(this, function (_b) {
@@ -2221,8 +2250,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2221
2250
  });
2222
2251
  return [3 /*break*/, 4];
2223
2252
  case 3:
2224
- error_22 = _b.sent();
2225
- console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_22));
2253
+ error_23 = _b.sent();
2254
+ console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_23));
2226
2255
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
2227
2256
  RequestId: requestId,
2228
2257
  ChatId: chatId
@@ -2235,7 +2264,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2235
2264
  };
2236
2265
  OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
2237
2266
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2238
- var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_23, telemetryData;
2267
+ var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_24, telemetryData;
2239
2268
  var _a, _b;
2240
2269
  if (optionalParams === void 0) { optionalParams = {}; }
2241
2270
  return __generator(this, function (_c) {
@@ -2292,12 +2321,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2292
2321
  });
2293
2322
  return [2 /*return*/, transcriptResponse];
2294
2323
  case 3:
2295
- error_23 = _c.sent();
2324
+ error_24 = _c.sent();
2296
2325
  telemetryData = {
2297
2326
  RequestId: requestId,
2298
2327
  ChatId: chatId
2299
2328
  };
2300
- exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_23, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2329
+ exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_24, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2301
2330
  return [3 /*break*/, 4];
2302
2331
  case 4: return [2 /*return*/];
2303
2332
  }
@@ -2412,7 +2441,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2412
2441
  };
2413
2442
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
2414
2443
  return __awaiter(this, void 0, void 0, function () {
2415
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, msdyn_surveyprovider, surveyProvider, liveWorkItemDetails, participantJoined, participantType, agentSurveyInviteLinkRequest, botSurveyInviteLinkRequest, optionalParams, agentSurveyInviteLinkResponse, botSurveyInviteLinkResponse, _a, agentSurveyInviteLink, agentFormsProLocale, botSurveyInviteLink, botFormsProLocale, postChatContext, ex_1;
2444
+ var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, msdyn_surveyprovider, surveyProvider, liveWorkItemDetails, participantJoined, participantType, agentSurveyInviteLinkRequest, botSurveyInviteLinkRequest, optionalParams, _a, agentSurveyInviteLinkResponse, botSurveyInviteLinkResponse, agentSurveyInviteLink, agentFormsProLocale, botSurveyInviteLink, botFormsProLocale, postChatContext, ex_1;
2416
2445
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2417
2446
  return __generator(this, function (_o) {
2418
2447
  switch (_o.label) {
@@ -2426,7 +2455,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2426
2455
  }
2427
2456
  _o.label = 1;
2428
2457
  case 1:
2429
- _o.trys.push([1, 8, , 9]);
2458
+ _o.trys.push([1, 6, , 7]);
2430
2459
  chatConfig = this.liveChatConfig;
2431
2460
  liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
2432
2461
  msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId, postConversationBotSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationBotSurveyOwnerId, msdyn_surveyprovider = liveWSAndLiveChatEngJoin.msdyn_surveyprovider;
@@ -2439,7 +2468,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2439
2468
  });
2440
2469
  return [2 /*return*/, Promise.reject("GetPostChatSurveyContext : msfp_sourcesurveyidentifier is mandatory for survey provider ".concat(SurveyProvider_1.SurveyProvider.CustomerVoice, "."))];
2441
2470
  }
2442
- if (!((0, parsers_1.parseLowerCaseString)(msdyn_postconversationsurveyenable) === "true")) return [3 /*break*/, 6];
2471
+ if (!((0, parsers_1.parseLowerCaseString)(msdyn_postconversationsurveyenable) === "true")) return [3 /*break*/, 4];
2443
2472
  return [4 /*yield*/, this.getConversationDetails()];
2444
2473
  case 2:
2445
2474
  liveWorkItemDetails = _o.sent();
@@ -2482,17 +2511,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
2482
2511
  if (this.authenticatedUserToken) {
2483
2512
  optionalParams.authenticatedUserToken = this.authenticatedUserToken;
2484
2513
  }
2485
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams)];
2514
+ return [4 /*yield*/, Promise.all([
2515
+ this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams),
2516
+ (postConversationBotSurveyOwnerId && msfp_botsourcesurveyidentifier)
2517
+ ? this.OCClient.getSurveyInviteLink(postConversationBotSurveyOwnerId, botSurveyInviteLinkRequest, optionalParams)
2518
+ : Promise.resolve(null)
2519
+ ])];
2486
2520
  case 3:
2487
- agentSurveyInviteLinkResponse = _o.sent();
2488
- _a = postConversationBotSurveyOwnerId && msfp_botsourcesurveyidentifier;
2489
- if (!_a) return [3 /*break*/, 5];
2490
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationBotSurveyOwnerId, botSurveyInviteLinkRequest, optionalParams)];
2491
- case 4:
2492
- _a = (_o.sent());
2493
- _o.label = 5;
2494
- case 5:
2495
- botSurveyInviteLinkResponse = _a;
2521
+ _a = _o.sent(), agentSurveyInviteLinkResponse = _a[0], botSurveyInviteLinkResponse = _a[1];
2496
2522
  agentSurveyInviteLink = void 0, agentFormsProLocale = void 0, botSurveyInviteLink = void 0, botFormsProLocale = void 0;
2497
2523
  if (agentSurveyInviteLinkResponse != null) {
2498
2524
  if (agentSurveyInviteLinkResponse.inviteList != null && agentSurveyInviteLinkResponse.inviteList.length == 1) {
@@ -2541,16 +2567,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
2541
2567
  });
2542
2568
  return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
2543
2569
  }
2544
- return [3 /*break*/, 7];
2545
- case 6:
2570
+ return [3 /*break*/, 5];
2571
+ case 4:
2546
2572
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
2547
2573
  RequestId: this.requestId,
2548
2574
  ChatId: (_l = this.chatToken) === null || _l === void 0 ? void 0 : _l.chatId,
2549
2575
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
2550
2576
  });
2551
2577
  return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side, or chat doesnt have a survey as part of their configuration.")];
2552
- case 7: return [3 /*break*/, 9];
2553
- case 8:
2578
+ case 5: return [3 /*break*/, 7];
2579
+ case 6:
2554
2580
  ex_1 = _o.sent();
2555
2581
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
2556
2582
  ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
@@ -2559,7 +2585,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2559
2585
  ExceptionDetails: JSON.stringify(ex_1)
2560
2586
  });
2561
2587
  return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
2562
- case 9: return [2 /*return*/];
2588
+ case 7: return [2 /*return*/];
2563
2589
  }
2564
2590
  });
2565
2591
  });
@@ -2752,12 +2778,26 @@ var OmnichannelChatSDK = /** @class */ (function () {
2752
2778
  regex: value
2753
2779
  });
2754
2780
  }
2781
+ this.compileDataMaskingRegex();
2755
2782
  }
2756
2783
  }
2757
2784
  return [2 /*return*/];
2758
2785
  });
2759
2786
  });
2760
2787
  };
2788
+ OmnichannelChatSDK.prototype.compileDataMaskingRegex = function () {
2789
+ this.regexCompiledForDataMasking = [];
2790
+ for (var _i = 0, _a = this.dataMaskingRules.rules; _i < _a.length; _i++) {
2791
+ var rule = _a[_i];
2792
+ try {
2793
+ var regex = new RegExp(rule.regex, 'g');
2794
+ this.regexCompiledForDataMasking.push(regex);
2795
+ }
2796
+ catch (e) {
2797
+ console.error("Error compiling regex for data masking rule id ".concat(rule.id, ": ").concat(e));
2798
+ }
2799
+ }
2800
+ };
2761
2801
  OmnichannelChatSDK.prototype.setAuthSettingConfig = function (authSettings) {
2762
2802
  return __awaiter(this, void 0, void 0, function () {
2763
2803
  return __generator(this, function (_a) {
@@ -2836,7 +2876,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2836
2876
  };
2837
2877
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2838
2878
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2839
- var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
2879
+ var sendCacheHeaders, bypassCache, liveChatConfig, error_25, _a;
2840
2880
  var _b, _c;
2841
2881
  if (optionalParams === void 0) { optionalParams = {}; }
2842
2882
  return __generator(this, function (_d) {
@@ -2857,8 +2897,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2857
2897
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
2858
2898
  return [2 /*return*/, this.liveChatConfig];
2859
2899
  case 3:
2860
- error_24 = _d.sent();
2861
- if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_24, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2900
+ error_25 = _d.sent();
2901
+ if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_25, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2862
2902
  this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
2863
2903
  _a = this;
2864
2904
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
@@ -2870,10 +2910,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2870
2910
  return [3 /*break*/, 7];
2871
2911
  case 6:
2872
2912
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2873
- if (((_c = (_b = error_24.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_24.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
2913
+ if (((_c = (_b = error_25.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_25.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
2874
2914
  console.warn("No widget with the given app id is present in the system.");
2875
2915
  }
2876
- throw error_24; // Bubble up error by default to throw ChatConfigRetrievalFailure
2916
+ throw error_25; // Bubble up error by default to throw ChatConfigRetrievalFailure
2877
2917
  case 7: return [3 /*break*/, 8];
2878
2918
  case 8: return [2 /*return*/, this.liveChatConfig];
2879
2919
  }
@@ -2908,7 +2948,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2908
2948
  };
2909
2949
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2910
2950
  return __awaiter(this, void 0, void 0, function () {
2911
- var sessionInfo, error_25, exceptionDetails;
2951
+ var sessionInfo, error_26, exceptionDetails;
2912
2952
  return __generator(this, function (_a) {
2913
2953
  switch (_a.label) {
2914
2954
  case 0:
@@ -2936,7 +2976,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2936
2976
  });
2937
2977
  return [3 /*break*/, 5];
2938
2978
  case 4:
2939
- error_25 = _a.sent();
2979
+ error_26 = _a.sent();
2940
2980
  exceptionDetails = {
2941
2981
  response: "UpdateChatTokenFailed"
2942
2982
  };
@@ -2953,7 +2993,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2953
2993
  };
2954
2994
  OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
2955
2995
  return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
2956
- var token, exceptionDetails, error_26, exceptionDetails, exceptionDetails;
2996
+ var token, exceptionDetails, error_27, exceptionDetails, exceptionDetails;
2957
2997
  if (optionalParams === void 0) { optionalParams = {}; }
2958
2998
  return __generator(this, function (_a) {
2959
2999
  switch (_a.label) {
@@ -2985,12 +3025,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2985
3025
  }
2986
3026
  return [3 /*break*/, 4];
2987
3027
  case 3:
2988
- error_26 = _a.sent();
3028
+ error_27 = _a.sent();
2989
3029
  exceptionDetails = {
2990
3030
  response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
2991
3031
  };
2992
- if (error_26.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
2993
- exceptionDetails.response = error_26.message;
3032
+ if (error_27.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3033
+ exceptionDetails.response = error_27.message;
2994
3034
  }
2995
3035
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2996
3036
  ExceptionDetails: JSON.stringify(exceptionDetails)
@@ -3064,7 +3104,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3064
3104
  * and ensure a retry in startChat won't be affected with
3065
3105
  * data from a failed session
3066
3106
  */
3067
- return [4 /*yield*/, this.endChat()];
3107
+ return [4 /*yield*/, this.internalEndChat()];
3068
3108
  case 2:
3069
3109
  /**
3070
3110
  * Calling cleanup to take care of any session cleanup,
@@ -3083,6 +3123,67 @@ var OmnichannelChatSDK = /** @class */ (function () {
3083
3123
  });
3084
3124
  });
3085
3125
  };
3126
+ /**
3127
+ * Get persistent chat history for authenticated users.
3128
+ * @param getPersistentChatHistoryOptionalParams Optional parameters for persistent chat history retrieval.
3129
+ */
3130
+ OmnichannelChatSDK.prototype.getPersistentChatHistory = function () {
3131
+ return __awaiter(this, arguments, void 0, function (getPersistentChatHistoryOptionalParams) {
3132
+ var params, result, error_28, telemetryData;
3133
+ var _a, _b, _c, _d, _e;
3134
+ if (getPersistentChatHistoryOptionalParams === void 0) { getPersistentChatHistoryOptionalParams = {}; }
3135
+ return __generator(this, function (_f) {
3136
+ switch (_f.label) {
3137
+ case 0:
3138
+ if (!this.requestId) {
3139
+ this.requestId = (0, ocsdk_1.uuidv4)();
3140
+ }
3141
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3142
+ RequestId: this.requestId
3143
+ });
3144
+ if (!this.isInitialized) {
3145
+ exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory);
3146
+ }
3147
+ if (!this.isPersistentChat || ((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable) === true) {
3148
+ exceptionThrowers_1.default.throwNotPersistentChatEnabled(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3149
+ RequestId: this.requestId,
3150
+ ChatId: (_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId
3151
+ });
3152
+ }
3153
+ if (!this.authenticatedUserToken) {
3154
+ exceptionThrowers_1.default.throwChatSDKError(ChatSDKError_1.ChatSDKErrorName.AuthenticatedUserTokenNotFound, new Error('Authenticated user token not found'), this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3155
+ RequestId: this.requestId,
3156
+ ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId
3157
+ });
3158
+ }
3159
+ _f.label = 1;
3160
+ case 1:
3161
+ _f.trys.push([1, 3, , 4]);
3162
+ params = {};
3163
+ params.pageSize = getPersistentChatHistoryOptionalParams.pageSize || undefined;
3164
+ params.pageToken = getPersistentChatHistoryOptionalParams.pageToken || undefined;
3165
+ return [4 /*yield*/, this.OCClient.getPersistentChatHistory(this.requestId, __assign(__assign({}, params), { authenticatedUserToken: this.authenticatedUserToken }))];
3166
+ case 2:
3167
+ result = _f.sent();
3168
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3169
+ RequestId: this.requestId,
3170
+ ChatId: (_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId
3171
+ });
3172
+ return [2 /*return*/, result];
3173
+ case 3:
3174
+ error_28 = _f.sent();
3175
+ telemetryData = {
3176
+ RequestId: this.requestId,
3177
+ ChatId: (_e = this.chatToken) === null || _e === void 0 ? void 0 : _e.chatId,
3178
+ ErrorMessage: (error_28 === null || error_28 === void 0 ? void 0 : error_28.message) || 'Unknown error' // Added error message for better debugging
3179
+ };
3180
+ exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(error_28, this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, telemetryData);
3181
+ return [3 /*break*/, 4];
3182
+ case 4: return [2 /*return*/];
3183
+ }
3184
+ });
3185
+ });
3186
+ };
3086
3187
  return OmnichannelChatSDK;
3087
3188
  }());
3088
3189
  exports.default = OmnichannelChatSDK;