botframework-webchat 4.14.0 → 4.15.1

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 (97) hide show
  1. package/.eslintrc.yml +5 -109
  2. package/.prettierrc.yml +1 -1
  3. package/README.md +1 -1
  4. package/babel.config.json +2 -2
  5. package/babel.sanitize-html.config.json +10 -0
  6. package/lib/AddFullBundle.d.ts.map +1 -1
  7. package/lib/AddFullBundle.js +1 -2
  8. package/lib/FullComposer.js +2 -2
  9. package/lib/FullReactWebChat.js +1 -1
  10. package/lib/adaptiveCards/AdaptiveCardsComposer.d.ts.map +1 -1
  11. package/lib/adaptiveCards/AdaptiveCardsComposer.js +6 -2
  12. package/lib/adaptiveCards/AdaptiveCardsContext.d.ts +0 -1
  13. package/lib/adaptiveCards/AdaptiveCardsContext.d.ts.map +1 -1
  14. package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.d.ts +7 -7
  15. package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.d.ts.map +1 -1
  16. package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.js +10 -3
  17. package/lib/adaptiveCards/Attachment/AdaptiveCardContent.js +8 -4
  18. package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts +9 -22
  19. package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts.map +1 -1
  20. package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.js +175 -95
  21. package/lib/adaptiveCards/Attachment/AnimationCardContent.js +1 -1
  22. package/lib/adaptiveCards/Attachment/AudioCardContent.js +1 -1
  23. package/lib/adaptiveCards/Attachment/CommonCard.js +7 -3
  24. package/lib/adaptiveCards/Attachment/HeroCardContent.js +7 -3
  25. package/lib/adaptiveCards/Attachment/OAuthCardContent.js +7 -3
  26. package/lib/adaptiveCards/Attachment/ReceiptCardContent.js +7 -3
  27. package/lib/adaptiveCards/Attachment/SignInCardContent.js +1 -1
  28. package/lib/adaptiveCards/Attachment/ThumbnailCardContent.js +7 -3
  29. package/lib/adaptiveCards/Attachment/VideoCardContent.js +1 -1
  30. package/lib/adaptiveCards/AttachmentForScreenReader/AdaptiveCardAttachment.js +7 -3
  31. package/lib/adaptiveCards/AttachmentForScreenReader/RichCardAttachment.js +1 -1
  32. package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts +3 -0
  33. package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts.map +1 -1
  34. package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.js +8 -1
  35. package/lib/adaptiveCards/Styles/adaptiveCardHostConfig.js +2 -2
  36. package/lib/adaptiveCards/Styles/createAdaptiveCardsStyleSet.js +1 -1
  37. package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.d.ts.map +1 -1
  38. package/lib/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.js +1 -1
  39. package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.d.ts.map +1 -1
  40. package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.js +1 -3
  41. package/lib/adaptiveCards/hooks/internal/useParseAdaptiveCardJSON.js +1 -1
  42. package/lib/adaptiveCards/hooks/useAdaptiveCardsHostConfig.js +1 -1
  43. package/lib/adaptiveCards/hooks/useAdaptiveCardsPackage.js +1 -1
  44. package/lib/adaptiveCards/normalizeStyleOptions.js +1 -1
  45. package/lib/addVersion.js +2 -2
  46. package/lib/createCognitiveServicesSpeechServicesPonyfillFactory.js +1 -1
  47. package/lib/createFullStyleSet.d.ts +324 -55
  48. package/lib/createFullStyleSet.d.ts.map +1 -1
  49. package/lib/createFullStyleSet.js +1 -1
  50. package/lib/fullBundleDefaultStyleOptions.js +1 -1
  51. package/lib/hooks/useStyleOptions.js +1 -1
  52. package/lib/index-es5.d.ts +1 -21
  53. package/lib/index-es5.d.ts.map +1 -1
  54. package/lib/index-es5.js +3 -43
  55. package/lib/index-minimal.js +27 -21
  56. package/lib/index.d.ts +10 -1
  57. package/lib/index.d.ts.map +1 -1
  58. package/lib/index.js +10 -7
  59. package/lib/polyfill.d.ts +23 -0
  60. package/lib/polyfill.d.ts.map +1 -0
  61. package/lib/polyfill.js +46 -0
  62. package/lib/renderMarkdown.d.ts.map +1 -1
  63. package/lib/renderMarkdown.js +34 -6
  64. package/lib/speech/CustomAudioInputStream.d.ts.map +1 -1
  65. package/lib/speech/CustomAudioInputStream.js +40 -15
  66. package/lib/speech/createAudioConfig.d.ts.map +1 -1
  67. package/lib/speech/createAudioConfig.js +9 -3
  68. package/lib/speech/createMicrophoneAudioConfigAndAudioContext.d.ts.map +1 -1
  69. package/lib/speech/createMicrophoneAudioConfigAndAudioContext.js +6 -1
  70. package/lib/speech/getUserMedia.js +1 -1
  71. package/lib/useComposerProps.js +1 -1
  72. package/package.json +35 -41
  73. package/src/AddFullBundle.tsx +0 -1
  74. package/src/__tests__/createDirectLine.spec.js +2 -0
  75. package/src/__tests__/renderMarkdown.spec.js +1 -1
  76. package/src/__tests__/versionTag.es5.spec.js +1 -0
  77. package/src/__tests__/versionTag.full.spec.js +1 -0
  78. package/src/__tests__/versionTag.minimal.spec.js +1 -0
  79. package/src/adaptiveCards/AdaptiveCardsComposer.tsx +4 -3
  80. package/src/adaptiveCards/Attachment/AdaptiveCardBuilder.ts +16 -12
  81. package/src/adaptiveCards/Attachment/AdaptiveCardRenderer.tsx +226 -96
  82. package/src/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.ts +8 -0
  83. package/src/adaptiveCards/Styles/createAdaptiveCardsStyleSet.spec.js +2 -0
  84. package/src/adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware.tsx +14 -12
  85. package/src/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.tsx +26 -25
  86. package/src/adaptiveCards/hooks/useAdaptiveCardsHostConfig.ts +4 -4
  87. package/src/createCognitiveServicesSpeechServicesPonyfillFactory.spec.js +5 -5
  88. package/src/index-es5.ts +3 -26
  89. package/src/polyfill.ts +29 -0
  90. package/src/renderMarkdown.ts +40 -4
  91. package/src/speech/CustomAudioInputStream.ts +39 -10
  92. package/src/speech/createAudioConfig.spec.js +1 -1
  93. package/src/speech/createAudioConfig.ts +9 -6
  94. package/src/speech/createMicrophoneAudioConfigAndAudioContext.ts +1 -3
  95. package/src/useComposerProps.ts +4 -4
  96. package/webpack.config.js +24 -4
  97. package/.eslintignore +0 -1
@@ -9,6 +9,14 @@ export default function ({
9
9
  }: FullBundleStyleOptions) {
10
10
  return {
11
11
  '&.webchat__adaptive-card-renderer': {
12
+ // Related to #4075.
13
+ // Adaptive Cards assume its host is in "forced border-box" mode.
14
+ // In CSS, the default is "content-box" mode.
15
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing#values
16
+ '& *': {
17
+ boxSizing: 'border-box'
18
+ },
19
+
12
20
  '& .ac-input, & .ac-inlineActionButton, & .ac-quickActionButton': {
13
21
  fontFamily: primaryFont
14
22
  },
@@ -1,3 +1,5 @@
1
+ /** @jest-environment jsdom */
2
+
1
3
  import createStyleSet from './createAdaptiveCardsStyleSet';
2
4
 
3
5
  describe('createAdaptiveCardsStyleSet', () => {
@@ -16,17 +16,19 @@ const RICH_CARD_CONTENT_TYPES = [
16
16
  ];
17
17
 
18
18
  export default function createAdaptiveCardsAttachmentMiddleware(): AttachmentForScreenReaderMiddleware {
19
- return () => next => (...args) => {
20
- const [
21
- {
22
- attachment: { content, contentType }
23
- }
24
- ] = args;
19
+ return () =>
20
+ next =>
21
+ (...args) => {
22
+ const [
23
+ {
24
+ attachment: { content, contentType }
25
+ }
26
+ ] = args;
25
27
 
26
- return content && RICH_CARD_CONTENT_TYPES.includes(contentType)
27
- ? () => <RichCardAttachment content={content} />
28
- : content && contentType === 'application/vnd.microsoft.card.adaptive'
29
- ? () => <AdaptiveCardAttachment content={content} />
30
- : next(...args);
31
- };
28
+ return content && RICH_CARD_CONTENT_TYPES.includes(contentType)
29
+ ? () => <RichCardAttachment content={content} />
30
+ : content && contentType === 'application/vnd.microsoft.card.adaptive'
31
+ ? () => <AdaptiveCardAttachment content={content} />
32
+ : next(...args);
33
+ };
32
34
  }
@@ -14,30 +14,31 @@ import VideoCardAttachment from './Attachment/VideoCardAttachment';
14
14
 
15
15
  export default function createAdaptiveCardsAttachmentMiddleware(): AttachmentMiddleware {
16
16
  // This is not returning a React component, but a render function.
17
- /* eslint-disable-next-line react/display-name */
18
- return () => next => (...args) => {
19
- const [{ attachment }] = args;
17
+ return () =>
18
+ next =>
19
+ (...args) => {
20
+ const [{ attachment }] = args;
20
21
 
21
- return attachment.contentType === 'application/vnd.microsoft.card.hero' ? (
22
- <HeroCardAttachment attachment={attachment} />
23
- ) : attachment.contentType === 'application/vnd.microsoft.card.adaptive' ? (
24
- <AdaptiveCardAttachment attachment={attachment} />
25
- ) : attachment.contentType === 'application/vnd.microsoft.card.animation' ? (
26
- <AnimationCardAttachment attachment={attachment} />
27
- ) : attachment.contentType === 'application/vnd.microsoft.card.audio' ? (
28
- <AudioCardAttachment attachment={attachment} />
29
- ) : attachment.contentType === 'application/vnd.microsoft.card.oauth' ? (
30
- <OAuthCardAttachment attachment={attachment} />
31
- ) : attachment.contentType === 'application/vnd.microsoft.card.receipt' ? (
32
- <ReceiptCardAttachment attachment={attachment} />
33
- ) : attachment.contentType === 'application/vnd.microsoft.card.signin' ? (
34
- <SignInCardAttachment attachment={attachment} />
35
- ) : attachment.contentType === 'application/vnd.microsoft.card.thumbnail' ? (
36
- <ThumbnailCardAttachment attachment={attachment} />
37
- ) : attachment.contentType === 'application/vnd.microsoft.card.video' ? (
38
- <VideoCardAttachment attachment={attachment} />
39
- ) : (
40
- next(...args)
41
- );
42
- };
22
+ return attachment.contentType === 'application/vnd.microsoft.card.hero' ? (
23
+ <HeroCardAttachment attachment={attachment} />
24
+ ) : attachment.contentType === 'application/vnd.microsoft.card.adaptive' ? (
25
+ <AdaptiveCardAttachment attachment={attachment} />
26
+ ) : attachment.contentType === 'application/vnd.microsoft.card.animation' ? (
27
+ <AnimationCardAttachment attachment={attachment} />
28
+ ) : attachment.contentType === 'application/vnd.microsoft.card.audio' ? (
29
+ <AudioCardAttachment attachment={attachment} />
30
+ ) : attachment.contentType === 'application/vnd.microsoft.card.oauth' ? (
31
+ <OAuthCardAttachment attachment={attachment} />
32
+ ) : attachment.contentType === 'application/vnd.microsoft.card.receipt' ? (
33
+ <ReceiptCardAttachment attachment={attachment} />
34
+ ) : attachment.contentType === 'application/vnd.microsoft.card.signin' ? (
35
+ <SignInCardAttachment attachment={attachment} />
36
+ ) : attachment.contentType === 'application/vnd.microsoft.card.thumbnail' ? (
37
+ <ThumbnailCardAttachment attachment={attachment} />
38
+ ) : attachment.contentType === 'application/vnd.microsoft.card.video' ? (
39
+ <VideoCardAttachment attachment={attachment} />
40
+ ) : (
41
+ next(...args)
42
+ );
43
+ };
43
44
  }
@@ -8,10 +8,10 @@ export default function useAdaptiveCardsHostConfig(): [any] {
8
8
  const { hostConfigFromProps } = useAdaptiveCardsContext();
9
9
  const [styleOptions] = useStyleOptions();
10
10
 
11
- const patchedHostConfig = useMemo(() => hostConfigFromProps || createDefaultAdaptiveCardHostConfig(styleOptions), [
12
- hostConfigFromProps,
13
- styleOptions
14
- ]);
11
+ const patchedHostConfig = useMemo(
12
+ () => hostConfigFromProps || createDefaultAdaptiveCardHostConfig(styleOptions),
13
+ [hostConfigFromProps, styleOptions]
14
+ );
15
15
 
16
16
  return [patchedHostConfig];
17
17
  }
@@ -1,3 +1,4 @@
1
+ /** @jest-environment jsdom */
1
2
  /* eslint-disable prefer-destructuring */
2
3
  /* eslint-disable no-global-assign */
3
4
  let consoleWarns;
@@ -17,20 +18,19 @@ beforeEach(() => {
17
18
  };
18
19
 
19
20
  createPonyfill = require('web-speech-cognitive-services/lib/SpeechServices');
20
- // eslint-disable-next-line @typescript-eslint/no-var-requires
21
- createCognitiveServicesSpeechServicesPonyfillFactory = require('./createCognitiveServicesSpeechServicesPonyfillFactory')
22
- .default;
21
+ createCognitiveServicesSpeechServicesPonyfillFactory =
22
+ require('./createCognitiveServicesSpeechServicesPonyfillFactory').default;
23
23
 
24
24
  window.AudioContext = class MockAudioContext {
25
25
  // eslint-disable-next-line class-methods-use-this
26
26
  createMediaStreamSource() {
27
- // eslint-disable-next-line @typescript-eslint/no-empty-function
27
+ // eslint-disable-next-line no-empty-function
28
28
  return { connect: () => {} };
29
29
  }
30
30
 
31
31
  // eslint-disable-next-line class-methods-use-this
32
32
  createScriptProcessor() {
33
- // eslint-disable-next-line @typescript-eslint/no-empty-function
33
+ // eslint-disable-next-line no-empty-function
34
34
  return { connect: () => {} };
35
35
  }
36
36
  };
package/src/index-es5.ts CHANGED
@@ -1,32 +1,9 @@
1
1
  /* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
2
2
  // window['WebChat'] is required for TypeScript
3
3
 
4
- // Polyfills for IE11 and other ES5 browsers
5
- // To maintain quality, we prefer polyfills without additives
6
- // For example, we prefer Promise implementation from "core-js" than "bluebird"
7
-
8
- import 'core-js/features/array/find-index';
9
- import 'core-js/features/array/find';
10
- import 'core-js/features/array/from';
11
- import 'core-js/features/array/includes';
12
- import 'core-js/features/array/iterator';
13
- import 'core-js/features/dom-collections';
14
- import 'core-js/features/math/sign';
15
- import 'core-js/features/number/is-finite';
16
- import 'core-js/features/object/assign';
17
- import 'core-js/features/object/entries';
18
- import 'core-js/features/object/from-entries';
19
- import 'core-js/features/object/is';
20
- import 'core-js/features/object/values';
21
- import 'core-js/features/promise';
22
- import 'core-js/features/promise/finally';
23
- import 'core-js/features/set';
24
- import 'core-js/features/string/ends-with';
25
- import 'core-js/features/string/starts-with';
26
- import 'core-js/features/symbol';
27
-
28
- import 'url-search-params-polyfill';
29
- import 'whatwg-fetch';
4
+ // Importing polyfills required for IE11/ES5.
5
+ import './polyfill';
6
+
30
7
  import { version } from './index-minimal';
31
8
  import addVersion from './addVersion';
32
9
  import defaultCreateDirectLine from './createDirectLine';
@@ -0,0 +1,29 @@
1
+ // Polyfills for IE11 and other ES5 browsers
2
+ // To maintain quality, we prefer polyfills without additives
3
+ // For example, we prefer Promise implementation from "core-js" than "bluebird"
4
+
5
+ // To reduce conflicts with hosting app, we should consider using
6
+ // @babel/plugin-transform-runtime to polyfill in transpiled code directly.
7
+
8
+ import 'core-js/features/array/find-index';
9
+ import 'core-js/features/array/find';
10
+ import 'core-js/features/array/from';
11
+ import 'core-js/features/array/includes';
12
+ import 'core-js/features/array/iterator';
13
+ import 'core-js/features/dom-collections';
14
+ import 'core-js/features/map';
15
+ import 'core-js/features/math/sign';
16
+ import 'core-js/features/number/is-finite';
17
+ import 'core-js/features/object/assign';
18
+ import 'core-js/features/object/entries';
19
+ import 'core-js/features/object/from-entries';
20
+ import 'core-js/features/object/is';
21
+ import 'core-js/features/object/values';
22
+ import 'core-js/features/promise';
23
+ import 'core-js/features/promise/finally';
24
+ import 'core-js/features/set';
25
+ import 'core-js/features/string/ends-with';
26
+ import 'core-js/features/string/starts-with';
27
+ import 'core-js/features/symbol';
28
+ import 'url-search-params-polyfill';
29
+ import 'whatwg-fetch';
@@ -57,6 +57,18 @@ const TRANSPARENT_GIF = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAA
57
57
  // This is used for parsing Markdown for external links.
58
58
  const internalMarkdownIt = new MarkdownIt();
59
59
 
60
+ const MARKDOWN_ATTRS_LEFT_DELIMITER = '⟬';
61
+ // Make sure the delimiter is free from any RegExp characters, such as *, ?, etc.
62
+ // IE11 does not support "u" flag and Babel could not remove it. We intentionally omitting the "u" flag here.
63
+ // eslint-disable-next-line security/detect-non-literal-regexp, require-unicode-regexp
64
+ const MARKDOWN_ATTRS_LEFT_DELIMITER_PATTERN = new RegExp(MARKDOWN_ATTRS_LEFT_DELIMITER, 'g');
65
+
66
+ const MARKDOWN_ATTRS_RIGHT_DELIMITER = '⟭';
67
+ // Make sure the delimiter is free from any RegExp characters, such as *, ?, etc.
68
+ // IE11 does not support "u" flag and Babel could not remove it. We intentionally omitting the "u" flag here.
69
+ // eslint-disable-next-line security/detect-non-literal-regexp, require-unicode-regexp
70
+ const MARKDOWN_ATTRS_RIGHT_DELIMITER_PATTERN = new RegExp(MARKDOWN_ATTRS_RIGHT_DELIMITER, 'g');
71
+
60
72
  export default function render(
61
73
  markdown: string,
62
74
  { markdownRespectCRLF }: { markdownRespectCRLF: boolean },
@@ -66,16 +78,37 @@ export default function render(
66
78
  markdown = markdown.replace(/\n\r|\r\n/gu, carriageReturn => (carriageReturn === '\n\r' ? '\r\n' : '\n\r'));
67
79
  }
68
80
 
69
- const html = new MarkdownIt({
81
+ // Related to #3165.
82
+ // We only support attributes "aria-label" and should leave other attributes as-is.
83
+ // However, `markdown-it-attrs` remove unrecognized attributes, such as {hello}.
84
+ // Before passing to `markdown-it-attrs`, we will convert known attributes from {aria-label="..."} into ⟬aria-label="..."⟭ (using white tortoise shell brackets).
85
+ // Then, we ask `markdown-it-attrs` to only process the new brackets, so it should only try to process things that we allowlisted.
86
+ // Lastly, we revert tortoise shell brackets back to curly brackets, for unprocessed attributes.
87
+ markdown = markdown
88
+ .replace(/\{\s*aria-label()\s*\}/giu, `${MARKDOWN_ATTRS_LEFT_DELIMITER}aria-label${MARKDOWN_ATTRS_RIGHT_DELIMITER}`)
89
+ .replace(
90
+ /\{\s*aria-label=("[^"]*"|[^\s}]*)\s*\}/giu,
91
+ (_, valueInsideQuotes) =>
92
+ `${MARKDOWN_ATTRS_LEFT_DELIMITER}aria-label=${valueInsideQuotes}${MARKDOWN_ATTRS_RIGHT_DELIMITER}`
93
+ );
94
+
95
+ let html = new MarkdownIt({
70
96
  breaks: false,
71
97
  html: false,
72
98
  linkify: true,
73
99
  typographer: true,
74
100
  xhtmlOut: true
75
101
  })
76
- .use(markdownItAttrs)
102
+ .use(markdownItAttrs, {
103
+ // `markdown-it-attrs` is added for accessibility and allow bot developers to specify `aria-label`.
104
+ // We are allowlisting `aria-label` only as it is allowlisted in `sanitize-html`.
105
+ // Other `aria-*` will be sanitized even we allowlisted here.
106
+ allowedAttributes: ['aria-label'],
107
+ leftDelimiter: MARKDOWN_ATTRS_LEFT_DELIMITER,
108
+ rightDelimiter: MARKDOWN_ATTRS_RIGHT_DELIMITER
109
+ })
77
110
  .use(iterator, 'url_new_win', 'link_open', (tokens, index) => {
78
- const token = tokens[index];
111
+ const token = tokens[+index];
79
112
 
80
113
  token.attrSet('rel', 'noopener noreferrer');
81
114
  token.attrSet('target', '_blank');
@@ -97,8 +130,11 @@ export default function render(
97
130
  })
98
131
  .render(markdown);
99
132
 
133
+ // Restore attributes not processed by `markdown-it-attrs`.
134
+ // TODO: [P2] #2511 After we fixed our polyfill story, we should use "String.prototype.replaceAll" instead of RegExp for replace all occurrences.
135
+ html = html.replace(MARKDOWN_ATTRS_LEFT_DELIMITER_PATTERN, '{').replace(MARKDOWN_ATTRS_RIGHT_DELIMITER_PATTERN, '}');
136
+
100
137
  // The signature from "sanitize-html" module is not correct.
101
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
102
138
  // @ts-ignore
103
139
  return sanitizeHTML(html, SANITIZE_HTML_OPTIONS);
104
140
  }
@@ -22,6 +22,7 @@ import {
22
22
  type as Type
23
23
  } from 'microsoft-cognitiveservices-speech-sdk/distrib/lib/src/common.speech/Exports';
24
24
 
25
+ import { isForbiddenPropertyName } from 'botframework-webchat-core';
25
26
  import { v4 } from 'uuid';
26
27
  import createDeferred, { DeferredPromise } from 'p-defer-es5';
27
28
 
@@ -88,9 +89,20 @@ abstract class CustomAudioInputStream extends AudioInputStream {
88
89
  id: options.id || v4().replace(/-/gu, '')
89
90
  };
90
91
 
92
+ // False alarm: indexer is a constant of type Symbol.
93
+ // eslint-disable-next-line security/detect-object-injection
91
94
  this[SYMBOL_DEVICE_INFO_DEFERRED] = createDeferred<DeviceInfo>();
95
+
96
+ // False alarm: indexer is a constant of type Symbol.
97
+ // eslint-disable-next-line security/detect-object-injection
92
98
  this[SYMBOL_EVENTS] = new EventSource<AudioSourceEvent>();
99
+
100
+ // False alarm: indexer is a constant of type Symbol.
101
+ // eslint-disable-next-line security/detect-object-injection
93
102
  this[SYMBOL_FORMAT_DEFERRED] = createDeferred<AudioStreamFormatImpl>();
103
+
104
+ // False alarm: indexer is a constant of type Symbol.
105
+ // eslint-disable-next-line security/detect-object-injection
94
106
  this[SYMBOL_OPTIONS] = normalizedOptions;
95
107
  }
96
108
 
@@ -101,9 +113,10 @@ abstract class CustomAudioInputStream extends AudioInputStream {
101
113
 
102
114
  /** Gets the event source for listening to events. */
103
115
  // ESLint: This code will only works in browsers other than IE11. Only works in ES5 is okay.
104
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
105
116
  // @ts-ignore Accessors are only available when targeting ECMAScript 5 and higher.ts(1056)
106
117
  get events(): EventSource<AudioSourceEvent> {
118
+ // False alarm: indexer is a constant of type Symbol.
119
+ // eslint-disable-next-line security/detect-object-injection
107
120
  return this[SYMBOL_EVENTS];
108
121
  }
109
122
 
@@ -114,16 +127,19 @@ abstract class CustomAudioInputStream extends AudioInputStream {
114
127
  // Speech SDK quirks: In normal speech recognition, getter of "format" is called only after "attach".
115
128
  // But in Direct Line Speech, it is called before "attach".
116
129
  // ESLint: This code will only works in browsers other than IE11. Only works in ES5 is okay.
117
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
118
130
  // @ts-ignore Accessors are only available when targeting ECMAScript 5 and higher.ts(1056)
119
131
  get format(): Promise<AudioStreamFormatImpl> {
120
132
  this.debug('Getting "format".');
121
133
 
134
+ // False alarm: indexer is a constant of type Symbol.
135
+ // eslint-disable-next-line security/detect-object-injection
122
136
  return this[SYMBOL_FORMAT_DEFERRED].promise;
123
137
  }
124
138
 
125
139
  /** Gets the ID of this audio stream. */
126
140
  id(): string {
141
+ // False alarm: indexer is a constant of type Symbol.
142
+ // eslint-disable-next-line security/detect-object-injection
127
143
  return this[SYMBOL_OPTIONS].id;
128
144
  }
129
145
 
@@ -131,6 +147,8 @@ abstract class CustomAudioInputStream extends AudioInputStream {
131
147
  // Speech SDK quirks: In JavaScript, onXxx means "listen to event XXX".
132
148
  // Instead, in Speech SDK, it means "emit event XXX".
133
149
  protected onEvent(event: AudioSourceEvent): void {
150
+ // False alarm: indexer is a constant of type Symbol.
151
+ // eslint-disable-next-line security/detect-object-injection
134
152
  this[SYMBOL_EVENTS].onEvent(event);
135
153
  Events.instance.onEvent(event);
136
154
  }
@@ -191,7 +209,6 @@ abstract class CustomAudioInputStream extends AudioInputStream {
191
209
 
192
210
  // Speech SDK quirks: Although "close" is marked as abstract, it is never called in our observations.
193
211
  // ESLint: Speech SDK requires this function, but we are not implementing it.
194
- // eslint-disable-next-line class-methods-use-this
195
212
  close(): void {
196
213
  this.debug('Callback for "close".');
197
214
 
@@ -215,14 +232,13 @@ abstract class CustomAudioInputStream extends AudioInputStream {
215
232
  /** Log the message to console if `debug` is set to `true`. */
216
233
  private debug(message, ...args) {
217
234
  // ESLint: For debugging, will only log when "debug" is set to "true".
218
- // eslint-disable-next-line no-console
235
+ // False alarm: indexer is a constant of type Symbol.
236
+ // eslint-disable-next-line no-console, security/detect-object-injection
219
237
  this[SYMBOL_OPTIONS].debug && console.info(`CustomAudioInputStream: ${message}`, ...args);
220
238
  }
221
239
 
222
240
  /** Implements this function. When called, it should start recording and return an `IAudioStreamNode`. */
223
- protected abstract performAttach(
224
- audioNodeId: string
225
- ): Promise<{
241
+ protected abstract performAttach(audioNodeId: string): Promise<{
226
242
  audioStreamNode: AudioStreamNode;
227
243
  deviceInfo: DeviceInfo;
228
244
  format: Format;
@@ -242,7 +258,13 @@ abstract class CustomAudioInputStream extends AudioInputStream {
242
258
 
243
259
  // Although only getter of "format" is called before "attach" (in Direct Line Speech),
244
260
  // we are handling both "deviceInfo" and "format" in similar way for uniformity.
261
+
262
+ // False alarm: indexer is a constant of type Symbol.
263
+ // eslint-disable-next-line security/detect-object-injection
245
264
  this[SYMBOL_DEVICE_INFO_DEFERRED].resolve(deviceInfo);
265
+
266
+ // False alarm: indexer is a constant of type Symbol.
267
+ // eslint-disable-next-line security/detect-object-injection
246
268
  this[SYMBOL_FORMAT_DEFERRED].resolve(
247
269
  new AudioStreamFormatImpl(format.samplesPerSec, format.bitsPerSample, format.channels)
248
270
  );
@@ -302,21 +324,28 @@ abstract class CustomAudioInputStream extends AudioInputStream {
302
324
 
303
325
  /** Gets the device information. */
304
326
  // ESLint: This code will only works in browsers other than IE11. Only works in ES5 is okay.
305
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
306
327
  // @ts-ignore Accessors are only available when targeting ECMAScript 5 and higher.ts(1056)
307
328
  get deviceInfo(): Promise<ISpeechConfigAudioDevice> {
308
329
  this.debug(`Getting "deviceInfo".`);
309
330
 
331
+ // False alarm: indexer is a constant of type Symbol.
332
+ // eslint-disable-next-line security/detect-object-injection
310
333
  return Promise.all([this[SYMBOL_DEVICE_INFO_DEFERRED].promise, this[SYMBOL_FORMAT_DEFERRED].promise]).then(
311
334
  ([{ connectivity, manufacturer, model, type }, { bitsPerSample, channels, samplesPerSec }]) => ({
312
335
  bitspersample: bitsPerSample,
313
336
  channelcount: channels,
314
337
  connectivity:
315
- typeof connectivity === 'string' ? Connectivity[connectivity] : connectivity || Connectivity.Unknown,
338
+ typeof connectivity === 'string' && !isForbiddenPropertyName(connectivity)
339
+ ? // Mitigated through denylisting.
340
+ // eslint-disable-next-line security/detect-object-injection
341
+ Connectivity[connectivity]
342
+ : connectivity || Connectivity.Unknown,
316
343
  manufacturer: manufacturer || '',
317
344
  model: model || '',
318
345
  samplerate: samplesPerSec,
319
- type: typeof type === 'string' ? Type[type] : type || Type.Unknown
346
+ // Mitigated through denylisting.
347
+ // eslint-disable-next-line security/detect-object-injection
348
+ type: typeof type === 'string' && !isForbiddenPropertyName(type) ? Type[type] : type || Type.Unknown
320
349
  })
321
350
  );
322
351
  }
@@ -1,4 +1,4 @@
1
- /* eslint @typescript-eslint/no-empty-function: "off" */
1
+ /* eslint no-empty-function: "off" */
2
2
 
3
3
  import createAudioConfig from './createAudioConfig';
4
4
 
@@ -5,9 +5,7 @@ import { AudioConfig } from 'microsoft-cognitiveservices-speech-sdk';
5
5
 
6
6
  import CustomAudioInputStream, { AudioStreamNode, DeviceInfo, Format } from './CustomAudioInputStream';
7
7
 
8
- type AttachFunction = (
9
- audioNodeId: string
10
- ) => Promise<{
8
+ type AttachFunction = (audioNodeId: string) => Promise<{
11
9
  audioStreamNode: AudioStreamNode;
12
10
  deviceInfo: DeviceInfo;
13
11
  format: Format;
@@ -45,20 +43,25 @@ class CreateAudioConfigAudioInputStream extends CustomAudioInputStream {
45
43
 
46
44
  super({ debug });
47
45
 
46
+ // False alarm: indexer is a constant of type Symbol.
47
+ // eslint-disable-next-line security/detect-object-injection
48
48
  this[SYMBOL_ATTACH] = attach;
49
+
50
+ // False alarm: indexer is a constant of type Symbol.
51
+ // eslint-disable-next-line security/detect-object-injection
49
52
  this[SYMBOL_TURN_OFF] = turnOff;
50
53
  }
51
54
 
52
55
  [SYMBOL_ATTACH]: AttachFunction;
53
56
  [SYMBOL_TURN_OFF]: TurnOffFunction;
54
57
 
55
- protected performAttach(
56
- audioNodeId: string
57
- ): Promise<{
58
+ protected performAttach(audioNodeId: string): Promise<{
58
59
  audioStreamNode: AudioStreamNode;
59
60
  deviceInfo: DeviceInfo;
60
61
  format: Format;
61
62
  }> {
63
+ // False alarm: indexer is a constant of type Symbol.
64
+ // eslint-disable-next-line security/detect-object-injection
62
65
  return this[SYMBOL_ATTACH](audioNodeId);
63
66
  }
64
67
 
@@ -55,9 +55,7 @@ function createMicrophoneAudioConfig(options: MicrophoneAudioInputStreamOptions)
55
55
  pcmRecorderWorkletUrl && pcmRecorder.setWorkletUrl(pcmRecorderWorkletUrl);
56
56
 
57
57
  return createAudioConfig({
58
- async attach(
59
- audioNodeId: string
60
- ): Promise<{
58
+ async attach(audioNodeId: string): Promise<{
61
59
  audioStreamNode: AudioStreamNode;
62
60
  deviceInfo: DeviceInfo;
63
61
  format: Format;
@@ -35,10 +35,10 @@ export default function useComposerProps({
35
35
  );
36
36
 
37
37
  // When styleSet is not specified, the styleOptions will be used to create Adaptive Cards styleSet and merged into useStyleSet.
38
- const extraStyleSet = useMemo(() => (styleSet ? undefined : createAdaptiveCardsStyleSet(styleOptions)), [
39
- styleOptions,
40
- styleSet
41
- ]);
38
+ const extraStyleSet = useMemo(
39
+ () => (styleSet ? undefined : createAdaptiveCardsStyleSet(styleOptions)),
40
+ [styleOptions, styleSet]
41
+ );
42
42
 
43
43
  const patchedRenderMarkdown = useMemo(
44
44
  () => (typeof renderMarkdown === 'undefined' ? defaultRenderMarkdown : renderMarkdown),
package/webpack.config.js CHANGED
@@ -14,6 +14,27 @@ let config = {
14
14
  'webchat-minimal': './lib/index-minimal.js'
15
15
  },
16
16
  mode: 'production',
17
+ module: {
18
+ rules: [
19
+ {
20
+ // To speed up bundling, we are limiting Babel to a number of packages which does not publish ES5 bits.
21
+ test: /\/node_modules\/(botframework-streaming|buffer|nanoid|postcss|punycode|sanitize-html)\//iu,
22
+ use: {
23
+ loader: 'babel-loader',
24
+ options: {
25
+ presets: [
26
+ [
27
+ '@babel/preset-env',
28
+ {
29
+ modules: 'commonjs'
30
+ }
31
+ ]
32
+ ]
33
+ }
34
+ }
35
+ }
36
+ ]
37
+ },
17
38
  optimization: {
18
39
  minimizer: [
19
40
  // Webpack use terser for minification
@@ -30,9 +51,7 @@ let config = {
30
51
  ]
31
52
  },
32
53
  output: {
33
- filename: '[name].js',
34
- libraryTarget: 'umd',
35
- path: resolve(__dirname, 'dist')
54
+ libraryTarget: 'umd'
36
55
  },
37
56
  plugins: [
38
57
  new StatsWriterPlugin({
@@ -77,7 +96,8 @@ let config = {
77
96
  react: resolve(__dirname, 'node_modules/isomorphic-react/dist/react.js'),
78
97
  'react-dom': resolve(__dirname, 'node_modules/isomorphic-react-dom/dist/react-dom.js')
79
98
  }
80
- }
99
+ },
100
+ target: ['web', 'es5']
81
101
  };
82
102
 
83
103
  // VSTS always emits uppercase environment variables.
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- /src/tsconfig.json