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