@microsoft/omnichannel-chat-sdk 1.11.1-main.986a9a7 → 1.11.1-main.e08c1d6

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.
@@ -52,6 +52,7 @@ declare class OmnichannelChatSDK {
52
52
  private dynamicsLocationCode;
53
53
  private chatToken;
54
54
  private liveChatConfig;
55
+ private widgetSnippetBaseUrl;
55
56
  private liveChatVersion;
56
57
  private dataMaskingRules;
57
58
  private authSettings;
@@ -154,6 +155,7 @@ declare class OmnichannelChatSDK {
154
155
  private setLocaleIdConfiguration;
155
156
  private setCallingOptionConfiguration;
156
157
  private setLiveChatVersionConfiguration;
158
+ private setWidgetSnippetBaseUrl;
157
159
  private getChatConfig;
158
160
  private buildConfigurations;
159
161
  private resolveIC3ClientUrl;
@@ -108,6 +108,7 @@ var startPolling_1 = require("./commands/startPolling");
108
108
  var stopPolling_1 = require("./commands/stopPolling");
109
109
  var urlResolvers_1 = require("./utils/urlResolvers");
110
110
  var OmnichannelConfigValidator_1 = require("./validators/OmnichannelConfigValidator");
111
+ var AMSClientUtils_1 = require("./utils/AMSClientUtils");
111
112
  var OmnichannelChatSDK = /** @class */ (function () {
112
113
  function OmnichannelChatSDK(omnichannelConfig, chatSDKConfig) {
113
114
  if (chatSDKConfig === void 0) { chatSDKConfig = SDKConfigValidators_1.defaultChatSDKConfig; }
@@ -119,6 +120,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
119
120
  this.unqServicesOrgUrl = null;
120
121
  this.coreServicesOrgUrl = null;
121
122
  this.dynamicsLocationCode = null;
123
+ this.widgetSnippetBaseUrl = '';
122
124
  this.dataMaskingRules = { rules: [] };
123
125
  this.authSettings = null;
124
126
  this.authenticatedUserToken = null;
@@ -393,35 +395,40 @@ var OmnichannelChatSDK = /** @class */ (function () {
393
395
  };
394
396
  OmnichannelChatSDK.prototype.loadAmsClient = function () {
395
397
  return __awaiter(this, void 0, void 0, function () {
396
- var _a, e_1;
397
- return __generator(this, function (_b) {
398
- switch (_b.label) {
398
+ var disableAMSWhitelistedUrls, disableAMSRegionBasedUrl, framedMode, _a, e_1;
399
+ var _b, _c, _d, _e;
400
+ return __generator(this, function (_f) {
401
+ switch (_f.label) {
399
402
  case 0:
400
403
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeMessagingClient);
401
- _b.label = 1;
404
+ _f.label = 1;
402
405
  case 1:
403
- _b.trys.push([1, 4, , 5]);
406
+ _f.trys.push([1, 4, , 5]);
404
407
  if (!this.isAMSClientAllowed) return [3 /*break*/, 3];
405
408
  if (!(this.AMSClientLoadCurrentState === AMSClientLoadStates_1.AMSClientLoadStates.NOT_LOADED)) return [3 /*break*/, 3];
406
409
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADING;
407
410
  this.debug && console.time("ams_creation");
411
+ disableAMSWhitelistedUrls = ((_c = (_b = this.chatSDKConfig) === null || _b === void 0 ? void 0 : _b.internalConfig) === null || _c === void 0 ? void 0 : _c.disableAMSWhitelistedUrls) !== false;
412
+ disableAMSRegionBasedUrl = ((_e = (_d = this.chatSDKConfig) === null || _d === void 0 ? void 0 : _d.internalConfig) === null || _e === void 0 ? void 0 : _e.disableAMSRegionBasedUrl) !== false;
413
+ framedMode = (0, AMSClientUtils_1.shouldUseFramedMode)(disableAMSWhitelistedUrls);
408
414
  _a = this;
409
415
  return [4 /*yield*/, (0, omnichannel_amsclient_1.default)({
410
- framedMode: (0, platform_1.isBrowser)(),
416
+ framedMode: framedMode,
411
417
  multiClient: true,
412
418
  debug: (this.detailedDebugEnabled ? this.debugAMS : this.debug),
413
- logger: this.amsClientLogger
419
+ logger: this.amsClientLogger,
420
+ baseUrl: framedMode && !disableAMSRegionBasedUrl ? (0, AMSClientUtils_1.retrieveRegionBasedUrl)(this.widgetSnippetBaseUrl) : ''
414
421
  })];
415
422
  case 2:
416
- _a.AMSClient = _b.sent();
423
+ _a.AMSClient = _f.sent();
417
424
  this.debug && console.timeEnd("ams_creation");
418
425
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADED;
419
- _b.label = 3;
426
+ _f.label = 3;
420
427
  case 3:
421
428
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeMessagingClient);
422
429
  return [3 /*break*/, 5];
423
430
  case 4:
424
- e_1 = _b.sent();
431
+ e_1 = _f.sent();
425
432
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.ERROR;
426
433
  exceptionThrowers_1.default.throwMessagingClientCreationFailure(e_1, this.scenarioMarker, TelemetryEvent_1.default.InitializeMessagingClient);
427
434
  return [3 /*break*/, 5];
@@ -468,11 +475,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
468
475
  // We will keep this logic for backward compatibility for customers with unknown implementation, so they can test before fully adoption
469
476
  OmnichannelChatSDK.prototype.sequentialInitialization = function () {
470
477
  return __awaiter(this, arguments, void 0, function (optionalParams) {
471
- var useCoreServices, _a, e_2, getLiveChatConfigOptionalParams, e_3, supportedLiveChatVersions, _b, _c, e_4;
472
- var _d;
478
+ var useCoreServices, _a, e_2, getLiveChatConfigOptionalParams, e_3, supportedLiveChatVersions, disableAMSWhitelistedUrls, disableAMSRegionBasedUrl, _b, _c, e_4;
479
+ var _d, _e, _f, _g, _h;
473
480
  if (optionalParams === void 0) { optionalParams = {}; }
474
- return __generator(this, function (_e) {
475
- switch (_e.label) {
481
+ return __generator(this, function (_j) {
482
+ switch (_j.label) {
476
483
  case 0:
477
484
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeChatSDK);
478
485
  if (this.isInitialized) {
@@ -481,29 +488,29 @@ var OmnichannelChatSDK = /** @class */ (function () {
481
488
  }
482
489
  this.useCoreServicesOrgUrlIfNotSet();
483
490
  useCoreServices = (0, CoreServicesUtils_1.isCoreServicesOrgUrl)(this.omnichannelConfig.orgUrl);
484
- _e.label = 1;
491
+ _j.label = 1;
485
492
  case 1:
486
- _e.trys.push([1, 3, , 4]);
493
+ _j.trys.push([1, 3, , 4]);
487
494
  this.OCSDKProvider = ocsdk_1.SDKProvider;
488
495
  _a = this;
489
496
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices), this.ocSdkLogger)];
490
497
  case 2:
491
- _a.OCClient = _e.sent();
498
+ _a.OCClient = _j.sent();
492
499
  (0, setOcUserAgent_1.default)(this.OCClient, (_d = this.chatSDKConfig) === null || _d === void 0 ? void 0 : _d.ocUserAgent);
493
500
  return [3 /*break*/, 4];
494
501
  case 3:
495
- e_2 = _e.sent();
502
+ e_2 = _j.sent();
496
503
  exceptionThrowers_1.default.throwOmnichannelClientInitializationFailure(e_2, this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
497
504
  return [3 /*break*/, 4];
498
505
  case 4:
499
- _e.trys.push([4, 6, , 7]);
506
+ _j.trys.push([4, 6, , 7]);
500
507
  getLiveChatConfigOptionalParams = optionalParams.getLiveChatConfigOptionalParams;
501
508
  return [4 /*yield*/, this.getChatConfig(getLiveChatConfigOptionalParams || {})];
502
509
  case 5:
503
- _e.sent();
510
+ _j.sent();
504
511
  return [3 /*break*/, 7];
505
512
  case 6:
506
- e_3 = _e.sent();
513
+ e_3 = _j.sent();
507
514
  exceptionThrowers_1.default.throwChatConfigRetrievalFailure(e_3, this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
508
515
  return [3 /*break*/, 7];
509
516
  case 7:
@@ -511,40 +518,43 @@ var OmnichannelChatSDK = /** @class */ (function () {
511
518
  if (!supportedLiveChatVersions.includes(this.liveChatVersion)) {
512
519
  exceptionThrowers_1.default.throwUnsupportedLiveChatVersionFailure(new Error(ChatSDKError_1.ChatSDKErrorName.UnsupportedLiveChatVersion), this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
513
520
  }
514
- _e.label = 8;
521
+ _j.label = 8;
515
522
  case 8:
516
- _e.trys.push([8, 14, , 15]);
523
+ _j.trys.push([8, 14, , 15]);
517
524
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 11];
518
525
  this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
519
526
  if (!(this.isAMSClientAllowed && this.AMSClientLoadCurrentState === AMSClientLoadStates_1.AMSClientLoadStates.NOT_LOADED)) return [3 /*break*/, 10];
520
527
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADING;
521
528
  this.debug && console.time("ams_seq_creation");
529
+ disableAMSWhitelistedUrls = ((_f = (_e = this.chatSDKConfig) === null || _e === void 0 ? void 0 : _e.internalConfig) === null || _f === void 0 ? void 0 : _f.disableAMSWhitelistedUrls) === false ? false : true;
530
+ disableAMSRegionBasedUrl = ((_h = (_g = this.chatSDKConfig) === null || _g === void 0 ? void 0 : _g.internalConfig) === null || _h === void 0 ? void 0 : _h.disableAMSRegionBasedUrl) === false ? false : true;
522
531
  _b = this;
523
532
  return [4 /*yield*/, (0, omnichannel_amsclient_1.default)({
524
- framedMode: (0, platform_1.isBrowser)(),
533
+ framedMode: (0, AMSClientUtils_1.shouldUseFramedMode)(disableAMSWhitelistedUrls),
525
534
  multiClient: true,
526
535
  debug: (this.detailedDebugEnabled ? this.debugAMS : this.debug),
527
- logger: this.amsClientLogger
536
+ logger: this.amsClientLogger,
537
+ baseUrl: (0, AMSClientUtils_1.shouldUseFramedMode)(disableAMSWhitelistedUrls) && !disableAMSRegionBasedUrl ? (0, AMSClientUtils_1.retrieveRegionBasedUrl)(this.widgetSnippetBaseUrl) : ''
528
538
  })];
529
539
  case 9:
530
- _b.AMSClient = _e.sent();
540
+ _b.AMSClient = _j.sent();
531
541
  this.debug && console.timeEnd("ams_seq_creation");
532
542
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADED;
533
- _e.label = 10;
543
+ _j.label = 10;
534
544
  case 10: return [3 /*break*/, 13];
535
545
  case 11:
536
546
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 13];
537
547
  _c = this;
538
548
  return [4 /*yield*/, this.getIC3Client()];
539
549
  case 12:
540
- _c.IC3Client = _e.sent();
541
- _e.label = 13;
550
+ _c.IC3Client = _j.sent();
551
+ _j.label = 13;
542
552
  case 13:
543
553
  this.isInitialized = true;
544
554
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
545
555
  return [3 /*break*/, 15];
546
556
  case 14:
547
- e_4 = _e.sent();
557
+ e_4 = _j.sent();
548
558
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.ERROR;
549
559
  exceptionThrowers_1.default.throwMessagingClientCreationFailure(e_4, this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
550
560
  return [3 /*break*/, 15];
@@ -2341,83 +2351,73 @@ var OmnichannelChatSDK = /** @class */ (function () {
2341
2351
  };
2342
2352
  OmnichannelChatSDK.prototype.getVoiceVideoCalling = function () {
2343
2353
  return __awaiter(this, arguments, void 0, function (voiceVideoCallingOptionalParams) {
2344
- var message, message, chatConfig, liveWSAndLiveChatEngJoin, msdyn_widgetsnippet, widgetSnippetSourceRegex, result;
2354
+ var message, message;
2345
2355
  var _this = this;
2346
2356
  if (voiceVideoCallingOptionalParams === void 0) { voiceVideoCallingOptionalParams = {}; }
2347
2357
  return __generator(this, function (_a) {
2348
- switch (_a.label) {
2349
- case 0:
2350
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
2351
- if (!this.isInitialized) {
2352
- exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling);
2353
- }
2354
- if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
2355
- message = "VoiceVideoCalling is only supported on browser";
2356
- exceptionThrowers_1.default.throwUnsupportedPlatform(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling, message);
2357
- }
2358
- if (!this.isVoiceVideoCallingEnabled()) {
2359
- message = "Voice and video call is not enabled";
2360
- exceptionThrowers_1.default.throwFeatureDisabled(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling, message);
2361
- }
2362
- return [4 /*yield*/, this.getLiveChatConfig()];
2363
- case 1:
2364
- chatConfig = _a.sent();
2365
- liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
2366
- msdyn_widgetsnippet = liveWSAndLiveChatEngJoin.msdyn_widgetsnippet;
2367
- widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
2368
- result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
2369
- if (result && result.length) {
2370
- return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
2371
- var LiveChatWidgetLibCDNUrl, defaultParams;
2372
- var _this = this;
2373
- var _a;
2374
- return __generator(this, function (_b) {
2375
- switch (_b.label) {
2376
- case 0:
2377
- LiveChatWidgetLibCDNUrl = "".concat(result[1], "/livechatwidget/v2scripts/callingsdk/").concat(settings_1.callingBundleVersion, "/CallingBundle.js");
2378
- (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
2379
- VoiceVideoCalling: LiveChatWidgetLibCDNUrl
2358
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
2359
+ if (!this.isInitialized) {
2360
+ exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling);
2361
+ }
2362
+ if (platform_1.default.isNode() || platform_1.default.isReactNative()) {
2363
+ message = "VoiceVideoCalling is only supported on browser";
2364
+ exceptionThrowers_1.default.throwUnsupportedPlatform(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling, message);
2365
+ }
2366
+ if (!this.isVoiceVideoCallingEnabled()) {
2367
+ message = "Voice and video call is not enabled";
2368
+ exceptionThrowers_1.default.throwFeatureDisabled(this.scenarioMarker, TelemetryEvent_1.default.GetVoiceVideoCalling, message);
2369
+ }
2370
+ if (this.widgetSnippetBaseUrl && this.widgetSnippetBaseUrl.length) {
2371
+ return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
2372
+ var LiveChatWidgetLibCDNUrl, defaultParams;
2373
+ var _this = this;
2374
+ var _a;
2375
+ return __generator(this, function (_b) {
2376
+ switch (_b.label) {
2377
+ case 0:
2378
+ LiveChatWidgetLibCDNUrl = "".concat(this.widgetSnippetBaseUrl, "/livechatwidget/v2scripts/callingsdk/").concat(settings_1.callingBundleVersion, "/CallingBundle.js");
2379
+ (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setCDNPackages({
2380
+ VoiceVideoCalling: LiveChatWidgetLibCDNUrl
2381
+ });
2382
+ defaultParams = {
2383
+ logger: this.callingSdkLogger
2384
+ };
2385
+ return [4 /*yield*/, (0, WebUtils_1.loadScript)(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
2386
+ var VoiceVideoCalling;
2387
+ return __generator(this, function (_a) {
2388
+ switch (_a.label) {
2389
+ case 0:
2390
+ this.debug && console.debug("".concat(LiveChatWidgetLibCDNUrl, " loaded!"));
2391
+ return [4 /*yield*/, (0, createVoiceVideoCalling_1.default)(__assign(__assign({}, voiceVideoCallingOptionalParams), defaultParams))];
2392
+ case 1:
2393
+ VoiceVideoCalling = _a.sent();
2394
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
2395
+ VoiceVideoCalling.useScenarioMarker(this.scenarioMarker);
2396
+ resolve(VoiceVideoCalling);
2397
+ return [2 /*return*/];
2398
+ }
2380
2399
  });
2381
- defaultParams = {
2382
- logger: this.callingSdkLogger
2383
- };
2384
- return [4 /*yield*/, (0, WebUtils_1.loadScript)(LiveChatWidgetLibCDNUrl, function () { return __awaiter(_this, void 0, void 0, function () {
2385
- var VoiceVideoCalling;
2386
- return __generator(this, function (_a) {
2387
- switch (_a.label) {
2388
- case 0:
2389
- this.debug && console.debug("".concat(LiveChatWidgetLibCDNUrl, " loaded!"));
2390
- return [4 /*yield*/, (0, createVoiceVideoCalling_1.default)(__assign(__assign({}, voiceVideoCallingOptionalParams), defaultParams))];
2391
- case 1:
2392
- VoiceVideoCalling = _a.sent();
2393
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetVoiceVideoCalling);
2394
- VoiceVideoCalling.useScenarioMarker(this.scenarioMarker);
2395
- resolve(VoiceVideoCalling);
2396
- return [2 /*return*/];
2397
- }
2398
- });
2399
- }); }, function () { return __awaiter(_this, void 0, void 0, function () {
2400
- var exceptionDetails;
2401
- return __generator(this, function (_a) {
2402
- exceptionDetails = {
2403
- response: "VoiceVideoCallingLoadFailed",
2404
- message: "Failed to load VoiceVideoCalling"
2405
- };
2406
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
2407
- ExceptionDetails: JSON.stringify(exceptionDetails)
2408
- });
2409
- throw new Error(exceptionDetails.response);
2410
- });
2411
- }); })];
2412
- case 1:
2413
- _b.sent();
2414
- return [2 /*return*/];
2415
- }
2416
- });
2417
- }); })];
2418
- }
2419
- return [2 /*return*/];
2400
+ }); }, function () { return __awaiter(_this, void 0, void 0, function () {
2401
+ var exceptionDetails;
2402
+ return __generator(this, function (_a) {
2403
+ exceptionDetails = {
2404
+ response: "VoiceVideoCallingLoadFailed",
2405
+ message: "Failed to load VoiceVideoCalling"
2406
+ };
2407
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetVoiceVideoCalling, {
2408
+ ExceptionDetails: JSON.stringify(exceptionDetails)
2409
+ });
2410
+ throw new Error(exceptionDetails.response);
2411
+ });
2412
+ }); })];
2413
+ case 1:
2414
+ _b.sent();
2415
+ return [2 /*return*/];
2416
+ }
2417
+ });
2418
+ }); })];
2420
2419
  }
2420
+ return [2 /*return*/];
2421
2421
  });
2422
2422
  });
2423
2423
  };
@@ -2812,6 +2812,22 @@ var OmnichannelChatSDK = /** @class */ (function () {
2812
2812
  });
2813
2813
  });
2814
2814
  };
2815
+ OmnichannelChatSDK.prototype.setWidgetSnippetBaseUrl = function (liveWSAndLiveChatEngJoin) {
2816
+ return __awaiter(this, void 0, void 0, function () {
2817
+ var widgetSnippetSourceRegex, msdyn_widgetsnippet, result;
2818
+ return __generator(this, function (_a) {
2819
+ widgetSnippetSourceRegex = new RegExp("src=\"(https:\\/\\/[\\w-.]+)[\\w-.\\/]+\"");
2820
+ msdyn_widgetsnippet = liveWSAndLiveChatEngJoin.msdyn_widgetsnippet;
2821
+ if (msdyn_widgetsnippet) { // Find src attribute with its url in code snippet
2822
+ result = msdyn_widgetsnippet.match(widgetSnippetSourceRegex);
2823
+ if (result && result.length) {
2824
+ this.widgetSnippetBaseUrl = result[1];
2825
+ }
2826
+ }
2827
+ return [2 /*return*/];
2828
+ });
2829
+ });
2830
+ };
2815
2831
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2816
2832
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2817
2833
  var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
@@ -2871,7 +2887,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2871
2887
  this.setPersistentChatConfiguration(liveWSAndLiveChatEngJoin),
2872
2888
  this.setCallingOptionConfiguration(liveWSAndLiveChatEngJoin),
2873
2889
  this.setLocaleIdConfiguration(chatWidgetLanguage),
2874
- this.setLiveChatVersionConfiguration(liveChatVersion)
2890
+ this.setLiveChatVersionConfiguration(liveChatVersion),
2891
+ this.setWidgetSnippetBaseUrl(liveWSAndLiveChatEngJoin)
2875
2892
  ]);
2876
2893
  return [2 /*return*/];
2877
2894
  });