@bytescale/sdk 3.59.0 → 3.61.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/dist/browser/cjs/main.js +513 -164
- package/dist/browser/esm/main.mjs +513 -164
- package/dist/node/cjs/main.js +351 -97
- package/dist/node/esm/main.mjs +351 -97
- package/dist/types/private/AuthSessionState.d.ts +2 -0
- package/dist/types/private/Scheduler.d.ts +12 -3
- package/dist/types/private/model/AuthSession.d.ts +4 -0
- package/dist/types/private/model/AuthSessionConfigBase.d.ts +2 -0
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +2 -0
- package/dist/types/public/shared/generated/runtime.d.ts +6 -0
- package/dist/worker/cjs/main.js +351 -97
- package/dist/worker/esm/main.mjs +351 -97
- package/package.json +1 -1
- package/tests/ApiClientAuth.test.ts +101 -2
- package/tests/AuthManagerBrowser.test.ts +109 -0
- package/tests/AuthServiceWorkerRewrite.test.ts +23 -3
- package/tests/Scheduler.test.ts +135 -0
- package/tests/UploadManagerAuth.test.ts +30 -0
package/dist/browser/cjs/main.js
CHANGED
|
@@ -193,6 +193,177 @@ var FairMutex = /*#__PURE__*/function () {
|
|
|
193
193
|
}]);
|
|
194
194
|
}();
|
|
195
195
|
;// ./src/private/AuthSessionState.ts
|
|
196
|
+
function AuthSessionState_empty() {}
|
|
197
|
+
function AuthSessionState_awaitIgnored(value, direct) {
|
|
198
|
+
if (!direct) {
|
|
199
|
+
return value && value.then ? value.then(AuthSessionState_empty) : Promise.resolve();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function AuthSessionState_invoke(body, then) {
|
|
203
|
+
var result = body();
|
|
204
|
+
if (result && result.then) {
|
|
205
|
+
return result.then(then);
|
|
206
|
+
}
|
|
207
|
+
return then(result);
|
|
208
|
+
}
|
|
209
|
+
function _settle(pact, state, value) {
|
|
210
|
+
if (!pact.s) {
|
|
211
|
+
if (value instanceof _Pact) {
|
|
212
|
+
if (value.s) {
|
|
213
|
+
if (state & 1) {
|
|
214
|
+
state = value.s;
|
|
215
|
+
}
|
|
216
|
+
value = value.v;
|
|
217
|
+
} else {
|
|
218
|
+
value.o = _settle.bind(null, pact, state);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (value && value.then) {
|
|
223
|
+
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
pact.s = state;
|
|
227
|
+
pact.v = value;
|
|
228
|
+
var observer = pact.o;
|
|
229
|
+
if (observer) {
|
|
230
|
+
observer(pact);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
var _Pact = /*#__PURE__*/function () {
|
|
235
|
+
function _Pact() {}
|
|
236
|
+
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
237
|
+
var result = new _Pact();
|
|
238
|
+
var state = this.s;
|
|
239
|
+
if (state) {
|
|
240
|
+
var callback = state & 1 ? onFulfilled : onRejected;
|
|
241
|
+
if (callback) {
|
|
242
|
+
try {
|
|
243
|
+
_settle(result, 1, callback(this.v));
|
|
244
|
+
} catch (e) {
|
|
245
|
+
_settle(result, 2, e);
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
} else {
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
this.o = function (_this) {
|
|
253
|
+
try {
|
|
254
|
+
var value = _this.v;
|
|
255
|
+
if (_this.s & 1) {
|
|
256
|
+
_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
257
|
+
} else if (onRejected) {
|
|
258
|
+
_settle(result, 1, onRejected(value));
|
|
259
|
+
} else {
|
|
260
|
+
_settle(result, 2, value);
|
|
261
|
+
}
|
|
262
|
+
} catch (e) {
|
|
263
|
+
_settle(result, 2, e);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
return result;
|
|
267
|
+
};
|
|
268
|
+
return _Pact;
|
|
269
|
+
}();
|
|
270
|
+
function _isSettledPact(thenable) {
|
|
271
|
+
return thenable instanceof _Pact && thenable.s & 1;
|
|
272
|
+
}
|
|
273
|
+
function _for(test, update, body) {
|
|
274
|
+
var stage;
|
|
275
|
+
for (;;) {
|
|
276
|
+
var shouldContinue = test();
|
|
277
|
+
if (_isSettledPact(shouldContinue)) {
|
|
278
|
+
shouldContinue = shouldContinue.v;
|
|
279
|
+
}
|
|
280
|
+
if (!shouldContinue) {
|
|
281
|
+
return result;
|
|
282
|
+
}
|
|
283
|
+
if (shouldContinue.then) {
|
|
284
|
+
stage = 0;
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
var result = body();
|
|
288
|
+
if (result && result.then) {
|
|
289
|
+
if (_isSettledPact(result)) {
|
|
290
|
+
result = result.s;
|
|
291
|
+
} else {
|
|
292
|
+
stage = 1;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (update) {
|
|
297
|
+
var updateValue = update();
|
|
298
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
299
|
+
stage = 2;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
var pact = new _Pact();
|
|
305
|
+
var reject = _settle.bind(null, pact, 2);
|
|
306
|
+
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
307
|
+
return pact;
|
|
308
|
+
function _resumeAfterBody(value) {
|
|
309
|
+
result = value;
|
|
310
|
+
do {
|
|
311
|
+
if (update) {
|
|
312
|
+
updateValue = update();
|
|
313
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
314
|
+
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
shouldContinue = test();
|
|
319
|
+
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
320
|
+
_settle(pact, 1, result);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (shouldContinue.then) {
|
|
324
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
result = body();
|
|
328
|
+
if (_isSettledPact(result)) {
|
|
329
|
+
result = result.v;
|
|
330
|
+
}
|
|
331
|
+
} while (!result || !result.then);
|
|
332
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
333
|
+
}
|
|
334
|
+
function _resumeAfterTest(shouldContinue) {
|
|
335
|
+
if (shouldContinue) {
|
|
336
|
+
result = body();
|
|
337
|
+
if (result && result.then) {
|
|
338
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
339
|
+
} else {
|
|
340
|
+
_resumeAfterBody(result);
|
|
341
|
+
}
|
|
342
|
+
} else {
|
|
343
|
+
_settle(pact, 1, result);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function _resumeAfterUpdate() {
|
|
347
|
+
if (shouldContinue = test()) {
|
|
348
|
+
if (shouldContinue.then) {
|
|
349
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
350
|
+
} else {
|
|
351
|
+
_resumeAfterTest(shouldContinue);
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
_settle(pact, 1, result);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function AuthSessionState_await(value, then, direct) {
|
|
359
|
+
if (direct) {
|
|
360
|
+
return then ? then(value) : value;
|
|
361
|
+
}
|
|
362
|
+
if (!value || !value.then) {
|
|
363
|
+
value = Promise.resolve(value);
|
|
364
|
+
}
|
|
365
|
+
return then ? value.then(then) : value;
|
|
366
|
+
}
|
|
196
367
|
function AuthSessionState_typeof(o) { "@babel/helpers - typeof"; return AuthSessionState_typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, AuthSessionState_typeof(o); }
|
|
197
368
|
function AuthSessionState_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
198
369
|
function AuthSessionState_defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, AuthSessionState_toPropertyKey(o.key), o); } }
|
|
@@ -299,6 +470,54 @@ var AuthSessionState = /*#__PURE__*/function () {
|
|
|
299
470
|
jwt: undefined
|
|
300
471
|
};
|
|
301
472
|
}
|
|
473
|
+
/** Waits for request-time auth to be current before resolving it. */
|
|
474
|
+
}, {
|
|
475
|
+
key: "resolveAuthConfigAsync",
|
|
476
|
+
value: function resolveAuthConfigAsync(authConfigId, requireReadyDefault) {
|
|
477
|
+
try {
|
|
478
|
+
var _exit = false;
|
|
479
|
+
var _a, _b;
|
|
480
|
+
if (authConfigId === false) {
|
|
481
|
+
return AuthSessionState_await(undefined);
|
|
482
|
+
}
|
|
483
|
+
return AuthSessionState_await(_for(function () {
|
|
484
|
+
return !_exit;
|
|
485
|
+
}, void 0, function () {
|
|
486
|
+
var session = AuthSessionState.getSession();
|
|
487
|
+
if (session === undefined || !session.isActive || !Array.isArray(session.authConfigs)) {
|
|
488
|
+
var _AuthSessionState$res = AuthSessionState.resolveAuthConfig(authConfigId, requireReadyDefault);
|
|
489
|
+
_exit = true;
|
|
490
|
+
return _AuthSessionState$res;
|
|
491
|
+
}
|
|
492
|
+
var state = session.authConfigs.find(function (config) {
|
|
493
|
+
return config.config.authConfigId === authConfigId;
|
|
494
|
+
});
|
|
495
|
+
if (state === undefined) {
|
|
496
|
+
var _AuthSessionState$res2 = AuthSessionState.resolveAuthConfig(authConfigId, requireReadyDefault);
|
|
497
|
+
_exit = true;
|
|
498
|
+
return _AuthSessionState$res2;
|
|
499
|
+
}
|
|
500
|
+
var authenticationPromise = (_a = state.authenticationPromise) !== null && _a !== void 0 ? _a : state.refreshPromise;
|
|
501
|
+
return AuthSessionState_invoke(function () {
|
|
502
|
+
if (authenticationPromise !== undefined) {
|
|
503
|
+
return AuthSessionState_awaitIgnored(authenticationPromise);
|
|
504
|
+
}
|
|
505
|
+
}, function () {
|
|
506
|
+
if (AuthSessionState.getSession() !== session || !session.isActive) {
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
var currentAuthenticationPromise = (_b = state.authenticationPromise) !== null && _b !== void 0 ? _b : state.refreshPromise;
|
|
510
|
+
if (currentAuthenticationPromise === undefined || currentAuthenticationPromise === authenticationPromise) {
|
|
511
|
+
var _AuthSessionState$res3 = AuthSessionState.resolveAuthConfig(authConfigId, true);
|
|
512
|
+
_exit = true;
|
|
513
|
+
return _AuthSessionState$res3;
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
}));
|
|
517
|
+
} catch (e) {
|
|
518
|
+
return Promise.reject(e);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
302
521
|
}]);
|
|
303
522
|
}();
|
|
304
523
|
AuthSessionState.stateKey = "BytescaleSessionState";
|
|
@@ -444,12 +663,43 @@ var BytescaleApiClientConfigUtils = /*#__PURE__*/function () {
|
|
|
444
663
|
value: function getAccountId(config) {
|
|
445
664
|
return BytescaleApiClientConfigUtils.resolveAuthentication(config).accountId;
|
|
446
665
|
}
|
|
666
|
+
}, {
|
|
667
|
+
key: "getAccountIdAsync",
|
|
668
|
+
value: function getAccountIdAsync(config) {
|
|
669
|
+
try {
|
|
670
|
+
return runtime_await(BytescaleApiClientConfigUtils.resolveAuthenticationAsync(config), function (_BytescaleApiClientCo) {
|
|
671
|
+
return _BytescaleApiClientCo.accountId;
|
|
672
|
+
});
|
|
673
|
+
} catch (e) {
|
|
674
|
+
return Promise.reject(e);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
447
677
|
}, {
|
|
448
678
|
key: "resolveAuthentication",
|
|
449
679
|
value: function resolveAuthentication(config) {
|
|
450
|
-
var _a
|
|
680
|
+
var _a;
|
|
451
681
|
var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
|
|
452
682
|
var authConfig = AuthSessionState.resolveAuthConfig(config.authConfigId, apiKey === undefined);
|
|
683
|
+
return BytescaleApiClientConfigUtils.resolveAuthenticationWithAuthConfig(config, authConfig);
|
|
684
|
+
}
|
|
685
|
+
}, {
|
|
686
|
+
key: "resolveAuthenticationAsync",
|
|
687
|
+
value: function resolveAuthenticationAsync(config) {
|
|
688
|
+
try {
|
|
689
|
+
var _a;
|
|
690
|
+
var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
|
|
691
|
+
return runtime_await(AuthSessionState.resolveAuthConfigAsync(config.authConfigId, apiKey === undefined), function (authConfig) {
|
|
692
|
+
return BytescaleApiClientConfigUtils.resolveAuthenticationWithAuthConfig(config, authConfig);
|
|
693
|
+
});
|
|
694
|
+
} catch (e) {
|
|
695
|
+
return Promise.reject(e);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}, {
|
|
699
|
+
key: "resolveAuthenticationWithAuthConfig",
|
|
700
|
+
value: function resolveAuthenticationWithAuthConfig(config, authConfig) {
|
|
701
|
+
var _a, _b;
|
|
702
|
+
var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
|
|
453
703
|
var apiKeyAccountId = apiKey === undefined ? undefined : BytescaleApiClientConfigUtils.getApiKeyAccountId(apiKey);
|
|
454
704
|
if (apiKeyAccountId !== undefined && authConfig !== undefined && apiKeyAccountId !== authConfig.accountId) {
|
|
455
705
|
throw new Error("The API key belongs to account '".concat(apiKeyAccountId, "', but AuthManager configuration '").concat((_b = config.authConfigId) !== null && _b !== void 0 ? _b : "default", "' belongs to account '").concat(authConfig.accountId, "'."));
|
|
@@ -536,7 +786,6 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
536
786
|
try {
|
|
537
787
|
var _this = this;
|
|
538
788
|
var _a;
|
|
539
|
-
Object.assign(context.headers, BytescaleApiClientConfigUtils.resolveAuthentication(_this.config).headers);
|
|
540
789
|
// Key: any possible value for 'baseUrlOverride'
|
|
541
790
|
// Value: user-overridden value for that base URL from the config.
|
|
542
791
|
var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this.config));
|
|
@@ -577,44 +826,48 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
577
826
|
}
|
|
578
827
|
var configHeaders = _this2.config.headers;
|
|
579
828
|
return runtime_await(runtime_await(configHeaders === undefined ? {} : typeof configHeaders === "function" ? configHeaders() : configHeaders, function (resolvedConfigHeaders) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
829
|
+
var _context$headers = context.headers;
|
|
830
|
+
return runtime_await(BytescaleApiClientConfigUtils.resolveAuthenticationAsync(_this2.config), function (_BytescaleApiClientCo2) {
|
|
831
|
+
Object.assign(_context$headers, _BytescaleApiClientCo2.headers);
|
|
832
|
+
for (var _i = 0, _Object$keys = Object.keys(resolvedConfigHeaders); _i < _Object$keys.length; _i++) {
|
|
833
|
+
var key = _Object$keys[_i];
|
|
834
|
+
if (key.toLowerCase() === "authorization" || key.toLowerCase() === "authorization-token") {
|
|
835
|
+
for (var _i2 = 0, _Object$keys2 = Object.keys(context.headers); _i2 < _Object$keys2.length; _i2++) {
|
|
836
|
+
var generatedKey = _Object$keys2[_i2];
|
|
837
|
+
if (generatedKey.toLowerCase() === key.toLowerCase()) {
|
|
838
|
+
// Custom auth headers have documented precedence; remove the generated spelling to make that deterministic.
|
|
839
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
840
|
+
delete context.headers[generatedKey];
|
|
841
|
+
}
|
|
589
842
|
}
|
|
590
843
|
}
|
|
591
844
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
return headers[key] === undefined ? delete headers[key] : {};
|
|
596
|
-
});
|
|
597
|
-
var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
|
|
598
|
-
return runtime_await(initOverrides);
|
|
599
|
-
};
|
|
600
|
-
var initParams = {
|
|
601
|
-
method: context.method,
|
|
602
|
-
headers: headers,
|
|
603
|
-
body: context.body
|
|
604
|
-
};
|
|
605
|
-
var _Object$assign = Object.assign({}, initParams);
|
|
606
|
-
return runtime_await(initOverrideFn({
|
|
607
|
-
init: initParams,
|
|
608
|
-
context: context
|
|
609
|
-
}), function (_initOverrideFn) {
|
|
610
|
-
var overriddenInit = Object.assign(_Object$assign, _initOverrideFn);
|
|
611
|
-
var init = Object.assign(Object.assign({}, overriddenInit), {
|
|
612
|
-
body: JSON.stringify(overriddenInit.body)
|
|
845
|
+
var headers = Object.assign(Object.assign({}, context.headers), resolvedConfigHeaders);
|
|
846
|
+
Object.keys(headers).forEach(function (key) {
|
|
847
|
+
return headers[key] === undefined ? delete headers[key] : {};
|
|
613
848
|
});
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
init: init
|
|
849
|
+
var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
|
|
850
|
+
return runtime_await(initOverrides);
|
|
617
851
|
};
|
|
852
|
+
var initParams = {
|
|
853
|
+
method: context.method,
|
|
854
|
+
headers: headers,
|
|
855
|
+
body: context.body
|
|
856
|
+
};
|
|
857
|
+
var _Object$assign = Object.assign({}, initParams);
|
|
858
|
+
return runtime_await(initOverrideFn({
|
|
859
|
+
init: initParams,
|
|
860
|
+
context: context
|
|
861
|
+
}), function (_initOverrideFn) {
|
|
862
|
+
var overriddenInit = Object.assign(_Object$assign, _initOverrideFn);
|
|
863
|
+
var init = Object.assign(Object.assign({}, overriddenInit), {
|
|
864
|
+
body: JSON.stringify(overriddenInit.body)
|
|
865
|
+
});
|
|
866
|
+
return {
|
|
867
|
+
url: url,
|
|
868
|
+
init: init
|
|
869
|
+
};
|
|
870
|
+
});
|
|
618
871
|
});
|
|
619
872
|
}, configHeaders === undefined || !(typeof configHeaders === "function")));
|
|
620
873
|
} catch (e) {
|
|
@@ -642,8 +895,8 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
642
895
|
// unless the following is set.
|
|
643
896
|
// https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
|
|
644
897
|
duplex: "half"
|
|
645
|
-
})), function (
|
|
646
|
-
response =
|
|
898
|
+
})), function (_BytescaleApiClientCo3) {
|
|
899
|
+
response = _BytescaleApiClientCo3;
|
|
647
900
|
});
|
|
648
901
|
}, function (e) {
|
|
649
902
|
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
@@ -2054,21 +2307,21 @@ function _invokeIgnored(body) {
|
|
|
2054
2307
|
return result.then(UploadManagerBase_empty);
|
|
2055
2308
|
}
|
|
2056
2309
|
}
|
|
2057
|
-
function
|
|
2310
|
+
function UploadManagerBase_settle(pact, state, value) {
|
|
2058
2311
|
if (!pact.s) {
|
|
2059
|
-
if (value instanceof
|
|
2312
|
+
if (value instanceof UploadManagerBase_Pact) {
|
|
2060
2313
|
if (value.s) {
|
|
2061
2314
|
if (state & 1) {
|
|
2062
2315
|
state = value.s;
|
|
2063
2316
|
}
|
|
2064
2317
|
value = value.v;
|
|
2065
2318
|
} else {
|
|
2066
|
-
value.o =
|
|
2319
|
+
value.o = UploadManagerBase_settle.bind(null, pact, state);
|
|
2067
2320
|
return;
|
|
2068
2321
|
}
|
|
2069
2322
|
}
|
|
2070
2323
|
if (value && value.then) {
|
|
2071
|
-
value.then(
|
|
2324
|
+
value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
|
|
2072
2325
|
return;
|
|
2073
2326
|
}
|
|
2074
2327
|
pact.s = state;
|
|
@@ -2079,7 +2332,7 @@ function _settle(pact, state, value) {
|
|
|
2079
2332
|
}
|
|
2080
2333
|
}
|
|
2081
2334
|
}
|
|
2082
|
-
var
|
|
2335
|
+
var UploadManagerBase_Pact = /*#__PURE__*/function () {
|
|
2083
2336
|
function _Pact() {}
|
|
2084
2337
|
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
2085
2338
|
var result = new _Pact();
|
|
@@ -2088,9 +2341,9 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
2088
2341
|
var callback = state & 1 ? onFulfilled : onRejected;
|
|
2089
2342
|
if (callback) {
|
|
2090
2343
|
try {
|
|
2091
|
-
|
|
2344
|
+
UploadManagerBase_settle(result, 1, callback(this.v));
|
|
2092
2345
|
} catch (e) {
|
|
2093
|
-
|
|
2346
|
+
UploadManagerBase_settle(result, 2, e);
|
|
2094
2347
|
}
|
|
2095
2348
|
return result;
|
|
2096
2349
|
} else {
|
|
@@ -2101,28 +2354,28 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
2101
2354
|
try {
|
|
2102
2355
|
var value = _this.v;
|
|
2103
2356
|
if (_this.s & 1) {
|
|
2104
|
-
|
|
2357
|
+
UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
2105
2358
|
} else if (onRejected) {
|
|
2106
|
-
|
|
2359
|
+
UploadManagerBase_settle(result, 1, onRejected(value));
|
|
2107
2360
|
} else {
|
|
2108
|
-
|
|
2361
|
+
UploadManagerBase_settle(result, 2, value);
|
|
2109
2362
|
}
|
|
2110
2363
|
} catch (e) {
|
|
2111
|
-
|
|
2364
|
+
UploadManagerBase_settle(result, 2, e);
|
|
2112
2365
|
}
|
|
2113
2366
|
};
|
|
2114
2367
|
return result;
|
|
2115
2368
|
};
|
|
2116
2369
|
return _Pact;
|
|
2117
2370
|
}();
|
|
2118
|
-
function
|
|
2119
|
-
return thenable instanceof
|
|
2371
|
+
function UploadManagerBase_isSettledPact(thenable) {
|
|
2372
|
+
return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
|
|
2120
2373
|
}
|
|
2121
|
-
function
|
|
2374
|
+
function UploadManagerBase_for(test, update, body) {
|
|
2122
2375
|
var stage;
|
|
2123
2376
|
for (;;) {
|
|
2124
2377
|
var shouldContinue = test();
|
|
2125
|
-
if (
|
|
2378
|
+
if (UploadManagerBase_isSettledPact(shouldContinue)) {
|
|
2126
2379
|
shouldContinue = shouldContinue.v;
|
|
2127
2380
|
}
|
|
2128
2381
|
if (!shouldContinue) {
|
|
@@ -2134,7 +2387,7 @@ function _for(test, update, body) {
|
|
|
2134
2387
|
}
|
|
2135
2388
|
var result = body();
|
|
2136
2389
|
if (result && result.then) {
|
|
2137
|
-
if (
|
|
2390
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
2138
2391
|
result = result.s;
|
|
2139
2392
|
} else {
|
|
2140
2393
|
stage = 1;
|
|
@@ -2143,14 +2396,14 @@ function _for(test, update, body) {
|
|
|
2143
2396
|
}
|
|
2144
2397
|
if (update) {
|
|
2145
2398
|
var updateValue = update();
|
|
2146
|
-
if (updateValue && updateValue.then && !
|
|
2399
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
2147
2400
|
stage = 2;
|
|
2148
2401
|
break;
|
|
2149
2402
|
}
|
|
2150
2403
|
}
|
|
2151
2404
|
}
|
|
2152
|
-
var pact = new
|
|
2153
|
-
var reject =
|
|
2405
|
+
var pact = new UploadManagerBase_Pact();
|
|
2406
|
+
var reject = UploadManagerBase_settle.bind(null, pact, 2);
|
|
2154
2407
|
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
2155
2408
|
return pact;
|
|
2156
2409
|
function _resumeAfterBody(value) {
|
|
@@ -2158,14 +2411,14 @@ function _for(test, update, body) {
|
|
|
2158
2411
|
do {
|
|
2159
2412
|
if (update) {
|
|
2160
2413
|
updateValue = update();
|
|
2161
|
-
if (updateValue && updateValue.then && !
|
|
2414
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
2162
2415
|
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
2163
2416
|
return;
|
|
2164
2417
|
}
|
|
2165
2418
|
}
|
|
2166
2419
|
shouldContinue = test();
|
|
2167
|
-
if (!shouldContinue ||
|
|
2168
|
-
|
|
2420
|
+
if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
2421
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
2169
2422
|
return;
|
|
2170
2423
|
}
|
|
2171
2424
|
if (shouldContinue.then) {
|
|
@@ -2173,7 +2426,7 @@ function _for(test, update, body) {
|
|
|
2173
2426
|
return;
|
|
2174
2427
|
}
|
|
2175
2428
|
result = body();
|
|
2176
|
-
if (
|
|
2429
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
2177
2430
|
result = result.v;
|
|
2178
2431
|
}
|
|
2179
2432
|
} while (!result || !result.then);
|
|
@@ -2188,7 +2441,7 @@ function _for(test, update, body) {
|
|
|
2188
2441
|
_resumeAfterBody(result);
|
|
2189
2442
|
}
|
|
2190
2443
|
} else {
|
|
2191
|
-
|
|
2444
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
2192
2445
|
}
|
|
2193
2446
|
}
|
|
2194
2447
|
function _resumeAfterUpdate() {
|
|
@@ -2199,7 +2452,7 @@ function _for(test, update, body) {
|
|
|
2199
2452
|
_resumeAfterTest(shouldContinue);
|
|
2200
2453
|
}
|
|
2201
2454
|
} else {
|
|
2202
|
-
|
|
2455
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
2203
2456
|
}
|
|
2204
2457
|
}
|
|
2205
2458
|
}
|
|
@@ -2239,40 +2492,41 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2239
2492
|
try {
|
|
2240
2493
|
var _this = this;
|
|
2241
2494
|
_this.assertNotCancelled(request);
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2495
|
+
return UploadManagerBase_await(BytescaleApiClientConfigUtils.getAccountIdAsync(_this.config), function (accountId) {
|
|
2496
|
+
var source = _this.processUploadSource(request.data);
|
|
2497
|
+
var preUploadInfo = _this.getPreUploadInfo(request, source);
|
|
2498
|
+
var bytesTotal = preUploadInfo.size;
|
|
2499
|
+
var makeOnProgressForPart = _this.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2500
|
+
var init = _this.preUpload(source);
|
|
2501
|
+
// Raise initial progress event SYNCHRONOUSLY.
|
|
2502
|
+
if (request.onProgress !== undefined) {
|
|
2503
|
+
request.onProgress(_this.makeProgressEvent(0, bytesTotal));
|
|
2504
|
+
}
|
|
2505
|
+
return UploadManagerBase_await(_this.beginUpload(request, preUploadInfo, accountId), function (uploadInfo) {
|
|
2506
|
+
var partCount = uploadInfo.uploadParts.count;
|
|
2507
|
+
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
2508
|
+
var _this$makeCancellatio = _this.makeCancellationMethods(),
|
|
2509
|
+
cancel = _this$makeCancellatio.cancel,
|
|
2510
|
+
addCancellationHandler = _this$makeCancellatio.addCancellationHandler;
|
|
2511
|
+
var intervalHandle = setInterval(_this.onIntervalTick(request, cancel), _this.intervalMs);
|
|
2512
|
+
var uploadedParts;
|
|
2513
|
+
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2514
|
+
return UploadManagerBase_await(_this.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2515
|
+
return _this.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler, accountId);
|
|
2516
|
+
})), function (_this$mapAsync) {
|
|
2517
|
+
uploadedParts = _this$mapAsync;
|
|
2518
|
+
return UploadManagerBase_awaitIgnored(_this.postUpload(init));
|
|
2519
|
+
});
|
|
2520
|
+
}, function (_wasThrown, _result) {
|
|
2521
|
+
clearInterval(intervalHandle);
|
|
2522
|
+
return UploadManagerBase_rethrow(_wasThrown, _result);
|
|
2523
|
+
}), function () {
|
|
2524
|
+
var etag = uploadedParts.flatMap(function (x) {
|
|
2525
|
+
return x.status === "Completed" ? [x.etag] : [];
|
|
2526
|
+
})[0];
|
|
2527
|
+
return Object.assign(Object.assign({}, uploadInfo.file), {
|
|
2528
|
+
etag: etag // The 'etag' in the original 'uploadInfo.file' will be null, so we set it to the final etag value here.
|
|
2529
|
+
});
|
|
2276
2530
|
});
|
|
2277
2531
|
});
|
|
2278
2532
|
});
|
|
@@ -2479,7 +2733,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2479
2733
|
var result = [];
|
|
2480
2734
|
var workQueue = UploadManagerBase_toConsumableArray(items);
|
|
2481
2735
|
return UploadManagerBase_await(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
|
|
2482
|
-
return _continueIgnored(
|
|
2736
|
+
return _continueIgnored(UploadManagerBase_for(function () {
|
|
2483
2737
|
return workQueue.length > 0;
|
|
2484
2738
|
}, void 0, function () {
|
|
2485
2739
|
var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
|
|
@@ -3217,15 +3471,27 @@ function Scheduler_toPrimitive(t, r) { if ("object" != Scheduler_typeof(t) || !t
|
|
|
3217
3471
|
* Q: Why not use 'setTimeout'?
|
|
3218
3472
|
* -------------------------
|
|
3219
3473
|
* A: setTimeout can be paused (e.g., during hibernation), risking JWT expiration before it triggers.
|
|
3220
|
-
* We therefore
|
|
3474
|
+
* We therefore check wall-clock time every second and on browser resume events. A backwards clock adjustment runs
|
|
3475
|
+
* scheduled callbacks immediately so authentication can be safely re-established against the server-provided TTL.
|
|
3221
3476
|
* -------------------------
|
|
3222
3477
|
*/
|
|
3223
3478
|
var Scheduler = /*#__PURE__*/function () {
|
|
3224
3479
|
function Scheduler() {
|
|
3480
|
+
var _this = this;
|
|
3225
3481
|
Scheduler_classCallCheck(this, Scheduler);
|
|
3482
|
+
this.clockRollbackToleranceMilliseconds = 1000;
|
|
3226
3483
|
this.callbacks = {};
|
|
3227
3484
|
this.nextId = 0;
|
|
3228
3485
|
this.intervalId = undefined;
|
|
3486
|
+
this.checkAfterResume = function () {
|
|
3487
|
+
return _this.checkCallbacks();
|
|
3488
|
+
};
|
|
3489
|
+
this.checkAfterVisibilityChange = function () {
|
|
3490
|
+
var _a;
|
|
3491
|
+
if (((_a = _this.documentEventTarget) === null || _a === void 0 ? void 0 : _a.visibilityState) === "visible") {
|
|
3492
|
+
_this.checkCallbacks();
|
|
3493
|
+
}
|
|
3494
|
+
};
|
|
3229
3495
|
}
|
|
3230
3496
|
return Scheduler_createClass(Scheduler, [{
|
|
3231
3497
|
key: "schedule",
|
|
@@ -3235,7 +3501,7 @@ var Scheduler = /*#__PURE__*/function () {
|
|
|
3235
3501
|
epoch: epoch,
|
|
3236
3502
|
callback: callback
|
|
3237
3503
|
};
|
|
3238
|
-
this.
|
|
3504
|
+
this.startMonitoring();
|
|
3239
3505
|
return handle;
|
|
3240
3506
|
}
|
|
3241
3507
|
}, {
|
|
@@ -3244,34 +3510,40 @@ var Scheduler = /*#__PURE__*/function () {
|
|
|
3244
3510
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
3245
3511
|
delete this.callbacks[handle];
|
|
3246
3512
|
if (Object.keys(this.callbacks).length === 0) {
|
|
3247
|
-
this.
|
|
3513
|
+
this.stopMonitoring();
|
|
3248
3514
|
}
|
|
3249
3515
|
}
|
|
3250
3516
|
}, {
|
|
3251
|
-
key: "
|
|
3252
|
-
value: function
|
|
3253
|
-
var
|
|
3517
|
+
key: "startMonitoring",
|
|
3518
|
+
value: function startMonitoring() {
|
|
3519
|
+
var _this2 = this;
|
|
3254
3520
|
if (this.intervalId === undefined) {
|
|
3521
|
+
this.lastObservedEpoch = Date.now();
|
|
3255
3522
|
this.intervalId = setInterval(function () {
|
|
3256
|
-
return
|
|
3523
|
+
return _this2.checkCallbacks();
|
|
3257
3524
|
}, 1000);
|
|
3525
|
+
this.startListeningForResume();
|
|
3258
3526
|
}
|
|
3259
3527
|
}
|
|
3260
3528
|
}, {
|
|
3261
|
-
key: "
|
|
3262
|
-
value: function
|
|
3529
|
+
key: "stopMonitoring",
|
|
3530
|
+
value: function stopMonitoring() {
|
|
3263
3531
|
if (this.intervalId !== undefined) {
|
|
3264
3532
|
clearInterval(this.intervalId);
|
|
3265
3533
|
this.intervalId = undefined;
|
|
3534
|
+
this.lastObservedEpoch = undefined;
|
|
3535
|
+
this.stopListeningForResume();
|
|
3266
3536
|
}
|
|
3267
3537
|
}
|
|
3268
3538
|
}, {
|
|
3269
3539
|
key: "checkCallbacks",
|
|
3270
3540
|
value: function checkCallbacks() {
|
|
3271
3541
|
var now = Date.now();
|
|
3542
|
+
var clockMovedBackwards = this.lastObservedEpoch !== undefined && now < this.lastObservedEpoch - this.clockRollbackToleranceMilliseconds;
|
|
3543
|
+
this.lastObservedEpoch = now;
|
|
3272
3544
|
for (var handleStr in this.callbacks) {
|
|
3273
3545
|
var handle = parseInt(handleStr);
|
|
3274
|
-
if (this.callbacks[handle].epoch <= now) {
|
|
3546
|
+
if (clockMovedBackwards || this.callbacks[handle].epoch <= now) {
|
|
3275
3547
|
try {
|
|
3276
3548
|
this.callbacks[handle].callback();
|
|
3277
3549
|
} catch (e) {
|
|
@@ -3281,6 +3553,38 @@ var Scheduler = /*#__PURE__*/function () {
|
|
|
3281
3553
|
}
|
|
3282
3554
|
}
|
|
3283
3555
|
}
|
|
3556
|
+
}, {
|
|
3557
|
+
key: "startListeningForResume",
|
|
3558
|
+
value: function startListeningForResume() {
|
|
3559
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
3560
|
+
this.windowEventTarget = window;
|
|
3561
|
+
for (var _i = 0, _arr = ["focus", "online", "pageshow"]; _i < _arr.length; _i++) {
|
|
3562
|
+
var eventName = _arr[_i];
|
|
3563
|
+
this.windowEventTarget.addEventListener(eventName, this.checkAfterResume);
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
if (typeof document !== "undefined" && typeof document.addEventListener === "function") {
|
|
3567
|
+
this.documentEventTarget = document;
|
|
3568
|
+
this.documentEventTarget.addEventListener("resume", this.checkAfterResume);
|
|
3569
|
+
this.documentEventTarget.addEventListener("visibilitychange", this.checkAfterVisibilityChange);
|
|
3570
|
+
}
|
|
3571
|
+
}
|
|
3572
|
+
}, {
|
|
3573
|
+
key: "stopListeningForResume",
|
|
3574
|
+
value: function stopListeningForResume() {
|
|
3575
|
+
if (this.windowEventTarget !== undefined) {
|
|
3576
|
+
for (var _i2 = 0, _arr2 = ["focus", "online", "pageshow"]; _i2 < _arr2.length; _i2++) {
|
|
3577
|
+
var eventName = _arr2[_i2];
|
|
3578
|
+
this.windowEventTarget.removeEventListener(eventName, this.checkAfterResume);
|
|
3579
|
+
}
|
|
3580
|
+
this.windowEventTarget = undefined;
|
|
3581
|
+
}
|
|
3582
|
+
if (this.documentEventTarget !== undefined) {
|
|
3583
|
+
this.documentEventTarget.removeEventListener("resume", this.checkAfterResume);
|
|
3584
|
+
this.documentEventTarget.removeEventListener("visibilitychange", this.checkAfterVisibilityChange);
|
|
3585
|
+
this.documentEventTarget = undefined;
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3284
3588
|
}]);
|
|
3285
3589
|
}();
|
|
3286
3590
|
;// ./src/public/browser/AuthManagerBrowser.ts
|
|
@@ -3602,10 +3906,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3602
3906
|
authConfigs: configs.map(function (config) {
|
|
3603
3907
|
return {
|
|
3604
3908
|
accessToken: undefined,
|
|
3909
|
+
authenticationPromise: Promise.resolve(),
|
|
3605
3910
|
config: config,
|
|
3606
3911
|
expiresAt: undefined,
|
|
3607
3912
|
jwt: undefined,
|
|
3608
|
-
refreshHandle: undefined
|
|
3913
|
+
refreshHandle: undefined,
|
|
3914
|
+
refreshPromise: undefined
|
|
3609
3915
|
};
|
|
3610
3916
|
}),
|
|
3611
3917
|
authServiceWorker: requiresServiceWorker && params.serviceWorkerScript !== undefined && canUseServiceWorkers ? {
|
|
@@ -3623,7 +3929,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3623
3929
|
})), function (session) {
|
|
3624
3930
|
return AuthManagerBrowser_catch(function () {
|
|
3625
3931
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_forOf((_a = session.authConfigs) !== null && _a !== void 0 ? _a : [], function (config) {
|
|
3626
|
-
return AuthManagerBrowser_awaitIgnored(_this2.refreshAuthConfig(session, config
|
|
3932
|
+
return AuthManagerBrowser_awaitIgnored(_this2.refreshAuthConfig(session, config));
|
|
3627
3933
|
}));
|
|
3628
3934
|
}, function (e) {
|
|
3629
3935
|
return AuthManagerBrowser_continue(AuthManagerBrowser_catch(function () {
|
|
@@ -3678,14 +3984,14 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3678
3984
|
return AuthManagerBrowser_invoke(function () {
|
|
3679
3985
|
if (session.authConfigs === undefined && typeof session.params.accountId === "string") {
|
|
3680
3986
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_catch(function () {
|
|
3681
|
-
return AuthManagerBrowser_awaitIgnored(_this3.deleteAccessToken(session.params.options, session.params.accountId));
|
|
3987
|
+
return AuthManagerBrowser_awaitIgnored(_this3.deleteAccessToken(session.params.options, _this3.getCdnUrl(session.params), session.params.accountId));
|
|
3682
3988
|
}, function (e) {
|
|
3683
3989
|
cleanupError = e;
|
|
3684
3990
|
}));
|
|
3685
3991
|
} else {
|
|
3686
3992
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_forOf(cookieConfigs, function (state) {
|
|
3687
3993
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_catch(function () {
|
|
3688
|
-
return AuthManagerBrowser_awaitIgnored(_this3.deleteAccessToken(session.params.options, state.config.accountId));
|
|
3994
|
+
return AuthManagerBrowser_awaitIgnored(_this3.deleteAccessToken(session.params.options, _this3.getConfigCdnUrl(session.params, state.config), state.config.accountId));
|
|
3689
3995
|
}, function (e) {
|
|
3690
3996
|
cleanupError !== null && cleanupError !== void 0 ? cleanupError : cleanupError = e;
|
|
3691
3997
|
}));
|
|
@@ -3714,16 +4020,48 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3714
4020
|
}, {
|
|
3715
4021
|
key: "refreshAuthConfig",
|
|
3716
4022
|
value: function refreshAuthConfig(session, state) {
|
|
3717
|
-
var rejectInvalidInitialToken = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
3718
4023
|
try {
|
|
4024
|
+
var _exit = false;
|
|
3719
4025
|
var _this4 = this;
|
|
3720
|
-
return AuthManagerBrowser_await(
|
|
4026
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_invoke(function () {
|
|
4027
|
+
if (state.refreshPromise !== undefined) {
|
|
4028
|
+
return AuthManagerBrowser_await(state.refreshPromise, function () {
|
|
4029
|
+
_exit = true;
|
|
4030
|
+
});
|
|
4031
|
+
}
|
|
4032
|
+
}, function (_result2) {
|
|
4033
|
+
if (_exit) return _result2;
|
|
4034
|
+
// Publish the pending operation before provider code can run, including provider code that calls back into the SDK.
|
|
4035
|
+
var refreshPromise = Promise.resolve().then(AuthManagerBrowser_async(function () {
|
|
4036
|
+
return _this4.performRefreshAuthConfig(session, state);
|
|
4037
|
+
}));
|
|
4038
|
+
state.authenticationPromise = refreshPromise;
|
|
4039
|
+
state.refreshPromise = refreshPromise;
|
|
4040
|
+
var clearRefreshPromise = function clearRefreshPromise() {
|
|
4041
|
+
if (state.refreshPromise === refreshPromise) {
|
|
4042
|
+
state.refreshPromise = undefined;
|
|
4043
|
+
}
|
|
4044
|
+
};
|
|
4045
|
+
refreshPromise.then(clearRefreshPromise, clearRefreshPromise);
|
|
4046
|
+
return AuthManagerBrowser_awaitIgnored(refreshPromise);
|
|
4047
|
+
}));
|
|
4048
|
+
} catch (e) {
|
|
4049
|
+
return Promise.reject(e);
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
}, {
|
|
4053
|
+
key: "performRefreshAuthConfig",
|
|
4054
|
+
value: function performRefreshAuthConfig(session, state) {
|
|
4055
|
+
try {
|
|
4056
|
+
var _this5 = this;
|
|
4057
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
3721
4058
|
var _a;
|
|
3722
4059
|
if (!session.isActive) {
|
|
3723
4060
|
return;
|
|
3724
4061
|
}
|
|
3725
4062
|
if (state.refreshHandle !== undefined) {
|
|
3726
|
-
|
|
4063
|
+
_this5.scheduler.unschedule(state.refreshHandle);
|
|
4064
|
+
state.refreshHandle = undefined;
|
|
3727
4065
|
}
|
|
3728
4066
|
var previous = {
|
|
3729
4067
|
accessToken: state.accessToken,
|
|
@@ -3731,27 +4069,27 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3731
4069
|
jwt: state.jwt,
|
|
3732
4070
|
serviceWorkerConfigured: session.serviceWorkerConfigured
|
|
3733
4071
|
};
|
|
3734
|
-
var refreshAt = Date.now() +
|
|
4072
|
+
var refreshAt = Date.now() + _this5.retryAuthAfterErrorSeconds * 1000;
|
|
3735
4073
|
return AuthManagerBrowser_finallyRethrows(function () {
|
|
3736
4074
|
return AuthManagerBrowser_catch(function () {
|
|
3737
|
-
return AuthManagerBrowser_await(
|
|
3738
|
-
var setCookie =
|
|
3739
|
-
return AuthManagerBrowser_await(
|
|
4075
|
+
return AuthManagerBrowser_await(_this5.getAuthorizationToken(session.params, state.config), function (jwt) {
|
|
4076
|
+
var setCookie = _this5.shouldSetCookie(session, state.config);
|
|
4077
|
+
return AuthManagerBrowser_await(_this5.setAccessToken(session.params.options, _this5.getConfigCdnUrl(session.params, state.config), state.config.accountId, jwt, setCookie), function (token) {
|
|
3740
4078
|
var expiresAt = Date.now() + token.ttlSeconds * 1000;
|
|
3741
4079
|
state.accessToken = token.accessToken;
|
|
3742
4080
|
state.expiresAt = expiresAt;
|
|
3743
4081
|
state.jwt = jwt;
|
|
3744
4082
|
return AuthManagerBrowser_invoke(function () {
|
|
3745
|
-
if (session.authServiceWorker !== undefined && (
|
|
3746
|
-
return AuthManagerBrowser_await(
|
|
3747
|
-
return AuthManagerBrowser_await(
|
|
4083
|
+
if (session.authServiceWorker !== undefined && (_this5.isServiceWorkerEnabled(state.config) || session.serviceWorkerConfigured !== true)) {
|
|
4084
|
+
return AuthManagerBrowser_await(_this5.sendCurrentServiceWorkerConfig(session), function () {
|
|
4085
|
+
return AuthManagerBrowser_await(_this5.waitForServiceWorker(), function () {
|
|
3748
4086
|
session.serviceWorkerConfigured = true;
|
|
3749
4087
|
});
|
|
3750
4088
|
});
|
|
3751
4089
|
}
|
|
3752
4090
|
}, function () {
|
|
3753
|
-
var desiredTtl = token.ttlSeconds -
|
|
3754
|
-
var actualTtl = Math.max(desiredTtl,
|
|
4091
|
+
var desiredTtl = token.ttlSeconds - _this5.refreshBeforeExpirySeconds;
|
|
4092
|
+
var actualTtl = Math.max(desiredTtl, _this5.minJwtTtlSeconds);
|
|
3755
4093
|
if (desiredTtl !== actualTtl) {
|
|
3756
4094
|
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(actualTtl, " seconds before refreshing."));
|
|
3757
4095
|
}
|
|
@@ -3765,18 +4103,18 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3765
4103
|
state.jwt = previous.jwt;
|
|
3766
4104
|
session.serviceWorkerConfigured = previous.serviceWorkerConfigured;
|
|
3767
4105
|
ConsoleUtils.warn("Unable to refresh JWT access token for auth config '".concat((_a = state.config.authConfigId) !== null && _a !== void 0 ? _a : "default", "': ").concat(e));
|
|
3768
|
-
if (
|
|
4106
|
+
if (_this5.isV2Params(session.params) && previous.accessToken === undefined && e instanceof InvalidAuthTokenError) {
|
|
3769
4107
|
throw e;
|
|
3770
4108
|
}
|
|
3771
4109
|
});
|
|
3772
|
-
}, function (_wasThrown,
|
|
3773
|
-
state.refreshHandle =
|
|
3774
|
-
|
|
4110
|
+
}, function (_wasThrown, _result3) {
|
|
4111
|
+
state.refreshHandle = _this5.scheduler.schedule(refreshAt, function () {
|
|
4112
|
+
_this5.refreshAuthConfig(session, state).then(function () {}, function (e) {
|
|
3775
4113
|
return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
|
|
3776
4114
|
});
|
|
3777
4115
|
});
|
|
3778
|
-
|
|
3779
|
-
return AuthManagerBrowser_rethrow(_wasThrown,
|
|
4116
|
+
_this5.updateSessionState(session);
|
|
4117
|
+
return AuthManagerBrowser_rethrow(_wasThrown, _result3);
|
|
3780
4118
|
});
|
|
3781
4119
|
}))));
|
|
3782
4120
|
} catch (e) {
|
|
@@ -3787,11 +4125,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3787
4125
|
key: "sendCurrentServiceWorkerConfig",
|
|
3788
4126
|
value: function sendCurrentServiceWorkerConfig(session) {
|
|
3789
4127
|
try {
|
|
3790
|
-
var
|
|
4128
|
+
var _this6 = this;
|
|
3791
4129
|
var _a;
|
|
3792
4130
|
var now = Date.now();
|
|
3793
4131
|
var config = ((_a = session.authConfigs) !== null && _a !== void 0 ? _a : []).flatMap(function (state) {
|
|
3794
|
-
if (!
|
|
4132
|
+
if (!_this6.isServiceWorkerEnabled(state.config) || state.jwt === undefined || state.expiresAt === undefined || state.expiresAt <= now) {
|
|
3795
4133
|
return [];
|
|
3796
4134
|
}
|
|
3797
4135
|
return [{
|
|
@@ -3801,10 +4139,10 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3801
4139
|
value: "Bearer ".concat(state.jwt)
|
|
3802
4140
|
}],
|
|
3803
4141
|
sourceUrlPrefixes: state.config.sourceUrlPrefixes,
|
|
3804
|
-
urlPrefix: "".concat(
|
|
4142
|
+
urlPrefix: "".concat(_this6.getConfigCdnUrl(session.params, state.config), "/").concat(state.config.accountId, "/")
|
|
3805
4143
|
}];
|
|
3806
4144
|
});
|
|
3807
|
-
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(
|
|
4145
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this6.sendServiceWorkerConfig(session, config, _this6.isV2Params(session.params) ? session.params.urlRewriteRules : undefined)));
|
|
3808
4146
|
} catch (e) {
|
|
3809
4147
|
return Promise.reject(e);
|
|
3810
4148
|
}
|
|
@@ -3813,21 +4151,21 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3813
4151
|
key: "sendServiceWorkerConfig",
|
|
3814
4152
|
value: function sendServiceWorkerConfig(session, config, urlRewriteRules) {
|
|
3815
4153
|
try {
|
|
3816
|
-
var
|
|
4154
|
+
var _this7 = this;
|
|
3817
4155
|
if (session.authServiceWorker === undefined) {
|
|
3818
4156
|
throw new Error("Service worker configuration cannot be applied because service workers are unavailable.");
|
|
3819
4157
|
}
|
|
3820
|
-
return AuthManagerBrowser_await(
|
|
4158
|
+
return AuthManagerBrowser_await(_this7.serviceWorkerUtils.sendMessage(Object.assign({
|
|
3821
4159
|
type: "SET_BYTESCALE_AUTH_CONFIG",
|
|
3822
4160
|
config: config.map(function (entry) {
|
|
3823
4161
|
return Object.assign(Object.assign({}, entry), {
|
|
3824
|
-
urlPrefix: "".concat(entry.sourceUrlPrefixes === undefined ? "" :
|
|
4162
|
+
urlPrefix: "".concat(entry.sourceUrlPrefixes === undefined ? "" : _this7.sourceScopedUrlPrefixMarker).concat(entry.urlPrefix)
|
|
3825
4163
|
});
|
|
3826
4164
|
})
|
|
3827
4165
|
}, urlRewriteRules === undefined ? {} : {
|
|
3828
4166
|
urlRewriteRules: urlRewriteRules
|
|
3829
|
-
}), session.authServiceWorker,
|
|
3830
|
-
session.authServiceWorker =
|
|
4167
|
+
}), session.authServiceWorker, _this7.serviceWorkerScriptFieldName), function (_this7$serviceWorkerU) {
|
|
4168
|
+
session.authServiceWorker = _this7$serviceWorkerU;
|
|
3831
4169
|
});
|
|
3832
4170
|
} catch (e) {
|
|
3833
4171
|
return Promise.reject(e);
|
|
@@ -3894,6 +4232,9 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3894
4232
|
if (isV2 && !this.isValidAccountId(config.accountId)) {
|
|
3895
4233
|
throw new Error("Invalid Bytescale account ID: '".concat(String(config.accountId), "'."));
|
|
3896
4234
|
}
|
|
4235
|
+
if (config.cdnUrl !== undefined && typeof config.cdnUrl !== "string") {
|
|
4236
|
+
throw new Error("The 'cdnUrl' field must be a string when provided.");
|
|
4237
|
+
}
|
|
3897
4238
|
if (config.enableCookieAuth !== undefined && typeof config.enableCookieAuth !== "boolean" || config.enableServiceWorkerAuth !== undefined && typeof config.enableServiceWorkerAuth !== "boolean") {
|
|
3898
4239
|
throw new Error("Authentication enablement flags must be booleans when provided.");
|
|
3899
4240
|
}
|
|
@@ -3914,7 +4255,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3914
4255
|
cookieConfig = config;
|
|
3915
4256
|
}
|
|
3916
4257
|
if (this.isServiceWorkerEnabled(config)) {
|
|
3917
|
-
var _prefix = "".concat(this.
|
|
4258
|
+
var _prefix = "".concat(this.getConfigCdnUrl(params, config), "/").concat(config.accountId, "/");
|
|
3918
4259
|
if (workerConfigsByPrefix.has(_prefix)) {
|
|
3919
4260
|
throw new Error("Multiple service-worker auth configurations target the same URL prefix: '".concat(_prefix, "'."));
|
|
3920
4261
|
}
|
|
@@ -3927,7 +4268,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3927
4268
|
_iterator2.f();
|
|
3928
4269
|
}
|
|
3929
4270
|
if (cookieConfig !== undefined) {
|
|
3930
|
-
var prefix = "".concat(this.
|
|
4271
|
+
var prefix = "".concat(this.getConfigCdnUrl(params, cookieConfig), "/").concat(cookieConfig.accountId, "/");
|
|
3931
4272
|
var workerConfig = workerConfigsByPrefix.get(prefix);
|
|
3932
4273
|
if (workerConfig !== undefined && workerConfig !== cookieConfig) {
|
|
3933
4274
|
throw new Error("Cookie and service-worker authentication cannot target the same account from different configs.");
|
|
@@ -3955,7 +4296,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3955
4296
|
}, {
|
|
3956
4297
|
key: "updateSessionState",
|
|
3957
4298
|
value: function updateSessionState(session) {
|
|
3958
|
-
var
|
|
4299
|
+
var _this8 = this;
|
|
3959
4300
|
var _a;
|
|
3960
4301
|
var configs = (_a = session.authConfigs) !== null && _a !== void 0 ? _a : [];
|
|
3961
4302
|
var defaultConfig = configs.find(function (state) {
|
|
@@ -3965,7 +4306,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3965
4306
|
session.accessToken = exposeLegacyDefault && defaultConfig !== undefined && this.isConfigUsable(defaultConfig) ? defaultConfig.accessToken : undefined;
|
|
3966
4307
|
session.accessTokenRefreshHandle = exposeLegacyDefault ? defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.refreshHandle : undefined;
|
|
3967
4308
|
session.isReady = configs.length > 0 && configs.every(function (state) {
|
|
3968
|
-
return
|
|
4309
|
+
return _this8.isConfigUsable(state);
|
|
3969
4310
|
}) && (session.authServiceWorker === undefined || session.serviceWorkerConfigured === true);
|
|
3970
4311
|
}
|
|
3971
4312
|
}, {
|
|
@@ -4006,8 +4347,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4006
4347
|
}
|
|
4007
4348
|
}, {
|
|
4008
4349
|
key: "getAccessTokenUrl",
|
|
4009
|
-
value: function getAccessTokenUrl(
|
|
4010
|
-
return "".concat(
|
|
4350
|
+
value: function getAccessTokenUrl(cdnUrl, accountId, setCookie) {
|
|
4351
|
+
return "".concat(cdnUrl, "/api/v1/access_tokens/").concat(accountId, "?set-cookie=").concat(setCookie ? "true" : "false");
|
|
4011
4352
|
}
|
|
4012
4353
|
}, {
|
|
4013
4354
|
key: "getCdnUrl",
|
|
@@ -4015,12 +4356,20 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4015
4356
|
var _a;
|
|
4016
4357
|
return BytescaleApiClientConfigUtils.getCdnUrl((_a = params.options) !== null && _a !== void 0 ? _a : {});
|
|
4017
4358
|
}
|
|
4359
|
+
}, {
|
|
4360
|
+
key: "getConfigCdnUrl",
|
|
4361
|
+
value: function getConfigCdnUrl(params, config) {
|
|
4362
|
+
var _a, _b;
|
|
4363
|
+
return BytescaleApiClientConfigUtils.getCdnUrl({
|
|
4364
|
+
cdnUrl: (_a = config.cdnUrl) !== null && _a !== void 0 ? _a : (_b = params.options) === null || _b === void 0 ? void 0 : _b.cdnUrl
|
|
4365
|
+
});
|
|
4366
|
+
}
|
|
4018
4367
|
}, {
|
|
4019
4368
|
key: "deleteAccessToken",
|
|
4020
|
-
value: function deleteAccessToken(options, accountId) {
|
|
4369
|
+
value: function deleteAccessToken(options, cdnUrl, accountId) {
|
|
4021
4370
|
try {
|
|
4022
|
-
var
|
|
4023
|
-
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(
|
|
4371
|
+
var _this9 = this;
|
|
4372
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this9.getAccessTokenUrl(cdnUrl, accountId, true), {
|
|
4024
4373
|
method: "DELETE",
|
|
4025
4374
|
credentials: "include",
|
|
4026
4375
|
headers: {}
|
|
@@ -4034,16 +4383,16 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4034
4383
|
}
|
|
4035
4384
|
}, {
|
|
4036
4385
|
key: "setAccessToken",
|
|
4037
|
-
value: function setAccessToken(options, accountId, jwt, setCookie) {
|
|
4386
|
+
value: function setAccessToken(options, cdnUrl, accountId, jwt, setCookie) {
|
|
4038
4387
|
try {
|
|
4039
|
-
var
|
|
4388
|
+
var _this0 = this;
|
|
4040
4389
|
var request = {
|
|
4041
4390
|
accessToken: jwt
|
|
4042
4391
|
};
|
|
4043
|
-
return AuthManagerBrowser_await(BaseAPI.fetch(
|
|
4392
|
+
return AuthManagerBrowser_await(BaseAPI.fetch(_this0.getAccessTokenUrl(cdnUrl, accountId, setCookie), {
|
|
4044
4393
|
method: "PUT",
|
|
4045
4394
|
credentials: "include",
|
|
4046
|
-
headers: AuthManagerBrowser_defineProperty({},
|
|
4395
|
+
headers: AuthManagerBrowser_defineProperty({}, _this0.contentType, _this0.contentTypeJson),
|
|
4047
4396
|
body: JSON.stringify(request)
|
|
4048
4397
|
}, {
|
|
4049
4398
|
isBytescaleApi: true,
|
|
@@ -4064,20 +4413,20 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4064
4413
|
key: "getAuthorizationToken",
|
|
4065
4414
|
value: function getAuthorizationToken(params, config) {
|
|
4066
4415
|
try {
|
|
4067
|
-
var
|
|
4068
|
-
var
|
|
4416
|
+
var _exit2 = false;
|
|
4417
|
+
var _this1 = this;
|
|
4069
4418
|
var _a, _b;
|
|
4070
4419
|
return AuthManagerBrowser_await(AuthManagerBrowser_invoke(function () {
|
|
4071
4420
|
if (typeof config.getAuthorizationToken === "function") {
|
|
4072
|
-
var _validateJwt =
|
|
4421
|
+
var _validateJwt = _this1.validateJwt;
|
|
4073
4422
|
return AuthManagerBrowser_await(config.getAuthorizationToken(), function (_config$getAuthorizat) {
|
|
4074
|
-
var
|
|
4075
|
-
|
|
4076
|
-
return
|
|
4423
|
+
var _this1$validateJwt = _validateJwt.call(_this1, _config$getAuthorizat, "The 'getAuthorizationToken' callback");
|
|
4424
|
+
_exit2 = true;
|
|
4425
|
+
return _this1$validateJwt;
|
|
4077
4426
|
});
|
|
4078
4427
|
}
|
|
4079
|
-
}, function (
|
|
4080
|
-
if (
|
|
4428
|
+
}, function (_result4) {
|
|
4429
|
+
if (_exit2) return _result4;
|
|
4081
4430
|
var endpointName = "Your auth API endpoint";
|
|
4082
4431
|
var _fetch = BaseAPI.fetch,
|
|
4083
4432
|
_config$authUrl = config.authUrl;
|
|
@@ -4089,13 +4438,13 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4089
4438
|
isBytescaleApi: false,
|
|
4090
4439
|
fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
|
|
4091
4440
|
}), function (result) {
|
|
4092
|
-
var actualContentType = (_b = result.headers.get(
|
|
4093
|
-
if (actualContentType.split(";")[0] !==
|
|
4094
|
-
throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(
|
|
4441
|
+
var actualContentType = (_b = result.headers.get(_this1.contentType)) !== null && _b !== void 0 ? _b : "";
|
|
4442
|
+
if (actualContentType.split(";")[0] !== _this1.contentTypeText) {
|
|
4443
|
+
throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this1.contentType, " response header, but the Bytescale SDK requires \"").concat(_this1.contentTypeText, "\"."));
|
|
4095
4444
|
}
|
|
4096
|
-
var _validateJwt2 =
|
|
4445
|
+
var _validateJwt2 = _this1.validateJwt;
|
|
4097
4446
|
return AuthManagerBrowser_await(result.text(), function (_result$text) {
|
|
4098
|
-
return _validateJwt2.call(
|
|
4447
|
+
return _validateJwt2.call(_this1, _result$text, endpointName);
|
|
4099
4448
|
});
|
|
4100
4449
|
});
|
|
4101
4450
|
});
|