@aws-amplify/interactions 4.0.51 → 4.1.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/aws-amplify-interactions.js +23054 -6091
  3. package/dist/aws-amplify-interactions.js.map +1 -1
  4. package/dist/aws-amplify-interactions.min.js +4 -4
  5. package/dist/aws-amplify-interactions.min.js.map +1 -1
  6. package/lib/Providers/AWSLexProvider.d.ts +12 -1
  7. package/lib/Providers/AWSLexProvider.js +48 -36
  8. package/lib/Providers/AWSLexProvider.js.map +1 -1
  9. package/lib/Providers/AWSLexProviderHelper/commonUtils.d.ts +1 -0
  10. package/lib/Providers/AWSLexProviderHelper/{convert.native.js → commonUtils.js} +36 -18
  11. package/lib/Providers/AWSLexProviderHelper/commonUtils.js.map +1 -0
  12. package/lib/Providers/AWSLexProviderHelper/utils.d.ts +3 -0
  13. package/lib/Providers/AWSLexProviderHelper/utils.js +83 -0
  14. package/lib/Providers/AWSLexProviderHelper/utils.js.map +1 -0
  15. package/lib/Providers/AWSLexProviderHelper/utils.native.d.ts +3 -0
  16. package/lib/Providers/AWSLexProviderHelper/utils.native.js +100 -0
  17. package/lib/Providers/AWSLexProviderHelper/utils.native.js.map +1 -0
  18. package/lib/Providers/AWSLexV2Provider.d.ts +58 -0
  19. package/lib/Providers/AWSLexV2Provider.js +351 -0
  20. package/lib/Providers/AWSLexV2Provider.js.map +1 -0
  21. package/lib/Providers/index.d.ts +1 -0
  22. package/lib/Providers/index.js +1 -0
  23. package/lib/Providers/index.js.map +1 -1
  24. package/lib/index.d.ts +1 -0
  25. package/lib/index.js +1 -0
  26. package/lib/index.js.map +1 -1
  27. package/lib/types/Providers/AWSLexV2Provider.d.ts +12 -0
  28. package/lib/types/Providers/AWSLexV2Provider.js +3 -0
  29. package/lib/types/Providers/AWSLexV2Provider.js.map +1 -0
  30. package/lib/types/index.d.ts +1 -0
  31. package/lib-esm/Providers/AWSLexProvider.d.ts +12 -1
  32. package/lib-esm/Providers/AWSLexProvider.js +47 -35
  33. package/lib-esm/Providers/AWSLexProvider.js.map +1 -1
  34. package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.d.ts +1 -0
  35. package/lib-esm/Providers/AWSLexProviderHelper/{convert.native.js → commonUtils.js} +36 -18
  36. package/lib-esm/Providers/AWSLexProviderHelper/commonUtils.js.map +1 -0
  37. package/lib-esm/Providers/AWSLexProviderHelper/utils.d.ts +3 -0
  38. package/lib-esm/Providers/AWSLexProviderHelper/utils.js +81 -0
  39. package/lib-esm/Providers/AWSLexProviderHelper/utils.js.map +1 -0
  40. package/lib-esm/Providers/AWSLexProviderHelper/utils.native.d.ts +3 -0
  41. package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js +98 -0
  42. package/lib-esm/Providers/AWSLexProviderHelper/utils.native.js.map +1 -0
  43. package/lib-esm/Providers/AWSLexV2Provider.d.ts +58 -0
  44. package/lib-esm/Providers/AWSLexV2Provider.js +349 -0
  45. package/lib-esm/Providers/AWSLexV2Provider.js.map +1 -0
  46. package/lib-esm/Providers/index.d.ts +1 -0
  47. package/lib-esm/Providers/index.js +1 -0
  48. package/lib-esm/Providers/index.js.map +1 -1
  49. package/lib-esm/index.d.ts +1 -0
  50. package/lib-esm/index.js +1 -0
  51. package/lib-esm/index.js.map +1 -1
  52. package/lib-esm/types/Providers/AWSLexV2Provider.d.ts +12 -0
  53. package/lib-esm/types/Providers/AWSLexV2Provider.js +1 -0
  54. package/lib-esm/types/Providers/AWSLexV2Provider.js.map +1 -0
  55. package/lib-esm/types/index.d.ts +1 -0
  56. package/package.json +8 -4
  57. package/src/Providers/AWSLexProvider.ts +28 -18
  58. package/src/Providers/AWSLexProviderHelper/commonUtils.ts +27 -0
  59. package/src/Providers/AWSLexProviderHelper/utils.native.ts +56 -0
  60. package/src/Providers/AWSLexProviderHelper/utils.ts +39 -0
  61. package/src/Providers/AWSLexV2Provider.ts +343 -0
  62. package/src/Providers/index.ts +1 -0
  63. package/src/index.ts +1 -0
  64. package/src/types/Providers/AWSLexProvider.ts +12 -0
  65. package/src/types/Providers/AWSLexV2Provider.ts +25 -0
  66. package/src/types/index.ts +1 -0
  67. package/lib/Providers/AWSLexProviderHelper/convert.d.ts +0 -3
  68. package/lib/Providers/AWSLexProviderHelper/convert.js +0 -13
  69. package/lib/Providers/AWSLexProviderHelper/convert.js.map +0 -1
  70. package/lib/Providers/AWSLexProviderHelper/convert.native.d.ts +0 -1
  71. package/lib/Providers/AWSLexProviderHelper/convert.native.js.map +0 -1
  72. package/lib-esm/Providers/AWSLexProviderHelper/convert.d.ts +0 -3
  73. package/lib-esm/Providers/AWSLexProviderHelper/convert.js +0 -11
  74. package/lib-esm/Providers/AWSLexProviderHelper/convert.js.map +0 -1
  75. package/lib-esm/Providers/AWSLexProviderHelper/convert.native.d.ts +0 -1
  76. package/lib-esm/Providers/AWSLexProviderHelper/convert.native.js.map +0 -1
  77. package/src/Providers/AWSLexProviderHelper/convert.native.ts +0 -13
  78. package/src/Providers/AWSLexProviderHelper/convert.ts +0 -12
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright 2017-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+
14
+ import { gunzip, strFromU8 } from 'fflate';
15
+
16
+ export const convert = async (stream: object): Promise<Uint8Array> => {
17
+ if (stream instanceof Blob || stream instanceof ReadableStream) {
18
+ return new Response(stream)
19
+ .arrayBuffer()
20
+ .then(buffer => new Uint8Array(buffer));
21
+ } else {
22
+ return Promise.reject('Invalid content type');
23
+ }
24
+ };
25
+
26
+ export const base64ToArrayBuffer = (base64: string): Uint8Array => {
27
+ return Uint8Array.from(window.atob(base64), c => c.charCodeAt(0));
28
+ };
29
+
30
+ export const gzipDecompressToString = async (
31
+ data: Uint8Array
32
+ ): Promise<string> => {
33
+ return await new Promise((resolve, reject) => {
34
+ gunzip(data, (err, resp) => {
35
+ if (err) reject(err);
36
+ else resolve(strFromU8(resp));
37
+ });
38
+ });
39
+ };
@@ -0,0 +1,343 @@
1
+ /*
2
+ * Copyright 2017-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+ import { AbstractInteractionsProvider } from './InteractionsProvider';
14
+ import {
15
+ InteractionsOptions,
16
+ AWSLexV2ProviderOptions,
17
+ InteractionsResponse,
18
+ InteractionsMessage,
19
+ } from '../types';
20
+ import {
21
+ LexRuntimeV2Client,
22
+ RecognizeTextCommand,
23
+ RecognizeTextCommandInput,
24
+ RecognizeTextCommandOutput,
25
+ RecognizeUtteranceCommand,
26
+ RecognizeUtteranceCommandInput,
27
+ RecognizeUtteranceCommandOutput,
28
+ } from '@aws-sdk/client-lex-runtime-v2';
29
+ import {
30
+ ConsoleLogger as Logger,
31
+ Credentials,
32
+ getAmplifyUserAgent,
33
+ } from '@aws-amplify/core';
34
+ import { convert } from './AWSLexProviderHelper/utils';
35
+ import { unGzipBase64AsJson } from './AWSLexProviderHelper/commonUtils';
36
+
37
+ const logger = new Logger('AWSLexV2Provider');
38
+
39
+ interface RecognizeUtteranceCommandOutputFormatted
40
+ extends Omit<
41
+ RecognizeUtteranceCommandOutput,
42
+ | 'messages'
43
+ | 'interpretations'
44
+ | 'sessionState'
45
+ | 'requestAttributes'
46
+ | 'audioStream'
47
+ > {
48
+ messages?: RecognizeTextCommandOutput['messages'];
49
+ sessionState?: RecognizeTextCommandOutput['sessionState'];
50
+ interpretations?: RecognizeTextCommandOutput['interpretations'];
51
+ requestAttributes?: RecognizeTextCommandOutput['requestAttributes'];
52
+ audioStream?: Uint8Array;
53
+ }
54
+
55
+ type AWSLexV2ProviderSendResponse =
56
+ | RecognizeTextCommandOutput
57
+ | RecognizeUtteranceCommandOutputFormatted;
58
+
59
+ type lexV2BaseReqParams = {
60
+ botId: string;
61
+ botAliasId: string;
62
+ localeId: string;
63
+ sessionId: string;
64
+ };
65
+
66
+ export class AWSLexV2Provider extends AbstractInteractionsProvider {
67
+ private _lexRuntimeServiceV2Client: LexRuntimeV2Client;
68
+ private _botsCompleteCallback: object;
69
+
70
+ /**
71
+ * Initialize Interactions with AWS configurations
72
+ * @param {InteractionsOptions} options - Configuration object for Interactions
73
+ */
74
+ constructor(options: InteractionsOptions = {}) {
75
+ super(options);
76
+ this._botsCompleteCallback = {};
77
+ }
78
+
79
+ /**
80
+ * get provider name of the plugin
81
+ * @returns {string} name of the provider
82
+ */
83
+ public getProviderName() {
84
+ return 'AWSLexV2Provider';
85
+ }
86
+
87
+ /**
88
+ * Configure Interactions part with aws configuration
89
+ * @param {AWSLexV2ProviderOptions} config - Configuration of the Interactions
90
+ * @return {AWSLexV2ProviderOptions} - Current configuration
91
+ */
92
+ public configure(
93
+ config: AWSLexV2ProviderOptions = {}
94
+ ): AWSLexV2ProviderOptions {
95
+ const propertiesToTest = [
96
+ 'name',
97
+ 'botId',
98
+ 'aliasId',
99
+ 'localeId',
100
+ 'providerName',
101
+ 'region',
102
+ ];
103
+
104
+ Object.keys(config).forEach(botKey => {
105
+ const botConfig = config[botKey];
106
+
107
+ // is bot config correct
108
+ if (!propertiesToTest.every(x => x in botConfig)) {
109
+ throw new Error('invalid bot configuration');
110
+ }
111
+ });
112
+ return super.configure(config);
113
+ }
114
+
115
+ /**
116
+ * Send a message to a bot
117
+ * @async
118
+ * @param {string} botname - Bot name to send the message
119
+ * @param {string | InteractionsMessage} message - message to send to the bot
120
+ * @return {Promise<InteractionsResponse>} A promise resolves to the response from the bot
121
+ */
122
+ public async sendMessage(
123
+ botname: string,
124
+ message: string | InteractionsMessage
125
+ ): Promise<InteractionsResponse> {
126
+ // check if bot exists
127
+ if (!this._config[botname]) {
128
+ return Promise.reject('Bot ' + botname + ' does not exist');
129
+ }
130
+
131
+ // check if credentials are present
132
+ let credentials;
133
+ try {
134
+ credentials = await Credentials.get();
135
+ } catch (error) {
136
+ return Promise.reject('No credentials');
137
+ }
138
+
139
+ this._lexRuntimeServiceV2Client = new LexRuntimeV2Client({
140
+ region: this._config[botname].region,
141
+ credentials,
142
+ customUserAgent: getAmplifyUserAgent(),
143
+ });
144
+
145
+ let response: AWSLexV2ProviderSendResponse;
146
+
147
+ // common base params for all requests
148
+ const reqBaseParams: lexV2BaseReqParams = {
149
+ botAliasId: this._config[botname].aliasId,
150
+ botId: this._config[botname].botId,
151
+ localeId: this._config[botname].localeId,
152
+ sessionId: credentials.identityId,
153
+ };
154
+
155
+ if (typeof message === 'string') {
156
+ response = await this._handleRecognizeTextCommand(
157
+ botname,
158
+ message,
159
+ reqBaseParams
160
+ );
161
+ } else {
162
+ response = await this._handleRecognizeUtteranceCommand(
163
+ botname,
164
+ message,
165
+ reqBaseParams
166
+ );
167
+ }
168
+ return response;
169
+ }
170
+
171
+ /**
172
+ * Attach a onComplete callback function to a bot.
173
+ * The callback is called once the bot's intent is fulfilled
174
+ * @param {string} botname - Bot name to attach the onComplete callback
175
+ * @param {(err: Error | null, confirmation: InteractionsResponse) => void} callback - called when Intent Fulfilled
176
+ */
177
+ public onComplete(
178
+ botname: string,
179
+ callback: (err: Error | null, confirmation: InteractionsResponse) => void
180
+ ) {
181
+ // does bot exist
182
+ if (!this._config[botname]) {
183
+ throw new Error('Bot ' + botname + ' does not exist');
184
+ }
185
+ this._botsCompleteCallback[botname] = callback;
186
+ }
187
+
188
+ /**
189
+ * @private
190
+ * call onComplete callback for a bot if configured
191
+ */
192
+ private _reportBotStatus(
193
+ data: AWSLexV2ProviderSendResponse,
194
+ botname: string
195
+ ) {
196
+ const sessionState = data?.sessionState;
197
+
198
+ // Check if state is fulfilled to resolve onFullfilment promise
199
+ logger.debug('postContent state', sessionState?.intent?.state);
200
+
201
+ const isConfigOnCompleteAttached =
202
+ typeof this._config?.[botname].onComplete === 'function';
203
+
204
+ const isApiOnCompleteAttached =
205
+ typeof this._botsCompleteCallback?.[botname] === 'function';
206
+
207
+ // no onComplete callbacks added
208
+ if (!isConfigOnCompleteAttached && !isApiOnCompleteAttached) return;
209
+
210
+ if (
211
+ sessionState?.intent?.state === 'ReadyForFulfillment' ||
212
+ sessionState?.intent?.state === 'Fulfilled'
213
+ ) {
214
+ if (isApiOnCompleteAttached) {
215
+ setTimeout(() => this._botsCompleteCallback?.[botname](null, data), 0);
216
+ }
217
+
218
+ if (isConfigOnCompleteAttached) {
219
+ setTimeout(() => this._config[botname].onComplete(null, data), 0);
220
+ }
221
+ }
222
+
223
+ if (sessionState?.intent?.state === 'Failed') {
224
+ const error = new Error('Bot conversation failed');
225
+ if (isApiOnCompleteAttached) {
226
+ setTimeout(() => this._botsCompleteCallback[botname](error), 0);
227
+ }
228
+
229
+ if (isConfigOnCompleteAttached) {
230
+ setTimeout(() => this._config[botname].onComplete(error), 0);
231
+ }
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Format UtteranceCommandOutput's response
237
+ * decompress attributes
238
+ * update audioStream format
239
+ */
240
+ private async _formatUtteranceCommandOutput(
241
+ data: RecognizeUtteranceCommandOutput
242
+ ): Promise<RecognizeUtteranceCommandOutputFormatted> {
243
+ const response: RecognizeUtteranceCommandOutputFormatted = {
244
+ ...data,
245
+ messages: await unGzipBase64AsJson(data.messages),
246
+ sessionState: await unGzipBase64AsJson(data.sessionState),
247
+ interpretations: await unGzipBase64AsJson(data.interpretations),
248
+ requestAttributes: await unGzipBase64AsJson(data.requestAttributes),
249
+ inputTranscript: await unGzipBase64AsJson(data.inputTranscript),
250
+ audioStream: data.audioStream
251
+ ? await convert(data.audioStream)
252
+ : undefined,
253
+ };
254
+ return response;
255
+ }
256
+
257
+ /**
258
+ * handle client's `RecognizeTextCommand`
259
+ * used for sending simple text message
260
+ */
261
+ private async _handleRecognizeTextCommand(
262
+ botname: string,
263
+ data: string,
264
+ baseParams: lexV2BaseReqParams
265
+ ) {
266
+ logger.debug('postText to lex2', data);
267
+
268
+ const params: RecognizeTextCommandInput = {
269
+ ...baseParams,
270
+ text: data,
271
+ };
272
+
273
+ try {
274
+ const recognizeTextCommand = new RecognizeTextCommand(params);
275
+ const data = await this._lexRuntimeServiceV2Client.send(
276
+ recognizeTextCommand
277
+ );
278
+
279
+ this._reportBotStatus(data, botname);
280
+ return data;
281
+ } catch (err) {
282
+ return Promise.reject(err);
283
+ }
284
+ }
285
+
286
+ /**
287
+ * handle client's `RecognizeUtteranceCommand`
288
+ * used for obj text or obj voice message
289
+ */
290
+ private async _handleRecognizeUtteranceCommand(
291
+ botname: string,
292
+ data: InteractionsMessage,
293
+ baseParams: lexV2BaseReqParams
294
+ ) {
295
+ const {
296
+ content,
297
+ options: { messageType },
298
+ } = data;
299
+
300
+ logger.debug('postContent to lex2', data);
301
+ let params: RecognizeUtteranceCommandInput;
302
+
303
+ // prepare params
304
+ if (messageType === 'voice') {
305
+ if (typeof content !== 'object') {
306
+ return Promise.reject('invalid content type');
307
+ }
308
+
309
+ const inputStream =
310
+ content instanceof Uint8Array ? content : await convert(content);
311
+
312
+ params = {
313
+ ...baseParams,
314
+ requestContentType: 'audio/x-l16; sample-rate=16000; channel-count=1',
315
+ inputStream,
316
+ };
317
+ } else {
318
+ // text input
319
+ if (typeof content !== 'string')
320
+ return Promise.reject('invalid content type');
321
+
322
+ params = {
323
+ ...baseParams,
324
+ requestContentType: 'text/plain; charset=utf-8',
325
+ inputStream: content,
326
+ };
327
+ }
328
+
329
+ // make API call to lex
330
+ try {
331
+ const recognizeUtteranceCommand = new RecognizeUtteranceCommand(params);
332
+ const data = await this._lexRuntimeServiceV2Client.send(
333
+ recognizeUtteranceCommand
334
+ );
335
+
336
+ const response = await this._formatUtteranceCommandOutput(data);
337
+ this._reportBotStatus(response, botname);
338
+ return response;
339
+ } catch (err) {
340
+ return Promise.reject(err);
341
+ }
342
+ }
343
+ }
@@ -11,4 +11,5 @@
11
11
  * and limitations under the License.
12
12
  */
13
13
  export * from './AWSLexProvider';
14
+ export * from './AWSLexV2Provider';
14
15
  export * from './InteractionsProvider';
package/src/index.ts CHANGED
@@ -20,5 +20,6 @@ export default Interactions;
20
20
  export * from './types';
21
21
  export * from './Providers/InteractionsProvider';
22
22
  export * from './Providers/AWSLexProvider';
23
+ export * from './Providers/AWSLexV2Provider';
23
24
 
24
25
  export { Interactions };
@@ -1,3 +1,15 @@
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
1
13
  export interface AWSLexProviderOption {
2
14
  name: string;
3
15
  alias: string;
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
+ * the License. A copy of the License is located at
6
+ *
7
+ * http://aws.amazon.com/apache2.0/
8
+ *
9
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
+ * and limitations under the License.
12
+ */
13
+ export interface AWSLexV2ProviderOption {
14
+ name: string;
15
+ botId: string;
16
+ aliasId: string;
17
+ localeId: string;
18
+ region: string;
19
+ providerName: string;
20
+ onComplete?(botname: string, callback: (err, confirmation) => void): void;
21
+ }
22
+
23
+ export interface AWSLexV2ProviderOptions {
24
+ [key: string]: AWSLexV2ProviderOption;
25
+ }
@@ -13,4 +13,5 @@
13
13
  export * from './Interactions';
14
14
  export * from './Provider';
15
15
  export * from './Providers/AWSLexProvider';
16
+ export * from './Providers/AWSLexV2Provider';
16
17
  export * from './Response';
@@ -1,3 +0,0 @@
1
- /// <reference types="node" />
2
- import { Readable } from 'stream';
3
- export declare const convert: (stream: Blob | ReadableStream<any> | Readable) => Promise<Uint8Array>;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convert = function (stream) {
4
- if (stream instanceof Blob || stream instanceof ReadableStream) {
5
- return new Response(stream)
6
- .arrayBuffer()
7
- .then(function (buffer) { return new Uint8Array(buffer); });
8
- }
9
- else {
10
- throw new Error('Readable is not supported.');
11
- }
12
- };
13
- //# sourceMappingURL=convert.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/Providers/AWSLexProviderHelper/convert.ts"],"names":[],"mappings":";;AACa,QAAA,OAAO,GAAG,UACtB,MAAwC;IAExC,IAAI,MAAM,YAAY,IAAI,IAAI,MAAM,YAAY,cAAc,EAAE;QAC/D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC;aACzB,WAAW,EAAE;aACb,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,IAAI,UAAU,CAAC,MAAM,CAAC,EAAtB,CAAsB,CAAC,CAAC;KACzC;SAAM;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KAC9C;AACF,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export declare const convert: (stream: Blob) => Promise<Uint8Array>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert.native.js","sourceRoot":"","sources":["../../../src/Providers/AWSLexProviderHelper/convert.native.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAa,QAAA,OAAO,GAAG,UAAC,MAAY;IACnC,OAAO,IAAI,OAAO,CAAC,UAAO,GAAG,EAAE,GAAG;;;YAC3B,OAAO,GAAG,GAAG,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YACtC,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC;YACrC,OAAO,CAAC,YAAY,GAAG,aAAa,CAAC;YACrC,OAAO,CAAC,MAAM,GAAG,UAAA,MAAM;gBACtB,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC9C,CAAC,CAAC;YACF,OAAO,CAAC,OAAO,GAAG,GAAG,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACnC,OAAO,CAAC,IAAI,EAAE,CAAC;;;SACf,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,3 +0,0 @@
1
- /// <reference types="node" />
2
- import { Readable } from 'stream';
3
- export declare const convert: (stream: Blob | ReadableStream<any> | Readable) => Promise<Uint8Array>;
@@ -1,11 +0,0 @@
1
- export var convert = function (stream) {
2
- if (stream instanceof Blob || stream instanceof ReadableStream) {
3
- return new Response(stream)
4
- .arrayBuffer()
5
- .then(function (buffer) { return new Uint8Array(buffer); });
6
- }
7
- else {
8
- throw new Error('Readable is not supported.');
9
- }
10
- };
11
- //# sourceMappingURL=convert.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert.js","sourceRoot":"","sources":["../../../src/Providers/AWSLexProviderHelper/convert.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,IAAM,OAAO,GAAG,UACtB,MAAwC;IAExC,IAAI,MAAM,YAAY,IAAI,IAAI,MAAM,YAAY,cAAc,EAAE;QAC/D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC;aACzB,WAAW,EAAE;aACb,IAAI,CAAC,UAAA,MAAM,IAAI,OAAA,IAAI,UAAU,CAAC,MAAM,CAAC,EAAtB,CAAsB,CAAC,CAAC;KACzC;SAAM;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;KAC9C;AACF,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- export declare const convert: (stream: Blob) => Promise<Uint8Array>;
@@ -1 +0,0 @@
1
- {"version":3,"file":"convert.native.js","sourceRoot":"","sources":["../../../src/Providers/AWSLexProviderHelper/convert.native.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,CAAC,IAAM,OAAO,GAAG,UAAC,MAAY;IACnC,OAAO,IAAI,OAAO,CAAC,UAAO,GAAG,EAAE,GAAG;;;YAC3B,OAAO,GAAG,GAAG,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YACtC,OAAO,GAAG,IAAI,cAAc,EAAE,CAAC;YACrC,OAAO,CAAC,YAAY,GAAG,aAAa,CAAC;YACrC,OAAO,CAAC,MAAM,GAAG,UAAA,MAAM;gBACtB,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC9C,CAAC,CAAC;YACF,OAAO,CAAC,OAAO,GAAG,GAAG,CAAC;YACtB,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACnC,OAAO,CAAC,IAAI,EAAE,CAAC;;;SACf,CAAC,CAAC;AACJ,CAAC,CAAC"}
@@ -1,13 +0,0 @@
1
- export const convert = (stream: Blob): Promise<Uint8Array> => {
2
- return new Promise(async (res, rej) => {
3
- const blobURL = URL.createObjectURL(stream);
4
- const request = new XMLHttpRequest();
5
- request.responseType = 'arraybuffer';
6
- request.onload = _event => {
7
- return res(new Uint8Array(request.response));
8
- };
9
- request.onerror = rej;
10
- request.open('GET', blobURL, true);
11
- request.send();
12
- });
13
- };
@@ -1,12 +0,0 @@
1
- import { Readable } from 'stream';
2
- export const convert = (
3
- stream: Blob | Readable | ReadableStream
4
- ): Promise<Uint8Array> => {
5
- if (stream instanceof Blob || stream instanceof ReadableStream) {
6
- return new Response(stream)
7
- .arrayBuffer()
8
- .then(buffer => new Uint8Array(buffer));
9
- } else {
10
- throw new Error('Readable is not supported.');
11
- }
12
- };