@microsoft/omnichannel-chat-sdk 1.4.3-main.bc6dccb → 1.4.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.
package/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
1
  # Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [Unreleased]
4
+ ## [1.4.3] - 2023-06-15
5
+
6
+ ### Fixed
7
+
8
+ - [Perf] Make sessionInit, AcsClientInit/Ic3ClientInit and AmsClientInit calls in parallel
5
9
 
6
10
  ## [1.4.2] - 2023-05-19
7
11
 
@@ -398,13 +398,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
398
398
  });
399
399
  };
400
400
  OmnichannelChatSDK.prototype.startChat = function (optionalParams) {
401
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
401
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
402
402
  if (optionalParams === void 0) { optionalParams = {}; }
403
403
  return __awaiter(this, void 0, void 0, function () {
404
- var shouldReinitIC3Client, _x, reconnectableChatsParams, reconnectableChatsResponse, e_4, telemetryData, conversationDetails, telemetryData, telemetryData, e_5, telemetryData, sessionInitOptionalParams, location_2, error_3, telemetryData, chatAdapterConfig, error_4, telemetryData, _y, error_5, telemetryData, error_6, telemetryData, error_7, telemetryData, _z, error_8, telemetryData;
404
+ var shouldReinitIC3Client, _q, reconnectableChatsParams, reconnectableChatsResponse, e_4, telemetryData, conversationDetails, telemetryData, telemetryData, e_5, telemetryData, sessionInitOptionalParams, location_2, sessionInitPromise, messagingClientPromise, attachmentClientPromise;
405
405
  var _this = this;
406
- return __generator(this, function (_0) {
407
- switch (_0.label) {
406
+ return __generator(this, function (_r) {
407
+ switch (_r.label) {
408
408
  case 0:
409
409
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.StartChat, {
410
410
  RequestId: this.requestId
@@ -414,31 +414,31 @@ var OmnichannelChatSDK = /** @class */ (function () {
414
414
  }
415
415
  shouldReinitIC3Client = !platform_1.default.isNode() && !platform_1.default.isReactNative() && !this.IC3Client && this.liveChatVersion === LiveChatVersion_1.default.V1;
416
416
  if (!shouldReinitIC3Client) return [3 /*break*/, 2];
417
- _x = this;
417
+ _q = this;
418
418
  return [4 /*yield*/, this.getIC3Client()];
419
419
  case 1:
420
- _x.IC3Client = _0.sent();
421
- _0.label = 2;
420
+ _q.IC3Client = _r.sent();
421
+ _r.label = 2;
422
422
  case 2:
423
423
  if (this.isChatReconnect && !((_a = this.chatSDKConfig.chatReconnect) === null || _a === void 0 ? void 0 : _a.disable) && !this.isPersistentChat && optionalParams.reconnectId) {
424
424
  this.reconnectId = optionalParams.reconnectId;
425
425
  }
426
426
  if (!(this.isPersistentChat && !((_b = this.chatSDKConfig.persistentChat) === null || _b === void 0 ? void 0 : _b.disable))) return [3 /*break*/, 6];
427
- _0.label = 3;
427
+ _r.label = 3;
428
428
  case 3:
429
- _0.trys.push([3, 5, , 6]);
429
+ _r.trys.push([3, 5, , 6]);
430
430
  reconnectableChatsParams = {
431
431
  authenticatedUserToken: this.authenticatedUserToken
432
432
  };
433
433
  return [4 /*yield*/, this.OCClient.getReconnectableChats(reconnectableChatsParams)];
434
434
  case 4:
435
- reconnectableChatsResponse = _0.sent();
435
+ reconnectableChatsResponse = _r.sent();
436
436
  if (reconnectableChatsResponse && reconnectableChatsResponse.reconnectid) {
437
437
  this.reconnectId = reconnectableChatsResponse.reconnectid;
438
438
  }
439
439
  return [3 /*break*/, 6];
440
440
  case 5:
441
- e_4 = _0.sent();
441
+ e_4 = _r.sent();
442
442
  telemetryData = {
443
443
  RequestId: this.requestId,
444
444
  ChatId: this.chatToken.chatId,
@@ -451,7 +451,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
451
451
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
452
452
  return [4 /*yield*/, this.getConversationDetails()];
453
453
  case 7:
454
- conversationDetails = _0.sent();
454
+ conversationDetails = _r.sent();
455
455
  if (Object.keys(conversationDetails).length === 0) {
456
456
  telemetryData = {
457
457
  RequestId: this.requestId,
@@ -467,30 +467,30 @@ var OmnichannelChatSDK = /** @class */ (function () {
467
467
  };
468
468
  exceptionThrowers_1.default.throwClosedConversation(this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
469
469
  }
470
- _0.label = 8;
470
+ _r.label = 8;
471
471
  case 8:
472
472
  if (!this.authSettings) return [3 /*break*/, 14];
473
473
  if (!!this.authenticatedUserToken) return [3 /*break*/, 10];
474
474
  return [4 /*yield*/, this.setAuthTokenProvider(this.chatSDKConfig.getAuthToken)];
475
475
  case 9:
476
- _0.sent();
477
- _0.label = 10;
476
+ _r.sent();
477
+ _r.label = 10;
478
478
  case 10:
479
479
  if (!(optionalParams.liveChatContext && Object.keys(optionalParams.liveChatContext).length > 0)) return [3 /*break*/, 14];
480
480
  this.chatToken = optionalParams.liveChatContext.chatToken || {};
481
481
  this.requestId = optionalParams.liveChatContext.requestId || ocsdk_1.uuidv4();
482
- _0.label = 11;
482
+ _r.label = 11;
483
483
  case 11:
484
- _0.trys.push([11, 13, , 14]);
484
+ _r.trys.push([11, 13, , 14]);
485
485
  return [4 /*yield*/, this.OCClient.validateAuthChatRecord(this.requestId, {
486
486
  authenticatedUserToken: this.authenticatedUserToken,
487
487
  chatId: this.chatToken.chatId
488
488
  })];
489
489
  case 12:
490
- _0.sent();
490
+ _r.sent();
491
491
  return [3 /*break*/, 14];
492
492
  case 13:
493
- e_5 = _0.sent();
493
+ e_5 = _r.sent();
494
494
  telemetryData = {
495
495
  RequestId: this.requestId,
496
496
  ChatId: this.chatToken.chatId,
@@ -501,8 +501,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
501
501
  if (!(this.chatToken && Object.keys(this.chatToken).length === 0)) return [3 /*break*/, 16];
502
502
  return [4 /*yield*/, this.getChatToken(false)];
503
503
  case 15:
504
- _0.sent();
505
- _0.label = 16;
504
+ _r.sent();
505
+ _r.label = 16;
506
506
  case 16:
507
507
  (_c = this.ic3ClientLogger) === null || _c === void 0 ? void 0 : _c.setChatId(this.chatToken.chatId || '');
508
508
  (_d = this.ocSdkLogger) === null || _d === void 0 ? void 0 : _d.setChatId(this.chatToken.chatId || '');
@@ -524,137 +524,167 @@ var OmnichannelChatSDK = /** @class */ (function () {
524
524
  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];
525
525
  return [4 /*yield*/, location_1.getLocationInfo(this.scenarioMarker, this.chatToken.chatId, this.requestId)];
526
526
  case 17:
527
- location_2 = _0.sent();
527
+ location_2 = _r.sent();
528
528
  sessionInitOptionalParams.initContext.latitude = location_2.latitude;
529
529
  sessionInitOptionalParams.initContext.longitude = location_2.longitude;
530
- _0.label = 18;
530
+ _r.label = 18;
531
531
  case 18:
532
- if (!!optionalParams.liveChatContext) return [3 /*break*/, 22];
533
- _0.label = 19;
532
+ sessionInitPromise = function () { return __awaiter(_this, void 0, void 0, function () {
533
+ var error_3, telemetryData;
534
+ var _a, _b, _c, _d;
535
+ return __generator(this, function (_e) {
536
+ switch (_e.label) {
537
+ case 0:
538
+ if (!!optionalParams.liveChatContext) return [3 /*break*/, 4];
539
+ _e.label = 1;
540
+ case 1:
541
+ _e.trys.push([1, 3, , 4]);
542
+ return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
543
+ case 2:
544
+ _e.sent();
545
+ return [3 /*break*/, 4];
546
+ case 3:
547
+ error_3 = _e.sent();
548
+ telemetryData = {
549
+ RequestId: this.requestId,
550
+ ChatId: this.chatToken.chatId,
551
+ };
552
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
553
+ if (((_a = error_3) === null || _a === void 0 ? void 0 : _a.isAxiosError) && ((_d = (_c = (_b = error_3.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) === null || _d === void 0 ? void 0 : _d.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
554
+ exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_3, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
555
+ }
556
+ exceptionThrowers_1.default.throwConversationInitializationFailure(error_3, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
557
+ return [3 /*break*/, 4];
558
+ case 4: return [2 /*return*/];
559
+ }
560
+ });
561
+ }); };
562
+ messagingClientPromise = function () { return __awaiter(_this, void 0, void 0, function () {
563
+ var chatAdapterConfig, error_4, telemetryData, _a, error_5, telemetryData, error_6, telemetryData, _b, error_7, telemetryData;
564
+ var _c, _d;
565
+ return __generator(this, function (_e) {
566
+ switch (_e.label) {
567
+ case 0:
568
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 8];
569
+ chatAdapterConfig = {
570
+ token: this.chatToken.token,
571
+ id: this.chatToken.visitorId || 'teamsvisitor',
572
+ threadId: this.chatToken.chatId,
573
+ environmentUrl: this.chatToken.acsEndpoint,
574
+ pollingInterval: 30000
575
+ };
576
+ _e.label = 1;
577
+ case 1:
578
+ _e.trys.push([1, 3, , 4]);
579
+ return [4 /*yield*/, ((_c = this.ACSClient) === null || _c === void 0 ? void 0 : _c.initialize({
580
+ token: chatAdapterConfig.token,
581
+ environmentUrl: chatAdapterConfig.environmentUrl
582
+ }))];
583
+ case 2:
584
+ _e.sent();
585
+ return [3 /*break*/, 4];
586
+ case 3:
587
+ error_4 = _e.sent();
588
+ telemetryData = {
589
+ RequestId: this.requestId,
590
+ ChatId: this.chatToken.chatId,
591
+ };
592
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_4, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
593
+ return [3 /*break*/, 4];
594
+ case 4:
595
+ _e.trys.push([4, 6, , 7]);
596
+ _a = this;
597
+ return [4 /*yield*/, ((_d = this.ACSClient) === null || _d === void 0 ? void 0 : _d.joinConversation({
598
+ id: chatAdapterConfig.id,
599
+ threadId: chatAdapterConfig.threadId,
600
+ pollingInterval: chatAdapterConfig.pollingInterval
601
+ }))];
602
+ case 5:
603
+ _a.conversation = (_e.sent());
604
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
605
+ RequestId: this.requestId,
606
+ ChatId: this.chatToken.chatId
607
+ });
608
+ return [3 /*break*/, 7];
609
+ case 6:
610
+ error_5 = _e.sent();
611
+ telemetryData = {
612
+ RequestId: this.requestId,
613
+ ChatId: this.chatToken.chatId,
614
+ };
615
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
616
+ return [3 /*break*/, 7];
617
+ case 7: return [3 /*break*/, 14];
618
+ case 8:
619
+ _e.trys.push([8, 10, , 11]);
620
+ return [4 /*yield*/, this.IC3Client.initialize({
621
+ token: this.chatToken.token,
622
+ regionGtms: this.chatToken.regionGTMS,
623
+ visitor: true
624
+ })];
625
+ case 9:
626
+ _e.sent();
627
+ return [3 /*break*/, 11];
628
+ case 10:
629
+ error_6 = _e.sent();
630
+ telemetryData = {
631
+ RequestId: this.requestId,
632
+ ChatId: this.chatToken.chatId,
633
+ };
634
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
635
+ return [3 /*break*/, 11];
636
+ case 11:
637
+ _e.trys.push([11, 13, , 14]);
638
+ _b = this;
639
+ return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
640
+ case 12:
641
+ _b.conversation = _e.sent();
642
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
643
+ RequestId: this.requestId,
644
+ ChatId: this.chatToken.chatId
645
+ });
646
+ return [3 /*break*/, 14];
647
+ case 13:
648
+ error_7 = _e.sent();
649
+ telemetryData = {
650
+ RequestId: this.requestId,
651
+ ChatId: this.chatToken.chatId,
652
+ };
653
+ exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
654
+ return [3 /*break*/, 14];
655
+ case 14: return [2 /*return*/];
656
+ }
657
+ });
658
+ }); };
659
+ attachmentClientPromise = function () { return __awaiter(_this, void 0, void 0, function () {
660
+ var error_8, telemetryData;
661
+ var _a;
662
+ return __generator(this, function (_b) {
663
+ switch (_b.label) {
664
+ case 0:
665
+ _b.trys.push([0, 3, , 4]);
666
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 2];
667
+ return [4 /*yield*/, ((_a = this.AMSClient) === null || _a === void 0 ? void 0 : _a.initialize({ chatToken: this.chatToken }))];
668
+ case 1:
669
+ _b.sent();
670
+ _b.label = 2;
671
+ case 2: return [3 /*break*/, 4];
672
+ case 3:
673
+ error_8 = _b.sent();
674
+ telemetryData = {
675
+ RequestId: this.requestId,
676
+ ChatId: this.chatToken.chatId,
677
+ };
678
+ exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
679
+ return [3 /*break*/, 4];
680
+ case 4: return [2 /*return*/];
681
+ }
682
+ });
683
+ }); };
684
+ return [4 /*yield*/, Promise.all([sessionInitPromise(), messagingClientPromise(), attachmentClientPromise()])];
534
685
  case 19:
535
- _0.trys.push([19, 21, , 22]);
536
- return [4 /*yield*/, this.OCClient.sessionInit(this.requestId, sessionInitOptionalParams)];
537
- case 20:
538
- _0.sent();
539
- return [3 /*break*/, 22];
540
- case 21:
541
- error_3 = _0.sent();
542
- telemetryData = {
543
- RequestId: this.requestId,
544
- ChatId: this.chatToken.chatId,
545
- };
546
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
547
- if (((_o = error_3) === null || _o === void 0 ? void 0 : _o.isAxiosError) && ((_r = (_q = (_p = error_3.response) === null || _p === void 0 ? void 0 : _p.headers) === null || _q === void 0 ? void 0 : _q.errorcode) === null || _r === void 0 ? void 0 : _r.toString()) === OmnichannelErrorCodes_1.default.WidgetUseOutsideOperatingHour.toString()) {
548
- exceptionThrowers_1.default.throwWidgetUseOutsideOperatingHour(error_3, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
549
- }
550
- exceptionThrowers_1.default.throwConversationInitializationFailure(error_3, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
551
- return [3 /*break*/, 22];
552
- case 22:
553
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 33];
554
- chatAdapterConfig = {
555
- token: this.chatToken.token,
556
- id: this.chatToken.visitorId || 'teamsvisitor',
557
- threadId: this.chatToken.chatId,
558
- environmentUrl: this.chatToken.acsEndpoint,
559
- pollingInterval: 30000
560
- };
561
- _0.label = 23;
562
- case 23:
563
- _0.trys.push([23, 25, , 26]);
564
- return [4 /*yield*/, ((_s = this.ACSClient) === null || _s === void 0 ? void 0 : _s.initialize({
565
- token: chatAdapterConfig.token,
566
- environmentUrl: chatAdapterConfig.environmentUrl
567
- }))];
568
- case 24:
569
- _0.sent();
570
- return [3 /*break*/, 26];
571
- case 25:
572
- error_4 = _0.sent();
573
- telemetryData = {
574
- RequestId: this.requestId,
575
- ChatId: this.chatToken.chatId,
576
- };
577
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_4, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
578
- return [3 /*break*/, 26];
579
- case 26:
580
- _0.trys.push([26, 28, , 29]);
581
- _y = this;
582
- return [4 /*yield*/, ((_t = this.ACSClient) === null || _t === void 0 ? void 0 : _t.joinConversation({
583
- id: chatAdapterConfig.id,
584
- threadId: chatAdapterConfig.threadId,
585
- pollingInterval: chatAdapterConfig.pollingInterval
586
- }))];
587
- case 27:
588
- _y.conversation = (_0.sent());
589
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
590
- RequestId: this.requestId,
591
- ChatId: this.chatToken.chatId
592
- });
593
- return [3 /*break*/, 29];
594
- case 28:
595
- error_5 = _0.sent();
596
- telemetryData = {
597
- RequestId: this.requestId,
598
- ChatId: this.chatToken.chatId,
599
- };
600
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_5, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
601
- return [3 /*break*/, 29];
602
- case 29:
603
- _0.trys.push([29, 31, , 32]);
604
- return [4 /*yield*/, ((_u = this.AMSClient) === null || _u === void 0 ? void 0 : _u.initialize({
605
- chatToken: this.chatToken
606
- }))];
607
- case 30:
608
- _0.sent();
609
- return [3 /*break*/, 32];
610
- case 31:
611
- error_6 = _0.sent();
612
- telemetryData = {
613
- RequestId: this.requestId,
614
- ChatId: this.chatToken.chatId,
615
- };
616
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_6, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
617
- return [3 /*break*/, 32];
618
- case 32: return [3 /*break*/, 39];
619
- case 33:
620
- _0.trys.push([33, 35, , 36]);
621
- return [4 /*yield*/, this.IC3Client.initialize({
622
- token: this.chatToken.token,
623
- regionGtms: this.chatToken.regionGTMS,
624
- visitor: true
625
- })];
626
- case 34:
627
- _0.sent();
628
- return [3 /*break*/, 36];
629
- case 35:
630
- error_7 = _0.sent();
631
- telemetryData = {
632
- RequestId: this.requestId,
633
- ChatId: this.chatToken.chatId,
634
- };
635
- exceptionThrowers_1.default.throwMessagingClientInitializationFailure(error_7, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
636
- return [3 /*break*/, 36];
637
- case 36:
638
- _0.trys.push([36, 38, , 39]);
639
- _z = this;
640
- return [4 /*yield*/, this.IC3Client.joinConversation(this.chatToken.chatId)];
641
- case 37:
642
- _z.conversation = _0.sent();
643
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.StartChat, {
644
- RequestId: this.requestId,
645
- ChatId: this.chatToken.chatId
646
- });
647
- return [3 /*break*/, 39];
648
- case 38:
649
- error_8 = _0.sent();
650
- telemetryData = {
651
- RequestId: this.requestId,
652
- ChatId: this.chatToken.chatId,
653
- };
654
- exceptionThrowers_1.default.throwMessagingClientConversationJoinFailure(error_8, this.scenarioMarker, TelemetryEvent_1.default.StartChat, telemetryData);
655
- return [3 /*break*/, 39];
656
- case 39:
657
- if (this.isPersistentChat && !((_v = this.chatSDKConfig.persistentChat) === null || _v === void 0 ? void 0 : _v.disable)) {
686
+ _r.sent();
687
+ if (this.isPersistentChat && !((_o = this.chatSDKConfig.persistentChat) === null || _o === void 0 ? void 0 : _o.disable)) {
658
688
  this.refreshTokenTimer = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
659
689
  return __generator(this, function (_a) {
660
690
  switch (_a.label) {
@@ -665,7 +695,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
665
695
  return [2 /*return*/];
666
696
  }
667
697
  });
668
- }); }, (_w = this.chatSDKConfig.persistentChat) === null || _w === void 0 ? void 0 : _w.tokenUpdateTime);
698
+ }); }, (_p = this.chatSDKConfig.persistentChat) === null || _p === void 0 ? void 0 : _p.tokenUpdateTime);
669
699
  }
670
700
  return [2 /*return*/];
671
701
  }