@microsoft/omnichannel-chat-sdk 1.10.16 → 1.10.17-main.243dcc1

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.
@@ -64,6 +64,7 @@ var ocsdk_1 = require("@microsoft/ocsdk");
64
64
  var chatAdapterCreators_1 = require("./utils/chatAdapterCreators");
65
65
  var CoreServicesUtils_1 = require("./utils/CoreServicesUtils");
66
66
  var locale_1 = require("./utils/locale");
67
+ var exceptionThrowers_1 = require("./utils/exceptionThrowers");
67
68
  var utilities_1 = require("./utils/utilities");
68
69
  var WebUtils_1 = require("./utils/WebUtils");
69
70
  var platform_1 = require("./utils/platform");
@@ -97,7 +98,6 @@ var createTelemetry_1 = require("./utils/createTelemetry");
97
98
  var createVoiceVideoCalling_1 = require("./api/createVoiceVideoCalling");
98
99
  var MessageTags_1 = require("./core/messaging/MessageTags");
99
100
  var exceptionSuppressors_1 = require("./utils/exceptionSuppressors");
100
- var exceptionThrowers_1 = require("./utils/exceptionThrowers");
101
101
  var location_1 = require("./utils/location");
102
102
  var internalUtils_1 = require("./utils/internalUtils");
103
103
  var loggerUtils_1 = require("./utils/loggerUtils");
@@ -138,6 +138,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
138
138
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.NOT_LOADED;
139
139
  this.isMaskingDisabled = false;
140
140
  this.maskingCharacter = "#";
141
+ this.isAMSClientAllowed = false;
141
142
  this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
142
143
  requestOptionalParams.initContext.locale = (0, locale_1.getLocaleStringFromId)(_this.localeId);
143
144
  if (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.customContext) {
@@ -242,9 +243,11 @@ var OmnichannelChatSDK = /** @class */ (function () {
242
243
  OmnichannelChatSDK.prototype.setDebug = function (flag) {
243
244
  var _a;
244
245
  this.debug = flag;
245
- this.getAMSClient().then(function (client) { return client === null || client === void 0 ? void 0 : client.setDebug(flag); });
246
246
  (_a = this.telemetry) === null || _a === void 0 ? void 0 : _a.setDebug(flag);
247
247
  this.scenarioMarker.setDebug(flag);
248
+ if (this.AMSClient) {
249
+ this.AMSClient.setDebug(flag);
250
+ }
248
251
  loggerUtils_1.default.setDebug(flag, this.ocSdkLogger, this.acsClientLogger, this.acsAdapterLogger, this.callingSdkLogger, this.amsClientLogger, this.ic3ClientLogger);
249
252
  };
250
253
  OmnichannelChatSDK.prototype.retryLoadAMSClient = function () {
@@ -254,7 +257,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
254
257
  switch (_a.label) {
255
258
  case 0:
256
259
  RETRY_DELAY_MS = 1000;
257
- MAX_RETRY_COUNT = 5;
260
+ MAX_RETRY_COUNT = 30;
258
261
  retryCount = 0;
259
262
  _a.label = 1;
260
263
  case 1:
@@ -278,6 +281,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
278
281
  return __generator(this, function (_b) {
279
282
  switch (_b.label) {
280
283
  case 0:
284
+ //return null to do not break promise creation
285
+ if (this.isAMSClientAllowed === false) {
286
+ return [2 /*return*/, null];
287
+ }
281
288
  if (this.AMSClientLoadCurrentState === AMSClientLoadStates_1.AMSClientLoadStates.NOT_LOADED && this.liveChatVersion === LiveChatVersion_1.default.V1) {
282
289
  return [2 /*return*/, null];
283
290
  }
@@ -289,10 +296,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
289
296
  case AMSClientLoadStates_1.AMSClientLoadStates.NOT_LOADED: return [3 /*break*/, 4];
290
297
  }
291
298
  return [3 /*break*/, 6];
292
- case 1: return [2 /*return*/, this.AMSClient];
293
- case 2: return [4 /*yield*/, this.retryLoadAMSClient()];
299
+ case 1:
300
+ this.debug && console.log("Attachment handler is already loaded");
301
+ return [2 /*return*/, this.AMSClient];
302
+ case 2:
303
+ this.debug && console.log("Attachment handler is loading, waiting for it to be ready");
304
+ return [4 /*yield*/, this.retryLoadAMSClient()];
294
305
  case 3: return [2 /*return*/, _b.sent()];
295
- case 4: return [4 /*yield*/, this.loadAmsClient()];
306
+ case 4:
307
+ this.debug && console.log("Attachment handler is not loaded, loading now");
308
+ return [4 /*yield*/, this.loadAmsClient()];
296
309
  case 5:
297
310
  _b.sent();
298
311
  return [2 /*return*/, this.AMSClient];
@@ -303,59 +316,79 @@ var OmnichannelChatSDK = /** @class */ (function () {
303
316
  };
304
317
  OmnichannelChatSDK.prototype.loadInitComponents = function () {
305
318
  return __awaiter(this, void 0, void 0, function () {
306
- var supportedLiveChatVersions;
307
- return __generator(this, function (_a) {
308
- this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeComponents);
309
- supportedLiveChatVersions = [LiveChatVersion_1.default.V1, LiveChatVersion_1.default.V2];
310
- if (!supportedLiveChatVersions.includes(this.liveChatVersion)) {
311
- exceptionThrowers_1.default.throwUnsupportedLiveChatVersionFailure(new Error(ChatSDKError_1.ChatSDKErrorName.UnsupportedLiveChatVersion), this.scenarioMarker, TelemetryEvent_1.default.InitializeComponents);
319
+ var supportedLiveChatVersions, _a;
320
+ return __generator(this, function (_b) {
321
+ switch (_b.label) {
322
+ case 0:
323
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeComponents);
324
+ supportedLiveChatVersions = [LiveChatVersion_1.default.V1, LiveChatVersion_1.default.V2];
325
+ if (!supportedLiveChatVersions.includes(this.liveChatVersion)) {
326
+ exceptionThrowers_1.default.throwUnsupportedLiveChatVersionFailure(new Error(ChatSDKError_1.ChatSDKErrorName.UnsupportedLiveChatVersion), this.scenarioMarker, TelemetryEvent_1.default.InitializeComponents);
327
+ }
328
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 1];
329
+ this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
330
+ return [3 /*break*/, 3];
331
+ case 1:
332
+ _a = this;
333
+ return [4 /*yield*/, this.getIC3Client()];
334
+ case 2:
335
+ _a.IC3Client = _b.sent();
336
+ _b.label = 3;
337
+ case 3:
338
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeComponents);
339
+ return [2 /*return*/];
312
340
  }
313
- this.isInitialized = true;
314
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeComponents);
315
- return [2 /*return*/];
316
341
  });
317
342
  });
318
343
  };
344
+ OmnichannelChatSDK.prototype.evaluateAMSAvailability = function () {
345
+ var _a, _b, _c, _d;
346
+ // it will load AMS only if enabled for Customer or Agent support for attachments, based on configuration
347
+ if (((_b = (_a = this.liveChatConfig) === null || _a === void 0 ? void 0 : _a.LiveWSAndLiveChatEngJoin) === null || _b === void 0 ? void 0 : _b.msdyn_enablefileattachmentsforcustomers) === "true" ||
348
+ ((_d = (_c = this.liveChatConfig) === null || _c === void 0 ? void 0 : _c.LiveWSAndLiveChatEngJoin) === null || _d === void 0 ? void 0 : _d.msdyn_enablefileattachmentsforagents) === "true") {
349
+ if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
350
+ //override of this value, since it will be needed to control access to attachment operations
351
+ this.isAMSClientAllowed = true;
352
+ return this.isAMSClientAllowed;
353
+ }
354
+ }
355
+ return this.isAMSClientAllowed;
356
+ };
319
357
  OmnichannelChatSDK.prototype.loadAmsClient = function () {
320
358
  return __awaiter(this, void 0, void 0, function () {
321
- var _a, _b, e_1;
322
- return __generator(this, function (_c) {
323
- switch (_c.label) {
359
+ var _a, e_1;
360
+ return __generator(this, function (_b) {
361
+ switch (_b.label) {
324
362
  case 0:
325
363
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.InitializeMessagingClient);
326
- _c.label = 1;
364
+ _b.label = 1;
327
365
  case 1:
328
- _c.trys.push([1, 6, , 7]);
329
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 3];
330
- this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
366
+ _b.trys.push([1, 4, , 5]);
367
+ if (!this.isAMSClientAllowed) return [3 /*break*/, 3];
368
+ if (!(this.AMSClientLoadCurrentState === AMSClientLoadStates_1.AMSClientLoadStates.NOT_LOADED)) return [3 /*break*/, 3];
331
369
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADING;
370
+ this.debug && console.time("ams_creation");
332
371
  _a = this;
333
372
  return [4 /*yield*/, (0, omnichannel_amsclient_1.default)({
334
373
  framedMode: (0, platform_1.isBrowser)(),
335
374
  multiClient: true,
336
- debug: false,
375
+ debug: this.debug,
337
376
  logger: this.amsClientLogger
338
377
  })];
339
378
  case 2:
340
- _a.AMSClient = _c.sent();
379
+ _a.AMSClient = _b.sent();
380
+ this.debug && console.timeEnd("ams_creation");
341
381
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADED;
342
- return [3 /*break*/, 5];
382
+ _b.label = 3;
343
383
  case 3:
344
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 5];
345
- _b = this;
346
- return [4 /*yield*/, this.getIC3Client()];
347
- case 4:
348
- _b.IC3Client = _c.sent();
349
- _c.label = 5;
350
- case 5:
351
384
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeMessagingClient);
352
- return [3 /*break*/, 7];
353
- case 6:
354
- e_1 = _c.sent();
385
+ return [3 /*break*/, 5];
386
+ case 4:
387
+ e_1 = _b.sent();
355
388
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.ERROR;
356
389
  exceptionThrowers_1.default.throwMessagingClientCreationFailure(e_1, this.scenarioMarker, TelemetryEvent_1.default.InitializeMessagingClient);
357
- return [3 /*break*/, 7];
358
- case 7: return [2 /*return*/];
390
+ return [3 /*break*/, 5];
391
+ case 5: return [2 /*return*/];
359
392
  }
360
393
  });
361
394
  });
@@ -440,37 +473,42 @@ var OmnichannelChatSDK = /** @class */ (function () {
440
473
  }
441
474
  _e.label = 8;
442
475
  case 8:
443
- _e.trys.push([8, 13, , 14]);
444
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 10];
476
+ _e.trys.push([8, 14, , 15]);
477
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 11];
445
478
  this.ACSClient = new ACSClient_1.default(this.acsClientLogger);
479
+ if (!(this.isAMSClientAllowed && this.AMSClientLoadCurrentState === AMSClientLoadStates_1.AMSClientLoadStates.NOT_LOADED)) return [3 /*break*/, 10];
480
+ this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADING;
481
+ this.debug && console.time("ams_seq_creation");
446
482
  _b = this;
447
483
  return [4 /*yield*/, (0, omnichannel_amsclient_1.default)({
448
484
  framedMode: (0, platform_1.isBrowser)(),
449
485
  multiClient: true,
450
- debug: false,
486
+ debug: this.debug,
451
487
  logger: this.amsClientLogger
452
488
  })];
453
489
  case 9:
454
490
  _b.AMSClient = _e.sent();
491
+ this.debug && console.timeEnd("ams_seq_creation");
455
492
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.LOADED;
456
- return [3 /*break*/, 12];
457
- case 10:
458
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 12];
493
+ _e.label = 10;
494
+ case 10: return [3 /*break*/, 13];
495
+ case 11:
496
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V1)) return [3 /*break*/, 13];
459
497
  _c = this;
460
498
  return [4 /*yield*/, this.getIC3Client()];
461
- case 11:
462
- _c.IC3Client = _e.sent();
463
- _e.label = 12;
464
499
  case 12:
500
+ _c.IC3Client = _e.sent();
501
+ _e.label = 13;
502
+ case 13:
465
503
  this.isInitialized = true;
466
504
  this.scenarioMarker.completeScenario(TelemetryEvent_1.default.InitializeChatSDK);
467
- return [3 /*break*/, 14];
468
- case 13:
505
+ return [3 /*break*/, 15];
506
+ case 14:
469
507
  e_4 = _e.sent();
470
508
  this.AMSClientLoadCurrentState = AMSClientLoadStates_1.AMSClientLoadStates.ERROR;
471
509
  exceptionThrowers_1.default.throwMessagingClientCreationFailure(e_4, this.scenarioMarker, TelemetryEvent_1.default.InitializeChatSDK);
472
- return [3 /*break*/, 14];
473
- case 14: return [2 /*return*/, this.liveChatConfig];
510
+ return [3 /*break*/, 15];
511
+ case 15: return [2 /*return*/, this.liveChatConfig];
474
512
  }
475
513
  });
476
514
  });
@@ -988,13 +1026,18 @@ var OmnichannelChatSDK = /** @class */ (function () {
988
1026
  switch (_a.label) {
989
1027
  case 0:
990
1028
  _a.trys.push([0, 4, , 5]);
1029
+ if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 3];
1030
+ if (!this.isAMSClientAllowed)
1031
+ return [2 /*return*/];
1032
+ // will wait till the AMSClient is loaded, and then initialize it
1033
+ this.debug && console.time("ams_promise_initialization");
991
1034
  return [4 /*yield*/, this.getAMSClient()];
992
1035
  case 1:
993
1036
  amsClient = _a.sent();
994
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 3];
995
1037
  return [4 /*yield*/, (amsClient === null || amsClient === void 0 ? void 0 : amsClient.initialize({ chatToken: this.chatToken }))];
996
1038
  case 2:
997
1039
  _a.sent();
1040
+ this.debug && console.timeEnd("ams_promise_initialization");
998
1041
  _a.label = 3;
999
1042
  case 3: return [3 /*break*/, 5];
1000
1043
  case 4:
@@ -1866,9 +1909,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1866
1909
  var _a, _b;
1867
1910
  return __generator(this, function (_c) {
1868
1911
  switch (_c.label) {
1869
- case 0: return [4 /*yield*/, this.getAMSClient()];
1870
- case 1:
1871
- amsClient = _c.sent();
1912
+ case 0:
1872
1913
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.UploadFileAttachment, {
1873
1914
  RequestId: this.requestId,
1874
1915
  ChatId: this.chatToken.chatId
@@ -1877,6 +1918,15 @@ var OmnichannelChatSDK = /** @class */ (function () {
1877
1918
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.UploadFileAttachment);
1878
1919
  }
1879
1920
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 8];
1921
+ if (this.isAMSClientAllowed === false) {
1922
+ exceptionThrowers_1.default.throwFeatureDisabled(this.scenarioMarker, TelemetryEvent_1.default.UploadFileAttachment, "Enable support for attachment upload and receive in the widget configuration.");
1923
+ }
1924
+ return [4 /*yield*/, this.getAMSClient()];
1925
+ case 1:
1926
+ amsClient = _c.sent();
1927
+ if (amsClient === null || amsClient === undefined) {
1928
+ (0, exceptionThrowers_1.throwAMSLoadFailure)(this.scenarioMarker, TelemetryEvent_1.default.UploadFileAttachment, "Attachment handler client is null, no action can be performed");
1929
+ }
1880
1930
  return [4 /*yield*/, (amsClient === null || amsClient === void 0 ? void 0 : amsClient.createObject((_a = this.chatToken) === null || _a === void 0 ? void 0 : _a.chatId, fileInfo))];
1881
1931
  case 2:
1882
1932
  createObjectResponse = _c.sent();
@@ -1987,9 +2037,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1987
2037
  var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
1988
2038
  return __generator(this, function (_b) {
1989
2039
  switch (_b.label) {
1990
- case 0: return [4 /*yield*/, this.getAMSClient()];
1991
- case 1:
1992
- amsClient = _b.sent();
2040
+ case 0:
1993
2041
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
1994
2042
  RequestId: this.requestId,
1995
2043
  ChatId: this.chatToken.chatId
@@ -1998,9 +2046,23 @@ var OmnichannelChatSDK = /** @class */ (function () {
1998
2046
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.DownloadFileAttachment);
1999
2047
  }
2000
2048
  if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 7];
2001
- _b.label = 2;
2049
+ _b.label = 1;
2050
+ case 1:
2051
+ _b.trys.push([1, 5, , 6]);
2052
+ if (this.isAMSClientAllowed === false) {
2053
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2054
+ RequestId: this.requestId,
2055
+ ChatId: this.chatToken.chatId,
2056
+ ExceptionDetails: "AMSClient is disabled"
2057
+ });
2058
+ exceptionThrowers_1.default.throwFeatureDisabled(this.scenarioMarker, TelemetryEvent_1.default.DownloadFileAttachment, "Enable support for attachment upload and receive in the widget configuration.");
2059
+ }
2060
+ return [4 /*yield*/, this.getAMSClient()];
2002
2061
  case 2:
2003
- _b.trys.push([2, 5, , 6]);
2062
+ amsClient = _b.sent();
2063
+ if (amsClient === null || amsClient === undefined) {
2064
+ (0, exceptionThrowers_1.throwAMSLoadFailure)(this.scenarioMarker, TelemetryEvent_1.default.DownloadFileAttachment, "Attachment handler is null, no action can be performed");
2065
+ }
2004
2066
  return [4 /*yield*/, (amsClient === null || amsClient === void 0 ? void 0 : amsClient.getViewStatus(fileMetadata))];
2005
2067
  case 3:
2006
2068
  response = _b.sent();
@@ -2698,6 +2760,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2698
2760
  case 2:
2699
2761
  liveChatConfig = _d.sent();
2700
2762
  this.liveChatConfig = liveChatConfig;
2763
+ this.evaluateAMSAvailability();
2701
2764
  this.buildConfigurations(liveChatConfig);
2702
2765
  /* istanbul ignore next */
2703
2766
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));