@twilio/mcs-client 0.6.4-rc.1 → 0.6.4
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 +917 -765
- package/builds/browser.js.map +1 -1
- package/builds/lib.js +917 -765
- package/builds/lib.js.map +1 -1
- package/builds/twilio-mcs-client.js +10818 -10602
- package/builds/twilio-mcs-client.min.js +1 -31
- package/dist/packages/mcs-client/package.json.js +1 -1
- package/package.json +17 -4
package/builds/lib.js
CHANGED
|
@@ -19,22 +19,37 @@ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
19
19
|
|
|
20
20
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
21
21
|
|
|
22
|
+
require('core-js/modules/es.reflect.to-string-tag.js');
|
|
23
|
+
require('core-js/modules/es.reflect.construct.js');
|
|
24
|
+
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
25
|
+
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
26
|
+
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
27
|
+
var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
|
|
28
|
+
var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
|
|
29
|
+
var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
|
|
22
30
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
31
|
+
require('core-js/modules/es.object.to-string.js');
|
|
23
32
|
require('core-js/modules/es.promise.js');
|
|
24
33
|
require('core-js/modules/es.array.iterator.js');
|
|
25
34
|
require('core-js/modules/es.map.js');
|
|
35
|
+
require('core-js/modules/es.string.iterator.js');
|
|
26
36
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
27
37
|
var require$$0 = require('crypto');
|
|
28
38
|
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
29
|
-
require('core-js/modules/web.dom-collections.for-each.js');
|
|
30
39
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
40
|
+
require('core-js/modules/es.array.concat.js');
|
|
41
|
+
require('core-js/modules/es.array.map.js');
|
|
42
|
+
require('core-js/modules/web.dom-collections.for-each.js');
|
|
43
|
+
var _typeof = require('@babel/runtime/helpers/typeof');
|
|
31
44
|
require('core-js/modules/es.array.from.js');
|
|
32
45
|
var log$2 = require('loglevel');
|
|
33
46
|
require('core-js/modules/es.string.starts-with.js');
|
|
34
|
-
require('core-js/modules/es.array.
|
|
47
|
+
require('core-js/modules/es.array.filter.js');
|
|
35
48
|
require('core-js/modules/es.regexp.exec.js');
|
|
36
49
|
require('core-js/modules/es.string.split.js');
|
|
37
50
|
require('core-js/modules/es.string.replace.js');
|
|
51
|
+
require('core-js/modules/es.array.join.js');
|
|
52
|
+
require('core-js/modules/es.array.slice.js');
|
|
38
53
|
require('core-js/modules/es.json.stringify.js');
|
|
39
54
|
require('core-js/modules/es.object.assign.js');
|
|
40
55
|
require('core-js/modules/web.url.js');
|
|
@@ -62,10 +77,17 @@ function _interopNamespace(e) {
|
|
|
62
77
|
return Object.freeze(n);
|
|
63
78
|
}
|
|
64
79
|
|
|
80
|
+
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
81
|
+
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
82
|
+
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
83
|
+
var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
|
|
84
|
+
var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
|
|
85
|
+
var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
|
|
65
86
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
66
87
|
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
67
88
|
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
68
89
|
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
90
|
+
var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
|
|
69
91
|
var log__namespace = /*#__PURE__*/_interopNamespace(log$2);
|
|
70
92
|
|
|
71
93
|
// this is pretty straight-forward - we use the crypto API.
|
|
@@ -226,6 +248,9 @@ uuid.v1 = v1;
|
|
|
226
248
|
uuid.v4 = v4;
|
|
227
249
|
var uuid_1 = uuid;
|
|
228
250
|
|
|
251
|
+
function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
252
|
+
|
|
253
|
+
function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
229
254
|
/**
|
|
230
255
|
* Cancellable promise. Extends the functionality of the native Promise to include the cancel method.
|
|
231
256
|
*
|
|
@@ -250,7 +275,11 @@ var uuid_1 = uuid;
|
|
|
250
275
|
* ```
|
|
251
276
|
*/
|
|
252
277
|
|
|
253
|
-
|
|
278
|
+
var CancellablePromise = /*#__PURE__*/function (_Promise) {
|
|
279
|
+
_inherits__default["default"](CancellablePromise, _Promise);
|
|
280
|
+
|
|
281
|
+
var _super = _createSuper$1(CancellablePromise);
|
|
282
|
+
|
|
254
283
|
/**
|
|
255
284
|
* Creates a new CancellablePromise.
|
|
256
285
|
* @param executor A callback used to initialize the promise. This callback is passed three arguments:
|
|
@@ -258,194 +287,217 @@ class CancellablePromise extends Promise {
|
|
|
258
287
|
* a reject callback used to reject the promise with a provided reason or error,
|
|
259
288
|
* and an onCancel callback used to define behavior of cancellation.
|
|
260
289
|
*/
|
|
261
|
-
|
|
290
|
+
function CancellablePromise(executor) {
|
|
291
|
+
var _this;
|
|
292
|
+
|
|
293
|
+
_classCallCheck__default["default"](this, CancellablePromise);
|
|
294
|
+
|
|
262
295
|
var outerId = uuid_1.v4();
|
|
263
296
|
var outerRejectPromise;
|
|
264
|
-
|
|
297
|
+
_this = _super.call(this, function (resolve, reject) {
|
|
265
298
|
outerRejectPromise = reject;
|
|
266
|
-
return executor(value
|
|
299
|
+
return executor(function (value) {
|
|
267
300
|
CancellablePromise.cancellationMap.delete(outerId);
|
|
268
301
|
resolve(value);
|
|
269
|
-
}, reason
|
|
302
|
+
}, function (reason) {
|
|
270
303
|
CancellablePromise.cancellationMap.delete(outerId);
|
|
271
304
|
reject(reason);
|
|
272
|
-
}, cancellationFunction
|
|
305
|
+
}, function (cancellationFunction) {
|
|
273
306
|
CancellablePromise.cancellationMap.set(outerId, cancellationFunction);
|
|
274
307
|
});
|
|
275
308
|
});
|
|
276
|
-
|
|
277
|
-
|
|
309
|
+
_this.id = outerId;
|
|
310
|
+
_this.rejectPromise = outerRejectPromise;
|
|
311
|
+
return _this;
|
|
278
312
|
}
|
|
279
313
|
/**
|
|
280
314
|
* Cancels the promise and invokes the cancellation callback if it was defined during instantiation. Cancellation will result in the promise being rejected.
|
|
281
315
|
*/
|
|
282
316
|
|
|
283
317
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
318
|
+
_createClass__default["default"](CancellablePromise, [{
|
|
319
|
+
key: "cancel",
|
|
320
|
+
value: function cancel() {
|
|
321
|
+
var onCancel = CancellablePromise.cancellationMap.get(this.id);
|
|
322
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel();
|
|
287
323
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
324
|
+
if (this.rejectPromise) {
|
|
325
|
+
this.catch(function () {
|
|
326
|
+
return void 0;
|
|
327
|
+
});
|
|
328
|
+
this.rejectPromise(new Error("Promise was cancelled"));
|
|
329
|
+
}
|
|
292
330
|
|
|
293
|
-
|
|
294
|
-
|
|
331
|
+
return this;
|
|
332
|
+
}
|
|
333
|
+
}]);
|
|
295
334
|
|
|
296
|
-
|
|
335
|
+
return CancellablePromise;
|
|
336
|
+
}( /*#__PURE__*/_wrapNativeSuper__default["default"](Promise));
|
|
297
337
|
|
|
298
338
|
_defineProperty__default["default"](CancellablePromise, "cancellationMap", new Map());
|
|
299
339
|
|
|
300
|
-
/******************************************************************************
|
|
301
|
-
Copyright (c) Microsoft Corporation.
|
|
302
|
-
|
|
303
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
304
|
-
purpose with or without fee is hereby granted.
|
|
305
|
-
|
|
306
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
307
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
308
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
309
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
310
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
311
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
312
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
313
|
-
***************************************************************************** */
|
|
314
340
|
function __decorate(decorators, target, key, desc) {
|
|
315
341
|
var c = arguments.length,
|
|
316
342
|
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
317
343
|
d;
|
|
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--) {
|
|
344
|
+
if ((typeof Reflect === "undefined" ? "undefined" : _typeof__default["default"](Reflect)) === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
|
|
319
345
|
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
320
346
|
}
|
|
321
347
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
322
348
|
}
|
|
323
349
|
function __metadata(metadataKey, metadataValue) {
|
|
324
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
350
|
+
if ((typeof Reflect === "undefined" ? "undefined" : _typeof__default["default"](Reflect)) === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
|
325
351
|
}
|
|
326
352
|
|
|
327
353
|
function prepareLine(prefix, args) {
|
|
328
354
|
return ["".concat(new Date().toISOString(), " MCS Client ").concat(prefix, ":")].concat(Array.from(args));
|
|
329
355
|
}
|
|
330
356
|
|
|
331
|
-
|
|
332
|
-
|
|
357
|
+
var Logger = /*#__PURE__*/function () {
|
|
358
|
+
function Logger(prefix) {
|
|
359
|
+
_classCallCheck__default["default"](this, Logger);
|
|
360
|
+
|
|
333
361
|
_defineProperty__default["default"](this, "prefix", "");
|
|
334
362
|
|
|
335
363
|
this.prefix = prefix !== null && prefix !== undefined && prefix.length > 0 ? prefix + " " : "";
|
|
336
364
|
}
|
|
337
365
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
setLevel(level) {
|
|
343
|
-
log__namespace.setLevel(level);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
static setLevel(level) {
|
|
347
|
-
log__namespace.setLevel(level);
|
|
348
|
-
}
|
|
349
|
-
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
trace() {
|
|
353
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
354
|
-
args[_key] = arguments[_key];
|
|
366
|
+
_createClass__default["default"](Logger, [{
|
|
367
|
+
key: "setLevel",
|
|
368
|
+
value: function setLevel(level) {
|
|
369
|
+
log__namespace.setLevel(level);
|
|
355
370
|
}
|
|
371
|
+
}, {
|
|
372
|
+
key: "trace",
|
|
373
|
+
value:
|
|
374
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
375
|
+
function trace() {
|
|
376
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
377
|
+
args[_key] = arguments[_key];
|
|
378
|
+
}
|
|
356
379
|
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
debug() {
|
|
361
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
362
|
-
args[_key2] = arguments[_key2];
|
|
380
|
+
log__namespace.trace.apply(null, prepareLine(this.prefix + "T", args));
|
|
363
381
|
}
|
|
382
|
+
}, {
|
|
383
|
+
key: "debug",
|
|
384
|
+
value: function debug() {
|
|
385
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
386
|
+
args[_key2] = arguments[_key2];
|
|
387
|
+
}
|
|
364
388
|
|
|
365
|
-
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
info() {
|
|
369
|
-
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
370
|
-
args[_key3] = arguments[_key3];
|
|
389
|
+
log__namespace.debug.apply(null, prepareLine(this.prefix + "D", args));
|
|
371
390
|
}
|
|
391
|
+
}, {
|
|
392
|
+
key: "info",
|
|
393
|
+
value: function info() {
|
|
394
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
395
|
+
args[_key3] = arguments[_key3];
|
|
396
|
+
}
|
|
372
397
|
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
warn() {
|
|
377
|
-
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
378
|
-
args[_key4] = arguments[_key4];
|
|
398
|
+
log__namespace.info.apply(null, prepareLine(this.prefix + "I", args));
|
|
379
399
|
}
|
|
400
|
+
}, {
|
|
401
|
+
key: "warn",
|
|
402
|
+
value: function warn() {
|
|
403
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
404
|
+
args[_key4] = arguments[_key4];
|
|
405
|
+
}
|
|
380
406
|
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
error() {
|
|
385
|
-
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
386
|
-
args[_key5] = arguments[_key5];
|
|
407
|
+
log__namespace.warn.apply(null, prepareLine(this.prefix + "W", args));
|
|
387
408
|
}
|
|
409
|
+
}, {
|
|
410
|
+
key: "error",
|
|
411
|
+
value: function error() {
|
|
412
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
413
|
+
args[_key5] = arguments[_key5];
|
|
414
|
+
}
|
|
388
415
|
|
|
389
|
-
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
static trace() {
|
|
393
|
-
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
394
|
-
args[_key6] = arguments[_key6];
|
|
416
|
+
log__namespace.error.apply(null, prepareLine(this.prefix + "E", args));
|
|
395
417
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
static debug() {
|
|
401
|
-
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
402
|
-
args[_key7] = arguments[_key7];
|
|
418
|
+
}], [{
|
|
419
|
+
key: "scope",
|
|
420
|
+
value: function scope(prefix) {
|
|
421
|
+
return new Logger(prefix);
|
|
403
422
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
static info() {
|
|
409
|
-
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
410
|
-
args[_key8] = arguments[_key8];
|
|
423
|
+
}, {
|
|
424
|
+
key: "setLevel",
|
|
425
|
+
value: function setLevel(level) {
|
|
426
|
+
log__namespace.setLevel(level);
|
|
411
427
|
}
|
|
428
|
+
}, {
|
|
429
|
+
key: "trace",
|
|
430
|
+
value: function trace() {
|
|
431
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
432
|
+
args[_key6] = arguments[_key6];
|
|
433
|
+
}
|
|
412
434
|
|
|
413
|
-
|
|
414
|
-
|
|
435
|
+
log__namespace.trace.apply(null, prepareLine("T", args));
|
|
436
|
+
}
|
|
437
|
+
}, {
|
|
438
|
+
key: "debug",
|
|
439
|
+
value: function debug() {
|
|
440
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
441
|
+
args[_key7] = arguments[_key7];
|
|
442
|
+
}
|
|
415
443
|
|
|
416
|
-
|
|
417
|
-
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
418
|
-
args[_key9] = arguments[_key9];
|
|
444
|
+
log__namespace.debug.apply(null, prepareLine("D", args));
|
|
419
445
|
}
|
|
446
|
+
}, {
|
|
447
|
+
key: "info",
|
|
448
|
+
value: function info() {
|
|
449
|
+
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
450
|
+
args[_key8] = arguments[_key8];
|
|
451
|
+
}
|
|
420
452
|
|
|
421
|
-
|
|
422
|
-
|
|
453
|
+
log__namespace.info.apply(null, prepareLine("I", args));
|
|
454
|
+
}
|
|
455
|
+
}, {
|
|
456
|
+
key: "warn",
|
|
457
|
+
value: function warn() {
|
|
458
|
+
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
459
|
+
args[_key9] = arguments[_key9];
|
|
460
|
+
}
|
|
423
461
|
|
|
424
|
-
|
|
425
|
-
for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
|
|
426
|
-
args[_key10] = arguments[_key10];
|
|
462
|
+
log__namespace.warn.apply(null, prepareLine("W", args));
|
|
427
463
|
}
|
|
464
|
+
}, {
|
|
465
|
+
key: "error",
|
|
466
|
+
value: function error() {
|
|
467
|
+
for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
|
|
468
|
+
args[_key10] = arguments[_key10];
|
|
469
|
+
}
|
|
428
470
|
|
|
429
|
-
|
|
430
|
-
|
|
471
|
+
log__namespace.error.apply(null, prepareLine("E", args));
|
|
472
|
+
}
|
|
473
|
+
}]);
|
|
431
474
|
|
|
432
|
-
|
|
475
|
+
return Logger;
|
|
476
|
+
}();
|
|
433
477
|
|
|
434
478
|
var MINIMUM_RETRY_DELAY = 1000;
|
|
435
479
|
var MAXIMUM_RETRY_DELAY = 4000;
|
|
436
480
|
var MAXIMUM_ATTEMPTS_COUNT = 3;
|
|
437
481
|
var RETRY_WHEN_THROTTLED = true;
|
|
438
482
|
|
|
439
|
-
var regionalMcsHost =
|
|
483
|
+
var regionalMcsHost = function regionalMcsHost(region) {
|
|
484
|
+
return "https://mcs.".concat(region !== null && region !== void 0 ? region : "us1", ".twilio.com");
|
|
485
|
+
};
|
|
440
486
|
|
|
441
|
-
var isFullUrl =
|
|
487
|
+
var isFullUrl = function isFullUrl(url) {
|
|
488
|
+
return url.startsWith("http");
|
|
489
|
+
};
|
|
442
490
|
|
|
443
|
-
var fullUrl = (partUrl, region)
|
|
491
|
+
var fullUrl = function fullUrl(partUrl, region) {
|
|
492
|
+
return "".concat(!isFullUrl(partUrl) ? regionalMcsHost(region) : "").concat(partUrl);
|
|
493
|
+
};
|
|
444
494
|
|
|
445
|
-
|
|
446
|
-
|
|
495
|
+
var Configuration = /*#__PURE__*/function () {
|
|
496
|
+
function Configuration(token, baseUrl, baseSetUrl, options) {
|
|
447
497
|
var _ref, _options$MCS, _ref2, _constructorOptions$r, _constructorOptions$r2, _constructorOptions$b;
|
|
448
498
|
|
|
499
|
+
_classCallCheck__default["default"](this, Configuration);
|
|
500
|
+
|
|
449
501
|
var constructorOptions = (_ref = (_options$MCS = options.MCS) !== null && _options$MCS !== void 0 ? _options$MCS : options) !== null && _ref !== void 0 ? _ref : {};
|
|
450
502
|
this.region = (_ref2 = (_constructorOptions$r = constructorOptions.region) !== null && _constructorOptions$r !== void 0 ? _constructorOptions$r : options.region) !== null && _ref2 !== void 0 ? _ref2 : 'us1';
|
|
451
503
|
this.mediaUrl = fullUrl(baseUrl, this.region);
|
|
@@ -455,23 +507,29 @@ class Configuration {
|
|
|
455
507
|
this.backoffConfigOverride = (_constructorOptions$b = constructorOptions.backoffConfigOverride) !== null && _constructorOptions$b !== void 0 ? _constructorOptions$b : Configuration.backoffConfigDefault;
|
|
456
508
|
}
|
|
457
509
|
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
}
|
|
510
|
+
_createClass__default["default"](Configuration, [{
|
|
511
|
+
key: "updateToken",
|
|
512
|
+
value: function updateToken(token) {
|
|
513
|
+
this.token = token;
|
|
514
|
+
}
|
|
515
|
+
}], [{
|
|
516
|
+
key: "backoffConfigDefault",
|
|
517
|
+
get: function get() {
|
|
518
|
+
return {
|
|
519
|
+
min: MINIMUM_RETRY_DELAY,
|
|
520
|
+
max: MAXIMUM_RETRY_DELAY,
|
|
521
|
+
maxAttemptsCount: MAXIMUM_ATTEMPTS_COUNT
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
}, {
|
|
525
|
+
key: "retryWhenThrottledDefault",
|
|
526
|
+
get: function get() {
|
|
527
|
+
return RETRY_WHEN_THROTTLED;
|
|
528
|
+
}
|
|
529
|
+
}]);
|
|
473
530
|
|
|
474
|
-
|
|
531
|
+
return Configuration;
|
|
532
|
+
}();
|
|
475
533
|
|
|
476
534
|
/**
|
|
477
535
|
* @classdesc A Media represents a metadata information for the media upload
|
|
@@ -485,140 +543,172 @@ class Configuration {
|
|
|
485
543
|
* @property {MediaCategory} category - attachment category
|
|
486
544
|
*/
|
|
487
545
|
|
|
488
|
-
|
|
489
|
-
|
|
546
|
+
var Media = /*#__PURE__*/function () {
|
|
547
|
+
function Media(config, network, data) {
|
|
548
|
+
_classCallCheck__default["default"](this, Media);
|
|
549
|
+
|
|
490
550
|
this.config = config;
|
|
491
551
|
this.network = network;
|
|
492
552
|
|
|
493
553
|
this._update(data);
|
|
494
554
|
}
|
|
495
555
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
return this.state.filename;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
get category() {
|
|
531
|
-
return this.state.category;
|
|
532
|
-
}
|
|
533
|
-
/**
|
|
534
|
-
* Returns direct content URL to uploaded binary. This URL will expire after some time.
|
|
535
|
-
* This function gets a new URL every time, preventing it from expiring but putting additional load on backend.
|
|
536
|
-
* See getCachedContentUrl() for a function that reduces the amount of network requests.
|
|
537
|
-
*
|
|
538
|
-
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
539
|
-
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
540
|
-
*/
|
|
556
|
+
_createClass__default["default"](Media, [{
|
|
557
|
+
key: "sid",
|
|
558
|
+
get: function get() {
|
|
559
|
+
return this.state.sid;
|
|
560
|
+
}
|
|
561
|
+
}, {
|
|
562
|
+
key: "serviceSid",
|
|
563
|
+
get: function get() {
|
|
564
|
+
return this.state.serviceSid;
|
|
565
|
+
}
|
|
566
|
+
}, {
|
|
567
|
+
key: "dateCreated",
|
|
568
|
+
get: function get() {
|
|
569
|
+
return this.state.dateCreated;
|
|
570
|
+
}
|
|
571
|
+
}, {
|
|
572
|
+
key: "dateUpdated",
|
|
573
|
+
get: function get() {
|
|
574
|
+
return this.state.dateUpdated;
|
|
575
|
+
}
|
|
576
|
+
}, {
|
|
577
|
+
key: "contentType",
|
|
578
|
+
get: function get() {
|
|
579
|
+
return this.state.contentType;
|
|
580
|
+
}
|
|
581
|
+
}, {
|
|
582
|
+
key: "size",
|
|
583
|
+
get: function get() {
|
|
584
|
+
return this.state.size;
|
|
585
|
+
}
|
|
586
|
+
/** @deprecated Use filename instead */
|
|
541
587
|
|
|
588
|
+
}, {
|
|
589
|
+
key: "fileName",
|
|
590
|
+
get: function get() {
|
|
591
|
+
return this.state.filename;
|
|
592
|
+
}
|
|
593
|
+
}, {
|
|
594
|
+
key: "filename",
|
|
595
|
+
get: function get() {
|
|
596
|
+
return this.state.filename;
|
|
597
|
+
}
|
|
598
|
+
}, {
|
|
599
|
+
key: "category",
|
|
600
|
+
get: function get() {
|
|
601
|
+
return this.state.category;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Returns direct content URL to uploaded binary. This URL will expire after some time.
|
|
605
|
+
* This function gets a new URL every time, preventing it from expiring but putting additional load on backend.
|
|
606
|
+
* See getCachedContentUrl() for a function that reduces the amount of network requests.
|
|
607
|
+
*
|
|
608
|
+
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
609
|
+
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
610
|
+
*/
|
|
611
|
+
|
|
612
|
+
}, {
|
|
613
|
+
key: "getContentUrl",
|
|
614
|
+
value: function getContentUrl() {
|
|
615
|
+
var _this = this;
|
|
616
|
+
|
|
617
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
618
|
+
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(resolve, reject, onCancel) {
|
|
619
|
+
var request, response;
|
|
620
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
621
|
+
while (1) {
|
|
622
|
+
switch (_context.prev = _context.next) {
|
|
623
|
+
case 0:
|
|
624
|
+
request = _this.network.get("".concat(_this.config.mediaUrl, "/").concat(_this.sid));
|
|
625
|
+
onCancel(function () {
|
|
626
|
+
return request.cancel();
|
|
627
|
+
});
|
|
628
|
+
_context.prev = 2;
|
|
629
|
+
_context.next = 5;
|
|
630
|
+
return request;
|
|
631
|
+
|
|
632
|
+
case 5:
|
|
633
|
+
response = _context.sent;
|
|
634
|
+
|
|
635
|
+
_this._update(response.body);
|
|
636
|
+
|
|
637
|
+
resolve(_this.state.contentDirectUrl);
|
|
638
|
+
_context.next = 13;
|
|
639
|
+
break;
|
|
542
640
|
|
|
543
|
-
|
|
544
|
-
|
|
641
|
+
case 10:
|
|
642
|
+
_context.prev = 10;
|
|
643
|
+
_context.t0 = _context["catch"](2);
|
|
644
|
+
reject(_context.t0);
|
|
545
645
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
request = _this.network.get("".concat(_this.config.mediaUrl, "/").concat(_this.sid));
|
|
554
|
-
onCancel(() => request.cancel());
|
|
555
|
-
_context.prev = 2;
|
|
556
|
-
_context.next = 5;
|
|
557
|
-
return request;
|
|
646
|
+
case 13:
|
|
647
|
+
case "end":
|
|
648
|
+
return _context.stop();
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}, _callee, null, [[2, 10]]);
|
|
652
|
+
}));
|
|
558
653
|
|
|
559
|
-
|
|
560
|
-
|
|
654
|
+
return function (_x, _x2, _x3) {
|
|
655
|
+
return _ref.apply(this, arguments);
|
|
656
|
+
};
|
|
657
|
+
}());
|
|
658
|
+
}
|
|
659
|
+
}, {
|
|
660
|
+
key: "_update",
|
|
661
|
+
value: function _update(data) {
|
|
662
|
+
var _data$links$content_d, _data$filename, _data$category, _data$is_multipart_up;
|
|
663
|
+
|
|
664
|
+
this.state = {
|
|
665
|
+
sid: data.sid,
|
|
666
|
+
serviceSid: data.service_sid,
|
|
667
|
+
channelSid: data.channel_sid,
|
|
668
|
+
messageSid: data.message_sid,
|
|
669
|
+
dateCreated: data.date_created ? new Date(data.date_created) : null,
|
|
670
|
+
dateUploadUpdated: data.date_upload_updated ? new Date(data.date_upload_updated) : null,
|
|
671
|
+
dateUpdated: data.date_updated ? new Date(data.date_updated) : null,
|
|
672
|
+
size: data.size,
|
|
673
|
+
contentType: data.content_type,
|
|
674
|
+
author: data.author,
|
|
675
|
+
url: data.url,
|
|
676
|
+
contentUrl: data.links.content,
|
|
677
|
+
contentDirectUrl: (_data$links$content_d = data.links.content_direct_temporary) !== null && _data$links$content_d !== void 0 ? _data$links$content_d : null,
|
|
678
|
+
filename: (_data$filename = data.filename) !== null && _data$filename !== void 0 ? _data$filename : null,
|
|
679
|
+
category: (_data$category = data.category) !== null && _data$category !== void 0 ? _data$category : "media",
|
|
680
|
+
isMultipartUpstream: (_data$is_multipart_up = data.is_multipart_upstream) !== null && _data$is_multipart_up !== void 0 ? _data$is_multipart_up : false
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
}]);
|
|
561
684
|
|
|
562
|
-
|
|
685
|
+
return Media;
|
|
686
|
+
}();
|
|
563
687
|
|
|
564
|
-
|
|
565
|
-
_context.next = 13;
|
|
566
|
-
break;
|
|
688
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
|
|
567
689
|
|
|
568
|
-
|
|
569
|
-
_context.prev = 10;
|
|
570
|
-
_context.t0 = _context["catch"](2);
|
|
571
|
-
reject(_context.t0);
|
|
690
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
572
691
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
return _context.stop();
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}, _callee, null, [[2, 10]]);
|
|
579
|
-
}));
|
|
692
|
+
var TransportError = /*#__PURE__*/function (_Error) {
|
|
693
|
+
_inherits__default["default"](TransportError, _Error);
|
|
580
694
|
|
|
581
|
-
|
|
582
|
-
return _ref.apply(this, arguments);
|
|
583
|
-
};
|
|
584
|
-
}());
|
|
585
|
-
}
|
|
695
|
+
var _super = _createSuper(TransportError);
|
|
586
696
|
|
|
587
|
-
|
|
588
|
-
var
|
|
589
|
-
|
|
590
|
-
this.state = {
|
|
591
|
-
sid: data.sid,
|
|
592
|
-
serviceSid: data.service_sid,
|
|
593
|
-
channelSid: data.channel_sid,
|
|
594
|
-
messageSid: data.message_sid,
|
|
595
|
-
dateCreated: data.date_created ? new Date(data.date_created) : null,
|
|
596
|
-
dateUploadUpdated: data.date_upload_updated ? new Date(data.date_upload_updated) : null,
|
|
597
|
-
dateUpdated: data.date_updated ? new Date(data.date_updated) : null,
|
|
598
|
-
size: data.size,
|
|
599
|
-
contentType: data.content_type,
|
|
600
|
-
author: data.author,
|
|
601
|
-
url: data.url,
|
|
602
|
-
contentUrl: data.links.content,
|
|
603
|
-
contentDirectUrl: (_data$links$content_d = data.links.content_direct_temporary) !== null && _data$links$content_d !== void 0 ? _data$links$content_d : null,
|
|
604
|
-
filename: (_data$filename = data.filename) !== null && _data$filename !== void 0 ? _data$filename : null,
|
|
605
|
-
category: (_data$category = data.category) !== null && _data$category !== void 0 ? _data$category : "media",
|
|
606
|
-
isMultipartUpstream: (_data$is_multipart_up = data.is_multipart_upstream) !== null && _data$is_multipart_up !== void 0 ? _data$is_multipart_up : false
|
|
607
|
-
};
|
|
608
|
-
}
|
|
697
|
+
function TransportError(message, code, body, status, headers) {
|
|
698
|
+
var _this;
|
|
609
699
|
|
|
610
|
-
|
|
700
|
+
_classCallCheck__default["default"](this, TransportError);
|
|
611
701
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
this.headers = headers;
|
|
702
|
+
_this = _super.call(this, message);
|
|
703
|
+
_this.code = code;
|
|
704
|
+
_this.body = body;
|
|
705
|
+
_this.status = status;
|
|
706
|
+
_this.headers = headers;
|
|
707
|
+
return _this;
|
|
619
708
|
}
|
|
620
709
|
|
|
621
|
-
|
|
710
|
+
return _createClass__default["default"](TransportError);
|
|
711
|
+
}( /*#__PURE__*/_wrapNativeSuper__default["default"](Error));
|
|
622
712
|
|
|
623
713
|
var XHR = global["XMLHttpRequest"] || require("xmlhttprequest").XMLHttpRequest;
|
|
624
714
|
|
|
@@ -627,7 +717,11 @@ function parseResponseHeaders(headerString) {
|
|
|
627
717
|
return {};
|
|
628
718
|
}
|
|
629
719
|
|
|
630
|
-
return headerString.split("\r\n").map(
|
|
720
|
+
return headerString.split("\r\n").map(function (el) {
|
|
721
|
+
return el.split(": ");
|
|
722
|
+
}).filter(function (el) {
|
|
723
|
+
return el.length === 2 && el[1].length > 0;
|
|
724
|
+
}).reduce(function (prev, curr) {
|
|
631
725
|
prev[curr[0]] = curr[1];
|
|
632
726
|
return prev;
|
|
633
727
|
}, {});
|
|
@@ -651,316 +745,348 @@ function extractBody(xhr) {
|
|
|
651
745
|
*/
|
|
652
746
|
|
|
653
747
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
var isCancelled = false;
|
|
659
|
-
onCancel(() => {
|
|
660
|
-
xhr.abort();
|
|
661
|
-
isCancelled = true;
|
|
662
|
-
});
|
|
663
|
-
xhr.open(method, url, true);
|
|
664
|
-
|
|
665
|
-
xhr.onreadystatechange = function onreadystatechange() {
|
|
666
|
-
if (xhr.readyState !== 4 || isCancelled) {
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
var responseHeaders = parseResponseHeaders(xhr.getAllResponseHeaders());
|
|
671
|
-
var body = extractBody(xhr);
|
|
748
|
+
var Transport = /*#__PURE__*/function () {
|
|
749
|
+
function Transport() {
|
|
750
|
+
_classCallCheck__default["default"](this, Transport);
|
|
751
|
+
}
|
|
672
752
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
753
|
+
_createClass__default["default"](Transport, [{
|
|
754
|
+
key: "get",
|
|
755
|
+
value:
|
|
756
|
+
/**
|
|
757
|
+
* Make a GET request by given URL
|
|
758
|
+
*/
|
|
759
|
+
function get(url, headers) {
|
|
760
|
+
return Transport.request("GET", url, headers);
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Make a POST request by given URL
|
|
764
|
+
*/
|
|
765
|
+
|
|
766
|
+
}, {
|
|
767
|
+
key: "post",
|
|
768
|
+
value: function post(url, headers, body) {
|
|
769
|
+
return Transport.request("POST", url, headers, body);
|
|
770
|
+
}
|
|
771
|
+
}], [{
|
|
772
|
+
key: "request",
|
|
773
|
+
value: function request(method, url, headers, body) {
|
|
774
|
+
return new CancellablePromise(function (resolve, reject, onCancel) {
|
|
775
|
+
var xhr = new XHR();
|
|
776
|
+
var isCancelled = false;
|
|
777
|
+
onCancel(function () {
|
|
778
|
+
xhr.abort();
|
|
779
|
+
isCancelled = true;
|
|
780
|
+
});
|
|
781
|
+
xhr.open(method, url, true);
|
|
681
782
|
|
|
682
|
-
|
|
683
|
-
|
|
783
|
+
xhr.onreadystatechange = function onreadystatechange() {
|
|
784
|
+
if (xhr.readyState !== 4 || isCancelled) {
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
684
787
|
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
var _body$replace$split$f;
|
|
788
|
+
var responseHeaders = parseResponseHeaders(xhr.getAllResponseHeaders());
|
|
789
|
+
var body = extractBody(xhr);
|
|
688
790
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
791
|
+
if (200 <= xhr.status && xhr.status < 300) {
|
|
792
|
+
resolve({
|
|
793
|
+
status: xhr.status,
|
|
794
|
+
headers: responseHeaders,
|
|
795
|
+
body: body
|
|
796
|
+
});
|
|
693
797
|
} else {
|
|
694
|
-
|
|
695
|
-
|
|
798
|
+
var _xhr$statusText;
|
|
799
|
+
|
|
800
|
+
var status = (_xhr$statusText = xhr.statusText) !== null && _xhr$statusText !== void 0 ? _xhr$statusText : "NONE";
|
|
801
|
+
var bodyRepresentation;
|
|
802
|
+
|
|
803
|
+
if (typeof body === "string") {
|
|
804
|
+
if (body && body.split("\n", 2).length === 1) bodyRepresentation = body;else {
|
|
805
|
+
var _body$replace$split$f;
|
|
806
|
+
|
|
807
|
+
// TODO: RTDSDK-3716: investigate why body is HTML string
|
|
808
|
+
var errorInfo = (_body$replace$split$f = body.replace(/<.*?>/g, "").split(/\r\n/g).filter(function (str) {
|
|
809
|
+
return str.length;
|
|
810
|
+
})[0]) === null || _body$replace$split$f === void 0 ? void 0 : _body$replace$split$f.split(" ");
|
|
811
|
+
bodyRepresentation = (errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.length) > 2 ? errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.slice(1).join(" ") : "";
|
|
812
|
+
}
|
|
813
|
+
} else {
|
|
814
|
+
bodyRepresentation = JSON.stringify(body);
|
|
815
|
+
}
|
|
696
816
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
817
|
+
var message = "".concat(xhr.status, ": [").concat(status, "] ").concat(bodyRepresentation);
|
|
818
|
+
reject(new TransportError(message, xhr.status, body, status, responseHeaders));
|
|
819
|
+
}
|
|
820
|
+
};
|
|
701
821
|
|
|
702
|
-
|
|
703
|
-
|
|
822
|
+
for (var headerName in headers) {
|
|
823
|
+
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
704
824
|
|
|
705
|
-
|
|
706
|
-
|
|
825
|
+
if (headerName === "Content-Type" && headers[headerName] === "application/json") {
|
|
826
|
+
body = JSON.stringify(body);
|
|
827
|
+
}
|
|
707
828
|
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
xhr.send(body);
|
|
711
|
-
});
|
|
712
|
-
}
|
|
713
|
-
/**
|
|
714
|
-
* Make a GET request by given URL
|
|
715
|
-
*/
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
get(url, headers) {
|
|
719
|
-
return Transport.request("GET", url, headers);
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Make a POST request by given URL
|
|
723
|
-
*/
|
|
724
829
|
|
|
830
|
+
xhr.send(body);
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
}]);
|
|
725
834
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
}
|
|
835
|
+
return Transport;
|
|
836
|
+
}();
|
|
731
837
|
|
|
732
838
|
var log$1 = Logger.scope("Network");
|
|
733
839
|
|
|
734
|
-
|
|
735
|
-
|
|
840
|
+
var Network = /*#__PURE__*/function () {
|
|
841
|
+
function Network(config, transport) {
|
|
842
|
+
_classCallCheck__default["default"](this, Network);
|
|
843
|
+
|
|
736
844
|
this.config = config;
|
|
737
845
|
this.transport = transport;
|
|
738
846
|
}
|
|
739
847
|
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
848
|
+
_createClass__default["default"](Network, [{
|
|
849
|
+
key: "backoffConfig",
|
|
850
|
+
value: function backoffConfig() {
|
|
851
|
+
return Object.assign(Configuration.backoffConfigDefault, this.config.backoffConfigOverride);
|
|
852
|
+
}
|
|
853
|
+
}, {
|
|
854
|
+
key: "retryWhenThrottled",
|
|
855
|
+
value: function retryWhenThrottled() {
|
|
856
|
+
var _ref, _this$config$retryWhe;
|
|
746
857
|
|
|
747
|
-
|
|
748
|
-
|
|
858
|
+
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;
|
|
859
|
+
}
|
|
860
|
+
}, {
|
|
861
|
+
key: "executeWithRetry",
|
|
862
|
+
value: function executeWithRetry(request, retryWhenThrottled) {
|
|
863
|
+
var _this = this;
|
|
864
|
+
|
|
865
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
866
|
+
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(resolve, reject, onCancel) {
|
|
867
|
+
var retrier, codesToRetryOn;
|
|
868
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
869
|
+
while (1) {
|
|
870
|
+
switch (_context2.prev = _context2.next) {
|
|
871
|
+
case 0:
|
|
872
|
+
retrier = new operationRetrier.Retrier(_this.backoffConfig());
|
|
873
|
+
codesToRetryOn = [502, 503, 504];
|
|
874
|
+
|
|
875
|
+
if (retryWhenThrottled) {
|
|
876
|
+
codesToRetryOn.push(429);
|
|
877
|
+
}
|
|
749
878
|
|
|
750
|
-
|
|
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
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
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();
|
|
879
|
+
onCancel(function () {
|
|
880
|
+
retrier.cancel();
|
|
881
|
+
retrier.removeAllListeners();
|
|
882
|
+
});
|
|
883
|
+
retrier.on("attempt", /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
884
|
+
var requestPromise, result;
|
|
885
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
886
|
+
while (1) {
|
|
887
|
+
switch (_context.prev = _context.next) {
|
|
888
|
+
case 0:
|
|
889
|
+
_context.prev = 0;
|
|
890
|
+
requestPromise = request();
|
|
891
|
+
onCancel(function () {
|
|
892
|
+
requestPromise.cancel();
|
|
893
|
+
retrier.cancel();
|
|
894
|
+
retrier.removeAllListeners();
|
|
895
|
+
});
|
|
896
|
+
_context.next = 5;
|
|
897
|
+
return requestPromise;
|
|
898
|
+
|
|
899
|
+
case 5:
|
|
900
|
+
result = _context.sent;
|
|
901
|
+
retrier.succeeded(result);
|
|
902
|
+
_context.next = 12;
|
|
903
|
+
break;
|
|
904
|
+
|
|
905
|
+
case 9:
|
|
906
|
+
_context.prev = 9;
|
|
907
|
+
_context.t0 = _context["catch"](0);
|
|
908
|
+
|
|
909
|
+
if (codesToRetryOn.indexOf(_context.t0.status) > -1) {
|
|
910
|
+
retrier.failed(_context.t0);
|
|
911
|
+
} else if (_context.t0.message === "Twilsock disconnected") {
|
|
912
|
+
// Ugly hack. We must make a proper exceptions for twilsock
|
|
913
|
+
retrier.failed(_context.t0);
|
|
914
|
+
} else {
|
|
915
|
+
// Fatal error
|
|
916
|
+
retrier.removeAllListeners();
|
|
917
|
+
retrier.cancel();
|
|
918
|
+
reject(_context.t0);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
case 12:
|
|
922
|
+
case "end":
|
|
923
|
+
return _context.stop();
|
|
924
|
+
}
|
|
812
925
|
}
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
926
|
+
}, _callee, null, [[0, 9]]);
|
|
927
|
+
})));
|
|
928
|
+
retrier.on("succeeded", function (result) {
|
|
929
|
+
resolve(result);
|
|
930
|
+
});
|
|
931
|
+
retrier.on("cancelled", function (err) {
|
|
932
|
+
return reject(err);
|
|
933
|
+
});
|
|
934
|
+
retrier.on("failed", function (err) {
|
|
935
|
+
return reject(err);
|
|
936
|
+
});
|
|
937
|
+
retrier.start();
|
|
938
|
+
|
|
939
|
+
case 9:
|
|
940
|
+
case "end":
|
|
941
|
+
return _context2.stop();
|
|
942
|
+
}
|
|
826
943
|
}
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
}));
|
|
944
|
+
}, _callee2);
|
|
945
|
+
}));
|
|
830
946
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
947
|
+
return function (_x, _x2, _x3) {
|
|
948
|
+
return _ref2.apply(this, arguments);
|
|
949
|
+
};
|
|
950
|
+
}());
|
|
951
|
+
}
|
|
952
|
+
}, {
|
|
953
|
+
key: "get",
|
|
954
|
+
value: function get(url) {
|
|
955
|
+
var _this2 = this;
|
|
956
|
+
|
|
957
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
958
|
+
var _ref4 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(resolve, reject, onCancel) {
|
|
959
|
+
var headers, request, response;
|
|
960
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
961
|
+
while (1) {
|
|
962
|
+
switch (_context3.prev = _context3.next) {
|
|
963
|
+
case 0:
|
|
964
|
+
headers = {
|
|
965
|
+
"X-Twilio-Token": _this2.config.token
|
|
966
|
+
};
|
|
967
|
+
request = _this2.executeWithRetry(function () {
|
|
968
|
+
return _this2.transport.get(url, headers);
|
|
969
|
+
}, _this2.retryWhenThrottled());
|
|
970
|
+
log$1.trace("sending GET request to ", url, " headers ", headers);
|
|
971
|
+
onCancel(function () {
|
|
972
|
+
return request.cancel();
|
|
973
|
+
});
|
|
974
|
+
_context3.prev = 4;
|
|
975
|
+
_context3.next = 7;
|
|
976
|
+
return request;
|
|
977
|
+
|
|
978
|
+
case 7:
|
|
979
|
+
response = _context3.sent;
|
|
980
|
+
log$1.trace("response", response);
|
|
981
|
+
resolve(response);
|
|
982
|
+
_context3.next = 16;
|
|
983
|
+
break;
|
|
836
984
|
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
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();
|
|
985
|
+
case 12:
|
|
986
|
+
_context3.prev = 12;
|
|
987
|
+
_context3.t0 = _context3["catch"](4);
|
|
988
|
+
log$1.debug("get() error ".concat(_context3.t0));
|
|
989
|
+
reject(_context3.t0);
|
|
990
|
+
|
|
991
|
+
case 16:
|
|
992
|
+
case "end":
|
|
993
|
+
return _context3.stop();
|
|
994
|
+
}
|
|
873
995
|
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
|
|
996
|
+
}, _callee3, null, [[4, 12]]);
|
|
997
|
+
}));
|
|
998
|
+
|
|
999
|
+
return function (_x4, _x5, _x6) {
|
|
1000
|
+
return _ref4.apply(this, arguments);
|
|
1001
|
+
};
|
|
1002
|
+
}());
|
|
1003
|
+
}
|
|
1004
|
+
}, {
|
|
1005
|
+
key: "post",
|
|
1006
|
+
value: function post(url, category, media, contentType, filename) {
|
|
1007
|
+
var _this3 = this;
|
|
877
1008
|
|
|
878
|
-
|
|
879
|
-
|
|
1009
|
+
var headers = {
|
|
1010
|
+
"X-Twilio-Token": this.config.token
|
|
880
1011
|
};
|
|
881
|
-
}());
|
|
882
|
-
}
|
|
883
1012
|
|
|
884
|
-
|
|
885
|
-
|
|
1013
|
+
if ((typeof FormData === "undefined" || !(media instanceof FormData)) && contentType) {
|
|
1014
|
+
Object.assign(headers, {
|
|
1015
|
+
"Content-Type": contentType
|
|
1016
|
+
});
|
|
1017
|
+
}
|
|
886
1018
|
|
|
887
|
-
|
|
888
|
-
"X-Twilio-Token": this.config.token
|
|
889
|
-
};
|
|
1019
|
+
var fullUrl = new URL(url);
|
|
890
1020
|
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
});
|
|
895
|
-
}
|
|
1021
|
+
if (category) {
|
|
1022
|
+
fullUrl.searchParams.append("Category", category);
|
|
1023
|
+
}
|
|
896
1024
|
|
|
897
|
-
|
|
1025
|
+
if (filename) {
|
|
1026
|
+
fullUrl.searchParams.append("Filename", filename);
|
|
1027
|
+
}
|
|
898
1028
|
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
1029
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1030
|
+
var _ref5 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(resolve, reject, onCancel) {
|
|
1031
|
+
var request, response;
|
|
1032
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
1033
|
+
while (1) {
|
|
1034
|
+
switch (_context4.prev = _context4.next) {
|
|
1035
|
+
case 0:
|
|
1036
|
+
request = _this3.transport.post(fullUrl.href, headers, media);
|
|
1037
|
+
onCancel(function () {
|
|
1038
|
+
return request.cancel();
|
|
1039
|
+
});
|
|
1040
|
+
log$1.trace("sending POST request to ".concat(url, " with headers ").concat(headers));
|
|
1041
|
+
_context4.prev = 3;
|
|
1042
|
+
_context4.next = 6;
|
|
1043
|
+
return request;
|
|
1044
|
+
|
|
1045
|
+
case 6:
|
|
1046
|
+
response = _context4.sent;
|
|
1047
|
+
_context4.next = 17;
|
|
1048
|
+
break;
|
|
902
1049
|
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
1050
|
+
case 9:
|
|
1051
|
+
_context4.prev = 9;
|
|
1052
|
+
_context4.t0 = _context4["catch"](3);
|
|
906
1053
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
while (1) {
|
|
912
|
-
switch (_context4.prev = _context4.next) {
|
|
913
|
-
case 0:
|
|
914
|
-
request = _this3.transport.post(fullUrl.href, headers, media);
|
|
915
|
-
onCancel(() => request.cancel());
|
|
916
|
-
log$1.trace("sending POST request to ".concat(url, " with headers ").concat(headers));
|
|
917
|
-
_context4.prev = 3;
|
|
918
|
-
_context4.next = 6;
|
|
919
|
-
return request;
|
|
920
|
-
|
|
921
|
-
case 6:
|
|
922
|
-
response = _context4.sent;
|
|
923
|
-
_context4.next = 17;
|
|
924
|
-
break;
|
|
925
|
-
|
|
926
|
-
case 9:
|
|
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
|
-
}
|
|
1054
|
+
if (!(global["XMLHttpRequest"] === undefined && media instanceof FormData)) {
|
|
1055
|
+
_context4.next = 14;
|
|
1056
|
+
break;
|
|
1057
|
+
}
|
|
934
1058
|
|
|
935
|
-
|
|
936
|
-
|
|
1059
|
+
reject(new TypeError("Posting FormData supported only with browser engine's FormData"));
|
|
1060
|
+
return _context4.abrupt("return");
|
|
937
1061
|
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1062
|
+
case 14:
|
|
1063
|
+
log$1.debug("post() error ".concat(_context4.t0));
|
|
1064
|
+
reject(_context4.t0);
|
|
1065
|
+
return _context4.abrupt("return");
|
|
942
1066
|
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
1067
|
+
case 17:
|
|
1068
|
+
log$1.trace("response", response);
|
|
1069
|
+
resolve(response);
|
|
946
1070
|
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
1071
|
+
case 19:
|
|
1072
|
+
case "end":
|
|
1073
|
+
return _context4.stop();
|
|
1074
|
+
}
|
|
950
1075
|
}
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
}));
|
|
1076
|
+
}, _callee4, null, [[3, 9]]);
|
|
1077
|
+
}));
|
|
954
1078
|
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
1079
|
+
return function (_x7, _x8, _x9) {
|
|
1080
|
+
return _ref5.apply(this, arguments);
|
|
1081
|
+
};
|
|
1082
|
+
}());
|
|
1083
|
+
}
|
|
1084
|
+
}]);
|
|
960
1085
|
|
|
961
|
-
|
|
1086
|
+
return Network;
|
|
1087
|
+
}();
|
|
962
1088
|
|
|
963
|
-
var version = "0.6.4
|
|
1089
|
+
var version = "0.6.4";
|
|
964
1090
|
|
|
965
1091
|
var _class;
|
|
966
1092
|
var log = Logger.scope("");
|
|
@@ -968,7 +1094,7 @@ var log = Logger.scope("");
|
|
|
968
1094
|
* @classdesc A Client provides an interface for Media Content Service
|
|
969
1095
|
*/
|
|
970
1096
|
|
|
971
|
-
exports["default"] = (_class =
|
|
1097
|
+
exports["default"] = (_class = /*#__PURE__*/function () {
|
|
972
1098
|
// eslint-disable-next-line
|
|
973
1099
|
|
|
974
1100
|
/**
|
|
@@ -980,10 +1106,13 @@ exports["default"] = (_class = class Client {
|
|
|
980
1106
|
* @param {String} baseSetUrl - Base URL for Media Content Service MediaSet resource, i.e. /v1/Services/{serviceSid}/MediaSet
|
|
981
1107
|
* @param {Client#ClientOptions} [options] - Options to customize the Client
|
|
982
1108
|
*/
|
|
983
|
-
|
|
1109
|
+
function Client(token, baseUrl, baseSetUrl) {
|
|
984
1110
|
var _this$options$logLeve, _this$options$transpo;
|
|
985
1111
|
|
|
986
1112
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
1113
|
+
|
|
1114
|
+
_classCallCheck__default["default"](this, Client);
|
|
1115
|
+
|
|
987
1116
|
this.options = options;
|
|
988
1117
|
this.options.logLevel = (_this$options$logLeve = this.options.logLevel) !== null && _this$options$logLeve !== void 0 ? _this$options$logLeve : "silent";
|
|
989
1118
|
this.config = new Configuration(token, baseUrl, baseSetUrl, this.options);
|
|
@@ -1006,276 +1135,299 @@ exports["default"] = (_class = class Client {
|
|
|
1006
1135
|
*/
|
|
1007
1136
|
|
|
1008
1137
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1138
|
+
_createClass__default["default"](Client, [{
|
|
1139
|
+
key: "updateToken",
|
|
1140
|
+
value: function updateToken(token) {
|
|
1141
|
+
log.info("updateToken");
|
|
1142
|
+
this.config.updateToken(token);
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Gets media from media service
|
|
1146
|
+
* @param {String} sid - Media's SID
|
|
1147
|
+
*/
|
|
1148
|
+
|
|
1149
|
+
}, {
|
|
1150
|
+
key: "get",
|
|
1151
|
+
value: function get(sid) {
|
|
1152
|
+
var _this = this;
|
|
1153
|
+
|
|
1154
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1155
|
+
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(resolve, reject, onCancel) {
|
|
1156
|
+
var request, response;
|
|
1157
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
1158
|
+
while (1) {
|
|
1159
|
+
switch (_context.prev = _context.next) {
|
|
1160
|
+
case 0:
|
|
1161
|
+
request = _this.network.get("".concat(_this.config.mediaUrl, "/").concat(sid));
|
|
1162
|
+
onCancel(function () {
|
|
1163
|
+
return request.cancel();
|
|
1164
|
+
});
|
|
1165
|
+
_context.prev = 2;
|
|
1166
|
+
_context.next = 5;
|
|
1167
|
+
return request;
|
|
1168
|
+
|
|
1169
|
+
case 5:
|
|
1170
|
+
response = _context.sent;
|
|
1171
|
+
resolve(new Media(_this.config, _this.network, response.body));
|
|
1172
|
+
_context.next = 12;
|
|
1173
|
+
break;
|
|
1017
1174
|
|
|
1175
|
+
case 9:
|
|
1176
|
+
_context.prev = 9;
|
|
1177
|
+
_context.t0 = _context["catch"](2);
|
|
1178
|
+
reject(_context.t0);
|
|
1018
1179
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(resolve, reject, onCancel) {
|
|
1024
|
-
var request, response;
|
|
1025
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
1026
|
-
while (1) {
|
|
1027
|
-
switch (_context.prev = _context.next) {
|
|
1028
|
-
case 0:
|
|
1029
|
-
request = _this.network.get("".concat(_this.config.mediaUrl, "/").concat(sid));
|
|
1030
|
-
onCancel(() => request.cancel());
|
|
1031
|
-
_context.prev = 2;
|
|
1032
|
-
_context.next = 5;
|
|
1033
|
-
return request;
|
|
1034
|
-
|
|
1035
|
-
case 5:
|
|
1036
|
-
response = _context.sent;
|
|
1037
|
-
resolve(new Media(_this.config, _this.network, response.body));
|
|
1038
|
-
_context.next = 12;
|
|
1039
|
-
break;
|
|
1040
|
-
|
|
1041
|
-
case 9:
|
|
1042
|
-
_context.prev = 9;
|
|
1043
|
-
_context.t0 = _context["catch"](2);
|
|
1044
|
-
reject(_context.t0);
|
|
1045
|
-
|
|
1046
|
-
case 12:
|
|
1047
|
-
case "end":
|
|
1048
|
-
return _context.stop();
|
|
1180
|
+
case 12:
|
|
1181
|
+
case "end":
|
|
1182
|
+
return _context.stop();
|
|
1183
|
+
}
|
|
1049
1184
|
}
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
}));
|
|
1185
|
+
}, _callee, null, [[2, 9]]);
|
|
1186
|
+
}));
|
|
1053
1187
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1188
|
+
return function (_x, _x2, _x3) {
|
|
1189
|
+
return _ref.apply(this, arguments);
|
|
1190
|
+
};
|
|
1191
|
+
}());
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Posts raw content to media service
|
|
1195
|
+
* @param {String} contentType - content type of media
|
|
1196
|
+
* @param {String|Buffer|Blob} media - content to post
|
|
1197
|
+
* @param {MediaCategory|null} category - category for the media
|
|
1198
|
+
*/
|
|
1199
|
+
|
|
1200
|
+
}, {
|
|
1201
|
+
key: "post",
|
|
1202
|
+
value: function post(contentType, media, category, filename) {
|
|
1203
|
+
var _this2 = this;
|
|
1204
|
+
|
|
1205
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1206
|
+
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(resolve, reject, onCancel) {
|
|
1207
|
+
var request, response;
|
|
1208
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
1209
|
+
while (1) {
|
|
1210
|
+
switch (_context2.prev = _context2.next) {
|
|
1211
|
+
case 0:
|
|
1212
|
+
request = _this2.network.post(_this2.config.mediaUrl, category !== null && category !== void 0 ? category : "media", media, contentType, filename);
|
|
1213
|
+
onCancel(function () {
|
|
1214
|
+
return request.cancel();
|
|
1215
|
+
});
|
|
1216
|
+
_context2.prev = 2;
|
|
1217
|
+
_context2.next = 5;
|
|
1218
|
+
return request;
|
|
1219
|
+
|
|
1220
|
+
case 5:
|
|
1221
|
+
response = _context2.sent;
|
|
1222
|
+
resolve(new Media(_this2.config, _this2.network, response.body));
|
|
1223
|
+
_context2.next = 12;
|
|
1224
|
+
break;
|
|
1065
1225
|
|
|
1226
|
+
case 9:
|
|
1227
|
+
_context2.prev = 9;
|
|
1228
|
+
_context2.t0 = _context2["catch"](2);
|
|
1229
|
+
reject(_context2.t0);
|
|
1066
1230
|
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(resolve, reject, onCancel) {
|
|
1072
|
-
var request, response;
|
|
1073
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
1074
|
-
while (1) {
|
|
1075
|
-
switch (_context2.prev = _context2.next) {
|
|
1076
|
-
case 0:
|
|
1077
|
-
request = _this2.network.post(_this2.config.mediaUrl, category !== null && category !== void 0 ? category : "media", media, contentType, filename);
|
|
1078
|
-
onCancel(() => request.cancel());
|
|
1079
|
-
_context2.prev = 2;
|
|
1080
|
-
_context2.next = 5;
|
|
1081
|
-
return request;
|
|
1082
|
-
|
|
1083
|
-
case 5:
|
|
1084
|
-
response = _context2.sent;
|
|
1085
|
-
resolve(new Media(_this2.config, _this2.network, response.body));
|
|
1086
|
-
_context2.next = 12;
|
|
1087
|
-
break;
|
|
1088
|
-
|
|
1089
|
-
case 9:
|
|
1090
|
-
_context2.prev = 9;
|
|
1091
|
-
_context2.t0 = _context2["catch"](2);
|
|
1092
|
-
reject(_context2.t0);
|
|
1093
|
-
|
|
1094
|
-
case 12:
|
|
1095
|
-
case "end":
|
|
1096
|
-
return _context2.stop();
|
|
1231
|
+
case 12:
|
|
1232
|
+
case "end":
|
|
1233
|
+
return _context2.stop();
|
|
1234
|
+
}
|
|
1097
1235
|
}
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
}));
|
|
1236
|
+
}, _callee2, null, [[2, 9]]);
|
|
1237
|
+
}));
|
|
1101
1238
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1239
|
+
return function (_x4, _x5, _x6) {
|
|
1240
|
+
return _ref2.apply(this, arguments);
|
|
1241
|
+
};
|
|
1242
|
+
}());
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Posts FormData to media service. Can be used only with browser engine's FormData.
|
|
1246
|
+
* In non-browser FormData case the method will do promise reject with
|
|
1247
|
+
* new TypeError("Posting FormData supported only with browser engine's FormData")
|
|
1248
|
+
* @param {FormData} formData - form data to post
|
|
1249
|
+
* @param {MediaCategory|null} category - category for the media
|
|
1250
|
+
*/
|
|
1251
|
+
|
|
1252
|
+
}, {
|
|
1253
|
+
key: "postFormData",
|
|
1254
|
+
value: function postFormData(formData, category) {
|
|
1255
|
+
var _this3 = this;
|
|
1256
|
+
|
|
1257
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1258
|
+
var _ref3 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(resolve, reject, onCancel) {
|
|
1259
|
+
var request, response;
|
|
1260
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
1261
|
+
while (1) {
|
|
1262
|
+
switch (_context3.prev = _context3.next) {
|
|
1263
|
+
case 0:
|
|
1264
|
+
request = _this3.network.post(_this3.config.mediaUrl, category !== null && category !== void 0 ? category : "media", formData);
|
|
1265
|
+
onCancel(function () {
|
|
1266
|
+
return request.cancel();
|
|
1267
|
+
});
|
|
1268
|
+
_context3.prev = 2;
|
|
1269
|
+
_context3.next = 5;
|
|
1270
|
+
return request;
|
|
1271
|
+
|
|
1272
|
+
case 5:
|
|
1273
|
+
response = _context3.sent;
|
|
1274
|
+
resolve(new Media(_this3.config, _this3.network, response.body));
|
|
1275
|
+
_context3.next = 12;
|
|
1276
|
+
break;
|
|
1114
1277
|
|
|
1278
|
+
case 9:
|
|
1279
|
+
_context3.prev = 9;
|
|
1280
|
+
_context3.t0 = _context3["catch"](2);
|
|
1281
|
+
reject(_context3.t0);
|
|
1115
1282
|
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
var _ref3 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(resolve, reject, onCancel) {
|
|
1121
|
-
var request, response;
|
|
1122
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
1123
|
-
while (1) {
|
|
1124
|
-
switch (_context3.prev = _context3.next) {
|
|
1125
|
-
case 0:
|
|
1126
|
-
request = _this3.network.post(_this3.config.mediaUrl, category !== null && category !== void 0 ? category : "media", formData);
|
|
1127
|
-
onCancel(() => request.cancel());
|
|
1128
|
-
_context3.prev = 2;
|
|
1129
|
-
_context3.next = 5;
|
|
1130
|
-
return request;
|
|
1131
|
-
|
|
1132
|
-
case 5:
|
|
1133
|
-
response = _context3.sent;
|
|
1134
|
-
resolve(new Media(_this3.config, _this3.network, response.body));
|
|
1135
|
-
_context3.next = 12;
|
|
1136
|
-
break;
|
|
1137
|
-
|
|
1138
|
-
case 9:
|
|
1139
|
-
_context3.prev = 9;
|
|
1140
|
-
_context3.t0 = _context3["catch"](2);
|
|
1141
|
-
reject(_context3.t0);
|
|
1142
|
-
|
|
1143
|
-
case 12:
|
|
1144
|
-
case "end":
|
|
1145
|
-
return _context3.stop();
|
|
1283
|
+
case 12:
|
|
1284
|
+
case "end":
|
|
1285
|
+
return _context3.stop();
|
|
1286
|
+
}
|
|
1146
1287
|
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
|
-
}));
|
|
1150
|
-
|
|
1151
|
-
return function (_x7, _x8, _x9) {
|
|
1152
|
-
return _ref3.apply(this, arguments);
|
|
1153
|
-
};
|
|
1154
|
-
}());
|
|
1155
|
-
}
|
|
1156
|
-
/**
|
|
1157
|
-
* Retrieve information about multiple media SIDs at the same time.
|
|
1158
|
-
* @param mediaSids Array of Media SIDs to get information from.
|
|
1159
|
-
*/
|
|
1288
|
+
}, _callee3, null, [[2, 9]]);
|
|
1289
|
+
}));
|
|
1160
1290
|
|
|
1291
|
+
return function (_x7, _x8, _x9) {
|
|
1292
|
+
return _ref3.apply(this, arguments);
|
|
1293
|
+
};
|
|
1294
|
+
}());
|
|
1295
|
+
}
|
|
1296
|
+
/**
|
|
1297
|
+
* Retrieve information about multiple media SIDs at the same time.
|
|
1298
|
+
* @param mediaSids Array of Media SIDs to get information from.
|
|
1299
|
+
*/
|
|
1300
|
+
|
|
1301
|
+
}, {
|
|
1302
|
+
key: "mediaSetGet",
|
|
1303
|
+
value: function mediaSetGet(mediaSids) {
|
|
1304
|
+
var _this4 = this;
|
|
1305
|
+
|
|
1306
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1307
|
+
var _ref4 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(resolve, reject, onCancel) {
|
|
1308
|
+
var query, request, response, media;
|
|
1309
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
1310
|
+
while (1) {
|
|
1311
|
+
switch (_context4.prev = _context4.next) {
|
|
1312
|
+
case 0:
|
|
1313
|
+
query = {
|
|
1314
|
+
command: "get",
|
|
1315
|
+
list: mediaSids.map(function (sid) {
|
|
1316
|
+
return {
|
|
1317
|
+
media_sid: sid
|
|
1318
|
+
};
|
|
1319
|
+
})
|
|
1320
|
+
};
|
|
1321
|
+
request = _this4.network.post("".concat(_this4.config.mediaSetUrl), null, query, "application/json");
|
|
1322
|
+
onCancel(function () {
|
|
1323
|
+
return request.cancel();
|
|
1324
|
+
});
|
|
1325
|
+
_context4.prev = 3;
|
|
1326
|
+
_context4.next = 6;
|
|
1327
|
+
return request;
|
|
1328
|
+
|
|
1329
|
+
case 6:
|
|
1330
|
+
response = _context4.sent;
|
|
1331
|
+
media = response.body.map(function (item) {
|
|
1332
|
+
if (item.code !== 200) {
|
|
1333
|
+
reject("Failed to obtain detailed information about Media items (failed SID ".concat(item.media_record.sid, ")"));
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1161
1336
|
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
var query, request, response, media;
|
|
1168
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
1169
|
-
while (1) {
|
|
1170
|
-
switch (_context4.prev = _context4.next) {
|
|
1171
|
-
case 0:
|
|
1172
|
-
query = {
|
|
1173
|
-
command: "get",
|
|
1174
|
-
list: mediaSids.map(sid => ({
|
|
1175
|
-
media_sid: sid
|
|
1176
|
-
}))
|
|
1177
|
-
};
|
|
1178
|
-
request = _this4.network.post("".concat(_this4.config.mediaSetUrl), null, query, "application/json");
|
|
1179
|
-
onCancel(() => request.cancel());
|
|
1180
|
-
_context4.prev = 3;
|
|
1181
|
-
_context4.next = 6;
|
|
1182
|
-
return request;
|
|
1183
|
-
|
|
1184
|
-
case 6:
|
|
1185
|
-
response = _context4.sent;
|
|
1186
|
-
media = response.body.map(item => {
|
|
1187
|
-
if (item.code !== 200) {
|
|
1188
|
-
reject("Failed to obtain detailed information about Media items (failed SID ".concat(item.media_record.sid, ")"));
|
|
1189
|
-
return;
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
return new Media(_this4.config, _this4.network, item.media_record);
|
|
1193
|
-
});
|
|
1194
|
-
resolve(media);
|
|
1195
|
-
_context4.next = 14;
|
|
1196
|
-
break;
|
|
1337
|
+
return new Media(_this4.config, _this4.network, item.media_record);
|
|
1338
|
+
});
|
|
1339
|
+
resolve(media);
|
|
1340
|
+
_context4.next = 14;
|
|
1341
|
+
break;
|
|
1197
1342
|
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1343
|
+
case 11:
|
|
1344
|
+
_context4.prev = 11;
|
|
1345
|
+
_context4.t0 = _context4["catch"](3);
|
|
1346
|
+
reject(_context4.t0);
|
|
1202
1347
|
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1348
|
+
case 14:
|
|
1349
|
+
case "end":
|
|
1350
|
+
return _context4.stop();
|
|
1351
|
+
}
|
|
1206
1352
|
}
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
}));
|
|
1353
|
+
}, _callee4, null, [[3, 11]]);
|
|
1354
|
+
}));
|
|
1210
1355
|
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
var
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1356
|
+
return function (_x10, _x11, _x12) {
|
|
1357
|
+
return _ref4.apply(this, arguments);
|
|
1358
|
+
};
|
|
1359
|
+
}());
|
|
1360
|
+
}
|
|
1361
|
+
/**
|
|
1362
|
+
* Retrieve temporary URLs for a set of media SIDs.
|
|
1363
|
+
* @param mediaSids array of the media SIDs to get URLs from.
|
|
1364
|
+
*/
|
|
1365
|
+
|
|
1366
|
+
}, {
|
|
1367
|
+
key: "mediaSetGetContentUrls",
|
|
1368
|
+
value: function mediaSetGetContentUrls(mediaSids) {
|
|
1369
|
+
var _this5 = this;
|
|
1370
|
+
|
|
1371
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
1372
|
+
var _ref5 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(resolve, reject, onCancel) {
|
|
1373
|
+
var query, request, response, urls;
|
|
1374
|
+
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
|
1375
|
+
while (1) {
|
|
1376
|
+
switch (_context5.prev = _context5.next) {
|
|
1377
|
+
case 0:
|
|
1378
|
+
query = {
|
|
1379
|
+
command: "get",
|
|
1380
|
+
list: mediaSids.map(function (sid) {
|
|
1381
|
+
return {
|
|
1382
|
+
media_sid: sid
|
|
1383
|
+
};
|
|
1384
|
+
})
|
|
1385
|
+
};
|
|
1386
|
+
request = _this5.network.post("".concat(_this5.config.mediaSetUrl), null, query, "application/json");
|
|
1387
|
+
onCancel(function () {
|
|
1388
|
+
return request.cancel();
|
|
1389
|
+
});
|
|
1390
|
+
_context5.prev = 3;
|
|
1391
|
+
_context5.next = 6;
|
|
1392
|
+
return request;
|
|
1393
|
+
|
|
1394
|
+
case 6:
|
|
1395
|
+
response = _context5.sent;
|
|
1396
|
+
urls = new Map();
|
|
1397
|
+
response.body.forEach(function (item) {
|
|
1398
|
+
if (item.code !== 200) {
|
|
1399
|
+
reject("Failed to obtain detailed information about Media items (failed SID ".concat(item.media_record.sid, ")"));
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1252
1402
|
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1403
|
+
urls.set(item.media_record.sid, item.media_record.links.content_direct_temporary);
|
|
1404
|
+
});
|
|
1405
|
+
resolve(urls);
|
|
1406
|
+
_context5.next = 15;
|
|
1407
|
+
break;
|
|
1258
1408
|
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1409
|
+
case 12:
|
|
1410
|
+
_context5.prev = 12;
|
|
1411
|
+
_context5.t0 = _context5["catch"](3);
|
|
1412
|
+
reject(_context5.t0);
|
|
1263
1413
|
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1414
|
+
case 15:
|
|
1415
|
+
case "end":
|
|
1416
|
+
return _context5.stop();
|
|
1417
|
+
}
|
|
1267
1418
|
}
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
}));
|
|
1419
|
+
}, _callee5, null, [[3, 12]]);
|
|
1420
|
+
}));
|
|
1271
1421
|
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1422
|
+
return function (_x13, _x14, _x15) {
|
|
1423
|
+
return _ref5.apply(this, arguments);
|
|
1424
|
+
};
|
|
1425
|
+
}());
|
|
1426
|
+
}
|
|
1427
|
+
}]);
|
|
1277
1428
|
|
|
1278
|
-
|
|
1429
|
+
return Client;
|
|
1430
|
+
}(), _defineProperty__default["default"](_class, "version", version), _class);
|
|
1279
1431
|
|
|
1280
1432
|
__decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0)], exports["default"].prototype, "updateToken", null);
|
|
1281
1433
|
|