@microsoft/omnichannel-chat-sdk 1.11.5 → 1.11.6-main.5700642

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.
@@ -118,6 +118,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
118
118
  this.ACSClient = null;
119
119
  this.AMSClient = null;
120
120
  this.sessionId = null;
121
+ // Operation queue for serializing chat operations
122
+ this.chatOperationInProgress = false;
123
+ this.pendingOperations = [];
121
124
  this.unqServicesOrgUrl = null;
122
125
  this.coreServicesOrgUrl = null;
123
126
  this.dynamicsLocationCode = null;
@@ -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
  });
@@ -628,7 +684,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
628
684
  };
629
685
  OmnichannelChatSDK.prototype.getChatReconnectContextWithAuthToken = function () {
630
686
  return __awaiter(this, void 0, void 0, function () {
631
- var context, reconnectableChatsParams, reconnectableChatsResponse, error_2, exceptionDetails, telemetryData;
687
+ var context, reconnectableChatsParams, reconnectableChatsResponse, error_3, exceptionDetails, telemetryData;
632
688
  return __generator(this, function (_a) {
633
689
  switch (_a.label) {
634
690
  case 0:
@@ -659,7 +715,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
659
715
  });
660
716
  return [3 /*break*/, 4];
661
717
  case 3:
662
- error_2 = _a.sent();
718
+ error_3 = _a.sent();
663
719
  exceptionDetails = {
664
720
  response: "OCClientGetReconnectableChatsFailed"
665
721
  };
@@ -668,11 +724,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
668
724
  ChatId: this.chatToken.chatId,
669
725
  ExceptionDetails: JSON.stringify(exceptionDetails)
670
726
  };
671
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_2)) {
672
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_2, this.scenarioMarker, TelemetryEvent_1.default.GetChatReconnectContextWithAuthToken, telemetryData);
727
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_3)) {
728
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_3, this.scenarioMarker, TelemetryEvent_1.default.GetChatReconnectContextWithAuthToken, telemetryData);
673
729
  }
674
730
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetChatReconnectContextWithAuthToken, telemetryData);
675
- console.error("OmnichannelChatSDK/GetChatReconnectContextWithAuthToken/error ".concat(error_2));
731
+ console.error("OmnichannelChatSDK/GetChatReconnectContextWithAuthToken/error ".concat(error_3));
676
732
  return [3 /*break*/, 4];
677
733
  case 4: return [2 /*return*/, context];
678
734
  }
@@ -681,7 +737,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
681
737
  };
682
738
  OmnichannelChatSDK.prototype.getChatReconnectContextWithReconnectId = function () {
683
739
  return __awaiter(this, arguments, void 0, function (optionalParams) {
684
- var context, reconnectAvailabilityResponse, error_3, exceptionDetails;
740
+ var context, reconnectAvailabilityResponse, error_4, exceptionDetails;
685
741
  if (optionalParams === void 0) { optionalParams = {}; }
686
742
  return __generator(this, function (_a) {
687
743
  switch (_a.label) {
@@ -716,7 +772,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
716
772
  });
717
773
  return [3 /*break*/, 4];
718
774
  case 3:
719
- error_3 = _a.sent();
775
+ error_4 = _a.sent();
720
776
  exceptionDetails = {
721
777
  response: "OCClientGetReconnectAvailabilityFailed"
722
778
  };
@@ -725,7 +781,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
725
781
  ChatId: this.chatToken.chatId,
726
782
  ExceptionDetails: JSON.stringify(exceptionDetails)
727
783
  });
728
- console.error("OmnichannelChatSDK/GetChatReconnectContextWithReconnectId/error ".concat(error_3));
784
+ console.error("OmnichannelChatSDK/GetChatReconnectContextWithReconnectId/error ".concat(error_4));
729
785
  return [3 /*break*/, 4];
730
786
  case 4:
731
787
  //here the context contains recconnectionId if valid, or redirectionURL if not valid
@@ -780,7 +836,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
780
836
  };
781
837
  OmnichannelChatSDK.prototype.startChat = function () {
782
838
  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;
839
+ var _this = this;
840
+ if (optionalParams === void 0) { optionalParams = {}; }
841
+ return __generator(this, function (_a) {
842
+ return [2 /*return*/, this.executeWithLock(function () { return _this.internalStartChat(optionalParams); })];
843
+ });
844
+ });
845
+ };
846
+ OmnichannelChatSDK.prototype.internalStartChat = function () {
847
+ return __awaiter(this, arguments, void 0, function (optionalParams) {
848
+ var shouldReinitIC3Client, _a, reconnectableChatsParams, reconnectableChatsResponse, e_6, telemetryData, conversationDetails, telemetryData, telemetryData, e_7, telemetryData, sessionInitOptionalParams, location_2, sessionInitPromise, createConversationPromise, messagingClientPromise, attachmentClientPromise, error_5;
784
849
  var _this = this;
785
850
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
786
851
  if (optionalParams === void 0) { optionalParams = {}; }
@@ -919,7 +984,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
919
984
  _o.label = 18;
920
985
  case 18:
921
986
  sessionInitPromise = function () { return __awaiter(_this, void 0, void 0, function () {
922
- var error_5, telemetryData;
987
+ var error_6, telemetryData;
923
988
  var _a, _b, _c;
924
989
  return __generator(this, function (_d) {
925
990
  switch (_d.label) {
@@ -933,23 +998,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
933
998
  _d.sent();
934
999
  return [3 /*break*/, 4];
935
1000
  case 3:
936
- error_5 = _d.sent();
1001
+ error_6 = _d.sent();
937
1002
  telemetryData = {
938
1003
  RequestId: this.requestId,
939
1004
  ChatId: this.chatToken.chatId,
940
1005
  };
941
1006
  // 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);
1007
+ 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()) {
1008
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
944
1009
  }
945
- exceptionThrowers_1.default.throwConversationInitializationFailure(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1010
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
946
1011
  return [3 /*break*/, 4];
947
1012
  case 4: return [2 /*return*/];
948
1013
  }
949
1014
  });
950
1015
  }); };
951
1016
  createConversationPromise = function () { return __awaiter(_this, void 0, void 0, function () {
952
- var chatToken, error_6, telemetryData;
1017
+ var chatToken, error_7, telemetryData;
953
1018
  var _a, _b, _c;
954
1019
  return __generator(this, function (_d) {
955
1020
  switch (_d.label) {
@@ -967,23 +1032,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
967
1032
  }
968
1033
  return [3 /*break*/, 4];
969
1034
  case 3:
970
- error_6 = _d.sent();
1035
+ error_7 = _d.sent();
971
1036
  telemetryData = {
972
1037
  RequestId: this.requestId,
973
1038
  ChatId: this.chatToken.chatId,
974
1039
  };
975
1040
  // 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);
1041
+ 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()) {
1042
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
978
1043
  }
979
- exceptionThrowers_1.default.throwConversationInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1044
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
980
1045
  return [3 /*break*/, 4];
981
1046
  case 4: return [2 /*return*/];
982
1047
  }
983
1048
  });
984
1049
  }); };
985
1050
  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;
1051
+ var chatAdapterConfig, error_8, telemetryData, _a, error_9, telemetryData, error_10, telemetryData, _b, error_11, telemetryData;
987
1052
  var _c, _d;
988
1053
  return __generator(this, function (_e) {
989
1054
  switch (_e.label) {
@@ -1007,12 +1072,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1007
1072
  _e.sent();
1008
1073
  return [3 /*break*/, 4];
1009
1074
  case 3:
1010
- error_7 = _e.sent();
1075
+ error_8 = _e.sent();
1011
1076
  telemetryData = {
1012
1077
  RequestId: this.requestId,
1013
1078
  ChatId: this.chatToken.chatId,
1014
1079
  };
1015
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1080
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1016
1081
  return [3 /*break*/, 4];
1017
1082
  case 4:
1018
1083
  _e.trys.push([4, 6, , 7]);
@@ -1030,12 +1095,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1030
1095
  });
1031
1096
  return [3 /*break*/, 7];
1032
1097
  case 6:
1033
- error_8 = _e.sent();
1098
+ error_9 = _e.sent();
1034
1099
  telemetryData = {
1035
1100
  RequestId: this.requestId,
1036
1101
  ChatId: this.chatToken.chatId,
1037
1102
  };
1038
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1103
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_9, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1039
1104
  return [3 /*break*/, 7];
1040
1105
  case 7: return [3 /*break*/, 14];
1041
1106
  case 8:
@@ -1049,12 +1114,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1049
1114
  _e.sent();
1050
1115
  return [3 /*break*/, 11];
1051
1116
  case 10:
1052
- error_9 = _e.sent();
1117
+ error_10 = _e.sent();
1053
1118
  telemetryData = {
1054
1119
  RequestId: this.requestId,
1055
1120
  ChatId: this.chatToken.chatId,
1056
1121
  };
1057
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_9, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1122
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_10, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1058
1123
  return [3 /*break*/, 11];
1059
1124
  case 11:
1060
1125
  _e.trys.push([11, 13, , 14]);
@@ -1068,19 +1133,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
1068
1133
  });
1069
1134
  return [3 /*break*/, 14];
1070
1135
  case 13:
1071
- error_10 = _e.sent();
1136
+ error_11 = _e.sent();
1072
1137
  telemetryData = {
1073
1138
  RequestId: this.requestId,
1074
1139
  ChatId: this.chatToken.chatId,
1075
1140
  };
1076
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_10, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1141
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_11, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1077
1142
  return [3 /*break*/, 14];
1078
1143
  case 14: return [2 /*return*/];
1079
1144
  }
1080
1145
  });
1081
1146
  }); };
1082
1147
  attachmentClientPromise = function () { return __awaiter(_this, void 0, void 0, function () {
1083
- var amsClient, error_11, telemetryData;
1148
+ var amsClient, error_12, telemetryData;
1084
1149
  return __generator(this, function (_a) {
1085
1150
  switch (_a.label) {
1086
1151
  case 0:
@@ -1100,7 +1165,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1100
1165
  _a.label = 3;
1101
1166
  case 3: return [3 /*break*/, 5];
1102
1167
  case 4:
1103
- error_11 = _a.sent();
1168
+ error_12 = _a.sent();
1104
1169
  telemetryData = {
1105
1170
  RequestId: this.requestId,
1106
1171
  ChatId: this.chatToken.chatId,
@@ -1127,15 +1192,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1127
1192
  _o.sent();
1128
1193
  return [3 /*break*/, 26];
1129
1194
  case 24:
1130
- error_4 = _o.sent();
1195
+ error_5 = _o.sent();
1131
1196
  // If conversation joining fails after conversation was created, clean up the conversation
1132
1197
  // Only cleanup conversations that were freshly created (not existing ones being reconnected to)
1133
- return [4 /*yield*/, this.handleConversationJoinFailure(error_4, optionalParams)];
1198
+ return [4 /*yield*/, this.handleConversationJoinFailure(error_5, optionalParams)];
1134
1199
  case 25:
1135
1200
  // If conversation joining fails after conversation was created, clean up the conversation
1136
1201
  // Only cleanup conversations that were freshly created (not existing ones being reconnected to)
1137
1202
  _o.sent();
1138
- throw error_4; // Re-throw the original error
1203
+ throw error_5; // Re-throw the original error
1139
1204
  case 26:
1140
1205
  if (this.isPersistentChat && !((_l = this.chatSDKConfig.persistentChat) === null || _l === void 0 ? void 0 : _l.disable)) {
1141
1206
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -1157,7 +1222,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1157
1222
  };
1158
1223
  OmnichannelChatSDK.prototype.closeChat = function (endChatOptionalParams) {
1159
1224
  return __awaiter(this, void 0, void 0, function () {
1160
- var cleanupMetadata, sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_12;
1225
+ var cleanupMetadata, sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_13;
1161
1226
  var _a, _b;
1162
1227
  return __generator(this, function (_c) {
1163
1228
  switch (_c.label) {
@@ -1192,8 +1257,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1192
1257
  _c.sent();
1193
1258
  return [3 /*break*/, 4];
1194
1259
  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)) }));
1260
+ error_13 = _c.sent();
1261
+ exceptionThrowers_1.default.throwConversationClosureFailure(error_13, this.scenarioMarker, TelemetryEvent_1.default.CloseChatSession, __assign(__assign({}, cleanupMetadata), { isSessionEnded: String(!(endChatOptionalParams === null || endChatOptionalParams === void 0 ? void 0 : endChatOptionalParams.isSessionEnded)) }));
1197
1262
  return [3 /*break*/, 4];
1198
1263
  case 4:
1199
1264
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CloseChatSession, cleanupMetadata);
@@ -1205,7 +1270,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1205
1270
  };
1206
1271
  OmnichannelChatSDK.prototype.endChat = function () {
1207
1272
  return __awaiter(this, arguments, void 0, function (endChatOptionalParams) {
1208
- var cleanupMetadata, error_13, telemetryData;
1273
+ var _this = this;
1274
+ if (endChatOptionalParams === void 0) { endChatOptionalParams = {}; }
1275
+ return __generator(this, function (_a) {
1276
+ return [2 /*return*/, this.executeWithLock(function () { return _this.internalEndChat(endChatOptionalParams); })];
1277
+ });
1278
+ });
1279
+ };
1280
+ OmnichannelChatSDK.prototype.internalEndChat = function () {
1281
+ return __awaiter(this, arguments, void 0, function (endChatOptionalParams) {
1282
+ var cleanupMetadata, error_14, telemetryData;
1209
1283
  var _a;
1210
1284
  if (endChatOptionalParams === void 0) { endChatOptionalParams = {}; }
1211
1285
  return __generator(this, function (_b) {
@@ -1255,15 +1329,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1255
1329
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, cleanupMetadata);
1256
1330
  return [3 /*break*/, 7];
1257
1331
  case 6:
1258
- error_13 = _b.sent();
1332
+ error_14 = _b.sent();
1259
1333
  telemetryData = {
1260
1334
  RequestId: this.requestId,
1261
1335
  ChatId: this.chatToken.chatId
1262
1336
  };
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);
1337
+ if (error_14 instanceof ChatSDKError_1.ChatSDKError) {
1338
+ exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_14.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1265
1339
  }
1266
- exceptionThrowers_1.default.throwConversationClosureFailure(error_13, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1340
+ exceptionThrowers_1.default.throwConversationClosureFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1267
1341
  return [3 /*break*/, 7];
1268
1342
  case 7: return [2 /*return*/];
1269
1343
  }
@@ -1310,7 +1384,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1310
1384
  };
1311
1385
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
1312
1386
  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;
1387
+ var requestId, chatToken, chatId, reconnectId, sessionId, getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_15, telemetryData;
1314
1388
  var _a, _b, _c, _d;
1315
1389
  if (optionalParams === void 0) { optionalParams = {}; }
1316
1390
  return __generator(this, function (_e) {
@@ -1383,15 +1457,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1383
1457
  });
1384
1458
  return [2 /*return*/, liveWorkItemDetails];
1385
1459
  case 3:
1386
- error_14 = _e.sent();
1460
+ error_15 = _e.sent();
1387
1461
  telemetryData = {
1388
1462
  RequestId: requestId,
1389
1463
  ChatId: chatId
1390
1464
  };
1391
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_14)) {
1392
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1465
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_15)) {
1466
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1393
1467
  }
1394
- exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1468
+ exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1395
1469
  return [3 /*break*/, 4];
1396
1470
  case 4: return [2 /*return*/, {}];
1397
1471
  }
@@ -1432,7 +1506,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1432
1506
  };
1433
1507
  OmnichannelChatSDK.prototype.getChatToken = function () {
1434
1508
  return __awaiter(this, arguments, void 0, function (cached, optionalParams) {
1435
- var getChatTokenOptionalParams, chatToken, error_15, telemetryData;
1509
+ var getChatTokenOptionalParams, chatToken, error_16, telemetryData;
1436
1510
  var _a, _b, _c;
1437
1511
  if (cached === void 0) { cached = true; }
1438
1512
  return __generator(this, function (_d) {
@@ -1474,16 +1548,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1474
1548
  });
1475
1549
  return [3 /*break*/, 4];
1476
1550
  case 3:
1477
- error_15 = _d.sent();
1551
+ error_16 = _d.sent();
1478
1552
  telemetryData = {
1479
1553
  RequestId: this.requestId,
1480
1554
  ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId,
1481
1555
  };
1482
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_15)) {
1483
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1556
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_16)) {
1557
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_16, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1484
1558
  }
1485
1559
  else {
1486
- exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1560
+ exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_16, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1487
1561
  }
1488
1562
  return [3 /*break*/, 4];
1489
1563
  case 4: return [3 /*break*/, 6];
@@ -1627,7 +1701,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1627
1701
  };
1628
1702
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
1629
1703
  return __awaiter(this, void 0, void 0, function () {
1630
- var sendMessageRequest, chatMessage, error_16, exceptionDetails, messageToSend, error_17, exceptionDetails;
1704
+ var sendMessageRequest, chatMessage, error_17, exceptionDetails, messageToSend, error_18, exceptionDetails;
1631
1705
  var _a;
1632
1706
  return __generator(this, function (_b) {
1633
1707
  switch (_b.label) {
@@ -1663,10 +1737,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1663
1737
  });
1664
1738
  return [2 /*return*/, chatMessage];
1665
1739
  case 3:
1666
- error_16 = _b.sent();
1740
+ error_17 = _b.sent();
1667
1741
  exceptionDetails = {
1668
1742
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1669
- errorObject: "".concat(error_16)
1743
+ errorObject: "".concat(error_17)
1670
1744
  };
1671
1745
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1672
1746
  RequestId: this.requestId,
@@ -1675,7 +1749,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1675
1749
  });
1676
1750
  throw new ChatSDKError_1.ChatSDKError(ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed, undefined, {
1677
1751
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1678
- errorObject: "".concat(error_16)
1752
+ errorObject: "".concat(error_17)
1679
1753
  });
1680
1754
  case 4: return [3 /*break*/, 9];
1681
1755
  case 5:
@@ -1711,10 +1785,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1711
1785
  });
1712
1786
  return [3 /*break*/, 9];
1713
1787
  case 8:
1714
- error_17 = _b.sent();
1788
+ error_18 = _b.sent();
1715
1789
  exceptionDetails = {
1716
1790
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1717
- errorObject: "".concat(error_17)
1791
+ errorObject: "".concat(error_18)
1718
1792
  };
1719
1793
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1720
1794
  RequestId: this.requestId,
@@ -1801,7 +1875,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1801
1875
  };
1802
1876
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
1803
1877
  return __awaiter(this, void 0, void 0, function () {
1804
- var error_18;
1878
+ var error_19;
1805
1879
  return __generator(this, function (_a) {
1806
1880
  switch (_a.label) {
1807
1881
  case 0:
@@ -1830,7 +1904,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1830
1904
  });
1831
1905
  return [3 /*break*/, 5];
1832
1906
  case 4:
1833
- error_18 = _a.sent();
1907
+ error_19 = _a.sent();
1834
1908
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1835
1909
  RequestId: this.requestId,
1836
1910
  ChatId: this.chatToken.chatId
@@ -1967,7 +2041,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1967
2041
  };
1968
2042
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
1969
2043
  return __awaiter(this, void 0, void 0, function () {
1970
- var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_19, fileMetadata, messageToSend, error_20;
2044
+ var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_20, fileMetadata, messageToSend, error_21;
1971
2045
  var _a, _b;
1972
2046
  return __generator(this, function (_c) {
1973
2047
  switch (_c.label) {
@@ -2036,7 +2110,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2036
2110
  });
2037
2111
  return [2 /*return*/, messageToSend];
2038
2112
  case 6:
2039
- error_19 = _c.sent();
2113
+ error_20 = _c.sent();
2040
2114
  console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
2041
2115
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2042
2116
  RequestId: this.requestId,
@@ -2082,8 +2156,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2082
2156
  });
2083
2157
  return [2 /*return*/, messageToSend];
2084
2158
  case 15:
2085
- error_20 = _c.sent();
2086
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_20));
2159
+ error_21 = _c.sent();
2160
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_21));
2087
2161
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2088
2162
  RequestId: this.requestId,
2089
2163
  ChatId: this.chatToken.chatId
@@ -2096,7 +2170,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2096
2170
  };
2097
2171
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
2098
2172
  return __awaiter(this, void 0, void 0, function () {
2099
- var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
2173
+ var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_22;
2100
2174
  return __generator(this, function (_b) {
2101
2175
  switch (_b.label) {
2102
2176
  case 0:
@@ -2156,8 +2230,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2156
2230
  });
2157
2231
  return [2 /*return*/, downloadedFile];
2158
2232
  case 9:
2159
- error_21 = _b.sent();
2160
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_21));
2233
+ error_22 = _b.sent();
2234
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_22));
2161
2235
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2162
2236
  RequestId: this.requestId,
2163
2237
  ChatId: this.chatToken.chatId
@@ -2170,7 +2244,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2170
2244
  };
2171
2245
  OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
2172
2246
  return __awaiter(this, arguments, void 0, function (body, optionalParams) {
2173
- var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_22;
2247
+ var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_23;
2174
2248
  var _a;
2175
2249
  if (optionalParams === void 0) { optionalParams = {}; }
2176
2250
  return __generator(this, function (_b) {
@@ -2221,8 +2295,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2221
2295
  });
2222
2296
  return [3 /*break*/, 4];
2223
2297
  case 3:
2224
- error_22 = _b.sent();
2225
- console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_22));
2298
+ error_23 = _b.sent();
2299
+ console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_23));
2226
2300
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
2227
2301
  RequestId: requestId,
2228
2302
  ChatId: chatId
@@ -2235,7 +2309,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2235
2309
  };
2236
2310
  OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
2237
2311
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2238
- var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_23, telemetryData;
2312
+ var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_24, telemetryData;
2239
2313
  var _a, _b;
2240
2314
  if (optionalParams === void 0) { optionalParams = {}; }
2241
2315
  return __generator(this, function (_c) {
@@ -2292,12 +2366,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2292
2366
  });
2293
2367
  return [2 /*return*/, transcriptResponse];
2294
2368
  case 3:
2295
- error_23 = _c.sent();
2369
+ error_24 = _c.sent();
2296
2370
  telemetryData = {
2297
2371
  RequestId: requestId,
2298
2372
  ChatId: chatId
2299
2373
  };
2300
- exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_23, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2374
+ exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_24, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2301
2375
  return [3 /*break*/, 4];
2302
2376
  case 4: return [2 /*return*/];
2303
2377
  }
@@ -2836,7 +2910,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2836
2910
  };
2837
2911
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2838
2912
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2839
- var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
2913
+ var sendCacheHeaders, bypassCache, liveChatConfig, error_25, _a;
2840
2914
  var _b, _c;
2841
2915
  if (optionalParams === void 0) { optionalParams = {}; }
2842
2916
  return __generator(this, function (_d) {
@@ -2857,8 +2931,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2857
2931
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
2858
2932
  return [2 /*return*/, this.liveChatConfig];
2859
2933
  case 3:
2860
- error_24 = _d.sent();
2861
- if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_24, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2934
+ error_25 = _d.sent();
2935
+ if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_25, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2862
2936
  this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
2863
2937
  _a = this;
2864
2938
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
@@ -2870,10 +2944,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2870
2944
  return [3 /*break*/, 7];
2871
2945
  case 6:
2872
2946
  // 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) {
2947
+ 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
2948
  console.warn("No widget with the given app id is present in the system.");
2875
2949
  }
2876
- throw error_24; // Bubble up error by default to throw ChatConfigRetrievalFailure
2950
+ throw error_25; // Bubble up error by default to throw ChatConfigRetrievalFailure
2877
2951
  case 7: return [3 /*break*/, 8];
2878
2952
  case 8: return [2 /*return*/, this.liveChatConfig];
2879
2953
  }
@@ -2908,7 +2982,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2908
2982
  };
2909
2983
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2910
2984
  return __awaiter(this, void 0, void 0, function () {
2911
- var sessionInfo, error_25, exceptionDetails;
2985
+ var sessionInfo, error_26, exceptionDetails;
2912
2986
  return __generator(this, function (_a) {
2913
2987
  switch (_a.label) {
2914
2988
  case 0:
@@ -2936,7 +3010,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2936
3010
  });
2937
3011
  return [3 /*break*/, 5];
2938
3012
  case 4:
2939
- error_25 = _a.sent();
3013
+ error_26 = _a.sent();
2940
3014
  exceptionDetails = {
2941
3015
  response: "UpdateChatTokenFailed"
2942
3016
  };
@@ -2953,7 +3027,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2953
3027
  };
2954
3028
  OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
2955
3029
  return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
2956
- var token, exceptionDetails, error_26, exceptionDetails, exceptionDetails;
3030
+ var token, exceptionDetails, error_27, exceptionDetails, exceptionDetails;
2957
3031
  if (optionalParams === void 0) { optionalParams = {}; }
2958
3032
  return __generator(this, function (_a) {
2959
3033
  switch (_a.label) {
@@ -2985,12 +3059,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2985
3059
  }
2986
3060
  return [3 /*break*/, 4];
2987
3061
  case 3:
2988
- error_26 = _a.sent();
3062
+ error_27 = _a.sent();
2989
3063
  exceptionDetails = {
2990
3064
  response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
2991
3065
  };
2992
- if (error_26.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
2993
- exceptionDetails.response = error_26.message;
3066
+ if (error_27.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3067
+ exceptionDetails.response = error_27.message;
2994
3068
  }
2995
3069
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2996
3070
  ExceptionDetails: JSON.stringify(exceptionDetails)
@@ -3064,7 +3138,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3064
3138
  * and ensure a retry in startChat won't be affected with
3065
3139
  * data from a failed session
3066
3140
  */
3067
- return [4 /*yield*/, this.endChat()];
3141
+ return [4 /*yield*/, this.internalEndChat()];
3068
3142
  case 2:
3069
3143
  /**
3070
3144
  * Calling cleanup to take care of any session cleanup,