@microsoft/omnichannel-chat-sdk 1.11.3-main.ad7ffbc → 1.11.3

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.
@@ -163,5 +163,14 @@ declare class OmnichannelChatSDK {
163
163
  private updateChatToken;
164
164
  private setAuthTokenProvider;
165
165
  private useCoreServicesOrgUrlIfNotSet;
166
+ /**
167
+ * Handles cleanup of failed conversation join attempts.
168
+ * Only cleans up conversations that were freshly created and failed to join.
169
+ *
170
+ * @param error - The error that occurred during conversation join
171
+ * @param optionalParams - Start chat optional parameters
172
+ * @private
173
+ */
174
+ private handleConversationJoinFailure;
166
175
  }
167
176
  export default OmnichannelChatSDK;
@@ -68,7 +68,7 @@ var locale_1 = require("./utils/locale");
68
68
  var exceptionThrowers_1 = require("./utils/exceptionThrowers");
69
69
  var utilities_1 = require("./utils/utilities");
70
70
  var WebUtils_1 = require("./utils/WebUtils");
71
- var platform_1 = require("./utils/platform");
71
+ var AMSClientUtils_1 = require("./utils/AMSClientUtils");
72
72
  var SDKConfigValidators_1 = require("./validators/SDKConfigValidators");
73
73
  var ACSParticipantDisplayName_1 = require("./core/messaging/ACSParticipantDisplayName");
74
74
  var AMSClientLoadStates_1 = require("./utils/AMSClientLoadStates");
@@ -102,13 +102,13 @@ var location_1 = require("./utils/location");
102
102
  var internalUtils_1 = require("./utils/internalUtils");
103
103
  var loggerUtils_1 = require("./utils/loggerUtils");
104
104
  var parsers_1 = require("./utils/parsers");
105
+ var platform_1 = require("./utils/platform");
105
106
  var retrieveCollectorUri_1 = require("./telemetry/retrieveCollectorUri");
106
107
  var setOcUserAgent_1 = require("./utils/setOcUserAgent");
107
108
  var startPolling_1 = require("./commands/startPolling");
108
109
  var stopPolling_1 = require("./commands/stopPolling");
109
110
  var urlResolvers_1 = require("./utils/urlResolvers");
110
111
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
111
- var AMSClientUtils_1 = require("./utils/AMSClientUtils");
112
112
  var OmnichannelChatSDK = /** @class */ (function () {
113
113
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
114
114
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
@@ -778,7 +778,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
778
778
  };
779
779
  OmnichannelChatSDK.prototype.startChat = function () {
780
780
  return __awaiter(this, arguments, void 0, function (optionalParams) {
781
- var shouldReinitIC3Client, _a, reconnectableChatsParams, reconnectableChatsResponse, e_6, telemetryData, conversationDetails, telemetryData, telemetryData, e_7, telemetryData, sessionInitOptionalParams, location_2, sessionInitPromise, createConversationPromise, messagingClientPromise, attachmentClientPromise;
781
+ var shouldReinitIC3Client, _a, reconnectableChatsParams, reconnectableChatsResponse, e_6, telemetryData, conversationDetails, telemetryData, telemetryData, e_7, telemetryData, sessionInitOptionalParams, location_2, sessionInitPromise, createConversationPromise, messagingClientPromise, attachmentClientPromise, error_4;
782
782
  var _this = this;
783
783
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
784
784
  if (optionalParams === void 0) { optionalParams = {}; }
@@ -917,7 +917,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
917
917
  _o.label = 18;
918
918
  case 18:
919
919
  sessionInitPromise = function () { return __awaiter(_this, void 0, void 0, function () {
920
- var error_4, telemetryData;
920
+ var error_5, telemetryData;
921
921
  var _a, _b, _c;
922
922
  return __generator(this, function (_d) {
923
923
  switch (_d.label) {
@@ -931,23 +931,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
931
931
  _d.sent();
932
932
  return [3 /*break*/, 4];
933
933
  case 3:
934
- error_4 = _d.sent();
934
+ error_5 = _d.sent();
935
935
  telemetryData = {
936
936
  RequestId: this.requestId,
937
937
  ChatId: this.chatToken.chatId,
938
938
  };
939
939
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
940
- if ((error_4 === null || error_4 === void 0 ? void 0 : error_4.isAxiosError) && ((_c = (_b = (_a = error_4.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()) {
941
- exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_4, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
940
+ 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()) {
941
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
942
942
  }
943
- exceptionThrowers_1.default.throwConversationInitializationFailure(error_4, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
943
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
944
944
  return [3 /*break*/, 4];
945
945
  case 4: return [2 /*return*/];
946
946
  }
947
947
  });
948
948
  }); };
949
949
  createConversationPromise = function () { return __awaiter(_this, void 0, void 0, function () {
950
- var chatToken, error_5, telemetryData;
950
+ var chatToken, error_6, telemetryData;
951
951
  var _a, _b, _c;
952
952
  return __generator(this, function (_d) {
953
953
  switch (_d.label) {
@@ -965,23 +965,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
965
965
  }
966
966
  return [3 /*break*/, 4];
967
967
  case 3:
968
- error_5 = _d.sent();
968
+ error_6 = _d.sent();
969
969
  telemetryData = {
970
970
  RequestId: this.requestId,
971
971
  ChatId: this.chatToken.chatId,
972
972
  };
973
973
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
974
- 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()) {
975
- exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
974
+ 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()) {
975
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
976
976
  }
977
- exceptionThrowers_1.default.throwConversationInitializationFailure(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
977
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
978
978
  return [3 /*break*/, 4];
979
979
  case 4: return [2 /*return*/];
980
980
  }
981
981
  });
982
982
  }); };
983
983
  messagingClientPromise = function () { return __awaiter(_this, void 0, void 0, function () {
984
- var chatAdapterConfig, error_6, telemetryData, _a, error_7, telemetryData, error_8, telemetryData, _b, error_9, telemetryData;
984
+ var chatAdapterConfig, error_7, telemetryData, _a, error_8, telemetryData, error_9, telemetryData, _b, error_10, telemetryData;
985
985
  var _c, _d;
986
986
  return __generator(this, function (_e) {
987
987
  switch (_e.label) {
@@ -1005,12 +1005,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1005
1005
  _e.sent();
1006
1006
  return [3 /*break*/, 4];
1007
1007
  case 3:
1008
- error_6 = _e.sent();
1008
+ error_7 = _e.sent();
1009
1009
  telemetryData = {
1010
1010
  RequestId: this.requestId,
1011
1011
  ChatId: this.chatToken.chatId,
1012
1012
  };
1013
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1013
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1014
1014
  return [3 /*break*/, 4];
1015
1015
  case 4:
1016
1016
  _e.trys.push([4, 6, , 7]);
@@ -1028,12 +1028,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1028
1028
  });
1029
1029
  return [3 /*break*/, 7];
1030
1030
  case 6:
1031
- error_7 = _e.sent();
1031
+ error_8 = _e.sent();
1032
1032
  telemetryData = {
1033
1033
  RequestId: this.requestId,
1034
1034
  ChatId: this.chatToken.chatId,
1035
1035
  };
1036
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1036
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1037
1037
  return [3 /*break*/, 7];
1038
1038
  case 7: return [3 /*break*/, 14];
1039
1039
  case 8:
@@ -1047,12 +1047,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1047
1047
  _e.sent();
1048
1048
  return [3 /*break*/, 11];
1049
1049
  case 10:
1050
- error_8 = _e.sent();
1050
+ error_9 = _e.sent();
1051
1051
  telemetryData = {
1052
1052
  RequestId: this.requestId,
1053
1053
  ChatId: this.chatToken.chatId,
1054
1054
  };
1055
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1055
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_9, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1056
1056
  return [3 /*break*/, 11];
1057
1057
  case 11:
1058
1058
  _e.trys.push([11, 13, , 14]);
@@ -1066,19 +1066,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
1066
1066
  });
1067
1067
  return [3 /*break*/, 14];
1068
1068
  case 13:
1069
- error_9 = _e.sent();
1069
+ error_10 = _e.sent();
1070
1070
  telemetryData = {
1071
1071
  RequestId: this.requestId,
1072
1072
  ChatId: this.chatToken.chatId,
1073
1073
  };
1074
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_9, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1074
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_10, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1075
1075
  return [3 /*break*/, 14];
1076
1076
  case 14: return [2 /*return*/];
1077
1077
  }
1078
1078
  });
1079
1079
  }); };
1080
1080
  attachmentClientPromise = function () { return __awaiter(_this, void 0, void 0, function () {
1081
- var amsClient, error_10, telemetryData;
1081
+ var amsClient, error_11, telemetryData;
1082
1082
  return __generator(this, function (_a) {
1083
1083
  switch (_a.label) {
1084
1084
  case 0:
@@ -1098,12 +1098,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
1098
1098
  _a.label = 3;
1099
1099
  case 3: return [3 /*break*/, 5];
1100
1100
  case 4:
1101
- error_10 = _a.sent();
1101
+ error_11 = _a.sent();
1102
1102
  telemetryData = {
1103
1103
  RequestId: this.requestId,
1104
1104
  ChatId: this.chatToken.chatId,
1105
1105
  };
1106
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_10, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1106
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_11, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
1107
1107
  return [3 /*break*/, 5];
1108
1108
  case 5: return [2 /*return*/];
1109
1109
  }
@@ -1118,9 +1118,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
1118
1118
  case 21:
1119
1119
  _o.sent(); // Await the session initialization
1120
1120
  _o.label = 22;
1121
- case 22: return [4 /*yield*/, Promise.all([messagingClientPromise(), attachmentClientPromise()])];
1121
+ case 22:
1122
+ _o.trys.push([22, 24, , 26]);
1123
+ return [4 /*yield*/, Promise.all([messagingClientPromise(), attachmentClientPromise()])];
1122
1124
  case 23:
1123
1125
  _o.sent();
1126
+ return [3 /*break*/, 26];
1127
+ case 24:
1128
+ error_4 = _o.sent();
1129
+ // If conversation joining fails after conversation was created, clean up the conversation
1130
+ // Only cleanup conversations that were freshly created (not existing ones being reconnected to)
1131
+ return [4 /*yield*/, this.handleConversationJoinFailure(error_4, optionalParams)];
1132
+ case 25:
1133
+ // If conversation joining fails after conversation was created, clean up the conversation
1134
+ // Only cleanup conversations that were freshly created (not existing ones being reconnected to)
1135
+ _o.sent();
1136
+ throw error_4; // Re-throw the original error
1137
+ case 26:
1124
1138
  if (this.isPersistentChat && !((_l = this.chatSDKConfig.persistentChat) === null || _l === void 0 ? void 0 : _l.disable)) {
1125
1139
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
1126
1140
  return __generator(this, function (_a) {
@@ -1141,7 +1155,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1141
1155
  };
1142
1156
  OmnichannelChatSDK.prototype.closeChat = function (endChatOptionalParams) {
1143
1157
  return __awaiter(this, void 0, void 0, function () {
1144
- var cleanupMetadata, sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_11;
1158
+ var cleanupMetadata, sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_12;
1145
1159
  var _a, _b;
1146
1160
  return __generator(this, function (_c) {
1147
1161
  switch (_c.label) {
@@ -1176,8 +1190,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
1176
1190
  _c.sent();
1177
1191
  return [3 /*break*/, 4];
1178
1192
  case 3:
1179
- error_11 = _c.sent();
1180
- exceptionThrowers_1.default.throwConversationClosureFailure(error_11, this.scenarioMarker, TelemetryEvent_1.default.CloseChatSession, __assign(__assign({}, cleanupMetadata), { isSessionEnded: String(!(endChatOptionalParams === null || endChatOptionalParams === void 0 ? void 0 : endChatOptionalParams.isSessionEnded)) }));
1193
+ error_12 = _c.sent();
1194
+ 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)) }));
1181
1195
  return [3 /*break*/, 4];
1182
1196
  case 4:
1183
1197
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.CloseChatSession, cleanupMetadata);
@@ -1189,7 +1203,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1189
1203
  };
1190
1204
  OmnichannelChatSDK.prototype.endChat = function () {
1191
1205
  return __awaiter(this, arguments, void 0, function (endChatOptionalParams) {
1192
- var cleanupMetadata, error_12, telemetryData;
1206
+ var cleanupMetadata, error_13, telemetryData;
1193
1207
  var _a;
1194
1208
  if (endChatOptionalParams === void 0) { endChatOptionalParams = {}; }
1195
1209
  return __generator(this, function (_b) {
@@ -1239,15 +1253,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1239
1253
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.EndChat, cleanupMetadata);
1240
1254
  return [3 /*break*/, 7];
1241
1255
  case 6:
1242
- error_12 = _b.sent();
1256
+ error_13 = _b.sent();
1243
1257
  telemetryData = {
1244
1258
  RequestId: this.requestId,
1245
1259
  ChatId: this.chatToken.chatId
1246
1260
  };
1247
- if (error_12 instanceof ChatSDKError_1.ChatSDKError) {
1248
- exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_12.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1261
+ if (error_13 instanceof ChatSDKError_1.ChatSDKError) {
1262
+ exceptionThrowers_1.default.throwConversationClosureFailure(new Error(JSON.stringify(error_13.exceptionDetails)), this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1249
1263
  }
1250
- exceptionThrowers_1.default.throwConversationClosureFailure(error_12, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1264
+ exceptionThrowers_1.default.throwConversationClosureFailure(error_13, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
1251
1265
  return [3 /*break*/, 7];
1252
1266
  case 7: return [2 /*return*/];
1253
1267
  }
@@ -1294,7 +1308,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1294
1308
  };
1295
1309
  OmnichannelChatSDK.prototype.getConversationDetails = function () {
1296
1310
  return __awaiter(this, arguments, void 0, function (optionalParams) {
1297
- var requestId, chatToken, chatId, reconnectId, sessionId, getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_13, telemetryData;
1311
+ var requestId, chatToken, chatId, reconnectId, sessionId, getLWIDetailsOptionalParams, lwiDetails, state, conversationId, agentAcceptedOn, canRenderPostChat, participantType, liveWorkItemDetails, error_14, telemetryData;
1298
1312
  var _a, _b, _c, _d;
1299
1313
  if (optionalParams === void 0) { optionalParams = {}; }
1300
1314
  return __generator(this, function (_e) {
@@ -1367,15 +1381,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1367
1381
  });
1368
1382
  return [2 /*return*/, liveWorkItemDetails];
1369
1383
  case 3:
1370
- error_13 = _e.sent();
1384
+ error_14 = _e.sent();
1371
1385
  telemetryData = {
1372
1386
  RequestId: requestId,
1373
- ChatId: chatId || ''
1387
+ ChatId: chatId
1374
1388
  };
1375
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_13)) {
1376
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_13, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1389
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_14)) {
1390
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1377
1391
  }
1378
- exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(error_13, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1392
+ exceptionSuppressors_1.default.suppressConversationDetailsRetrievalFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetConversationDetails, telemetryData);
1379
1393
  return [3 /*break*/, 4];
1380
1394
  case 4: return [2 /*return*/, {}];
1381
1395
  }
@@ -1416,7 +1430,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1416
1430
  };
1417
1431
  OmnichannelChatSDK.prototype.getChatToken = function () {
1418
1432
  return __awaiter(this, arguments, void 0, function (cached, optionalParams) {
1419
- var getChatTokenOptionalParams, chatToken, error_14, telemetryData;
1433
+ var getChatTokenOptionalParams, chatToken, error_15, telemetryData;
1420
1434
  var _a, _b, _c;
1421
1435
  if (cached === void 0) { cached = true; }
1422
1436
  return __generator(this, function (_d) {
@@ -1458,16 +1472,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
1458
1472
  });
1459
1473
  return [3 /*break*/, 4];
1460
1474
  case 3:
1461
- error_14 = _d.sent();
1475
+ error_15 = _d.sent();
1462
1476
  telemetryData = {
1463
1477
  RequestId: this.requestId,
1464
1478
  ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId,
1465
1479
  };
1466
- if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_14)) {
1467
- exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1480
+ if ((0, utilities_1.isClientIdNotFoundErrorMessage)(error_15)) {
1481
+ exceptionThrowers_1.default.throwAuthContactIdNotFoundFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1468
1482
  }
1469
1483
  else {
1470
- exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_14, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1484
+ exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_15, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
1471
1485
  }
1472
1486
  return [3 /*break*/, 4];
1473
1487
  case 4: return [3 /*break*/, 6];
@@ -1611,7 +1625,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1611
1625
  };
1612
1626
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
1613
1627
  return __awaiter(this, void 0, void 0, function () {
1614
- var sendMessageRequest, chatMessage, error_15, exceptionDetails, messageToSend, error_16, exceptionDetails;
1628
+ var sendMessageRequest, chatMessage, error_16, exceptionDetails, messageToSend, error_17, exceptionDetails;
1615
1629
  var _a;
1616
1630
  return __generator(this, function (_b) {
1617
1631
  switch (_b.label) {
@@ -1647,10 +1661,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1647
1661
  });
1648
1662
  return [2 /*return*/, chatMessage];
1649
1663
  case 3:
1650
- error_15 = _b.sent();
1664
+ error_16 = _b.sent();
1651
1665
  exceptionDetails = {
1652
1666
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1653
- errorObject: "".concat(error_15)
1667
+ errorObject: "".concat(error_16)
1654
1668
  };
1655
1669
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1656
1670
  RequestId: this.requestId,
@@ -1659,7 +1673,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1659
1673
  });
1660
1674
  throw new ChatSDKError_1.ChatSDKError(ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed, undefined, {
1661
1675
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1662
- errorObject: "".concat(error_15)
1676
+ errorObject: "".concat(error_16)
1663
1677
  });
1664
1678
  case 4: return [3 /*break*/, 9];
1665
1679
  case 5:
@@ -1695,10 +1709,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
1695
1709
  });
1696
1710
  return [3 /*break*/, 9];
1697
1711
  case 8:
1698
- error_16 = _b.sent();
1712
+ error_17 = _b.sent();
1699
1713
  exceptionDetails = {
1700
1714
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1701
- errorObject: "".concat(error_16)
1715
+ errorObject: "".concat(error_17)
1702
1716
  };
1703
1717
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1704
1718
  RequestId: this.requestId,
@@ -1785,7 +1799,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1785
1799
  };
1786
1800
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
1787
1801
  return __awaiter(this, void 0, void 0, function () {
1788
- var error_17;
1802
+ var error_18;
1789
1803
  return __generator(this, function (_a) {
1790
1804
  switch (_a.label) {
1791
1805
  case 0:
@@ -1814,7 +1828,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1814
1828
  });
1815
1829
  return [3 /*break*/, 5];
1816
1830
  case 4:
1817
- error_17 = _a.sent();
1831
+ error_18 = _a.sent();
1818
1832
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1819
1833
  RequestId: this.requestId,
1820
1834
  ChatId: this.chatToken.chatId
@@ -1951,7 +1965,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1951
1965
  };
1952
1966
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
1953
1967
  return __awaiter(this, void 0, void 0, function () {
1954
- var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_18, fileMetadata, messageToSend, error_19;
1968
+ var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_19, fileMetadata, messageToSend, error_20;
1955
1969
  var _a, _b;
1956
1970
  return __generator(this, function (_c) {
1957
1971
  switch (_c.label) {
@@ -2020,7 +2034,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2020
2034
  });
2021
2035
  return [2 /*return*/, messageToSend];
2022
2036
  case 6:
2023
- error_18 = _c.sent();
2037
+ error_19 = _c.sent();
2024
2038
  console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
2025
2039
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2026
2040
  RequestId: this.requestId,
@@ -2066,8 +2080,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2066
2080
  });
2067
2081
  return [2 /*return*/, messageToSend];
2068
2082
  case 15:
2069
- error_19 = _c.sent();
2070
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_19));
2083
+ error_20 = _c.sent();
2084
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_20));
2071
2085
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2072
2086
  RequestId: this.requestId,
2073
2087
  ChatId: this.chatToken.chatId
@@ -2080,7 +2094,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2080
2094
  };
2081
2095
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
2082
2096
  return __awaiter(this, void 0, void 0, function () {
2083
- var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_20;
2097
+ var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
2084
2098
  return __generator(this, function (_b) {
2085
2099
  switch (_b.label) {
2086
2100
  case 0:
@@ -2140,8 +2154,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2140
2154
  });
2141
2155
  return [2 /*return*/, downloadedFile];
2142
2156
  case 9:
2143
- error_20 = _b.sent();
2144
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_20));
2157
+ error_21 = _b.sent();
2158
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_21));
2145
2159
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2146
2160
  RequestId: this.requestId,
2147
2161
  ChatId: this.chatToken.chatId
@@ -2154,7 +2168,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2154
2168
  };
2155
2169
  OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
2156
2170
  return __awaiter(this, arguments, void 0, function (body, optionalParams) {
2157
- var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_21;
2171
+ var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_22;
2158
2172
  var _a;
2159
2173
  if (optionalParams === void 0) { optionalParams = {}; }
2160
2174
  return __generator(this, function (_b) {
@@ -2205,8 +2219,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2205
2219
  });
2206
2220
  return [3 /*break*/, 4];
2207
2221
  case 3:
2208
- error_21 = _b.sent();
2209
- console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_21));
2222
+ error_22 = _b.sent();
2223
+ console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_22));
2210
2224
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
2211
2225
  RequestId: requestId,
2212
2226
  ChatId: chatId
@@ -2219,7 +2233,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2219
2233
  };
2220
2234
  OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
2221
2235
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2222
- var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_22, telemetryData;
2236
+ var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_23, telemetryData;
2223
2237
  var _a, _b;
2224
2238
  if (optionalParams === void 0) { optionalParams = {}; }
2225
2239
  return __generator(this, function (_c) {
@@ -2276,12 +2290,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2276
2290
  });
2277
2291
  return [2 /*return*/, transcriptResponse];
2278
2292
  case 3:
2279
- error_22 = _c.sent();
2293
+ error_23 = _c.sent();
2280
2294
  telemetryData = {
2281
2295
  RequestId: requestId,
2282
2296
  ChatId: chatId
2283
2297
  };
2284
- exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_22, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2298
+ exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_23, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2285
2299
  return [3 /*break*/, 4];
2286
2300
  case 4: return [2 /*return*/];
2287
2301
  }
@@ -2803,7 +2817,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2803
2817
  };
2804
2818
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2805
2819
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2806
- var sendCacheHeaders, bypassCache, liveChatConfig, error_23, _a;
2820
+ var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
2807
2821
  var _b, _c;
2808
2822
  if (optionalParams === void 0) { optionalParams = {}; }
2809
2823
  return __generator(this, function (_d) {
@@ -2824,8 +2838,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2824
2838
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
2825
2839
  return [2 /*return*/, this.liveChatConfig];
2826
2840
  case 3:
2827
- error_23 = _d.sent();
2828
- if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_23, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2841
+ error_24 = _d.sent();
2842
+ if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_24, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2829
2843
  this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
2830
2844
  _a = this;
2831
2845
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
@@ -2837,10 +2851,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2837
2851
  return [3 /*break*/, 7];
2838
2852
  case 6:
2839
2853
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2840
- if (((_c = (_b = error_23.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_23.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
2854
+ 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) {
2841
2855
  console.warn("No widget with the given app id is present in the system.");
2842
2856
  }
2843
- throw error_23; // Bubble up error by default to throw ChatConfigRetrievalFailure
2857
+ throw error_24; // Bubble up error by default to throw ChatConfigRetrievalFailure
2844
2858
  case 7: return [3 /*break*/, 8];
2845
2859
  case 8: return [2 /*return*/, this.liveChatConfig];
2846
2860
  }
@@ -2875,7 +2889,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2875
2889
  };
2876
2890
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2877
2891
  return __awaiter(this, void 0, void 0, function () {
2878
- var sessionInfo, error_24, exceptionDetails;
2892
+ var sessionInfo, error_25, exceptionDetails;
2879
2893
  return __generator(this, function (_a) {
2880
2894
  switch (_a.label) {
2881
2895
  case 0:
@@ -2903,7 +2917,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2903
2917
  });
2904
2918
  return [3 /*break*/, 5];
2905
2919
  case 4:
2906
- error_24 = _a.sent();
2920
+ error_25 = _a.sent();
2907
2921
  exceptionDetails = {
2908
2922
  response: "UpdateChatTokenFailed"
2909
2923
  };
@@ -2920,7 +2934,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2920
2934
  };
2921
2935
  OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
2922
2936
  return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
2923
- var token, exceptionDetails, error_25, exceptionDetails, exceptionDetails;
2937
+ var token, exceptionDetails, error_26, exceptionDetails, exceptionDetails;
2924
2938
  if (optionalParams === void 0) { optionalParams = {}; }
2925
2939
  return __generator(this, function (_a) {
2926
2940
  switch (_a.label) {
@@ -2952,12 +2966,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2952
2966
  }
2953
2967
  return [3 /*break*/, 4];
2954
2968
  case 3:
2955
- error_25 = _a.sent();
2969
+ error_26 = _a.sent();
2956
2970
  exceptionDetails = {
2957
2971
  response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
2958
2972
  };
2959
- if (error_25.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
2960
- exceptionDetails.response = error_25.message;
2973
+ if (error_26.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
2974
+ exceptionDetails.response = error_26.message;
2961
2975
  }
2962
2976
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
2963
2977
  ExceptionDetails: JSON.stringify(exceptionDetails)
@@ -3002,6 +3016,54 @@ var OmnichannelChatSDK = /** @class */ (function () {
3002
3016
  }
3003
3017
  }
3004
3018
  };
3019
+ /**
3020
+ * Handles cleanup of failed conversation join attempts.
3021
+ * Only cleans up conversations that were freshly created and failed to join.
3022
+ *
3023
+ * @param error - The error that occurred during conversation join
3024
+ * @param optionalParams - Start chat optional parameters
3025
+ * @private
3026
+ */
3027
+ OmnichannelChatSDK.prototype.handleConversationJoinFailure = function (error, optionalParams) {
3028
+ return __awaiter(this, void 0, void 0, function () {
3029
+ var shouldCleanup, cleanupError_1;
3030
+ var _a;
3031
+ return __generator(this, function (_b) {
3032
+ switch (_b.label) {
3033
+ case 0:
3034
+ shouldCleanup = error instanceof ChatSDKError_1.ChatSDKError &&
3035
+ (error === null || error === void 0 ? void 0 : error.message) === ChatSDKError_1.ChatSDKErrorName.MessagingClientConversationJoinFailure &&
3036
+ !((_a = this.chatSDKConfig.useCreateConversation) === null || _a === void 0 ? void 0 : _a.disable) &&
3037
+ !(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0) &&
3038
+ !this.reconnectId;
3039
+ if (!shouldCleanup) return [3 /*break*/, 4];
3040
+ _b.label = 1;
3041
+ case 1:
3042
+ _b.trys.push([1, 3, , 4]);
3043
+ /**
3044
+ * Calling cleanup to take care of any session cleanup,
3045
+ * and ensure a retry in startChat won't be affected with
3046
+ * data from a failed session
3047
+ */
3048
+ return [4 /*yield*/, this.endChat()];
3049
+ case 2:
3050
+ /**
3051
+ * Calling cleanup to take care of any session cleanup,
3052
+ * and ensure a retry in startChat won't be affected with
3053
+ * data from a failed session
3054
+ */
3055
+ _b.sent();
3056
+ return [3 /*break*/, 4];
3057
+ case 3:
3058
+ cleanupError_1 = _b.sent();
3059
+ // Don't let cleanup errors mask the original error
3060
+ this.debug && console.error('Failed to cleanup conversation after join failure:', cleanupError_1);
3061
+ return [3 /*break*/, 4];
3062
+ case 4: return [2 /*return*/];
3063
+ }
3064
+ });
3065
+ });
3066
+ };
3005
3067
  return OmnichannelChatSDK;
3006
3068
  }());
3007
3069
  exports.default = OmnichannelChatSDK;