botframework-webchat 4.14.1 → 4.15.0
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.
- package/.eslintrc.yml +5 -109
- package/.prettierrc.yml +1 -1
- package/README.md +1 -1
- package/lib/AddFullBundle.d.ts.map +1 -1
- package/lib/AddFullBundle.js +1 -2
- package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.d.ts.map +1 -1
- package/lib/adaptiveCards/Attachment/AdaptiveCardBuilder.js +10 -3
- package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts +2 -1
- package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.d.ts.map +1 -1
- package/lib/adaptiveCards/Attachment/AdaptiveCardRenderer.js +138 -74
- package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts +3 -0
- package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.d.ts.map +1 -1
- package/lib/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.js +8 -1
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.d.ts.map +1 -1
- package/lib/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.js +26 -29
- package/lib/addVersion.js +1 -1
- package/lib/createFullStyleSet.d.ts +324 -55
- package/lib/createFullStyleSet.d.ts.map +1 -1
- package/lib/index-es5.d.ts +1 -21
- package/lib/index-es5.d.ts.map +1 -1
- package/lib/index-es5.js +2 -42
- package/lib/index-minimal.js +20 -18
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -6
- package/lib/polyfill.d.ts +23 -0
- package/lib/polyfill.d.ts.map +1 -0
- package/lib/polyfill.js +46 -0
- package/lib/renderMarkdown.d.ts.map +1 -1
- package/lib/renderMarkdown.js +34 -6
- package/lib/speech/CustomAudioInputStream.d.ts.map +1 -1
- package/lib/speech/CustomAudioInputStream.js +40 -15
- package/lib/speech/createAudioConfig.d.ts.map +1 -1
- package/lib/speech/createAudioConfig.js +9 -3
- package/package.json +25 -32
- package/src/AddFullBundle.tsx +0 -1
- package/src/adaptiveCards/Attachment/AdaptiveCardBuilder.ts +7 -3
- package/src/adaptiveCards/Attachment/AdaptiveCardRenderer.tsx +182 -88
- package/src/adaptiveCards/Styles/StyleSet/AdaptiveCardRenderer.ts +8 -0
- package/src/adaptiveCards/createAdaptiveCardsAttachmentMiddleware.tsx +0 -1
- package/src/createCognitiveServicesSpeechServicesPonyfillFactory.spec.js +2 -3
- package/src/index-es5.ts +3 -26
- package/src/polyfill.ts +29 -0
- package/src/renderMarkdown.ts +40 -4
- package/src/speech/CustomAudioInputStream.ts +38 -7
- package/src/speech/createAudioConfig.spec.js +1 -1
- package/src/speech/createAudioConfig.ts +7 -0
- package/.eslintignore +0 -1
package/src/renderMarkdown.ts
CHANGED
|
@@ -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
|
-
|
|
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,7 +232,8 @@ 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
|
-
//
|
|
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
|
|
|
@@ -240,7 +258,13 @@ abstract class CustomAudioInputStream extends AudioInputStream {
|
|
|
240
258
|
|
|
241
259
|
// Although only getter of "format" is called before "attach" (in Direct Line Speech),
|
|
242
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
|
|
243
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
|
|
244
268
|
this[SYMBOL_FORMAT_DEFERRED].resolve(
|
|
245
269
|
new AudioStreamFormatImpl(format.samplesPerSec, format.bitsPerSample, format.channels)
|
|
246
270
|
);
|
|
@@ -300,21 +324,28 @@ abstract class CustomAudioInputStream extends AudioInputStream {
|
|
|
300
324
|
|
|
301
325
|
/** Gets the device information. */
|
|
302
326
|
// ESLint: This code will only works in browsers other than IE11. Only works in ES5 is okay.
|
|
303
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
304
327
|
// @ts-ignore Accessors are only available when targeting ECMAScript 5 and higher.ts(1056)
|
|
305
328
|
get deviceInfo(): Promise<ISpeechConfigAudioDevice> {
|
|
306
329
|
this.debug(`Getting "deviceInfo".`);
|
|
307
330
|
|
|
331
|
+
// False alarm: indexer is a constant of type Symbol.
|
|
332
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
308
333
|
return Promise.all([this[SYMBOL_DEVICE_INFO_DEFERRED].promise, this[SYMBOL_FORMAT_DEFERRED].promise]).then(
|
|
309
334
|
([{ connectivity, manufacturer, model, type }, { bitsPerSample, channels, samplesPerSec }]) => ({
|
|
310
335
|
bitspersample: bitsPerSample,
|
|
311
336
|
channelcount: channels,
|
|
312
337
|
connectivity:
|
|
313
|
-
typeof connectivity === 'string'
|
|
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,
|
|
314
343
|
manufacturer: manufacturer || '',
|
|
315
344
|
model: model || '',
|
|
316
345
|
samplerate: samplesPerSec,
|
|
317
|
-
|
|
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
|
|
318
349
|
})
|
|
319
350
|
);
|
|
320
351
|
}
|
|
@@ -43,7 +43,12 @@ class CreateAudioConfigAudioInputStream extends CustomAudioInputStream {
|
|
|
43
43
|
|
|
44
44
|
super({ debug });
|
|
45
45
|
|
|
46
|
+
// False alarm: indexer is a constant of type Symbol.
|
|
47
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
46
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
|
|
47
52
|
this[SYMBOL_TURN_OFF] = turnOff;
|
|
48
53
|
}
|
|
49
54
|
|
|
@@ -55,6 +60,8 @@ class CreateAudioConfigAudioInputStream extends CustomAudioInputStream {
|
|
|
55
60
|
deviceInfo: DeviceInfo;
|
|
56
61
|
format: Format;
|
|
57
62
|
}> {
|
|
63
|
+
// False alarm: indexer is a constant of type Symbol.
|
|
64
|
+
// eslint-disable-next-line security/detect-object-injection
|
|
58
65
|
return this[SYMBOL_ATTACH](audioNodeId);
|
|
59
66
|
}
|
|
60
67
|
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/src/tsconfig.json
|