@bytescale/sdk 3.60.0 → 3.62.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 +91 -0
- package/dist/browser/cjs/main.js +508 -161
- package/dist/browser/esm/main.mjs +508 -161
- 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/dtos/AuthSwConfigEntryDto.d.ts +3 -1
- package/dist/types/private/model/AuthSession.d.ts +4 -0
- package/dist/types/private/model/AuthSessionConfigBase.d.ts +8 -0
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +3 -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 +115 -2
- package/tests/AuthManagerBrowser.test.ts +145 -2
- package/tests/AuthServiceWorkerRequestScope.test.ts +259 -0
- package/tests/AuthServiceWorkerRewrite.test.ts +17 -152
- package/tests/Scheduler.test.ts +135 -0
- package/tests/UploadManagerAuth.test.ts +30 -0
- package/tests/fixtures/auth-sw-3.61.0.js +272 -0
- package/tests/utils/AuthServiceWorkerHarness.ts +183 -0
|
@@ -153,6 +153,177 @@ var FairMutex = /*#__PURE__*/function () {
|
|
|
153
153
|
}]);
|
|
154
154
|
}();
|
|
155
155
|
;// ./src/private/AuthSessionState.ts
|
|
156
|
+
function AuthSessionState_empty() {}
|
|
157
|
+
function AuthSessionState_awaitIgnored(value, direct) {
|
|
158
|
+
if (!direct) {
|
|
159
|
+
return value && value.then ? value.then(AuthSessionState_empty) : Promise.resolve();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function AuthSessionState_invoke(body, then) {
|
|
163
|
+
var result = body();
|
|
164
|
+
if (result && result.then) {
|
|
165
|
+
return result.then(then);
|
|
166
|
+
}
|
|
167
|
+
return then(result);
|
|
168
|
+
}
|
|
169
|
+
function _settle(pact, state, value) {
|
|
170
|
+
if (!pact.s) {
|
|
171
|
+
if (value instanceof _Pact) {
|
|
172
|
+
if (value.s) {
|
|
173
|
+
if (state & 1) {
|
|
174
|
+
state = value.s;
|
|
175
|
+
}
|
|
176
|
+
value = value.v;
|
|
177
|
+
} else {
|
|
178
|
+
value.o = _settle.bind(null, pact, state);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (value && value.then) {
|
|
183
|
+
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
pact.s = state;
|
|
187
|
+
pact.v = value;
|
|
188
|
+
var observer = pact.o;
|
|
189
|
+
if (observer) {
|
|
190
|
+
observer(pact);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
var _Pact = /*#__PURE__*/function () {
|
|
195
|
+
function _Pact() {}
|
|
196
|
+
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
197
|
+
var result = new _Pact();
|
|
198
|
+
var state = this.s;
|
|
199
|
+
if (state) {
|
|
200
|
+
var callback = state & 1 ? onFulfilled : onRejected;
|
|
201
|
+
if (callback) {
|
|
202
|
+
try {
|
|
203
|
+
_settle(result, 1, callback(this.v));
|
|
204
|
+
} catch (e) {
|
|
205
|
+
_settle(result, 2, e);
|
|
206
|
+
}
|
|
207
|
+
return result;
|
|
208
|
+
} else {
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
this.o = function (_this) {
|
|
213
|
+
try {
|
|
214
|
+
var value = _this.v;
|
|
215
|
+
if (_this.s & 1) {
|
|
216
|
+
_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
217
|
+
} else if (onRejected) {
|
|
218
|
+
_settle(result, 1, onRejected(value));
|
|
219
|
+
} else {
|
|
220
|
+
_settle(result, 2, value);
|
|
221
|
+
}
|
|
222
|
+
} catch (e) {
|
|
223
|
+
_settle(result, 2, e);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
return result;
|
|
227
|
+
};
|
|
228
|
+
return _Pact;
|
|
229
|
+
}();
|
|
230
|
+
function _isSettledPact(thenable) {
|
|
231
|
+
return thenable instanceof _Pact && thenable.s & 1;
|
|
232
|
+
}
|
|
233
|
+
function _for(test, update, body) {
|
|
234
|
+
var stage;
|
|
235
|
+
for (;;) {
|
|
236
|
+
var shouldContinue = test();
|
|
237
|
+
if (_isSettledPact(shouldContinue)) {
|
|
238
|
+
shouldContinue = shouldContinue.v;
|
|
239
|
+
}
|
|
240
|
+
if (!shouldContinue) {
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
if (shouldContinue.then) {
|
|
244
|
+
stage = 0;
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
var result = body();
|
|
248
|
+
if (result && result.then) {
|
|
249
|
+
if (_isSettledPact(result)) {
|
|
250
|
+
result = result.s;
|
|
251
|
+
} else {
|
|
252
|
+
stage = 1;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (update) {
|
|
257
|
+
var updateValue = update();
|
|
258
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
259
|
+
stage = 2;
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
var pact = new _Pact();
|
|
265
|
+
var reject = _settle.bind(null, pact, 2);
|
|
266
|
+
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
267
|
+
return pact;
|
|
268
|
+
function _resumeAfterBody(value) {
|
|
269
|
+
result = value;
|
|
270
|
+
do {
|
|
271
|
+
if (update) {
|
|
272
|
+
updateValue = update();
|
|
273
|
+
if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
|
|
274
|
+
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
shouldContinue = test();
|
|
279
|
+
if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
280
|
+
_settle(pact, 1, result);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (shouldContinue.then) {
|
|
284
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
result = body();
|
|
288
|
+
if (_isSettledPact(result)) {
|
|
289
|
+
result = result.v;
|
|
290
|
+
}
|
|
291
|
+
} while (!result || !result.then);
|
|
292
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
293
|
+
}
|
|
294
|
+
function _resumeAfterTest(shouldContinue) {
|
|
295
|
+
if (shouldContinue) {
|
|
296
|
+
result = body();
|
|
297
|
+
if (result && result.then) {
|
|
298
|
+
result.then(_resumeAfterBody).then(void 0, reject);
|
|
299
|
+
} else {
|
|
300
|
+
_resumeAfterBody(result);
|
|
301
|
+
}
|
|
302
|
+
} else {
|
|
303
|
+
_settle(pact, 1, result);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function _resumeAfterUpdate() {
|
|
307
|
+
if (shouldContinue = test()) {
|
|
308
|
+
if (shouldContinue.then) {
|
|
309
|
+
shouldContinue.then(_resumeAfterTest).then(void 0, reject);
|
|
310
|
+
} else {
|
|
311
|
+
_resumeAfterTest(shouldContinue);
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
_settle(pact, 1, result);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function AuthSessionState_await(value, then, direct) {
|
|
319
|
+
if (direct) {
|
|
320
|
+
return then ? then(value) : value;
|
|
321
|
+
}
|
|
322
|
+
if (!value || !value.then) {
|
|
323
|
+
value = Promise.resolve(value);
|
|
324
|
+
}
|
|
325
|
+
return then ? value.then(then) : value;
|
|
326
|
+
}
|
|
156
327
|
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); }
|
|
157
328
|
function AuthSessionState_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
158
329
|
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); } }
|
|
@@ -259,6 +430,54 @@ var AuthSessionState = /*#__PURE__*/function () {
|
|
|
259
430
|
jwt: undefined
|
|
260
431
|
};
|
|
261
432
|
}
|
|
433
|
+
/** Waits for request-time auth to be current before resolving it. */
|
|
434
|
+
}, {
|
|
435
|
+
key: "resolveAuthConfigAsync",
|
|
436
|
+
value: function resolveAuthConfigAsync(authConfigId, requireReadyDefault) {
|
|
437
|
+
try {
|
|
438
|
+
var _exit = false;
|
|
439
|
+
var _a, _b;
|
|
440
|
+
if (authConfigId === false) {
|
|
441
|
+
return AuthSessionState_await(undefined);
|
|
442
|
+
}
|
|
443
|
+
return AuthSessionState_await(_for(function () {
|
|
444
|
+
return !_exit;
|
|
445
|
+
}, void 0, function () {
|
|
446
|
+
var session = AuthSessionState.getSession();
|
|
447
|
+
if (session === undefined || !session.isActive || !Array.isArray(session.authConfigs)) {
|
|
448
|
+
var _AuthSessionState$res = AuthSessionState.resolveAuthConfig(authConfigId, requireReadyDefault);
|
|
449
|
+
_exit = true;
|
|
450
|
+
return _AuthSessionState$res;
|
|
451
|
+
}
|
|
452
|
+
var state = session.authConfigs.find(function (config) {
|
|
453
|
+
return config.config.authConfigId === authConfigId;
|
|
454
|
+
});
|
|
455
|
+
if (state === undefined) {
|
|
456
|
+
var _AuthSessionState$res2 = AuthSessionState.resolveAuthConfig(authConfigId, requireReadyDefault);
|
|
457
|
+
_exit = true;
|
|
458
|
+
return _AuthSessionState$res2;
|
|
459
|
+
}
|
|
460
|
+
var authenticationPromise = (_a = state.authenticationPromise) !== null && _a !== void 0 ? _a : state.refreshPromise;
|
|
461
|
+
return AuthSessionState_invoke(function () {
|
|
462
|
+
if (authenticationPromise !== undefined) {
|
|
463
|
+
return AuthSessionState_awaitIgnored(authenticationPromise);
|
|
464
|
+
}
|
|
465
|
+
}, function () {
|
|
466
|
+
if (AuthSessionState.getSession() !== session || !session.isActive) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
var currentAuthenticationPromise = (_b = state.authenticationPromise) !== null && _b !== void 0 ? _b : state.refreshPromise;
|
|
470
|
+
if (currentAuthenticationPromise === undefined || currentAuthenticationPromise === authenticationPromise) {
|
|
471
|
+
var _AuthSessionState$res3 = AuthSessionState.resolveAuthConfig(authConfigId, true);
|
|
472
|
+
_exit = true;
|
|
473
|
+
return _AuthSessionState$res3;
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
}));
|
|
477
|
+
} catch (e) {
|
|
478
|
+
return Promise.reject(e);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
262
481
|
}]);
|
|
263
482
|
}();
|
|
264
483
|
AuthSessionState.stateKey = "BytescaleSessionState";
|
|
@@ -404,12 +623,43 @@ var BytescaleApiClientConfigUtils = /*#__PURE__*/function () {
|
|
|
404
623
|
value: function getAccountId(config) {
|
|
405
624
|
return BytescaleApiClientConfigUtils.resolveAuthentication(config).accountId;
|
|
406
625
|
}
|
|
626
|
+
}, {
|
|
627
|
+
key: "getAccountIdAsync",
|
|
628
|
+
value: function getAccountIdAsync(config) {
|
|
629
|
+
try {
|
|
630
|
+
return runtime_await(BytescaleApiClientConfigUtils.resolveAuthenticationAsync(config), function (_BytescaleApiClientCo) {
|
|
631
|
+
return _BytescaleApiClientCo.accountId;
|
|
632
|
+
});
|
|
633
|
+
} catch (e) {
|
|
634
|
+
return Promise.reject(e);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
407
637
|
}, {
|
|
408
638
|
key: "resolveAuthentication",
|
|
409
639
|
value: function resolveAuthentication(config) {
|
|
410
|
-
var _a
|
|
640
|
+
var _a;
|
|
411
641
|
var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
|
|
412
642
|
var authConfig = AuthSessionState.resolveAuthConfig(config.authConfigId, apiKey === undefined);
|
|
643
|
+
return BytescaleApiClientConfigUtils.resolveAuthenticationWithAuthConfig(config, authConfig);
|
|
644
|
+
}
|
|
645
|
+
}, {
|
|
646
|
+
key: "resolveAuthenticationAsync",
|
|
647
|
+
value: function resolveAuthenticationAsync(config) {
|
|
648
|
+
try {
|
|
649
|
+
var _a;
|
|
650
|
+
var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
|
|
651
|
+
return runtime_await(AuthSessionState.resolveAuthConfigAsync(config.authConfigId, apiKey === undefined), function (authConfig) {
|
|
652
|
+
return BytescaleApiClientConfigUtils.resolveAuthenticationWithAuthConfig(config, authConfig);
|
|
653
|
+
});
|
|
654
|
+
} catch (e) {
|
|
655
|
+
return Promise.reject(e);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}, {
|
|
659
|
+
key: "resolveAuthenticationWithAuthConfig",
|
|
660
|
+
value: function resolveAuthenticationWithAuthConfig(config, authConfig) {
|
|
661
|
+
var _a, _b;
|
|
662
|
+
var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
|
|
413
663
|
var apiKeyAccountId = apiKey === undefined ? undefined : BytescaleApiClientConfigUtils.getApiKeyAccountId(apiKey);
|
|
414
664
|
if (apiKeyAccountId !== undefined && authConfig !== undefined && apiKeyAccountId !== authConfig.accountId) {
|
|
415
665
|
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, "'."));
|
|
@@ -496,7 +746,6 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
496
746
|
try {
|
|
497
747
|
var _this = this;
|
|
498
748
|
var _a;
|
|
499
|
-
Object.assign(context.headers, BytescaleApiClientConfigUtils.resolveAuthentication(_this.config).headers);
|
|
500
749
|
// Key: any possible value for 'baseUrlOverride'
|
|
501
750
|
// Value: user-overridden value for that base URL from the config.
|
|
502
751
|
var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this.config));
|
|
@@ -537,44 +786,48 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
537
786
|
}
|
|
538
787
|
var configHeaders = _this2.config.headers;
|
|
539
788
|
return runtime_await(runtime_await(configHeaders === undefined ? {} : typeof configHeaders === "function" ? configHeaders() : configHeaders, function (resolvedConfigHeaders) {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
789
|
+
var _context$headers = context.headers;
|
|
790
|
+
return runtime_await(BytescaleApiClientConfigUtils.resolveAuthenticationAsync(_this2.config), function (_BytescaleApiClientCo2) {
|
|
791
|
+
Object.assign(_context$headers, _BytescaleApiClientCo2.headers);
|
|
792
|
+
for (var _i = 0, _Object$keys = Object.keys(resolvedConfigHeaders); _i < _Object$keys.length; _i++) {
|
|
793
|
+
var key = _Object$keys[_i];
|
|
794
|
+
if (key.toLowerCase() === "authorization" || key.toLowerCase() === "authorization-token") {
|
|
795
|
+
for (var _i2 = 0, _Object$keys2 = Object.keys(context.headers); _i2 < _Object$keys2.length; _i2++) {
|
|
796
|
+
var generatedKey = _Object$keys2[_i2];
|
|
797
|
+
if (generatedKey.toLowerCase() === key.toLowerCase()) {
|
|
798
|
+
// Custom auth headers have documented precedence; remove the generated spelling to make that deterministic.
|
|
799
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
800
|
+
delete context.headers[generatedKey];
|
|
801
|
+
}
|
|
549
802
|
}
|
|
550
803
|
}
|
|
551
804
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
return headers[key] === undefined ? delete headers[key] : {};
|
|
556
|
-
});
|
|
557
|
-
var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
|
|
558
|
-
return runtime_await(initOverrides);
|
|
559
|
-
};
|
|
560
|
-
var initParams = {
|
|
561
|
-
method: context.method,
|
|
562
|
-
headers: headers,
|
|
563
|
-
body: context.body
|
|
564
|
-
};
|
|
565
|
-
var _Object$assign = Object.assign({}, initParams);
|
|
566
|
-
return runtime_await(initOverrideFn({
|
|
567
|
-
init: initParams,
|
|
568
|
-
context: context
|
|
569
|
-
}), function (_initOverrideFn) {
|
|
570
|
-
var overriddenInit = Object.assign(_Object$assign, _initOverrideFn);
|
|
571
|
-
var init = Object.assign(Object.assign({}, overriddenInit), {
|
|
572
|
-
body: JSON.stringify(overriddenInit.body)
|
|
805
|
+
var headers = Object.assign(Object.assign({}, context.headers), resolvedConfigHeaders);
|
|
806
|
+
Object.keys(headers).forEach(function (key) {
|
|
807
|
+
return headers[key] === undefined ? delete headers[key] : {};
|
|
573
808
|
});
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
init: init
|
|
809
|
+
var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
|
|
810
|
+
return runtime_await(initOverrides);
|
|
577
811
|
};
|
|
812
|
+
var initParams = {
|
|
813
|
+
method: context.method,
|
|
814
|
+
headers: headers,
|
|
815
|
+
body: context.body
|
|
816
|
+
};
|
|
817
|
+
var _Object$assign = Object.assign({}, initParams);
|
|
818
|
+
return runtime_await(initOverrideFn({
|
|
819
|
+
init: initParams,
|
|
820
|
+
context: context
|
|
821
|
+
}), function (_initOverrideFn) {
|
|
822
|
+
var overriddenInit = Object.assign(_Object$assign, _initOverrideFn);
|
|
823
|
+
var init = Object.assign(Object.assign({}, overriddenInit), {
|
|
824
|
+
body: JSON.stringify(overriddenInit.body)
|
|
825
|
+
});
|
|
826
|
+
return {
|
|
827
|
+
url: url,
|
|
828
|
+
init: init
|
|
829
|
+
};
|
|
830
|
+
});
|
|
578
831
|
});
|
|
579
832
|
}, configHeaders === undefined || !(typeof configHeaders === "function")));
|
|
580
833
|
} catch (e) {
|
|
@@ -602,8 +855,8 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
602
855
|
// unless the following is set.
|
|
603
856
|
// https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
|
|
604
857
|
duplex: "half"
|
|
605
|
-
})), function (
|
|
606
|
-
response =
|
|
858
|
+
})), function (_BytescaleApiClientCo3) {
|
|
859
|
+
response = _BytescaleApiClientCo3;
|
|
607
860
|
});
|
|
608
861
|
}, function (e) {
|
|
609
862
|
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
@@ -2014,21 +2267,21 @@ function _invokeIgnored(body) {
|
|
|
2014
2267
|
return result.then(UploadManagerBase_empty);
|
|
2015
2268
|
}
|
|
2016
2269
|
}
|
|
2017
|
-
function
|
|
2270
|
+
function UploadManagerBase_settle(pact, state, value) {
|
|
2018
2271
|
if (!pact.s) {
|
|
2019
|
-
if (value instanceof
|
|
2272
|
+
if (value instanceof UploadManagerBase_Pact) {
|
|
2020
2273
|
if (value.s) {
|
|
2021
2274
|
if (state & 1) {
|
|
2022
2275
|
state = value.s;
|
|
2023
2276
|
}
|
|
2024
2277
|
value = value.v;
|
|
2025
2278
|
} else {
|
|
2026
|
-
value.o =
|
|
2279
|
+
value.o = UploadManagerBase_settle.bind(null, pact, state);
|
|
2027
2280
|
return;
|
|
2028
2281
|
}
|
|
2029
2282
|
}
|
|
2030
2283
|
if (value && value.then) {
|
|
2031
|
-
value.then(
|
|
2284
|
+
value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
|
|
2032
2285
|
return;
|
|
2033
2286
|
}
|
|
2034
2287
|
pact.s = state;
|
|
@@ -2039,7 +2292,7 @@ function _settle(pact, state, value) {
|
|
|
2039
2292
|
}
|
|
2040
2293
|
}
|
|
2041
2294
|
}
|
|
2042
|
-
var
|
|
2295
|
+
var UploadManagerBase_Pact = /*#__PURE__*/function () {
|
|
2043
2296
|
function _Pact() {}
|
|
2044
2297
|
_Pact.prototype.then = function (onFulfilled, onRejected) {
|
|
2045
2298
|
var result = new _Pact();
|
|
@@ -2048,9 +2301,9 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
2048
2301
|
var callback = state & 1 ? onFulfilled : onRejected;
|
|
2049
2302
|
if (callback) {
|
|
2050
2303
|
try {
|
|
2051
|
-
|
|
2304
|
+
UploadManagerBase_settle(result, 1, callback(this.v));
|
|
2052
2305
|
} catch (e) {
|
|
2053
|
-
|
|
2306
|
+
UploadManagerBase_settle(result, 2, e);
|
|
2054
2307
|
}
|
|
2055
2308
|
return result;
|
|
2056
2309
|
} else {
|
|
@@ -2061,28 +2314,28 @@ var _Pact = /*#__PURE__*/function () {
|
|
|
2061
2314
|
try {
|
|
2062
2315
|
var value = _this.v;
|
|
2063
2316
|
if (_this.s & 1) {
|
|
2064
|
-
|
|
2317
|
+
UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
|
|
2065
2318
|
} else if (onRejected) {
|
|
2066
|
-
|
|
2319
|
+
UploadManagerBase_settle(result, 1, onRejected(value));
|
|
2067
2320
|
} else {
|
|
2068
|
-
|
|
2321
|
+
UploadManagerBase_settle(result, 2, value);
|
|
2069
2322
|
}
|
|
2070
2323
|
} catch (e) {
|
|
2071
|
-
|
|
2324
|
+
UploadManagerBase_settle(result, 2, e);
|
|
2072
2325
|
}
|
|
2073
2326
|
};
|
|
2074
2327
|
return result;
|
|
2075
2328
|
};
|
|
2076
2329
|
return _Pact;
|
|
2077
2330
|
}();
|
|
2078
|
-
function
|
|
2079
|
-
return thenable instanceof
|
|
2331
|
+
function UploadManagerBase_isSettledPact(thenable) {
|
|
2332
|
+
return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
|
|
2080
2333
|
}
|
|
2081
|
-
function
|
|
2334
|
+
function UploadManagerBase_for(test, update, body) {
|
|
2082
2335
|
var stage;
|
|
2083
2336
|
for (;;) {
|
|
2084
2337
|
var shouldContinue = test();
|
|
2085
|
-
if (
|
|
2338
|
+
if (UploadManagerBase_isSettledPact(shouldContinue)) {
|
|
2086
2339
|
shouldContinue = shouldContinue.v;
|
|
2087
2340
|
}
|
|
2088
2341
|
if (!shouldContinue) {
|
|
@@ -2094,7 +2347,7 @@ function _for(test, update, body) {
|
|
|
2094
2347
|
}
|
|
2095
2348
|
var result = body();
|
|
2096
2349
|
if (result && result.then) {
|
|
2097
|
-
if (
|
|
2350
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
2098
2351
|
result = result.s;
|
|
2099
2352
|
} else {
|
|
2100
2353
|
stage = 1;
|
|
@@ -2103,14 +2356,14 @@ function _for(test, update, body) {
|
|
|
2103
2356
|
}
|
|
2104
2357
|
if (update) {
|
|
2105
2358
|
var updateValue = update();
|
|
2106
|
-
if (updateValue && updateValue.then && !
|
|
2359
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
2107
2360
|
stage = 2;
|
|
2108
2361
|
break;
|
|
2109
2362
|
}
|
|
2110
2363
|
}
|
|
2111
2364
|
}
|
|
2112
|
-
var pact = new
|
|
2113
|
-
var reject =
|
|
2365
|
+
var pact = new UploadManagerBase_Pact();
|
|
2366
|
+
var reject = UploadManagerBase_settle.bind(null, pact, 2);
|
|
2114
2367
|
(stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
|
|
2115
2368
|
return pact;
|
|
2116
2369
|
function _resumeAfterBody(value) {
|
|
@@ -2118,14 +2371,14 @@ function _for(test, update, body) {
|
|
|
2118
2371
|
do {
|
|
2119
2372
|
if (update) {
|
|
2120
2373
|
updateValue = update();
|
|
2121
|
-
if (updateValue && updateValue.then && !
|
|
2374
|
+
if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
|
|
2122
2375
|
updateValue.then(_resumeAfterUpdate).then(void 0, reject);
|
|
2123
2376
|
return;
|
|
2124
2377
|
}
|
|
2125
2378
|
}
|
|
2126
2379
|
shouldContinue = test();
|
|
2127
|
-
if (!shouldContinue ||
|
|
2128
|
-
|
|
2380
|
+
if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
|
|
2381
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
2129
2382
|
return;
|
|
2130
2383
|
}
|
|
2131
2384
|
if (shouldContinue.then) {
|
|
@@ -2133,7 +2386,7 @@ function _for(test, update, body) {
|
|
|
2133
2386
|
return;
|
|
2134
2387
|
}
|
|
2135
2388
|
result = body();
|
|
2136
|
-
if (
|
|
2389
|
+
if (UploadManagerBase_isSettledPact(result)) {
|
|
2137
2390
|
result = result.v;
|
|
2138
2391
|
}
|
|
2139
2392
|
} while (!result || !result.then);
|
|
@@ -2148,7 +2401,7 @@ function _for(test, update, body) {
|
|
|
2148
2401
|
_resumeAfterBody(result);
|
|
2149
2402
|
}
|
|
2150
2403
|
} else {
|
|
2151
|
-
|
|
2404
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
2152
2405
|
}
|
|
2153
2406
|
}
|
|
2154
2407
|
function _resumeAfterUpdate() {
|
|
@@ -2159,7 +2412,7 @@ function _for(test, update, body) {
|
|
|
2159
2412
|
_resumeAfterTest(shouldContinue);
|
|
2160
2413
|
}
|
|
2161
2414
|
} else {
|
|
2162
|
-
|
|
2415
|
+
UploadManagerBase_settle(pact, 1, result);
|
|
2163
2416
|
}
|
|
2164
2417
|
}
|
|
2165
2418
|
}
|
|
@@ -2199,40 +2452,41 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2199
2452
|
try {
|
|
2200
2453
|
var _this = this;
|
|
2201
2454
|
_this.assertNotCancelled(request);
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2455
|
+
return UploadManagerBase_await(BytescaleApiClientConfigUtils.getAccountIdAsync(_this.config), function (accountId) {
|
|
2456
|
+
var source = _this.processUploadSource(request.data);
|
|
2457
|
+
var preUploadInfo = _this.getPreUploadInfo(request, source);
|
|
2458
|
+
var bytesTotal = preUploadInfo.size;
|
|
2459
|
+
var makeOnProgressForPart = _this.makeOnProgressForPartFactory(request, bytesTotal);
|
|
2460
|
+
var init = _this.preUpload(source);
|
|
2461
|
+
// Raise initial progress event SYNCHRONOUSLY.
|
|
2462
|
+
if (request.onProgress !== undefined) {
|
|
2463
|
+
request.onProgress(_this.makeProgressEvent(0, bytesTotal));
|
|
2464
|
+
}
|
|
2465
|
+
return UploadManagerBase_await(_this.beginUpload(request, preUploadInfo, accountId), function (uploadInfo) {
|
|
2466
|
+
var partCount = uploadInfo.uploadParts.count;
|
|
2467
|
+
var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
|
|
2468
|
+
var _this$makeCancellatio = _this.makeCancellationMethods(),
|
|
2469
|
+
cancel = _this$makeCancellatio.cancel,
|
|
2470
|
+
addCancellationHandler = _this$makeCancellatio.addCancellationHandler;
|
|
2471
|
+
var intervalHandle = setInterval(_this.onIntervalTick(request, cancel), _this.intervalMs);
|
|
2472
|
+
var uploadedParts;
|
|
2473
|
+
return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
|
|
2474
|
+
return UploadManagerBase_await(_this.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
|
|
2475
|
+
return _this.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler, accountId);
|
|
2476
|
+
})), function (_this$mapAsync) {
|
|
2477
|
+
uploadedParts = _this$mapAsync;
|
|
2478
|
+
return UploadManagerBase_awaitIgnored(_this.postUpload(init));
|
|
2479
|
+
});
|
|
2480
|
+
}, function (_wasThrown, _result) {
|
|
2481
|
+
clearInterval(intervalHandle);
|
|
2482
|
+
return UploadManagerBase_rethrow(_wasThrown, _result);
|
|
2483
|
+
}), function () {
|
|
2484
|
+
var etag = uploadedParts.flatMap(function (x) {
|
|
2485
|
+
return x.status === "Completed" ? [x.etag] : [];
|
|
2486
|
+
})[0];
|
|
2487
|
+
return Object.assign(Object.assign({}, uploadInfo.file), {
|
|
2488
|
+
etag: etag // The 'etag' in the original 'uploadInfo.file' will be null, so we set it to the final etag value here.
|
|
2489
|
+
});
|
|
2236
2490
|
});
|
|
2237
2491
|
});
|
|
2238
2492
|
});
|
|
@@ -2439,7 +2693,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
|
|
|
2439
2693
|
var result = [];
|
|
2440
2694
|
var workQueue = UploadManagerBase_toConsumableArray(items);
|
|
2441
2695
|
return UploadManagerBase_await(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
|
|
2442
|
-
return _continueIgnored(
|
|
2696
|
+
return _continueIgnored(UploadManagerBase_for(function () {
|
|
2443
2697
|
return workQueue.length > 0;
|
|
2444
2698
|
}, void 0, function () {
|
|
2445
2699
|
var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
|
|
@@ -3177,15 +3431,27 @@ function Scheduler_toPrimitive(t, r) { if ("object" != Scheduler_typeof(t) || !t
|
|
|
3177
3431
|
* Q: Why not use 'setTimeout'?
|
|
3178
3432
|
* -------------------------
|
|
3179
3433
|
* A: setTimeout can be paused (e.g., during hibernation), risking JWT expiration before it triggers.
|
|
3180
|
-
* We therefore
|
|
3434
|
+
* We therefore check wall-clock time every second and on browser resume events. A backwards clock adjustment runs
|
|
3435
|
+
* scheduled callbacks immediately so authentication can be safely re-established against the server-provided TTL.
|
|
3181
3436
|
* -------------------------
|
|
3182
3437
|
*/
|
|
3183
3438
|
var Scheduler = /*#__PURE__*/function () {
|
|
3184
3439
|
function Scheduler() {
|
|
3440
|
+
var _this = this;
|
|
3185
3441
|
Scheduler_classCallCheck(this, Scheduler);
|
|
3442
|
+
this.clockRollbackToleranceMilliseconds = 1000;
|
|
3186
3443
|
this.callbacks = {};
|
|
3187
3444
|
this.nextId = 0;
|
|
3188
3445
|
this.intervalId = undefined;
|
|
3446
|
+
this.checkAfterResume = function () {
|
|
3447
|
+
return _this.checkCallbacks();
|
|
3448
|
+
};
|
|
3449
|
+
this.checkAfterVisibilityChange = function () {
|
|
3450
|
+
var _a;
|
|
3451
|
+
if (((_a = _this.documentEventTarget) === null || _a === void 0 ? void 0 : _a.visibilityState) === "visible") {
|
|
3452
|
+
_this.checkCallbacks();
|
|
3453
|
+
}
|
|
3454
|
+
};
|
|
3189
3455
|
}
|
|
3190
3456
|
return Scheduler_createClass(Scheduler, [{
|
|
3191
3457
|
key: "schedule",
|
|
@@ -3195,7 +3461,7 @@ var Scheduler = /*#__PURE__*/function () {
|
|
|
3195
3461
|
epoch: epoch,
|
|
3196
3462
|
callback: callback
|
|
3197
3463
|
};
|
|
3198
|
-
this.
|
|
3464
|
+
this.startMonitoring();
|
|
3199
3465
|
return handle;
|
|
3200
3466
|
}
|
|
3201
3467
|
}, {
|
|
@@ -3204,34 +3470,40 @@ var Scheduler = /*#__PURE__*/function () {
|
|
|
3204
3470
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
3205
3471
|
delete this.callbacks[handle];
|
|
3206
3472
|
if (Object.keys(this.callbacks).length === 0) {
|
|
3207
|
-
this.
|
|
3473
|
+
this.stopMonitoring();
|
|
3208
3474
|
}
|
|
3209
3475
|
}
|
|
3210
3476
|
}, {
|
|
3211
|
-
key: "
|
|
3212
|
-
value: function
|
|
3213
|
-
var
|
|
3477
|
+
key: "startMonitoring",
|
|
3478
|
+
value: function startMonitoring() {
|
|
3479
|
+
var _this2 = this;
|
|
3214
3480
|
if (this.intervalId === undefined) {
|
|
3481
|
+
this.lastObservedEpoch = Date.now();
|
|
3215
3482
|
this.intervalId = setInterval(function () {
|
|
3216
|
-
return
|
|
3483
|
+
return _this2.checkCallbacks();
|
|
3217
3484
|
}, 1000);
|
|
3485
|
+
this.startListeningForResume();
|
|
3218
3486
|
}
|
|
3219
3487
|
}
|
|
3220
3488
|
}, {
|
|
3221
|
-
key: "
|
|
3222
|
-
value: function
|
|
3489
|
+
key: "stopMonitoring",
|
|
3490
|
+
value: function stopMonitoring() {
|
|
3223
3491
|
if (this.intervalId !== undefined) {
|
|
3224
3492
|
clearInterval(this.intervalId);
|
|
3225
3493
|
this.intervalId = undefined;
|
|
3494
|
+
this.lastObservedEpoch = undefined;
|
|
3495
|
+
this.stopListeningForResume();
|
|
3226
3496
|
}
|
|
3227
3497
|
}
|
|
3228
3498
|
}, {
|
|
3229
3499
|
key: "checkCallbacks",
|
|
3230
3500
|
value: function checkCallbacks() {
|
|
3231
3501
|
var now = Date.now();
|
|
3502
|
+
var clockMovedBackwards = this.lastObservedEpoch !== undefined && now < this.lastObservedEpoch - this.clockRollbackToleranceMilliseconds;
|
|
3503
|
+
this.lastObservedEpoch = now;
|
|
3232
3504
|
for (var handleStr in this.callbacks) {
|
|
3233
3505
|
var handle = parseInt(handleStr);
|
|
3234
|
-
if (this.callbacks[handle].epoch <= now) {
|
|
3506
|
+
if (clockMovedBackwards || this.callbacks[handle].epoch <= now) {
|
|
3235
3507
|
try {
|
|
3236
3508
|
this.callbacks[handle].callback();
|
|
3237
3509
|
} catch (e) {
|
|
@@ -3241,6 +3513,38 @@ var Scheduler = /*#__PURE__*/function () {
|
|
|
3241
3513
|
}
|
|
3242
3514
|
}
|
|
3243
3515
|
}
|
|
3516
|
+
}, {
|
|
3517
|
+
key: "startListeningForResume",
|
|
3518
|
+
value: function startListeningForResume() {
|
|
3519
|
+
if (typeof window !== "undefined" && typeof window.addEventListener === "function") {
|
|
3520
|
+
this.windowEventTarget = window;
|
|
3521
|
+
for (var _i = 0, _arr = ["focus", "online", "pageshow"]; _i < _arr.length; _i++) {
|
|
3522
|
+
var eventName = _arr[_i];
|
|
3523
|
+
this.windowEventTarget.addEventListener(eventName, this.checkAfterResume);
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3526
|
+
if (typeof document !== "undefined" && typeof document.addEventListener === "function") {
|
|
3527
|
+
this.documentEventTarget = document;
|
|
3528
|
+
this.documentEventTarget.addEventListener("resume", this.checkAfterResume);
|
|
3529
|
+
this.documentEventTarget.addEventListener("visibilitychange", this.checkAfterVisibilityChange);
|
|
3530
|
+
}
|
|
3531
|
+
}
|
|
3532
|
+
}, {
|
|
3533
|
+
key: "stopListeningForResume",
|
|
3534
|
+
value: function stopListeningForResume() {
|
|
3535
|
+
if (this.windowEventTarget !== undefined) {
|
|
3536
|
+
for (var _i2 = 0, _arr2 = ["focus", "online", "pageshow"]; _i2 < _arr2.length; _i2++) {
|
|
3537
|
+
var eventName = _arr2[_i2];
|
|
3538
|
+
this.windowEventTarget.removeEventListener(eventName, this.checkAfterResume);
|
|
3539
|
+
}
|
|
3540
|
+
this.windowEventTarget = undefined;
|
|
3541
|
+
}
|
|
3542
|
+
if (this.documentEventTarget !== undefined) {
|
|
3543
|
+
this.documentEventTarget.removeEventListener("resume", this.checkAfterResume);
|
|
3544
|
+
this.documentEventTarget.removeEventListener("visibilitychange", this.checkAfterVisibilityChange);
|
|
3545
|
+
this.documentEventTarget = undefined;
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3244
3548
|
}]);
|
|
3245
3549
|
}();
|
|
3246
3550
|
;// ./src/public/browser/AuthManagerBrowser.ts
|
|
@@ -3516,6 +3820,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3516
3820
|
this.refreshBeforeExpirySeconds = 20;
|
|
3517
3821
|
this.scheduler = new Scheduler();
|
|
3518
3822
|
this.sourceScopedUrlPrefixMarker = "!bytescale-source-scoped!";
|
|
3823
|
+
this.requestScopedUrlPrefixMarker = "!bytescale-request-scoped!";
|
|
3519
3824
|
this.authSessionMutex = AuthSessionState.getMutex();
|
|
3520
3825
|
}
|
|
3521
3826
|
return AuthManagerBrowser_createClass(AuthManagerImpl, [{
|
|
@@ -3562,10 +3867,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3562
3867
|
authConfigs: configs.map(function (config) {
|
|
3563
3868
|
return {
|
|
3564
3869
|
accessToken: undefined,
|
|
3870
|
+
authenticationPromise: Promise.resolve(),
|
|
3565
3871
|
config: config,
|
|
3566
3872
|
expiresAt: undefined,
|
|
3567
3873
|
jwt: undefined,
|
|
3568
|
-
refreshHandle: undefined
|
|
3874
|
+
refreshHandle: undefined,
|
|
3875
|
+
refreshPromise: undefined
|
|
3569
3876
|
};
|
|
3570
3877
|
}),
|
|
3571
3878
|
authServiceWorker: requiresServiceWorker && params.serviceWorkerScript !== undefined && canUseServiceWorkers ? {
|
|
@@ -3583,7 +3890,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3583
3890
|
})), function (session) {
|
|
3584
3891
|
return AuthManagerBrowser_catch(function () {
|
|
3585
3892
|
return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_forOf((_a = session.authConfigs) !== null && _a !== void 0 ? _a : [], function (config) {
|
|
3586
|
-
return AuthManagerBrowser_awaitIgnored(_this2.refreshAuthConfig(session, config
|
|
3893
|
+
return AuthManagerBrowser_awaitIgnored(_this2.refreshAuthConfig(session, config));
|
|
3587
3894
|
}));
|
|
3588
3895
|
}, function (e) {
|
|
3589
3896
|
return AuthManagerBrowser_continue(AuthManagerBrowser_catch(function () {
|
|
@@ -3674,16 +3981,48 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3674
3981
|
}, {
|
|
3675
3982
|
key: "refreshAuthConfig",
|
|
3676
3983
|
value: function refreshAuthConfig(session, state) {
|
|
3677
|
-
var rejectInvalidInitialToken = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
3678
3984
|
try {
|
|
3985
|
+
var _exit = false;
|
|
3679
3986
|
var _this4 = this;
|
|
3680
|
-
return AuthManagerBrowser_await(
|
|
3987
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_invoke(function () {
|
|
3988
|
+
if (state.refreshPromise !== undefined) {
|
|
3989
|
+
return AuthManagerBrowser_await(state.refreshPromise, function () {
|
|
3990
|
+
_exit = true;
|
|
3991
|
+
});
|
|
3992
|
+
}
|
|
3993
|
+
}, function (_result2) {
|
|
3994
|
+
if (_exit) return _result2;
|
|
3995
|
+
// Publish the pending operation before provider code can run, including provider code that calls back into the SDK.
|
|
3996
|
+
var refreshPromise = Promise.resolve().then(AuthManagerBrowser_async(function () {
|
|
3997
|
+
return _this4.performRefreshAuthConfig(session, state);
|
|
3998
|
+
}));
|
|
3999
|
+
state.authenticationPromise = refreshPromise;
|
|
4000
|
+
state.refreshPromise = refreshPromise;
|
|
4001
|
+
var clearRefreshPromise = function clearRefreshPromise() {
|
|
4002
|
+
if (state.refreshPromise === refreshPromise) {
|
|
4003
|
+
state.refreshPromise = undefined;
|
|
4004
|
+
}
|
|
4005
|
+
};
|
|
4006
|
+
refreshPromise.then(clearRefreshPromise, clearRefreshPromise);
|
|
4007
|
+
return AuthManagerBrowser_awaitIgnored(refreshPromise);
|
|
4008
|
+
}));
|
|
4009
|
+
} catch (e) {
|
|
4010
|
+
return Promise.reject(e);
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
}, {
|
|
4014
|
+
key: "performRefreshAuthConfig",
|
|
4015
|
+
value: function performRefreshAuthConfig(session, state) {
|
|
4016
|
+
try {
|
|
4017
|
+
var _this5 = this;
|
|
4018
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
|
|
3681
4019
|
var _a;
|
|
3682
4020
|
if (!session.isActive) {
|
|
3683
4021
|
return;
|
|
3684
4022
|
}
|
|
3685
4023
|
if (state.refreshHandle !== undefined) {
|
|
3686
|
-
|
|
4024
|
+
_this5.scheduler.unschedule(state.refreshHandle);
|
|
4025
|
+
state.refreshHandle = undefined;
|
|
3687
4026
|
}
|
|
3688
4027
|
var previous = {
|
|
3689
4028
|
accessToken: state.accessToken,
|
|
@@ -3691,27 +4030,27 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3691
4030
|
jwt: state.jwt,
|
|
3692
4031
|
serviceWorkerConfigured: session.serviceWorkerConfigured
|
|
3693
4032
|
};
|
|
3694
|
-
var refreshAt = Date.now() +
|
|
4033
|
+
var refreshAt = Date.now() + _this5.retryAuthAfterErrorSeconds * 1000;
|
|
3695
4034
|
return AuthManagerBrowser_finallyRethrows(function () {
|
|
3696
4035
|
return AuthManagerBrowser_catch(function () {
|
|
3697
|
-
return AuthManagerBrowser_await(
|
|
3698
|
-
var setCookie =
|
|
3699
|
-
return AuthManagerBrowser_await(
|
|
4036
|
+
return AuthManagerBrowser_await(_this5.getAuthorizationToken(session.params, state.config), function (jwt) {
|
|
4037
|
+
var setCookie = _this5.shouldSetCookie(session, state.config);
|
|
4038
|
+
return AuthManagerBrowser_await(_this5.setAccessToken(session.params.options, _this5.getConfigCdnUrl(session.params, state.config), state.config.accountId, jwt, setCookie), function (token) {
|
|
3700
4039
|
var expiresAt = Date.now() + token.ttlSeconds * 1000;
|
|
3701
4040
|
state.accessToken = token.accessToken;
|
|
3702
4041
|
state.expiresAt = expiresAt;
|
|
3703
4042
|
state.jwt = jwt;
|
|
3704
4043
|
return AuthManagerBrowser_invoke(function () {
|
|
3705
|
-
if (session.authServiceWorker !== undefined && (
|
|
3706
|
-
return AuthManagerBrowser_await(
|
|
3707
|
-
return AuthManagerBrowser_await(
|
|
4044
|
+
if (session.authServiceWorker !== undefined && (_this5.isServiceWorkerEnabled(state.config) || session.serviceWorkerConfigured !== true)) {
|
|
4045
|
+
return AuthManagerBrowser_await(_this5.sendCurrentServiceWorkerConfig(session), function () {
|
|
4046
|
+
return AuthManagerBrowser_await(_this5.waitForServiceWorker(), function () {
|
|
3708
4047
|
session.serviceWorkerConfigured = true;
|
|
3709
4048
|
});
|
|
3710
4049
|
});
|
|
3711
4050
|
}
|
|
3712
4051
|
}, function () {
|
|
3713
|
-
var desiredTtl = token.ttlSeconds -
|
|
3714
|
-
var actualTtl = Math.max(desiredTtl,
|
|
4052
|
+
var desiredTtl = token.ttlSeconds - _this5.refreshBeforeExpirySeconds;
|
|
4053
|
+
var actualTtl = Math.max(desiredTtl, _this5.minJwtTtlSeconds);
|
|
3715
4054
|
if (desiredTtl !== actualTtl) {
|
|
3716
4055
|
ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(actualTtl, " seconds before refreshing."));
|
|
3717
4056
|
}
|
|
@@ -3725,18 +4064,18 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3725
4064
|
state.jwt = previous.jwt;
|
|
3726
4065
|
session.serviceWorkerConfigured = previous.serviceWorkerConfigured;
|
|
3727
4066
|
ConsoleUtils.warn("Unable to refresh JWT access token for auth config '".concat((_a = state.config.authConfigId) !== null && _a !== void 0 ? _a : "default", "': ").concat(e));
|
|
3728
|
-
if (
|
|
4067
|
+
if (_this5.isV2Params(session.params) && previous.accessToken === undefined && e instanceof InvalidAuthTokenError) {
|
|
3729
4068
|
throw e;
|
|
3730
4069
|
}
|
|
3731
4070
|
});
|
|
3732
|
-
}, function (_wasThrown,
|
|
3733
|
-
state.refreshHandle =
|
|
3734
|
-
|
|
4071
|
+
}, function (_wasThrown, _result3) {
|
|
4072
|
+
state.refreshHandle = _this5.scheduler.schedule(refreshAt, function () {
|
|
4073
|
+
_this5.refreshAuthConfig(session, state).then(function () {}, function (e) {
|
|
3735
4074
|
return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
|
|
3736
4075
|
});
|
|
3737
4076
|
});
|
|
3738
|
-
|
|
3739
|
-
return AuthManagerBrowser_rethrow(_wasThrown,
|
|
4077
|
+
_this5.updateSessionState(session);
|
|
4078
|
+
return AuthManagerBrowser_rethrow(_wasThrown, _result3);
|
|
3740
4079
|
});
|
|
3741
4080
|
}))));
|
|
3742
4081
|
} catch (e) {
|
|
@@ -3747,11 +4086,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3747
4086
|
key: "sendCurrentServiceWorkerConfig",
|
|
3748
4087
|
value: function sendCurrentServiceWorkerConfig(session) {
|
|
3749
4088
|
try {
|
|
3750
|
-
var
|
|
4089
|
+
var _this6 = this;
|
|
3751
4090
|
var _a;
|
|
3752
4091
|
var now = Date.now();
|
|
3753
4092
|
var config = ((_a = session.authConfigs) !== null && _a !== void 0 ? _a : []).flatMap(function (state) {
|
|
3754
|
-
if (!
|
|
4093
|
+
if (!_this6.isServiceWorkerEnabled(state.config) || state.jwt === undefined || state.expiresAt === undefined || state.expiresAt <= now) {
|
|
3755
4094
|
return [];
|
|
3756
4095
|
}
|
|
3757
4096
|
return [{
|
|
@@ -3760,11 +4099,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3760
4099
|
key: "Authorization",
|
|
3761
4100
|
value: "Bearer ".concat(state.jwt)
|
|
3762
4101
|
}],
|
|
4102
|
+
requestUrlPrefixes: state.config.requestUrlPrefixes,
|
|
3763
4103
|
sourceUrlPrefixes: state.config.sourceUrlPrefixes,
|
|
3764
|
-
urlPrefix: "".concat(
|
|
4104
|
+
urlPrefix: "".concat(_this6.getConfigCdnUrl(session.params, state.config), "/").concat(state.config.accountId, "/")
|
|
3765
4105
|
}];
|
|
3766
4106
|
});
|
|
3767
|
-
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(
|
|
4107
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this6.sendServiceWorkerConfig(session, config, _this6.isV2Params(session.params) ? session.params.urlRewriteRules : undefined)));
|
|
3768
4108
|
} catch (e) {
|
|
3769
4109
|
return Promise.reject(e);
|
|
3770
4110
|
}
|
|
@@ -3773,21 +4113,21 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3773
4113
|
key: "sendServiceWorkerConfig",
|
|
3774
4114
|
value: function sendServiceWorkerConfig(session, config, urlRewriteRules) {
|
|
3775
4115
|
try {
|
|
3776
|
-
var
|
|
4116
|
+
var _this7 = this;
|
|
3777
4117
|
if (session.authServiceWorker === undefined) {
|
|
3778
4118
|
throw new Error("Service worker configuration cannot be applied because service workers are unavailable.");
|
|
3779
4119
|
}
|
|
3780
|
-
return AuthManagerBrowser_await(
|
|
4120
|
+
return AuthManagerBrowser_await(_this7.serviceWorkerUtils.sendMessage(Object.assign({
|
|
3781
4121
|
type: "SET_BYTESCALE_AUTH_CONFIG",
|
|
3782
4122
|
config: config.map(function (entry) {
|
|
3783
4123
|
return Object.assign(Object.assign({}, entry), {
|
|
3784
|
-
urlPrefix: "".concat(entry.sourceUrlPrefixes === undefined ? "" :
|
|
4124
|
+
urlPrefix: "".concat(entry.requestUrlPrefixes === undefined ? "" : _this7.requestScopedUrlPrefixMarker).concat(entry.sourceUrlPrefixes === undefined ? "" : _this7.sourceScopedUrlPrefixMarker).concat(entry.urlPrefix)
|
|
3785
4125
|
});
|
|
3786
4126
|
})
|
|
3787
4127
|
}, urlRewriteRules === undefined ? {} : {
|
|
3788
4128
|
urlRewriteRules: urlRewriteRules
|
|
3789
|
-
}), session.authServiceWorker,
|
|
3790
|
-
session.authServiceWorker =
|
|
4129
|
+
}), session.authServiceWorker, _this7.serviceWorkerScriptFieldName), function (_this7$serviceWorkerU) {
|
|
4130
|
+
session.authServiceWorker = _this7$serviceWorkerU;
|
|
3791
4131
|
});
|
|
3792
4132
|
} catch (e) {
|
|
3793
4133
|
return Promise.reject(e);
|
|
@@ -3803,6 +4143,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3803
4143
|
}
|
|
3804
4144
|
return configs.map(function (config) {
|
|
3805
4145
|
return config === null || AuthManagerBrowser_typeof(config) !== "object" ? config : Object.assign(Object.assign({}, config), {
|
|
4146
|
+
requestUrlPrefixes: Array.isArray(config.requestUrlPrefixes) ? AuthManagerBrowser_toConsumableArray(config.requestUrlPrefixes) : config.requestUrlPrefixes,
|
|
3806
4147
|
sourceUrlPrefixes: Array.isArray(config.sourceUrlPrefixes) ? AuthManagerBrowser_toConsumableArray(config.sourceUrlPrefixes) : config.sourceUrlPrefixes
|
|
3807
4148
|
});
|
|
3808
4149
|
});
|
|
@@ -3860,11 +4201,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3860
4201
|
if (config.enableCookieAuth !== undefined && typeof config.enableCookieAuth !== "boolean" || config.enableServiceWorkerAuth !== undefined && typeof config.enableServiceWorkerAuth !== "boolean") {
|
|
3861
4202
|
throw new Error("Authentication enablement flags must be booleans when provided.");
|
|
3862
4203
|
}
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
}))) {
|
|
3866
|
-
throw new Error("The 'sourceUrlPrefixes' field must be an array of strings.");
|
|
3867
|
-
}
|
|
4204
|
+
this.validateUrlPrefixes(config.sourceUrlPrefixes, "sourceUrlPrefixes");
|
|
4205
|
+
this.validateUrlPrefixes(config.requestUrlPrefixes, "requestUrlPrefixes");
|
|
3868
4206
|
var isManual = typeof config.getAuthorizationToken === "function";
|
|
3869
4207
|
var isAutomatic = typeof config.authUrl === "string" && typeof config.authHeaders === "function";
|
|
3870
4208
|
if (isManual === isAutomatic || isManual && (config.authUrl !== undefined || config.authHeaders !== undefined)) {
|
|
@@ -3906,6 +4244,15 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3906
4244
|
}
|
|
3907
4245
|
}
|
|
3908
4246
|
}
|
|
4247
|
+
}, {
|
|
4248
|
+
key: "validateUrlPrefixes",
|
|
4249
|
+
value: function validateUrlPrefixes(prefixes, fieldName) {
|
|
4250
|
+
if (prefixes !== undefined && (!Array.isArray(prefixes) || !prefixes.every(function (prefix) {
|
|
4251
|
+
return typeof prefix === "string";
|
|
4252
|
+
}))) {
|
|
4253
|
+
throw new Error("The '".concat(fieldName, "' field must be an array of strings."));
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
3909
4256
|
}, {
|
|
3910
4257
|
key: "validateUrlRewriteRules",
|
|
3911
4258
|
value: function validateUrlRewriteRules(rules) {
|
|
@@ -3918,7 +4265,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3918
4265
|
}, {
|
|
3919
4266
|
key: "updateSessionState",
|
|
3920
4267
|
value: function updateSessionState(session) {
|
|
3921
|
-
var
|
|
4268
|
+
var _this8 = this;
|
|
3922
4269
|
var _a;
|
|
3923
4270
|
var configs = (_a = session.authConfigs) !== null && _a !== void 0 ? _a : [];
|
|
3924
4271
|
var defaultConfig = configs.find(function (state) {
|
|
@@ -3928,7 +4275,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3928
4275
|
session.accessToken = exposeLegacyDefault && defaultConfig !== undefined && this.isConfigUsable(defaultConfig) ? defaultConfig.accessToken : undefined;
|
|
3929
4276
|
session.accessTokenRefreshHandle = exposeLegacyDefault ? defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.refreshHandle : undefined;
|
|
3930
4277
|
session.isReady = configs.length > 0 && configs.every(function (state) {
|
|
3931
|
-
return
|
|
4278
|
+
return _this8.isConfigUsable(state);
|
|
3932
4279
|
}) && (session.authServiceWorker === undefined || session.serviceWorkerConfigured === true);
|
|
3933
4280
|
}
|
|
3934
4281
|
}, {
|
|
@@ -3990,8 +4337,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
3990
4337
|
key: "deleteAccessToken",
|
|
3991
4338
|
value: function deleteAccessToken(options, cdnUrl, accountId) {
|
|
3992
4339
|
try {
|
|
3993
|
-
var
|
|
3994
|
-
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(
|
|
4340
|
+
var _this9 = this;
|
|
4341
|
+
return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this9.getAccessTokenUrl(cdnUrl, accountId, true), {
|
|
3995
4342
|
method: "DELETE",
|
|
3996
4343
|
credentials: "include",
|
|
3997
4344
|
headers: {}
|
|
@@ -4007,14 +4354,14 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4007
4354
|
key: "setAccessToken",
|
|
4008
4355
|
value: function setAccessToken(options, cdnUrl, accountId, jwt, setCookie) {
|
|
4009
4356
|
try {
|
|
4010
|
-
var
|
|
4357
|
+
var _this0 = this;
|
|
4011
4358
|
var request = {
|
|
4012
4359
|
accessToken: jwt
|
|
4013
4360
|
};
|
|
4014
|
-
return AuthManagerBrowser_await(BaseAPI.fetch(
|
|
4361
|
+
return AuthManagerBrowser_await(BaseAPI.fetch(_this0.getAccessTokenUrl(cdnUrl, accountId, setCookie), {
|
|
4015
4362
|
method: "PUT",
|
|
4016
4363
|
credentials: "include",
|
|
4017
|
-
headers: AuthManagerBrowser_defineProperty({},
|
|
4364
|
+
headers: AuthManagerBrowser_defineProperty({}, _this0.contentType, _this0.contentTypeJson),
|
|
4018
4365
|
body: JSON.stringify(request)
|
|
4019
4366
|
}, {
|
|
4020
4367
|
isBytescaleApi: true,
|
|
@@ -4035,20 +4382,20 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4035
4382
|
key: "getAuthorizationToken",
|
|
4036
4383
|
value: function getAuthorizationToken(params, config) {
|
|
4037
4384
|
try {
|
|
4038
|
-
var
|
|
4039
|
-
var
|
|
4385
|
+
var _exit2 = false;
|
|
4386
|
+
var _this1 = this;
|
|
4040
4387
|
var _a, _b;
|
|
4041
4388
|
return AuthManagerBrowser_await(AuthManagerBrowser_invoke(function () {
|
|
4042
4389
|
if (typeof config.getAuthorizationToken === "function") {
|
|
4043
|
-
var _validateJwt =
|
|
4390
|
+
var _validateJwt = _this1.validateJwt;
|
|
4044
4391
|
return AuthManagerBrowser_await(config.getAuthorizationToken(), function (_config$getAuthorizat) {
|
|
4045
|
-
var
|
|
4046
|
-
|
|
4047
|
-
return
|
|
4392
|
+
var _this1$validateJwt = _validateJwt.call(_this1, _config$getAuthorizat, "The 'getAuthorizationToken' callback");
|
|
4393
|
+
_exit2 = true;
|
|
4394
|
+
return _this1$validateJwt;
|
|
4048
4395
|
});
|
|
4049
4396
|
}
|
|
4050
|
-
}, function (
|
|
4051
|
-
if (
|
|
4397
|
+
}, function (_result4) {
|
|
4398
|
+
if (_exit2) return _result4;
|
|
4052
4399
|
var endpointName = "Your auth API endpoint";
|
|
4053
4400
|
var _fetch = BaseAPI.fetch,
|
|
4054
4401
|
_config$authUrl = config.authUrl;
|
|
@@ -4060,13 +4407,13 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
4060
4407
|
isBytescaleApi: false,
|
|
4061
4408
|
fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
|
|
4062
4409
|
}), function (result) {
|
|
4063
|
-
var actualContentType = (_b = result.headers.get(
|
|
4064
|
-
if (actualContentType.split(";")[0] !==
|
|
4065
|
-
throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(
|
|
4410
|
+
var actualContentType = (_b = result.headers.get(_this1.contentType)) !== null && _b !== void 0 ? _b : "";
|
|
4411
|
+
if (actualContentType.split(";")[0] !== _this1.contentTypeText) {
|
|
4412
|
+
throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this1.contentType, " response header, but the Bytescale SDK requires \"").concat(_this1.contentTypeText, "\"."));
|
|
4066
4413
|
}
|
|
4067
|
-
var _validateJwt2 =
|
|
4414
|
+
var _validateJwt2 = _this1.validateJwt;
|
|
4068
4415
|
return AuthManagerBrowser_await(result.text(), function (_result$text) {
|
|
4069
|
-
return _validateJwt2.call(
|
|
4416
|
+
return _validateJwt2.call(_this1, _result$text, endpointName);
|
|
4070
4417
|
});
|
|
4071
4418
|
});
|
|
4072
4419
|
});
|