@microsoft/omnichannel-chat-sdk 1.3.0 → 1.3.1-main.559caa3

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.
@@ -87,6 +87,7 @@ var createOmnichannelMessage_1 = require("./utils/createOmnichannelMessage");
87
87
  var createTelemetry_1 = require("./utils/createTelemetry");
88
88
  var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
89
89
  var MessageTags_1 = require("./core/messaging/MessageTags");
90
+ var exceptionThrowers_1 = require("./utils/exceptionThrowers");
90
91
  var location_1 = require("./utils/location");
91
92
  var utilities_1 = require("./utils/utilities");
92
93
  var urlResolvers_1 = require("./utils/urlResolvers");
@@ -113,7 +114,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
113
114
  this.isChatReconnect = false;
114
115
  this.reconnectId = null;
115
116
  this.refreshTokenTimer = null;
116
- this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams) {
117
+ this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
117
118
  requestOptionalParams.initContext.locale = locale_1.getLocaleStringFromId(_this.localeId);
118
119
  if (optionalParams.customContext) {
119
120
  requestOptionalParams.initContext.customContextData = optionalParams.customContext; // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -138,17 +139,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
138
139
  }
139
140
  if (optionalParams.sendDefaultInitContext) {
140
141
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
141
- var exceptionDetails = {
142
- response: ChatSDKErrors_1.default.UnsupportedPlatform,
143
- message: "sendDefaultInitContext is only supported on browser"
144
- };
145
- console.error(exceptionDetails.message);
146
- _this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAgentAvailability, {
142
+ var message = "sendDefaultInitContext is only supported on browser";
143
+ var telemetryData = {
147
144
  RequestId: _this.requestId,
148
- ChatId: _this.chatToken.chatId,
149
- ExceptionDetails: JSON.stringify(exceptionDetails)
150
- });
151
- throw new Error(exceptionDetails.response);
145
+ ChatId: _this.chatToken.chatId
146
+ };
147
+ exceptionThrowers_1.default.throwUnsupportedPlatform(_this.scenarioMarker, telemetryEvent, message, telemetryData);
152
148
  }
153
149
  requestOptionalParams.getContext = true;
154
150
  }
@@ -231,7 +227,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
231
227
  OmnichannelChatSDK.prototype.initialize = function (optionalParams) {
232
228
  if (optionalParams === void 0) { optionalParams = {}; }
233
229
  return __awaiter(this, void 0, void 0, function () {
234
- var _a, getLiveChatConfigOptionalParams, _b, _c, e_1;
230
+ var _a, e_1, getLiveChatConfigOptionalParams, e_2, supportedLiveChatVersions, _b, _c, e_3;
235
231
  return __generator(this, function (_d) {
236
232
  switch (_d.label) {
237
233
  case 0:
@@ -242,17 +238,37 @@ var OmnichannelChatSDK = /** @class */ (function () {
242
238
  }
243
239
  _d.label = 1;
244
240
  case 1:
245
- _d.trys.push([1, 9, , 10]);
241
+ _d.trys.push([1, 3, , 4]);
246
242
  this.OCSDKProvider = ocsdk_1.SDKProvider;
247
243
  _a = this;
248
244
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, {}, this.ocSdkLogger)];
249
245
  case 2:
250
246
  _a.OCClient = _d.sent();
247
+ return [3 /*break*/, 4];
248
+ case 3:
249
+ e_1 = _d.sent();
250
+ exceptionThrowers_1.default.throwOmnichannelClientInitializationFailure(e_1, this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
251
+ return [3 /*break*/, 4];
252
+ case 4:
253
+ _d.trys.push([4, 6, , 7]);
251
254
  getLiveChatConfigOptionalParams = optionalParams.getLiveChatConfigOptionalParams;
252
255
  return [4 /*yield*/, this.getChatConfig(getLiveChatConfigOptionalParams || {})];
253
- case 3:
256
+ case 5:
254
257
  _d.sent();
255
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
258
+ return [3 /*break*/, 7];
259
+ case 6:
260
+ e_2 = _d.sent();
261
+ exceptionThrowers_1.default.throwChatConfigRetrievalFailure(e_2, this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
262
+ return [3 /*break*/, 7];
263
+ case 7:
264
+ supportedLiveChatVersions = [LiveChatVersion_1.default.V1, LiveChatVersion_1.default.V2];
265
+ if (!supportedLiveChatVersions.includes(this.liveChatVersion)) {
266
+ exceptionThrowers_1.default.throwUnsupportedLiveChatVersionFailure(new Error(ChatSDKErrors_1.default.UnsupportedLiveChatVersion), this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
267
+ }
268
+ _d.label = 8;
269
+ case 8:
270
+ _d.trys.push([8, 13, , 14]);
271
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 10];
256
272
  this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
257
273
  _b = this;
258
274
  return [4 /*yield*/, omnichannel_amsclient_1.default({
@@ -261,28 +277,25 @@ var OmnichannelChatSDK = /** @class */ (function () {
261
277
  debug: false,
262
278
  logger: this.amsClientLogger
263
279
  })];
264
- case 4:
280
+ case 9:
265
281
  _b.AMSClient = _d.sent();
266
- return [3 /*break*/, 8];
267
- case 5:
268
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 7];
282
+ return [3 /*break*/, 12];
283
+ case 10:
284
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 12];
269
285
  _c = this;
270
286
  return [4 /*yield*/, this.getIC3Client()];
271
- case 6:
287
+ case 11:
272
288
  _c.IC3Client = _d.sent();
273
- return [3 /*break*/, 8];
274
- case 7: throw new Error("Unsupported LiveChatVersion");
275
- case 8:
289
+ _d.label = 12;
290
+ case 12:
276
291
  this.isInitialized = true;
277
292
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
278
- return [3 /*break*/, 10];
279
- case 9:
280
- e_1 = _d.sent();
281
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.InitializeChatSDK, {
282
- ExceptionDetails: JSON.stringify(e_1)
283
- });
284
- return [3 /*break*/, 10];
285
- case 10: return [2 /*return*/, this.liveChatConfig];
293
+ return [3 /*break*/, 14];
294
+ case 13:
295
+ e_3 = _d.sent();
296
+ exceptionThrowers_1.default.throwMessagingClientCreationFailure(e_3, this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
297
+ return [3 /*break*/, 14];
298
+ case 14: return [2 /*return*/, this.liveChatConfig];
286
299
  }
287
300
  });
288
301
  });
@@ -375,116 +388,108 @@ var OmnichannelChatSDK = /** @class */ (function () {
375
388
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
376
389
  if (optionalParams === void 0) { optionalParams = {}; }
377
390
  return __awaiter(this, void 0, void 0, function () {
378
- var shouldReinitIC3Client, _w, reconnectableChatsParams, reconnectableChatsResponse, _x, exceptionDetails, conversationDetails, exceptionDetails, exceptionDetails, _y, exceptionDetails, sessionInitOptionalParams, location_2, error_3, exceptionDetails, chatAdapterConfig, error_4, exceptionDetails, _z, error_5, exceptionDetails, error_6, exceptionDetails, error_7, exceptionDetails, _0, error_8, exceptionDetails;
391
+ var shouldReinitIC3Client, _w, reconnectableChatsParams, reconnectableChatsResponse, e_4, telemetryData, conversationDetails, telemetryData, telemetryData, e_5, telemetryData, sessionInitOptionalParams, location_2, error_3, telemetryData, chatAdapterConfig, error_4, telemetryData, _x, error_5, telemetryData, error_6, telemetryData, error_7, telemetryData, _y, error_8, telemetryData;
379
392
  var _this = this;
380
- return __generator(this, function (_1) {
381
- switch (_1.label) {
393
+ return __generator(this, function (_z) {
394
+ switch (_z.label) {
382
395
  case 0:
383
396
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
384
397
  RequestId: this.requestId
385
398
  });
399
+ if (!this.isInitialized) {
400
+ exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.StartChat);
401
+ }
386
402
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
387
403
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
388
404
  _w = this;
389
405
  return [4 /*yield*/, this.getIC3Client()];
390
406
  case 1:
391
- _w.IC3Client = _1.sent();
392
- _1.label = 2;
407
+ _w.IC3Client = _z.sent();
408
+ _z.label = 2;
393
409
  case 2:
394
410
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
395
411
  this.reconnectId = optionalParams.reconnectId;
396
412
  }
397
413
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
398
- _1.label = 3;
414
+ _z.label = 3;
399
415
  case 3:
400
- _1.trys.push([3, 5, , 6]);
416
+ _z.trys.push([3, 5, , 6]);
401
417
  reconnectableChatsParams = {
402
418
  authenticatedUserToken: this.authenticatedUserToken
403
419
  };
404
420
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
405
421
  case 4:
406
- reconnectableChatsResponse = _1.sent();
422
+ reconnectableChatsResponse = _z.sent();
407
423
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
408
424
  this.reconnectId = reconnectableChatsResponse.reconnectid;
409
425
  }
410
426
  return [3 /*break*/, 6];
411
427
  case 5:
412
- _x = _1.sent();
413
- exceptionDetails = {
414
- response: "OCClientGetReconnectableChatsFailed"
428
+ e_4 = _z.sent();
429
+ telemetryData = {
430
+ RequestId: this.requestId,
431
+ ChatId: this.chatToken.chatId,
415
432
  };
416
- throw Error(exceptionDetails.response);
433
+ exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(e_4, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
434
+ return [3 /*break*/, 6];
417
435
  case 6:
418
436
  if (!(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0 && !this.reconnectId)) return [3 /*break*/, 8];
419
437
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
420
438
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
421
439
  return [4 /*yield*/, this.getConversationDetails()];
422
440
  case 7:
423
- conversationDetails = _1.sent();
441
+ conversationDetails = _z.sent();
424
442
  if (Object.keys(conversationDetails).length === 0) {
425
- exceptionDetails = {
426
- response: "InvalidConversation"
427
- };
428
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
443
+ telemetryData = {
429
444
  RequestId: this.requestId,
430
445
  ChatId: this.chatToken.chatId,
431
- ExceptionDetails: JSON.stringify(exceptionDetails)
432
- });
433
- console.error("Conversation not found");
434
- throw Error(exceptionDetails.response);
446
+ };
447
+ exceptionThrowers_1.default.throwInvalidConversation(this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
435
448
  }
436
449
  if (conversationDetails.state === LiveWorkItemState_1.default.WrapUp || conversationDetails.state === LiveWorkItemState_1.default.Closed) {
437
- exceptionDetails = {
438
- response: "ClosedConversation"
439
- };
440
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
450
+ console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
451
+ telemetryData = {
441
452
  RequestId: this.requestId,
442
453
  ChatId: this.chatToken.chatId,
443
- ExceptionDetails: JSON.stringify(exceptionDetails)
444
- });
445
- console.error("Unable to join conversation that's in '" + conversationDetails.state + "' state");
446
- throw Error(exceptionDetails.response);
454
+ };
455
+ exceptionThrowers_1.default.throwClosedConversation(this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
447
456
  }
448
- _1.label = 8;
457
+ _z.label = 8;
449
458
  case 8:
450
459
  if (!this.authSettings) return [3 /*break*/, 14];
451
460
  if (!!this.authenticatedUserToken) return [3 /*break*/, 10];
452
461
  return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
453
462
  case 9:
454
- _1.sent();
455
- _1.label = 10;
463
+ _z.sent();
464
+ _z.label = 10;
456
465
  case 10:
457
466
  if (!(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0)) return [3 /*break*/, 14];
458
467
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
459
468
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
460
- _1.label = 11;
469
+ _z.label = 11;
461
470
  case 11:
462
- _1.trys.push([11, 13, , 14]);
471
+ _z.trys.push([11, 13, , 14]);
463
472
  return [4 /*yield*/, this.OCClient.validateAuthChatRecord(this.requestId, {
464
473
  authenticatedUserToken: this.authenticatedUserToken,
465
474
  chatId: this.chatToken.chatId
466
475
  })];
467
476
  case 12:
468
- _1.sent();
477
+ _z.sent();
469
478
  return [3 /*break*/, 14];
470
479
  case 13:
471
- _y = _1.sent();
472
- exceptionDetails = {
473
- response: "OCClientValidateAuthChatRecordFailed",
474
- message: "InvalidAuthChatRecord"
475
- };
476
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
480
+ e_5 = _z.sent();
481
+ telemetryData = {
477
482
  RequestId: this.requestId,
478
483
  ChatId: this.chatToken.chatId,
479
- ExceptionDetails: JSON.stringify(exceptionDetails)
480
- });
481
- throw Error(exceptionDetails.response);
484
+ };
485
+ exceptionThrowers_1.default.throwAuthenticatedChatConversationRetrievalFailure(e_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
486
+ return [3 /*break*/, 14];
482
487
  case 14:
483
488
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 16];
484
489
  return [4 /*yield*/, this.getChatToken(false)];
485
490
  case 15:
486
- _1.sent();
487
- _1.label = 16;
491
+ _z.sent();
492
+ _z.label = 16;
488
493
  case 16:
489
494
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
490
495
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
@@ -495,7 +500,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
495
500
  sessionInitOptionalParams = {
496
501
  initContext: {}
497
502
  };
498
- sessionInitOptionalParams = this.populateInitChatOptionalParam(sessionInitOptionalParams, optionalParams);
503
+ sessionInitOptionalParams = this.populateInitChatOptionalParam(sessionInitOptionalParams, optionalParams, TelemetryEvent_1.default.StartChat);
499
504
  sessionInitOptionalParams.initContext.isProactiveChat = !!optionalParams.isProactiveChat;
500
505
  if (this.isPersistentChat && !((_j = this.chatSDKConfig.persistentChat) === null || _j === void 0 ? void 0 : _j.disable)) {
501
506
  sessionInitOptionalParams.reconnectId = this.reconnectId;
@@ -506,36 +511,31 @@ var OmnichannelChatSDK = /** @class */ (function () {
506
511
  if (!(((_m = (_l = this.liveChatConfig) === null || _l === void 0 ? void 0 : _l.LiveWSAndLiveChatEngJoin) === null || _m === void 0 ? void 0 : _m.msdyn_requestvisitorlocation) === "true")) return [3 /*break*/, 18];
507
512
  return [4 /*yield*/, location_1.getLocationInfo(this.scenarioMarker, this.chatToken.chatId, this.requestId)];
508
513
  case 17:
509
- location_2 = _1.sent();
514
+ location_2 = _z.sent();
510
515
  sessionInitOptionalParams.initContext.latitude = location_2.latitude;
511
516
  sessionInitOptionalParams.initContext.longitude = location_2.longitude;
512
- _1.label = 18;
517
+ _z.label = 18;
513
518
  case 18:
514
519
  if (!!optionalParams.liveChatContext) return [3 /*break*/, 22];
515
- _1.label = 19;
520
+ _z.label = 19;
516
521
  case 19:
517
- _1.trys.push([19, 21, , 22]);
522
+ _z.trys.push([19, 21, , 22]);
518
523
  return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
519
524
  case 20:
520
- _1.sent();
525
+ _z.sent();
521
526
  return [3 /*break*/, 22];
522
527
  case 21:
523
- error_3 = _1.sent();
524
- exceptionDetails = {
525
- response: "OCClientSessionInitFailed"
528
+ error_3 = _z.sent();
529
+ telemetryData = {
530
+ RequestId: this.requestId,
531
+ ChatId: this.chatToken.chatId,
526
532
  };
527
533
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
528
534
  if (((_o = error_3) === null || _o === void 0 ? void 0 : _o.isAxiosError) && ((_q = (_p = error_3.response) === null || _p === void 0 ? void 0 : _p.headers) === null || _q === void 0 ? void 0 : _q.errorcode.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
529
- exceptionDetails.response = OmnichannelErrorCodes_1.default[OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour].toString();
530
- exceptionDetails.message = 'Widget used outside of operating hours';
531
- console.error(exceptionDetails.message);
535
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_3, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
532
536
  }
533
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
534
- RequestId: this.requestId,
535
- ChatId: this.chatToken.chatId,
536
- ExceptionDetails: JSON.stringify(exceptionDetails)
537
- });
538
- throw new Error(exceptionDetails.response);
537
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_3, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
538
+ return [3 /*break*/, 22];
539
539
  case 22:
540
540
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 33];
541
541
  chatAdapterConfig = {
@@ -545,120 +545,101 @@ var OmnichannelChatSDK = /** @class */ (function () {
545
545
  environmentUrl: this.chatToken.acsEndpoint,
546
546
  pollingInterval: 30000
547
547
  };
548
- _1.label = 23;
548
+ _z.label = 23;
549
549
  case 23:
550
- _1.trys.push([23, 25, , 26]);
550
+ _z.trys.push([23, 25, , 26]);
551
551
  return [4 /*yield*/, ((_r = this.ACSClient) === null || _r === void 0 ? void 0 : _r.initialize({
552
552
  token: chatAdapterConfig.token,
553
553
  environmentUrl: chatAdapterConfig.environmentUrl
554
554
  }))];
555
555
  case 24:
556
- _1.sent();
556
+ _z.sent();
557
557
  return [3 /*break*/, 26];
558
558
  case 25:
559
- error_4 = _1.sent();
560
- exceptionDetails = {
561
- response: "ACSClientInitializeFailed"
562
- };
563
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
559
+ error_4 = _z.sent();
560
+ telemetryData = {
564
561
  RequestId: this.requestId,
565
562
  ChatId: this.chatToken.chatId,
566
- ExceptionDetails: JSON.stringify(exceptionDetails)
567
- });
568
- console.error("OmnichannelChatSDK/startChat/initialize/error " + error_4);
569
- return [2 /*return*/, error_4];
563
+ };
564
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_4, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
565
+ return [3 /*break*/, 26];
570
566
  case 26:
571
- _1.trys.push([26, 28, , 29]);
572
- _z = this;
567
+ _z.trys.push([26, 28, , 29]);
568
+ _x = this;
573
569
  return [4 /*yield*/, ((_s = this.ACSClient) === null || _s === void 0 ? void 0 : _s.joinConversation({
574
570
  id: chatAdapterConfig.id,
575
571
  threadId: chatAdapterConfig.threadId,
576
572
  pollingInterval: chatAdapterConfig.pollingInterval
577
573
  }))];
578
574
  case 27:
579
- _z.conversation = (_1.sent());
575
+ _x.conversation = (_z.sent());
580
576
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
581
577
  RequestId: this.requestId,
582
578
  ChatId: this.chatToken.chatId
583
579
  });
584
580
  return [3 /*break*/, 29];
585
581
  case 28:
586
- error_5 = _1.sent();
587
- exceptionDetails = {
588
- response: "ACSClientJoinConversationFailed"
589
- };
590
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
582
+ error_5 = _z.sent();
583
+ telemetryData = {
591
584
  RequestId: this.requestId,
592
585
  ChatId: this.chatToken.chatId,
593
- ExceptionDetails: JSON.stringify(exceptionDetails)
594
- });
595
- console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_5);
596
- throw Error(exceptionDetails.response);
586
+ };
587
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
588
+ return [3 /*break*/, 29];
597
589
  case 29:
598
- _1.trys.push([29, 31, , 32]);
590
+ _z.trys.push([29, 31, , 32]);
599
591
  return [4 /*yield*/, ((_t = this.AMSClient) === null || _t === void 0 ? void 0 : _t.initialize({
600
592
  chatToken: this.chatToken
601
593
  }))];
602
594
  case 30:
603
- _1.sent();
595
+ _z.sent();
604
596
  return [3 /*break*/, 32];
605
597
  case 31:
606
- error_6 = _1.sent();
607
- exceptionDetails = {
608
- response: "AMSClientInitializeFailed"
609
- };
610
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
598
+ error_6 = _z.sent();
599
+ telemetryData = {
611
600
  RequestId: this.requestId,
612
601
  ChatId: this.chatToken.chatId,
613
- ExceptionDetails: JSON.stringify(exceptionDetails)
614
- });
615
- throw Error(exceptionDetails.response);
602
+ };
603
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
604
+ return [3 /*break*/, 32];
616
605
  case 32: return [3 /*break*/, 39];
617
606
  case 33:
618
- _1.trys.push([33, 35, , 36]);
607
+ _z.trys.push([33, 35, , 36]);
619
608
  return [4 /*yield*/, this.IC3Client.initialize({
620
609
  token: this.chatToken.token,
621
610
  regionGtms: this.chatToken.regionGTMS,
622
611
  visitor: true
623
612
  })];
624
613
  case 34:
625
- _1.sent();
614
+ _z.sent();
626
615
  return [3 /*break*/, 36];
627
616
  case 35:
628
- error_7 = _1.sent();
629
- exceptionDetails = {
630
- response: "IC3ClientInitializeFailed"
631
- };
632
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
617
+ error_7 = _z.sent();
618
+ telemetryData = {
633
619
  RequestId: this.requestId,
634
620
  ChatId: this.chatToken.chatId,
635
- ExceptionDetails: JSON.stringify(exceptionDetails)
636
- });
637
- console.error("OmnichannelChatSDK/startChat/initialize/error " + error_7);
638
- return [2 /*return*/, error_7];
621
+ };
622
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
623
+ return [3 /*break*/, 36];
639
624
  case 36:
640
- _1.trys.push([36, 38, , 39]);
641
- _0 = this;
625
+ _z.trys.push([36, 38, , 39]);
626
+ _y = this;
642
627
  return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
643
628
  case 37:
644
- _0.conversation = _1.sent();
629
+ _y.conversation = _z.sent();
645
630
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
646
631
  RequestId: this.requestId,
647
632
  ChatId: this.chatToken.chatId
648
633
  });
649
634
  return [3 /*break*/, 39];
650
635
  case 38:
651
- error_8 = _1.sent();
652
- exceptionDetails = {
653
- response: "IC3ClientJoinConversationFailed"
654
- };
655
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.StartChat, {
636
+ error_8 = _z.sent();
637
+ telemetryData = {
656
638
  RequestId: this.requestId,
657
639
  ChatId: this.chatToken.chatId,
658
- ExceptionDetails: JSON.stringify(exceptionDetails)
659
- });
660
- console.error("OmnichannelChatSDK/startChat/joinConversation/error " + error_8);
661
- return [2 /*return*/, error_8];
640
+ };
641
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
642
+ return [3 /*break*/, 39];
662
643
  case 39:
663
644
  if (this.isPersistentChat && !((_u = this.chatSDKConfig.persistentChat) === null || _u === void 0 ? void 0 : _u.disable)) {
664
645
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -681,7 +662,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
681
662
  OmnichannelChatSDK.prototype.endChat = function () {
682
663
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
683
664
  return __awaiter(this, void 0, void 0, function () {
684
- var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, exceptionDetails;
665
+ var sessionCloseOptionalParams, isReconnectChat, isChatReconnect, error_9, telemetryData;
685
666
  return __generator(this, function (_r) {
686
667
  switch (_r.label) {
687
668
  case 0:
@@ -738,16 +719,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
738
719
  return [3 /*break*/, 4];
739
720
  case 3:
740
721
  error_9 = _r.sent();
741
- exceptionDetails = {
742
- response: "OCClientSessionCloseFailed"
743
- };
744
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.EndChat, {
722
+ telemetryData = {
745
723
  RequestId: this.requestId,
746
- ChatId: this.chatToken.chatId,
747
- ExceptionDetails: JSON.stringify(exceptionDetails),
748
- });
749
- console.error("OmnichannelChatSDK/endChat/error " + error_9);
750
- return [2 /*return*/, error_9];
724
+ ChatId: this.chatToken.chatId
725
+ };
726
+ exceptionThrowers_1.default.throwConversationClosureFailure(error_9, this.scenarioMarker, TelemetryEvent_1.default.EndChat, telemetryData);
727
+ return [3 /*break*/, 4];
751
728
  case 4:
752
729
  if (this.refreshTokenTimer !== null) {
753
730
  clearInterval(this.refreshTokenTimer);
@@ -879,20 +856,20 @@ var OmnichannelChatSDK = /** @class */ (function () {
879
856
  });
880
857
  };
881
858
  OmnichannelChatSDK.prototype.getChatToken = function (cached) {
882
- var _a, _b;
859
+ var _a, _b, _c;
883
860
  if (cached === void 0) { cached = true; }
884
861
  return __awaiter(this, void 0, void 0, function () {
885
- var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, acsEndpoint, attachmentConfiguration, error_11, exceptionDetails;
886
- return __generator(this, function (_c) {
887
- switch (_c.label) {
862
+ var getChatTokenOptionalParams, chatToken, chatId, token, regionGtms, expiresIn, visitorId, voiceVideoCallToken, acsEndpoint, attachmentConfiguration, error_11, telemetryData;
863
+ return __generator(this, function (_d) {
864
+ switch (_d.label) {
888
865
  case 0:
889
866
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetChatToken, {
890
867
  RequestId: this.requestId
891
868
  });
892
869
  if (!!cached) return [3 /*break*/, 5];
893
- _c.label = 1;
870
+ _d.label = 1;
894
871
  case 1:
895
- _c.trys.push([1, 3, , 4]);
872
+ _d.trys.push([1, 3, , 4]);
896
873
  getChatTokenOptionalParams = {};
897
874
  if (this.authenticatedUserToken) {
898
875
  getChatTokenOptionalParams.authenticatedUserToken = this.authenticatedUserToken;
@@ -905,7 +882,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
905
882
  }
906
883
  return [4 /*yield*/, this.OCClient.getChatToken(this.requestId, getChatTokenOptionalParams)];
907
884
  case 2:
908
- chatToken = _c.sent();
885
+ chatToken = _d.sent();
909
886
  chatId = chatToken.ChatId, token = chatToken.Token, regionGtms = chatToken.RegionGtms, expiresIn = chatToken.ExpiresIn, visitorId = chatToken.VisitorId, voiceVideoCallToken = chatToken.VoiceVideoCallToken, acsEndpoint = chatToken.ACSEndpoint, attachmentConfiguration = chatToken.AttachmentConfiguration;
910
887
  this.chatToken = {
911
888
  chatId: chatId,
@@ -926,16 +903,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
926
903
  });
927
904
  return [3 /*break*/, 4];
928
905
  case 3:
929
- error_11 = _c.sent();
930
- exceptionDetails = {
931
- response: "OCClientGetChatTokenFailed"
932
- };
933
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetChatToken, {
906
+ error_11 = _d.sent();
907
+ telemetryData = {
934
908
  RequestId: this.requestId,
935
- ChatId: this.chatToken.chatId,
936
- ExceptionDetails: JSON.stringify(exceptionDetails),
937
- });
938
- console.error("OmnichannelChatSDK/getChatToken/error " + error_11);
909
+ ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId,
910
+ };
911
+ exceptionThrowers_1.default.throwChatTokenRetrievalFailure(error_11, this.scenarioMarker, TelemetryEvent_1.default.GetChatToken, telemetryData);
939
912
  return [3 /*break*/, 4];
940
913
  case 4: return [3 /*break*/, 6];
941
914
  case 5:
@@ -943,7 +916,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
943
916
  RequestId: this.requestId,
944
917
  ChatId: this.chatToken.chatId
945
918
  });
946
- _c.label = 6;
919
+ _d.label = 6;
947
920
  case 6: return [2 /*return*/, this.chatToken];
948
921
  }
949
922
  });
@@ -1671,31 +1644,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
1671
1644
  OmnichannelChatSDK.prototype.getVoiceVideoCalling = function (params) {
1672
1645
  if (params === void 0) { params = {}; }
1673
1646
  return __awaiter(this, void 0, void 0, function () {
1674
- var exceptionDetails, exceptionDetails, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1647
+ var message, message, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
1675
1648
  var _this = this;
1676
1649
  return __generator(this, function (_a) {
1677
1650
  switch (_a.label) {
1678
1651
  case 0:
1679
1652
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
1680
1653
  if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
1681
- exceptionDetails = {
1682
- response: "UnsupportedPlatform",
1683
- message: "VoiceVideoCalling is only supported on browser"
1684
- };
1685
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1686
- ExceptionDetails: JSON.stringify(exceptionDetails)
1687
- });
1688
- throw new Error(exceptionDetails.response);
1654
+ message = "VoiceVideoCalling is only supported on browser";
1655
+ exceptionThrowers_1.default.throwUnsupportedPlatform(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling, message);
1689
1656
  }
1690
1657
  if (this.callingOption.toString() === CallingOptionsOptionSetNumber_1.default.NoCalling.toString()) {
1691
- exceptionDetails = {
1692
- response: "FeatureDisabled",
1693
- message: "Voice and video call is not enabled"
1694
- };
1695
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
1696
- ExceptionDetails: JSON.stringify(exceptionDetails)
1697
- });
1698
- throw new Error(exceptionDetails.response);
1658
+ message = "Voice and video call is not enabled";
1659
+ exceptionThrowers_1.default.throwFeatureDisabled(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling, message);
1699
1660
  }
1700
1661
  return [4 /*yield*/, this.getChatConfig()];
1701
1662
  case 1:
@@ -1874,7 +1835,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1874
1835
  OmnichannelChatSDK.prototype.getAgentAvailability = function (optionalParams) {
1875
1836
  if (optionalParams === void 0) { optionalParams = {}; }
1876
1837
  return __awaiter(this, void 0, void 0, function () {
1877
- var reportError, getAgentAvailabilityOptionalParams, response, e_2;
1838
+ var reportError, getAgentAvailabilityOptionalParams, response, e_6;
1878
1839
  var _this = this;
1879
1840
  return __generator(this, function (_a) {
1880
1841
  switch (_a.label) {
@@ -1907,7 +1868,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1907
1868
  getAgentAvailabilityOptionalParams = {
1908
1869
  initContext: {}
1909
1870
  };
1910
- getAgentAvailabilityOptionalParams = this.populateInitChatOptionalParam(getAgentAvailabilityOptionalParams, optionalParams);
1871
+ getAgentAvailabilityOptionalParams = this.populateInitChatOptionalParam(getAgentAvailabilityOptionalParams, optionalParams, TelemetryEvent_1.default.GetAgentAvailability);
1911
1872
  _a.label = 1;
1912
1873
  case 1:
1913
1874
  _a.trys.push([1, 3, , 4]);
@@ -1916,9 +1877,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
1916
1877
  response = _a.sent();
1917
1878
  return [2 /*return*/, response];
1918
1879
  case 3:
1919
- e_2 = _a.sent();
1880
+ e_6 = _a.sent();
1920
1881
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1921
- reportError("GetAgentAvailabilityFailed", e_2.message);
1882
+ reportError("GetAgentAvailabilityFailed", e_6.message);
1922
1883
  return [3 /*break*/, 4];
1923
1884
  case 4: return [2 /*return*/];
1924
1885
  }
@@ -2021,22 +1982,19 @@ var OmnichannelChatSDK = /** @class */ (function () {
2021
1982
  OmnichannelChatSDK.prototype.getChatConfig = function (optionalParams) {
2022
1983
  if (optionalParams === void 0) { optionalParams = {}; }
2023
1984
  return __awaiter(this, void 0, void 0, function () {
2024
- var sendCacheHeaders, bypassCache, liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled, error_18;
1985
+ var sendCacheHeaders, bypassCache, liveChatConfig, dataMaskingConfig, authSettings, liveWSAndLiveChatEngJoin, liveChatVersion, chatWidgetLanguage, msdyn_localeid, setting, preChatSurvey, msdyn_prechatenabled, msdyn_callingoptions, msdyn_conversationmode, msdyn_enablechatreconnect, isPreChatEnabled, isChatReconnectEnabled;
2025
1986
  return __generator(this, function (_a) {
2026
1987
  switch (_a.label) {
2027
1988
  case 0:
2028
1989
  sendCacheHeaders = optionalParams.sendCacheHeaders;
2029
- _a.label = 1;
2030
- case 1:
2031
- _a.trys.push([1, 5, , 6]);
2032
1990
  bypassCache = sendCacheHeaders === true;
2033
1991
  return [4 /*yield*/, this.OCClient.getChatConfig(this.requestId, bypassCache)];
2034
- case 2:
1992
+ case 1:
2035
1993
  liveChatConfig = _a.sent();
2036
1994
  dataMaskingConfig = liveChatConfig.DataMaskingInfo, authSettings = liveChatConfig.LiveChatConfigAuthSettings, liveWSAndLiveChatEngJoin = liveChatConfig.LiveWSAndLiveChatEngJoin, liveChatVersion = liveChatConfig.LiveChatVersion, chatWidgetLanguage = liveChatConfig.ChatWidgetLanguage;
2037
1995
  msdyn_localeid = chatWidgetLanguage.msdyn_localeid;
2038
1996
  this.localeId = msdyn_localeid || locale_1.defaultLocaleId;
2039
- this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V1;
1997
+ this.liveChatVersion = liveChatVersion || LiveChatVersion_1.default.V2;
2040
1998
  /* istanbul ignore next */
2041
1999
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] " + this.liveChatVersion);
2042
2000
  setting = dataMaskingConfig.setting;
@@ -2058,12 +2016,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2058
2016
  if (isPreChatEnabled && preChatSurvey && preChatSurvey.trim().length > 0) {
2059
2017
  this.preChatSurvey = preChatSurvey;
2060
2018
  }
2061
- if (!this.authSettings) return [3 /*break*/, 4];
2019
+ if (!this.authSettings) return [3 /*break*/, 3];
2062
2020
  return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
2063
- case 3:
2021
+ case 2:
2064
2022
  _a.sent();
2065
- _a.label = 4;
2066
- case 4:
2023
+ _a.label = 3;
2024
+ case 3:
2067
2025
  if (this.preChatSurvey) {
2068
2026
  /* istanbul ignore next */
2069
2027
  this.debug && console.log('Prechat Survey!');
@@ -2071,11 +2029,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
2071
2029
  this.callingOption = msdyn_callingoptions;
2072
2030
  this.liveChatConfig = liveChatConfig;
2073
2031
  return [2 /*return*/, this.liveChatConfig];
2074
- case 5:
2075
- error_18 = _a.sent();
2076
- console.error("OmnichannelChatSDK/getChatConfig/error " + error_18);
2077
- return [2 /*return*/, error_18];
2078
- case 6: return [2 /*return*/];
2079
2032
  }
2080
2033
  });
2081
2034
  });
@@ -2088,7 +2041,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2088
2041
  };
2089
2042
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2090
2043
  return __awaiter(this, void 0, void 0, function () {
2091
- var sessionInfo, error_19, exceptionDetails;
2044
+ var sessionInfo, error_18, exceptionDetails;
2092
2045
  return __generator(this, function (_a) {
2093
2046
  switch (_a.label) {
2094
2047
  case 0:
@@ -2116,7 +2069,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2116
2069
  });
2117
2070
  return [3 /*break*/, 5];
2118
2071
  case 4:
2119
- error_19 = _a.sent();
2072
+ error_18 = _a.sent();
2120
2073
  exceptionDetails = {
2121
2074
  response: "UpdateChatTokenFailed"
2122
2075
  };
@@ -2125,7 +2078,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2125
2078
  ChatId: this.chatToken.chatId,
2126
2079
  ExceptionDetails: JSON.stringify(exceptionDetails)
2127
2080
  });
2128
- console.error("OmnichannelChatSDK/updateChatToken/error " + error_19);
2081
+ console.error("OmnichannelChatSDK/updateChatToken/error " + error_18);
2129
2082
  return [3 /*break*/, 5];
2130
2083
  case 5: return [2 /*return*/];
2131
2084
  }