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