@microsoft/omnichannel-chat-widget 1.7.6 → 1.7.7-main.262d750

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 (42) hide show
  1. package/lib/cjs/common/Constants.js +3 -0
  2. package/lib/cjs/common/facades/FacadeChatSDK.js +62 -19
  3. package/lib/cjs/common/utils.js +14 -2
  4. package/lib/cjs/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +15 -0
  5. package/lib/cjs/components/livechatwidget/common/createMarkdown.js +4 -3
  6. package/lib/cjs/components/livechatwidget/common/initWebChatComposer.js +27 -22
  7. package/lib/cjs/components/livechatwidget/interfaces/ISendBox.js +1 -0
  8. package/lib/cjs/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +17 -13
  9. package/lib/cjs/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +10 -5
  10. package/lib/cjs/components/webchatcontainerstateful/WebChatContainerStateful.js +13 -1
  11. package/lib/cjs/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +2 -0
  12. package/lib/cjs/components/webchatcontainerstateful/common/defaultStyles/defaultWebChatStyles.js +1 -1
  13. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer.js +3 -1
  14. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +15 -2
  15. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware.js +9 -10
  16. package/lib/cjs/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware.js +3 -1
  17. package/lib/cjs/plugins/createChatTranscript.js +5 -1
  18. package/lib/esm/common/Constants.js +3 -0
  19. package/lib/esm/common/facades/FacadeChatSDK.js +62 -19
  20. package/lib/esm/common/utils.js +11 -1
  21. package/lib/esm/components/footerstateful/downloadtranscriptstateful/DownloadTranscriptStateful.js +15 -0
  22. package/lib/esm/components/livechatwidget/common/createMarkdown.js +4 -3
  23. package/lib/esm/components/livechatwidget/common/initWebChatComposer.js +28 -22
  24. package/lib/esm/components/livechatwidget/interfaces/ISendBox.js +1 -0
  25. package/lib/esm/components/livechatwidget/livechatwidgetstateful/LiveChatWidgetStateful.js +17 -13
  26. package/lib/esm/components/prechatsurveypanestateful/PreChatSurveyPaneStateful.js +10 -5
  27. package/lib/esm/components/webchatcontainerstateful/WebChatContainerStateful.js +15 -3
  28. package/lib/esm/components/webchatcontainerstateful/common/defaultProps/defaultWebChatContainerStatefulProps.js +2 -0
  29. package/lib/esm/components/webchatcontainerstateful/common/defaultStyles/defaultWebChatStyles.js +1 -1
  30. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/markdownrenderers/HyperlinkTextOverrideRenderer.js +3 -1
  31. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/renderingmiddlewares/timestamps/DeliveredTimestamp.js +15 -2
  32. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware.js +9 -10
  33. package/lib/esm/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/sanitizationMiddleware.js +3 -1
  34. package/lib/esm/plugins/createChatTranscript.js +5 -1
  35. package/lib/types/common/Constants.d.ts +3 -0
  36. package/lib/types/common/facades/FacadeChatSDK.d.ts +2 -0
  37. package/lib/types/common/utils.d.ts +1 -0
  38. package/lib/types/components/livechatwidget/common/createMarkdown.d.ts +1 -1
  39. package/lib/types/components/livechatwidget/interfaces/ISendBox.d.ts +12 -0
  40. package/lib/types/components/webchatcontainerstateful/interfaces/IWebChatContainerStatefulProps.d.ts +5 -0
  41. package/lib/types/components/webchatcontainerstateful/webchatcontroller/middlewares/storemiddlewares/htmlTextMiddleware.d.ts +1 -1
  42. package/package.json +2 -2
@@ -11,7 +11,9 @@ class HyperlinkTextOverrideRenderer {
11
11
  convertTextToHtmlNode(text) {
12
12
  const htmlNode = document.createElement(HtmlAttributeNames.div);
13
13
  try {
14
- text = DOMPurify.sanitize(text); // eslint-disable-line @typescript-eslint/no-explicit-any
14
+ text = DOMPurify.sanitize(text, {
15
+ ADD_ATTR: ["target"]
16
+ });
15
17
  htmlNode.innerHTML = text;
16
18
  } catch {
17
19
  return htmlNode;
@@ -25,14 +25,27 @@ export const DeliveredTimestamp = _ref => {
25
25
  timestamp
26
26
  }
27
27
  } = args;
28
+ const getTimeElement = timestamp => {
29
+ const timeString = getTimestampHourMinute(timestamp);
30
+ const isAmPmFormat = timeString.toLowerCase().includes("am") || timeString.toLowerCase().includes("pm");
31
+
32
+ // For clients that use languages that are written right-to-left, but still use AM/PM time format, we need to
33
+ // make sure the "rtl" direction doesn't produce "PM 1:23", but remains "1:23 PM"
34
+ if (dir === "rtl" && isAmPmFormat) {
35
+ return /*#__PURE__*/React.createElement("span", {
36
+ dir: "ltr"
37
+ }, getTimestampHourMinute(timestamp));
38
+ }
39
+ return timeString;
40
+ };
28
41
  return /*#__PURE__*/React.createElement(Stack, {
29
42
  style: contentStyles,
30
43
  dir: dir
31
44
  }, role === DirectLineSenderRole.Bot && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
32
45
  dir: dir,
33
46
  "aria-hidden": "false"
34
- }, name, " - ", getTimestampHourMinute(timestamp))), role === DirectLineSenderRole.User && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
47
+ }, name, " - ", getTimeElement(timestamp))), role === DirectLineSenderRole.User && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
35
48
  "aria-hidden": "false",
36
49
  dir: dir
37
- }, " ", getTimestampHourMinute(timestamp), " - ", ((_state$domainStates$m = state.domainStates.middlewareLocalizedTexts) === null || _state$domainStates$m === void 0 ? void 0 : _state$domainStates$m.MIDDLEWARE_MESSAGE_DELIVERED) ?? defaultMiddlewareLocalizedTexts.MIDDLEWARE_MESSAGE_DELIVERED)));
50
+ }, " ", getTimeElement(timestamp), " - ", ((_state$domainStates$m = state.domainStates.middlewareLocalizedTexts) === null || _state$domainStates$m === void 0 ? void 0 : _state$domainStates$m.MIDDLEWARE_MESSAGE_DELIVERED) ?? defaultMiddlewareLocalizedTexts.MIDDLEWARE_MESSAGE_DELIVERED)));
38
51
  };
@@ -16,8 +16,9 @@ const convertTextToHtmlNode = text => {
16
16
  if (!text) return "";
17
17
  const element = document.createElement(HtmlAttributeNames.div);
18
18
  try {
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
- text = DOMPurify.sanitize(text);
19
+ text = DOMPurify.sanitize(text, {
20
+ ADD_ATTR: ["target"]
21
+ });
21
22
  element.innerHTML = text;
22
23
  } catch (e) {
23
24
  const errorMessage = `Failed to purify and set innertHTML with text: ${text}`;
@@ -33,7 +34,7 @@ const convertTextToHtmlNode = text => {
33
34
  };
34
35
 
35
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
- const processHTMLText = (action, text) => {
37
+ const processHTMLText = (action, text, honorsTargetInHTMLLinks) => {
37
38
  const htmlNode = convertTextToHtmlNode(text);
38
39
  const aNodes = htmlNode.getElementsByTagName(HtmlAttributeNames.aTagName);
39
40
  if ((aNodes === null || aNodes === void 0 ? void 0 : aNodes.length) > 0) {
@@ -46,8 +47,8 @@ const processHTMLText = (action, text) => {
46
47
  continue;
47
48
  }
48
49
 
49
- // Add target to 'a' node if target is missing or does not equal to blank
50
- if (!aNode.target || aNode.target !== Constants.blank) {
50
+ // Add target to 'a' node if target is missing or if honorsTargetInHTMLLinks is false
51
+ if (!aNode.target || !honorsTargetInHTMLLinks) {
51
52
  aNode.target = Constants.blank;
52
53
  }
53
54
 
@@ -63,9 +64,6 @@ const processHTMLText = (action, text) => {
63
64
  }
64
65
  }
65
66
  }
66
-
67
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- action = updateIn(action, [Constants.payload, Constants.activity, Constants.text], () => htmlNode.innerHTML);
69
67
  } catch (e) {
70
68
  let errorMessage = "Failed to apply action: ";
71
69
  try {
@@ -82,11 +80,12 @@ const processHTMLText = (action, text) => {
82
80
  });
83
81
  }
84
82
  }
83
+ action = updateIn(action, [Constants.payload, Constants.activity, Constants.text], () => htmlNode.innerHTML);
85
84
  return action;
86
85
  };
87
86
 
88
87
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
89
- const htmlTextMiddleware = _ref => {
88
+ const htmlTextMiddleware = honorsTargetInHTMLLinks => _ref => {
90
89
  let {
91
90
  dispatch
92
91
  } = _ref;
@@ -96,7 +95,7 @@ const htmlTextMiddleware = _ref => {
96
95
  var _action$payload, _action$payload$activ;
97
96
  const text = (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : (_action$payload$activ = _action$payload.activity) === null || _action$payload$activ === void 0 ? void 0 : _action$payload$activ.text;
98
97
  if (text) {
99
- action = processHTMLText(action, text);
98
+ action = processHTMLText(action, text, honorsTargetInHTMLLinks ?? false);
100
99
  }
101
100
  } catch (e) {
102
101
  let errorMessage = "Failed to validate action.";
@@ -20,7 +20,9 @@ const sanitizationMiddleware = _ref => {
20
20
  var _action$payload;
21
21
  let text = (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : _action$payload.text;
22
22
  if (text) {
23
- text = DOMPurify.sanitize(text) ?? " ";
23
+ text = DOMPurify.sanitize(text, {
24
+ ADD_ATTR: ["target"]
25
+ }) ?? " ";
24
26
  }
25
27
  } catch (e) {
26
28
  const copyDataForTelemetry = {
@@ -5,6 +5,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
5
5
 
6
6
  import { createFileAndDownload } from "../common/utils";
7
7
  import defaultLibraryScripts from "../components/footerstateful/downloadtranscriptstateful/common/defaultLibraryScripts";
8
+ import DOMPurify from "dompurify";
8
9
  class TranscriptHTMLBuilder {
9
10
  // eslint-disable-line @typescript-eslint/no-explicit-any
10
11
 
@@ -669,7 +670,10 @@ const createChatTranscript = async function (transcript, facadeChatSDK) {
669
670
  reader.readAsDataURL(blob);
670
671
  });
671
672
  };
672
- let messages = transcriptMessages;
673
+ let messages = transcriptMessages.filter(message => {
674
+ message.content = DOMPurify.sanitize(message.content);
675
+ return message.content.length > 0;
676
+ });
673
677
  if (renderAttachments) {
674
678
  messages = await Promise.all(transcriptMessages.map(async message => {
675
679
  // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -74,6 +74,8 @@ export declare class Constants {
74
74
  static readonly Title = "title";
75
75
  static readonly Target = "target";
76
76
  static readonly Blank = "_blank";
77
+ static readonly TargetSelf = "_self";
78
+ static readonly TargetTop = "_top";
77
79
  static readonly TargetRelationship = "rel";
78
80
  static readonly TargetRelationshipAttributes = "noopener noreferrer";
79
81
  static readonly OpenLinkIconCssClass = "webchat__render-markdown__external-link-icon";
@@ -102,6 +104,7 @@ export declare class HtmlIdNames {
102
104
  export declare class HtmlClassNames {
103
105
  static readonly webChatBannerCloseButton = "webchat__toast__dismissButton";
104
106
  static readonly webChatBannerExpandButton = "webchat__toaster__expandIcon";
107
+ static readonly webChatHistoryContainer = "webchat__basic-transcript";
105
108
  }
106
109
  export declare class HtmlElementSelectors {
107
110
  static readonly sendBoxSelector = "textarea[data-id=\"webchat-sendbox-input\"]";
@@ -40,6 +40,8 @@ export declare class FacadeChatSDK {
40
40
  constructor(input: IFacadeChatSDKInput, disableReauthentication: boolean);
41
41
  private convertExpiration;
42
42
  private isTokenExpired;
43
+ private enforceBase64Encoding;
44
+ private extractExpFromToken;
43
45
  private setToken;
44
46
  private tokenRing;
45
47
  private validateAndExecuteCall;
@@ -46,3 +46,4 @@ export declare const createFileAndDownload: (fileName: string, blobData: string,
46
46
  export declare const formatTemplateString: (templateMessage: string, values: any) => string;
47
47
  export declare const parseLowerCaseString: (property: string | boolean | undefined) => string;
48
48
  export declare const setOcUserAgent: (chatSDK: any) => void;
49
+ export declare function getDeviceType(): string;
@@ -1,2 +1,2 @@
1
1
  import MarkdownIt from "markdown-it";
2
- export declare const createMarkdown: (disableMarkdownMessageFormatting: boolean, disableNewLineMarkdownSupport: boolean) => MarkdownIt;
2
+ export declare const createMarkdown: (disableMarkdownMessageFormatting: boolean, disableNewLineMarkdownSupport: boolean, opensMarkdownLinksInSameTab?: boolean) => MarkdownIt;
@@ -0,0 +1,12 @@
1
+ export interface ISendBox {
2
+ /**
3
+ * Target the textarea element in the send box
4
+ */
5
+ textarea?: {
6
+ /**
7
+ * Customer can increase minHeight as a work-around to avoid bug when some languages (like Arabic, Chinese,
8
+ * Hebrew, etc) will show a scrollbar in the textarea element when placeholder is visible
9
+ */
10
+ minHeight?: string;
11
+ };
12
+ }
@@ -6,10 +6,13 @@ import { IWebChatProps } from "./IWebChatProps";
6
6
  import { StyleOptions } from "botframework-webchat-api";
7
7
  import { IAdaptiveCardStyles } from "./IAdaptiveCardStyles";
8
8
  import { IBotAuthConfig } from "./IBotAuthConfig";
9
+ import { ISendBox } from "../../livechatwidget/interfaces/ISendBox";
9
10
  export interface IWebChatContainerStatefulProps {
10
11
  containerStyles?: IStyle;
11
12
  disableNewLineMarkdownSupport?: boolean;
12
13
  disableMarkdownMessageFormatting?: boolean;
14
+ opensMarkdownLinksInSameTab?: boolean;
15
+ honorsTargetInHTMLLinks?: boolean;
13
16
  webChatStyles?: StyleOptions;
14
17
  webChatProps?: IWebChatProps;
15
18
  directLine?: any;
@@ -20,4 +23,6 @@ export interface IWebChatContainerStatefulProps {
20
23
  botAuthConfig?: IBotAuthConfig;
21
24
  hyperlinkTextOverride?: boolean;
22
25
  adaptiveCardStyles?: IAdaptiveCardStyles;
26
+ sendBoxTextBox?: ISendBox;
27
+ webChatHistoryMobileAccessibilityLabel?: string;
23
28
  }
@@ -4,7 +4,7 @@
4
4
  * Ensures that links within messages are processed so that the caller website cannot be traced.
5
5
  ******/
6
6
  import { IWebChatAction } from "../../../interfaces/IWebChatAction";
7
- declare const htmlTextMiddleware: ({ dispatch }: {
7
+ declare const htmlTextMiddleware: (honorsTargetInHTMLLinks?: boolean) => ({ dispatch }: {
8
8
  dispatch: any;
9
9
  }) => (next: any) => (action: IWebChatAction) => any;
10
10
  export default htmlTextMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/omnichannel-chat-widget",
3
- "version": "1.7.6",
3
+ "version": "1.7.7-main.262d750",
4
4
  "description": "Microsoft Omnichannel Chat Widget",
5
5
  "main": "lib/cjs/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -78,7 +78,7 @@
78
78
  "dependencies": {
79
79
  "@azure/core-tracing": "^1.2.0",
80
80
  "@microsoft/omnichannel-chat-components": "1.1.8",
81
- "@microsoft/omnichannel-chat-sdk": "^1.10.13",
81
+ "@microsoft/omnichannel-chat-sdk": "^1.10.15",
82
82
  "@opentelemetry/api": "^1.9.0",
83
83
  "abort-controller-es5": "^2.0.1",
84
84
  "dompurify": "^3.2.4",