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