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