@microsoft/omnichannel-chat-sdk 1.11.6-main.b982edb → 1.11.7-main.3418dc3

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
@@ -1898,8 +1972,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1898
1972
  OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
1899
1973
  return __awaiter(this, void 0, void 0, function () {
1900
1974
  var _this = this;
1901
- var _a;
1902
- return __generator(this, function (_b) {
1975
+ return __generator(this, function (_a) {
1903
1976
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1904
1977
  RequestId: this.requestId,
1905
1978
  ChatId: this.chatToken.chatId
@@ -1907,59 +1980,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
1907
1980
  if (!this.isInitialized) {
1908
1981
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.OnAgentEndSession);
1909
1982
  }
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
- }
1983
+ try {
1984
+ this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
1985
+ var liveWorkItemDetails;
1986
+ return __generator(this, function (_a) {
1987
+ switch (_a.label) {
1988
+ case 0: return [4 /*yield*/, this.getConversationDetails()];
1989
+ case 1:
1990
+ liveWorkItemDetails = _a.sent();
1991
+ if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
1992
+ onAgentEndSessionCallback(event);
1993
+ this.stopPolling();
1994
+ }
1995
+ return [2 /*return*/];
1950
1996
  }
1951
1997
  });
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
- }
1998
+ }); });
1999
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2000
+ RequestId: this.requestId,
2001
+ ChatId: this.chatToken.chatId
2002
+ });
2003
+ }
2004
+ catch (error) {
2005
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2006
+ RequestId: this.requestId,
2007
+ ChatId: this.chatToken.chatId
2008
+ });
1963
2009
  }
1964
2010
  return [2 /*return*/];
1965
2011
  });
@@ -1967,7 +2013,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1967
2013
  };
1968
2014
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
1969
2015
  return __awaiter(this, void 0, void 0, function () {
1970
- var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_19, fileMetadata, messageToSend, error_20;
2016
+ var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_20, fileMetadata, messageToSend, error_21;
1971
2017
  var _a, _b;
1972
2018
  return __generator(this, function (_c) {
1973
2019
  switch (_c.label) {
@@ -2036,7 +2082,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2036
2082
  });
2037
2083
  return [2 /*return*/, messageToSend];
2038
2084
  case 6:
2039
- error_19 = _c.sent();
2085
+ error_20 = _c.sent();
2040
2086
  console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
2041
2087
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2042
2088
  RequestId: this.requestId,
@@ -2082,8 +2128,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2082
2128
  });
2083
2129
  return [2 /*return*/, messageToSend];
2084
2130
  case 15:
2085
- error_20 = _c.sent();
2086
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_20));
2131
+ error_21 = _c.sent();
2132
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_21));
2087
2133
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2088
2134
  RequestId: this.requestId,
2089
2135
  ChatId: this.chatToken.chatId
@@ -2096,7 +2142,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2096
2142
  };
2097
2143
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
2098
2144
  return __awaiter(this, void 0, void 0, function () {
2099
- var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
2145
+ var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_22;
2100
2146
  return __generator(this, function (_b) {
2101
2147
  switch (_b.label) {
2102
2148
  case 0:
@@ -2156,8 +2202,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2156
2202
  });
2157
2203
  return [2 /*return*/, downloadedFile];
2158
2204
  case 9:
2159
- error_21 = _b.sent();
2160
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_21));
2205
+ error_22 = _b.sent();
2206
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_22));
2161
2207
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2162
2208
  RequestId: this.requestId,
2163
2209
  ChatId: this.chatToken.chatId
@@ -2170,7 +2216,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2170
2216
  };
2171
2217
  OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
2172
2218
  return __awaiter(this, arguments, void 0, function (body, optionalParams) {
2173
- var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_22;
2219
+ var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_23;
2174
2220
  var _a;
2175
2221
  if (optionalParams === void 0) { optionalParams = {}; }
2176
2222
  return __generator(this, function (_b) {
@@ -2221,8 +2267,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2221
2267
  });
2222
2268
  return [3 /*break*/, 4];
2223
2269
  case 3:
2224
- error_22 = _b.sent();
2225
- console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_22));
2270
+ error_23 = _b.sent();
2271
+ console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_23));
2226
2272
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
2227
2273
  RequestId: requestId,
2228
2274
  ChatId: chatId
@@ -2235,7 +2281,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2235
2281
  };
2236
2282
  OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
2237
2283
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2238
- var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_23, telemetryData;
2284
+ var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_24, telemetryData;
2239
2285
  var _a, _b;
2240
2286
  if (optionalParams === void 0) { optionalParams = {}; }
2241
2287
  return __generator(this, function (_c) {
@@ -2292,12 +2338,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2292
2338
  });
2293
2339
  return [2 /*return*/, transcriptResponse];
2294
2340
  case 3:
2295
- error_23 = _c.sent();
2341
+ error_24 = _c.sent();
2296
2342
  telemetryData = {
2297
2343
  RequestId: requestId,
2298
2344
  ChatId: chatId
2299
2345
  };
2300
- exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_23, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2346
+ exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_24, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2301
2347
  return [3 /*break*/, 4];
2302
2348
  case 4: return [2 /*return*/];
2303
2349
  }
@@ -2412,7 +2458,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2412
2458
  };
2413
2459
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
2414
2460
  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;
2461
+ 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
2462
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2417
2463
  return __generator(this, function (_o) {
2418
2464
  switch (_o.label) {
@@ -2426,7 +2472,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2426
2472
  }
2427
2473
  _o.label = 1;
2428
2474
  case 1:
2429
- _o.trys.push([1, 8, , 9]);
2475
+ _o.trys.push([1, 6, , 7]);
2430
2476
  chatConfig = this.liveChatConfig;
2431
2477
  liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
2432
2478
  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 +2485,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2439
2485
  });
2440
2486
  return [2 /*return*/, Promise.reject("GetPostChatSurveyContext : msfp_sourcesurveyidentifier is mandatory for survey provider ".concat(SurveyProvider_1.SurveyProvider.CustomerVoice, "."))];
2441
2487
  }
2442
- if (!((0, parsers_1.parseLowerCaseString)(msdyn_postconversationsurveyenable) === "true")) return [3 /*break*/, 6];
2488
+ if (!((0, parsers_1.parseLowerCaseString)(msdyn_postconversationsurveyenable) === "true")) return [3 /*break*/, 4];
2443
2489
  return [4 /*yield*/, this.getConversationDetails()];
2444
2490
  case 2:
2445
2491
  liveWorkItemDetails = _o.sent();
@@ -2482,17 +2528,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
2482
2528
  if (this.authenticatedUserToken) {
2483
2529
  optionalParams.authenticatedUserToken = this.authenticatedUserToken;
2484
2530
  }
2485
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams)];
2531
+ return [4 /*yield*/, Promise.all([
2532
+ this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams),
2533
+ (postConversationBotSurveyOwnerId && msfp_botsourcesurveyidentifier)
2534
+ ? this.OCClient.getSurveyInviteLink(postConversationBotSurveyOwnerId, botSurveyInviteLinkRequest, optionalParams)
2535
+ : Promise.resolve(null)
2536
+ ])];
2486
2537
  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;
2538
+ _a = _o.sent(), agentSurveyInviteLinkResponse = _a[0], botSurveyInviteLinkResponse = _a[1];
2496
2539
  agentSurveyInviteLink = void 0, agentFormsProLocale = void 0, botSurveyInviteLink = void 0, botFormsProLocale = void 0;
2497
2540
  if (agentSurveyInviteLinkResponse != null) {
2498
2541
  if (agentSurveyInviteLinkResponse.inviteList != null && agentSurveyInviteLinkResponse.inviteList.length == 1) {
@@ -2541,16 +2584,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
2541
2584
  });
2542
2585
  return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
2543
2586
  }
2544
- return [3 /*break*/, 7];
2545
- case 6:
2587
+ return [3 /*break*/, 5];
2588
+ case 4:
2546
2589
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
2547
2590
  RequestId: this.requestId,
2548
2591
  ChatId: (_l = this.chatToken) === null || _l === void 0 ? void 0 : _l.chatId,
2549
2592
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
2550
2593
  });
2551
2594
  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:
2595
+ case 5: return [3 /*break*/, 7];
2596
+ case 6:
2554
2597
  ex_1 = _o.sent();
2555
2598
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
2556
2599
  ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
@@ -2559,7 +2602,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2559
2602
  ExceptionDetails: JSON.stringify(ex_1)
2560
2603
  });
2561
2604
  return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
2562
- case 9: return [2 /*return*/];
2605
+ case 7: return [2 /*return*/];
2563
2606
  }
2564
2607
  });
2565
2608
  });
@@ -2836,7 +2879,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2836
2879
  };
2837
2880
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2838
2881
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2839
- var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
2882
+ var sendCacheHeaders, bypassCache, liveChatConfig, error_25, _a;
2840
2883
  var _b, _c;
2841
2884
  if (optionalParams === void 0) { optionalParams = {}; }
2842
2885
  return __generator(this, function (_d) {
@@ -2857,8 +2900,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2857
2900
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
2858
2901
  return [2 /*return*/, this.liveChatConfig];
2859
2902
  case 3:
2860
- error_24 = _d.sent();
2861
- if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_24, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2903
+ error_25 = _d.sent();
2904
+ if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_25, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2862
2905
  this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
2863
2906
  _a = this;
2864
2907
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
@@ -2870,10 +2913,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2870
2913
  return [3 /*break*/, 7];
2871
2914
  case 6:
2872
2915
  // 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) {
2916
+ 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
2917
  console.warn("No widget with the given app id is present in the system.");
2875
2918
  }
2876
- throw error_24; // Bubble up error by default to throw ChatConfigRetrievalFailure
2919
+ throw error_25; // Bubble up error by default to throw ChatConfigRetrievalFailure
2877
2920
  case 7: return [3 /*break*/, 8];
2878
2921
  case 8: return [2 /*return*/, this.liveChatConfig];
2879
2922
  }
@@ -2908,7 +2951,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2908
2951
  };
2909
2952
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2910
2953
  return __awaiter(this, void 0, void 0, function () {
2911
- var sessionInfo, error_25, exceptionDetails;
2954
+ var sessionInfo, error_26, exceptionDetails;
2912
2955
  return __generator(this, function (_a) {
2913
2956
  switch (_a.label) {
2914
2957
  case 0:
@@ -2936,7 +2979,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2936
2979
  });
2937
2980
  return [3 /*break*/, 5];
2938
2981
  case 4:
2939
- error_25 = _a.sent();
2982
+ error_26 = _a.sent();
2940
2983
  exceptionDetails = {
2941
2984
  response: "UpdateChatTokenFailed"
2942
2985
  };
@@ -2953,7 +2996,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2953
2996
  };
2954
2997
  OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
2955
2998
  return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
2956
- var token, exceptionDetails, error_26, exceptionDetails, exceptionDetails;
2999
+ var token, exceptionDetails, error_27, exceptionDetails, exceptionDetails;
2957
3000
  if (optionalParams === void 0) { optionalParams = {}; }
2958
3001
  return __generator(this, function (_a) {
2959
3002
  switch (_a.label) {
@@ -2985,12 +3028,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2985
3028
  }
2986
3029
  return [3 /*break*/, 4];
2987
3030
  case 3:
2988
- error_26 = _a.sent();
3031
+ error_27 = _a.sent();
2989
3032
  exceptionDetails = {
2990
3033
  response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
2991
3034
  };
2992
- if (error_26.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
2993
- exceptionDetails.response = error_26.message;
3035
+ if (error_27.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3036
+ exceptionDetails.response = error_27.message;
2994
3037
  }
2995
3038
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2996
3039
  ExceptionDetails: JSON.stringify(exceptionDetails)
@@ -3064,7 +3107,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3064
3107
  * and ensure a retry in startChat won't be affected with
3065
3108
  * data from a failed session
3066
3109
  */
3067
- return [4 /*yield*/, this.endChat()];
3110
+ return [4 /*yield*/, this.internalEndChat()];
3068
3111
  case 2:
3069
3112
  /**
3070
3113
  * Calling cleanup to take care of any session cleanup,
@@ -3083,6 +3126,67 @@ var OmnichannelChatSDK = /** @class */ (function () {
3083
3126
  });
3084
3127
  });
3085
3128
  };
3129
+ /**
3130
+ * Get persistent chat history for authenticated users.
3131
+ * @param getPersistentChatHistoryOptionalParams Optional parameters for persistent chat history retrieval.
3132
+ */
3133
+ OmnichannelChatSDK.prototype.getPersistentChatHistory = function () {
3134
+ return __awaiter(this, arguments, void 0, function (getPersistentChatHistoryOptionalParams) {
3135
+ var params, result, error_28, telemetryData;
3136
+ var _a, _b, _c, _d, _e;
3137
+ if (getPersistentChatHistoryOptionalParams === void 0) { getPersistentChatHistoryOptionalParams = {}; }
3138
+ return __generator(this, function (_f) {
3139
+ switch (_f.label) {
3140
+ case 0:
3141
+ if (!this.requestId) {
3142
+ this.requestId = (0, ocsdk_1.uuidv4)();
3143
+ }
3144
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3145
+ RequestId: this.requestId
3146
+ });
3147
+ if (!this.isInitialized) {
3148
+ exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory);
3149
+ }
3150
+ if (!this.isPersistentChat || ((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable) === true) {
3151
+ exceptionThrowers_1.default.throwNotPersistentChatEnabled(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3152
+ RequestId: this.requestId,
3153
+ ChatId: (_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId
3154
+ });
3155
+ }
3156
+ if (!this.authenticatedUserToken) {
3157
+ exceptionThrowers_1.default.throwChatSDKError(ChatSDKError_1.ChatSDKErrorName.AuthenticatedUserTokenNotFound, new Error('Authenticated user token not found'), this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3158
+ RequestId: this.requestId,
3159
+ ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId
3160
+ });
3161
+ }
3162
+ _f.label = 1;
3163
+ case 1:
3164
+ _f.trys.push([1, 3, , 4]);
3165
+ params = {};
3166
+ params.pageSize = getPersistentChatHistoryOptionalParams.pageSize || undefined;
3167
+ params.pageToken = getPersistentChatHistoryOptionalParams.pageToken || undefined;
3168
+ return [4 /*yield*/, this.OCClient.getPersistentChatHistory(this.requestId, __assign(__assign({}, params), { authenticatedUserToken: this.authenticatedUserToken }))];
3169
+ case 2:
3170
+ result = _f.sent();
3171
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3172
+ RequestId: this.requestId,
3173
+ ChatId: (_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId
3174
+ });
3175
+ return [2 /*return*/, result];
3176
+ case 3:
3177
+ error_28 = _f.sent();
3178
+ telemetryData = {
3179
+ RequestId: this.requestId,
3180
+ ChatId: (_e = this.chatToken) === null || _e === void 0 ? void 0 : _e.chatId,
3181
+ ErrorMessage: (error_28 === null || error_28 === void 0 ? void 0 : error_28.message) || 'Unknown error' // Added error message for better debugging
3182
+ };
3183
+ exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(error_28, this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, telemetryData);
3184
+ return [3 /*break*/, 4];
3185
+ case 4: return [2 /*return*/];
3186
+ }
3187
+ });
3188
+ });
3189
+ };
3086
3190
  return OmnichannelChatSDK;
3087
3191
  }());
3088
3192
  exports.default = OmnichannelChatSDK;