@twilio/mcs-client 0.6.2-rc.1 → 0.6.3-rc.2
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 +455 -58
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +41 -3
- package/builds/lib.js +430 -58
- package/builds/lib.js.map +1 -1
- package/builds/twilio-mcs-client.js +10620 -11294
- package/builds/twilio-mcs-client.min.js +24 -37
- 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/media.js +2 -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 +7 -9
- package/CHANGELOG.md +0 -331
package/builds/browser.js
CHANGED
|
@@ -28,12 +28,12 @@ var global =
|
|
|
28
28
|
|
|
29
29
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
30
30
|
|
|
31
|
-
var shared = require('@twilio/shared');
|
|
32
|
-
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
33
31
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
32
|
+
require('core-js/modules/es.promise.js');
|
|
34
33
|
require('core-js/modules/es.array.iterator.js');
|
|
35
34
|
require('core-js/modules/es.map.js');
|
|
36
35
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
36
|
+
var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
|
|
37
37
|
require('core-js/modules/web.dom-collections.for-each.js');
|
|
38
38
|
var _regeneratorRuntime = require('@babel/runtime/regenerator');
|
|
39
39
|
require('core-js/modules/es.array.from.js');
|
|
@@ -53,28 +53,284 @@ var declarativeTypeValidator = require('@twilio/declarative-type-validator');
|
|
|
53
53
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
54
54
|
|
|
55
55
|
function _interopNamespace(e) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
}
|
|
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]; }
|
|
67
65
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
n["default"] = e;
|
|
70
|
+
return Object.freeze(n);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
74
73
|
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
74
|
+
var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
|
|
75
75
|
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
|
|
76
76
|
var log__namespace = /*#__PURE__*/_interopNamespace(log$2);
|
|
77
77
|
|
|
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
|
+
|
|
78
334
|
/******************************************************************************
|
|
79
335
|
Copyright (c) Microsoft Corporation.
|
|
80
336
|
|
|
@@ -91,8 +347,8 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
91
347
|
***************************************************************************** */
|
|
92
348
|
function __decorate(decorators, target, key, desc) {
|
|
93
349
|
var c = arguments.length,
|
|
94
|
-
|
|
95
|
-
|
|
350
|
+
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
351
|
+
d;
|
|
96
352
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
|
|
97
353
|
if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
98
354
|
}
|
|
@@ -105,99 +361,125 @@ function __metadata(metadataKey, metadataValue) {
|
|
|
105
361
|
function prepareLine(prefix, args) {
|
|
106
362
|
return ["".concat(new Date().toISOString(), " MCS Client ").concat(prefix, ":")].concat(Array.from(args));
|
|
107
363
|
}
|
|
364
|
+
|
|
108
365
|
class Logger {
|
|
109
366
|
constructor(prefix) {
|
|
110
367
|
_defineProperty__default["default"](this, "prefix", "");
|
|
368
|
+
|
|
111
369
|
this.prefix = prefix !== null && prefix !== undefined && prefix.length > 0 ? prefix + " " : "";
|
|
112
370
|
}
|
|
371
|
+
|
|
113
372
|
static scope(prefix) {
|
|
114
373
|
return new Logger(prefix);
|
|
115
374
|
}
|
|
375
|
+
|
|
116
376
|
setLevel(level) {
|
|
117
377
|
log__namespace.setLevel(level);
|
|
118
378
|
}
|
|
379
|
+
|
|
119
380
|
static setLevel(level) {
|
|
120
381
|
log__namespace.setLevel(level);
|
|
121
382
|
}
|
|
122
383
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
384
|
+
|
|
385
|
+
|
|
123
386
|
trace() {
|
|
124
387
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
125
388
|
args[_key] = arguments[_key];
|
|
126
389
|
}
|
|
390
|
+
|
|
127
391
|
log__namespace.trace.apply(null, prepareLine(this.prefix + "T", args));
|
|
128
392
|
}
|
|
393
|
+
|
|
129
394
|
debug() {
|
|
130
395
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
131
396
|
args[_key2] = arguments[_key2];
|
|
132
397
|
}
|
|
398
|
+
|
|
133
399
|
log__namespace.debug.apply(null, prepareLine(this.prefix + "D", args));
|
|
134
400
|
}
|
|
401
|
+
|
|
135
402
|
info() {
|
|
136
403
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
137
404
|
args[_key3] = arguments[_key3];
|
|
138
405
|
}
|
|
406
|
+
|
|
139
407
|
log__namespace.info.apply(null, prepareLine(this.prefix + "I", args));
|
|
140
408
|
}
|
|
409
|
+
|
|
141
410
|
warn() {
|
|
142
411
|
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
143
412
|
args[_key4] = arguments[_key4];
|
|
144
413
|
}
|
|
414
|
+
|
|
145
415
|
log__namespace.warn.apply(null, prepareLine(this.prefix + "W", args));
|
|
146
416
|
}
|
|
417
|
+
|
|
147
418
|
error() {
|
|
148
419
|
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
149
420
|
args[_key5] = arguments[_key5];
|
|
150
421
|
}
|
|
422
|
+
|
|
151
423
|
log__namespace.error.apply(null, prepareLine(this.prefix + "E", args));
|
|
152
424
|
}
|
|
425
|
+
|
|
153
426
|
static trace() {
|
|
154
427
|
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
155
428
|
args[_key6] = arguments[_key6];
|
|
156
429
|
}
|
|
430
|
+
|
|
157
431
|
log__namespace.trace.apply(null, prepareLine("T", args));
|
|
158
432
|
}
|
|
433
|
+
|
|
159
434
|
static debug() {
|
|
160
435
|
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
161
436
|
args[_key7] = arguments[_key7];
|
|
162
437
|
}
|
|
438
|
+
|
|
163
439
|
log__namespace.debug.apply(null, prepareLine("D", args));
|
|
164
440
|
}
|
|
441
|
+
|
|
165
442
|
static info() {
|
|
166
443
|
for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
|
|
167
444
|
args[_key8] = arguments[_key8];
|
|
168
445
|
}
|
|
446
|
+
|
|
169
447
|
log__namespace.info.apply(null, prepareLine("I", args));
|
|
170
448
|
}
|
|
449
|
+
|
|
171
450
|
static warn() {
|
|
172
451
|
for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
|
|
173
452
|
args[_key9] = arguments[_key9];
|
|
174
453
|
}
|
|
454
|
+
|
|
175
455
|
log__namespace.warn.apply(null, prepareLine("W", args));
|
|
176
456
|
}
|
|
457
|
+
|
|
177
458
|
static error() {
|
|
178
459
|
for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
|
|
179
460
|
args[_key10] = arguments[_key10];
|
|
180
461
|
}
|
|
462
|
+
|
|
181
463
|
log__namespace.error.apply(null, prepareLine("E", args));
|
|
182
464
|
}
|
|
465
|
+
|
|
183
466
|
}
|
|
184
467
|
|
|
185
468
|
var MINIMUM_RETRY_DELAY = 1000;
|
|
186
469
|
var MAXIMUM_RETRY_DELAY = 4000;
|
|
187
470
|
var MAXIMUM_ATTEMPTS_COUNT = 3;
|
|
188
471
|
var RETRY_WHEN_THROTTLED = true;
|
|
472
|
+
|
|
189
473
|
var regionalMcsHost = region => "https://mcs.".concat(region !== null && region !== void 0 ? region : "us1", ".twilio.com");
|
|
474
|
+
|
|
190
475
|
var isFullUrl = url => url.startsWith("http");
|
|
476
|
+
|
|
191
477
|
var fullUrl = (partUrl, region) => "".concat(!isFullUrl(partUrl) ? regionalMcsHost(region) : "").concat(partUrl);
|
|
478
|
+
|
|
192
479
|
class Configuration {
|
|
193
480
|
constructor(token, baseUrl, baseSetUrl, options) {
|
|
194
481
|
var _ref, _options$MCS, _ref2, _constructorOptions$r, _constructorOptions$r2, _constructorOptions$b;
|
|
195
|
-
|
|
196
|
-
_defineProperty__default["default"](this, "retryWhenThrottledOverride", void 0);
|
|
197
|
-
_defineProperty__default["default"](this, "backoffConfigOverride", void 0);
|
|
198
|
-
_defineProperty__default["default"](this, "mediaUrl", void 0);
|
|
199
|
-
_defineProperty__default["default"](this, "mediaSetUrl", void 0);
|
|
200
|
-
_defineProperty__default["default"](this, "region", void 0);
|
|
482
|
+
|
|
201
483
|
var constructorOptions = (_ref = (_options$MCS = options.MCS) !== null && _options$MCS !== void 0 ? _options$MCS : options) !== null && _ref !== void 0 ? _ref : {};
|
|
202
484
|
this.region = (_ref2 = (_constructorOptions$r = constructorOptions.region) !== null && _constructorOptions$r !== void 0 ? _constructorOptions$r : options.region) !== null && _ref2 !== void 0 ? _ref2 : 'us1';
|
|
203
485
|
this.mediaUrl = fullUrl(baseUrl, this.region);
|
|
@@ -206,6 +488,7 @@ class Configuration {
|
|
|
206
488
|
this.retryWhenThrottledOverride = (_constructorOptions$r2 = constructorOptions.retryWhenThrottledOverride) !== null && _constructorOptions$r2 !== void 0 ? _constructorOptions$r2 : RETRY_WHEN_THROTTLED;
|
|
207
489
|
this.backoffConfigOverride = (_constructorOptions$b = constructorOptions.backoffConfigOverride) !== null && _constructorOptions$b !== void 0 ? _constructorOptions$b : Configuration.backoffConfigDefault;
|
|
208
490
|
}
|
|
491
|
+
|
|
209
492
|
static get backoffConfigDefault() {
|
|
210
493
|
return {
|
|
211
494
|
min: MINIMUM_RETRY_DELAY,
|
|
@@ -213,12 +496,15 @@ class Configuration {
|
|
|
213
496
|
maxAttemptsCount: MAXIMUM_ATTEMPTS_COUNT
|
|
214
497
|
};
|
|
215
498
|
}
|
|
499
|
+
|
|
216
500
|
static get retryWhenThrottledDefault() {
|
|
217
501
|
return RETRY_WHEN_THROTTLED;
|
|
218
502
|
}
|
|
503
|
+
|
|
219
504
|
updateToken(token) {
|
|
220
505
|
this.token = token;
|
|
221
506
|
}
|
|
507
|
+
|
|
222
508
|
}
|
|
223
509
|
|
|
224
510
|
/**
|
|
@@ -232,40 +518,49 @@ class Configuration {
|
|
|
232
518
|
* @property {String} fileName - file name, if present, null otherwise
|
|
233
519
|
* @property {MediaCategory} category - attachment category
|
|
234
520
|
*/
|
|
521
|
+
|
|
235
522
|
class Media {
|
|
236
523
|
constructor(config, network, data) {
|
|
237
|
-
_defineProperty__default["default"](this, "state", void 0);
|
|
238
|
-
_defineProperty__default["default"](this, "network", void 0);
|
|
239
|
-
_defineProperty__default["default"](this, "config", void 0);
|
|
240
524
|
this.config = config;
|
|
241
525
|
this.network = network;
|
|
526
|
+
|
|
242
527
|
this._update(data);
|
|
243
528
|
}
|
|
529
|
+
|
|
244
530
|
get sid() {
|
|
245
531
|
return this.state.sid;
|
|
246
532
|
}
|
|
533
|
+
|
|
247
534
|
get serviceSid() {
|
|
248
535
|
return this.state.serviceSid;
|
|
249
536
|
}
|
|
537
|
+
|
|
250
538
|
get dateCreated() {
|
|
251
539
|
return this.state.dateCreated;
|
|
252
540
|
}
|
|
541
|
+
|
|
253
542
|
get dateUpdated() {
|
|
254
543
|
return this.state.dateUpdated;
|
|
255
544
|
}
|
|
545
|
+
|
|
256
546
|
get contentType() {
|
|
257
547
|
return this.state.contentType;
|
|
258
548
|
}
|
|
549
|
+
|
|
259
550
|
get size() {
|
|
260
551
|
return this.state.size;
|
|
261
552
|
}
|
|
262
553
|
/** @deprecated Use filename instead */
|
|
554
|
+
|
|
555
|
+
|
|
263
556
|
get fileName() {
|
|
264
557
|
return this.state.filename;
|
|
265
558
|
}
|
|
559
|
+
|
|
266
560
|
get filename() {
|
|
267
561
|
return this.state.filename;
|
|
268
562
|
}
|
|
563
|
+
|
|
269
564
|
get category() {
|
|
270
565
|
return this.state.category;
|
|
271
566
|
}
|
|
@@ -277,9 +572,12 @@ class Media {
|
|
|
277
572
|
* It is reasonable to build your own refresh logic upon these two functions: as soon as URL returned
|
|
278
573
|
* by getCachedContentUrl() returns 40x status you should call getContentUrl() to refresh it.
|
|
279
574
|
*/
|
|
575
|
+
|
|
576
|
+
|
|
280
577
|
getContentUrl() {
|
|
281
578
|
var _this = this;
|
|
282
|
-
|
|
579
|
+
|
|
580
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
283
581
|
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(resolve, reject, onCancel) {
|
|
284
582
|
var request, response;
|
|
285
583
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
@@ -291,16 +589,21 @@ class Media {
|
|
|
291
589
|
_context.prev = 2;
|
|
292
590
|
_context.next = 5;
|
|
293
591
|
return request;
|
|
592
|
+
|
|
294
593
|
case 5:
|
|
295
594
|
response = _context.sent;
|
|
595
|
+
|
|
296
596
|
_this._update(response.body);
|
|
597
|
+
|
|
297
598
|
resolve(_this.state.contentDirectUrl);
|
|
298
599
|
_context.next = 13;
|
|
299
600
|
break;
|
|
601
|
+
|
|
300
602
|
case 10:
|
|
301
603
|
_context.prev = 10;
|
|
302
604
|
_context.t0 = _context["catch"](2);
|
|
303
605
|
reject(_context.t0);
|
|
606
|
+
|
|
304
607
|
case 13:
|
|
305
608
|
case "end":
|
|
306
609
|
return _context.stop();
|
|
@@ -308,13 +611,16 @@ class Media {
|
|
|
308
611
|
}
|
|
309
612
|
}, _callee, null, [[2, 10]]);
|
|
310
613
|
}));
|
|
614
|
+
|
|
311
615
|
return function (_x, _x2, _x3) {
|
|
312
616
|
return _ref.apply(this, arguments);
|
|
313
617
|
};
|
|
314
618
|
}());
|
|
315
619
|
}
|
|
620
|
+
|
|
316
621
|
_update(data) {
|
|
317
622
|
var _data$links$content_d, _data$filename, _data$category, _data$is_multipart_up;
|
|
623
|
+
|
|
318
624
|
this.state = {
|
|
319
625
|
sid: data.sid,
|
|
320
626
|
serviceSid: data.service_sid,
|
|
@@ -334,39 +640,40 @@ class Media {
|
|
|
334
640
|
isMultipartUpstream: (_data$is_multipart_up = data.is_multipart_upstream) !== null && _data$is_multipart_up !== void 0 ? _data$is_multipart_up : false
|
|
335
641
|
};
|
|
336
642
|
}
|
|
643
|
+
|
|
337
644
|
}
|
|
338
645
|
|
|
339
646
|
class TransportError extends Error {
|
|
340
647
|
constructor(message, code, body, status, headers) {
|
|
341
648
|
super(message);
|
|
342
|
-
_defineProperty__default["default"](this, "code", void 0);
|
|
343
|
-
_defineProperty__default["default"](this, "body", void 0);
|
|
344
|
-
_defineProperty__default["default"](this, "status", void 0);
|
|
345
|
-
_defineProperty__default["default"](this, "headers", void 0);
|
|
346
649
|
this.code = code;
|
|
347
650
|
this.body = body;
|
|
348
651
|
this.status = status;
|
|
349
652
|
this.headers = headers;
|
|
350
653
|
}
|
|
654
|
+
|
|
351
655
|
}
|
|
352
656
|
|
|
353
|
-
var XHR =
|
|
354
|
-
|
|
355
|
-
global["XMLHttpRequest"] || {};
|
|
657
|
+
var XHR = global["XMLHttpRequest"] || {};
|
|
658
|
+
|
|
356
659
|
function parseResponseHeaders(headerString) {
|
|
357
660
|
if (!headerString) {
|
|
358
661
|
return {};
|
|
359
662
|
}
|
|
663
|
+
|
|
360
664
|
return headerString.split("\r\n").map(el => el.split(": ")).filter(el => el.length === 2 && el[1].length > 0).reduce((prev, curr) => {
|
|
361
665
|
prev[curr[0]] = curr[1];
|
|
362
666
|
return prev;
|
|
363
667
|
}, {});
|
|
364
668
|
}
|
|
669
|
+
|
|
365
670
|
function extractBody(xhr) {
|
|
366
671
|
var contentType = xhr.getResponseHeader("Content-Type");
|
|
672
|
+
|
|
367
673
|
if (!contentType || contentType.indexOf("application/json") !== 0 || xhr.responseText.length === 0) {
|
|
368
674
|
return xhr.responseText;
|
|
369
675
|
}
|
|
676
|
+
|
|
370
677
|
try {
|
|
371
678
|
return JSON.parse(xhr.responseText);
|
|
372
679
|
} catch (e) {
|
|
@@ -376,9 +683,11 @@ function extractBody(xhr) {
|
|
|
376
683
|
/**
|
|
377
684
|
* Provides generic network interface
|
|
378
685
|
*/
|
|
686
|
+
|
|
687
|
+
|
|
379
688
|
class Transport {
|
|
380
689
|
static request(method, url, headers, body) {
|
|
381
|
-
return new
|
|
690
|
+
return new CancellablePromise((resolve, reject, onCancel) => {
|
|
382
691
|
var xhr = new XHR();
|
|
383
692
|
var isCancelled = false;
|
|
384
693
|
onCancel(() => {
|
|
@@ -386,12 +695,15 @@ class Transport {
|
|
|
386
695
|
isCancelled = true;
|
|
387
696
|
});
|
|
388
697
|
xhr.open(method, url, true);
|
|
698
|
+
|
|
389
699
|
xhr.onreadystatechange = function onreadystatechange() {
|
|
390
700
|
if (xhr.readyState !== 4 || isCancelled) {
|
|
391
701
|
return;
|
|
392
702
|
}
|
|
703
|
+
|
|
393
704
|
var responseHeaders = parseResponseHeaders(xhr.getAllResponseHeaders());
|
|
394
705
|
var body = extractBody(xhr);
|
|
706
|
+
|
|
395
707
|
if (200 <= xhr.status && xhr.status < 300) {
|
|
396
708
|
resolve({
|
|
397
709
|
status: xhr.status,
|
|
@@ -400,11 +712,14 @@ class Transport {
|
|
|
400
712
|
});
|
|
401
713
|
} else {
|
|
402
714
|
var _xhr$statusText;
|
|
715
|
+
|
|
403
716
|
var status = (_xhr$statusText = xhr.statusText) !== null && _xhr$statusText !== void 0 ? _xhr$statusText : "NONE";
|
|
404
717
|
var bodyRepresentation;
|
|
718
|
+
|
|
405
719
|
if (typeof body === "string") {
|
|
406
720
|
if (body && body.split("\n", 2).length === 1) bodyRepresentation = body;else {
|
|
407
721
|
var _body$replace$split$f;
|
|
722
|
+
|
|
408
723
|
// TODO: RTDSDK-3716: investigate why body is HTML string
|
|
409
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(" ");
|
|
410
725
|
bodyRepresentation = (errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.length) > 2 ? errorInfo === null || errorInfo === void 0 ? void 0 : errorInfo.slice(1).join(" ") : "";
|
|
@@ -412,51 +727,64 @@ class Transport {
|
|
|
412
727
|
} else {
|
|
413
728
|
bodyRepresentation = JSON.stringify(body);
|
|
414
729
|
}
|
|
730
|
+
|
|
415
731
|
var message = "".concat(xhr.status, ": [").concat(status, "] ").concat(bodyRepresentation);
|
|
416
732
|
reject(new TransportError(message, xhr.status, body, status, responseHeaders));
|
|
417
733
|
}
|
|
418
734
|
};
|
|
735
|
+
|
|
419
736
|
for (var headerName in headers) {
|
|
420
737
|
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
738
|
+
|
|
421
739
|
if (headerName === "Content-Type" && headers[headerName] === "application/json") {
|
|
422
740
|
body = JSON.stringify(body);
|
|
423
741
|
}
|
|
424
742
|
}
|
|
743
|
+
|
|
425
744
|
xhr.send(body);
|
|
426
745
|
});
|
|
427
746
|
}
|
|
428
747
|
/**
|
|
429
748
|
* Make a GET request by given URL
|
|
430
749
|
*/
|
|
750
|
+
|
|
751
|
+
|
|
431
752
|
get(url, headers) {
|
|
432
753
|
return Transport.request("GET", url, headers);
|
|
433
754
|
}
|
|
434
755
|
/**
|
|
435
756
|
* Make a POST request by given URL
|
|
436
757
|
*/
|
|
758
|
+
|
|
759
|
+
|
|
437
760
|
post(url, headers, body) {
|
|
438
761
|
return Transport.request("POST", url, headers, body);
|
|
439
762
|
}
|
|
763
|
+
|
|
440
764
|
}
|
|
441
765
|
|
|
442
766
|
var log$1 = Logger.scope("Network");
|
|
767
|
+
|
|
443
768
|
class Network {
|
|
444
769
|
constructor(config, transport) {
|
|
445
|
-
_defineProperty__default["default"](this, "config", void 0);
|
|
446
|
-
_defineProperty__default["default"](this, "transport", void 0);
|
|
447
770
|
this.config = config;
|
|
448
771
|
this.transport = transport;
|
|
449
772
|
}
|
|
773
|
+
|
|
450
774
|
backoffConfig() {
|
|
451
775
|
return Object.assign(Configuration.backoffConfigDefault, this.config.backoffConfigOverride);
|
|
452
776
|
}
|
|
777
|
+
|
|
453
778
|
retryWhenThrottled() {
|
|
454
779
|
var _ref, _this$config$retryWhe;
|
|
780
|
+
|
|
455
781
|
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;
|
|
456
782
|
}
|
|
783
|
+
|
|
457
784
|
executeWithRetry(request, retryWhenThrottled) {
|
|
458
785
|
var _this = this;
|
|
459
|
-
|
|
786
|
+
|
|
787
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
460
788
|
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(resolve, reject, onCancel) {
|
|
461
789
|
var retrier, codesToRetryOn;
|
|
462
790
|
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
@@ -465,9 +793,11 @@ class Network {
|
|
|
465
793
|
case 0:
|
|
466
794
|
retrier = new operationRetrier.Retrier(_this.backoffConfig());
|
|
467
795
|
codesToRetryOn = [502, 503, 504];
|
|
796
|
+
|
|
468
797
|
if (retryWhenThrottled) {
|
|
469
798
|
codesToRetryOn.push(429);
|
|
470
799
|
}
|
|
800
|
+
|
|
471
801
|
onCancel(() => {
|
|
472
802
|
retrier.cancel();
|
|
473
803
|
retrier.removeAllListeners();
|
|
@@ -487,14 +817,17 @@ class Network {
|
|
|
487
817
|
});
|
|
488
818
|
_context.next = 5;
|
|
489
819
|
return requestPromise;
|
|
820
|
+
|
|
490
821
|
case 5:
|
|
491
822
|
result = _context.sent;
|
|
492
823
|
retrier.succeeded(result);
|
|
493
824
|
_context.next = 12;
|
|
494
825
|
break;
|
|
826
|
+
|
|
495
827
|
case 9:
|
|
496
828
|
_context.prev = 9;
|
|
497
829
|
_context.t0 = _context["catch"](0);
|
|
830
|
+
|
|
498
831
|
if (codesToRetryOn.indexOf(_context.t0.status) > -1) {
|
|
499
832
|
retrier.failed(_context.t0);
|
|
500
833
|
} else if (_context.t0.message === "Twilsock disconnected") {
|
|
@@ -506,6 +839,7 @@ class Network {
|
|
|
506
839
|
retrier.cancel();
|
|
507
840
|
reject(_context.t0);
|
|
508
841
|
}
|
|
842
|
+
|
|
509
843
|
case 12:
|
|
510
844
|
case "end":
|
|
511
845
|
return _context.stop();
|
|
@@ -519,6 +853,7 @@ class Network {
|
|
|
519
853
|
retrier.on("cancelled", err => reject(err));
|
|
520
854
|
retrier.on("failed", err => reject(err));
|
|
521
855
|
retrier.start();
|
|
856
|
+
|
|
522
857
|
case 9:
|
|
523
858
|
case "end":
|
|
524
859
|
return _context2.stop();
|
|
@@ -526,14 +861,17 @@ class Network {
|
|
|
526
861
|
}
|
|
527
862
|
}, _callee2);
|
|
528
863
|
}));
|
|
864
|
+
|
|
529
865
|
return function (_x, _x2, _x3) {
|
|
530
866
|
return _ref2.apply(this, arguments);
|
|
531
867
|
};
|
|
532
868
|
}());
|
|
533
869
|
}
|
|
870
|
+
|
|
534
871
|
get(url) {
|
|
535
872
|
var _this2 = this;
|
|
536
|
-
|
|
873
|
+
|
|
874
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
537
875
|
var _ref4 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(resolve, reject, onCancel) {
|
|
538
876
|
var headers, request, response;
|
|
539
877
|
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
@@ -549,17 +887,20 @@ class Network {
|
|
|
549
887
|
_context3.prev = 4;
|
|
550
888
|
_context3.next = 7;
|
|
551
889
|
return request;
|
|
890
|
+
|
|
552
891
|
case 7:
|
|
553
892
|
response = _context3.sent;
|
|
554
893
|
log$1.trace("response", response);
|
|
555
894
|
resolve(response);
|
|
556
895
|
_context3.next = 16;
|
|
557
896
|
break;
|
|
897
|
+
|
|
558
898
|
case 12:
|
|
559
899
|
_context3.prev = 12;
|
|
560
900
|
_context3.t0 = _context3["catch"](4);
|
|
561
901
|
log$1.debug("get() error ".concat(_context3.t0));
|
|
562
902
|
reject(_context3.t0);
|
|
903
|
+
|
|
563
904
|
case 16:
|
|
564
905
|
case "end":
|
|
565
906
|
return _context3.stop();
|
|
@@ -567,29 +908,37 @@ class Network {
|
|
|
567
908
|
}
|
|
568
909
|
}, _callee3, null, [[4, 12]]);
|
|
569
910
|
}));
|
|
911
|
+
|
|
570
912
|
return function (_x4, _x5, _x6) {
|
|
571
913
|
return _ref4.apply(this, arguments);
|
|
572
914
|
};
|
|
573
915
|
}());
|
|
574
916
|
}
|
|
917
|
+
|
|
575
918
|
post(url, category, media, contentType, filename) {
|
|
576
919
|
var _this3 = this;
|
|
920
|
+
|
|
577
921
|
var headers = {
|
|
578
922
|
"X-Twilio-Token": this.config.token
|
|
579
923
|
};
|
|
924
|
+
|
|
580
925
|
if ((typeof FormData === "undefined" || !(media instanceof FormData)) && contentType) {
|
|
581
926
|
Object.assign(headers, {
|
|
582
927
|
"Content-Type": contentType
|
|
583
928
|
});
|
|
584
929
|
}
|
|
930
|
+
|
|
585
931
|
var fullUrl = new URL(url);
|
|
932
|
+
|
|
586
933
|
if (category) {
|
|
587
934
|
fullUrl.searchParams.append("Category", category);
|
|
588
935
|
}
|
|
936
|
+
|
|
589
937
|
if (filename) {
|
|
590
938
|
fullUrl.searchParams.append("Filename", filename);
|
|
591
939
|
}
|
|
592
|
-
|
|
940
|
+
|
|
941
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
593
942
|
var _ref5 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(resolve, reject, onCancel) {
|
|
594
943
|
var request, response;
|
|
595
944
|
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
@@ -602,26 +951,33 @@ class Network {
|
|
|
602
951
|
_context4.prev = 3;
|
|
603
952
|
_context4.next = 6;
|
|
604
953
|
return request;
|
|
954
|
+
|
|
605
955
|
case 6:
|
|
606
956
|
response = _context4.sent;
|
|
607
957
|
_context4.next = 17;
|
|
608
958
|
break;
|
|
959
|
+
|
|
609
960
|
case 9:
|
|
610
961
|
_context4.prev = 9;
|
|
611
962
|
_context4.t0 = _context4["catch"](3);
|
|
963
|
+
|
|
612
964
|
if (!(global["XMLHttpRequest"] === undefined && media instanceof FormData)) {
|
|
613
965
|
_context4.next = 14;
|
|
614
966
|
break;
|
|
615
967
|
}
|
|
968
|
+
|
|
616
969
|
reject(new TypeError("Posting FormData supported only with browser engine's FormData"));
|
|
617
970
|
return _context4.abrupt("return");
|
|
971
|
+
|
|
618
972
|
case 14:
|
|
619
973
|
log$1.debug("post() error ".concat(_context4.t0));
|
|
620
974
|
reject(_context4.t0);
|
|
621
975
|
return _context4.abrupt("return");
|
|
976
|
+
|
|
622
977
|
case 17:
|
|
623
978
|
log$1.trace("response", response);
|
|
624
979
|
resolve(response);
|
|
980
|
+
|
|
625
981
|
case 19:
|
|
626
982
|
case "end":
|
|
627
983
|
return _context4.stop();
|
|
@@ -629,20 +985,23 @@ class Network {
|
|
|
629
985
|
}
|
|
630
986
|
}, _callee4, null, [[3, 9]]);
|
|
631
987
|
}));
|
|
988
|
+
|
|
632
989
|
return function (_x7, _x8, _x9) {
|
|
633
990
|
return _ref5.apply(this, arguments);
|
|
634
991
|
};
|
|
635
992
|
}());
|
|
636
993
|
}
|
|
994
|
+
|
|
637
995
|
}
|
|
638
996
|
|
|
639
|
-
var version = "0.6.
|
|
997
|
+
var version = "0.6.3-rc.2";
|
|
640
998
|
|
|
641
999
|
var _class;
|
|
642
1000
|
var log = Logger.scope("");
|
|
643
1001
|
/**
|
|
644
1002
|
* @classdesc A Client provides an interface for Media Content Service
|
|
645
1003
|
*/
|
|
1004
|
+
|
|
646
1005
|
exports["default"] = (_class = class Client {
|
|
647
1006
|
// eslint-disable-next-line
|
|
648
1007
|
|
|
@@ -657,11 +1016,8 @@ exports["default"] = (_class = class Client {
|
|
|
657
1016
|
*/
|
|
658
1017
|
constructor(token, baseUrl, baseSetUrl) {
|
|
659
1018
|
var _this$options$logLeve, _this$options$transpo;
|
|
1019
|
+
|
|
660
1020
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
661
|
-
_defineProperty__default["default"](this, "transport", void 0);
|
|
662
|
-
_defineProperty__default["default"](this, "options", void 0);
|
|
663
|
-
_defineProperty__default["default"](this, "network", void 0);
|
|
664
|
-
_defineProperty__default["default"](this, "config", void 0);
|
|
665
1021
|
this.options = options;
|
|
666
1022
|
this.options.logLevel = (_this$options$logLeve = this.options.logLevel) !== null && _this$options$logLeve !== void 0 ? _this$options$logLeve : "silent";
|
|
667
1023
|
this.config = new Configuration(token, baseUrl, baseSetUrl, this.options);
|
|
@@ -676,11 +1032,14 @@ exports["default"] = (_class = class Client {
|
|
|
676
1032
|
* @property {String} [logLevel='silent'] - The level of logging to enable. Valid options
|
|
677
1033
|
* (from strictest to broadest): ['silent', 'error', 'warn', 'info', 'debug', 'trace']
|
|
678
1034
|
*/
|
|
1035
|
+
|
|
679
1036
|
/**
|
|
680
1037
|
* Update the token used for Client operations
|
|
681
1038
|
* @param {String} token - The JWT string of the new token
|
|
682
1039
|
* @returns {void}
|
|
683
1040
|
*/
|
|
1041
|
+
|
|
1042
|
+
|
|
684
1043
|
updateToken(token) {
|
|
685
1044
|
log.info("updateToken");
|
|
686
1045
|
this.config.updateToken(token);
|
|
@@ -689,9 +1048,12 @@ exports["default"] = (_class = class Client {
|
|
|
689
1048
|
* Gets media from media service
|
|
690
1049
|
* @param {String} sid - Media's SID
|
|
691
1050
|
*/
|
|
1051
|
+
|
|
1052
|
+
|
|
692
1053
|
get(sid) {
|
|
693
1054
|
var _this = this;
|
|
694
|
-
|
|
1055
|
+
|
|
1056
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
695
1057
|
var _ref = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee(resolve, reject, onCancel) {
|
|
696
1058
|
var request, response;
|
|
697
1059
|
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
@@ -703,15 +1065,18 @@ exports["default"] = (_class = class Client {
|
|
|
703
1065
|
_context.prev = 2;
|
|
704
1066
|
_context.next = 5;
|
|
705
1067
|
return request;
|
|
1068
|
+
|
|
706
1069
|
case 5:
|
|
707
1070
|
response = _context.sent;
|
|
708
1071
|
resolve(new Media(_this.config, _this.network, response.body));
|
|
709
1072
|
_context.next = 12;
|
|
710
1073
|
break;
|
|
1074
|
+
|
|
711
1075
|
case 9:
|
|
712
1076
|
_context.prev = 9;
|
|
713
1077
|
_context.t0 = _context["catch"](2);
|
|
714
1078
|
reject(_context.t0);
|
|
1079
|
+
|
|
715
1080
|
case 12:
|
|
716
1081
|
case "end":
|
|
717
1082
|
return _context.stop();
|
|
@@ -719,6 +1084,7 @@ exports["default"] = (_class = class Client {
|
|
|
719
1084
|
}
|
|
720
1085
|
}, _callee, null, [[2, 9]]);
|
|
721
1086
|
}));
|
|
1087
|
+
|
|
722
1088
|
return function (_x, _x2, _x3) {
|
|
723
1089
|
return _ref.apply(this, arguments);
|
|
724
1090
|
};
|
|
@@ -730,9 +1096,12 @@ exports["default"] = (_class = class Client {
|
|
|
730
1096
|
* @param {String|Buffer|Blob} media - content to post
|
|
731
1097
|
* @param {MediaCategory|null} category - category for the media
|
|
732
1098
|
*/
|
|
1099
|
+
|
|
1100
|
+
|
|
733
1101
|
post(contentType, media, category, filename) {
|
|
734
1102
|
var _this2 = this;
|
|
735
|
-
|
|
1103
|
+
|
|
1104
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
736
1105
|
var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(resolve, reject, onCancel) {
|
|
737
1106
|
var request, response;
|
|
738
1107
|
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
|
|
@@ -744,15 +1113,18 @@ exports["default"] = (_class = class Client {
|
|
|
744
1113
|
_context2.prev = 2;
|
|
745
1114
|
_context2.next = 5;
|
|
746
1115
|
return request;
|
|
1116
|
+
|
|
747
1117
|
case 5:
|
|
748
1118
|
response = _context2.sent;
|
|
749
1119
|
resolve(new Media(_this2.config, _this2.network, response.body));
|
|
750
1120
|
_context2.next = 12;
|
|
751
1121
|
break;
|
|
1122
|
+
|
|
752
1123
|
case 9:
|
|
753
1124
|
_context2.prev = 9;
|
|
754
1125
|
_context2.t0 = _context2["catch"](2);
|
|
755
1126
|
reject(_context2.t0);
|
|
1127
|
+
|
|
756
1128
|
case 12:
|
|
757
1129
|
case "end":
|
|
758
1130
|
return _context2.stop();
|
|
@@ -760,6 +1132,7 @@ exports["default"] = (_class = class Client {
|
|
|
760
1132
|
}
|
|
761
1133
|
}, _callee2, null, [[2, 9]]);
|
|
762
1134
|
}));
|
|
1135
|
+
|
|
763
1136
|
return function (_x4, _x5, _x6) {
|
|
764
1137
|
return _ref2.apply(this, arguments);
|
|
765
1138
|
};
|
|
@@ -772,9 +1145,12 @@ exports["default"] = (_class = class Client {
|
|
|
772
1145
|
* @param {FormData} formData - form data to post
|
|
773
1146
|
* @param {MediaCategory|null} category - category for the media
|
|
774
1147
|
*/
|
|
1148
|
+
|
|
1149
|
+
|
|
775
1150
|
postFormData(formData, category) {
|
|
776
1151
|
var _this3 = this;
|
|
777
|
-
|
|
1152
|
+
|
|
1153
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
778
1154
|
var _ref3 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee3(resolve, reject, onCancel) {
|
|
779
1155
|
var request, response;
|
|
780
1156
|
return _regeneratorRuntime__default["default"].wrap(function _callee3$(_context3) {
|
|
@@ -786,15 +1162,18 @@ exports["default"] = (_class = class Client {
|
|
|
786
1162
|
_context3.prev = 2;
|
|
787
1163
|
_context3.next = 5;
|
|
788
1164
|
return request;
|
|
1165
|
+
|
|
789
1166
|
case 5:
|
|
790
1167
|
response = _context3.sent;
|
|
791
1168
|
resolve(new Media(_this3.config, _this3.network, response.body));
|
|
792
1169
|
_context3.next = 12;
|
|
793
1170
|
break;
|
|
1171
|
+
|
|
794
1172
|
case 9:
|
|
795
1173
|
_context3.prev = 9;
|
|
796
1174
|
_context3.t0 = _context3["catch"](2);
|
|
797
1175
|
reject(_context3.t0);
|
|
1176
|
+
|
|
798
1177
|
case 12:
|
|
799
1178
|
case "end":
|
|
800
1179
|
return _context3.stop();
|
|
@@ -802,6 +1181,7 @@ exports["default"] = (_class = class Client {
|
|
|
802
1181
|
}
|
|
803
1182
|
}, _callee3, null, [[2, 9]]);
|
|
804
1183
|
}));
|
|
1184
|
+
|
|
805
1185
|
return function (_x7, _x8, _x9) {
|
|
806
1186
|
return _ref3.apply(this, arguments);
|
|
807
1187
|
};
|
|
@@ -811,9 +1191,12 @@ exports["default"] = (_class = class Client {
|
|
|
811
1191
|
* Retrieve information about multiple media SIDs at the same time.
|
|
812
1192
|
* @param mediaSids Array of Media SIDs to get information from.
|
|
813
1193
|
*/
|
|
1194
|
+
|
|
1195
|
+
|
|
814
1196
|
mediaSetGet(mediaSids) {
|
|
815
1197
|
var _this4 = this;
|
|
816
|
-
|
|
1198
|
+
|
|
1199
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
817
1200
|
var _ref4 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee4(resolve, reject, onCancel) {
|
|
818
1201
|
var query, request, response, media;
|
|
819
1202
|
return _regeneratorRuntime__default["default"].wrap(function _callee4$(_context4) {
|
|
@@ -831,6 +1214,7 @@ exports["default"] = (_class = class Client {
|
|
|
831
1214
|
_context4.prev = 3;
|
|
832
1215
|
_context4.next = 6;
|
|
833
1216
|
return request;
|
|
1217
|
+
|
|
834
1218
|
case 6:
|
|
835
1219
|
response = _context4.sent;
|
|
836
1220
|
media = response.body.map(item => {
|
|
@@ -838,15 +1222,18 @@ exports["default"] = (_class = class Client {
|
|
|
838
1222
|
reject("Failed to obtain detailed information about Media items (failed SID ".concat(item.media_record.sid, ")"));
|
|
839
1223
|
return;
|
|
840
1224
|
}
|
|
1225
|
+
|
|
841
1226
|
return new Media(_this4.config, _this4.network, item.media_record);
|
|
842
1227
|
});
|
|
843
1228
|
resolve(media);
|
|
844
1229
|
_context4.next = 14;
|
|
845
1230
|
break;
|
|
1231
|
+
|
|
846
1232
|
case 11:
|
|
847
1233
|
_context4.prev = 11;
|
|
848
1234
|
_context4.t0 = _context4["catch"](3);
|
|
849
1235
|
reject(_context4.t0);
|
|
1236
|
+
|
|
850
1237
|
case 14:
|
|
851
1238
|
case "end":
|
|
852
1239
|
return _context4.stop();
|
|
@@ -854,6 +1241,7 @@ exports["default"] = (_class = class Client {
|
|
|
854
1241
|
}
|
|
855
1242
|
}, _callee4, null, [[3, 11]]);
|
|
856
1243
|
}));
|
|
1244
|
+
|
|
857
1245
|
return function (_x10, _x11, _x12) {
|
|
858
1246
|
return _ref4.apply(this, arguments);
|
|
859
1247
|
};
|
|
@@ -863,9 +1251,12 @@ exports["default"] = (_class = class Client {
|
|
|
863
1251
|
* Retrieve temporary URLs for a set of media SIDs.
|
|
864
1252
|
* @param mediaSids array of the media SIDs to get URLs from.
|
|
865
1253
|
*/
|
|
1254
|
+
|
|
1255
|
+
|
|
866
1256
|
mediaSetGetContentUrls(mediaSids) {
|
|
867
1257
|
var _this5 = this;
|
|
868
|
-
|
|
1258
|
+
|
|
1259
|
+
return new CancellablePromise( /*#__PURE__*/function () {
|
|
869
1260
|
var _ref5 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee5(resolve, reject, onCancel) {
|
|
870
1261
|
var query, request, response, urls;
|
|
871
1262
|
return _regeneratorRuntime__default["default"].wrap(function _callee5$(_context5) {
|
|
@@ -883,6 +1274,7 @@ exports["default"] = (_class = class Client {
|
|
|
883
1274
|
_context5.prev = 3;
|
|
884
1275
|
_context5.next = 6;
|
|
885
1276
|
return request;
|
|
1277
|
+
|
|
886
1278
|
case 6:
|
|
887
1279
|
response = _context5.sent;
|
|
888
1280
|
urls = new Map();
|
|
@@ -891,15 +1283,18 @@ exports["default"] = (_class = class Client {
|
|
|
891
1283
|
reject("Failed to obtain detailed information about Media items (failed SID ".concat(item.media_record.sid, ")"));
|
|
892
1284
|
return;
|
|
893
1285
|
}
|
|
1286
|
+
|
|
894
1287
|
urls.set(item.media_record.sid, item.media_record.links.content_direct_temporary);
|
|
895
1288
|
});
|
|
896
1289
|
resolve(urls);
|
|
897
1290
|
_context5.next = 15;
|
|
898
1291
|
break;
|
|
1292
|
+
|
|
899
1293
|
case 12:
|
|
900
1294
|
_context5.prev = 12;
|
|
901
1295
|
_context5.t0 = _context5["catch"](3);
|
|
902
1296
|
reject(_context5.t0);
|
|
1297
|
+
|
|
903
1298
|
case 15:
|
|
904
1299
|
case "end":
|
|
905
1300
|
return _context5.stop();
|
|
@@ -907,20 +1302,22 @@ exports["default"] = (_class = class Client {
|
|
|
907
1302
|
}
|
|
908
1303
|
}, _callee5, null, [[3, 12]]);
|
|
909
1304
|
}));
|
|
1305
|
+
|
|
910
1306
|
return function (_x13, _x14, _x15) {
|
|
911
1307
|
return _ref5.apply(this, arguments);
|
|
912
1308
|
};
|
|
913
1309
|
}());
|
|
914
1310
|
}
|
|
1311
|
+
|
|
915
1312
|
}, _defineProperty__default["default"](_class, "version", version), _class);
|
|
1313
|
+
|
|
916
1314
|
__decorate([declarativeTypeValidator.validateTypes(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", void 0)], exports["default"].prototype, "updateToken", null);
|
|
917
|
-
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", shared.CancellablePromise)], exports["default"].prototype, "get", null);
|
|
918
|
-
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"]);
|
|
919
1315
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
1316
|
+
__decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyString), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", CancellablePromise)], exports["default"].prototype, "get", null);
|
|
1317
|
+
|
|
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,
|
|
1319
|
+
|
|
1320
|
+
exports.CancellablePromise = CancellablePromise;
|
|
924
1321
|
exports.Client = exports["default"];
|
|
925
1322
|
exports.McsClient = exports["default"];
|
|
926
1323
|
exports.McsMedia = Media;
|