@microsoft/omnichannel-chat-widget 1.0.4 → 1.0.5-main.b47afe8

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.
@@ -9,6 +9,8 @@ var _NotificationScenarios = require("../../webchatcontainerstateful/webchatcont
9
9
  var _NotificationHandler = require("../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler");
10
10
  var _TelemetryHelper = require("../../../common/telemetry/TelemetryHelper");
11
11
  var _TelemetryConstants = require("../../../common/telemetry/TelemetryConstants");
12
+ var _dompurify = _interopRequireDefault(require("dompurify"));
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
14
  const processDisplayName = displayName => {
13
15
  // if displayname matches "teamsvisitor:<some alphanumeric string>", we replace it with "Customer"
14
16
  const displayNameRegex = ".+:.+";
@@ -64,6 +66,8 @@ const processContent = (transcriptContent, isAgentChat, renderMarkDown) => {
64
66
  }
65
67
  if (renderMarkDown) {
66
68
  transcriptContent = renderMarkDown(transcriptContent);
69
+ } else {
70
+ transcriptContent = _dompurify.default.sanitize(transcriptContent);
67
71
  }
68
72
  return transcriptContent;
69
73
  };
@@ -34,10 +34,13 @@ var _htmlPlayerMiddleware = _interopRequireDefault(require("../../webchatcontain
34
34
  var _htmlTextMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware"));
35
35
  var _preProcessingMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware"));
36
36
  var _sanitizationMiddleware = _interopRequireDefault(require("../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware"));
37
+ var _dompurify = _interopRequireDefault(require("dompurify"));
37
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
39
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
39
40
  const initWebChatComposer = (props, state, dispatch, chatSDK) => {
40
41
  var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _state$domainStates$l4, _state$domainStates$l5, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain11, _props$webChatContain12, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain13, _props$webChatContain14, _defaultWebChatContai, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
42
+ // Add a hook to make all links open a new window
43
+ postDomPurifyActivities();
41
44
  const localizedTexts = {
42
45
  ..._defaultMiddlewareLocalizedTexts.defaultMiddlewareLocalizedTexts,
43
46
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -90,9 +93,17 @@ const initWebChatComposer = (props, state, dispatch, chatSDK) => {
90
93
  markdownRenderers.forEach(renderer => {
91
94
  text = renderer.render(text);
92
95
  });
96
+ text = _dompurify.default.sanitize(text);
93
97
  return text;
94
98
  };
95
-
99
+ function postDomPurifyActivities() {
100
+ _dompurify.default.addHook("afterSanitizeAttributes", function (node) {
101
+ // set all elements owning target to target=_blank
102
+ if ("target" in node) {
103
+ node.setAttribute("target", "_blank");
104
+ }
105
+ });
106
+ }
96
107
  // Initialize the remaining Web Chat props
97
108
  const webChatProps = {
98
109
  ..._defaultWebChatContainerStatefulProps.defaultWebChatContainerStatefulProps.webChatProps,
@@ -142,6 +142,14 @@ const LiveChatWidgetStateful = props => {
142
142
  }
143
143
  if (isChatValid === false) {
144
144
  if (localState) {
145
+ // adding the reconnect logic for the case when customer tries to reconnect from a new browser or InPrivate browser
146
+ if ((0, _reconnectChatHelper.isReconnectEnabled)(props.chatConfig) === true) {
147
+ await (0, _reconnectChatHelper.handleChatReconnect)(chatSDK, props, dispatch, setAdapter, _startChat.initStartChat, state);
148
+ // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
149
+ if (state.appStates.conversationState === _ConversationState.ConversationState.Active || state.appStates.conversationState === _ConversationState.ConversationState.ReconnectChat) {
150
+ return;
151
+ }
152
+ }
145
153
  await (0, _startChat.setPreChatAndInitiateChat)(chatSDK, dispatch, setAdapter, undefined, undefined, localState, props);
146
154
  return;
147
155
  } else {
@@ -3,6 +3,7 @@ import { NotificationScenarios } from "../../webchatcontainerstateful/webchatcon
3
3
  import { NotificationHandler } from "../../webchatcontainerstateful/webchatcontroller/notification/NotificationHandler";
4
4
  import { TelemetryHelper } from "../../../common/telemetry/TelemetryHelper";
5
5
  import { LogLevel, TelemetryEvent } from "../../../common/telemetry/TelemetryConstants";
6
+ import DOMPurify from "dompurify";
6
7
  const processDisplayName = displayName => {
7
8
  // if displayname matches "teamsvisitor:<some alphanumeric string>", we replace it with "Customer"
8
9
  const displayNameRegex = ".+:.+";
@@ -58,6 +59,8 @@ const processContent = (transcriptContent, isAgentChat, renderMarkDown) => {
58
59
  }
59
60
  if (renderMarkDown) {
60
61
  transcriptContent = renderMarkDown(transcriptContent);
62
+ } else {
63
+ transcriptContent = DOMPurify.sanitize(transcriptContent);
61
64
  }
62
65
  return transcriptContent;
63
66
  };
@@ -28,10 +28,13 @@ import htmlPlayerMiddleware from "../../webchatcontainerstateful/webchatcontroll
28
28
  import htmlTextMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware";
29
29
  import preProcessingMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/preProcessingMiddleware";
30
30
  import sanitizationMiddleware from "../../webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware";
31
+ import DOMPurify from "dompurify";
31
32
 
32
33
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
34
  export const initWebChatComposer = (props, state, dispatch, chatSDK) => {
34
35
  var _props$webChatContain, _props$webChatContain2, _props$webChatContain3, _props$webChatContain4, _state$domainStates$l4, _state$domainStates$l5, _props$webChatContain9, _props$webChatContain10, _state$domainStates$r, _state$domainStates$r2, _props$webChatContain11, _props$webChatContain12, _state$domainStates$r3, _state$domainStates$r4, _props$webChatContain13, _props$webChatContain14, _defaultWebChatContai, _props$webChatContain15, _props$webChatContain16, _state$domainStates$r5, _state$domainStates$r6, _props$webChatContain17, _props$webChatContain18, _defaultWebChatContai2, _props$webChatContain19, _props$webChatContain20, _defaultWebChatContai3, _props$webChatContain21, _props$webChatContain22;
36
+ // Add a hook to make all links open a new window
37
+ postDomPurifyActivities();
35
38
  const localizedTexts = {
36
39
  ...defaultMiddlewareLocalizedTexts,
37
40
  ...((_props$webChatContain = props.webChatContainerProps) === null || _props$webChatContain === void 0 ? void 0 : _props$webChatContain.localizedTexts)
@@ -84,9 +87,17 @@ export const initWebChatComposer = (props, state, dispatch, chatSDK) => {
84
87
  markdownRenderers.forEach(renderer => {
85
88
  text = renderer.render(text);
86
89
  });
90
+ text = DOMPurify.sanitize(text);
87
91
  return text;
88
92
  };
89
-
93
+ function postDomPurifyActivities() {
94
+ DOMPurify.addHook("afterSanitizeAttributes", function (node) {
95
+ // set all elements owning target to target=_blank
96
+ if ("target" in node) {
97
+ node.setAttribute("target", "_blank");
98
+ }
99
+ });
100
+ }
90
101
  // Initialize the remaining Web Chat props
91
102
  const webChatProps = {
92
103
  ...defaultWebChatContainerStatefulProps.webChatProps,
@@ -134,6 +134,14 @@ export const LiveChatWidgetStateful = props => {
134
134
  }
135
135
  if (isChatValid === false) {
136
136
  if (localState) {
137
+ // adding the reconnect logic for the case when customer tries to reconnect from a new browser or InPrivate browser
138
+ if (isReconnectEnabled(props.chatConfig) === true) {
139
+ await handleChatReconnect(chatSDK, props, dispatch, setAdapter, initStartChat, state);
140
+ // If chat reconnect has kicked in chat state will become Active or Reconnect. So just exit, else go next
141
+ if (state.appStates.conversationState === ConversationState.Active || state.appStates.conversationState === ConversationState.ReconnectChat) {
142
+ return;
143
+ }
144
+ }
137
145
  await setPreChatAndInitiateChat(chatSDK, dispatch, setAdapter, undefined, undefined, localState, props);
138
146
  return;
139
147
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.0.4",
3
+ "version": "1.0.5-main.b47afe8",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",