@twilio/mcs-client 0.5.3 → 0.6.0-rc.10
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/CHANGELOG.md +87 -0
- package/builds/browser.js +733 -370
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +55 -26
- package/builds/lib.js +708 -370
- package/builds/lib.js.map +1 -1
- package/builds/twilio-mcs-client.js +3371 -2210
- package/builds/twilio-mcs-client.min.js +3 -17
- package/dist/_virtual/rng-browser.js +34 -0
- package/dist/_virtual/rng-browser.js.map +1 -0
- package/dist/cancellable-promise.js +98 -0
- package/dist/cancellable-promise.js.map +1 -0
- package/dist/client.js +88 -23
- package/dist/client.js.map +1 -1
- package/dist/configuration.js.map +1 -1
- package/dist/index.js +5 -9
- package/dist/index.js.map +1 -1
- package/dist/logger.js +2 -4
- package/dist/logger.js.map +1 -1
- package/dist/media.js +15 -22
- package/dist/media.js.map +1 -1
- package/dist/node_modules/tslib/tslib.es6.js +1 -1
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/node_modules/uuid/index.js +44 -0
- package/dist/node_modules/uuid/index.js.map +1 -0
- package/dist/node_modules/uuid/lib/bytesToUuid.js +60 -0
- package/dist/node_modules/uuid/lib/bytesToUuid.js.map +1 -0
- package/dist/node_modules/uuid/lib/rng-browser.js +65 -0
- package/dist/node_modules/uuid/lib/rng-browser.js.map +1 -0
- package/dist/node_modules/uuid/v1.js +146 -0
- package/dist/node_modules/uuid/v1.js.map +1 -0
- package/dist/node_modules/uuid/v4.js +66 -0
- package/dist/node_modules/uuid/v4.js.map +1 -0
- package/dist/packages/mcs-client/package.json.js +1 -1
- package/dist/services/network.js +54 -32
- package/dist/services/network.js.map +1 -1
- package/dist/services/transport.js +26 -11
- package/dist/services/transport.js.map +1 -1
- package/dist/services/transporterror.js.map +1 -1
- package/package.json +16 -14
package/builds/lib.js
CHANGED
|
@@ -19,9 +19,14 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
19
19
|
|
|
20
20
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
21
21
|
|
|
22
|
-
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
23
22
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
24
23
|
require('core-js/modules/es.promise.js');
|
|
24
|
+
require('core-js/modules/es.array.iterator.js');
|
|
25
|
+
require('core-js/modules/es.map.js');
|
|
26
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
27
|
+
var require$$0 = require('crypto');
|
|
28
|
+
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
29
|
+
require('core-js/modules/web.dom-collections.for-each.js');
|
|
25
30
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
26
31
|
require('core-js/modules/es.array.from.js');
|
|
27
32
|
var log$2 = require('loglevel');
|
|
@@ -29,41 +34,270 @@ require('core-js/modules/es.string.starts-with.js');
|
|
|
29
34
|
require('core-js/modules/es.array.reduce.js');
|
|
30
35
|
require('core-js/modules/es.regexp.exec.js');
|
|
31
36
|
require('core-js/modules/es.string.split.js');
|
|
37
|
+
require('core-js/modules/es.string.replace.js');
|
|
38
|
+
require('core-js/modules/es.json.stringify.js');
|
|
32
39
|
require('core-js/modules/es.object.assign.js');
|
|
33
|
-
require('core-js/modules/es.array.iterator.js');
|
|
34
|
-
require('core-js/modules/web.dom-collections.iterator.js');
|
|
35
40
|
require('core-js/modules/web.url.js');
|
|
41
|
+
require('core-js/modules/web.url-search-params.js');
|
|
36
42
|
var operationRetrier = require('@twilio/operation-retrier');
|
|
37
43
|
var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
|
38
44
|
|
|
39
45
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
40
46
|
|
|
41
47
|
function _interopNamespace(e) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return e[k];
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
48
|
+
if (e && e.__esModule) return e;
|
|
49
|
+
var n = Object.create(null);
|
|
50
|
+
if (e) {
|
|
51
|
+
Object.keys(e).forEach(function (k) {
|
|
52
|
+
if (k !== 'default') {
|
|
53
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
54
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () { return e[k]; }
|
|
55
57
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
n["default"] = e;
|
|
62
|
+
return Object.freeze(n);
|
|
59
63
|
}
|
|
60
64
|
|
|
61
|
-
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
62
65
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
66
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
67
|
+
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
63
68
|
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
64
69
|
var log__namespace = /*#__PURE__*/_interopNamespace(log$2);
|
|
65
70
|
|
|
66
|
-
|
|
71
|
+
// this is pretty straight-forward - we use the crypto API.
|
|
72
|
+
|
|
73
|
+
var crypto = require$$0__default["default"];
|
|
74
|
+
|
|
75
|
+
var rng$2 = function nodeRNG() {
|
|
76
|
+
return crypto.randomBytes(16);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
81
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
82
|
+
*/
|
|
83
|
+
var byteToHex = [];
|
|
84
|
+
|
|
85
|
+
for (var i = 0; i < 256; ++i) {
|
|
86
|
+
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function bytesToUuid$2(buf, offset) {
|
|
90
|
+
var i = offset || 0;
|
|
91
|
+
var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
|
|
92
|
+
|
|
93
|
+
return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join('');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var bytesToUuid_1 = bytesToUuid$2;
|
|
97
|
+
|
|
98
|
+
var rng$1 = rng$2;
|
|
99
|
+
var bytesToUuid$1 = bytesToUuid_1; // **`v1()` - Generate time-based UUID**
|
|
100
|
+
//
|
|
101
|
+
// Inspired by https://github.com/LiosK/UUID.js
|
|
102
|
+
// and http://docs.python.org/library/uuid.html
|
|
103
|
+
|
|
104
|
+
var _nodeId;
|
|
105
|
+
|
|
106
|
+
var _clockseq; // Previous uuid creation time
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
var _lastMSecs = 0;
|
|
110
|
+
var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
|
|
111
|
+
|
|
112
|
+
function v1$1(options, buf, offset) {
|
|
113
|
+
var i = buf && offset || 0;
|
|
114
|
+
var b = buf || [];
|
|
115
|
+
options = options || {};
|
|
116
|
+
var node = options.node || _nodeId;
|
|
117
|
+
var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
|
|
118
|
+
// specified. We do this lazily to minimize issues related to insufficient
|
|
119
|
+
// system entropy. See #189
|
|
120
|
+
|
|
121
|
+
if (node == null || clockseq == null) {
|
|
122
|
+
var seedBytes = rng$1();
|
|
123
|
+
|
|
124
|
+
if (node == null) {
|
|
125
|
+
// Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
|
|
126
|
+
node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (clockseq == null) {
|
|
130
|
+
// Per 4.2.2, randomize (14 bit) clockseq
|
|
131
|
+
clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
|
|
132
|
+
}
|
|
133
|
+
} // UUID timestamps are 100 nano-second units since the Gregorian epoch,
|
|
134
|
+
// (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
|
|
135
|
+
// time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
|
|
136
|
+
// (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime(); // Per 4.2.1.2, use count of uuid's generated during the current clock
|
|
140
|
+
// cycle to simulate higher resolution clock
|
|
141
|
+
|
|
142
|
+
var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
|
|
143
|
+
|
|
144
|
+
var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
|
|
145
|
+
|
|
146
|
+
if (dt < 0 && options.clockseq === undefined) {
|
|
147
|
+
clockseq = clockseq + 1 & 0x3fff;
|
|
148
|
+
} // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
|
|
149
|
+
// time interval
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
|
|
153
|
+
nsecs = 0;
|
|
154
|
+
} // Per 4.2.1.2 Throw error if too many uuids are requested
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
if (nsecs >= 10000) {
|
|
158
|
+
throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
_lastMSecs = msecs;
|
|
162
|
+
_lastNSecs = nsecs;
|
|
163
|
+
_clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
|
|
164
|
+
|
|
165
|
+
msecs += 12219292800000; // `time_low`
|
|
166
|
+
|
|
167
|
+
var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
|
|
168
|
+
b[i++] = tl >>> 24 & 0xff;
|
|
169
|
+
b[i++] = tl >>> 16 & 0xff;
|
|
170
|
+
b[i++] = tl >>> 8 & 0xff;
|
|
171
|
+
b[i++] = tl & 0xff; // `time_mid`
|
|
172
|
+
|
|
173
|
+
var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
|
|
174
|
+
b[i++] = tmh >>> 8 & 0xff;
|
|
175
|
+
b[i++] = tmh & 0xff; // `time_high_and_version`
|
|
176
|
+
|
|
177
|
+
b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
|
|
178
|
+
|
|
179
|
+
b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
|
|
180
|
+
|
|
181
|
+
b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
|
|
182
|
+
|
|
183
|
+
b[i++] = clockseq & 0xff; // `node`
|
|
184
|
+
|
|
185
|
+
for (var n = 0; n < 6; ++n) {
|
|
186
|
+
b[i + n] = node[n];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return buf ? buf : bytesToUuid$1(b);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
var v1_1 = v1$1;
|
|
193
|
+
|
|
194
|
+
var rng = rng$2;
|
|
195
|
+
var bytesToUuid = bytesToUuid_1;
|
|
196
|
+
|
|
197
|
+
function v4$1(options, buf, offset) {
|
|
198
|
+
var i = buf && offset || 0;
|
|
199
|
+
|
|
200
|
+
if (typeof options == 'string') {
|
|
201
|
+
buf = options === 'binary' ? new Array(16) : null;
|
|
202
|
+
options = null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
options = options || {};
|
|
206
|
+
var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
207
|
+
|
|
208
|
+
rnds[6] = rnds[6] & 0x0f | 0x40;
|
|
209
|
+
rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
|
|
210
|
+
|
|
211
|
+
if (buf) {
|
|
212
|
+
for (var ii = 0; ii < 16; ++ii) {
|
|
213
|
+
buf[i + ii] = rnds[ii];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return buf || bytesToUuid(rnds);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
var v4_1 = v4$1;
|
|
221
|
+
|
|
222
|
+
var v1 = v1_1;
|
|
223
|
+
var v4 = v4_1;
|
|
224
|
+
var uuid = v4;
|
|
225
|
+
uuid.v1 = v1;
|
|
226
|
+
uuid.v4 = v4;
|
|
227
|
+
var uuid_1 = uuid;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Cancellable promise. Extends the functionality of the native Promise to include the cancel method.
|
|
231
|
+
*
|
|
232
|
+
* Example:
|
|
233
|
+
*
|
|
234
|
+
* ```ts
|
|
235
|
+
*
|
|
236
|
+
* const cancellableFetchPromise = new CancellablePromise(async (resolve, reject, onCancel) => {
|
|
237
|
+
* const request = fetch("https://example.com/");
|
|
238
|
+
*
|
|
239
|
+
* onCancel(() => request.cancel());
|
|
240
|
+
*
|
|
241
|
+
* try {
|
|
242
|
+
* const response = await request;
|
|
243
|
+
* resolve(response);
|
|
244
|
+
* } catch (err) {
|
|
245
|
+
* reject(err);
|
|
246
|
+
* }
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* cancellableFetchPromise.cancel();
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
class CancellablePromise extends Promise {
|
|
254
|
+
/**
|
|
255
|
+
* Creates a new CancellablePromise.
|
|
256
|
+
* @param executor A callback used to initialize the promise. This callback is passed three arguments:
|
|
257
|
+
* a resolve callback used to resolve the promise with a value or the result of another promise,
|
|
258
|
+
* a reject callback used to reject the promise with a provided reason or error,
|
|
259
|
+
* and an onCancel callback used to define behavior of cancellation.
|
|
260
|
+
*/
|
|
261
|
+
constructor(executor) {
|
|
262
|
+
var outerId = uuid_1.v4();
|
|
263
|
+
var outerRejectPromise;
|
|
264
|
+
super((resolve, reject) => {
|
|
265
|
+
outerRejectPromise = reject;
|
|
266
|
+
return executor(value => {
|
|
267
|
+
CancellablePromise.cancellationMap.delete(outerId);
|
|
268
|
+
resolve(value);
|
|
269
|
+
}, reason => {
|
|
270
|
+
CancellablePromise.cancellationMap.delete(outerId);
|
|
271
|
+
reject(reason);
|
|
272
|
+
}, cancellationFunction => {
|
|
273
|
+
CancellablePromise.cancellationMap.set(outerId, cancellationFunction);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
this.id = outerId;
|
|
277
|
+
this.rejectPromise = outerRejectPromise;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Cancels the promise and invokes the cancellation callback if it was defined during instantiation. Cancellation will result in the promise being rejected.
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
cancel() {
|
|
285
|
+
var onCancel = CancellablePromise.cancellationMap.get(this.id);
|
|
286
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
287
|
+
|
|
288
|
+
if (this.rejectPromise) {
|
|
289
|
+
this.catch(() => void 0);
|
|
290
|
+
this.rejectPromise(new Error("Promise was cancelled"));
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
_defineProperty__default["default"](CancellablePromise, "cancellationMap", new Map());
|
|
299
|
+
|
|
300
|
+
/******************************************************************************
|
|
67
301
|
Copyright (c) Microsoft Corporation.
|
|
68
302
|
|
|
69
303
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -96,7 +330,7 @@ function prepareLine(prefix, args) {
|
|
|
96
330
|
|
|
97
331
|
class Logger {
|
|
98
332
|
constructor(prefix) {
|
|
99
|
-
_defineProperty__default[
|
|
333
|
+
_defineProperty__default["default"](this, "prefix", "");
|
|
100
334
|
|
|
101
335
|
this.prefix = prefix !== null && prefix !== undefined && prefix.length > 0 ? prefix + " " : "";
|
|
102
336
|
}
|
|
@@ -250,6 +484,7 @@ class Configuration {
|
|
|
250
484
|
* @property {String} fileName - file name, if present, null otherwise
|
|
251
485
|
* @property {MediaCategory} category - attachment category
|
|
252
486
|
*/
|
|
487
|
+
|
|
253
488
|
class Media {
|
|
254
489
|
constructor(config, network, data) {
|
|
255
490
|
this.config = config;
|
|
@@ -302,79 +537,51 @@ class Media {
|
|
|
302
537
|
*
|
|
303
538
|
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
304
539
|
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
305
|
-
*
|
|
306
|
-
* @returns {Promise<string>}
|
|
307
540
|
*/
|
|
308
541
|
|
|
309
542
|
|
|
310
543
|
getContentUrl() {
|
|
311
544
|
var _this = this;
|
|
312
545
|
|
|
313
|
-
return
|
|
314
|
-
var
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
334
|
-
}, _callee);
|
|
335
|
-
}))();
|
|
336
|
-
}
|
|
337
|
-
/**
|
|
338
|
-
* Returns direct content URL to uploaded binary. This URL will expire after some time.
|
|
339
|
-
* This function does not support getting a new URL however. Once set it will remain the same.
|
|
340
|
-
* Use getContentUrl() to query a new one.
|
|
341
|
-
*
|
|
342
|
-
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
343
|
-
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
344
|
-
*
|
|
345
|
-
* @returns {Promise<string>}
|
|
346
|
-
*/
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
getCachedContentUrl() {
|
|
350
|
-
var _this2 = this;
|
|
351
|
-
|
|
352
|
-
return _asyncToGenerator__default['default']( /*#__PURE__*/_regeneratorRuntime__default['default'].mark(function _callee2() {
|
|
353
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
|
|
354
|
-
while (1) {
|
|
355
|
-
switch (_context2.prev = _context2.next) {
|
|
356
|
-
case 0:
|
|
357
|
-
if (!_this2.state.contentDirectUrl) {
|
|
358
|
-
_context2.next = 2;
|
|
546
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
547
|
+
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(resolve, reject, onCancel) {
|
|
548
|
+
var request, response;
|
|
549
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
550
|
+
while (1) {
|
|
551
|
+
switch (_context.prev = _context.next) {
|
|
552
|
+
case 0:
|
|
553
|
+
request = _this.network.get("".concat(_this.config.mediaUrl, "/").concat(_this.sid));
|
|
554
|
+
onCancel(() => request.cancel());
|
|
555
|
+
_context.prev = 2;
|
|
556
|
+
_context.next = 5;
|
|
557
|
+
return request;
|
|
558
|
+
|
|
559
|
+
case 5:
|
|
560
|
+
response = _context.sent;
|
|
561
|
+
|
|
562
|
+
_this._update(response.body);
|
|
563
|
+
|
|
564
|
+
resolve(_this.state.contentDirectUrl);
|
|
565
|
+
_context.next = 13;
|
|
359
566
|
break;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return _context2.abrupt("return", Promise.resolve(_this2.state.contentDirectUrl));
|
|
363
567
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
568
|
+
case 10:
|
|
569
|
+
_context.prev = 10;
|
|
570
|
+
_context.t0 = _context["catch"](2);
|
|
571
|
+
reject(_context.t0);
|
|
367
572
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
case "end":
|
|
373
|
-
return _context2.stop();
|
|
573
|
+
case 13:
|
|
574
|
+
case "end":
|
|
575
|
+
return _context.stop();
|
|
576
|
+
}
|
|
374
577
|
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
578
|
+
}, _callee, null, [[2, 10]]);
|
|
579
|
+
}));
|
|
580
|
+
|
|
581
|
+
return function (_x, _x2, _x3) {
|
|
582
|
+
return _ref.apply(this, arguments);
|
|
583
|
+
};
|
|
584
|
+
}());
|
|
378
585
|
}
|
|
379
586
|
|
|
380
587
|
_update(data) {
|
|
@@ -446,64 +653,62 @@ function extractBody(xhr) {
|
|
|
446
653
|
|
|
447
654
|
class Transport {
|
|
448
655
|
static request(method, url, headers, body) {
|
|
449
|
-
return
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
656
|
+
return new CancellablePromise((resolve, reject, onCancel) => {
|
|
657
|
+
var xhr = new XHR();
|
|
658
|
+
var isCancelled = false;
|
|
659
|
+
onCancel(() => {
|
|
660
|
+
xhr.abort();
|
|
661
|
+
isCancelled = true;
|
|
662
|
+
});
|
|
663
|
+
xhr.open(method, url, true);
|
|
664
|
+
|
|
665
|
+
xhr.onreadystatechange = function onreadystatechange() {
|
|
666
|
+
if (xhr.readyState !== 4 || isCancelled) {
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
462
669
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (200 <= xhr.status && xhr.status < 300) {
|
|
467
|
-
resolve({
|
|
468
|
-
status: xhr.status,
|
|
469
|
-
headers,
|
|
470
|
-
body
|
|
471
|
-
});
|
|
472
|
-
} else {
|
|
473
|
-
var _xhr$statusText;
|
|
474
|
-
|
|
475
|
-
var status = (_xhr$statusText = xhr.statusText) !== null && _xhr$statusText !== void 0 ? _xhr$statusText : "NONE";
|
|
476
|
-
var bodyRepresentation;
|
|
477
|
-
|
|
478
|
-
if (typeof body === "string") {
|
|
479
|
-
bodyRepresentation = body && body.split("\n", 2).length === 1 ? body : "";
|
|
480
|
-
} else {
|
|
481
|
-
bodyRepresentation = JSON.stringify(body);
|
|
482
|
-
}
|
|
670
|
+
var responseHeaders = parseResponseHeaders(xhr.getAllResponseHeaders());
|
|
671
|
+
var body = extractBody(xhr);
|
|
483
672
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
673
|
+
if (200 <= xhr.status && xhr.status < 300) {
|
|
674
|
+
resolve({
|
|
675
|
+
status: xhr.status,
|
|
676
|
+
headers: responseHeaders,
|
|
677
|
+
body
|
|
678
|
+
});
|
|
679
|
+
} else {
|
|
680
|
+
var _xhr$statusText;
|
|
488
681
|
|
|
489
|
-
|
|
490
|
-
|
|
682
|
+
var status = (_xhr$statusText = xhr.statusText) !== null && _xhr$statusText !== void 0 ? _xhr$statusText : "NONE";
|
|
683
|
+
var bodyRepresentation;
|
|
491
684
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
xhr.send(body);
|
|
498
|
-
}));
|
|
685
|
+
if (typeof body === "string") {
|
|
686
|
+
if (body && body.split("\n", 2).length === 1) bodyRepresentation = body;else {
|
|
687
|
+
var _body$replace$split$f;
|
|
499
688
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
689
|
+
// TODO: RTDSDK-3716: investigate why body is HTML string
|
|
690
|
+
var errorInfo = (_body$replace$split$f = body.replace(/<.*?>/g, "").split(/\r\n/g).filter(str => str.length)[0]) === null || _body$replace$split$f === void 0 ? void 0 : _body$replace$split$f.split(" ");
|
|
691
|
+
bodyRepresentation = (errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.length) > 2 ? errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.slice(1).join(" ") : "";
|
|
692
|
+
}
|
|
693
|
+
} else {
|
|
694
|
+
bodyRepresentation = JSON.stringify(body);
|
|
503
695
|
}
|
|
696
|
+
|
|
697
|
+
var message = "".concat(xhr.status, ": [").concat(status, "] ").concat(bodyRepresentation);
|
|
698
|
+
reject(new TransportError(message, xhr.status, body, status, responseHeaders));
|
|
504
699
|
}
|
|
505
|
-
}
|
|
506
|
-
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
for (var headerName in headers) {
|
|
703
|
+
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
704
|
+
|
|
705
|
+
if (headerName === "Content-Type" && headers[headerName] === "application/json") {
|
|
706
|
+
body = JSON.stringify(body);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
xhr.send(body);
|
|
711
|
+
});
|
|
507
712
|
}
|
|
508
713
|
/**
|
|
509
714
|
* Make a GET request by given URL
|
|
@@ -511,20 +716,7 @@ class Transport {
|
|
|
511
716
|
|
|
512
717
|
|
|
513
718
|
get(url, headers) {
|
|
514
|
-
return
|
|
515
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee2$(_context2) {
|
|
516
|
-
while (1) {
|
|
517
|
-
switch (_context2.prev = _context2.next) {
|
|
518
|
-
case 0:
|
|
519
|
-
return _context2.abrupt("return", Transport.request("GET", url, headers));
|
|
520
|
-
|
|
521
|
-
case 1:
|
|
522
|
-
case "end":
|
|
523
|
-
return _context2.stop();
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}, _callee2);
|
|
527
|
-
}))();
|
|
719
|
+
return Transport.request("GET", url, headers);
|
|
528
720
|
}
|
|
529
721
|
/**
|
|
530
722
|
* Make a POST request by given URL
|
|
@@ -532,20 +724,7 @@ class Transport {
|
|
|
532
724
|
|
|
533
725
|
|
|
534
726
|
post(url, headers, body) {
|
|
535
|
-
return
|
|
536
|
-
return _regeneratorRuntime__default['default'].wrap(function _callee3$(_context3) {
|
|
537
|
-
while (1) {
|
|
538
|
-
switch (_context3.prev = _context3.next) {
|
|
539
|
-
case 0:
|
|
540
|
-
return _context3.abrupt("return", Transport.request("POST", url, headers, body));
|
|
541
|
-
|
|
542
|
-
case 1:
|
|
543
|
-
case "end":
|
|
544
|
-
return _context3.stop();
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}, _callee3);
|
|
548
|
-
}))();
|
|
727
|
+
return Transport.request("POST", url, headers, body);
|
|
549
728
|
}
|
|
550
729
|
|
|
551
730
|
}
|
|
@@ -571,37 +750,48 @@ class Network {
|
|
|
571
750
|
executeWithRetry(request, retryWhenThrottled) {
|
|
572
751
|
var _this = this;
|
|
573
752
|
|
|
574
|
-
return
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
753
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
754
|
+
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(resolve, reject, onCancel) {
|
|
755
|
+
var retrier, codesToRetryOn;
|
|
756
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
757
|
+
while (1) {
|
|
758
|
+
switch (_context2.prev = _context2.next) {
|
|
759
|
+
case 0:
|
|
760
|
+
retrier = new operationRetrier.Retrier(_this.backoffConfig());
|
|
761
|
+
codesToRetryOn = [502, 503, 504];
|
|
581
762
|
|
|
582
763
|
if (retryWhenThrottled) {
|
|
583
764
|
codesToRetryOn.push(429);
|
|
584
765
|
}
|
|
585
766
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
767
|
+
onCancel(() => {
|
|
768
|
+
retrier.cancel();
|
|
769
|
+
retrier.removeAllListeners();
|
|
770
|
+
});
|
|
771
|
+
retrier.on("attempt", /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
772
|
+
var requestPromise, result;
|
|
773
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
590
774
|
while (1) {
|
|
591
775
|
switch (_context.prev = _context.next) {
|
|
592
776
|
case 0:
|
|
593
777
|
_context.prev = 0;
|
|
594
|
-
|
|
595
|
-
|
|
778
|
+
requestPromise = request();
|
|
779
|
+
onCancel(() => {
|
|
780
|
+
requestPromise.cancel();
|
|
781
|
+
retrier.cancel();
|
|
782
|
+
retrier.removeAllListeners();
|
|
783
|
+
});
|
|
784
|
+
_context.next = 5;
|
|
785
|
+
return requestPromise;
|
|
596
786
|
|
|
597
|
-
case
|
|
787
|
+
case 5:
|
|
598
788
|
result = _context.sent;
|
|
599
789
|
retrier.succeeded(result);
|
|
600
|
-
_context.next =
|
|
790
|
+
_context.next = 12;
|
|
601
791
|
break;
|
|
602
792
|
|
|
603
|
-
case
|
|
604
|
-
_context.prev =
|
|
793
|
+
case 9:
|
|
794
|
+
_context.prev = 9;
|
|
605
795
|
_context.t0 = _context["catch"](0);
|
|
606
796
|
|
|
607
797
|
if (codesToRetryOn.indexOf(_context.t0.status) > -1) {
|
|
@@ -616,12 +806,12 @@ class Network {
|
|
|
616
806
|
reject(_context.t0);
|
|
617
807
|
}
|
|
618
808
|
|
|
619
|
-
case
|
|
809
|
+
case 12:
|
|
620
810
|
case "end":
|
|
621
811
|
return _context.stop();
|
|
622
812
|
}
|
|
623
813
|
}
|
|
624
|
-
}, _callee, null, [[0,
|
|
814
|
+
}, _callee, null, [[0, 9]]);
|
|
625
815
|
})));
|
|
626
816
|
retrier.on("succeeded", result => {
|
|
627
817
|
resolve(result);
|
|
@@ -629,132 +819,156 @@ class Network {
|
|
|
629
819
|
retrier.on("cancelled", err => reject(err));
|
|
630
820
|
retrier.on("failed", err => reject(err));
|
|
631
821
|
retrier.start();
|
|
632
|
-
}));
|
|
633
822
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
823
|
+
case 9:
|
|
824
|
+
case "end":
|
|
825
|
+
return _context2.stop();
|
|
826
|
+
}
|
|
637
827
|
}
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
|
|
828
|
+
}, _callee2);
|
|
829
|
+
}));
|
|
830
|
+
|
|
831
|
+
return function (_x, _x2, _x3) {
|
|
832
|
+
return _ref2.apply(this, arguments);
|
|
833
|
+
};
|
|
834
|
+
}());
|
|
641
835
|
}
|
|
642
836
|
|
|
643
837
|
get(url) {
|
|
644
838
|
var _this2 = this;
|
|
645
839
|
|
|
646
|
-
return
|
|
647
|
-
var
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
840
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
841
|
+
var _ref4 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(resolve, reject, onCancel) {
|
|
842
|
+
var headers, request, response;
|
|
843
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
844
|
+
while (1) {
|
|
845
|
+
switch (_context3.prev = _context3.next) {
|
|
846
|
+
case 0:
|
|
847
|
+
headers = {
|
|
848
|
+
"X-Twilio-Token": _this2.config.token
|
|
849
|
+
};
|
|
850
|
+
request = _this2.executeWithRetry(() => _this2.transport.get(url, headers), _this2.retryWhenThrottled());
|
|
851
|
+
log$1.trace("sending GET request to ", url, " headers ", headers);
|
|
852
|
+
onCancel(() => request.cancel());
|
|
853
|
+
_context3.prev = 4;
|
|
854
|
+
_context3.next = 7;
|
|
855
|
+
return request;
|
|
856
|
+
|
|
857
|
+
case 7:
|
|
858
|
+
response = _context3.sent;
|
|
859
|
+
log$1.trace("response", response);
|
|
860
|
+
resolve(response);
|
|
861
|
+
_context3.next = 16;
|
|
862
|
+
break;
|
|
863
|
+
|
|
864
|
+
case 12:
|
|
865
|
+
_context3.prev = 12;
|
|
866
|
+
_context3.t0 = _context3["catch"](4);
|
|
867
|
+
log$1.debug("get() error ".concat(_context3.t0));
|
|
868
|
+
reject(_context3.t0);
|
|
869
|
+
|
|
870
|
+
case 16:
|
|
871
|
+
case "end":
|
|
872
|
+
return _context3.stop();
|
|
873
|
+
}
|
|
674
874
|
}
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
|
|
875
|
+
}, _callee3, null, [[4, 12]]);
|
|
876
|
+
}));
|
|
877
|
+
|
|
878
|
+
return function (_x4, _x5, _x6) {
|
|
879
|
+
return _ref4.apply(this, arguments);
|
|
880
|
+
};
|
|
881
|
+
}());
|
|
678
882
|
}
|
|
679
883
|
|
|
680
884
|
post(url, category, media, contentType, filename) {
|
|
681
885
|
var _this3 = this;
|
|
682
886
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
while (1) {
|
|
687
|
-
switch (_context4.prev = _context4.next) {
|
|
688
|
-
case 0:
|
|
689
|
-
headers = {
|
|
690
|
-
"X-Twilio-Token": _this3.config.token
|
|
691
|
-
};
|
|
692
|
-
|
|
693
|
-
if ((typeof FormData === "undefined" || !(media instanceof FormData)) && contentType) {
|
|
694
|
-
Object.assign(headers, {
|
|
695
|
-
"Content-Type": contentType
|
|
696
|
-
});
|
|
697
|
-
}
|
|
887
|
+
var headers = {
|
|
888
|
+
"X-Twilio-Token": this.config.token
|
|
889
|
+
};
|
|
698
890
|
|
|
699
|
-
|
|
891
|
+
if ((typeof FormData === "undefined" || !(media instanceof FormData)) && contentType) {
|
|
892
|
+
Object.assign(headers, {
|
|
893
|
+
"Content-Type": contentType
|
|
894
|
+
});
|
|
895
|
+
}
|
|
700
896
|
|
|
701
|
-
|
|
702
|
-
fullUrl.searchParams.append("Category", category);
|
|
703
|
-
}
|
|
897
|
+
var fullUrl = new URL(url);
|
|
704
898
|
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
899
|
+
if (category) {
|
|
900
|
+
fullUrl.searchParams.append("Category", category);
|
|
901
|
+
}
|
|
708
902
|
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
return _this3.transport.post(fullUrl.href, headers, media);
|
|
903
|
+
if (filename) {
|
|
904
|
+
fullUrl.searchParams.append("Filename", filename);
|
|
905
|
+
}
|
|
713
906
|
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
907
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
908
|
+
var _ref5 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(resolve, reject, onCancel) {
|
|
909
|
+
var request, response;
|
|
910
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
911
|
+
while (1) {
|
|
912
|
+
switch (_context4.prev = _context4.next) {
|
|
913
|
+
case 0:
|
|
914
|
+
request = _this3.transport.post(fullUrl.href, headers, media);
|
|
915
|
+
onCancel(() => request.cancel());
|
|
916
|
+
log$1.trace("sending POST request to ".concat(url, " with headers ").concat(headers));
|
|
917
|
+
_context4.prev = 3;
|
|
918
|
+
_context4.next = 6;
|
|
919
|
+
return request;
|
|
920
|
+
|
|
921
|
+
case 6:
|
|
922
|
+
response = _context4.sent;
|
|
923
|
+
_context4.next = 17;
|
|
924
|
+
break;
|
|
718
925
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
926
|
+
case 9:
|
|
927
|
+
_context4.prev = 9;
|
|
928
|
+
_context4.t0 = _context4["catch"](3);
|
|
722
929
|
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
930
|
+
if (!(global["XMLHttpRequest"] === undefined && media instanceof FormData)) {
|
|
931
|
+
_context4.next = 14;
|
|
932
|
+
break;
|
|
933
|
+
}
|
|
727
934
|
|
|
728
|
-
|
|
935
|
+
reject(new TypeError("Posting FormData supported only with browser engine's FormData"));
|
|
936
|
+
return _context4.abrupt("return");
|
|
729
937
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
938
|
+
case 14:
|
|
939
|
+
log$1.debug("post() error ".concat(_context4.t0));
|
|
940
|
+
reject(_context4.t0);
|
|
941
|
+
return _context4.abrupt("return");
|
|
733
942
|
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
943
|
+
case 17:
|
|
944
|
+
log$1.trace("response", response);
|
|
945
|
+
resolve(response);
|
|
737
946
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
947
|
+
case 19:
|
|
948
|
+
case "end":
|
|
949
|
+
return _context4.stop();
|
|
950
|
+
}
|
|
741
951
|
}
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
|
|
952
|
+
}, _callee4, null, [[3, 9]]);
|
|
953
|
+
}));
|
|
954
|
+
|
|
955
|
+
return function (_x7, _x8, _x9) {
|
|
956
|
+
return _ref5.apply(this, arguments);
|
|
957
|
+
};
|
|
958
|
+
}());
|
|
745
959
|
}
|
|
746
960
|
|
|
747
961
|
}
|
|
748
962
|
|
|
749
|
-
var version = "0.
|
|
963
|
+
var version = "0.6.0-rc.10";
|
|
750
964
|
|
|
751
|
-
var _class
|
|
965
|
+
var _class;
|
|
752
966
|
var log = Logger.scope("");
|
|
753
967
|
/**
|
|
754
968
|
* @classdesc A Client provides an interface for Media Content Service
|
|
755
969
|
*/
|
|
756
970
|
|
|
757
|
-
exports[
|
|
971
|
+
exports["default"] = (_class = class Client {
|
|
758
972
|
// eslint-disable-next-line
|
|
759
973
|
|
|
760
974
|
/**
|
|
@@ -799,66 +1013,96 @@ exports['default'] = (_temp = _class = class Client {
|
|
|
799
1013
|
/**
|
|
800
1014
|
* Gets media from media service
|
|
801
1015
|
* @param {String} sid - Media's SID
|
|
802
|
-
* @returns {Promise<Media>}
|
|
803
1016
|
*/
|
|
804
1017
|
|
|
805
1018
|
|
|
806
1019
|
get(sid) {
|
|
807
1020
|
var _this = this;
|
|
808
1021
|
|
|
809
|
-
return
|
|
810
|
-
var
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
1022
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1023
|
+
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(resolve, reject, onCancel) {
|
|
1024
|
+
var request, response;
|
|
1025
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
1026
|
+
while (1) {
|
|
1027
|
+
switch (_context.prev = _context.next) {
|
|
1028
|
+
case 0:
|
|
1029
|
+
request = _this.network.get("".concat(_this.config.mediaUrl, "/").concat(sid));
|
|
1030
|
+
onCancel(() => request.cancel());
|
|
1031
|
+
_context.prev = 2;
|
|
1032
|
+
_context.next = 5;
|
|
1033
|
+
return request;
|
|
1034
|
+
|
|
1035
|
+
case 5:
|
|
1036
|
+
response = _context.sent;
|
|
1037
|
+
resolve(new Media(_this.config, _this.network, response.body));
|
|
1038
|
+
_context.next = 12;
|
|
1039
|
+
break;
|
|
1040
|
+
|
|
1041
|
+
case 9:
|
|
1042
|
+
_context.prev = 9;
|
|
1043
|
+
_context.t0 = _context["catch"](2);
|
|
1044
|
+
reject(_context.t0);
|
|
1045
|
+
|
|
1046
|
+
case 12:
|
|
1047
|
+
case "end":
|
|
1048
|
+
return _context.stop();
|
|
1049
|
+
}
|
|
825
1050
|
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
|
|
1051
|
+
}, _callee, null, [[2, 9]]);
|
|
1052
|
+
}));
|
|
1053
|
+
|
|
1054
|
+
return function (_x, _x2, _x3) {
|
|
1055
|
+
return _ref.apply(this, arguments);
|
|
1056
|
+
};
|
|
1057
|
+
}());
|
|
829
1058
|
}
|
|
830
1059
|
/**
|
|
831
1060
|
* Posts raw content to media service
|
|
832
1061
|
* @param {String} contentType - content type of media
|
|
833
1062
|
* @param {String|Buffer|Blob} media - content to post
|
|
834
1063
|
* @param {MediaCategory|null} category - category for the media
|
|
835
|
-
* @returns {Promise<Media>}
|
|
836
1064
|
*/
|
|
837
1065
|
|
|
838
1066
|
|
|
839
1067
|
post(contentType, media, category, filename) {
|
|
840
1068
|
var _this2 = this;
|
|
841
1069
|
|
|
842
|
-
return
|
|
843
|
-
var
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
1070
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1071
|
+
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(resolve, reject, onCancel) {
|
|
1072
|
+
var request, response;
|
|
1073
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
1074
|
+
while (1) {
|
|
1075
|
+
switch (_context2.prev = _context2.next) {
|
|
1076
|
+
case 0:
|
|
1077
|
+
request = _this2.network.post(_this2.config.mediaUrl, category !== null && category !== void 0 ? category : "media", media, contentType, filename);
|
|
1078
|
+
onCancel(() => request.cancel());
|
|
1079
|
+
_context2.prev = 2;
|
|
1080
|
+
_context2.next = 5;
|
|
1081
|
+
return request;
|
|
1082
|
+
|
|
1083
|
+
case 5:
|
|
1084
|
+
response = _context2.sent;
|
|
1085
|
+
resolve(new Media(_this2.config, _this2.network, response.body));
|
|
1086
|
+
_context2.next = 12;
|
|
1087
|
+
break;
|
|
1088
|
+
|
|
1089
|
+
case 9:
|
|
1090
|
+
_context2.prev = 9;
|
|
1091
|
+
_context2.t0 = _context2["catch"](2);
|
|
1092
|
+
reject(_context2.t0);
|
|
1093
|
+
|
|
1094
|
+
case 12:
|
|
1095
|
+
case "end":
|
|
1096
|
+
return _context2.stop();
|
|
1097
|
+
}
|
|
858
1098
|
}
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
|
|
1099
|
+
}, _callee2, null, [[2, 9]]);
|
|
1100
|
+
}));
|
|
1101
|
+
|
|
1102
|
+
return function (_x4, _x5, _x6) {
|
|
1103
|
+
return _ref2.apply(this, arguments);
|
|
1104
|
+
};
|
|
1105
|
+
}());
|
|
862
1106
|
}
|
|
863
1107
|
/**
|
|
864
1108
|
* Posts FormData to media service. Can be used only with browser engine's FormData.
|
|
@@ -866,33 +1110,48 @@ exports['default'] = (_temp = _class = class Client {
|
|
|
866
1110
|
* new TypeError("Posting FormData supported only with browser engine's FormData")
|
|
867
1111
|
* @param {FormData} formData - form data to post
|
|
868
1112
|
* @param {MediaCategory|null} category - category for the media
|
|
869
|
-
* @returns {Promise<Media>}
|
|
870
1113
|
*/
|
|
871
1114
|
|
|
872
1115
|
|
|
873
1116
|
postFormData(formData, category) {
|
|
874
1117
|
var _this3 = this;
|
|
875
1118
|
|
|
876
|
-
return
|
|
877
|
-
var
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
1119
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1120
|
+
var _ref3 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(resolve, reject, onCancel) {
|
|
1121
|
+
var request, response;
|
|
1122
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
1123
|
+
while (1) {
|
|
1124
|
+
switch (_context3.prev = _context3.next) {
|
|
1125
|
+
case 0:
|
|
1126
|
+
request = _this3.network.post(_this3.config.mediaUrl, category !== null && category !== void 0 ? category : "media", formData);
|
|
1127
|
+
onCancel(() => request.cancel());
|
|
1128
|
+
_context3.prev = 2;
|
|
1129
|
+
_context3.next = 5;
|
|
1130
|
+
return request;
|
|
1131
|
+
|
|
1132
|
+
case 5:
|
|
1133
|
+
response = _context3.sent;
|
|
1134
|
+
resolve(new Media(_this3.config, _this3.network, response.body));
|
|
1135
|
+
_context3.next = 12;
|
|
1136
|
+
break;
|
|
1137
|
+
|
|
1138
|
+
case 9:
|
|
1139
|
+
_context3.prev = 9;
|
|
1140
|
+
_context3.t0 = _context3["catch"](2);
|
|
1141
|
+
reject(_context3.t0);
|
|
1142
|
+
|
|
1143
|
+
case 12:
|
|
1144
|
+
case "end":
|
|
1145
|
+
return _context3.stop();
|
|
1146
|
+
}
|
|
892
1147
|
}
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
|
|
1148
|
+
}, _callee3, null, [[2, 9]]);
|
|
1149
|
+
}));
|
|
1150
|
+
|
|
1151
|
+
return function (_x7, _x8, _x9) {
|
|
1152
|
+
return _ref3.apply(this, arguments);
|
|
1153
|
+
};
|
|
1154
|
+
}());
|
|
896
1155
|
}
|
|
897
1156
|
/**
|
|
898
1157
|
* Retrieve information about multiple media SIDs at the same time.
|
|
@@ -903,51 +1162,130 @@ exports['default'] = (_temp = _class = class Client {
|
|
|
903
1162
|
mediaSetGet(mediaSids) {
|
|
904
1163
|
var _this4 = this;
|
|
905
1164
|
|
|
906
|
-
return
|
|
907
|
-
var
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1165
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1166
|
+
var _ref4 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(resolve, reject, onCancel) {
|
|
1167
|
+
var query, request, response, media;
|
|
1168
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
1169
|
+
while (1) {
|
|
1170
|
+
switch (_context4.prev = _context4.next) {
|
|
1171
|
+
case 0:
|
|
1172
|
+
query = {
|
|
1173
|
+
command: "get",
|
|
1174
|
+
list: mediaSids.map(sid => ({
|
|
1175
|
+
media_sid: sid
|
|
1176
|
+
}))
|
|
1177
|
+
};
|
|
1178
|
+
request = _this4.network.post("".concat(_this4.config.mediaSetUrl), null, query, "application/json");
|
|
1179
|
+
onCancel(() => request.cancel());
|
|
1180
|
+
_context4.prev = 3;
|
|
1181
|
+
_context4.next = 6;
|
|
1182
|
+
return request;
|
|
1183
|
+
|
|
1184
|
+
case 6:
|
|
1185
|
+
response = _context4.sent;
|
|
1186
|
+
media = response.body.map(item => {
|
|
1187
|
+
if (item.code !== 200) {
|
|
1188
|
+
reject("Failed to obtain detailed information about Media items (failed SID ".concat(item.media_record.sid, ")"));
|
|
1189
|
+
return;
|
|
1190
|
+
}
|
|
927
1191
|
|
|
928
|
-
|
|
929
|
-
|
|
1192
|
+
return new Media(_this4.config, _this4.network, item.media_record);
|
|
1193
|
+
});
|
|
1194
|
+
resolve(media);
|
|
1195
|
+
_context4.next = 14;
|
|
1196
|
+
break;
|
|
1197
|
+
|
|
1198
|
+
case 11:
|
|
1199
|
+
_context4.prev = 11;
|
|
1200
|
+
_context4.t0 = _context4["catch"](3);
|
|
1201
|
+
reject(_context4.t0);
|
|
930
1202
|
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
1203
|
+
case 14:
|
|
1204
|
+
case "end":
|
|
1205
|
+
return _context4.stop();
|
|
1206
|
+
}
|
|
934
1207
|
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
|
|
1208
|
+
}, _callee4, null, [[3, 11]]);
|
|
1209
|
+
}));
|
|
1210
|
+
|
|
1211
|
+
return function (_x10, _x11, _x12) {
|
|
1212
|
+
return _ref4.apply(this, arguments);
|
|
1213
|
+
};
|
|
1214
|
+
}());
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Retrieve temporary URLs for a set of media SIDs.
|
|
1218
|
+
* @param mediaSids array of the media SIDs to get URLs from.
|
|
1219
|
+
*/
|
|
1220
|
+
|
|
1221
|
+
|
|
1222
|
+
mediaSetGetContentUrls(mediaSids) {
|
|
1223
|
+
var _this5 = this;
|
|
1224
|
+
|
|
1225
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1226
|
+
var _ref5 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(resolve, reject, onCancel) {
|
|
1227
|
+
var query, request, response, urls;
|
|
1228
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
|
1229
|
+
while (1) {
|
|
1230
|
+
switch (_context5.prev = _context5.next) {
|
|
1231
|
+
case 0:
|
|
1232
|
+
query = {
|
|
1233
|
+
command: "get",
|
|
1234
|
+
list: mediaSids.map(sid => ({
|
|
1235
|
+
media_sid: sid
|
|
1236
|
+
}))
|
|
1237
|
+
};
|
|
1238
|
+
request = _this5.network.post("".concat(_this5.config.mediaSetUrl), null, query, "application/json");
|
|
1239
|
+
onCancel(() => request.cancel());
|
|
1240
|
+
_context5.prev = 3;
|
|
1241
|
+
_context5.next = 6;
|
|
1242
|
+
return request;
|
|
1243
|
+
|
|
1244
|
+
case 6:
|
|
1245
|
+
response = _context5.sent;
|
|
1246
|
+
urls = new Map();
|
|
1247
|
+
response.body.forEach(item => {
|
|
1248
|
+
if (item.code !== 200) {
|
|
1249
|
+
reject("Failed to obtain detailed information about Media items (failed SID ".concat(item.media_record.sid, ")"));
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
urls.set(item.media_record.sid, item.media_record.links.content_direct_temporary);
|
|
1254
|
+
});
|
|
1255
|
+
resolve(urls);
|
|
1256
|
+
_context5.next = 15;
|
|
1257
|
+
break;
|
|
1258
|
+
|
|
1259
|
+
case 12:
|
|
1260
|
+
_context5.prev = 12;
|
|
1261
|
+
_context5.t0 = _context5["catch"](3);
|
|
1262
|
+
reject(_context5.t0);
|
|
1263
|
+
|
|
1264
|
+
case 15:
|
|
1265
|
+
case "end":
|
|
1266
|
+
return _context5.stop();
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}, _callee5, null, [[3, 12]]);
|
|
1270
|
+
}));
|
|
1271
|
+
|
|
1272
|
+
return function (_x13, _x14, _x15) {
|
|
1273
|
+
return _ref5.apply(this, arguments);
|
|
1274
|
+
};
|
|
1275
|
+
}());
|
|
938
1276
|
}
|
|
939
1277
|
|
|
940
|
-
}, _defineProperty__default[
|
|
1278
|
+
}, _defineProperty__default["default"](_class, "version", version), _class);
|
|
941
1279
|
|
|
942
|
-
__decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0)], exports[
|
|
1280
|
+
__decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0)], exports["default"].prototype, "updateToken", null);
|
|
943
1281
|
|
|
944
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype",
|
|
1282
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", CancellablePromise)], exports["default"].prototype, "get", null);
|
|
945
1283
|
|
|
946
|
-
exports[
|
|
1284
|
+
exports["default"] = __decorate([declarativeTypeValidator.validateConstructorTypes(declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.nonEmptyString, [declarativeTypeValidator.nonEmptyString, declarativeTypeValidator.literal(null)], [declarativeTypeValidator.pureObject, "undefined"]), __metadata("design:paramtypes", [String, String, Object, Object])], exports["default"]); // Proper renames should happen in index.ts,
|
|
947
1285
|
|
|
948
|
-
exports.
|
|
949
|
-
exports.
|
|
1286
|
+
exports.CancellablePromise = CancellablePromise;
|
|
1287
|
+
exports.Client = exports["default"];
|
|
1288
|
+
exports.McsClient = exports["default"];
|
|
950
1289
|
exports.McsMedia = Media;
|
|
951
1290
|
exports.Media = Media;
|
|
952
|
-
exports.default = exports['default'];
|
|
953
1291
|
//# sourceMappingURL=lib.js.map
|