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