@bytescale/sdk 3.0.0-alpha.9 → 3.1.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/README.md +388 -48
- package/dist/browser/cjs/main.js +704 -568
- package/dist/node/cjs/main.js +622 -240
- package/dist/node/esm/main.mjs +622 -240
- package/dist/types/index.d.ts +1 -1
- package/dist/types/private/AuthSessionState.d.ts +25 -8
- package/dist/types/private/EnvChecker.d.ts +1 -1
- package/dist/types/private/Mutex.d.ts +1 -1
- package/dist/types/private/StreamUtils.d.ts +1 -0
- package/dist/types/private/UploadManagerBase.d.ts +6 -1
- package/dist/types/private/UploadManagerBrowserWorkerBase.d.ts +19 -0
- package/dist/types/private/UploadManagerFetchUtils.d.ts +8 -0
- package/dist/types/private/model/AuthManagerInterface.d.ts +22 -5
- package/dist/types/private/model/AuthSession.d.ts +2 -2
- package/dist/types/private/model/OnPartProgress.d.ts +1 -1
- package/dist/types/private/model/UploadSourceProcessed.d.ts +6 -1
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +10 -6
- package/dist/types/public/browser/UploadManagerBrowser.d.ts +3 -12
- package/dist/types/public/node/AuthManagerNode.d.ts +8 -3
- package/dist/types/public/shared/CommonTypes.d.ts +0 -1
- package/dist/types/public/shared/UrlBuilder.d.ts +10 -12
- package/dist/types/public/shared/UrlBuilderTypes.d.ts +0 -6
- package/dist/types/public/shared/generated/runtime.d.ts +7 -5
- package/dist/types/public/worker/UploadManagerWorker.d.ts +8 -0
- package/dist/types/public/worker/index.d.ts +2 -0
- package/dist/worker/cjs/main.js +2578 -0
- package/dist/worker/esm/main.mjs +2578 -0
- package/package.json +7 -4
- package/tests/UploadManager.test.ts +0 -7
- package/tests/UrlBuilder.test.ts +33 -27
package/dist/browser/cjs/main.js
CHANGED
|
@@ -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 size 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
|
}
|
|
@@ -191,72 +507,30 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
191
507
|
this.config = config;
|
|
192
508
|
BytescaleApiClientConfigUtils.validate(config);
|
|
193
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* Returns a successful response (2**) else throws an error.
|
|
512
|
+
*/
|
|
194
513
|
runtime_createClass(BaseAPI, [{
|
|
195
514
|
key: "request",
|
|
196
515
|
value: function request(context, initOverrides, baseUrlOverride) {
|
|
197
516
|
try {
|
|
198
517
|
var _this2 = this;
|
|
199
|
-
var _a
|
|
518
|
+
var _a;
|
|
200
519
|
var apiKey = _this2.config.apiKey;
|
|
201
520
|
context.headers["Authorization"] = "Bearer ".concat(apiKey); // authorization-header authentication
|
|
202
|
-
|
|
203
|
-
|
|
521
|
+
var session = AuthSessionState.getSession();
|
|
522
|
+
if ((session === null || session === void 0 ? void 0 : session.accessToken) !== undefined) {
|
|
523
|
+
context.headers["Authorization-Token"] = session.accessToken;
|
|
204
524
|
}
|
|
205
525
|
// Key: any possible value for 'baseUrlOverride'
|
|
206
526
|
// Value: user-overridden value for that base URL from the config.
|
|
207
527
|
var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this2.config));
|
|
208
|
-
return
|
|
528
|
+
return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
|
|
209
529
|
var url = _ref.url,
|
|
210
530
|
init = _ref.init;
|
|
211
|
-
return
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
return Promise.reject(e);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Returns a successful response (2**) else throws an error.
|
|
219
|
-
*/
|
|
220
|
-
}, {
|
|
221
|
-
key: "doFetch",
|
|
222
|
-
value: function doFetch(url, init, isBytescaleApi) {
|
|
223
|
-
try {
|
|
224
|
-
var _exit3 = false;
|
|
225
|
-
var _this4 = this;
|
|
226
|
-
var _a, _b;
|
|
227
|
-
var response;
|
|
228
|
-
return _continue(_catch(function () {
|
|
229
|
-
return _await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, init), function (_BytescaleApiClientCo) {
|
|
230
|
-
response = _BytescaleApiClientCo;
|
|
231
|
-
});
|
|
232
|
-
}, function (e) {
|
|
233
|
-
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
234
|
-
// HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
|
|
235
|
-
throw new Error(isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
|
|
236
|
-
}), function (_result) {
|
|
237
|
-
var _exit2 = false;
|
|
238
|
-
if (_exit3) return _result;
|
|
239
|
-
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
240
|
-
if (isBytescaleApi) {
|
|
241
|
-
var jsonError = undefined;
|
|
242
|
-
return _continue(_catch(function () {
|
|
243
|
-
return _await(response.json(), function (_response$json) {
|
|
244
|
-
jsonError = _response$json;
|
|
245
|
-
});
|
|
246
|
-
}, _empty), function () {
|
|
247
|
-
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
248
|
-
throw new BytescaleApiError(jsonError);
|
|
249
|
-
}
|
|
250
|
-
// HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
|
|
251
|
-
// this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
|
|
252
|
-
// this error will appear from any intermediary service failure.
|
|
253
|
-
throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
}, function (_result2) {
|
|
257
|
-
if (_exit2) return _result2;
|
|
258
|
-
throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
|
|
259
|
-
});
|
|
531
|
+
return BaseAPI.fetch(url, init, Object.assign(Object.assign({}, _this2.config), {
|
|
532
|
+
isBytescaleApi: true
|
|
533
|
+
}));
|
|
260
534
|
});
|
|
261
535
|
} catch (e) {
|
|
262
536
|
return Promise.reject(e);
|
|
@@ -279,23 +553,23 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
279
553
|
key: "createFetchParams",
|
|
280
554
|
value: function createFetchParams(context, initOverrides, baseUrlOverride) {
|
|
281
555
|
try {
|
|
282
|
-
var
|
|
283
|
-
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(
|
|
556
|
+
var _this4 = this;
|
|
557
|
+
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this4.config)) + context.path;
|
|
284
558
|
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
285
559
|
// only add the querystring to the URL if there are query parameters.
|
|
286
560
|
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
287
561
|
// do not handle correctly sometimes.
|
|
288
562
|
url += "?" + querystring(context.query);
|
|
289
563
|
}
|
|
290
|
-
var configHeaders =
|
|
564
|
+
var configHeaders = _this4.config.headers;
|
|
291
565
|
var _Object$assign3 = Object.assign({}, context.headers);
|
|
292
|
-
return
|
|
566
|
+
return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
|
|
293
567
|
var headers = Object.assign(_Object$assign3, _configHeaders);
|
|
294
568
|
Object.keys(headers).forEach(function (key) {
|
|
295
569
|
return headers[key] === undefined ? delete headers[key] : {};
|
|
296
570
|
});
|
|
297
571
|
var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
|
|
298
|
-
return
|
|
572
|
+
return runtime_await(initOverrides);
|
|
299
573
|
};
|
|
300
574
|
var initParams = {
|
|
301
575
|
method: context.method,
|
|
@@ -303,7 +577,7 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
303
577
|
body: context.body
|
|
304
578
|
};
|
|
305
579
|
var _Object$assign2 = Object.assign({}, initParams);
|
|
306
|
-
return
|
|
580
|
+
return runtime_await(initOverrideFn({
|
|
307
581
|
init: initParams,
|
|
308
582
|
context: context
|
|
309
583
|
}), function (_initOverrideFn) {
|
|
@@ -321,6 +595,59 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
321
595
|
return Promise.reject(e);
|
|
322
596
|
}
|
|
323
597
|
}
|
|
598
|
+
}], [{
|
|
599
|
+
key: "fetch",
|
|
600
|
+
value: function fetch(url, init, config) {
|
|
601
|
+
try {
|
|
602
|
+
var _exit3 = false;
|
|
603
|
+
var _a, _b;
|
|
604
|
+
var response;
|
|
605
|
+
return runtime_continue(_catch(function () {
|
|
606
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(config)(url, Object.assign(Object.assign({}, init), {
|
|
607
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
608
|
+
//
|
|
609
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
610
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
611
|
+
//
|
|
612
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
613
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
614
|
+
cache: "no-store"
|
|
615
|
+
})), function (_BytescaleApiClientCo) {
|
|
616
|
+
response = _BytescaleApiClientCo;
|
|
617
|
+
});
|
|
618
|
+
}, function (e) {
|
|
619
|
+
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
620
|
+
// HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
|
|
621
|
+
throw new Error(config.isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
|
|
622
|
+
}), function (_result) {
|
|
623
|
+
var _exit2 = false;
|
|
624
|
+
if (_exit3) return _result;
|
|
625
|
+
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
626
|
+
if (config.isBytescaleApi) {
|
|
627
|
+
var jsonError = undefined;
|
|
628
|
+
return runtime_continue(_catch(function () {
|
|
629
|
+
return runtime_await(response.json(), function (_response$json) {
|
|
630
|
+
jsonError = _response$json;
|
|
631
|
+
});
|
|
632
|
+
}, runtime_empty), function () {
|
|
633
|
+
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
634
|
+
throw new BytescaleApiError(jsonError);
|
|
635
|
+
}
|
|
636
|
+
// HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
|
|
637
|
+
// this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
|
|
638
|
+
// this error will appear from any intermediary service failure.
|
|
639
|
+
throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
}, function (_result2) {
|
|
643
|
+
if (_exit2) return _result2;
|
|
644
|
+
throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
} catch (e) {
|
|
648
|
+
return Promise.reject(e);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
324
651
|
}]);
|
|
325
652
|
return BaseAPI;
|
|
326
653
|
}();
|
|
@@ -328,11 +655,11 @@ var CancelledError = /*#__PURE__*/function (_Error) {
|
|
|
328
655
|
_inherits(CancelledError, _Error);
|
|
329
656
|
var _super = _createSuper(CancelledError);
|
|
330
657
|
function CancelledError() {
|
|
331
|
-
var
|
|
658
|
+
var _this5;
|
|
332
659
|
runtime_classCallCheck(this, CancelledError);
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
return
|
|
660
|
+
_this5 = _super.call(this, "Operation cancelled by caller.");
|
|
661
|
+
_this5.name = "CancelledError";
|
|
662
|
+
return _this5;
|
|
336
663
|
}
|
|
337
664
|
return runtime_createClass(CancelledError);
|
|
338
665
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -340,13 +667,13 @@ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
|
|
|
340
667
|
_inherits(BytescaleApiError, _Error2);
|
|
341
668
|
var _super2 = _createSuper(BytescaleApiError);
|
|
342
669
|
function BytescaleApiError(response) {
|
|
343
|
-
var
|
|
670
|
+
var _this6;
|
|
344
671
|
runtime_classCallCheck(this, BytescaleApiError);
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return
|
|
672
|
+
_this6 = _super2.call(this, response.error.message);
|
|
673
|
+
_this6.name = "BytescaleApiError";
|
|
674
|
+
_this6.errorCode = response.error.code;
|
|
675
|
+
_this6.details = response.error.details;
|
|
676
|
+
return _this6;
|
|
350
677
|
}
|
|
351
678
|
return runtime_createClass(BytescaleApiError);
|
|
352
679
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -372,8 +699,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
|
|
|
372
699
|
key: "value",
|
|
373
700
|
value: function value() {
|
|
374
701
|
try {
|
|
375
|
-
var
|
|
376
|
-
return
|
|
702
|
+
var _this8 = this;
|
|
703
|
+
return runtime_await(_this8.raw.json());
|
|
377
704
|
} catch (e) {
|
|
378
705
|
return Promise.reject(e);
|
|
379
706
|
}
|
|
@@ -389,7 +716,7 @@ var VoidApiResponse = /*#__PURE__*/function () {
|
|
|
389
716
|
runtime_createClass(VoidApiResponse, [{
|
|
390
717
|
key: "value",
|
|
391
718
|
value: function value() {
|
|
392
|
-
return
|
|
719
|
+
return runtime_await(undefined);
|
|
393
720
|
}
|
|
394
721
|
}]);
|
|
395
722
|
return VoidApiResponse;
|
|
@@ -414,8 +741,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
414
741
|
key: "text",
|
|
415
742
|
value: function text() {
|
|
416
743
|
try {
|
|
417
|
-
var
|
|
418
|
-
return
|
|
744
|
+
var _this10 = this;
|
|
745
|
+
return runtime_await(_this10.raw.text());
|
|
419
746
|
} catch (e) {
|
|
420
747
|
return Promise.reject(e);
|
|
421
748
|
}
|
|
@@ -424,8 +751,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
424
751
|
key: "blob",
|
|
425
752
|
value: function blob() {
|
|
426
753
|
try {
|
|
427
|
-
var
|
|
428
|
-
return
|
|
754
|
+
var _this12 = this;
|
|
755
|
+
return runtime_await(_this12.raw.blob());
|
|
429
756
|
} catch (e) {
|
|
430
757
|
return Promise.reject(e);
|
|
431
758
|
}
|
|
@@ -434,8 +761,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
434
761
|
key: "json",
|
|
435
762
|
value: function json() {
|
|
436
763
|
try {
|
|
437
|
-
var
|
|
438
|
-
return
|
|
764
|
+
var _this14 = this;
|
|
765
|
+
return runtime_await(_this14.raw.json());
|
|
439
766
|
} catch (e) {
|
|
440
767
|
return Promise.reject(e);
|
|
441
768
|
}
|
|
@@ -1360,33 +1687,32 @@ function UrlBuilder_toPrimitive(input, hint) { if (UrlBuilder_typeof(input) !==
|
|
|
1360
1687
|
|
|
1361
1688
|
|
|
1362
1689
|
var UrlBuilder = /*#__PURE__*/function () {
|
|
1363
|
-
function UrlBuilder(
|
|
1690
|
+
function UrlBuilder() {
|
|
1364
1691
|
UrlBuilder_classCallCheck(this, UrlBuilder);
|
|
1365
|
-
var _a;
|
|
1366
|
-
this.cdnUrl = (_a = config === null || config === void 0 ? void 0 : config.cdnUrl) !== null && _a !== void 0 ? _a : BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1367
1692
|
}
|
|
1368
|
-
|
|
1369
|
-
* Builds a URL to either a raw file or a transformed file.
|
|
1370
|
-
*
|
|
1371
|
-
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1372
|
-
*
|
|
1373
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1374
|
-
*
|
|
1375
|
-
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1376
|
-
*
|
|
1377
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1378
|
-
*
|
|
1379
|
-
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1380
|
-
*
|
|
1381
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1382
|
-
*
|
|
1383
|
-
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1384
|
-
*
|
|
1385
|
-
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1386
|
-
*/
|
|
1387
|
-
UrlBuilder_createClass(UrlBuilder, [{
|
|
1693
|
+
UrlBuilder_createClass(UrlBuilder, null, [{
|
|
1388
1694
|
key: "url",
|
|
1389
|
-
value:
|
|
1695
|
+
value:
|
|
1696
|
+
/**
|
|
1697
|
+
* Builds a URL to either a raw file or a transformed file.
|
|
1698
|
+
*
|
|
1699
|
+
* Example 1) Getting a publicly-accessible raw file URL:
|
|
1700
|
+
*
|
|
1701
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg" })
|
|
1702
|
+
*
|
|
1703
|
+
* Example 2) Getting a publicly-accessible image URL, resized to 500x500:
|
|
1704
|
+
*
|
|
1705
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } } } })
|
|
1706
|
+
*
|
|
1707
|
+
* Example 3) Getting a privately-accessible image URL, resized to 500x500 (requires 'AuthManager.beginAuthSession' to be called before accessing the URL):
|
|
1708
|
+
*
|
|
1709
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "image", params: { w: 500, h: 500, fit: "crop" } }, auth: true } })
|
|
1710
|
+
*
|
|
1711
|
+
* Example 4) Getting a publicly-accessible image URL, resized using a transformation preset called "thumbnail" that was created manually in the Bytescale Dashboard:
|
|
1712
|
+
*
|
|
1713
|
+
* new UrlBuilder().url({ accountId: "1234abc", filePath: "/example.jpg", options: { transformation: { type: "preset", preset: "thumbnail" } } })
|
|
1714
|
+
*/
|
|
1715
|
+
function url(params) {
|
|
1390
1716
|
var _a;
|
|
1391
1717
|
return ((_a = params.options) === null || _a === void 0 ? void 0 : _a.transformation) === undefined ? this.raw(params) : this.transformation(params, params.options);
|
|
1392
1718
|
}
|
|
@@ -1412,7 +1738,8 @@ var UrlBuilder = /*#__PURE__*/function () {
|
|
|
1412
1738
|
}, {
|
|
1413
1739
|
key: "getBaseUrl",
|
|
1414
1740
|
value: function getBaseUrl(params, prefix) {
|
|
1415
|
-
|
|
1741
|
+
var cdnUrl = BytescaleApiClientConfigUtils.defaultCdnUrl;
|
|
1742
|
+
return "".concat(cdnUrl, "/").concat(params.accountId, "/").concat(prefix).concat(params.filePath);
|
|
1416
1743
|
}
|
|
1417
1744
|
}, {
|
|
1418
1745
|
key: "getCommonTransformationQueryParams",
|
|
@@ -1507,21 +1834,21 @@ function _invokeIgnored(body) {
|
|
|
1507
1834
|
return result.then(UploadManagerBase_empty);
|
|
1508
1835
|
}
|
|
1509
1836
|
}
|
|
1510
|
-
function
|
|
1837
|
+
function UploadManagerBase_settle(pact, state, value) {
|
|
1511
1838
|
if (!pact.s) {
|
|
1512
|
-
if (value instanceof
|
|
1839
|
+
if (value instanceof UploadManagerBase_Pact) {
|
|
1513
1840
|
if (value.s) {
|
|
1514
1841
|
if (state & 1) {
|
|
1515
1842
|
state = value.s;
|
|
1516
1843
|
}
|
|
1517
1844
|
value = value.v;
|
|
1518
1845
|
} else {
|
|
1519
|
-
value.o =
|
|
1846
|
+
value.o = UploadManagerBase_settle.bind(null, pact, state);
|
|
1520
1847
|
return;
|
|
1521
1848
|
}
|
|
1522
1849
|
}
|
|
1523
1850
|
if (value && value.then) {
|
|
1524
|
-
value.then(
|
|
1851
|
+
value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
|
|
1525
1852
|
return;
|
|
1526
1853
|
}
|
|
1527
1854
|
pact.s = state;
|
|
@@ -1532,7 +1859,7 @@ function _settle(pact, state, value) {
|
|
|
1532
1859
|
}
|
|
1533
1860
|
}
|
|
1534
1861
|
}
|
|
1535
|
-
var
|
|
1862
|
+
var UploadManagerBase_Pact = /*#__PURE__*/function () {
|
|
1536
1863
|
function _Pact() {}
|
|
1537
1864
|
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
1538
1865
|
var result = new _Pact();
|
|
@@ -1541,9 +1868,9 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
1541
1868
|
var callback = state & 1 ? onFulfilled : onRejected;
|
|
1542
1869
|
if (callback) {
|
|
1543
1870
|
try {
|
|
1544
|
-
|
|
1871
|
+
UploadManagerBase_settle(result, 1, callback(this.v));
|
|
1545
1872
|
} catch (e) {
|
|
1546
|
-
|
|
1873
|
+
UploadManagerBase_settle(result, 2, e);
|
|
1547
1874
|
}
|
|
1548
1875
|
return result;
|
|
1549
1876
|
} else {
|
|
@@ -1554,28 +1881,28 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
1554
1881
|
try {
|
|
1555
1882
|
var value = _this.v;
|
|
1556
1883
|
if (_this.s & 1) {
|
|
1557
|
-
|
|
1884
|
+
UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
1558
1885
|
} else if (onRejected) {
|
|
1559
|
-
|
|
1886
|
+
UploadManagerBase_settle(result, 1, onRejected(value));
|
|
1560
1887
|
} else {
|
|
1561
|
-
|
|
1888
|
+
UploadManagerBase_settle(result, 2, value);
|
|
1562
1889
|
}
|
|
1563
1890
|
} catch (e) {
|
|
1564
|
-
|
|
1891
|
+
UploadManagerBase_settle(result, 2, e);
|
|
1565
1892
|
}
|
|
1566
1893
|
};
|
|
1567
1894
|
return result;
|
|
1568
1895
|
};
|
|
1569
1896
|
return _Pact;
|
|
1570
1897
|
}();
|
|
1571
|
-
function
|
|
1572
|
-
return thenable instanceof
|
|
1898
|
+
function UploadManagerBase_isSettledPact(thenable) {
|
|
1899
|
+
return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
|
|
1573
1900
|
}
|
|
1574
|
-
function
|
|
1901
|
+
function UploadManagerBase_for(test, update, body) {
|
|
1575
1902
|
var stage;
|
|
1576
1903
|
for (;;) {
|
|
1577
1904
|
var shouldContinue = test();
|
|
1578
|
-
if (
|
|
1905
|
+
if (UploadManagerBase_isSettledPact(shouldContinue)) {
|
|
1579
1906
|
shouldContinue = shouldContinue.v;
|
|
1580
1907
|
}
|
|
1581
1908
|
if (!shouldContinue) {
|
|
@@ -1587,7 +1914,7 @@ function _for(test, update, body) {
|
|
|
1587
1914
|
}
|
|
1588
1915
|
var result = body();
|
|
1589
1916
|
if (result && result.then) {
|
|
1590
|
-
if (
|
|
1917
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
1591
1918
|
result = result.s;
|
|
1592
1919
|
} else {
|
|
1593
1920
|
stage = 1;
|
|
@@ -1596,14 +1923,14 @@ function _for(test, update, body) {
|
|
|
1596
1923
|
}
|
|
1597
1924
|
if (update) {
|
|
1598
1925
|
var updateValue = update();
|
|
1599
|
-
if (updateValue && updateValue.then && !
|
|
1926
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
1600
1927
|
stage = 2;
|
|
1601
1928
|
break;
|
|
1602
1929
|
}
|
|
1603
1930
|
}
|
|
1604
1931
|
}
|
|
1605
|
-
var pact = new
|
|
1606
|
-
var reject =
|
|
1932
|
+
var pact = new UploadManagerBase_Pact();
|
|
1933
|
+
var reject = UploadManagerBase_settle.bind(null, pact, 2);
|
|
1607
1934
|
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
1608
1935
|
return pact;
|
|
1609
1936
|
function _resumeAfterBody(value) {
|
|
@@ -1611,14 +1938,14 @@ function _for(test, update, body) {
|
|
|
1611
1938
|
do {
|
|
1612
1939
|
if (update) {
|
|
1613
1940
|
updateValue = update();
|
|
1614
|
-
if (updateValue && updateValue.then && !
|
|
1941
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
1615
1942
|
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
1616
1943
|
return;
|
|
1617
1944
|
}
|
|
1618
1945
|
}
|
|
1619
1946
|
shouldContinue = test();
|
|
1620
|
-
if (!shouldContinue ||
|
|
1621
|
-
|
|
1947
|
+
if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
1948
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1622
1949
|
return;
|
|
1623
1950
|
}
|
|
1624
1951
|
if (shouldContinue.then) {
|
|
@@ -1626,7 +1953,7 @@ function _for(test, update, body) {
|
|
|
1626
1953
|
return;
|
|
1627
1954
|
}
|
|
1628
1955
|
result = body();
|
|
1629
|
-
if (
|
|
1956
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
1630
1957
|
result = result.v;
|
|
1631
1958
|
}
|
|
1632
1959
|
} while (!result || !result.then);
|
|
@@ -1641,7 +1968,7 @@ function _for(test, update, body) {
|
|
|
1641
1968
|
_resumeAfterBody(result);
|
|
1642
1969
|
}
|
|
1643
1970
|
} else {
|
|
1644
|
-
|
|
1971
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1645
1972
|
}
|
|
1646
1973
|
}
|
|
1647
1974
|
function _resumeAfterUpdate() {
|
|
@@ -1652,7 +1979,7 @@ function _for(test, update, body) {
|
|
|
1652
1979
|
_resumeAfterTest(shouldContinue);
|
|
1653
1980
|
}
|
|
1654
1981
|
} else {
|
|
1655
|
-
|
|
1982
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
1656
1983
|
}
|
|
1657
1984
|
}
|
|
1658
1985
|
}
|
|
@@ -1668,7 +1995,7 @@ function UploadManagerBase_iterableToArray(iter) { if (typeof Symbol !== "undefi
|
|
|
1668
1995
|
function UploadManagerBase_arrayWithoutHoles(arr) { if (Array.isArray(arr)) return UploadManagerBase_arrayLikeToArray(arr); }
|
|
1669
1996
|
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; }
|
|
1670
1997
|
function UploadManagerBase_empty() {}
|
|
1671
|
-
function
|
|
1998
|
+
function UploadManagerBase_awaitIgnored(value, direct) {
|
|
1672
1999
|
if (!direct) {
|
|
1673
2000
|
return value && value.then ? value.then(UploadManagerBase_empty) : Promise.resolve();
|
|
1674
2001
|
}
|
|
@@ -1682,11 +2009,11 @@ function UploadManagerBase_await(value, then, direct) {
|
|
|
1682
2009
|
}
|
|
1683
2010
|
return then ? value.then(then) : value;
|
|
1684
2011
|
}
|
|
1685
|
-
function
|
|
2012
|
+
function UploadManagerBase_rethrow(thrown, value) {
|
|
1686
2013
|
if (thrown) throw value;
|
|
1687
2014
|
return value;
|
|
1688
2015
|
}
|
|
1689
|
-
function
|
|
2016
|
+
function UploadManagerBase_finallyRethrows(body, finalizer) {
|
|
1690
2017
|
try {
|
|
1691
2018
|
var result = body();
|
|
1692
2019
|
} catch (e) {
|
|
@@ -1717,6 +2044,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1717
2044
|
this.defaultMaxConcurrentUploadParts = 4;
|
|
1718
2045
|
this.intervalMs = 500;
|
|
1719
2046
|
this.uploadApi = new UploadApi(config);
|
|
2047
|
+
this.accountId = BytescaleApiClientConfigUtils.getAccountId(config);
|
|
1720
2048
|
}
|
|
1721
2049
|
UploadManagerBase_createClass(UploadManagerBase, [{
|
|
1722
2050
|
key: "upload",
|
|
@@ -1726,10 +2054,13 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1726
2054
|
_this2.assertNotCancelled(request);
|
|
1727
2055
|
var source = _this2.processUploadSource(request.data);
|
|
1728
2056
|
var preUploadInfo = _this2.getPreUploadInfo(request, source);
|
|
1729
|
-
var
|
|
2057
|
+
var bytesTotal = preUploadInfo.size;
|
|
2058
|
+
var makeOnProgressForPart = _this2.makeOnProgressForPartFactory(request, bytesTotal);
|
|
1730
2059
|
var init = _this2.preUpload(source);
|
|
1731
2060
|
// Raise initial progress event SYNCHRONOUSLY.
|
|
1732
|
-
onProgress
|
|
2061
|
+
if (request.onProgress !== undefined) {
|
|
2062
|
+
request.onProgress(_this2.makeProgressEvent(0, bytesTotal));
|
|
2063
|
+
}
|
|
1733
2064
|
return UploadManagerBase_await(_this2.beginUpload(request, preUploadInfo), function (uploadInfo) {
|
|
1734
2065
|
var partCount = uploadInfo.uploadParts.count;
|
|
1735
2066
|
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
@@ -1737,15 +2068,15 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1737
2068
|
cancel = _this2$makeCancellati.cancel,
|
|
1738
2069
|
addCancellationHandler = _this2$makeCancellati.addCancellationHandler;
|
|
1739
2070
|
var intervalHandle = setInterval(_this2.onIntervalTick(request, cancel), _this2.intervalMs);
|
|
1740
|
-
return UploadManagerBase_continue(
|
|
2071
|
+
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
1741
2072
|
return UploadManagerBase_await(_this2.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
1742
|
-
return _this2.uploadPart(request, source, part, uploadInfo,
|
|
2073
|
+
return _this2.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler);
|
|
1743
2074
|
})), function () {
|
|
1744
|
-
return
|
|
2075
|
+
return UploadManagerBase_awaitIgnored(_this2.postUpload(init));
|
|
1745
2076
|
});
|
|
1746
2077
|
}, function (_wasThrown, _result) {
|
|
1747
2078
|
clearInterval(intervalHandle);
|
|
1748
|
-
return
|
|
2079
|
+
return UploadManagerBase_rethrow(_wasThrown, _result);
|
|
1749
2080
|
}), function () {
|
|
1750
2081
|
return uploadInfo.file;
|
|
1751
2082
|
});
|
|
@@ -1795,21 +2126,37 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1795
2126
|
addCancellationHandler: addCancellationHandler
|
|
1796
2127
|
};
|
|
1797
2128
|
}
|
|
2129
|
+
/**
|
|
2130
|
+
* Returns a callback, which when called, returns a callback that can be used by ONE specific part to report its progress.
|
|
2131
|
+
*/
|
|
1798
2132
|
}, {
|
|
1799
|
-
key: "
|
|
1800
|
-
value: function
|
|
2133
|
+
key: "makeOnProgressForPartFactory",
|
|
2134
|
+
value: function makeOnProgressForPartFactory(request, bytesTotal) {
|
|
2135
|
+
var _this4 = this;
|
|
1801
2136
|
var onProgress = request.onProgress;
|
|
1802
2137
|
if (onProgress === undefined) {
|
|
1803
|
-
return function () {
|
|
2138
|
+
return function () {
|
|
2139
|
+
return function () {};
|
|
2140
|
+
};
|
|
1804
2141
|
}
|
|
1805
2142
|
var bytesSent = 0;
|
|
1806
|
-
return function (
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
2143
|
+
return function () {
|
|
2144
|
+
var bytesSentForPart = 0;
|
|
2145
|
+
return function (bytesSentTotalForPart) {
|
|
2146
|
+
var delta = bytesSentTotalForPart - bytesSentForPart;
|
|
2147
|
+
bytesSentForPart += delta;
|
|
2148
|
+
bytesSent += delta;
|
|
2149
|
+
onProgress(_this4.makeProgressEvent(bytesSent, bytesTotal));
|
|
2150
|
+
};
|
|
2151
|
+
};
|
|
2152
|
+
}
|
|
2153
|
+
}, {
|
|
2154
|
+
key: "makeProgressEvent",
|
|
2155
|
+
value: function makeProgressEvent(bytesSent, bytesTotal) {
|
|
2156
|
+
return {
|
|
2157
|
+
bytesTotal: bytesTotal,
|
|
2158
|
+
bytesSent: bytesSent,
|
|
2159
|
+
progress: Math.round(bytesSent / bytesTotal * 100)
|
|
1813
2160
|
};
|
|
1814
2161
|
}
|
|
1815
2162
|
}, {
|
|
@@ -1832,9 +2179,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1832
2179
|
mime = _ref2.mime,
|
|
1833
2180
|
originalFileName = _ref2.originalFileName;
|
|
1834
2181
|
try {
|
|
1835
|
-
var
|
|
1836
|
-
return UploadManagerBase_await(
|
|
1837
|
-
accountId:
|
|
2182
|
+
var _this6 = this;
|
|
2183
|
+
return UploadManagerBase_await(_this6.uploadApi.beginMultipartUpload({
|
|
2184
|
+
accountId: _this6.accountId,
|
|
1838
2185
|
beginMultipartUploadRequest: {
|
|
1839
2186
|
metadata: request.metadata,
|
|
1840
2187
|
mime: mime,
|
|
@@ -1853,14 +2200,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1853
2200
|
key: "uploadPart",
|
|
1854
2201
|
value: function uploadPart(request, source, partIndex, uploadInfo, onProgress, addCancellationHandler) {
|
|
1855
2202
|
try {
|
|
1856
|
-
var
|
|
1857
|
-
|
|
1858
|
-
return UploadManagerBase_await(
|
|
1859
|
-
|
|
1860
|
-
return UploadManagerBase_await(
|
|
1861
|
-
|
|
1862
|
-
return
|
|
1863
|
-
accountId:
|
|
2203
|
+
var _this8 = this;
|
|
2204
|
+
_this8.assertNotCancelled(request);
|
|
2205
|
+
return UploadManagerBase_await(_this8.getUploadPart(partIndex, uploadInfo), function (part) {
|
|
2206
|
+
_this8.assertNotCancelled(request);
|
|
2207
|
+
return UploadManagerBase_await(_this8.putUploadPart(part, source, onProgress, addCancellationHandler), function (etag) {
|
|
2208
|
+
_this8.assertNotCancelled(request);
|
|
2209
|
+
return UploadManagerBase_awaitIgnored(_this8.uploadApi.completeUploadPart({
|
|
2210
|
+
accountId: _this8.accountId,
|
|
1864
2211
|
uploadId: uploadInfo.uploadId,
|
|
1865
2212
|
uploadPartIndex: partIndex,
|
|
1866
2213
|
completeUploadPartRequest: {
|
|
@@ -1880,9 +2227,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1880
2227
|
key: "putUploadPart",
|
|
1881
2228
|
value: function putUploadPart(part, source, onProgress, addCancellationHandler) {
|
|
1882
2229
|
try {
|
|
1883
|
-
var
|
|
2230
|
+
var _this10 = this;
|
|
1884
2231
|
var contentLength = part.range.inclusiveEnd + 1 - part.range.inclusiveStart;
|
|
1885
|
-
return UploadManagerBase_await(
|
|
2232
|
+
return UploadManagerBase_await(_this10.doPutUploadPart(part, contentLength, source, onProgress, addCancellationHandler), function (_ref3) {
|
|
1886
2233
|
var status = _ref3.status,
|
|
1887
2234
|
etag = _ref3.etag;
|
|
1888
2235
|
if (Math.floor(status / 100) !== 2) {
|
|
@@ -1891,6 +2238,8 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1891
2238
|
if (etag === undefined) {
|
|
1892
2239
|
throw new Error("No 'etag' response header found in upload part response.");
|
|
1893
2240
|
}
|
|
2241
|
+
// Always send 100% for part, as some UploadManager implementations either don't report progress, or may not report the last chunk uploaded.
|
|
2242
|
+
onProgress(contentLength);
|
|
1894
2243
|
return etag;
|
|
1895
2244
|
});
|
|
1896
2245
|
} catch (e) {
|
|
@@ -1899,15 +2248,15 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1899
2248
|
}
|
|
1900
2249
|
}, {
|
|
1901
2250
|
key: "getUploadPart",
|
|
1902
|
-
value: function getUploadPart(
|
|
2251
|
+
value: function getUploadPart(partIndex, uploadInfo) {
|
|
1903
2252
|
try {
|
|
1904
|
-
var
|
|
2253
|
+
var _this12 = this;
|
|
1905
2254
|
if (partIndex === 0) {
|
|
1906
2255
|
return uploadInfo.uploadParts.first;
|
|
1907
2256
|
}
|
|
1908
|
-
return UploadManagerBase_await(
|
|
2257
|
+
return UploadManagerBase_await(_this12.uploadApi.getUploadPart({
|
|
1909
2258
|
uploadId: uploadInfo.uploadId,
|
|
1910
|
-
accountId:
|
|
2259
|
+
accountId: _this12.accountId,
|
|
1911
2260
|
uploadPartIndex: partIndex
|
|
1912
2261
|
}));
|
|
1913
2262
|
} catch (e) {
|
|
@@ -1931,14 +2280,14 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1931
2280
|
value: function mapAsync(items, concurrency, callback) {
|
|
1932
2281
|
try {
|
|
1933
2282
|
var workQueue = UploadManagerBase_toConsumableArray(items);
|
|
1934
|
-
return
|
|
1935
|
-
return _continueIgnored(
|
|
2283
|
+
return UploadManagerBase_awaitIgnored(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
|
|
2284
|
+
return _continueIgnored(UploadManagerBase_for(function () {
|
|
1936
2285
|
return workQueue.length > 0;
|
|
1937
2286
|
}, void 0, function () {
|
|
1938
2287
|
var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
|
|
1939
2288
|
return _invokeIgnored(function () {
|
|
1940
2289
|
if (work !== undefined) {
|
|
1941
|
-
return
|
|
2290
|
+
return UploadManagerBase_awaitIgnored(callback(work));
|
|
1942
2291
|
}
|
|
1943
2292
|
});
|
|
1944
2293
|
}));
|
|
@@ -1950,9 +2299,9 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
1950
2299
|
}]);
|
|
1951
2300
|
return UploadManagerBase;
|
|
1952
2301
|
}();
|
|
1953
|
-
;// CONCATENATED MODULE: ./src/
|
|
1954
|
-
function
|
|
1955
|
-
function
|
|
2302
|
+
;// CONCATENATED MODULE: ./src/private/UploadManagerBrowserWorkerBase.ts
|
|
2303
|
+
function UploadManagerBrowserWorkerBase_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerBrowserWorkerBase_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; }, UploadManagerBrowserWorkerBase_typeof(obj); }
|
|
2304
|
+
function UploadManagerBrowserWorkerBase_await(value, then, direct) {
|
|
1956
2305
|
if (direct) {
|
|
1957
2306
|
return then ? then(value) : value;
|
|
1958
2307
|
}
|
|
@@ -1961,44 +2310,31 @@ function UploadManagerBrowser_await(value, then, direct) {
|
|
|
1961
2310
|
}
|
|
1962
2311
|
return then ? value.then(then) : value;
|
|
1963
2312
|
}
|
|
1964
|
-
function
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
}
|
|
1968
|
-
function
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
}
|
|
1977
|
-
return finalizer(false, result);
|
|
1978
|
-
}
|
|
1979
|
-
function UploadManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
1980
|
-
function UploadManagerBrowser_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, UploadManagerBrowser_toPropertyKey(descriptor.key), descriptor); } }
|
|
1981
|
-
function UploadManagerBrowser_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerBrowser_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerBrowser_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
1982
|
-
function UploadManagerBrowser_toPropertyKey(arg) { var key = UploadManagerBrowser_toPrimitive(arg, "string"); return UploadManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
|
|
1983
|
-
function UploadManagerBrowser_toPrimitive(input, hint) { if (UploadManagerBrowser_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerBrowser_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1984
|
-
function UploadManagerBrowser_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) UploadManagerBrowser_setPrototypeOf(subClass, superClass); }
|
|
1985
|
-
function UploadManagerBrowser_setPrototypeOf(o, p) { UploadManagerBrowser_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadManagerBrowser_setPrototypeOf(o, p); }
|
|
1986
|
-
function UploadManagerBrowser_createSuper(Derived) { var hasNativeReflectConstruct = UploadManagerBrowser_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadManagerBrowser_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadManagerBrowser_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadManagerBrowser_possibleConstructorReturn(this, result); }; }
|
|
1987
|
-
function UploadManagerBrowser_possibleConstructorReturn(self, call) { if (call && (UploadManagerBrowser_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return UploadManagerBrowser_assertThisInitialized(self); }
|
|
1988
|
-
function UploadManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1989
|
-
function UploadManagerBrowser_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; } }
|
|
1990
|
-
function UploadManagerBrowser_getPrototypeOf(o) { UploadManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerBrowser_getPrototypeOf(o); }
|
|
1991
|
-
|
|
2313
|
+
function UploadManagerBrowserWorkerBase_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2314
|
+
function UploadManagerBrowserWorkerBase_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, UploadManagerBrowserWorkerBase_toPropertyKey(descriptor.key), descriptor); } }
|
|
2315
|
+
function UploadManagerBrowserWorkerBase_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerBrowserWorkerBase_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerBrowserWorkerBase_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
2316
|
+
function UploadManagerBrowserWorkerBase_toPropertyKey(arg) { var key = UploadManagerBrowserWorkerBase_toPrimitive(arg, "string"); return UploadManagerBrowserWorkerBase_typeof(key) === "symbol" ? key : String(key); }
|
|
2317
|
+
function UploadManagerBrowserWorkerBase_toPrimitive(input, hint) { if (UploadManagerBrowserWorkerBase_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerBrowserWorkerBase_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
2318
|
+
function UploadManagerBrowserWorkerBase_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) UploadManagerBrowserWorkerBase_setPrototypeOf(subClass, superClass); }
|
|
2319
|
+
function UploadManagerBrowserWorkerBase_setPrototypeOf(o, p) { UploadManagerBrowserWorkerBase_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadManagerBrowserWorkerBase_setPrototypeOf(o, p); }
|
|
2320
|
+
function UploadManagerBrowserWorkerBase_createSuper(Derived) { var hasNativeReflectConstruct = UploadManagerBrowserWorkerBase_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadManagerBrowserWorkerBase_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadManagerBrowserWorkerBase_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadManagerBrowserWorkerBase_possibleConstructorReturn(this, result); }; }
|
|
2321
|
+
function UploadManagerBrowserWorkerBase_possibleConstructorReturn(self, call) { if (call && (UploadManagerBrowserWorkerBase_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return UploadManagerBrowserWorkerBase_assertThisInitialized(self); }
|
|
2322
|
+
function UploadManagerBrowserWorkerBase_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
2323
|
+
function UploadManagerBrowserWorkerBase_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; } }
|
|
2324
|
+
function UploadManagerBrowserWorkerBase_getPrototypeOf(o) { UploadManagerBrowserWorkerBase_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerBrowserWorkerBase_getPrototypeOf(o); }
|
|
1992
2325
|
|
|
1993
2326
|
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2327
|
+
/**
|
|
2328
|
+
* The "browser" and "worker" runtimes support the same input types, but the former uses XHR and the latter uses Fetch.
|
|
2329
|
+
*/
|
|
2330
|
+
var UploadManagerBrowserWorkerBase = /*#__PURE__*/function (_UploadManagerBase) {
|
|
2331
|
+
UploadManagerBrowserWorkerBase_inherits(UploadManagerBrowserWorkerBase, _UploadManagerBase);
|
|
2332
|
+
var _super = UploadManagerBrowserWorkerBase_createSuper(UploadManagerBrowserWorkerBase);
|
|
2333
|
+
function UploadManagerBrowserWorkerBase() {
|
|
2334
|
+
UploadManagerBrowserWorkerBase_classCallCheck(this, UploadManagerBrowserWorkerBase);
|
|
1999
2335
|
return _super.apply(this, arguments);
|
|
2000
2336
|
}
|
|
2001
|
-
|
|
2337
|
+
UploadManagerBrowserWorkerBase_createClass(UploadManagerBrowserWorkerBase, [{
|
|
2002
2338
|
key: "processUploadSource",
|
|
2003
2339
|
value: function processUploadSource(data) {
|
|
2004
2340
|
if (typeof data === "string") {
|
|
@@ -2010,13 +2346,19 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2010
2346
|
})
|
|
2011
2347
|
};
|
|
2012
2348
|
}
|
|
2349
|
+
if (data.byteLength !== undefined) {
|
|
2350
|
+
return {
|
|
2351
|
+
type: "ArrayBuffer",
|
|
2352
|
+
value: data
|
|
2353
|
+
};
|
|
2354
|
+
}
|
|
2013
2355
|
if (data.size !== undefined) {
|
|
2014
2356
|
return {
|
|
2015
2357
|
type: "Blob",
|
|
2016
2358
|
value: data
|
|
2017
2359
|
};
|
|
2018
2360
|
}
|
|
2019
|
-
throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, or File object (from a file input element).");
|
|
2361
|
+
throw new Error("Unsupported type for 'data' parameter. Please provide a String, Blob, ArrayBuffer, or File object (from a file input element).");
|
|
2020
2362
|
}
|
|
2021
2363
|
}, {
|
|
2022
2364
|
key: "getPreUploadInfoPartial",
|
|
@@ -2024,8 +2366,15 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2024
2366
|
switch (data.type) {
|
|
2025
2367
|
case "Blob":
|
|
2026
2368
|
return this.getBlobInfo(data);
|
|
2369
|
+
case "ArrayBuffer":
|
|
2370
|
+
return {
|
|
2371
|
+
mime: undefined,
|
|
2372
|
+
size: data.value.byteLength,
|
|
2373
|
+
originalFileName: undefined,
|
|
2374
|
+
maxConcurrentUploadParts: undefined
|
|
2375
|
+
};
|
|
2027
2376
|
default:
|
|
2028
|
-
assertUnreachable(data
|
|
2377
|
+
assertUnreachable(data);
|
|
2029
2378
|
}
|
|
2030
2379
|
}
|
|
2031
2380
|
}, {
|
|
@@ -2036,11 +2385,66 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2036
2385
|
}, {
|
|
2037
2386
|
key: "postUpload",
|
|
2038
2387
|
value: function postUpload(_init) {
|
|
2039
|
-
return
|
|
2388
|
+
return UploadManagerBrowserWorkerBase_await();
|
|
2040
2389
|
} // NO-OP.
|
|
2041
2390
|
}, {
|
|
2391
|
+
key: "getRequestBody",
|
|
2392
|
+
value: function getRequestBody(part, blob) {
|
|
2393
|
+
return part.range.inclusiveEnd === -1 ? new Blob() : blob.value.slice(part.range.inclusiveStart, part.range.inclusiveEnd + 1);
|
|
2394
|
+
}
|
|
2395
|
+
}]);
|
|
2396
|
+
return UploadManagerBrowserWorkerBase;
|
|
2397
|
+
}(UploadManagerBase);
|
|
2398
|
+
;// CONCATENATED MODULE: ./src/public/browser/UploadManagerBrowser.ts
|
|
2399
|
+
function UploadManagerBrowser_typeof(obj) { "@babel/helpers - typeof"; return UploadManagerBrowser_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; }, UploadManagerBrowser_typeof(obj); }
|
|
2400
|
+
function UploadManagerBrowser_await(value, then, direct) {
|
|
2401
|
+
if (direct) {
|
|
2402
|
+
return then ? then(value) : value;
|
|
2403
|
+
}
|
|
2404
|
+
if (!value || !value.then) {
|
|
2405
|
+
value = Promise.resolve(value);
|
|
2406
|
+
}
|
|
2407
|
+
return then ? value.then(then) : value;
|
|
2408
|
+
}
|
|
2409
|
+
function UploadManagerBrowser_rethrow(thrown, value) {
|
|
2410
|
+
if (thrown) throw value;
|
|
2411
|
+
return value;
|
|
2412
|
+
}
|
|
2413
|
+
function UploadManagerBrowser_finallyRethrows(body, finalizer) {
|
|
2414
|
+
try {
|
|
2415
|
+
var result = body();
|
|
2416
|
+
} catch (e) {
|
|
2417
|
+
return finalizer(true, e);
|
|
2418
|
+
}
|
|
2419
|
+
if (result && result.then) {
|
|
2420
|
+
return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
|
|
2421
|
+
}
|
|
2422
|
+
return finalizer(false, result);
|
|
2423
|
+
}
|
|
2424
|
+
function UploadManagerBrowser_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2425
|
+
function UploadManagerBrowser_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, UploadManagerBrowser_toPropertyKey(descriptor.key), descriptor); } }
|
|
2426
|
+
function UploadManagerBrowser_createClass(Constructor, protoProps, staticProps) { if (protoProps) UploadManagerBrowser_defineProperties(Constructor.prototype, protoProps); if (staticProps) UploadManagerBrowser_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
2427
|
+
function UploadManagerBrowser_toPropertyKey(arg) { var key = UploadManagerBrowser_toPrimitive(arg, "string"); return UploadManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
|
|
2428
|
+
function UploadManagerBrowser_toPrimitive(input, hint) { if (UploadManagerBrowser_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (UploadManagerBrowser_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
2429
|
+
function UploadManagerBrowser_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) UploadManagerBrowser_setPrototypeOf(subClass, superClass); }
|
|
2430
|
+
function UploadManagerBrowser_setPrototypeOf(o, p) { UploadManagerBrowser_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return UploadManagerBrowser_setPrototypeOf(o, p); }
|
|
2431
|
+
function UploadManagerBrowser_createSuper(Derived) { var hasNativeReflectConstruct = UploadManagerBrowser_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = UploadManagerBrowser_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = UploadManagerBrowser_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return UploadManagerBrowser_possibleConstructorReturn(this, result); }; }
|
|
2432
|
+
function UploadManagerBrowser_possibleConstructorReturn(self, call) { if (call && (UploadManagerBrowser_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return UploadManagerBrowser_assertThisInitialized(self); }
|
|
2433
|
+
function UploadManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
2434
|
+
function UploadManagerBrowser_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; } }
|
|
2435
|
+
function UploadManagerBrowser_getPrototypeOf(o) { UploadManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return UploadManagerBrowser_getPrototypeOf(o); }
|
|
2436
|
+
|
|
2437
|
+
|
|
2438
|
+
var UploadManager = /*#__PURE__*/function (_UploadManagerBrowser) {
|
|
2439
|
+
UploadManagerBrowser_inherits(UploadManager, _UploadManagerBrowser);
|
|
2440
|
+
var _super = UploadManagerBrowser_createSuper(UploadManager);
|
|
2441
|
+
function UploadManager() {
|
|
2442
|
+
UploadManagerBrowser_classCallCheck(this, UploadManager);
|
|
2443
|
+
return _super.apply(this, arguments);
|
|
2444
|
+
}
|
|
2445
|
+
UploadManagerBrowser_createClass(UploadManager, [{
|
|
2042
2446
|
key: "doPutUploadPart",
|
|
2043
|
-
value: function doPutUploadPart(part,
|
|
2447
|
+
value: function doPutUploadPart(part, _contentLength, source, onProgress, addCancellationHandler) {
|
|
2044
2448
|
try {
|
|
2045
2449
|
var _this2 = this;
|
|
2046
2450
|
var xhr = new XMLHttpRequest();
|
|
@@ -2050,23 +2454,15 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2050
2454
|
xhr.abort();
|
|
2051
2455
|
}
|
|
2052
2456
|
});
|
|
2053
|
-
var lastBytesSent = 0;
|
|
2054
|
-
var setBytesSent = function setBytesSent(newBytesSent) {
|
|
2055
|
-
var delta = newBytesSent - lastBytesSent;
|
|
2056
|
-
lastBytesSent = newBytesSent;
|
|
2057
|
-
onProgress(delta);
|
|
2058
|
-
};
|
|
2059
2457
|
return UploadManagerBrowser_finallyRethrows(function () {
|
|
2060
2458
|
return UploadManagerBrowser_await(new Promise(function (resolve, reject) {
|
|
2061
2459
|
xhr.upload.addEventListener("progress", function (evt) {
|
|
2062
2460
|
if (evt.lengthComputable) {
|
|
2063
|
-
|
|
2461
|
+
onProgress(evt.loaded);
|
|
2064
2462
|
}
|
|
2065
2463
|
}, false);
|
|
2066
2464
|
xhr.addEventListener("load", function () {
|
|
2067
2465
|
var _a;
|
|
2068
|
-
// Ensure we always report the progress of a finished upload as 100%.
|
|
2069
|
-
setBytesSent(contentLength);
|
|
2070
2466
|
var etag = (_a = xhr.getResponseHeader("etag")) !== null && _a !== void 0 ? _a : undefined;
|
|
2071
2467
|
resolve({
|
|
2072
2468
|
etag: etag,
|
|
@@ -2093,14 +2489,9 @@ var UploadManager = /*#__PURE__*/function (_UploadManagerBase) {
|
|
|
2093
2489
|
return Promise.reject(e);
|
|
2094
2490
|
}
|
|
2095
2491
|
}
|
|
2096
|
-
}, {
|
|
2097
|
-
key: "getRequestBody",
|
|
2098
|
-
value: function getRequestBody(part, blob) {
|
|
2099
|
-
return part.range.inclusiveEnd === -1 ? new Blob() : blob.value.slice(part.range.inclusiveStart, part.range.inclusiveEnd + 1);
|
|
2100
|
-
}
|
|
2101
2492
|
}]);
|
|
2102
2493
|
return UploadManager;
|
|
2103
|
-
}(
|
|
2494
|
+
}(UploadManagerBrowserWorkerBase);
|
|
2104
2495
|
;// CONCATENATED MODULE: ./src/private/ConsoleUtils.ts
|
|
2105
2496
|
function ConsoleUtils_typeof(obj) { "@babel/helpers - typeof"; return ConsoleUtils_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; }, ConsoleUtils_typeof(obj); }
|
|
2106
2497
|
function ConsoleUtils_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
@@ -2130,269 +2521,6 @@ var ConsoleUtils = /*#__PURE__*/function () {
|
|
|
2130
2521
|
}]);
|
|
2131
2522
|
return ConsoleUtils;
|
|
2132
2523
|
}();
|
|
2133
|
-
;// CONCATENATED MODULE: ./src/private/Mutex.ts
|
|
2134
|
-
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); }
|
|
2135
|
-
function _call(body, then, direct) {
|
|
2136
|
-
if (direct) {
|
|
2137
|
-
return then ? then(body()) : body();
|
|
2138
|
-
}
|
|
2139
|
-
try {
|
|
2140
|
-
var result = Promise.resolve(body());
|
|
2141
|
-
return then ? result.then(then) : result;
|
|
2142
|
-
} catch (e) {
|
|
2143
|
-
return Promise.reject(e);
|
|
2144
|
-
}
|
|
2145
|
-
}
|
|
2146
|
-
function Mutex_rethrow(thrown, value) {
|
|
2147
|
-
if (thrown) throw value;
|
|
2148
|
-
return value;
|
|
2149
|
-
}
|
|
2150
|
-
function Mutex_finallyRethrows(body, finalizer) {
|
|
2151
|
-
try {
|
|
2152
|
-
var result = body();
|
|
2153
|
-
} catch (e) {
|
|
2154
|
-
return finalizer(true, e);
|
|
2155
|
-
}
|
|
2156
|
-
if (result && result.then) {
|
|
2157
|
-
return result.then(finalizer.bind(null, false), finalizer.bind(null, true));
|
|
2158
|
-
}
|
|
2159
|
-
return finalizer(false, result);
|
|
2160
|
-
}
|
|
2161
|
-
function Mutex_await(value, then, direct) {
|
|
2162
|
-
if (direct) {
|
|
2163
|
-
return then ? then(value) : value;
|
|
2164
|
-
}
|
|
2165
|
-
if (!value || !value.then) {
|
|
2166
|
-
value = Promise.resolve(value);
|
|
2167
|
-
}
|
|
2168
|
-
return then ? value.then(then) : value;
|
|
2169
|
-
}
|
|
2170
|
-
function Mutex_empty() {}
|
|
2171
|
-
function Mutex_awaitIgnored(value, direct) {
|
|
2172
|
-
if (!direct) {
|
|
2173
|
-
return value && value.then ? value.then(Mutex_empty) : Promise.resolve();
|
|
2174
|
-
}
|
|
2175
|
-
}
|
|
2176
|
-
function Mutex_settle(pact, state, value) {
|
|
2177
|
-
if (!pact.s) {
|
|
2178
|
-
if (value instanceof Mutex_Pact) {
|
|
2179
|
-
if (value.s) {
|
|
2180
|
-
if (state & 1) {
|
|
2181
|
-
state = value.s;
|
|
2182
|
-
}
|
|
2183
|
-
value = value.v;
|
|
2184
|
-
} else {
|
|
2185
|
-
value.o = Mutex_settle.bind(null, pact, state);
|
|
2186
|
-
return;
|
|
2187
|
-
}
|
|
2188
|
-
}
|
|
2189
|
-
if (value && value.then) {
|
|
2190
|
-
value.then(Mutex_settle.bind(null, pact, state), Mutex_settle.bind(null, pact, 2));
|
|
2191
|
-
return;
|
|
2192
|
-
}
|
|
2193
|
-
pact.s = state;
|
|
2194
|
-
pact.v = value;
|
|
2195
|
-
var observer = pact.o;
|
|
2196
|
-
if (observer) {
|
|
2197
|
-
observer(pact);
|
|
2198
|
-
}
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
var Mutex_Pact = /*#__PURE__*/function () {
|
|
2202
|
-
function _Pact() {}
|
|
2203
|
-
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
2204
|
-
var result = new _Pact();
|
|
2205
|
-
var state = this.s;
|
|
2206
|
-
if (state) {
|
|
2207
|
-
var callback = state & 1 ? onFulfilled : onRejected;
|
|
2208
|
-
if (callback) {
|
|
2209
|
-
try {
|
|
2210
|
-
Mutex_settle(result, 1, callback(this.v));
|
|
2211
|
-
} catch (e) {
|
|
2212
|
-
Mutex_settle(result, 2, e);
|
|
2213
|
-
}
|
|
2214
|
-
return result;
|
|
2215
|
-
} else {
|
|
2216
|
-
return this;
|
|
2217
|
-
}
|
|
2218
|
-
}
|
|
2219
|
-
this.o = function (_this) {
|
|
2220
|
-
try {
|
|
2221
|
-
var value = _this.v;
|
|
2222
|
-
if (_this.s & 1) {
|
|
2223
|
-
Mutex_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
2224
|
-
} else if (onRejected) {
|
|
2225
|
-
Mutex_settle(result, 1, onRejected(value));
|
|
2226
|
-
} else {
|
|
2227
|
-
Mutex_settle(result, 2, value);
|
|
2228
|
-
}
|
|
2229
|
-
} catch (e) {
|
|
2230
|
-
Mutex_settle(result, 2, e);
|
|
2231
|
-
}
|
|
2232
|
-
};
|
|
2233
|
-
return result;
|
|
2234
|
-
};
|
|
2235
|
-
return _Pact;
|
|
2236
|
-
}();
|
|
2237
|
-
function Mutex_isSettledPact(thenable) {
|
|
2238
|
-
return thenable instanceof Mutex_Pact && thenable.s & 1;
|
|
2239
|
-
}
|
|
2240
|
-
function Mutex_for(test, update, body) {
|
|
2241
|
-
var stage;
|
|
2242
|
-
for (;;) {
|
|
2243
|
-
var shouldContinue = test();
|
|
2244
|
-
if (Mutex_isSettledPact(shouldContinue)) {
|
|
2245
|
-
shouldContinue = shouldContinue.v;
|
|
2246
|
-
}
|
|
2247
|
-
if (!shouldContinue) {
|
|
2248
|
-
return result;
|
|
2249
|
-
}
|
|
2250
|
-
if (shouldContinue.then) {
|
|
2251
|
-
stage = 0;
|
|
2252
|
-
break;
|
|
2253
|
-
}
|
|
2254
|
-
var result = body();
|
|
2255
|
-
if (result && result.then) {
|
|
2256
|
-
if (Mutex_isSettledPact(result)) {
|
|
2257
|
-
result = result.s;
|
|
2258
|
-
} else {
|
|
2259
|
-
stage = 1;
|
|
2260
|
-
break;
|
|
2261
|
-
}
|
|
2262
|
-
}
|
|
2263
|
-
if (update) {
|
|
2264
|
-
var updateValue = update();
|
|
2265
|
-
if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
|
|
2266
|
-
stage = 2;
|
|
2267
|
-
break;
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
}
|
|
2271
|
-
var pact = new Mutex_Pact();
|
|
2272
|
-
var reject = Mutex_settle.bind(null, pact, 2);
|
|
2273
|
-
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
2274
|
-
return pact;
|
|
2275
|
-
function _resumeAfterBody(value) {
|
|
2276
|
-
result = value;
|
|
2277
|
-
do {
|
|
2278
|
-
if (update) {
|
|
2279
|
-
updateValue = update();
|
|
2280
|
-
if (updateValue && updateValue.then && !Mutex_isSettledPact(updateValue)) {
|
|
2281
|
-
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
2282
|
-
return;
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
shouldContinue = test();
|
|
2286
|
-
if (!shouldContinue || Mutex_isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
2287
|
-
Mutex_settle(pact, 1, result);
|
|
2288
|
-
return;
|
|
2289
|
-
}
|
|
2290
|
-
if (shouldContinue.then) {
|
|
2291
|
-
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
2292
|
-
return;
|
|
2293
|
-
}
|
|
2294
|
-
result = body();
|
|
2295
|
-
if (Mutex_isSettledPact(result)) {
|
|
2296
|
-
result = result.v;
|
|
2297
|
-
}
|
|
2298
|
-
} while (!result || !result.then);
|
|
2299
|
-
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2300
|
-
}
|
|
2301
|
-
function _resumeAfterTest(shouldContinue) {
|
|
2302
|
-
if (shouldContinue) {
|
|
2303
|
-
result = body();
|
|
2304
|
-
if (result && result.then) {
|
|
2305
|
-
result.then(_resumeAfterBody).then(void 0, reject);
|
|
2306
|
-
} else {
|
|
2307
|
-
_resumeAfterBody(result);
|
|
2308
|
-
}
|
|
2309
|
-
} else {
|
|
2310
|
-
Mutex_settle(pact, 1, result);
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
function _resumeAfterUpdate() {
|
|
2314
|
-
if (shouldContinue = test()) {
|
|
2315
|
-
if (shouldContinue.then) {
|
|
2316
|
-
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
2317
|
-
} else {
|
|
2318
|
-
_resumeAfterTest(shouldContinue);
|
|
2319
|
-
}
|
|
2320
|
-
} else {
|
|
2321
|
-
Mutex_settle(pact, 1, result);
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
function Mutex_continue(value, then) {
|
|
2326
|
-
return value && value.then ? value.then(then) : then(value);
|
|
2327
|
-
}
|
|
2328
|
-
function Mutex_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2329
|
-
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); } }
|
|
2330
|
-
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; }
|
|
2331
|
-
function Mutex_toPropertyKey(arg) { var key = Mutex_toPrimitive(arg, "string"); return Mutex_typeof(key) === "symbol" ? key : String(key); }
|
|
2332
|
-
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); }
|
|
2333
|
-
/**
|
|
2334
|
-
* A lightweight mutex. (Other libraries contain too many features and we want to keep the size upload-js down).
|
|
2335
|
-
*
|
|
2336
|
-
* Characteristics:
|
|
2337
|
-
* - Non-reentrant.
|
|
2338
|
-
* - Unfair. (Multiple callers awaiting 'acquire' will be granted the mutex in no order.)
|
|
2339
|
-
* - When calling `safe` consecutively with no 'awaits' in-between, the current context will synchronously acquire
|
|
2340
|
-
* the mutex every time.
|
|
2341
|
-
*/
|
|
2342
|
-
var Mutex = /*#__PURE__*/function () {
|
|
2343
|
-
function Mutex() {
|
|
2344
|
-
Mutex_classCallCheck(this, Mutex);
|
|
2345
|
-
this.mutex = undefined;
|
|
2346
|
-
this.resolver = undefined;
|
|
2347
|
-
}
|
|
2348
|
-
Mutex_createClass(Mutex, [{
|
|
2349
|
-
key: "safe",
|
|
2350
|
-
value: function safe(callback) {
|
|
2351
|
-
try {
|
|
2352
|
-
var _this2 = this;
|
|
2353
|
-
return Mutex_await(_this2.acquire(), function () {
|
|
2354
|
-
return Mutex_finallyRethrows(callback, function (_wasThrown, _result) {
|
|
2355
|
-
_this2.release();
|
|
2356
|
-
return Mutex_rethrow(_wasThrown, _result);
|
|
2357
|
-
});
|
|
2358
|
-
});
|
|
2359
|
-
} catch (e) {
|
|
2360
|
-
return Promise.reject(e);
|
|
2361
|
-
}
|
|
2362
|
-
}
|
|
2363
|
-
}, {
|
|
2364
|
-
key: "acquire",
|
|
2365
|
-
value: function acquire() {
|
|
2366
|
-
try {
|
|
2367
|
-
var _this4 = this;
|
|
2368
|
-
// Loop necessary for when multiple calls are made to 'acquire' before a 'release' is called, else the call to
|
|
2369
|
-
// 'release' will resume every caller currently waiting on 'acquire'.
|
|
2370
|
-
return Mutex_continue(Mutex_for(function () {
|
|
2371
|
-
return _this4.mutex !== undefined;
|
|
2372
|
-
}, void 0, function () {
|
|
2373
|
-
return Mutex_awaitIgnored(_this4.mutex);
|
|
2374
|
-
}), function () {
|
|
2375
|
-
_this4.mutex = new Promise(function (resolve) {
|
|
2376
|
-
_this4.resolver = resolve;
|
|
2377
|
-
});
|
|
2378
|
-
});
|
|
2379
|
-
} catch (e) {
|
|
2380
|
-
return Promise.reject(e);
|
|
2381
|
-
}
|
|
2382
|
-
}
|
|
2383
|
-
}, {
|
|
2384
|
-
key: "release",
|
|
2385
|
-
value: function release() {
|
|
2386
|
-
if (this.resolver === undefined) {
|
|
2387
|
-
throw new Error("Unable to release mutex: already released.");
|
|
2388
|
-
}
|
|
2389
|
-
this.resolver();
|
|
2390
|
-
this.resolver = undefined;
|
|
2391
|
-
this.mutex = undefined;
|
|
2392
|
-
}
|
|
2393
|
-
}]);
|
|
2394
|
-
return Mutex;
|
|
2395
|
-
}();
|
|
2396
2524
|
;// CONCATENATED MODULE: ./src/public/browser/AuthManagerBrowser.ts
|
|
2397
2525
|
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); }
|
|
2398
2526
|
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; }
|
|
@@ -2459,64 +2587,47 @@ function AuthManagerBrowser_defineProperties(target, props) { for (var i = 0; i
|
|
|
2459
2587
|
function AuthManagerBrowser_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthManagerBrowser_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthManagerBrowser_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
2460
2588
|
function AuthManagerBrowser_toPropertyKey(arg) { var key = AuthManagerBrowser_toPrimitive(arg, "string"); return AuthManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
|
|
2461
2589
|
function AuthManagerBrowser_toPrimitive(input, hint) { if (AuthManagerBrowser_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthManagerBrowser_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
2462
|
-
function AuthManagerBrowser_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) AuthManagerBrowser_setPrototypeOf(subClass, superClass); }
|
|
2463
|
-
function AuthManagerBrowser_setPrototypeOf(o, p) { AuthManagerBrowser_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return AuthManagerBrowser_setPrototypeOf(o, p); }
|
|
2464
|
-
function AuthManagerBrowser_createSuper(Derived) { var hasNativeReflectConstruct = AuthManagerBrowser_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = AuthManagerBrowser_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = AuthManagerBrowser_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return AuthManagerBrowser_possibleConstructorReturn(this, result); }; }
|
|
2465
|
-
function AuthManagerBrowser_possibleConstructorReturn(self, call) { if (call && (AuthManagerBrowser_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return AuthManagerBrowser_assertThisInitialized(self); }
|
|
2466
|
-
function AuthManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
2467
|
-
function AuthManagerBrowser_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; } }
|
|
2468
|
-
function AuthManagerBrowser_getPrototypeOf(o) { AuthManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return AuthManagerBrowser_getPrototypeOf(o); }
|
|
2469
2590
|
|
|
2470
2591
|
|
|
2471
2592
|
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
_this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
|
|
2486
|
-
_this.retryAuthAfterErrorSeconds = 5;
|
|
2487
|
-
_this.refreshBeforeExpirySeconds = 20;
|
|
2488
|
-
var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl(config);
|
|
2489
|
-
var accountId = BytescaleApiClientConfigUtils.getAccountId(config);
|
|
2490
|
-
_this.accessTokenUrl = "".concat(cdnUrl, "/api/v1/access_tokens/").concat(accountId);
|
|
2491
|
-
return _this;
|
|
2492
|
-
}
|
|
2493
|
-
AuthManagerBrowser_createClass(AuthManager, [{
|
|
2593
|
+
var AuthManagerImpl = /*#__PURE__*/function () {
|
|
2594
|
+
function AuthManagerImpl() {
|
|
2595
|
+
AuthManagerBrowser_classCallCheck(this, AuthManagerImpl);
|
|
2596
|
+
this.contentType = "content-type";
|
|
2597
|
+
this.contentTypeJson = "application/json";
|
|
2598
|
+
this.contentTypeText = "text/plain";
|
|
2599
|
+
this.minJwtTtlSeconds = 10;
|
|
2600
|
+
this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
|
|
2601
|
+
this.retryAuthAfterErrorSeconds = 5;
|
|
2602
|
+
this.refreshBeforeExpirySeconds = 20;
|
|
2603
|
+
this.authSessionMutex = AuthSessionState.getMutex();
|
|
2604
|
+
}
|
|
2605
|
+
AuthManagerBrowser_createClass(AuthManagerImpl, [{
|
|
2494
2606
|
key: "isAuthSessionActive",
|
|
2495
2607
|
value: function isAuthSessionActive() {
|
|
2496
|
-
return AuthSessionState.
|
|
2608
|
+
return AuthSessionState.getSession() !== undefined;
|
|
2497
2609
|
}
|
|
2498
2610
|
}, {
|
|
2499
2611
|
key: "beginAuthSession",
|
|
2500
|
-
value: function beginAuthSession(
|
|
2612
|
+
value: function beginAuthSession(params) {
|
|
2501
2613
|
try {
|
|
2502
|
-
var
|
|
2614
|
+
var _this2 = this;
|
|
2503
2615
|
var newSession = {
|
|
2504
2616
|
accessToken: undefined,
|
|
2505
2617
|
accessTokenRefreshHandle: undefined,
|
|
2506
|
-
|
|
2507
|
-
authHeaders: authHeaders,
|
|
2618
|
+
params: params,
|
|
2508
2619
|
isActive: true
|
|
2509
2620
|
};
|
|
2510
|
-
return AuthManagerBrowser_await(
|
|
2621
|
+
return AuthManagerBrowser_await(_this2.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
2511
2622
|
// We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
|
|
2512
|
-
if (
|
|
2623
|
+
if (_this2.isAuthSessionActive()) {
|
|
2513
2624
|
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.");
|
|
2514
2625
|
}
|
|
2515
|
-
AuthSessionState.
|
|
2626
|
+
AuthSessionState.setSession(newSession);
|
|
2516
2627
|
return AuthManagerBrowser_await();
|
|
2517
2628
|
})), function () {
|
|
2518
2629
|
// IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
|
|
2519
|
-
return AuthManagerBrowser_awaitIgnored(
|
|
2630
|
+
return AuthManagerBrowser_awaitIgnored(_this2.refreshAccessToken(newSession));
|
|
2520
2631
|
});
|
|
2521
2632
|
} catch (e) {
|
|
2522
2633
|
return Promise.reject(e);
|
|
@@ -2526,18 +2637,18 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2526
2637
|
key: "endAuthSession",
|
|
2527
2638
|
value: function endAuthSession() {
|
|
2528
2639
|
try {
|
|
2529
|
-
var
|
|
2530
|
-
return AuthManagerBrowser_awaitIgnored(
|
|
2531
|
-
|
|
2640
|
+
var _this4 = this;
|
|
2641
|
+
return AuthManagerBrowser_awaitIgnored(_this4.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
2642
|
+
var session = AuthSessionState.getSession();
|
|
2643
|
+
if (session === undefined) {
|
|
2532
2644
|
return;
|
|
2533
2645
|
}
|
|
2534
|
-
|
|
2535
|
-
AuthSessionState.session = undefined;
|
|
2646
|
+
AuthSessionState.setSession(undefined);
|
|
2536
2647
|
session.isActive = false;
|
|
2537
2648
|
if (session.accessTokenRefreshHandle !== undefined) {
|
|
2538
2649
|
clearTimeout(session.accessTokenRefreshHandle);
|
|
2539
2650
|
}
|
|
2540
|
-
return AuthManagerBrowser_awaitIgnored(
|
|
2651
|
+
return AuthManagerBrowser_awaitIgnored(_this4.deleteAccessToken(session.params));
|
|
2541
2652
|
})));
|
|
2542
2653
|
} catch (e) {
|
|
2543
2654
|
return Promise.reject(e);
|
|
@@ -2547,26 +2658,26 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2547
2658
|
key: "refreshAccessToken",
|
|
2548
2659
|
value: function refreshAccessToken(session) {
|
|
2549
2660
|
try {
|
|
2550
|
-
var
|
|
2551
|
-
return AuthManagerBrowser_awaitIgnored(
|
|
2661
|
+
var _this6 = this;
|
|
2662
|
+
return AuthManagerBrowser_awaitIgnored(_this6.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
2552
2663
|
if (!session.isActive) {
|
|
2553
2664
|
return;
|
|
2554
2665
|
}
|
|
2555
|
-
var timeout =
|
|
2666
|
+
var timeout = _this6.retryAuthAfterErrorSeconds;
|
|
2556
2667
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
|
|
2557
2668
|
return AuthManagerBrowser_catch(function () {
|
|
2558
|
-
var _getAccessToken =
|
|
2559
|
-
_session$
|
|
2560
|
-
return AuthManagerBrowser_await(session.authHeaders(), function (_session$
|
|
2561
|
-
return AuthManagerBrowser_await(_getAccessToken.call(
|
|
2562
|
-
return AuthManagerBrowser_await(
|
|
2563
|
-
var desiredTtl = setTokenResult.ttlSeconds -
|
|
2564
|
-
timeout = Math.max(desiredTtl,
|
|
2669
|
+
var _getAccessToken = _this6.getAccessToken,
|
|
2670
|
+
_session$params = session.params;
|
|
2671
|
+
return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
|
|
2672
|
+
return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
|
|
2673
|
+
return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt), function (setTokenResult) {
|
|
2674
|
+
var desiredTtl = setTokenResult.ttlSeconds - _this6.refreshBeforeExpirySeconds;
|
|
2675
|
+
timeout = Math.max(desiredTtl, _this6.minJwtTtlSeconds);
|
|
2565
2676
|
if (desiredTtl !== timeout) {
|
|
2566
2677
|
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
|
|
2567
2678
|
}
|
|
2568
2679
|
// 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!
|
|
2569
|
-
timeout = Math.min(timeout,
|
|
2680
|
+
timeout = Math.min(timeout, _this6.maxJwtTtlSeconds);
|
|
2570
2681
|
session.accessToken = setTokenResult.accessToken;
|
|
2571
2682
|
});
|
|
2572
2683
|
});
|
|
@@ -2577,7 +2688,7 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2577
2688
|
});
|
|
2578
2689
|
}, function (_wasThrown, _result) {
|
|
2579
2690
|
session.accessTokenRefreshHandle = window.setTimeout(function () {
|
|
2580
|
-
|
|
2691
|
+
_this6.refreshAccessToken(session).then(function () {}, function (e) {
|
|
2581
2692
|
return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
|
|
2582
2693
|
});
|
|
2583
2694
|
}, timeout * 1000);
|
|
@@ -2588,34 +2699,49 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2588
2699
|
return Promise.reject(e);
|
|
2589
2700
|
}
|
|
2590
2701
|
}
|
|
2702
|
+
}, {
|
|
2703
|
+
key: "getAccessTokenUrl",
|
|
2704
|
+
value: function getAccessTokenUrl(params) {
|
|
2705
|
+
var _a;
|
|
2706
|
+
var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl((_a = params.options) !== null && _a !== void 0 ? _a : {});
|
|
2707
|
+
return "".concat(cdnUrl, "/api/v1/access_tokens/").concat(params.accountId);
|
|
2708
|
+
}
|
|
2591
2709
|
}, {
|
|
2592
2710
|
key: "deleteAccessToken",
|
|
2593
|
-
value: function deleteAccessToken() {
|
|
2711
|
+
value: function deleteAccessToken(params) {
|
|
2594
2712
|
try {
|
|
2595
|
-
var
|
|
2596
|
-
|
|
2713
|
+
var _this8 = this;
|
|
2714
|
+
var _a;
|
|
2715
|
+
return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params), {
|
|
2597
2716
|
method: "DELETE",
|
|
2598
2717
|
credentials: "include",
|
|
2599
2718
|
headers: {}
|
|
2600
|
-
},
|
|
2719
|
+
}, {
|
|
2720
|
+
isBytescaleApi: true,
|
|
2721
|
+
fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
|
|
2722
|
+
}));
|
|
2601
2723
|
} catch (e) {
|
|
2602
2724
|
return Promise.reject(e);
|
|
2603
2725
|
}
|
|
2604
2726
|
}
|
|
2605
2727
|
}, {
|
|
2606
2728
|
key: "setAccessToken",
|
|
2607
|
-
value: function setAccessToken(jwt) {
|
|
2729
|
+
value: function setAccessToken(params, jwt) {
|
|
2608
2730
|
try {
|
|
2609
|
-
var
|
|
2731
|
+
var _this10 = this;
|
|
2732
|
+
var _a;
|
|
2610
2733
|
var request = {
|
|
2611
2734
|
accessToken: jwt
|
|
2612
2735
|
};
|
|
2613
|
-
return AuthManagerBrowser_await(
|
|
2736
|
+
return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params), {
|
|
2614
2737
|
method: "PUT",
|
|
2615
2738
|
credentials: "include",
|
|
2616
|
-
headers: AuthManagerBrowser_defineProperty({},
|
|
2739
|
+
headers: AuthManagerBrowser_defineProperty({}, _this10.contentType, _this10.contentTypeJson),
|
|
2617
2740
|
body: JSON.stringify(request)
|
|
2618
|
-
},
|
|
2741
|
+
}, {
|
|
2742
|
+
isBytescaleApi: true,
|
|
2743
|
+
fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
|
|
2744
|
+
}), function (response) {
|
|
2619
2745
|
return AuthManagerBrowser_await(response.json());
|
|
2620
2746
|
});
|
|
2621
2747
|
} catch (e) {
|
|
@@ -2624,17 +2750,23 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2624
2750
|
}
|
|
2625
2751
|
}, {
|
|
2626
2752
|
key: "getAccessToken",
|
|
2627
|
-
value: function getAccessToken(
|
|
2753
|
+
value: function getAccessToken(params, headers) {
|
|
2628
2754
|
try {
|
|
2629
|
-
var
|
|
2755
|
+
var _this12 = this;
|
|
2756
|
+
var _a, _b;
|
|
2630
2757
|
var endpointName = "Your auth API endpoint";
|
|
2631
|
-
var requiredContentType =
|
|
2632
|
-
return AuthManagerBrowser_await(
|
|
2758
|
+
var requiredContentType = _this12.contentTypeText;
|
|
2759
|
+
return AuthManagerBrowser_await(BaseAPI.fetch(params.authUrl, {
|
|
2633
2760
|
method: "GET",
|
|
2634
2761
|
headers: headers
|
|
2635
|
-
},
|
|
2636
|
-
|
|
2637
|
-
|
|
2762
|
+
}, {
|
|
2763
|
+
isBytescaleApi: false,
|
|
2764
|
+
fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
|
|
2765
|
+
}), function (result) {
|
|
2766
|
+
var actualContentType = (_b = result.headers.get(_this12.contentType)) !== null && _b !== void 0 ? _b : "";
|
|
2767
|
+
// Support content types like "text/plain; charset=utf-8" and "text/plain"
|
|
2768
|
+
if (actualContentType.split(";")[0] !== requiredContentType) {
|
|
2769
|
+
throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this12.contentType, " response header, but the Bytescale SDK requires \"").concat(requiredContentType, "\"."));
|
|
2638
2770
|
}
|
|
2639
2771
|
return AuthManagerBrowser_await(result.text(), function (jwt) {
|
|
2640
2772
|
if (jwt.length === 0) {
|
|
@@ -2652,8 +2784,12 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
|
|
|
2652
2784
|
}
|
|
2653
2785
|
}
|
|
2654
2786
|
}]);
|
|
2655
|
-
return
|
|
2656
|
-
}(
|
|
2787
|
+
return AuthManagerImpl;
|
|
2788
|
+
}();
|
|
2789
|
+
/**
|
|
2790
|
+
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
|
2791
|
+
*/
|
|
2792
|
+
var AuthManager = new AuthManagerImpl();
|
|
2657
2793
|
;// CONCATENATED MODULE: ./src/public/browser/index.ts
|
|
2658
2794
|
|
|
2659
2795
|
|