@bytescale/sdk 1.5.0 → 3.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +377 -38
- package/dist/browser/cjs/main.js +458 -380
- package/dist/node/cjs/main.js +446 -99
- package/dist/node/esm/main.mjs +448 -101
- package/dist/types/private/AuthSessionState.d.ts +25 -8
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +1 -0
- package/dist/types/public/shared/UrlBuilder.d.ts +1 -0
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +65 -65
- package/dist/types/public/shared/generated/apis/FileApi.d.ts +104 -3
- package/dist/types/public/shared/generated/apis/FolderApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/JobApi.d.ts +0 -3
- package/dist/types/public/shared/generated/apis/UploadApi.d.ts +6 -3
- package/dist/types/public/shared/generated/models/index.d.ts +5 -7
- package/dist/types/public/shared/generated/runtime.d.ts +8 -6
- package/package.json +2 -6
- package/tests/UrlBuilder.test.ts +31 -36
package/dist/browser/cjs/main.js
CHANGED
|
@@ -42,7 +42,7 @@ __lib_require__.d(__lib_exports__, {
|
|
|
42
42
|
"AuthManager": function() { return /* reexport */ AuthManager; },
|
|
43
43
|
"BaseAPI": function() { return /* reexport */ BaseAPI; },
|
|
44
44
|
"BinaryResult": function() { return /* reexport */ BinaryResult; },
|
|
45
|
-
"
|
|
45
|
+
"BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
|
|
46
46
|
"BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
|
|
47
47
|
"CancelledError": function() { return /* reexport */ CancelledError; },
|
|
48
48
|
"CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
|
|
@@ -58,16 +58,332 @@ __lib_require__.d(__lib_exports__, {
|
|
|
58
58
|
"querystring": function() { return /* reexport */ querystring; }
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
;// CONCATENATED MODULE: ./src/private/
|
|
61
|
+
;// CONCATENATED MODULE: ./src/private/Mutex.ts
|
|
62
62
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
63
|
+
function _call(body, then, direct) {
|
|
64
|
+
if (direct) {
|
|
65
|
+
return then ? then(body()) : body();
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
var result = Promise.resolve(body());
|
|
69
|
+
return then ? result.then(then) : result;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return Promise.reject(e);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function _rethrow(thrown, value) {
|
|
75
|
+
if (thrown) throw value;
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
function _finallyRethrows(body, finalizer) {
|
|
79
|
+
try {
|
|
80
|
+
var result = body();
|
|
81
|
+
} catch (e) {
|
|
82
|
+
return finalizer(true, e);
|
|
83
|
+
}
|
|
84
|
+
if (result && result.then) {
|
|
85
|
+
return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
|
|
86
|
+
}
|
|
87
|
+
return finalizer(false, result);
|
|
88
|
+
}
|
|
89
|
+
function _await(value, then, direct) {
|
|
90
|
+
if (direct) {
|
|
91
|
+
return then ? then(value) : value;
|
|
92
|
+
}
|
|
93
|
+
if (!value || !value.then) {
|
|
94
|
+
value = Promise.resolve(value);
|
|
95
|
+
}
|
|
96
|
+
return then ? value.then(then) : value;
|
|
97
|
+
}
|
|
98
|
+
function _empty() {}
|
|
99
|
+
function _awaitIgnored(value, direct) {
|
|
100
|
+
if (!direct) {
|
|
101
|
+
return value && value.then ? value.then(_empty) : Promise.resolve();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function _settle(pact, state, value) {
|
|
105
|
+
if (!pact.s) {
|
|
106
|
+
if (value instanceof _Pact) {
|
|
107
|
+
if (value.s) {
|
|
108
|
+
if (state & 1) {
|
|
109
|
+
state = value.s;
|
|
110
|
+
}
|
|
111
|
+
value = value.v;
|
|
112
|
+
} else {
|
|
113
|
+
value.o = _settle.bind(null, pact, state);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (value && value.then) {
|
|
118
|
+
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
pact.s = state;
|
|
122
|
+
pact.v = value;
|
|
123
|
+
var observer = pact.o;
|
|
124
|
+
if (observer) {
|
|
125
|
+
observer(pact);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
var _Pact = /*#__PURE__*/function () {
|
|
130
|
+
function _Pact() {}
|
|
131
|
+
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
132
|
+
var result = new _Pact();
|
|
133
|
+
var state = this.s;
|
|
134
|
+
if (state) {
|
|
135
|
+
var callback = state & 1 ? onFulfilled : onRejected;
|
|
136
|
+
if (callback) {
|
|
137
|
+
try {
|
|
138
|
+
_settle(result, 1, callback(this.v));
|
|
139
|
+
} catch (e) {
|
|
140
|
+
_settle(result, 2, e);
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
} else {
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this.o = function (_this) {
|
|
148
|
+
try {
|
|
149
|
+
var value = _this.v;
|
|
150
|
+
if (_this.s & 1) {
|
|
151
|
+
_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
152
|
+
} else if (onRejected) {
|
|
153
|
+
_settle(result, 1, onRejected(value));
|
|
154
|
+
} else {
|
|
155
|
+
_settle(result, 2, value);
|
|
156
|
+
}
|
|
157
|
+
} catch (e) {
|
|
158
|
+
_settle(result, 2, e);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return result;
|
|
162
|
+
};
|
|
163
|
+
return _Pact;
|
|
164
|
+
}();
|
|
165
|
+
function _isSettledPact(thenable) {
|
|
166
|
+
return thenable instanceof _Pact && thenable.s & 1;
|
|
167
|
+
}
|
|
168
|
+
function _for(test, update, body) {
|
|
169
|
+
var stage;
|
|
170
|
+
for (;;) {
|
|
171
|
+
var shouldContinue = test();
|
|
172
|
+
if (_isSettledPact(shouldContinue)) {
|
|
173
|
+
shouldContinue = shouldContinue.v;
|
|
174
|
+
}
|
|
175
|
+
if (!shouldContinue) {
|
|
176
|
+
return result;
|
|
177
|
+
}
|
|
178
|
+
if (shouldContinue.then) {
|
|
179
|
+
stage = 0;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
var result = body();
|
|
183
|
+
if (result && result.then) {
|
|
184
|
+
if (_isSettledPact(result)) {
|
|
185
|
+
result = result.s;
|
|
186
|
+
} else {
|
|
187
|
+
stage = 1;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (update) {
|
|
192
|
+
var updateValue = update();
|
|
193
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
194
|
+
stage = 2;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
var pact = new _Pact();
|
|
200
|
+
var reject = _settle.bind(null, pact, 2);
|
|
201
|
+
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
202
|
+
return pact;
|
|
203
|
+
function _resumeAfterBody(value) {
|
|
204
|
+
result = value;
|
|
205
|
+
do {
|
|
206
|
+
if (update) {
|
|
207
|
+
updateValue = update();
|
|
208
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
209
|
+
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
shouldContinue = test();
|
|
214
|
+
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
215
|
+
_settle(pact, 1, result);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
if (shouldContinue.then) {
|
|
219
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
result = body();
|
|
223
|
+
if (_isSettledPact(result)) {
|
|
224
|
+
result = result.v;
|
|
225
|
+
}
|
|
226
|
+
} while (!result || !result.then);
|
|
227
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
228
|
+
}
|
|
229
|
+
function _resumeAfterTest(shouldContinue) {
|
|
230
|
+
if (shouldContinue) {
|
|
231
|
+
result = body();
|
|
232
|
+
if (result && result.then) {
|
|
233
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
234
|
+
} else {
|
|
235
|
+
_resumeAfterBody(result);
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
_settle(pact, 1, result);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function _resumeAfterUpdate() {
|
|
242
|
+
if (shouldContinue = test()) {
|
|
243
|
+
if (shouldContinue.then) {
|
|
244
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
245
|
+
} else {
|
|
246
|
+
_resumeAfterTest(shouldContinue);
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
_settle(pact, 1, result);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function _continue(value, then) {
|
|
254
|
+
return value && value.then ? value.then(then) : then(value);
|
|
255
|
+
}
|
|
256
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
63
257
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
64
258
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
65
259
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
66
260
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
261
|
+
/**
|
|
262
|
+
* A lightweight mutex. (Other libraries contain too many features and we want to keep the size upload-js down).
|
|
263
|
+
*
|
|
264
|
+
* Characteristics:
|
|
265
|
+
* - Non-reentrant.
|
|
266
|
+
* - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
|
|
267
|
+
* - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
|
|
268
|
+
* the mutex every time.
|
|
269
|
+
*/
|
|
270
|
+
var Mutex = /*#__PURE__*/function () {
|
|
271
|
+
function Mutex() {
|
|
272
|
+
_classCallCheck(this, Mutex);
|
|
273
|
+
this.mutex = undefined;
|
|
274
|
+
this.resolver = undefined;
|
|
275
|
+
}
|
|
276
|
+
_createClass(Mutex, [{
|
|
277
|
+
key: "safe",
|
|
278
|
+
value: function safe(callback) {
|
|
279
|
+
try {
|
|
280
|
+
var _this2 = this;
|
|
281
|
+
return _await(_this2.acquire(), function () {
|
|
282
|
+
return _finallyRethrows(callback, function (_wasThrown, _result) {
|
|
283
|
+
_this2.release();
|
|
284
|
+
return _rethrow(_wasThrown, _result);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
} catch (e) {
|
|
288
|
+
return Promise.reject(e);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}, {
|
|
292
|
+
key: "acquire",
|
|
293
|
+
value: function acquire() {
|
|
294
|
+
try {
|
|
295
|
+
var _this4 = this;
|
|
296
|
+
// Loop necessary for when multiple calls are made to 'acquire' before a 'release' is called, else the call to
|
|
297
|
+
// 'release' will resume every caller currently waiting on 'acquire'.
|
|
298
|
+
return _continue(_for(function () {
|
|
299
|
+
return _this4.mutex !== undefined;
|
|
300
|
+
}, void 0, function () {
|
|
301
|
+
return _awaitIgnored(_this4.mutex);
|
|
302
|
+
}), function () {
|
|
303
|
+
_this4.mutex = new Promise(function (resolve) {
|
|
304
|
+
_this4.resolver = resolve;
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
} catch (e) {
|
|
308
|
+
return Promise.reject(e);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}, {
|
|
312
|
+
key: "release",
|
|
313
|
+
value: function release() {
|
|
314
|
+
if (this.resolver === undefined) {
|
|
315
|
+
throw new Error("Unable to release mutex: already released.");
|
|
316
|
+
}
|
|
317
|
+
this.resolver();
|
|
318
|
+
this.resolver = undefined;
|
|
319
|
+
this.mutex = undefined;
|
|
320
|
+
}
|
|
321
|
+
}]);
|
|
322
|
+
return Mutex;
|
|
323
|
+
}();
|
|
324
|
+
;// CONCATENATED MODULE: ./src/private/AuthSessionState.ts
|
|
325
|
+
function AuthSessionState_typeof(obj) { "@babel/helpers - typeof"; return AuthSessionState_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, AuthSessionState_typeof(obj); }
|
|
326
|
+
function AuthSessionState_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
327
|
+
function AuthSessionState_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, AuthSessionState_toPropertyKey(descriptor.key), descriptor); } }
|
|
328
|
+
function AuthSessionState_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthSessionState_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthSessionState_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
329
|
+
function AuthSessionState_toPropertyKey(arg) { var key = AuthSessionState_toPrimitive(arg, "string"); return AuthSessionState_typeof(key) === "symbol" ? key : String(key); }
|
|
330
|
+
function AuthSessionState_toPrimitive(input, hint) { if (AuthSessionState_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthSessionState_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Maintains a global session state, even across package versions.
|
|
334
|
+
*
|
|
335
|
+
* This is to allow users to start auth sessions via the Bytescale JavaScript SDK, where due to versioning or other
|
|
336
|
+
* bundling issues, the Bytescale Upload Widget has been bundled with a different Bytescale JavaScript SDK. In this
|
|
337
|
+
* scenario, the user wouldn't be able to start an auth session with the Bytescale Upload Widget. Therefore, we use
|
|
338
|
+
* global state (i.e. on the window) to ensure the session state can be shared between the user's instance of the
|
|
339
|
+
* Bytescale JavaScript SDK and the Upload Widget's version of the Bytescale JavaScript SDK.
|
|
340
|
+
*
|
|
341
|
+
* Users also frequently have problems caused by them not keeping track of *Api and *Manager instances correctly, so
|
|
342
|
+
* making this global prevents a lot of common mistakes.
|
|
343
|
+
*/
|
|
344
|
+
var AuthSessionState = /*#__PURE__*/function () {
|
|
345
|
+
function AuthSessionState() {
|
|
346
|
+
AuthSessionState_classCallCheck(this, AuthSessionState);
|
|
347
|
+
}
|
|
348
|
+
AuthSessionState_createClass(AuthSessionState, null, [{
|
|
349
|
+
key: "getMutex",
|
|
350
|
+
value:
|
|
351
|
+
/**
|
|
352
|
+
* Called in the browser only.
|
|
353
|
+
*/
|
|
354
|
+
function getMutex() {
|
|
355
|
+
var key = AuthSessionState.mutexKey;
|
|
356
|
+
var mutex = window[key];
|
|
357
|
+
if (mutex === undefined) {
|
|
358
|
+
mutex = new Mutex();
|
|
359
|
+
window[key] = mutex;
|
|
360
|
+
}
|
|
361
|
+
return mutex;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Called in the browser only.
|
|
365
|
+
*/
|
|
366
|
+
}, {
|
|
367
|
+
key: "setSession",
|
|
368
|
+
value: function setSession(session) {
|
|
369
|
+
window[AuthSessionState.stateKey] = session;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Called in the browser and in Node.js (so we check the env before calling env-specific code).
|
|
373
|
+
*/
|
|
374
|
+
}, {
|
|
375
|
+
key: "getSession",
|
|
376
|
+
value: function getSession() {
|
|
377
|
+
if (typeof window === "undefined") {
|
|
378
|
+
return undefined;
|
|
379
|
+
}
|
|
380
|
+
return window[AuthSessionState.stateKey];
|
|
381
|
+
}
|
|
382
|
+
}]);
|
|
383
|
+
return AuthSessionState;
|
|
384
|
+
}();
|
|
385
|
+
AuthSessionState.stateKey = "BytescaleSessionState";
|
|
386
|
+
AuthSessionState.mutexKey = "BytescaleSessionStateMutex";
|
|
71
387
|
;// CONCATENATED MODULE: ./src/public/shared/generated/runtime.ts
|
|
72
388
|
function runtime_typeof(obj) { "@babel/helpers - typeof"; return runtime_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, runtime_typeof(obj); }
|
|
73
389
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
@@ -91,8 +407,8 @@ function _catch(body, recover) {
|
|
|
91
407
|
}
|
|
92
408
|
return result;
|
|
93
409
|
}
|
|
94
|
-
function
|
|
95
|
-
function
|
|
410
|
+
function runtime_empty() {}
|
|
411
|
+
function runtime_continue(value, then) {
|
|
96
412
|
return value && value.then ? value.then(then) : then(value);
|
|
97
413
|
}
|
|
98
414
|
function _invoke(body, then) {
|
|
@@ -103,7 +419,7 @@ function _invoke(body, then) {
|
|
|
103
419
|
return then(result);
|
|
104
420
|
}
|
|
105
421
|
function _defineProperty(obj, key, value) { key = runtime_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
106
|
-
function
|
|
422
|
+
function runtime_await(value, then, direct) {
|
|
107
423
|
if (direct) {
|
|
108
424
|
return then ? then(value) : value;
|
|
109
425
|
}
|
|
@@ -118,21 +434,21 @@ function runtime_createClass(Constructor, protoProps, staticProps) { if (protoPr
|
|
|
118
434
|
function runtime_toPropertyKey(arg) { var key = runtime_toPrimitive(arg, "string"); return runtime_typeof(key) === "symbol" ? key : String(key); }
|
|
119
435
|
function runtime_toPrimitive(input, hint) { if (runtime_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (runtime_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
120
436
|
|
|
121
|
-
var
|
|
122
|
-
function
|
|
123
|
-
runtime_classCallCheck(this,
|
|
437
|
+
var BytescaleApiClientConfigUtils = /*#__PURE__*/function () {
|
|
438
|
+
function BytescaleApiClientConfigUtils() {
|
|
439
|
+
runtime_classCallCheck(this, BytescaleApiClientConfigUtils);
|
|
124
440
|
}
|
|
125
|
-
runtime_createClass(
|
|
441
|
+
runtime_createClass(BytescaleApiClientConfigUtils, null, [{
|
|
126
442
|
key: "getApiUrl",
|
|
127
443
|
value: function getApiUrl(config) {
|
|
128
444
|
var _a;
|
|
129
|
-
return (_a = config.apiUrl) !== null && _a !== void 0 ? _a :
|
|
445
|
+
return (_a = config.apiUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultApiUrl;
|
|
130
446
|
}
|
|
131
447
|
}, {
|
|
132
448
|
key: "getCdnUrl",
|
|
133
449
|
value: function getCdnUrl(config) {
|
|
134
450
|
var _a;
|
|
135
|
-
return (_a = config.cdnUrl) !== null && _a !== void 0 ? _a :
|
|
451
|
+
return (_a = config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
136
452
|
}
|
|
137
453
|
}, {
|
|
138
454
|
key: "getFetchApi",
|
|
@@ -140,11 +456,48 @@ var BytescaleApiClientConfigResolver = /*#__PURE__*/function () {
|
|
|
140
456
|
var _a;
|
|
141
457
|
return (_a = config.fetchApi) !== null && _a !== void 0 ? _a : fetch;
|
|
142
458
|
}
|
|
459
|
+
}, {
|
|
460
|
+
key: "getAccountId",
|
|
461
|
+
value: function getAccountId(config) {
|
|
462
|
+
var _a, _b;
|
|
463
|
+
var accountId;
|
|
464
|
+
if (BytescaleApiClientConfigUtils.specialApiKeys.includes(config.apiKey)) {
|
|
465
|
+
accountId = BytescaleApiClientConfigUtils.specialApiKeyAccountId;
|
|
466
|
+
} else {
|
|
467
|
+
accountId = (_b = (_a = config.apiKey.split("_")[1]) === null || _a === void 0 ? void 0 : _a.substr(0, BytescaleApiClientConfigUtils.accountIdLength)) !== null && _b !== void 0 ? _b : "";
|
|
468
|
+
if (accountId.length !== BytescaleApiClientConfigUtils.accountIdLength) {
|
|
469
|
+
throw new Error("Invalid Bytescale API key.");
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return accountId;
|
|
473
|
+
}
|
|
474
|
+
}, {
|
|
475
|
+
key: "validate",
|
|
476
|
+
value: function validate(config) {
|
|
477
|
+
var _a;
|
|
478
|
+
// Defensive programming, for users not using TypeScript. Mainly because this is used by UploadWidget users.
|
|
479
|
+
if ((config !== null && config !== void 0 ? config : undefined) === undefined) {
|
|
480
|
+
throw new Error("Config parameter required.");
|
|
481
|
+
}
|
|
482
|
+
if (((_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined) === undefined) {
|
|
483
|
+
throw new Error("Please provide an API key via the 'apiKey' config parameter.");
|
|
484
|
+
}
|
|
485
|
+
if (config.apiKey.trim() !== config.apiKey) {
|
|
486
|
+
// We do not support API keys with whitespace (by trimming ourselves) because otherwise we'd need to support this
|
|
487
|
+
// everywhere in perpetuity (since removing the trimming would be a breaking change).
|
|
488
|
+
throw new Error("API key needs trimming (whitespace detected).");
|
|
489
|
+
}
|
|
490
|
+
// This performs futher validation on the API key...
|
|
491
|
+
BytescaleApiClientConfigUtils.getAccountId(config);
|
|
492
|
+
}
|
|
143
493
|
}]);
|
|
144
|
-
return
|
|
494
|
+
return BytescaleApiClientConfigUtils;
|
|
145
495
|
}();
|
|
146
|
-
|
|
147
|
-
|
|
496
|
+
BytescaleApiClientConfigUtils.defaultApiUrl = "https://api.bytescale.com";
|
|
497
|
+
BytescaleApiClientConfigUtils.defaultCdnUrl = "https://upcdn.io";
|
|
498
|
+
BytescaleApiClientConfigUtils.specialApiKeys = ["free", "demo"];
|
|
499
|
+
BytescaleApiClientConfigUtils.specialApiKeyAccountId = "W142hJk";
|
|
500
|
+
BytescaleApiClientConfigUtils.accountIdLength = 7; // Sync with: upload/shared/**/AccountIdUtils
|
|
148
501
|
/**
|
|
149
502
|
* This is the base class for all generated API classes.
|
|
150
503
|
*/
|
|
@@ -152,22 +505,24 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
152
505
|
function BaseAPI(config) {
|
|
153
506
|
runtime_classCallCheck(this, BaseAPI);
|
|
154
507
|
this.config = config;
|
|
508
|
+
BytescaleApiClientConfigUtils.validate(config);
|
|
155
509
|
}
|
|
156
510
|
runtime_createClass(BaseAPI, [{
|
|
157
511
|
key: "request",
|
|
158
512
|
value: function request(context, initOverrides, baseUrlOverride) {
|
|
159
513
|
try {
|
|
160
514
|
var _this2 = this;
|
|
161
|
-
var _a
|
|
515
|
+
var _a;
|
|
162
516
|
var apiKey = _this2.config.apiKey;
|
|
163
517
|
context.headers["Authorization"] = "Bearer ".concat(apiKey); // authorization-header authentication
|
|
164
|
-
|
|
165
|
-
|
|
518
|
+
var session = AuthSessionState.getSession();
|
|
519
|
+
if ((session === null || session === void 0 ? void 0 : session.accessToken) !== undefined) {
|
|
520
|
+
context.headers["Authorization-Token"] = session.accessToken;
|
|
166
521
|
}
|
|
167
522
|
// Key: any possible value for 'baseUrlOverride'
|
|
168
523
|
// Value: user-overridden value for that base URL from the config.
|
|
169
|
-
var nonDefaultBasePaths = _defineProperty({},
|
|
170
|
-
return
|
|
524
|
+
var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this2.config));
|
|
525
|
+
return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
|
|
171
526
|
var url = _ref.url,
|
|
172
527
|
init = _ref.init;
|
|
173
528
|
return _this2.doFetch(url, init, true);
|
|
@@ -187,8 +542,8 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
187
542
|
var _this4 = this;
|
|
188
543
|
var _a, _b;
|
|
189
544
|
var response;
|
|
190
|
-
return
|
|
191
|
-
return
|
|
545
|
+
return runtime_continue(_catch(function () {
|
|
546
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init), function (_BytescaleApiClientCo) {
|
|
192
547
|
response = _BytescaleApiClientCo;
|
|
193
548
|
});
|
|
194
549
|
}, function (e) {
|
|
@@ -201,11 +556,11 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
201
556
|
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
202
557
|
if (isBytescaleApi) {
|
|
203
558
|
var jsonError = undefined;
|
|
204
|
-
return
|
|
205
|
-
return
|
|
559
|
+
return runtime_continue(_catch(function () {
|
|
560
|
+
return runtime_await(response.json(), function (_response$json) {
|
|
206
561
|
jsonError = _response$json;
|
|
207
562
|
});
|
|
208
|
-
},
|
|
563
|
+
}, runtime_empty), function () {
|
|
209
564
|
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
210
565
|
throw new BytescaleApiError(jsonError);
|
|
211
566
|
}
|
|
@@ -242,7 +597,7 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
242
597
|
value: function createFetchParams(context, initOverrides, baseUrlOverride) {
|
|
243
598
|
try {
|
|
244
599
|
var _this6 = this;
|
|
245
|
-
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride :
|
|
600
|
+
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this6.config)) + context.path;
|
|
246
601
|
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
247
602
|
// only add the querystring to the URL if there are query parameters.
|
|
248
603
|
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
@@ -251,13 +606,13 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
251
606
|
}
|
|
252
607
|
var configHeaders = _this6.config.headers;
|
|
253
608
|
var _Object$assign3 = Object.assign({}, context.headers);
|
|
254
|
-
return
|
|
609
|
+
return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
|
|
255
610
|
var headers = Object.assign(_Object$assign3, _configHeaders);
|
|
256
611
|
Object.keys(headers).forEach(function (key) {
|
|
257
612
|
return headers[key] === undefined ? delete headers[key] : {};
|
|
258
613
|
});
|
|
259
614
|
var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
|
|
260
|
-
return
|
|
615
|
+
return runtime_await(initOverrides);
|
|
261
616
|
};
|
|
262
617
|
var initParams = {
|
|
263
618
|
method: context.method,
|
|
@@ -265,7 +620,7 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
265
620
|
body: context.body
|
|
266
621
|
};
|
|
267
622
|
var _Object$assign2 = Object.assign({}, initParams);
|
|
268
|
-
return
|
|
623
|
+
return runtime_await(initOverrideFn({
|
|
269
624
|
init: initParams,
|
|
270
625
|
context: context
|
|
271
626
|
}), function (_initOverrideFn) {
|
|
@@ -286,9 +641,6 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
286
641
|
}]);
|
|
287
642
|
return BaseAPI;
|
|
288
643
|
}();
|
|
289
|
-
BaseAPI.specialApiKeys = ["free", "demo"];
|
|
290
|
-
BaseAPI.specialApiKeyAccountId = "W142hJk";
|
|
291
|
-
BaseAPI.accountIdLength = 7; // Sync with: upload/shared/**/AccountIdUtils
|
|
292
644
|
var CancelledError = /*#__PURE__*/function (_Error) {
|
|
293
645
|
_inherits(CancelledError, _Error);
|
|
294
646
|
var _super = _createSuper(CancelledError);
|
|
@@ -338,7 +690,7 @@ var JSONApiResponse = /*#__PURE__*/function () {
|
|
|
338
690
|
value: function value() {
|
|
339
691
|
try {
|
|
340
692
|
var _this10 = this;
|
|
341
|
-
return
|
|
693
|
+
return runtime_await(_this10.raw.json());
|
|
342
694
|
} catch (e) {
|
|
343
695
|
return Promise.reject(e);
|
|
344
696
|
}
|
|
@@ -354,7 +706,7 @@ var VoidApiResponse = /*#__PURE__*/function () {
|
|
|
354
706
|
runtime_createClass(VoidApiResponse, [{
|
|
355
707
|
key: "value",
|
|
356
708
|
value: function value() {
|
|
357
|
-
return
|
|
709
|
+
return runtime_await(undefined);
|
|
358
710
|
}
|
|
359
711
|
}]);
|
|
360
712
|
return VoidApiResponse;
|
|
@@ -380,7 +732,7 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
380
732
|
value: function text() {
|
|
381
733
|
try {
|
|
382
734
|
var _this12 = this;
|
|
383
|
-
return
|
|
735
|
+
return runtime_await(_this12.raw.text());
|
|
384
736
|
} catch (e) {
|
|
385
737
|
return Promise.reject(e);
|
|
386
738
|
}
|
|
@@ -390,7 +742,7 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
390
742
|
value: function blob() {
|
|
391
743
|
try {
|
|
392
744
|
var _this14 = this;
|
|
393
|
-
return
|
|
745
|
+
return runtime_await(_this14.raw.blob());
|
|
394
746
|
} catch (e) {
|
|
395
747
|
return Promise.reject(e);
|
|
396
748
|
}
|
|
@@ -400,7 +752,7 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
400
752
|
value: function json() {
|
|
401
753
|
try {
|
|
402
754
|
var _this16 = this;
|
|
403
|
-
return
|
|
755
|
+
return runtime_await(_this16.raw.json());
|
|
404
756
|
} catch (e) {
|
|
405
757
|
return Promise.reject(e);
|
|
406
758
|
}
|
|
@@ -446,9 +798,6 @@ function FileApi_getPrototypeOf(o) { FileApi_getPrototypeOf = Object.setPrototyp
|
|
|
446
798
|
*/
|
|
447
799
|
// @ts-ignore
|
|
448
800
|
|
|
449
|
-
/**
|
|
450
|
-
*
|
|
451
|
-
*/
|
|
452
801
|
var FileApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
453
802
|
FileApi_inherits(FileApi, _runtime$BaseAPI);
|
|
454
803
|
var _super = FileApi_createSuper(FileApi);
|
|
@@ -747,9 +1096,6 @@ function FolderApi_getPrototypeOf(o) { FolderApi_getPrototypeOf = Object.setProt
|
|
|
747
1096
|
*/
|
|
748
1097
|
// @ts-ignore
|
|
749
1098
|
|
|
750
|
-
/**
|
|
751
|
-
*
|
|
752
|
-
*/
|
|
753
1099
|
var FolderApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
754
1100
|
FolderApi_inherits(FolderApi, _runtime$BaseAPI);
|
|
755
1101
|
var _super = FolderApi_createSuper(FolderApi);
|
|
@@ -1007,9 +1353,6 @@ function JobApi_getPrototypeOf(o) { JobApi_getPrototypeOf = Object.setPrototypeO
|
|
|
1007
1353
|
*/
|
|
1008
1354
|
// @ts-ignore
|
|
1009
1355
|
|
|
1010
|
-
/**
|
|
1011
|
-
*
|
|
1012
|
-
*/
|
|
1013
1356
|
var JobApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
1014
1357
|
JobApi_inherits(JobApi, _runtime$BaseAPI);
|
|
1015
1358
|
var _super = JobApi_createSuper(JobApi);
|
|
@@ -1142,9 +1485,6 @@ function UploadApi_getPrototypeOf(o) { UploadApi_getPrototypeOf = Object.setProt
|
|
|
1142
1485
|
*/
|
|
1143
1486
|
// @ts-ignore
|
|
1144
1487
|
|
|
1145
|
-
/**
|
|
1146
|
-
*
|
|
1147
|
-
*/
|
|
1148
1488
|
var UploadApi = /*#__PURE__*/function (_runtime$BaseAPI) {
|
|
1149
1489
|
UploadApi_inherits(UploadApi, _runtime$BaseAPI);
|
|
1150
1490
|
var _super = UploadApi_createSuper(UploadApi);
|
|
@@ -1340,7 +1680,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1340
1680
|
function UrlBuilder(config) {
|
|
1341
1681
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1342
1682
|
var _a;
|
|
1343
|
-
this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a :
|
|
1683
|
+
this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1344
1684
|
}
|
|
1345
1685
|
/**
|
|
1346
1686
|
* Builds a URL to either a raw file or a transformed file.
|
|
@@ -1365,7 +1705,7 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1365
1705
|
key: "url",
|
|
1366
1706
|
value: function url(params) {
|
|
1367
1707
|
var _a;
|
|
1368
|
-
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options
|
|
1708
|
+
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1369
1709
|
}
|
|
1370
1710
|
}, {
|
|
1371
1711
|
key: "raw",
|
|
@@ -1379,18 +1719,25 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1379
1719
|
key: "transformation",
|
|
1380
1720
|
value: function transformation(params, trans) {
|
|
1381
1721
|
var _a;
|
|
1382
|
-
var baseUrl = this.getBaseUrl(params, trans.
|
|
1383
|
-
var transParams = this.getTransformationParams(trans
|
|
1384
|
-
cachePermanently: "cache_perm"
|
|
1385
|
-
});
|
|
1722
|
+
var baseUrl = this.getBaseUrl(params, trans.transformation === "preset" ? trans.transformationPreset : trans.transformation);
|
|
1723
|
+
var transParams = trans.transformation === "preset" ? [] : this.getTransformationParams(trans);
|
|
1386
1724
|
var commonParams = this.getCommonQueryParams((_a = params.options) !== null && _a !== void 0 ? _a : {});
|
|
1387
|
-
|
|
1725
|
+
var transCommonParams = this.getCommonTransformationQueryParams(trans);
|
|
1726
|
+
// This format puts "artifact" at the end, which isn't required, but is convention.
|
|
1727
|
+
return this.addQueryParams(baseUrl, [].concat(_toConsumableArray(transParams), _toConsumableArray(commonParams), _toConsumableArray(transCommonParams)));
|
|
1388
1728
|
}
|
|
1389
1729
|
}, {
|
|
1390
1730
|
key: "getBaseUrl",
|
|
1391
1731
|
value: function getBaseUrl(params, prefix) {
|
|
1392
1732
|
return "".concat(this.cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1393
1733
|
}
|
|
1734
|
+
}, {
|
|
1735
|
+
key: "getCommonTransformationQueryParams",
|
|
1736
|
+
value: function getCommonTransformationQueryParams(trans) {
|
|
1737
|
+
return this.makeQueryParams(["cachePermanently", "large", "artifact"], {
|
|
1738
|
+
cachePermanently: "cache_perm"
|
|
1739
|
+
})(trans);
|
|
1740
|
+
}
|
|
1394
1741
|
}, {
|
|
1395
1742
|
key: "getCommonQueryParams",
|
|
1396
1743
|
value: function getCommonQueryParams(params) {
|
|
@@ -1416,8 +1763,9 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1416
1763
|
}
|
|
1417
1764
|
}, {
|
|
1418
1765
|
key: "getTransformationParams",
|
|
1419
|
-
value: function getTransformationParams(trans
|
|
1420
|
-
|
|
1766
|
+
value: function getTransformationParams(trans) {
|
|
1767
|
+
var params = trans.transformationParams;
|
|
1768
|
+
if (params === undefined) {
|
|
1421
1769
|
return [];
|
|
1422
1770
|
}
|
|
1423
1771
|
var serializeObj = function serializeObj(obj) {
|
|
@@ -1425,11 +1773,10 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1425
1773
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
1426
1774
|
key = _ref2[0],
|
|
1427
1775
|
value = _ref2[1];
|
|
1428
|
-
|
|
1429
|
-
return [(_a = keyRewrites[key]) !== null && _a !== void 0 ? _a : key, value.toString()];
|
|
1776
|
+
return [key, value.toString()];
|
|
1430
1777
|
});
|
|
1431
1778
|
};
|
|
1432
|
-
return Array.isArray(
|
|
1779
|
+
return Array.isArray(params) ? params.flatMap(serializeObj) : serializeObj(params);
|
|
1433
1780
|
}
|
|
1434
1781
|
}, {
|
|
1435
1782
|
key: "addQueryParams",
|
|
@@ -1477,21 +1824,21 @@ function _invokeIgnored(body) {
|
|
|
1477
1824
|
return result.then(UploadManagerBase_empty);
|
|
1478
1825
|
}
|
|
1479
1826
|
}
|
|
1480
|
-
function
|
|
1827
|
+
function UploadManagerBase_settle(pact, state, value) {
|
|
1481
1828
|
if (!pact.s) {
|
|
1482
|
-
if (value instanceof
|
|
1829
|
+
if (value instanceof UploadManagerBase_Pact) {
|
|
1483
1830
|
if (value.s) {
|
|
1484
1831
|
if (state & 1) {
|
|
1485
1832
|
state = value.s;
|
|
1486
1833
|
}
|
|
1487
1834
|
value = value.v;
|
|
1488
1835
|
} else {
|
|
1489
|
-
value.o =
|
|
1836
|
+
value.o = UploadManagerBase_settle.bind(null, pact, state);
|
|
1490
1837
|
return;
|
|
1491
1838
|
}
|
|
1492
1839
|
}
|
|
1493
1840
|
if (value && value.then) {
|
|
1494
|
-
value.then(
|
|
1841
|
+
value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
|
|
1495
1842
|
return;
|
|
1496
1843
|
}
|
|
1497
1844
|
pact.s = state;
|
|
@@ -1502,7 +1849,7 @@ function _settle(pact, state, value) {
|
|
|
1502
1849
|
}
|
|
1503
1850
|
}
|
|
1504
1851
|
}
|
|
1505
|
-
var
|
|
1852
|
+
var UploadManagerBase_Pact = /*#__PURE__*/function () {
|
|
1506
1853
|
function _Pact() {}
|
|
1507
1854
|
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
1508
1855
|
var result = new _Pact();
|
|
@@ -1511,9 +1858,9 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
1511
1858
|
var callback = state & 1 ? onFulfilled : onRejected;
|
|
1512
1859
|
if (callback) {
|
|
1513
1860
|
try {
|
|
1514
|
-
|
|
1861
|
+
UploadManagerBase_settle(result, 1, callback(this.v));
|
|
1515
1862
|
} catch (e) {
|
|
1516
|
-
|
|
1863
|
+
UploadManagerBase_settle(result, 2, e);
|
|
1517
1864
|
}
|
|
1518
1865
|
return result;
|
|
1519
1866
|
} else {
|
|
@@ -1524,28 +1871,28 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
1524
1871
|
try {
|
|
1525
1872
|
var value = _this.v;
|
|
1526
1873
|
if (_this.s & 1) {
|
|
1527
|
-
|
|
1874
|
+
UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
1528
1875
|
} else if (onRejected) {
|
|
1529
|
-
|
|
1876
|
+
UploadManagerBase_settle(result, 1, onRejected(value));
|
|
1530
1877
|
} else {
|
|
1531
|
-
|
|
1878
|
+
UploadManagerBase_settle(result, 2, value);
|
|
1532
1879
|
}
|
|
1533
1880
|
} catch (e) {
|
|
1534
|
-
|
|
1881
|
+
UploadManagerBase_settle(result, 2, e);
|
|
1535
1882
|
}
|
|
1536
1883
|
};
|
|
1537
1884
|
return result;
|
|
1538
1885
|
};
|
|
1539
1886
|
return _Pact;
|
|
1540
1887
|
}();
|
|
1541
|
-
function
|
|
1542
|
-
return thenable instanceof
|
|
1888
|
+
function UploadManagerBase_isSettledPact(thenable) {
|
|
1889
|
+
return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
|
|
1543
1890
|
}
|
|
1544
|
-
function
|
|
1891
|
+
function UploadManagerBase_for(test, update, body) {
|
|
1545
1892
|
var stage;
|
|
1546
1893
|
for (;;) {
|
|
1547
1894
|
var shouldContinue = test();
|
|
1548
|
-
if (
|
|
1895
|
+
if (UploadManagerBase_isSettledPact(shouldContinue)) {
|
|
1549
1896
|
shouldContinue = shouldContinue.v;
|
|
1550
1897
|
}
|
|
1551
1898
|
if (!shouldContinue) {
|
|
@@ -1557,7 +1904,7 @@ function _for(test, update, body) {
|
|
|
1557
1904
|
}
|
|
1558
1905
|
var result = body();
|
|
1559
1906
|
if (result && result.then) {
|
|
1560
|
-
if (
|
|
1907
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
1561
1908
|
result = result.s;
|
|
1562
1909
|
} else {
|
|
1563
1910
|
stage = 1;
|
|
@@ -1566,14 +1913,14 @@ function _for(test, update, body) {
|
|
|
1566
1913
|
}
|
|
1567
1914
|
if (update) {
|
|
1568
1915
|
var updateValue = update();
|
|
1569
|
-
if (updateValue && updateValue.then && !
|
|
1916
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
1570
1917
|
stage = 2;
|
|
1571
1918
|
break;
|
|
1572
1919
|
}
|
|
1573
1920
|
}
|
|
1574
1921
|
}
|
|
1575
|
-
var pact = new
|
|
1576
|
-
var reject =
|
|
1922
|
+
var pact = new UploadManagerBase_Pact();
|
|
1923
|
+
var reject = UploadManagerBase_settle.bind(null, pact, 2);
|
|
1577
1924
|
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
1578
1925
|
return pact;
|
|
1579
1926
|
function _resumeAfterBody(value) {
|
|
@@ -1581,14 +1928,14 @@ function _for(test, update, body) {
|
|
|
1581
1928
|
do {
|
|
1582
1929
|
if (update) {
|
|
1583
1930
|
updateValue = update();
|
|
1584
|
-
if (updateValue && updateValue.then && !
|
|
1931
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
1585
1932
|
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
1586
1933
|
return;
|
|
1587
1934
|
}
|
|
1588
1935
|
}
|
|
1589
1936
|
shouldContinue = test();
|
|
1590
|
-
if (!shouldContinue ||
|
|
1591
|
-
|
|
1937
|
+
if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
1938
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1592
1939
|
return;
|
|
1593
1940
|
}
|
|
1594
1941
|
if (shouldContinue.then) {
|
|
@@ -1596,7 +1943,7 @@ function _for(test, update, body) {
|
|
|
1596
1943
|
return;
|
|
1597
1944
|
}
|
|
1598
1945
|
result = body();
|
|
1599
|
-
if (
|
|
1946
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
1600
1947
|
result = result.v;
|
|
1601
1948
|
}
|
|
1602
1949
|
} while (!result || !result.then);
|
|
@@ -1611,7 +1958,7 @@ function _for(test, update, body) {
|
|
|
1611
1958
|
_resumeAfterBody(result);
|
|
1612
1959
|
}
|
|
1613
1960
|
} else {
|
|
1614
|
-
|
|
1961
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1615
1962
|
}
|
|
1616
1963
|
}
|
|
1617
1964
|
function _resumeAfterUpdate() {
|
|
@@ -1622,7 +1969,7 @@ function _for(test, update, body) {
|
|
|
1622
1969
|
_resumeAfterTest(shouldContinue);
|
|
1623
1970
|
}
|
|
1624
1971
|
} else {
|
|
1625
|
-
|
|
1972
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1626
1973
|
}
|
|
1627
1974
|
}
|
|
1628
1975
|
}
|
|
@@ -1638,7 +1985,7 @@ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefi
|
|
|
1638
1985
|
function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
|
|
1639
1986
|
function UploadManagerBase_arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
1640
1987
|
function UploadManagerBase_empty() {}
|
|
1641
|
-
function
|
|
1988
|
+
function UploadManagerBase_awaitIgnored(value, direct) {
|
|
1642
1989
|
if (!direct) {
|
|
1643
1990
|
return value && value.then ? value.then(UploadManagerBase_empty) : Promise.resolve();
|
|
1644
1991
|
}
|
|
@@ -1652,11 +1999,11 @@ function UploadManagerBase_await(value, then, direct) {
|
|
|
1652
1999
|
}
|
|
1653
2000
|
return then ? value.then(then) : value;
|
|
1654
2001
|
}
|
|
1655
|
-
function
|
|
2002
|
+
function UploadManagerBase_rethrow(thrown, value) {
|
|
1656
2003
|
if (thrown) throw value;
|
|
1657
2004
|
return value;
|
|
1658
2005
|
}
|
|
1659
|
-
function
|
|
2006
|
+
function UploadManagerBase_finallyRethrows(body, finalizer) {
|
|
1660
2007
|
try {
|
|
1661
2008
|
var result = body();
|
|
1662
2009
|
} catch (e) {
|
|
@@ -1707,15 +2054,15 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1707
2054
|
cancel = _this2$makeCancellati.cancel,
|
|
1708
2055
|
addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
|
|
1709
2056
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
1710
|
-
return UploadManagerBase_continue(
|
|
2057
|
+
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
1711
2058
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
1712
2059
|
return _this2.uploadPart(request, source, part, uploadInfo, onProgress, addCancellationHandler);
|
|
1713
2060
|
})), function () {
|
|
1714
|
-
return
|
|
2061
|
+
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
1715
2062
|
});
|
|
1716
2063
|
}, function (_wasThrown, _result) {
|
|
1717
2064
|
clearInterval(intervalHandle);
|
|
1718
|
-
return
|
|
2065
|
+
return UploadManagerBase_rethrow(_wasThrown, _result);
|
|
1719
2066
|
}), function () {
|
|
1720
2067
|
return uploadInfo.file;
|
|
1721
2068
|
});
|
|
@@ -1829,7 +2176,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1829
2176
|
_this7.assertNotCancelled(request);
|
|
1830
2177
|
return UploadManagerBase_await(_this7.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
1831
2178
|
_this7.assertNotCancelled(request);
|
|
1832
|
-
return
|
|
2179
|
+
return UploadManagerBase_awaitIgnored(_this7.uploadApi.completeUploadPart({
|
|
1833
2180
|
accountId: request.accountId,
|
|
1834
2181
|
uploadId: uploadInfo.uploadId,
|
|
1835
2182
|
uploadPartIndex: partIndex,
|
|
@@ -1901,14 +2248,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1901
2248
|
value: function mapAsync(items, concurrency, callback) {
|
|
1902
2249
|
try {
|
|
1903
2250
|
var workQueue = UploadManagerBase_toConsumableArray(items);
|
|
1904
|
-
return
|
|
1905
|
-
return _continueIgnored(
|
|
2251
|
+
return UploadManagerBase_awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
|
|
2252
|
+
return _continueIgnored(UploadManagerBase_for(function () {
|
|
1906
2253
|
return workQueue.length > 0;
|
|
1907
2254
|
}, void 0, function () {
|
|
1908
2255
|
var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
|
|
1909
2256
|
return _invokeIgnored(function () {
|
|
1910
2257
|
if (work !== undefined) {
|
|
1911
|
-
return
|
|
2258
|
+
return UploadManagerBase_awaitIgnored(callback(work));
|
|
1912
2259
|
}
|
|
1913
2260
|
});
|
|
1914
2261
|
}));
|
|
@@ -2100,269 +2447,6 @@ var ConsoleUtils = /*#__PURE__*/function () {
|
|
|
2100
2447
|
}]);
|
|
2101
2448
|
return ConsoleUtils;
|
|
2102
2449
|
}();
|
|
2103
|
-
;// CONCATENATED MODULE: ./src/private/Mutex.ts
|
|
2104
|
-
function Mutex_typeof(obj) { "@babel/helpers - typeof"; return Mutex_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, Mutex_typeof(obj); }
|
|
2105
|
-
function _call(body, then, direct) {
|
|
2106
|
-
if (direct) {
|
|
2107
|
-
return then ? then(body()) : body();
|
|
2108
|
-
}
|
|
2109
|
-
try {
|
|
2110
|
-
var result = Promise.resolve(body());
|
|
2111
|
-
return then ? result.then(then) : result;
|
|
2112
|
-
} catch (e) {
|
|
2113
|
-
return Promise.reject(e);
|
|
2114
|
-
}
|
|
2115
|
-
}
|
|
2116
|
-
function Mutex_rethrow(thrown, value) {
|
|
2117
|
-
if (thrown) throw value;
|
|
2118
|
-
return value;
|
|
2119
|
-
}
|
|
2120
|
-
function Mutex_finallyRethrows(body, finalizer) {
|
|
2121
|
-
try {
|
|
2122
|
-
var result = body();
|
|
2123
|
-
} catch (e) {
|
|
2124
|
-
return finalizer(true, e);
|
|
2125
|
-
}
|
|
2126
|
-
if (result && result.then) {
|
|
2127
|
-
return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
|
|
2128
|
-
}
|
|
2129
|
-
return finalizer(false, result);
|
|
2130
|
-
}
|
|
2131
|
-
function Mutex_await(value, then, direct) {
|
|
2132
|
-
if (direct) {
|
|
2133
|
-
return then ? then(value) : value;
|
|
2134
|
-
}
|
|
2135
|
-
if (!value || !value.then) {
|
|
2136
|
-
value = Promise.resolve(value);
|
|
2137
|
-
}
|
|
2138
|
-
return then ? value.then(then) : value;
|
|
2139
|
-
}
|
|
2140
|
-
function Mutex_empty() {}
|
|
2141
|
-
function Mutex_awaitIgnored(value, direct) {
|
|
2142
|
-
if (!direct) {
|
|
2143
|
-
return value && value.then ? value.then(Mutex_empty) : Promise.resolve();
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
function Mutex_settle(pact, state, value) {
|
|
2147
|
-
if (!pact.s) {
|
|
2148
|
-
if (value instanceof Mutex_Pact) {
|
|
2149
|
-
if (value.s) {
|
|
2150
|
-
if (state & 1) {
|
|
2151
|
-
state = value.s;
|
|
2152
|
-
}
|
|
2153
|
-
value = value.v;
|
|
2154
|
-
} else {
|
|
2155
|
-
value.o = Mutex_settle.bind(null, pact, state);
|
|
2156
|
-
return;
|
|
2157
|
-
}
|
|
2158
|
-
}
|
|
2159
|
-
if (value && value.then) {
|
|
2160
|
-
value.then(Mutex_settle.bind(null, pact, state), Mutex_settle.bind(null, pact, 2));
|
|
2161
|
-
return;
|
|
2162
|
-
}
|
|
2163
|
-
pact.s = state;
|
|
2164
|
-
pact.v = value;
|
|
2165
|
-
var observer = pact.o;
|
|
2166
|
-
if (observer) {
|
|
2167
|
-
observer(pact);
|
|
2168
|
-
}
|
|
2169
|
-
}
|
|
2170
|
-
}
|
|
2171
|
-
var Mutex_Pact = /*#__PURE__*/function () {
|
|
2172
|
-
function _Pact() {}
|
|
2173
|
-
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
2174
|
-
var result = new _Pact();
|
|
2175
|
-
var state = this.s;
|
|
2176
|
-
if (state) {
|
|
2177
|
-
var callback = state & 1 ? onFulfilled : onRejected;
|
|
2178
|
-
if (callback) {
|
|
2179
|
-
try {
|
|
2180
|
-
Mutex_settle(result, 1, callback(this.v));
|
|
2181
|
-
} catch (e) {
|
|
2182
|
-
Mutex_settle(result, 2, e);
|
|
2183
|
-
}
|
|
2184
|
-
return result;
|
|
2185
|
-
} else {
|
|
2186
|
-
return this;
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
this.o = function (_this) {
|
|
2190
|
-
try {
|
|
2191
|
-
var value = _this.v;
|
|
2192
|
-
if (_this.s & 1) {
|
|
2193
|
-
Mutex_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
2194
|
-
} else if (onRejected) {
|
|
2195
|
-
Mutex_settle(result, 1, onRejected(value));
|
|
2196
|
-
} else {
|
|
2197
|
-
Mutex_settle(result, 2, value);
|
|
2198
|
-
}
|
|
2199
|
-
} catch (e) {
|
|
2200
|
-
Mutex_settle(result, 2, e);
|
|
2201
|
-
}
|
|
2202
|
-
};
|
|
2203
|
-
return result;
|
|
2204
|
-
};
|
|
2205
|
-
return _Pact;
|
|
2206
|
-
}();
|
|
2207
|
-
function Mutex_isSettledPact(thenable) {
|
|
2208
|
-
return thenable instanceof Mutex_Pact && thenable.s & 1;
|
|
2209
|
-
}
|
|
2210
|
-
function Mutex_for(test, update, body) {
|
|
2211
|
-
var stage;
|
|
2212
|
-
for (;;) {
|
|
2213
|
-
var shouldContinue = test();
|
|
2214
|
-
if (Mutex_isSettledPact(shouldContinue)) {
|
|
2215
|
-
shouldContinue = shouldContinue.v;
|
|
2216
|
-
}
|
|
2217
|
-
if (!shouldContinue) {
|
|
2218
|
-
return result;
|
|
2219
|
-
}
|
|
2220
|
-
if (shouldContinue.then) {
|
|
2221
|
-
stage = 0;
|
|
2222
|
-
break;
|
|
2223
|
-
}
|
|
2224
|
-
var result = body();
|
|
2225
|
-
if (result && result.then) {
|
|
2226
|
-
if (Mutex_isSettledPact(result)) {
|
|
2227
|
-
result = result.s;
|
|
2228
|
-
} else {
|
|
2229
|
-
stage = 1;
|
|
2230
|
-
break;
|
|
2231
|
-
}
|
|
2232
|
-
}
|
|
2233
|
-
if (update) {
|
|
2234
|
-
var updateValue = update();
|
|
2235
|
-
if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
|
|
2236
|
-
stage = 2;
|
|
2237
|
-
break;
|
|
2238
|
-
}
|
|
2239
|
-
}
|
|
2240
|
-
}
|
|
2241
|
-
var pact = new Mutex_Pact();
|
|
2242
|
-
var reject = Mutex_settle.bind(null, pact, 2);
|
|
2243
|
-
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
2244
|
-
return pact;
|
|
2245
|
-
function _resumeAfterBody(value) {
|
|
2246
|
-
result = value;
|
|
2247
|
-
do {
|
|
2248
|
-
if (update) {
|
|
2249
|
-
updateValue = update();
|
|
2250
|
-
if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
|
|
2251
|
-
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
2252
|
-
return;
|
|
2253
|
-
}
|
|
2254
|
-
}
|
|
2255
|
-
shouldContinue = test();
|
|
2256
|
-
if (!shouldContinue || Mutex_isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
2257
|
-
Mutex_settle(pact, 1, result);
|
|
2258
|
-
return;
|
|
2259
|
-
}
|
|
2260
|
-
if (shouldContinue.then) {
|
|
2261
|
-
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
2262
|
-
return;
|
|
2263
|
-
}
|
|
2264
|
-
result = body();
|
|
2265
|
-
if (Mutex_isSettledPact(result)) {
|
|
2266
|
-
result = result.v;
|
|
2267
|
-
}
|
|
2268
|
-
} while (!result || !result.then);
|
|
2269
|
-
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2270
|
-
}
|
|
2271
|
-
function _resumeAfterTest(shouldContinue) {
|
|
2272
|
-
if (shouldContinue) {
|
|
2273
|
-
result = body();
|
|
2274
|
-
if (result && result.then) {
|
|
2275
|
-
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2276
|
-
} else {
|
|
2277
|
-
_resumeAfterBody(result);
|
|
2278
|
-
}
|
|
2279
|
-
} else {
|
|
2280
|
-
Mutex_settle(pact, 1, result);
|
|
2281
|
-
}
|
|
2282
|
-
}
|
|
2283
|
-
function _resumeAfterUpdate() {
|
|
2284
|
-
if (shouldContinue = test()) {
|
|
2285
|
-
if (shouldContinue.then) {
|
|
2286
|
-
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
2287
|
-
} else {
|
|
2288
|
-
_resumeAfterTest(shouldContinue);
|
|
2289
|
-
}
|
|
2290
|
-
} else {
|
|
2291
|
-
Mutex_settle(pact, 1, result);
|
|
2292
|
-
}
|
|
2293
|
-
}
|
|
2294
|
-
}
|
|
2295
|
-
function Mutex_continue(value, then) {
|
|
2296
|
-
return value && value.then ? value.then(then) : then(value);
|
|
2297
|
-
}
|
|
2298
|
-
function Mutex_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2299
|
-
function Mutex_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, Mutex_toPropertyKey(descriptor.key), descriptor); } }
|
|
2300
|
-
function Mutex_createClass(Constructor, protoProps, staticProps) { if (protoProps) Mutex_defineProperties(Constructor.prototype, protoProps); if (staticProps) Mutex_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
2301
|
-
function Mutex_toPropertyKey(arg) { var key = Mutex_toPrimitive(arg, "string"); return Mutex_typeof(key) === "symbol" ? key : String(key); }
|
|
2302
|
-
function Mutex_toPrimitive(input, hint) { if (Mutex_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (Mutex_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
2303
|
-
/**
|
|
2304
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep the size upload-js down).
|
|
2305
|
-
*
|
|
2306
|
-
* Characteristics:
|
|
2307
|
-
* - Non-reentrant.
|
|
2308
|
-
* - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
|
|
2309
|
-
* - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
|
|
2310
|
-
* the mutex every time.
|
|
2311
|
-
*/
|
|
2312
|
-
var Mutex = /*#__PURE__*/function () {
|
|
2313
|
-
function Mutex() {
|
|
2314
|
-
Mutex_classCallCheck(this, Mutex);
|
|
2315
|
-
this.mutex = undefined;
|
|
2316
|
-
this.resolver = undefined;
|
|
2317
|
-
}
|
|
2318
|
-
Mutex_createClass(Mutex, [{
|
|
2319
|
-
key: "safe",
|
|
2320
|
-
value: function safe(callback) {
|
|
2321
|
-
try {
|
|
2322
|
-
var _this2 = this;
|
|
2323
|
-
return Mutex_await(_this2.acquire(), function () {
|
|
2324
|
-
return Mutex_finallyRethrows(callback, function (_wasThrown, _result) {
|
|
2325
|
-
_this2.release();
|
|
2326
|
-
return Mutex_rethrow(_wasThrown, _result);
|
|
2327
|
-
});
|
|
2328
|
-
});
|
|
2329
|
-
} catch (e) {
|
|
2330
|
-
return Promise.reject(e);
|
|
2331
|
-
}
|
|
2332
|
-
}
|
|
2333
|
-
}, {
|
|
2334
|
-
key: "acquire",
|
|
2335
|
-
value: function acquire() {
|
|
2336
|
-
try {
|
|
2337
|
-
var _this4 = this;
|
|
2338
|
-
// Loop necessary for when multiple calls are made to 'acquire' before a 'release' is called, else the call to
|
|
2339
|
-
// 'release' will resume every caller currently waiting on 'acquire'.
|
|
2340
|
-
return Mutex_continue(Mutex_for(function () {
|
|
2341
|
-
return _this4.mutex !== undefined;
|
|
2342
|
-
}, void 0, function () {
|
|
2343
|
-
return Mutex_awaitIgnored(_this4.mutex);
|
|
2344
|
-
}), function () {
|
|
2345
|
-
_this4.mutex = new Promise(function (resolve) {
|
|
2346
|
-
_this4.resolver = resolve;
|
|
2347
|
-
});
|
|
2348
|
-
});
|
|
2349
|
-
} catch (e) {
|
|
2350
|
-
return Promise.reject(e);
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
}, {
|
|
2354
|
-
key: "release",
|
|
2355
|
-
value: function release() {
|
|
2356
|
-
if (this.resolver === undefined) {
|
|
2357
|
-
throw new Error("Unable to release mutex: already released.");
|
|
2358
|
-
}
|
|
2359
|
-
this.resolver();
|
|
2360
|
-
this.resolver = undefined;
|
|
2361
|
-
this.mutex = undefined;
|
|
2362
|
-
}
|
|
2363
|
-
}]);
|
|
2364
|
-
return Mutex;
|
|
2365
|
-
}();
|
|
2366
2450
|
;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
|
|
2367
2451
|
function AuthManagerBrowser_typeof(obj) { "@babel/helpers - typeof"; return AuthManagerBrowser_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, AuthManagerBrowser_typeof(obj); }
|
|
2368
2452
|
function AuthManagerBrowser_defineProperty(obj, key, value) { key = AuthManagerBrowser_toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -2439,38 +2523,30 @@ function AuthManagerBrowser_getPrototypeOf(o) { AuthManagerBrowser_getPrototypeO
|
|
|
2439
2523
|
|
|
2440
2524
|
|
|
2441
2525
|
|
|
2442
|
-
|
|
2443
2526
|
var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
2444
2527
|
AuthManagerBrowser_inherits(AuthManager, _BaseAPI);
|
|
2445
2528
|
var _super = AuthManagerBrowser_createSuper(AuthManager);
|
|
2446
2529
|
function AuthManager(config) {
|
|
2447
2530
|
var _this;
|
|
2448
2531
|
AuthManagerBrowser_classCallCheck(this, AuthManager);
|
|
2449
|
-
var _a, _b;
|
|
2450
2532
|
_this = _super.call(this, config);
|
|
2451
|
-
_this.authSessionMutex = new Mutex();
|
|
2452
2533
|
_this.contentType = "content-type";
|
|
2453
2534
|
_this.contentTypeJson = "application/json";
|
|
2454
2535
|
_this.contentTypeText = "text/plain";
|
|
2455
2536
|
_this.minJwtTtlSeconds = 10;
|
|
2537
|
+
_this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
|
|
2456
2538
|
_this.retryAuthAfterErrorSeconds = 5;
|
|
2457
2539
|
_this.refreshBeforeExpirySeconds = 20;
|
|
2458
|
-
var
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
accountId = (_b = (_a = config.apiKey.split("_")[1]) === null || _a === void 0 ? void 0 : _a.substr(0, BaseAPI.accountIdLength)) !== null && _b !== void 0 ? _b : "";
|
|
2463
|
-
if (accountId.length !== BaseAPI.accountIdLength) {
|
|
2464
|
-
throw new Error("Invalid Bytescale API key.");
|
|
2465
|
-
}
|
|
2466
|
-
}
|
|
2467
|
-
_this.accessTokenUrl = "".concat(BytescaleApiClientConfigResolver.getCdnUrl(config), "/api/v1/access_tokens/").concat(accountId);
|
|
2540
|
+
var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl(config);
|
|
2541
|
+
var accountId = BytescaleApiClientConfigUtils.getAccountId(config);
|
|
2542
|
+
_this.accessTokenUrl = "".concat(cdnUrl, "/api/v1/access_tokens/").concat(accountId);
|
|
2543
|
+
_this.authSessionMutex = AuthSessionState.getMutex();
|
|
2468
2544
|
return _this;
|
|
2469
2545
|
}
|
|
2470
2546
|
AuthManagerBrowser_createClass(AuthManager, [{
|
|
2471
2547
|
key: "isAuthSessionActive",
|
|
2472
2548
|
value: function isAuthSessionActive() {
|
|
2473
|
-
return AuthSessionState.
|
|
2549
|
+
return AuthSessionState.getSession() !== undefined;
|
|
2474
2550
|
}
|
|
2475
2551
|
}, {
|
|
2476
2552
|
key: "beginAuthSession",
|
|
@@ -2489,7 +2565,7 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2489
2565
|
if (_this3.isAuthSessionActive()) {
|
|
2490
2566
|
throw new Error("Auth session already active: see AuthManager.isAuthSessionActive(). Please call 'await endAuthSession()' and then 'await beginAuthSession(...)' if you want to start a new auth session.");
|
|
2491
2567
|
}
|
|
2492
|
-
AuthSessionState.
|
|
2568
|
+
AuthSessionState.setSession(newSession);
|
|
2493
2569
|
return AuthManagerBrowser_await();
|
|
2494
2570
|
})), function () {
|
|
2495
2571
|
// IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
|
|
@@ -2505,11 +2581,11 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2505
2581
|
try {
|
|
2506
2582
|
var _this5 = this;
|
|
2507
2583
|
return AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
2508
|
-
|
|
2584
|
+
var session = AuthSessionState.getSession();
|
|
2585
|
+
if (session === undefined) {
|
|
2509
2586
|
return;
|
|
2510
2587
|
}
|
|
2511
|
-
|
|
2512
|
-
AuthSessionState.session = undefined;
|
|
2588
|
+
AuthSessionState.setSession(undefined);
|
|
2513
2589
|
session.isActive = false;
|
|
2514
2590
|
if (session.accessTokenRefreshHandle !== undefined) {
|
|
2515
2591
|
clearTimeout(session.accessTokenRefreshHandle);
|
|
@@ -2542,6 +2618,8 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2542
2618
|
if (desiredTtl !== timeout) {
|
|
2543
2619
|
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
|
|
2544
2620
|
}
|
|
2621
|
+
// There's need to print a warning for this: it's OK to silently request the JWT before it expires. Also, this is 24 days in this case!
|
|
2622
|
+
timeout = Math.min(timeout, _this7.maxJwtTtlSeconds);
|
|
2545
2623
|
session.accessToken = setTokenResult.accessToken;
|
|
2546
2624
|
});
|
|
2547
2625
|
});
|