@microsoft/omnichannel-chat-sdk 1.11.7-main.3418dc3 → 1.11.7-main.80a4f46

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.
@@ -84,6 +84,7 @@ declare class OmnichannelChatSDK {
84
84
  private debugAMS;
85
85
  private debugACS;
86
86
  private detailedDebugEnabled;
87
+ private regexCompiledForDataMasking;
87
88
  constructor(omnichannelConfig: OmnichannelConfig, chatSDKConfig?: ChatSDKConfig);
88
89
  /**
89
90
  * Executes an operation with mutual exclusion to prevent race conditions
@@ -165,6 +166,7 @@ declare class OmnichannelChatSDK {
165
166
  private getIC3Client;
166
167
  private setPrechatConfigurations;
167
168
  private setDataMaskingConfiguration;
169
+ private compileDataMaskingRegex;
168
170
  private setAuthSettingConfig;
169
171
  private setPersistentChatConfiguration;
170
172
  private setLocaleIdConfiguration;
@@ -150,6 +150,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
150
150
  this.debugAMS = false;
151
151
  this.debugACS = false;
152
152
  this.detailedDebugEnabled = false;
153
+ this.regexCompiledForDataMasking = [];
153
154
  this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
154
155
  requestOptionalParams.initContext.locale = (0, locale_1.getLocaleStringFromId)(_this.localeId);
155
156
  if (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.customContext) {
@@ -1687,21 +1688,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1687
1688
  }
1688
1689
  var content = message.content;
1689
1690
  var match;
1690
- for (var _i = 0, _a = this.dataMaskingRules.rules; _i < _a.length; _i++) {
1691
- var maskingRule = _a[_i];
1692
- var regex = new RegExp(maskingRule.regex, 'g');
1693
- while ((match = regex.exec(content)) !== null) {
1694
- var replaceStr = match[0].replace(/./g, this.maskingCharacter);
1695
- content = content.replace(match[0], replaceStr);
1691
+ if (this.regexCompiledForDataMasking.length === 0) {
1692
+ return message;
1693
+ }
1694
+ for (var _i = 0, _a = this.regexCompiledForDataMasking; _i < _a.length; _i++) {
1695
+ var regex = _a[_i];
1696
+ try {
1697
+ var lastIndex = -1;
1698
+ while ((match = regex.exec(content)) !== null) {
1699
+ // Prevent infinite loop from zero-width matches
1700
+ if (regex.lastIndex === lastIndex) {
1701
+ this.debug && console.warn("[OmnichannelChatSDK][transformMessage] Data masking regex caused zero-width match, skipping rule ".concat(regex));
1702
+ break;
1703
+ }
1704
+ lastIndex = regex.lastIndex;
1705
+ var replaceStr = match[0].replace(/./g, this.maskingCharacter);
1706
+ content = content.replace(match[0], replaceStr);
1707
+ }
1708
+ match = null;
1709
+ }
1710
+ catch (error) {
1711
+ // Log error for invalid regex but continue processing other rules
1712
+ this.debug && console.error("[OmnichannelChatSDK][transformMessage] Data masking regex failed for rule ".concat(regex, ": ").concat(error));
1696
1713
  }
1697
- match = null;
1698
1714
  }
1699
1715
  message.content = content;
1700
1716
  return message;
1701
1717
  };
1702
1718
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
1703
1719
  return __awaiter(this, void 0, void 0, function () {
1704
- var sendMessageRequest, chatMessage, error_17, exceptionDetails, messageToSend, error_18, exceptionDetails;
1720
+ var sendMessageRequest, chatMessage, error_17, exceptionDetails;
1705
1721
  var _a;
1706
1722
  return __generator(this, function (_b) {
1707
1723
  switch (_b.label) {
@@ -1714,7 +1730,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
1714
1730
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.SendMessages);
1715
1731
  }
1716
1732
  this.transformMessage(message);
1717
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
1718
1733
  sendMessageRequest = {
1719
1734
  content: message.content,
1720
1735
  };
@@ -1751,52 +1766,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1751
1766
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1752
1767
  errorObject: "".concat(error_17)
1753
1768
  });
1754
- case 4: return [3 /*break*/, 9];
1755
- case 5:
1756
- messageToSend = {
1757
- content: message.content,
1758
- timestamp: new Date(),
1759
- contentType: MessageContentType_1.default.Text,
1760
- deliveryMode: DeliveryMode_1.default.Bridged,
1761
- messageType: MessageType_1.default.UserMessage,
1762
- properties: undefined,
1763
- tags: __spreadArray([], MessageTags_1.defaultMessageTags, true),
1764
- sender: {
1765
- displayName: "Customer",
1766
- id: "customer",
1767
- type: PersonType_1.default.User
1768
- }
1769
- };
1770
- if (message.tags) {
1771
- messageToSend.tags = message.tags;
1772
- }
1773
- if (message.timestamp) {
1774
- messageToSend.timestamp = message.timestamp;
1775
- }
1776
- _b.label = 6;
1777
- case 6:
1778
- _b.trys.push([6, 8, , 9]);
1779
- return [4 /*yield*/, this.conversation.sendMessage(messageToSend)];
1780
- case 7:
1781
- _b.sent();
1782
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.SendMessages, {
1783
- RequestId: this.requestId,
1784
- ChatId: this.chatToken.chatId
1785
- });
1786
- return [3 /*break*/, 9];
1787
- case 8:
1788
- error_18 = _b.sent();
1789
- exceptionDetails = {
1790
- response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1791
- errorObject: "".concat(error_18)
1792
- };
1793
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendMessages, {
1794
- RequestId: this.requestId,
1795
- ChatId: this.chatToken.chatId,
1796
- ExceptionDetails: JSON.stringify(exceptionDetails)
1797
- });
1798
- throw new Error(ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed);
1799
- case 9: return [2 /*return*/];
1769
+ case 4: return [2 /*return*/];
1800
1770
  }
1801
1771
  });
1802
1772
  });
@@ -1875,7 +1845,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1875
1845
  };
1876
1846
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
1877
1847
  return __awaiter(this, void 0, void 0, function () {
1878
- var error_19;
1848
+ var error_18;
1879
1849
  return __generator(this, function (_a) {
1880
1850
  switch (_a.label) {
1881
1851
  case 0:
@@ -1904,7 +1874,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1904
1874
  });
1905
1875
  return [3 /*break*/, 5];
1906
1876
  case 4:
1907
- error_19 = _a.sent();
1877
+ error_18 = _a.sent();
1908
1878
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1909
1879
  RequestId: this.requestId,
1910
1880
  ChatId: this.chatToken.chatId
@@ -2013,7 +1983,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2013
1983
  };
2014
1984
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
2015
1985
  return __awaiter(this, void 0, void 0, function () {
2016
- var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_20, fileMetadata, messageToSend, error_21;
1986
+ var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_19, fileMetadata, messageToSend, error_20;
2017
1987
  var _a, _b;
2018
1988
  return __generator(this, function (_c) {
2019
1989
  switch (_c.label) {
@@ -2082,7 +2052,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2082
2052
  });
2083
2053
  return [2 /*return*/, messageToSend];
2084
2054
  case 6:
2085
- error_20 = _c.sent();
2055
+ error_19 = _c.sent();
2086
2056
  console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
2087
2057
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2088
2058
  RequestId: this.requestId,
@@ -2128,8 +2098,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2128
2098
  });
2129
2099
  return [2 /*return*/, messageToSend];
2130
2100
  case 15:
2131
- error_21 = _c.sent();
2132
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_21));
2101
+ error_20 = _c.sent();
2102
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_20));
2133
2103
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2134
2104
  RequestId: this.requestId,
2135
2105
  ChatId: this.chatToken.chatId
@@ -2142,7 +2112,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2142
2112
  };
2143
2113
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
2144
2114
  return __awaiter(this, void 0, void 0, function () {
2145
- var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_22;
2115
+ var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
2146
2116
  return __generator(this, function (_b) {
2147
2117
  switch (_b.label) {
2148
2118
  case 0:
@@ -2202,8 +2172,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2202
2172
  });
2203
2173
  return [2 /*return*/, downloadedFile];
2204
2174
  case 9:
2205
- error_22 = _b.sent();
2206
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_22));
2175
+ error_21 = _b.sent();
2176
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_21));
2207
2177
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2208
2178
  RequestId: this.requestId,
2209
2179
  ChatId: this.chatToken.chatId
@@ -2216,7 +2186,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2216
2186
  };
2217
2187
  OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
2218
2188
  return __awaiter(this, arguments, void 0, function (body, optionalParams) {
2219
- var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_23;
2189
+ var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_22;
2220
2190
  var _a;
2221
2191
  if (optionalParams === void 0) { optionalParams = {}; }
2222
2192
  return __generator(this, function (_b) {
@@ -2267,8 +2237,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2267
2237
  });
2268
2238
  return [3 /*break*/, 4];
2269
2239
  case 3:
2270
- error_23 = _b.sent();
2271
- console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_23));
2240
+ error_22 = _b.sent();
2241
+ console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_22));
2272
2242
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
2273
2243
  RequestId: requestId,
2274
2244
  ChatId: chatId
@@ -2281,7 +2251,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2281
2251
  };
2282
2252
  OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
2283
2253
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2284
- var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_24, telemetryData;
2254
+ var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_23, telemetryData;
2285
2255
  var _a, _b;
2286
2256
  if (optionalParams === void 0) { optionalParams = {}; }
2287
2257
  return __generator(this, function (_c) {
@@ -2338,12 +2308,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2338
2308
  });
2339
2309
  return [2 /*return*/, transcriptResponse];
2340
2310
  case 3:
2341
- error_24 = _c.sent();
2311
+ error_23 = _c.sent();
2342
2312
  telemetryData = {
2343
2313
  RequestId: requestId,
2344
2314
  ChatId: chatId
2345
2315
  };
2346
- exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_24, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2316
+ exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_23, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2347
2317
  return [3 /*break*/, 4];
2348
2318
  case 4: return [2 /*return*/];
2349
2319
  }
@@ -2795,12 +2765,26 @@ var OmnichannelChatSDK = /** @class */ (function () {
2795
2765
  regex: value
2796
2766
  });
2797
2767
  }
2768
+ this.compileDataMaskingRegex();
2798
2769
  }
2799
2770
  }
2800
2771
  return [2 /*return*/];
2801
2772
  });
2802
2773
  });
2803
2774
  };
2775
+ OmnichannelChatSDK.prototype.compileDataMaskingRegex = function () {
2776
+ this.regexCompiledForDataMasking = [];
2777
+ for (var _i = 0, _a = this.dataMaskingRules.rules; _i < _a.length; _i++) {
2778
+ var rule = _a[_i];
2779
+ try {
2780
+ var regex = new RegExp(rule.regex, 'g');
2781
+ this.regexCompiledForDataMasking.push(regex);
2782
+ }
2783
+ catch (e) {
2784
+ console.error("Error compiling regex for data masking rule id ".concat(rule.id, ": ").concat(e));
2785
+ }
2786
+ }
2787
+ };
2804
2788
  OmnichannelChatSDK.prototype.setAuthSettingConfig = function (authSettings) {
2805
2789
  return __awaiter(this, void 0, void 0, function () {
2806
2790
  return __generator(this, function (_a) {
@@ -2879,7 +2863,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2879
2863
  };
2880
2864
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2881
2865
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2882
- var sendCacheHeaders, bypassCache, liveChatConfig, error_25, _a;
2866
+ var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
2883
2867
  var _b, _c;
2884
2868
  if (optionalParams === void 0) { optionalParams = {}; }
2885
2869
  return __generator(this, function (_d) {
@@ -2900,8 +2884,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2900
2884
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
2901
2885
  return [2 /*return*/, this.liveChatConfig];
2902
2886
  case 3:
2903
- error_25 = _d.sent();
2904
- if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_25, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2887
+ error_24 = _d.sent();
2888
+ if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_24, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2905
2889
  this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
2906
2890
  _a = this;
2907
2891
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
@@ -2913,10 +2897,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2913
2897
  return [3 /*break*/, 7];
2914
2898
  case 6:
2915
2899
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2916
- if (((_c = (_b = error_25.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_25.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
2900
+ if (((_c = (_b = error_24.response) === null || _b === void 0 ? void 0 : _b.headers) === null || _c === void 0 ? void 0 : _c.errorcode) && parseInt(error_24.response.headers.errorcode) === OmnichannelErrorCodes_1.default.WidgetNotFound) {
2917
2901
  console.warn("No widget with the given app id is present in the system.");
2918
2902
  }
2919
- throw error_25; // Bubble up error by default to throw ChatConfigRetrievalFailure
2903
+ throw error_24; // Bubble up error by default to throw ChatConfigRetrievalFailure
2920
2904
  case 7: return [3 /*break*/, 8];
2921
2905
  case 8: return [2 /*return*/, this.liveChatConfig];
2922
2906
  }
@@ -2951,7 +2935,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2951
2935
  };
2952
2936
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2953
2937
  return __awaiter(this, void 0, void 0, function () {
2954
- var sessionInfo, error_26, exceptionDetails;
2938
+ var sessionInfo, error_25, exceptionDetails;
2955
2939
  return __generator(this, function (_a) {
2956
2940
  switch (_a.label) {
2957
2941
  case 0:
@@ -2979,7 +2963,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2979
2963
  });
2980
2964
  return [3 /*break*/, 5];
2981
2965
  case 4:
2982
- error_26 = _a.sent();
2966
+ error_25 = _a.sent();
2983
2967
  exceptionDetails = {
2984
2968
  response: "UpdateChatTokenFailed"
2985
2969
  };
@@ -2996,7 +2980,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2996
2980
  };
2997
2981
  OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
2998
2982
  return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
2999
- var token, exceptionDetails, error_27, exceptionDetails, exceptionDetails;
2983
+ var token, exceptionDetails, error_26, exceptionDetails, exceptionDetails;
3000
2984
  if (optionalParams === void 0) { optionalParams = {}; }
3001
2985
  return __generator(this, function (_a) {
3002
2986
  switch (_a.label) {
@@ -3028,12 +3012,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
3028
3012
  }
3029
3013
  return [3 /*break*/, 4];
3030
3014
  case 3:
3031
- error_27 = _a.sent();
3015
+ error_26 = _a.sent();
3032
3016
  exceptionDetails = {
3033
3017
  response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
3034
3018
  };
3035
- if (error_27.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3036
- exceptionDetails.response = error_27.message;
3019
+ if (error_26.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3020
+ exceptionDetails.response = error_26.message;
3037
3021
  }
3038
3022
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
3039
3023
  ExceptionDetails: JSON.stringify(exceptionDetails)
@@ -3132,7 +3116,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3132
3116
  */
3133
3117
  OmnichannelChatSDK.prototype.getPersistentChatHistory = function () {
3134
3118
  return __awaiter(this, arguments, void 0, function (getPersistentChatHistoryOptionalParams) {
3135
- var params, result, error_28, telemetryData;
3119
+ var params, result, error_27, telemetryData;
3136
3120
  var _a, _b, _c, _d, _e;
3137
3121
  if (getPersistentChatHistoryOptionalParams === void 0) { getPersistentChatHistoryOptionalParams = {}; }
3138
3122
  return __generator(this, function (_f) {
@@ -3174,13 +3158,13 @@ var OmnichannelChatSDK = /** @class */ (function () {
3174
3158
  });
3175
3159
  return [2 /*return*/, result];
3176
3160
  case 3:
3177
- error_28 = _f.sent();
3161
+ error_27 = _f.sent();
3178
3162
  telemetryData = {
3179
3163
  RequestId: this.requestId,
3180
3164
  ChatId: (_e = this.chatToken) === null || _e === void 0 ? void 0 : _e.chatId,
3181
- ErrorMessage: (error_28 === null || error_28 === void 0 ? void 0 : error_28.message) || 'Unknown error' // Added error message for better debugging
3165
+ ErrorMessage: (error_27 === null || error_27 === void 0 ? void 0 : error_27.message) || 'Unknown error' // Added error message for better debugging
3182
3166
  };
3183
- exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(error_28, this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, telemetryData);
3167
+ exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(error_27, this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, telemetryData);
3184
3168
  return [3 /*break*/, 4];
3185
3169
  case 4: return [2 /*return*/];
3186
3170
  }