@microsoft/omnichannel-chat-sdk 1.11.7-main.ac96468 → 1.11.7-main.e13c432

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.
Files changed (33) hide show
  1. package/lib/OmnichannelChatSDK.d.ts +9 -1
  2. package/lib/OmnichannelChatSDK.js +174 -158
  3. package/lib/OmnichannelChatSDK.js.map +1 -1
  4. package/lib/config/settings.d.ts +3 -2
  5. package/lib/config/settings.js +4 -2
  6. package/lib/config/settings.js.map +1 -1
  7. package/lib/core/ChatSDKError.d.ts +3 -1
  8. package/lib/core/ChatSDKError.js +2 -0
  9. package/lib/core/ChatSDKError.js.map +1 -1
  10. package/lib/core/GetPersistentChatHistoryOptionalParams.d.ts +10 -0
  11. package/lib/core/GetPersistentChatHistoryOptionalParams.js +3 -0
  12. package/lib/core/GetPersistentChatHistoryOptionalParams.js.map +1 -0
  13. package/lib/core/messaging/OmnichannelMessage.d.ts +6 -0
  14. package/lib/index.d.ts +2 -2
  15. package/lib/index.js.map +1 -1
  16. package/lib/telemetry/TelemetryEvent.d.ts +2 -1
  17. package/lib/telemetry/TelemetryEvent.js +1 -0
  18. package/lib/telemetry/TelemetryEvent.js.map +1 -1
  19. package/lib/tsconfig.tsbuildinfo +1 -1
  20. package/lib/utils/createOcSDKConfiguration.d.ts +2 -2
  21. package/lib/utils/createOcSDKConfiguration.js +16 -2
  22. package/lib/utils/createOcSDKConfiguration.js.map +1 -1
  23. package/lib/utils/createOmnichannelMessage.js +9 -0
  24. package/lib/utils/createOmnichannelMessage.js.map +1 -1
  25. package/lib/utils/exceptionThrowers.d.ts +6 -0
  26. package/lib/utils/exceptionThrowers.js +8 -2
  27. package/lib/utils/exceptionThrowers.js.map +1 -1
  28. package/lib/utils/setOcUserAgent.js +2 -1
  29. package/lib/utils/setOcUserAgent.js.map +1 -1
  30. package/lib/utils/version.d.ts +9 -0
  31. package/lib/utils/version.js +28 -0
  32. package/lib/utils/version.js.map +1 -0
  33. package/package.json +2 -2
@@ -105,7 +105,6 @@ var loggerUtils_1 = require("./utils/loggerUtils");
105
105
  var parsers_1 = require("./utils/parsers");
106
106
  var platform_1 = require("./utils/platform");
107
107
  var retrieveCollectorUri_1 = require("./telemetry/retrieveCollectorUri");
108
- var setOcUserAgent_1 = require("./utils/setOcUserAgent");
109
108
  var startPolling_1 = require("./commands/startPolling");
110
109
  var stopPolling_1 = require("./commands/stopPolling");
111
110
  var urlResolvers_1 = require("./utils/urlResolvers");
@@ -150,6 +149,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
150
149
  this.debugAMS = false;
151
150
  this.debugACS = false;
152
151
  this.detailedDebugEnabled = false;
152
+ this.regexCompiledForDataMasking = [];
153
153
  this.populateInitChatOptionalParam = function (requestOptionalParams, optionalParams, telemetryEvent) {
154
154
  requestOptionalParams.initContext.locale = (0, locale_1.getLocaleStringFromId)(_this.localeId);
155
155
  if (optionalParams === null || optionalParams === void 0 ? void 0 : optionalParams.customContext) {
@@ -551,10 +551,9 @@ var OmnichannelChatSDK = /** @class */ (function () {
551
551
  _j.trys.push([1, 3, , 4]);
552
552
  this.OCSDKProvider = ocsdk_1.SDKProvider;
553
553
  _a = this;
554
- return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices), this.ocSdkLogger)];
554
+ return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices, (_d = this.chatSDKConfig) === null || _d === void 0 ? void 0 : _d.ocUserAgent), this.ocSdkLogger)];
555
555
  case 2:
556
556
  _a.OCClient = _j.sent();
557
- (0, setOcUserAgent_1.default)(this.OCClient, (_d = this.chatSDKConfig) === null || _d === void 0 ? void 0 : _d.ocUserAgent);
558
557
  return [3 /*break*/, 4];
559
558
  case 3:
560
559
  e_2 = _j.sent();
@@ -657,8 +656,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
657
656
  useCoreServices = (0, CoreServicesUtils_1.isCoreServicesOrgUrl)(this.omnichannelConfig.orgUrl);
658
657
  try {
659
658
  this.OCSDKProvider = ocsdk_1.SDKProvider;
660
- this.OCClient = ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices), this.ocSdkLogger);
661
- (0, setOcUserAgent_1.default)(this.OCClient, (_a = this.chatSDKConfig) === null || _a === void 0 ? void 0 : _a.ocUserAgent);
659
+ this.OCClient = ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(useCoreServices, (_a = this.chatSDKConfig) === null || _a === void 0 ? void 0 : _a.ocUserAgent), this.ocSdkLogger);
662
660
  }
663
661
  catch (e) {
664
662
  exceptionThrowers_1.default.throwOmnichannelClientInitializationFailure(e, this.scenarioMarker, TelemetryEvent_1.default.InitializeLoadChatConfig);
@@ -1687,21 +1685,36 @@ var OmnichannelChatSDK = /** @class */ (function () {
1687
1685
  }
1688
1686
  var content = message.content;
1689
1687
  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);
1688
+ if (this.regexCompiledForDataMasking.length === 0) {
1689
+ return message;
1690
+ }
1691
+ for (var _i = 0, _a = this.regexCompiledForDataMasking; _i < _a.length; _i++) {
1692
+ var regex = _a[_i];
1693
+ try {
1694
+ var lastIndex = -1;
1695
+ while ((match = regex.exec(content)) !== null) {
1696
+ // Prevent infinite loop from zero-width matches
1697
+ if (regex.lastIndex === lastIndex) {
1698
+ this.debug && console.warn("[OmnichannelChatSDK][transformMessage] Data masking regex caused zero-width match, skipping rule ".concat(regex));
1699
+ break;
1700
+ }
1701
+ lastIndex = regex.lastIndex;
1702
+ var replaceStr = match[0].replace(/./g, this.maskingCharacter);
1703
+ content = content.replace(match[0], replaceStr);
1704
+ }
1705
+ match = null;
1706
+ }
1707
+ catch (error) {
1708
+ // Log error for invalid regex but continue processing other rules
1709
+ this.debug && console.error("[OmnichannelChatSDK][transformMessage] Data masking regex failed for rule ".concat(regex, ": ").concat(error));
1696
1710
  }
1697
- match = null;
1698
1711
  }
1699
1712
  message.content = content;
1700
1713
  return message;
1701
1714
  };
1702
1715
  OmnichannelChatSDK.prototype.sendMessage = function (message) {
1703
1716
  return __awaiter(this, void 0, void 0, function () {
1704
- var sendMessageRequest, chatMessage, error_17, exceptionDetails, messageToSend, error_18, exceptionDetails;
1717
+ var sendMessageRequest, chatMessage, error_17, exceptionDetails;
1705
1718
  var _a;
1706
1719
  return __generator(this, function (_b) {
1707
1720
  switch (_b.label) {
@@ -1714,7 +1727,6 @@ var OmnichannelChatSDK = /** @class */ (function () {
1714
1727
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.SendMessages);
1715
1728
  }
1716
1729
  this.transformMessage(message);
1717
- if (!(this.liveChatVersion === LiveChatVersion_1.default.V2)) return [3 /*break*/, 5];
1718
1730
  sendMessageRequest = {
1719
1731
  content: message.content,
1720
1732
  };
@@ -1751,52 +1763,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1751
1763
  response: ChatSDKError_1.ChatSDKErrorName.ChatSDKSendMessageFailed,
1752
1764
  errorObject: "".concat(error_17)
1753
1765
  });
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*/];
1766
+ case 4: return [2 /*return*/];
1800
1767
  }
1801
1768
  });
1802
1769
  });
@@ -1847,12 +1814,17 @@ var OmnichannelChatSDK = /** @class */ (function () {
1847
1814
  }
1848
1815
  (_b = this.conversation) === null || _b === void 0 ? void 0 : _b.registerOnNewMessage(function (event) {
1849
1816
  var id = event.id;
1817
+ var isChatMessageEditedEvent = Object.keys(event).includes("editedOn");
1818
+ console.log("[OmnichannelChatSDK][onNewMessage] New message received", event);
1819
+ console.log("[OmnichannelChatSDK][onNewMessage] isChatMessageEditedEvent=>", isChatMessageEditedEvent);
1850
1820
  var omnichannelMessage = (0, createOmnichannelMessage_1.default)(event, {
1851
1821
  liveChatVersion: _this.liveChatVersion,
1852
1822
  debug: (_this.detailedDebugEnabled ? _this.debugACS : _this.debug),
1853
1823
  });
1854
- if (!postedMessages_1.has(id)) {
1824
+ // send callback for new messages or edited existent messages
1825
+ if (!postedMessages_1.has(id) || isChatMessageEditedEvent) {
1855
1826
  onNewMessageCallback(omnichannelMessage);
1827
+ console.log("[OmnichannelChatSDK][onNewMessage] Message posted");
1856
1828
  postedMessages_1.add(id);
1857
1829
  }
1858
1830
  }, registerOnNewMessageOptionalParams);
@@ -1875,7 +1847,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1875
1847
  };
1876
1848
  OmnichannelChatSDK.prototype.sendTypingEvent = function () {
1877
1849
  return __awaiter(this, void 0, void 0, function () {
1878
- var error_19;
1850
+ var error_18;
1879
1851
  return __generator(this, function (_a) {
1880
1852
  switch (_a.label) {
1881
1853
  case 0:
@@ -1904,7 +1876,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1904
1876
  });
1905
1877
  return [3 /*break*/, 5];
1906
1878
  case 4:
1907
- error_19 = _a.sent();
1879
+ error_18 = _a.sent();
1908
1880
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.SendTypingEvent, {
1909
1881
  RequestId: this.requestId,
1910
1882
  ChatId: this.chatToken.chatId
@@ -1972,8 +1944,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
1972
1944
  OmnichannelChatSDK.prototype.onAgentEndSession = function (onAgentEndSessionCallback) {
1973
1945
  return __awaiter(this, void 0, void 0, function () {
1974
1946
  var _this = this;
1975
- var _a;
1976
- return __generator(this, function (_b) {
1947
+ return __generator(this, function (_a) {
1977
1948
  this.scenarioMarker.startScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1978
1949
  RequestId: this.requestId,
1979
1950
  ChatId: this.chatToken.chatId
@@ -1981,59 +1952,32 @@ var OmnichannelChatSDK = /** @class */ (function () {
1981
1952
  if (!this.isInitialized) {
1982
1953
  exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.OnAgentEndSession);
1983
1954
  }
1984
- if (this.liveChatVersion === LiveChatVersion_1.default.V2) {
1985
- try {
1986
- this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
1987
- var liveWorkItemDetails;
1988
- return __generator(this, function (_a) {
1989
- switch (_a.label) {
1990
- case 0: return [4 /*yield*/, this.getConversationDetails()];
1991
- case 1:
1992
- liveWorkItemDetails = _a.sent();
1993
- if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
1994
- onAgentEndSessionCallback(event);
1995
- this.stopPolling();
1996
- }
1997
- return [2 /*return*/];
1998
- }
1999
- });
2000
- }); });
2001
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2002
- RequestId: this.requestId,
2003
- ChatId: this.chatToken.chatId
2004
- });
2005
- }
2006
- catch (error) {
2007
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2008
- RequestId: this.requestId,
2009
- ChatId: this.chatToken.chatId
2010
- });
2011
- }
2012
- }
2013
- else {
2014
- try {
2015
- (_a = this.conversation) === null || _a === void 0 ? void 0 : _a.registerOnThreadUpdate(function (message) {
2016
- var members = message.members;
2017
- // Agent ending conversation would have 1 member left in the chat thread
2018
- if (members.length === 1) {
2019
- onAgentEndSessionCallback(message);
2020
- if (_this.refreshTokenTimer !== null) {
2021
- clearInterval(_this.refreshTokenTimer);
2022
- _this.refreshTokenTimer = null;
2023
- }
1955
+ try {
1956
+ this.conversation.registerOnThreadUpdate(function (event) { return __awaiter(_this, void 0, void 0, function () {
1957
+ var liveWorkItemDetails;
1958
+ return __generator(this, function (_a) {
1959
+ switch (_a.label) {
1960
+ case 0: return [4 /*yield*/, this.getConversationDetails()];
1961
+ case 1:
1962
+ liveWorkItemDetails = _a.sent();
1963
+ if (Object.keys(liveWorkItemDetails).length === 0 || liveWorkItemDetails.state == LiveWorkItemState_1.default.WrapUp || liveWorkItemDetails.state == LiveWorkItemState_1.default.Closed) {
1964
+ onAgentEndSessionCallback(event);
1965
+ this.stopPolling();
1966
+ }
1967
+ return [2 /*return*/];
2024
1968
  }
2025
1969
  });
2026
- this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2027
- RequestId: this.requestId,
2028
- ChatId: this.chatToken.chatId
2029
- });
2030
- }
2031
- catch (error) {
2032
- this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
2033
- RequestId: this.requestId,
2034
- ChatId: this.chatToken.chatId
2035
- });
2036
- }
1970
+ }); });
1971
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1972
+ RequestId: this.requestId,
1973
+ ChatId: this.chatToken.chatId
1974
+ });
1975
+ }
1976
+ catch (error) {
1977
+ this.scenarioMarker.failScenario(TelemetryEvent_1.default.OnAgentEndSession, {
1978
+ RequestId: this.requestId,
1979
+ ChatId: this.chatToken.chatId
1980
+ });
2037
1981
  }
2038
1982
  return [2 /*return*/];
2039
1983
  });
@@ -2041,7 +1985,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2041
1985
  };
2042
1986
  OmnichannelChatSDK.prototype.uploadFileAttachment = function (fileInfo) {
2043
1987
  return __awaiter(this, void 0, void 0, function () {
2044
- var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_20, fileMetadata, messageToSend, error_21;
1988
+ var amsClient, createObjectResponse, documentId, uploadDocumentResponse, fileIdsProperty, fileMetaProperty, sendMessageRequest, messageToSend, error_19, fileMetadata, messageToSend, error_20;
2045
1989
  var _a, _b;
2046
1990
  return __generator(this, function (_c) {
2047
1991
  switch (_c.label) {
@@ -2110,7 +2054,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2110
2054
  });
2111
2055
  return [2 /*return*/, messageToSend];
2112
2056
  case 6:
2113
- error_20 = _c.sent();
2057
+ error_19 = _c.sent();
2114
2058
  console.error("OmnichannelChatSDK/uploadFileAttachment/sendMessage/error");
2115
2059
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2116
2060
  RequestId: this.requestId,
@@ -2156,8 +2100,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2156
2100
  });
2157
2101
  return [2 /*return*/, messageToSend];
2158
2102
  case 15:
2159
- error_21 = _c.sent();
2160
- console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_21));
2103
+ error_20 = _c.sent();
2104
+ console.error("OmnichannelChatSDK/uploadFileAttachment/error: ".concat(error_20));
2161
2105
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.UploadFileAttachment, {
2162
2106
  RequestId: this.requestId,
2163
2107
  ChatId: this.chatToken.chatId
@@ -2170,7 +2114,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2170
2114
  };
2171
2115
  OmnichannelChatSDK.prototype.downloadFileAttachment = function (fileMetadata) {
2172
2116
  return __awaiter(this, void 0, void 0, function () {
2173
- var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_22;
2117
+ var amsClient, response, view_location, viewResponse, _a, downloadedFile, error_21;
2174
2118
  return __generator(this, function (_b) {
2175
2119
  switch (_b.label) {
2176
2120
  case 0:
@@ -2230,8 +2174,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2230
2174
  });
2231
2175
  return [2 /*return*/, downloadedFile];
2232
2176
  case 9:
2233
- error_22 = _b.sent();
2234
- console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_22));
2177
+ error_21 = _b.sent();
2178
+ console.error("OmnichannelChatSDK/downloadFileAttachment/error: ".concat(error_21));
2235
2179
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.DownloadFileAttachment, {
2236
2180
  RequestId: this.requestId,
2237
2181
  ChatId: this.chatToken.chatId
@@ -2244,7 +2188,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2244
2188
  };
2245
2189
  OmnichannelChatSDK.prototype.emailLiveChatTranscript = function (body_1) {
2246
2190
  return __awaiter(this, arguments, void 0, function (body, optionalParams) {
2247
- var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_23;
2191
+ var emailTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, emailRequestBody, error_22;
2248
2192
  var _a;
2249
2193
  if (optionalParams === void 0) { optionalParams = {}; }
2250
2194
  return __generator(this, function (_b) {
@@ -2295,8 +2239,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2295
2239
  });
2296
2240
  return [3 /*break*/, 4];
2297
2241
  case 3:
2298
- error_23 = _b.sent();
2299
- console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_23));
2242
+ error_22 = _b.sent();
2243
+ console.error("OmnichannelChatSDK/emailLiveChatTranscript/error: ".concat(error_22));
2300
2244
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.EmailLiveChatTranscript, {
2301
2245
  RequestId: requestId,
2302
2246
  ChatId: chatId
@@ -2309,7 +2253,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2309
2253
  };
2310
2254
  OmnichannelChatSDK.prototype.getLiveChatTranscript = function () {
2311
2255
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2312
- var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_24, telemetryData;
2256
+ var getChatTranscriptOptionalParams, requestId, chatToken, chatId, sessionId, transcriptResponse, error_23, telemetryData;
2313
2257
  var _a, _b;
2314
2258
  if (optionalParams === void 0) { optionalParams = {}; }
2315
2259
  return __generator(this, function (_c) {
@@ -2366,12 +2310,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
2366
2310
  });
2367
2311
  return [2 /*return*/, transcriptResponse];
2368
2312
  case 3:
2369
- error_24 = _c.sent();
2313
+ error_23 = _c.sent();
2370
2314
  telemetryData = {
2371
2315
  RequestId: requestId,
2372
2316
  ChatId: chatId
2373
2317
  };
2374
- exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_24, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2318
+ exceptionThrowers_1.default.throwLiveChatTranscriptRetrievalFailure(error_23, this.scenarioMarker, TelemetryEvent_1.default.GetLiveChatTranscript, telemetryData);
2375
2319
  return [3 /*break*/, 4];
2376
2320
  case 4: return [2 /*return*/];
2377
2321
  }
@@ -2486,7 +2430,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2486
2430
  };
2487
2431
  OmnichannelChatSDK.prototype.getPostChatSurveyContext = function () {
2488
2432
  return __awaiter(this, void 0, void 0, function () {
2489
- var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, msdyn_surveyprovider, surveyProvider, liveWorkItemDetails, participantJoined, participantType, agentSurveyInviteLinkRequest, botSurveyInviteLinkRequest, optionalParams, agentSurveyInviteLinkResponse, botSurveyInviteLinkResponse, _a, agentSurveyInviteLink, agentFormsProLocale, botSurveyInviteLink, botFormsProLocale, postChatContext, ex_1;
2433
+ var conversationId, chatConfig, liveWSAndLiveChatEngJoin, msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId, postConversationBotSurveyOwnerId, msdyn_surveyprovider, surveyProvider, liveWorkItemDetails, participantJoined, participantType, agentSurveyInviteLinkRequest, botSurveyInviteLinkRequest, optionalParams, _a, agentSurveyInviteLinkResponse, botSurveyInviteLinkResponse, agentSurveyInviteLink, agentFormsProLocale, botSurveyInviteLink, botFormsProLocale, postChatContext, ex_1;
2490
2434
  var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
2491
2435
  return __generator(this, function (_o) {
2492
2436
  switch (_o.label) {
@@ -2500,7 +2444,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2500
2444
  }
2501
2445
  _o.label = 1;
2502
2446
  case 1:
2503
- _o.trys.push([1, 8, , 9]);
2447
+ _o.trys.push([1, 6, , 7]);
2504
2448
  chatConfig = this.liveChatConfig;
2505
2449
  liveWSAndLiveChatEngJoin = chatConfig.LiveWSAndLiveChatEngJoin;
2506
2450
  msdyn_postconversationsurveyenable = liveWSAndLiveChatEngJoin.msdyn_postconversationsurveyenable, msfp_sourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_sourcesurveyidentifier, msfp_botsourcesurveyidentifier = liveWSAndLiveChatEngJoin.msfp_botsourcesurveyidentifier, postConversationSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationSurveyOwnerId, postConversationBotSurveyOwnerId = liveWSAndLiveChatEngJoin.postConversationBotSurveyOwnerId, msdyn_surveyprovider = liveWSAndLiveChatEngJoin.msdyn_surveyprovider;
@@ -2513,7 +2457,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2513
2457
  });
2514
2458
  return [2 /*return*/, Promise.reject("GetPostChatSurveyContext : msfp_sourcesurveyidentifier is mandatory for survey provider ".concat(SurveyProvider_1.SurveyProvider.CustomerVoice, "."))];
2515
2459
  }
2516
- if (!((0, parsers_1.parseLowerCaseString)(msdyn_postconversationsurveyenable) === "true")) return [3 /*break*/, 6];
2460
+ if (!((0, parsers_1.parseLowerCaseString)(msdyn_postconversationsurveyenable) === "true")) return [3 /*break*/, 4];
2517
2461
  return [4 /*yield*/, this.getConversationDetails()];
2518
2462
  case 2:
2519
2463
  liveWorkItemDetails = _o.sent();
@@ -2556,17 +2500,14 @@ var OmnichannelChatSDK = /** @class */ (function () {
2556
2500
  if (this.authenticatedUserToken) {
2557
2501
  optionalParams.authenticatedUserToken = this.authenticatedUserToken;
2558
2502
  }
2559
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams)];
2503
+ return [4 /*yield*/, Promise.all([
2504
+ this.OCClient.getSurveyInviteLink(postConversationSurveyOwnerId, agentSurveyInviteLinkRequest, optionalParams),
2505
+ (postConversationBotSurveyOwnerId && msfp_botsourcesurveyidentifier)
2506
+ ? this.OCClient.getSurveyInviteLink(postConversationBotSurveyOwnerId, botSurveyInviteLinkRequest, optionalParams)
2507
+ : Promise.resolve(null)
2508
+ ])];
2560
2509
  case 3:
2561
- agentSurveyInviteLinkResponse = _o.sent();
2562
- _a = postConversationBotSurveyOwnerId && msfp_botsourcesurveyidentifier;
2563
- if (!_a) return [3 /*break*/, 5];
2564
- return [4 /*yield*/, this.OCClient.getSurveyInviteLink(postConversationBotSurveyOwnerId, botSurveyInviteLinkRequest, optionalParams)];
2565
- case 4:
2566
- _a = (_o.sent());
2567
- _o.label = 5;
2568
- case 5:
2569
- botSurveyInviteLinkResponse = _a;
2510
+ _a = _o.sent(), agentSurveyInviteLinkResponse = _a[0], botSurveyInviteLinkResponse = _a[1];
2570
2511
  agentSurveyInviteLink = void 0, agentFormsProLocale = void 0, botSurveyInviteLink = void 0, botFormsProLocale = void 0;
2571
2512
  if (agentSurveyInviteLinkResponse != null) {
2572
2513
  if (agentSurveyInviteLinkResponse.inviteList != null && agentSurveyInviteLinkResponse.inviteList.length == 1) {
@@ -2615,16 +2556,16 @@ var OmnichannelChatSDK = /** @class */ (function () {
2615
2556
  });
2616
2557
  return [2 /*return*/, Promise.reject("surveyInviteLinkResponse is null.")];
2617
2558
  }
2618
- return [3 /*break*/, 7];
2619
- case 6:
2559
+ return [3 /*break*/, 5];
2560
+ case 4:
2620
2561
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
2621
2562
  RequestId: this.requestId,
2622
2563
  ChatId: (_l = this.chatToken) === null || _l === void 0 ? void 0 : _l.chatId,
2623
2564
  ExceptionDetails: "Post Chat Survey is disabled. Please check the Omnichannel Administration Portal."
2624
2565
  });
2625
2566
  return [2 /*return*/, Promise.reject("Post Chat is disabled from admin side, or chat doesnt have a survey as part of their configuration.")];
2626
- case 7: return [3 /*break*/, 9];
2627
- case 8:
2567
+ case 5: return [3 /*break*/, 7];
2568
+ case 6:
2628
2569
  ex_1 = _o.sent();
2629
2570
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetPostChatSurveyContext, {
2630
2571
  ConversationId: conversationId !== null && conversationId !== void 0 ? conversationId : "",
@@ -2633,7 +2574,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2633
2574
  ExceptionDetails: JSON.stringify(ex_1)
2634
2575
  });
2635
2576
  return [2 /*return*/, Promise.reject("Retrieving post chat context failed " + JSON.stringify(ex_1))];
2636
- case 9: return [2 /*return*/];
2577
+ case 7: return [2 /*return*/];
2637
2578
  }
2638
2579
  });
2639
2580
  });
@@ -2826,12 +2767,26 @@ var OmnichannelChatSDK = /** @class */ (function () {
2826
2767
  regex: value
2827
2768
  });
2828
2769
  }
2770
+ this.compileDataMaskingRegex();
2829
2771
  }
2830
2772
  }
2831
2773
  return [2 /*return*/];
2832
2774
  });
2833
2775
  });
2834
2776
  };
2777
+ OmnichannelChatSDK.prototype.compileDataMaskingRegex = function () {
2778
+ this.regexCompiledForDataMasking = [];
2779
+ for (var _i = 0, _a = this.dataMaskingRules.rules; _i < _a.length; _i++) {
2780
+ var rule = _a[_i];
2781
+ try {
2782
+ var regex = new RegExp(rule.regex, 'g');
2783
+ this.regexCompiledForDataMasking.push(regex);
2784
+ }
2785
+ catch (e) {
2786
+ console.error("Error compiling regex for data masking rule id ".concat(rule.id, ": ").concat(e));
2787
+ }
2788
+ }
2789
+ };
2835
2790
  OmnichannelChatSDK.prototype.setAuthSettingConfig = function (authSettings) {
2836
2791
  return __awaiter(this, void 0, void 0, function () {
2837
2792
  return __generator(this, function (_a) {
@@ -2910,7 +2865,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2910
2865
  };
2911
2866
  OmnichannelChatSDK.prototype.getChatConfig = function () {
2912
2867
  return __awaiter(this, arguments, void 0, function (optionalParams) {
2913
- var sendCacheHeaders, bypassCache, liveChatConfig, error_25, _a;
2868
+ var sendCacheHeaders, bypassCache, liveChatConfig, error_24, _a;
2914
2869
  var _b, _c;
2915
2870
  if (optionalParams === void 0) { optionalParams = {}; }
2916
2871
  return __generator(this, function (_d) {
@@ -2931,8 +2886,8 @@ var OmnichannelChatSDK = /** @class */ (function () {
2931
2886
  this.debug && console.log("[OmnichannelChatSDK][getChatConfig][liveChatVersion] ".concat(this.liveChatVersion));
2932
2887
  return [2 /*return*/, this.liveChatConfig];
2933
2888
  case 3:
2934
- error_25 = _d.sent();
2935
- if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_25, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2889
+ error_24 = _d.sent();
2890
+ if (!(0, internalUtils_1.isCoreServicesOrgUrlDNSError)(error_24, this.coreServicesOrgUrl, this.dynamicsLocationCode)) return [3 /*break*/, 6];
2936
2891
  this.omnichannelConfig.orgUrl = this.unqServicesOrgUrl;
2937
2892
  _a = this;
2938
2893
  return [4 /*yield*/, ocsdk_1.SDKProvider.getSDK(this.omnichannelConfig, (0, createOcSDKConfiguration_1.default)(false), this.ocSdkLogger)];
@@ -2944,10 +2899,10 @@ var OmnichannelChatSDK = /** @class */ (function () {
2944
2899
  return [3 /*break*/, 7];
2945
2900
  case 6:
2946
2901
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2947
- 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) {
2902
+ 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) {
2948
2903
  console.warn("No widget with the given app id is present in the system.");
2949
2904
  }
2950
- throw error_25; // Bubble up error by default to throw ChatConfigRetrievalFailure
2905
+ throw error_24; // Bubble up error by default to throw ChatConfigRetrievalFailure
2951
2906
  case 7: return [3 /*break*/, 8];
2952
2907
  case 8: return [2 /*return*/, this.liveChatConfig];
2953
2908
  }
@@ -2982,7 +2937,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
2982
2937
  };
2983
2938
  OmnichannelChatSDK.prototype.updateChatToken = function (newToken, newRegionGTMS) {
2984
2939
  return __awaiter(this, void 0, void 0, function () {
2985
- var sessionInfo, error_26, exceptionDetails;
2940
+ var sessionInfo, error_25, exceptionDetails;
2986
2941
  return __generator(this, function (_a) {
2987
2942
  switch (_a.label) {
2988
2943
  case 0:
@@ -3010,7 +2965,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3010
2965
  });
3011
2966
  return [3 /*break*/, 5];
3012
2967
  case 4:
3013
- error_26 = _a.sent();
2968
+ error_25 = _a.sent();
3014
2969
  exceptionDetails = {
3015
2970
  response: "UpdateChatTokenFailed"
3016
2971
  };
@@ -3027,7 +2982,7 @@ var OmnichannelChatSDK = /** @class */ (function () {
3027
2982
  };
3028
2983
  OmnichannelChatSDK.prototype.setAuthTokenProvider = function (provider_1) {
3029
2984
  return __awaiter(this, arguments, void 0, function (provider, optionalParams) {
3030
- var token, exceptionDetails, error_27, exceptionDetails, exceptionDetails;
2985
+ var token, exceptionDetails, error_26, exceptionDetails, exceptionDetails;
3031
2986
  if (optionalParams === void 0) { optionalParams = {}; }
3032
2987
  return __generator(this, function (_a) {
3033
2988
  switch (_a.label) {
@@ -3059,12 +3014,12 @@ var OmnichannelChatSDK = /** @class */ (function () {
3059
3014
  }
3060
3015
  return [3 /*break*/, 4];
3061
3016
  case 3:
3062
- error_27 = _a.sent();
3017
+ error_26 = _a.sent();
3063
3018
  exceptionDetails = {
3064
3019
  response: ChatSDKError_1.ChatSDKErrorName.GetAuthTokenFailed
3065
3020
  };
3066
- if (error_27.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3067
- exceptionDetails.response = error_27.message;
3021
+ if (error_26.message == ChatSDKError_1.ChatSDKErrorName.UndefinedAuthToken) {
3022
+ exceptionDetails.response = error_26.message;
3068
3023
  }
3069
3024
  this.scenarioMarker.failScenario(TelemetryEvent_1.default.GetAuthToken, {
3070
3025
  ExceptionDetails: JSON.stringify(exceptionDetails)
@@ -3157,6 +3112,67 @@ var OmnichannelChatSDK = /** @class */ (function () {
3157
3112
  });
3158
3113
  });
3159
3114
  };
3115
+ /**
3116
+ * Get persistent chat history for authenticated users.
3117
+ * @param getPersistentChatHistoryOptionalParams Optional parameters for persistent chat history retrieval.
3118
+ */
3119
+ OmnichannelChatSDK.prototype.getPersistentChatHistory = function () {
3120
+ return __awaiter(this, arguments, void 0, function (getPersistentChatHistoryOptionalParams) {
3121
+ var params, result, error_27, telemetryData;
3122
+ var _a, _b, _c, _d, _e;
3123
+ if (getPersistentChatHistoryOptionalParams === void 0) { getPersistentChatHistoryOptionalParams = {}; }
3124
+ return __generator(this, function (_f) {
3125
+ switch (_f.label) {
3126
+ case 0:
3127
+ if (!this.requestId) {
3128
+ this.requestId = (0, ocsdk_1.uuidv4)();
3129
+ }
3130
+ this.scenarioMarker.startScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3131
+ RequestId: this.requestId
3132
+ });
3133
+ if (!this.isInitialized) {
3134
+ exceptionThrowers_1.default.throwUninitializedChatSDK(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory);
3135
+ }
3136
+ if (!this.isPersistentChat || ((_a = this.chatSDKConfig.persistentChat) === null || _a === void 0 ? void 0 : _a.disable) === true) {
3137
+ exceptionThrowers_1.default.throwNotPersistentChatEnabled(this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3138
+ RequestId: this.requestId,
3139
+ ChatId: (_b = this.chatToken) === null || _b === void 0 ? void 0 : _b.chatId
3140
+ });
3141
+ }
3142
+ if (!this.authenticatedUserToken) {
3143
+ exceptionThrowers_1.default.throwChatSDKError(ChatSDKError_1.ChatSDKErrorName.AuthenticatedUserTokenNotFound, new Error('Authenticated user token not found'), this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, {
3144
+ RequestId: this.requestId,
3145
+ ChatId: (_c = this.chatToken) === null || _c === void 0 ? void 0 : _c.chatId
3146
+ });
3147
+ }
3148
+ _f.label = 1;
3149
+ case 1:
3150
+ _f.trys.push([1, 3, , 4]);
3151
+ params = {};
3152
+ params.pageSize = getPersistentChatHistoryOptionalParams.pageSize || undefined;
3153
+ params.pageToken = getPersistentChatHistoryOptionalParams.pageToken || undefined;
3154
+ return [4 /*yield*/, this.OCClient.getPersistentChatHistory(this.requestId, __assign(__assign({}, params), { authenticatedUserToken: this.authenticatedUserToken }))];
3155
+ case 2:
3156
+ result = _f.sent();
3157
+ this.scenarioMarker.completeScenario(TelemetryEvent_1.default.GetPersistentChatHistory, {
3158
+ RequestId: this.requestId,
3159
+ ChatId: (_d = this.chatToken) === null || _d === void 0 ? void 0 : _d.chatId
3160
+ });
3161
+ return [2 /*return*/, result];
3162
+ case 3:
3163
+ error_27 = _f.sent();
3164
+ telemetryData = {
3165
+ RequestId: this.requestId,
3166
+ ChatId: (_e = this.chatToken) === null || _e === void 0 ? void 0 : _e.chatId,
3167
+ ErrorMessage: (error_27 === null || error_27 === void 0 ? void 0 : error_27.message) || 'Unknown error' // Added error message for better debugging
3168
+ };
3169
+ exceptionThrowers_1.default.throwPersistentChatConversationRetrievalFailure(error_27, this.scenarioMarker, TelemetryEvent_1.default.GetPersistentChatHistory, telemetryData);
3170
+ return [3 /*break*/, 4];
3171
+ case 4: return [2 /*return*/];
3172
+ }
3173
+ });
3174
+ });
3175
+ };
3160
3176
  return OmnichannelChatSDK;
3161
3177
  }());
3162
3178
  exports.default = OmnichannelChatSDK;