@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/lib.js
CHANGED
|
@@ -19,283 +19,30 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
19
19
|
|
|
20
20
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
21
21
|
|
|
22
|
-
var
|
|
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');
|
|
30
|
-
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
31
|
-
require('core-js/modules/es.array.from.js');
|
|
22
|
+
var shared = require('@twilio/shared');
|
|
32
23
|
var log$2 = require('loglevel');
|
|
33
|
-
require('core-js/modules/es.string.starts-with.js');
|
|
34
|
-
require('core-js/modules/es.array.reduce.js');
|
|
35
|
-
require('core-js/modules/es.regexp.exec.js');
|
|
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');
|
|
39
|
-
require('core-js/modules/es.object.assign.js');
|
|
40
|
-
require('core-js/modules/web.url.js');
|
|
41
|
-
require('core-js/modules/web.url-search-params.js');
|
|
42
24
|
var operationRetrier = require('@twilio/operation-retrier');
|
|
43
25
|
var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
|
44
26
|
|
|
45
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
46
|
-
|
|
47
27
|
function _interopNamespace(e) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
28
|
+
if (e && e.__esModule) return e;
|
|
29
|
+
var n = Object.create(null);
|
|
30
|
+
if (e) {
|
|
31
|
+
Object.keys(e).forEach(function (k) {
|
|
32
|
+
if (k !== 'default') {
|
|
33
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
34
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function () { return e[k]; }
|
|
37
|
+
});
|
|
38
|
+
}
|
|
57
39
|
});
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
n["default"] = e;
|
|
62
|
-
return Object.freeze(n);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
66
|
-
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
67
|
-
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
68
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
69
|
-
var log__namespace = /*#__PURE__*/_interopNamespace(log$2);
|
|
70
|
-
|
|
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
40
|
}
|
|
128
|
-
|
|
129
|
-
|
|
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);
|
|
41
|
+
n["default"] = e;
|
|
42
|
+
return Object.freeze(n);
|
|
190
43
|
}
|
|
191
44
|
|
|
192
|
-
var
|
|
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());
|
|
45
|
+
var log__namespace = /*#__PURE__*/_interopNamespace(log$2);
|
|
299
46
|
|
|
300
47
|
/******************************************************************************
|
|
301
48
|
Copyright (c) Microsoft Corporation.
|
|
@@ -313,11 +60,9 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
313
60
|
***************************************************************************** */
|
|
314
61
|
function __decorate(decorators, target, key, desc) {
|
|
315
62
|
var c = arguments.length,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
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--)
|
|
319
|
-
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
320
|
-
}
|
|
63
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
64
|
+
d;
|
|
65
|
+
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;
|
|
321
66
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
322
67
|
}
|
|
323
68
|
function __metadata(metadataKey, metadataValue) {
|
|
@@ -325,136 +70,108 @@ function __metadata(metadataKey, metadataValue) {
|
|
|
325
70
|
}
|
|
326
71
|
|
|
327
72
|
function prepareLine(prefix, args) {
|
|
328
|
-
return [
|
|
73
|
+
return [`${new Date().toISOString()} MCS Client ${prefix}:`].concat(Array.from(args));
|
|
329
74
|
}
|
|
330
|
-
|
|
331
75
|
class Logger {
|
|
76
|
+
prefix = "";
|
|
332
77
|
constructor(prefix) {
|
|
333
|
-
_defineProperty__default["default"](this, "prefix", "");
|
|
334
|
-
|
|
335
78
|
this.prefix = prefix !== null && prefix !== undefined && prefix.length > 0 ? prefix + " " : "";
|
|
336
79
|
}
|
|
337
|
-
|
|
338
80
|
static scope(prefix) {
|
|
339
81
|
return new Logger(prefix);
|
|
340
82
|
}
|
|
341
|
-
|
|
342
83
|
setLevel(level) {
|
|
343
84
|
log__namespace.setLevel(level);
|
|
344
85
|
}
|
|
345
|
-
|
|
346
86
|
static setLevel(level) {
|
|
347
87
|
log__namespace.setLevel(level);
|
|
348
88
|
}
|
|
349
89
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
350
|
-
|
|
351
|
-
|
|
352
90
|
trace() {
|
|
353
91
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
354
92
|
args[_key] = arguments[_key];
|
|
355
93
|
}
|
|
356
|
-
|
|
357
94
|
log__namespace.trace.apply(null, prepareLine(this.prefix + "T", args));
|
|
358
95
|
}
|
|
359
|
-
|
|
360
96
|
debug() {
|
|
361
97
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
362
98
|
args[_key2] = arguments[_key2];
|
|
363
99
|
}
|
|
364
|
-
|
|
365
100
|
log__namespace.debug.apply(null, prepareLine(this.prefix + "D", args));
|
|
366
101
|
}
|
|
367
|
-
|
|
368
102
|
info() {
|
|
369
103
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
370
104
|
args[_key3] = arguments[_key3];
|
|
371
105
|
}
|
|
372
|
-
|
|
373
106
|
log__namespace.info.apply(null, prepareLine(this.prefix + "I", args));
|
|
374
107
|
}
|
|
375
|
-
|
|
376
108
|
warn() {
|
|
377
109
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
378
110
|
args[_key4] = arguments[_key4];
|
|
379
111
|
}
|
|
380
|
-
|
|
381
112
|
log__namespace.warn.apply(null, prepareLine(this.prefix + "W", args));
|
|
382
113
|
}
|
|
383
|
-
|
|
384
114
|
error() {
|
|
385
115
|
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
386
116
|
args[_key5] = arguments[_key5];
|
|
387
117
|
}
|
|
388
|
-
|
|
389
118
|
log__namespace.error.apply(null, prepareLine(this.prefix + "E", args));
|
|
390
119
|
}
|
|
391
|
-
|
|
392
120
|
static trace() {
|
|
393
121
|
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
394
122
|
args[_key6] = arguments[_key6];
|
|
395
123
|
}
|
|
396
|
-
|
|
397
124
|
log__namespace.trace.apply(null, prepareLine("T", args));
|
|
398
125
|
}
|
|
399
|
-
|
|
400
126
|
static debug() {
|
|
401
127
|
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
402
128
|
args[_key7] = arguments[_key7];
|
|
403
129
|
}
|
|
404
|
-
|
|
405
130
|
log__namespace.debug.apply(null, prepareLine("D", args));
|
|
406
131
|
}
|
|
407
|
-
|
|
408
132
|
static info() {
|
|
409
133
|
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
410
134
|
args[_key8] = arguments[_key8];
|
|
411
135
|
}
|
|
412
|
-
|
|
413
136
|
log__namespace.info.apply(null, prepareLine("I", args));
|
|
414
137
|
}
|
|
415
|
-
|
|
416
138
|
static warn() {
|
|
417
139
|
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
418
140
|
args[_key9] = arguments[_key9];
|
|
419
141
|
}
|
|
420
|
-
|
|
421
142
|
log__namespace.warn.apply(null, prepareLine("W", args));
|
|
422
143
|
}
|
|
423
|
-
|
|
424
144
|
static error() {
|
|
425
145
|
for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
|
|
426
146
|
args[_key10] = arguments[_key10];
|
|
427
147
|
}
|
|
428
|
-
|
|
429
148
|
log__namespace.error.apply(null, prepareLine("E", args));
|
|
430
149
|
}
|
|
431
|
-
|
|
432
150
|
}
|
|
433
151
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
var isFullUrl = url => url.startsWith("http");
|
|
442
|
-
|
|
443
|
-
var fullUrl = (partUrl, region) => "".concat(!isFullUrl(partUrl) ? regionalMcsHost(region) : "").concat(partUrl);
|
|
444
|
-
|
|
152
|
+
const MINIMUM_RETRY_DELAY = 1000;
|
|
153
|
+
const MAXIMUM_RETRY_DELAY = 4000;
|
|
154
|
+
const MAXIMUM_ATTEMPTS_COUNT = 3;
|
|
155
|
+
const RETRY_WHEN_THROTTLED = true;
|
|
156
|
+
const regionalMcsHost = region => `https://mcs.${region ?? "us1"}.twilio.com`;
|
|
157
|
+
const isFullUrl = url => url.startsWith("http");
|
|
158
|
+
const fullUrl = (partUrl, region) => `${!isFullUrl(partUrl) ? regionalMcsHost(region) : ""}${partUrl}`;
|
|
445
159
|
class Configuration {
|
|
160
|
+
token;
|
|
161
|
+
retryWhenThrottledOverride;
|
|
162
|
+
backoffConfigOverride;
|
|
163
|
+
mediaUrl;
|
|
164
|
+
mediaSetUrl;
|
|
165
|
+
region;
|
|
446
166
|
constructor(token, baseUrl, baseSetUrl, options) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
var constructorOptions = (_ref = (_options$MCS = options.MCS) !== null && _options$MCS !== void 0 ? _options$MCS : options) !== null && _ref !== void 0 ? _ref : {};
|
|
450
|
-
this.region = (_ref2 = (_constructorOptions$r = constructorOptions.region) !== null && _constructorOptions$r !== void 0 ? _constructorOptions$r : options.region) !== null && _ref2 !== void 0 ? _ref2 : 'us1';
|
|
167
|
+
const constructorOptions = options.MCS ?? options ?? {};
|
|
168
|
+
this.region = constructorOptions.region ?? options.region ?? 'us1';
|
|
451
169
|
this.mediaUrl = fullUrl(baseUrl, this.region);
|
|
452
|
-
this.mediaSetUrl = baseSetUrl ? fullUrl(baseSetUrl) :
|
|
170
|
+
this.mediaSetUrl = baseSetUrl ? fullUrl(baseSetUrl) : `${this.mediaUrl}Set`;
|
|
453
171
|
this.token = token;
|
|
454
|
-
this.retryWhenThrottledOverride =
|
|
455
|
-
this.backoffConfigOverride =
|
|
172
|
+
this.retryWhenThrottledOverride = constructorOptions.retryWhenThrottledOverride ?? RETRY_WHEN_THROTTLED;
|
|
173
|
+
this.backoffConfigOverride = constructorOptions.backoffConfigOverride ?? Configuration.backoffConfigDefault;
|
|
456
174
|
}
|
|
457
|
-
|
|
458
175
|
static get backoffConfigDefault() {
|
|
459
176
|
return {
|
|
460
177
|
min: MINIMUM_RETRY_DELAY,
|
|
@@ -462,15 +179,12 @@ class Configuration {
|
|
|
462
179
|
maxAttemptsCount: MAXIMUM_ATTEMPTS_COUNT
|
|
463
180
|
};
|
|
464
181
|
}
|
|
465
|
-
|
|
466
182
|
static get retryWhenThrottledDefault() {
|
|
467
183
|
return RETRY_WHEN_THROTTLED;
|
|
468
184
|
}
|
|
469
|
-
|
|
470
185
|
updateToken(token) {
|
|
471
186
|
this.token = token;
|
|
472
187
|
}
|
|
473
|
-
|
|
474
188
|
}
|
|
475
189
|
|
|
476
190
|
/**
|
|
@@ -484,49 +198,40 @@ class Configuration {
|
|
|
484
198
|
* @property {String} fileName - file name, if present, null otherwise
|
|
485
199
|
* @property {MediaCategory} category - attachment category
|
|
486
200
|
*/
|
|
487
|
-
|
|
488
201
|
class Media {
|
|
202
|
+
state;
|
|
203
|
+
network;
|
|
204
|
+
config;
|
|
489
205
|
constructor(config, network, data) {
|
|
490
206
|
this.config = config;
|
|
491
207
|
this.network = network;
|
|
492
|
-
|
|
493
208
|
this._update(data);
|
|
494
209
|
}
|
|
495
|
-
|
|
496
210
|
get sid() {
|
|
497
211
|
return this.state.sid;
|
|
498
212
|
}
|
|
499
|
-
|
|
500
213
|
get serviceSid() {
|
|
501
214
|
return this.state.serviceSid;
|
|
502
215
|
}
|
|
503
|
-
|
|
504
216
|
get dateCreated() {
|
|
505
217
|
return this.state.dateCreated;
|
|
506
218
|
}
|
|
507
|
-
|
|
508
219
|
get dateUpdated() {
|
|
509
220
|
return this.state.dateUpdated;
|
|
510
221
|
}
|
|
511
|
-
|
|
512
222
|
get contentType() {
|
|
513
223
|
return this.state.contentType;
|
|
514
224
|
}
|
|
515
|
-
|
|
516
225
|
get size() {
|
|
517
226
|
return this.state.size;
|
|
518
227
|
}
|
|
519
228
|
/** @deprecated Use filename instead */
|
|
520
|
-
|
|
521
|
-
|
|
522
229
|
get fileName() {
|
|
523
230
|
return this.state.filename;
|
|
524
231
|
}
|
|
525
|
-
|
|
526
232
|
get filename() {
|
|
527
233
|
return this.state.filename;
|
|
528
234
|
}
|
|
529
|
-
|
|
530
235
|
get category() {
|
|
531
236
|
return this.state.category;
|
|
532
237
|
}
|
|
@@ -538,55 +243,20 @@ class Media {
|
|
|
538
243
|
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
539
244
|
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
540
245
|
*/
|
|
541
|
-
|
|
542
|
-
|
|
543
246
|
getContentUrl() {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
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;
|
|
566
|
-
break;
|
|
567
|
-
|
|
568
|
-
case 10:
|
|
569
|
-
_context.prev = 10;
|
|
570
|
-
_context.t0 = _context["catch"](2);
|
|
571
|
-
reject(_context.t0);
|
|
572
|
-
|
|
573
|
-
case 13:
|
|
574
|
-
case "end":
|
|
575
|
-
return _context.stop();
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}, _callee, null, [[2, 10]]);
|
|
579
|
-
}));
|
|
580
|
-
|
|
581
|
-
return function (_x, _x2, _x3) {
|
|
582
|
-
return _ref.apply(this, arguments);
|
|
583
|
-
};
|
|
584
|
-
}());
|
|
247
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
248
|
+
const request = this.network.get(`${this.config.mediaUrl}/${this.sid}`);
|
|
249
|
+
onCancel(() => request.cancel());
|
|
250
|
+
try {
|
|
251
|
+
const response = await request;
|
|
252
|
+
this._update(response.body);
|
|
253
|
+
resolve(this.state.contentDirectUrl);
|
|
254
|
+
} catch (e) {
|
|
255
|
+
reject(e);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
585
258
|
}
|
|
586
|
-
|
|
587
259
|
_update(data) {
|
|
588
|
-
var _data$links$content_d, _data$filename, _data$category, _data$is_multipart_up;
|
|
589
|
-
|
|
590
260
|
this.state = {
|
|
591
261
|
sid: data.sid,
|
|
592
262
|
serviceSid: data.service_sid,
|
|
@@ -600,16 +270,19 @@ class Media {
|
|
|
600
270
|
author: data.author,
|
|
601
271
|
url: data.url,
|
|
602
272
|
contentUrl: data.links.content,
|
|
603
|
-
contentDirectUrl:
|
|
604
|
-
filename:
|
|
605
|
-
category:
|
|
606
|
-
isMultipartUpstream:
|
|
273
|
+
contentDirectUrl: data.links.content_direct_temporary ?? null,
|
|
274
|
+
filename: data.filename ?? null,
|
|
275
|
+
category: data.category ?? "media",
|
|
276
|
+
isMultipartUpstream: data.is_multipart_upstream ?? false
|
|
607
277
|
};
|
|
608
278
|
}
|
|
609
|
-
|
|
610
279
|
}
|
|
611
280
|
|
|
612
281
|
class TransportError extends Error {
|
|
282
|
+
code;
|
|
283
|
+
body;
|
|
284
|
+
status;
|
|
285
|
+
headers;
|
|
613
286
|
constructor(message, code, body, status, headers) {
|
|
614
287
|
super(message);
|
|
615
288
|
this.code = code;
|
|
@@ -617,29 +290,25 @@ class TransportError extends Error {
|
|
|
617
290
|
this.status = status;
|
|
618
291
|
this.headers = headers;
|
|
619
292
|
}
|
|
620
|
-
|
|
621
293
|
}
|
|
622
294
|
|
|
623
|
-
|
|
624
|
-
|
|
295
|
+
const XHR =
|
|
296
|
+
// eslint-disable-next-line
|
|
297
|
+
global["XMLHttpRequest"] || require("xmlhttprequest").XMLHttpRequest;
|
|
625
298
|
function parseResponseHeaders(headerString) {
|
|
626
299
|
if (!headerString) {
|
|
627
300
|
return {};
|
|
628
301
|
}
|
|
629
|
-
|
|
630
|
-
return headerString.split("\r\n").map(el => el.split(": ")).filter(el => el.length === 2 && el[1].length > 0).reduce((prev, curr) => {
|
|
302
|
+
return headerString.split("\u000d\u000a").map(el => el.split("\u003a\u0020")).filter(el => el.length === 2 && el[1].length > 0).reduce((prev, curr) => {
|
|
631
303
|
prev[curr[0]] = curr[1];
|
|
632
304
|
return prev;
|
|
633
305
|
}, {});
|
|
634
306
|
}
|
|
635
|
-
|
|
636
307
|
function extractBody(xhr) {
|
|
637
|
-
|
|
638
|
-
|
|
308
|
+
const contentType = xhr.getResponseHeader("Content-Type");
|
|
639
309
|
if (!contentType || contentType.indexOf("application/json") !== 0 || xhr.responseText.length === 0) {
|
|
640
310
|
return xhr.responseText;
|
|
641
311
|
}
|
|
642
|
-
|
|
643
312
|
try {
|
|
644
313
|
return JSON.parse(xhr.responseText);
|
|
645
314
|
} catch (e) {
|
|
@@ -649,27 +318,22 @@ function extractBody(xhr) {
|
|
|
649
318
|
/**
|
|
650
319
|
* Provides generic network interface
|
|
651
320
|
*/
|
|
652
|
-
|
|
653
|
-
|
|
654
321
|
class Transport {
|
|
655
322
|
static request(method, url, headers, body) {
|
|
656
|
-
return new CancellablePromise((resolve, reject, onCancel) => {
|
|
657
|
-
|
|
658
|
-
|
|
323
|
+
return new shared.CancellablePromise((resolve, reject, onCancel) => {
|
|
324
|
+
const xhr = new XHR();
|
|
325
|
+
let isCancelled = false;
|
|
659
326
|
onCancel(() => {
|
|
660
327
|
xhr.abort();
|
|
661
328
|
isCancelled = true;
|
|
662
329
|
});
|
|
663
330
|
xhr.open(method, url, true);
|
|
664
|
-
|
|
665
331
|
xhr.onreadystatechange = function onreadystatechange() {
|
|
666
332
|
if (xhr.readyState !== 4 || isCancelled) {
|
|
667
333
|
return;
|
|
668
334
|
}
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
var body = extractBody(xhr);
|
|
672
|
-
|
|
335
|
+
const responseHeaders = parseResponseHeaders(xhr.getAllResponseHeaders());
|
|
336
|
+
const body = extractBody(xhr);
|
|
673
337
|
if (200 <= xhr.status && xhr.status < 300) {
|
|
674
338
|
resolve({
|
|
675
339
|
status: xhr.status,
|
|
@@ -677,300 +341,172 @@ class Transport {
|
|
|
677
341
|
body
|
|
678
342
|
});
|
|
679
343
|
} else {
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
var status = (_xhr$statusText = xhr.statusText) !== null && _xhr$statusText !== void 0 ? _xhr$statusText : "NONE";
|
|
683
|
-
var bodyRepresentation;
|
|
684
|
-
|
|
344
|
+
const status = xhr.statusText ?? "NONE";
|
|
345
|
+
let bodyRepresentation;
|
|
685
346
|
if (typeof body === "string") {
|
|
686
347
|
if (body && body.split("\n", 2).length === 1) bodyRepresentation = body;else {
|
|
687
|
-
var _body$replace$split$f;
|
|
688
|
-
|
|
689
348
|
// TODO: RTDSDK-3716: investigate why body is HTML string
|
|
690
|
-
|
|
691
|
-
bodyRepresentation =
|
|
349
|
+
const errorInfo = body.replace(/<.*?>/g, "").split(/\r\n/g).filter(str => str.length)[0]?.split(" ");
|
|
350
|
+
bodyRepresentation = errorInfo?.length > 2 ? errorInfo?.slice(1).join(" ") : "";
|
|
692
351
|
}
|
|
693
352
|
} else {
|
|
694
353
|
bodyRepresentation = JSON.stringify(body);
|
|
695
354
|
}
|
|
696
|
-
|
|
697
|
-
var message = "".concat(xhr.status, ": [").concat(status, "] ").concat(bodyRepresentation);
|
|
355
|
+
const message = `${xhr.status}: [${status}] ${bodyRepresentation}`;
|
|
698
356
|
reject(new TransportError(message, xhr.status, body, status, responseHeaders));
|
|
699
357
|
}
|
|
700
358
|
};
|
|
701
|
-
|
|
702
|
-
for (var headerName in headers) {
|
|
359
|
+
for (const headerName in headers) {
|
|
703
360
|
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
704
|
-
|
|
705
361
|
if (headerName === "Content-Type" && headers[headerName] === "application/json") {
|
|
706
362
|
body = JSON.stringify(body);
|
|
707
363
|
}
|
|
708
364
|
}
|
|
709
|
-
|
|
710
365
|
xhr.send(body);
|
|
711
366
|
});
|
|
712
367
|
}
|
|
713
368
|
/**
|
|
714
369
|
* Make a GET request by given URL
|
|
715
370
|
*/
|
|
716
|
-
|
|
717
|
-
|
|
718
371
|
get(url, headers) {
|
|
719
372
|
return Transport.request("GET", url, headers);
|
|
720
373
|
}
|
|
721
374
|
/**
|
|
722
375
|
* Make a POST request by given URL
|
|
723
376
|
*/
|
|
724
|
-
|
|
725
|
-
|
|
726
377
|
post(url, headers, body) {
|
|
727
378
|
return Transport.request("POST", url, headers, body);
|
|
728
379
|
}
|
|
729
|
-
|
|
730
380
|
}
|
|
731
381
|
|
|
732
|
-
|
|
733
|
-
|
|
382
|
+
const log$1 = Logger.scope("Network");
|
|
734
383
|
class Network {
|
|
384
|
+
config;
|
|
385
|
+
transport;
|
|
735
386
|
constructor(config, transport) {
|
|
736
387
|
this.config = config;
|
|
737
388
|
this.transport = transport;
|
|
738
389
|
}
|
|
739
|
-
|
|
740
390
|
backoffConfig() {
|
|
741
391
|
return Object.assign(Configuration.backoffConfigDefault, this.config.backoffConfigOverride);
|
|
742
392
|
}
|
|
743
|
-
|
|
744
393
|
retryWhenThrottled() {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
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;
|
|
394
|
+
return this.config.retryWhenThrottledOverride ?? Configuration.retryWhenThrottledDefault ?? false;
|
|
748
395
|
}
|
|
749
|
-
|
|
750
396
|
executeWithRetry(request, retryWhenThrottled) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
retrier.removeAllListeners();
|
|
783
|
-
});
|
|
784
|
-
_context.next = 5;
|
|
785
|
-
return requestPromise;
|
|
786
|
-
|
|
787
|
-
case 5:
|
|
788
|
-
result = _context.sent;
|
|
789
|
-
retrier.succeeded(result);
|
|
790
|
-
_context.next = 12;
|
|
791
|
-
break;
|
|
792
|
-
|
|
793
|
-
case 9:
|
|
794
|
-
_context.prev = 9;
|
|
795
|
-
_context.t0 = _context["catch"](0);
|
|
796
|
-
|
|
797
|
-
if (codesToRetryOn.indexOf(_context.t0.status) > -1) {
|
|
798
|
-
retrier.failed(_context.t0);
|
|
799
|
-
} else if (_context.t0.message === "Twilsock disconnected") {
|
|
800
|
-
// Ugly hack. We must make a proper exceptions for twilsock
|
|
801
|
-
retrier.failed(_context.t0);
|
|
802
|
-
} else {
|
|
803
|
-
// Fatal error
|
|
804
|
-
retrier.removeAllListeners();
|
|
805
|
-
retrier.cancel();
|
|
806
|
-
reject(_context.t0);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
case 12:
|
|
810
|
-
case "end":
|
|
811
|
-
return _context.stop();
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
}, _callee, null, [[0, 9]]);
|
|
815
|
-
})));
|
|
816
|
-
retrier.on("succeeded", result => {
|
|
817
|
-
resolve(result);
|
|
818
|
-
});
|
|
819
|
-
retrier.on("cancelled", err => reject(err));
|
|
820
|
-
retrier.on("failed", err => reject(err));
|
|
821
|
-
retrier.start();
|
|
822
|
-
|
|
823
|
-
case 9:
|
|
824
|
-
case "end":
|
|
825
|
-
return _context2.stop();
|
|
826
|
-
}
|
|
397
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
398
|
+
const retrier = new operationRetrier.Retrier(this.backoffConfig());
|
|
399
|
+
const codesToRetryOn = [502, 503, 504];
|
|
400
|
+
if (retryWhenThrottled) {
|
|
401
|
+
codesToRetryOn.push(429);
|
|
402
|
+
}
|
|
403
|
+
onCancel(() => {
|
|
404
|
+
retrier.cancel();
|
|
405
|
+
retrier.removeAllListeners();
|
|
406
|
+
});
|
|
407
|
+
retrier.on("attempt", async () => {
|
|
408
|
+
try {
|
|
409
|
+
const requestPromise = request();
|
|
410
|
+
onCancel(() => {
|
|
411
|
+
requestPromise.cancel();
|
|
412
|
+
retrier.cancel();
|
|
413
|
+
retrier.removeAllListeners();
|
|
414
|
+
});
|
|
415
|
+
const result = await requestPromise;
|
|
416
|
+
retrier.succeeded(result);
|
|
417
|
+
} catch (err) {
|
|
418
|
+
if (codesToRetryOn.indexOf(err.status) > -1) {
|
|
419
|
+
retrier.failed(err);
|
|
420
|
+
} else if (err.message === "Twilsock disconnected") {
|
|
421
|
+
// Ugly hack. We must make a proper exceptions for twilsock
|
|
422
|
+
retrier.failed(err);
|
|
423
|
+
} else {
|
|
424
|
+
// Fatal error
|
|
425
|
+
retrier.removeAllListeners();
|
|
426
|
+
retrier.cancel();
|
|
427
|
+
reject(err);
|
|
827
428
|
}
|
|
828
|
-
}
|
|
829
|
-
})
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
retrier.on("succeeded", result => {
|
|
432
|
+
resolve(result);
|
|
433
|
+
});
|
|
434
|
+
retrier.on("cancelled", err => reject(err));
|
|
435
|
+
retrier.on("failed", err => reject(err));
|
|
436
|
+
retrier.start();
|
|
437
|
+
});
|
|
835
438
|
}
|
|
836
|
-
|
|
837
439
|
get(url) {
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
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
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}, _callee3, null, [[4, 12]]);
|
|
876
|
-
}));
|
|
877
|
-
|
|
878
|
-
return function (_x4, _x5, _x6) {
|
|
879
|
-
return _ref4.apply(this, arguments);
|
|
440
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
441
|
+
const headers = {
|
|
442
|
+
"X-Twilio-Token": this.config.token
|
|
880
443
|
};
|
|
881
|
-
|
|
444
|
+
const request = this.executeWithRetry(() => this.transport.get(url, headers), this.retryWhenThrottled());
|
|
445
|
+
log$1.trace("sending GET request to ", url, " headers ", headers);
|
|
446
|
+
onCancel(() => request.cancel());
|
|
447
|
+
try {
|
|
448
|
+
const response = await request;
|
|
449
|
+
log$1.trace("response", response);
|
|
450
|
+
resolve(response);
|
|
451
|
+
} catch (err) {
|
|
452
|
+
log$1.debug(`get() error ${err}`);
|
|
453
|
+
reject(err);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
882
456
|
}
|
|
883
|
-
|
|
884
457
|
post(url, category, media, contentType, filename) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
var headers = {
|
|
458
|
+
const headers = {
|
|
888
459
|
"X-Twilio-Token": this.config.token
|
|
889
460
|
};
|
|
890
|
-
|
|
891
461
|
if ((typeof FormData === "undefined" || !(media instanceof FormData)) && contentType) {
|
|
892
462
|
Object.assign(headers, {
|
|
893
463
|
"Content-Type": contentType
|
|
894
464
|
});
|
|
895
465
|
}
|
|
896
|
-
|
|
897
|
-
var fullUrl = new URL(url);
|
|
898
|
-
|
|
466
|
+
const fullUrl = new URL(url);
|
|
899
467
|
if (category) {
|
|
900
468
|
fullUrl.searchParams.append("Category", category);
|
|
901
469
|
}
|
|
902
|
-
|
|
903
470
|
if (filename) {
|
|
904
471
|
fullUrl.searchParams.append("Filename", filename);
|
|
905
472
|
}
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
_context4.prev = 9;
|
|
928
|
-
_context4.t0 = _context4["catch"](3);
|
|
929
|
-
|
|
930
|
-
if (!(global["XMLHttpRequest"] === undefined && media instanceof FormData)) {
|
|
931
|
-
_context4.next = 14;
|
|
932
|
-
break;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
reject(new TypeError("Posting FormData supported only with browser engine's FormData"));
|
|
936
|
-
return _context4.abrupt("return");
|
|
937
|
-
|
|
938
|
-
case 14:
|
|
939
|
-
log$1.debug("post() error ".concat(_context4.t0));
|
|
940
|
-
reject(_context4.t0);
|
|
941
|
-
return _context4.abrupt("return");
|
|
942
|
-
|
|
943
|
-
case 17:
|
|
944
|
-
log$1.trace("response", response);
|
|
945
|
-
resolve(response);
|
|
946
|
-
|
|
947
|
-
case 19:
|
|
948
|
-
case "end":
|
|
949
|
-
return _context4.stop();
|
|
950
|
-
}
|
|
951
|
-
}
|
|
952
|
-
}, _callee4, null, [[3, 9]]);
|
|
953
|
-
}));
|
|
954
|
-
|
|
955
|
-
return function (_x7, _x8, _x9) {
|
|
956
|
-
return _ref5.apply(this, arguments);
|
|
957
|
-
};
|
|
958
|
-
}());
|
|
473
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
474
|
+
const request = this.transport.post(fullUrl.href, headers, media);
|
|
475
|
+
onCancel(() => request.cancel());
|
|
476
|
+
log$1.trace(`sending POST request to ${url} with headers ${headers}`);
|
|
477
|
+
let response;
|
|
478
|
+
try {
|
|
479
|
+
response = await request;
|
|
480
|
+
} catch (err) {
|
|
481
|
+
// If global["XMLHttpRequest"] is undefined, it means that the code is
|
|
482
|
+
// not being executed in the browser.
|
|
483
|
+
if (global["XMLHttpRequest"] === undefined && media instanceof FormData) {
|
|
484
|
+
reject(new TypeError("Posting FormData supported only with browser engine's FormData"));
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
log$1.debug(`post() error ${err}`);
|
|
488
|
+
reject(err);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
log$1.trace("response", response);
|
|
492
|
+
resolve(response);
|
|
493
|
+
});
|
|
959
494
|
}
|
|
960
|
-
|
|
961
495
|
}
|
|
962
496
|
|
|
963
|
-
var version = "0.
|
|
497
|
+
var version = "1.0.0-rc.3";
|
|
964
498
|
|
|
965
|
-
|
|
966
|
-
var log = Logger.scope("");
|
|
499
|
+
const log = Logger.scope("");
|
|
967
500
|
/**
|
|
968
501
|
* @classdesc A Client provides an interface for Media Content Service
|
|
969
502
|
*/
|
|
970
|
-
|
|
971
|
-
exports["default"] = (_class = class Client {
|
|
503
|
+
exports["default"] = class Client {
|
|
972
504
|
// eslint-disable-next-line
|
|
973
|
-
|
|
505
|
+
transport;
|
|
506
|
+
options;
|
|
507
|
+
network;
|
|
508
|
+
config;
|
|
509
|
+
static version = version;
|
|
974
510
|
/**
|
|
975
511
|
* Base URLs must be full URLs with host. If host is not provided it will be generated from a default configuration
|
|
976
512
|
* template using options.region.
|
|
@@ -981,14 +517,12 @@ exports["default"] = (_class = class Client {
|
|
|
981
517
|
* @param {Client#ClientOptions} [options] - Options to customize the Client
|
|
982
518
|
*/
|
|
983
519
|
constructor(token, baseUrl, baseSetUrl) {
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
520
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
987
521
|
this.options = options;
|
|
988
|
-
this.options.logLevel =
|
|
522
|
+
this.options.logLevel = this.options.logLevel ?? "silent";
|
|
989
523
|
this.config = new Configuration(token, baseUrl, baseSetUrl, this.options);
|
|
990
524
|
log.setLevel(this.options.logLevel);
|
|
991
|
-
this.options.transport =
|
|
525
|
+
this.options.transport = this.options.transport ?? new Transport();
|
|
992
526
|
this.transport = this.options.transport;
|
|
993
527
|
this.network = new Network(this.config, this.transport);
|
|
994
528
|
}
|
|
@@ -998,14 +532,11 @@ exports["default"] = (_class = class Client {
|
|
|
998
532
|
* @property {String} [logLevel='silent'] - The level of logging to enable. Valid options
|
|
999
533
|
* (from strictest to broadest): ['silent', 'error', 'warn', 'info', 'debug', 'trace']
|
|
1000
534
|
*/
|
|
1001
|
-
|
|
1002
535
|
/**
|
|
1003
536
|
* Update the token used for Client operations
|
|
1004
537
|
* @param {String} token - The JWT string of the new token
|
|
1005
538
|
* @returns {void}
|
|
1006
539
|
*/
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
540
|
updateToken(token) {
|
|
1010
541
|
log.info("updateToken");
|
|
1011
542
|
this.config.updateToken(token);
|
|
@@ -1014,47 +545,17 @@ exports["default"] = (_class = class Client {
|
|
|
1014
545
|
* Gets media from media service
|
|
1015
546
|
* @param {String} sid - Media's SID
|
|
1016
547
|
*/
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
548
|
get(sid) {
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
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
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
}, _callee, null, [[2, 9]]);
|
|
1052
|
-
}));
|
|
1053
|
-
|
|
1054
|
-
return function (_x, _x2, _x3) {
|
|
1055
|
-
return _ref.apply(this, arguments);
|
|
1056
|
-
};
|
|
1057
|
-
}());
|
|
549
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
550
|
+
const request = this.network.get(`${this.config.mediaUrl}/${sid}`);
|
|
551
|
+
onCancel(() => request.cancel());
|
|
552
|
+
try {
|
|
553
|
+
const response = await request;
|
|
554
|
+
resolve(new Media(this.config, this.network, response.body));
|
|
555
|
+
} catch (e) {
|
|
556
|
+
reject(e);
|
|
557
|
+
}
|
|
558
|
+
});
|
|
1058
559
|
}
|
|
1059
560
|
/**
|
|
1060
561
|
* Posts raw content to media service
|
|
@@ -1062,47 +563,17 @@ exports["default"] = (_class = class Client {
|
|
|
1062
563
|
* @param {String|Buffer|Blob} media - content to post
|
|
1063
564
|
* @param {MediaCategory|null} category - category for the media
|
|
1064
565
|
*/
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
566
|
post(contentType, media, category, filename) {
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
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
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
}, _callee2, null, [[2, 9]]);
|
|
1100
|
-
}));
|
|
1101
|
-
|
|
1102
|
-
return function (_x4, _x5, _x6) {
|
|
1103
|
-
return _ref2.apply(this, arguments);
|
|
1104
|
-
};
|
|
1105
|
-
}());
|
|
567
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
568
|
+
const request = this.network.post(this.config.mediaUrl, category ?? "media", media, contentType, filename);
|
|
569
|
+
onCancel(() => request.cancel());
|
|
570
|
+
try {
|
|
571
|
+
const response = await request;
|
|
572
|
+
resolve(new Media(this.config, this.network, response.body));
|
|
573
|
+
} catch (e) {
|
|
574
|
+
reject(e);
|
|
575
|
+
}
|
|
576
|
+
});
|
|
1106
577
|
}
|
|
1107
578
|
/**
|
|
1108
579
|
* Posts FormData to media service. Can be used only with browser engine's FormData.
|
|
@@ -1111,179 +582,86 @@ exports["default"] = (_class = class Client {
|
|
|
1111
582
|
* @param {FormData} formData - form data to post
|
|
1112
583
|
* @param {MediaCategory|null} category - category for the media
|
|
1113
584
|
*/
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
585
|
postFormData(formData, category) {
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
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
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}, _callee3, null, [[2, 9]]);
|
|
1149
|
-
}));
|
|
1150
|
-
|
|
1151
|
-
return function (_x7, _x8, _x9) {
|
|
1152
|
-
return _ref3.apply(this, arguments);
|
|
1153
|
-
};
|
|
1154
|
-
}());
|
|
586
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
587
|
+
const request = this.network.post(this.config.mediaUrl, category ?? "media", formData);
|
|
588
|
+
onCancel(() => request.cancel());
|
|
589
|
+
try {
|
|
590
|
+
const response = await request;
|
|
591
|
+
resolve(new Media(this.config, this.network, response.body));
|
|
592
|
+
} catch (e) {
|
|
593
|
+
reject(e);
|
|
594
|
+
}
|
|
595
|
+
});
|
|
1155
596
|
}
|
|
1156
597
|
/**
|
|
1157
598
|
* Retrieve information about multiple media SIDs at the same time.
|
|
1158
599
|
* @param mediaSids Array of Media SIDs to get information from.
|
|
1159
600
|
*/
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
601
|
mediaSetGet(mediaSids) {
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
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
|
-
}
|
|
1191
|
-
|
|
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);
|
|
1202
|
-
|
|
1203
|
-
case 14:
|
|
1204
|
-
case "end":
|
|
1205
|
-
return _context4.stop();
|
|
1206
|
-
}
|
|
1207
|
-
}
|
|
1208
|
-
}, _callee4, null, [[3, 11]]);
|
|
1209
|
-
}));
|
|
1210
|
-
|
|
1211
|
-
return function (_x10, _x11, _x12) {
|
|
1212
|
-
return _ref4.apply(this, arguments);
|
|
602
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
603
|
+
const query = {
|
|
604
|
+
command: "get",
|
|
605
|
+
list: mediaSids.map(sid => ({
|
|
606
|
+
media_sid: sid
|
|
607
|
+
}))
|
|
1213
608
|
};
|
|
1214
|
-
|
|
609
|
+
const request = this.network.post(`${this.config.mediaSetUrl}`, null, query, "application/json");
|
|
610
|
+
onCancel(() => request.cancel());
|
|
611
|
+
try {
|
|
612
|
+
const response = await request;
|
|
613
|
+
const media = response.body.map(item => {
|
|
614
|
+
if (item.code !== 200) {
|
|
615
|
+
reject(`Failed to obtain detailed information about Media items (failed SID ${item.media_record.sid})`);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
return new Media(this.config, this.network, item.media_record);
|
|
619
|
+
});
|
|
620
|
+
resolve(media);
|
|
621
|
+
} catch (e) {
|
|
622
|
+
reject(e);
|
|
623
|
+
}
|
|
624
|
+
});
|
|
1215
625
|
}
|
|
1216
626
|
/**
|
|
1217
627
|
* Retrieve temporary URLs for a set of media SIDs.
|
|
1218
628
|
* @param mediaSids array of the media SIDs to get URLs from.
|
|
1219
629
|
*/
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
630
|
mediaSetGetContentUrls(mediaSids) {
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
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);
|
|
631
|
+
return new shared.CancellablePromise(async (resolve, reject, onCancel) => {
|
|
632
|
+
const query = {
|
|
633
|
+
command: "get",
|
|
634
|
+
list: mediaSids.map(sid => ({
|
|
635
|
+
media_sid: sid
|
|
636
|
+
}))
|
|
1274
637
|
};
|
|
1275
|
-
|
|
638
|
+
const request = this.network.post(`${this.config.mediaSetUrl}`, null, query, "application/json");
|
|
639
|
+
onCancel(() => request.cancel());
|
|
640
|
+
try {
|
|
641
|
+
const response = await request;
|
|
642
|
+
const urls = new Map();
|
|
643
|
+
response.body.forEach(item => {
|
|
644
|
+
if (item.code !== 200) {
|
|
645
|
+
reject(`Failed to obtain detailed information about Media items (failed SID ${item.media_record.sid})`);
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
urls.set(item.media_record.sid, item.media_record.links.content_direct_temporary);
|
|
649
|
+
});
|
|
650
|
+
resolve(urls);
|
|
651
|
+
} catch (e) {
|
|
652
|
+
reject(e);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
1276
655
|
}
|
|
1277
|
-
|
|
1278
|
-
}, _defineProperty__default["default"](_class, "version", version), _class);
|
|
1279
|
-
|
|
656
|
+
};
|
|
1280
657
|
__decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0)], exports["default"].prototype, "updateToken", null);
|
|
658
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", shared.CancellablePromise)], exports["default"].prototype, "get", null);
|
|
659
|
+
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"]);
|
|
1281
660
|
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
exports.CancellablePromise = CancellablePromise;
|
|
661
|
+
Object.defineProperty(exports, 'CancellablePromise', {
|
|
662
|
+
enumerable: true,
|
|
663
|
+
get: function () { return shared.CancellablePromise; }
|
|
664
|
+
});
|
|
1287
665
|
exports.Client = exports["default"];
|
|
1288
666
|
exports.McsClient = exports["default"];
|
|
1289
667
|
exports.McsMedia = Media;
|