@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.
@@ -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, _b;
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
- for (var _i = 0, _Object$keys = Object.keys(resolvedConfigHeaders); _i < _Object$keys.length; _i++) {
581
- var key = _Object$keys[_i];
582
- if (key.toLowerCase() === "authorization" || key.toLowerCase() === "authorization-token") {
583
- for (var _i2 = 0, _Object$keys2 = Object.keys(context.headers); _i2 < _Object$keys2.length; _i2++) {
584
- var generatedKey = _Object$keys2[_i2];
585
- if (generatedKey.toLowerCase() === key.toLowerCase()) {
586
- // Custom auth headers have documented precedence; remove the generated spelling to make that deterministic.
587
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
588
- delete context.headers[generatedKey];
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
- var headers = Object.assign(Object.assign({}, context.headers), resolvedConfigHeaders);
594
- Object.keys(headers).forEach(function (key) {
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
- return {
615
- url: url,
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 (_BytescaleApiClientCo) {
646
- response = _BytescaleApiClientCo;
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 _settle(pact, state, value) {
2310
+ function UploadManagerBase_settle(pact, state, value) {
2058
2311
  if (!pact.s) {
2059
- if (value instanceof _Pact) {
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 = _settle.bind(null, pact, state);
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(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
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 _Pact = /*#__PURE__*/function () {
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
- _settle(result, 1, callback(this.v));
2344
+ UploadManagerBase_settle(result, 1, callback(this.v));
2092
2345
  } catch (e) {
2093
- _settle(result, 2, e);
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
- _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
2357
+ UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
2105
2358
  } else if (onRejected) {
2106
- _settle(result, 1, onRejected(value));
2359
+ UploadManagerBase_settle(result, 1, onRejected(value));
2107
2360
  } else {
2108
- _settle(result, 2, value);
2361
+ UploadManagerBase_settle(result, 2, value);
2109
2362
  }
2110
2363
  } catch (e) {
2111
- _settle(result, 2, e);
2364
+ UploadManagerBase_settle(result, 2, e);
2112
2365
  }
2113
2366
  };
2114
2367
  return result;
2115
2368
  };
2116
2369
  return _Pact;
2117
2370
  }();
2118
- function _isSettledPact(thenable) {
2119
- return thenable instanceof _Pact && thenable.s & 1;
2371
+ function UploadManagerBase_isSettledPact(thenable) {
2372
+ return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
2120
2373
  }
2121
- function _for(test, update, body) {
2374
+ function UploadManagerBase_for(test, update, body) {
2122
2375
  var stage;
2123
2376
  for (;;) {
2124
2377
  var shouldContinue = test();
2125
- if (_isSettledPact(shouldContinue)) {
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 (_isSettledPact(result)) {
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 && !_isSettledPact(updateValue)) {
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 _Pact();
2153
- var reject = _settle.bind(null, pact, 2);
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 && !_isSettledPact(updateValue)) {
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 || _isSettledPact(shouldContinue) && !shouldContinue.v) {
2168
- _settle(pact, 1, result);
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 (_isSettledPact(result)) {
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
- _settle(pact, 1, result);
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
- _settle(pact, 1, result);
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
- var accountId = BytescaleApiClientConfigUtils.getAccountId(_this.config);
2243
- var source = _this.processUploadSource(request.data);
2244
- var preUploadInfo = _this.getPreUploadInfo(request, source);
2245
- var bytesTotal = preUploadInfo.size;
2246
- var makeOnProgressForPart = _this.makeOnProgressForPartFactory(request, bytesTotal);
2247
- var init = _this.preUpload(source);
2248
- // Raise initial progress event SYNCHRONOUSLY.
2249
- if (request.onProgress !== undefined) {
2250
- request.onProgress(_this.makeProgressEvent(0, bytesTotal));
2251
- }
2252
- return UploadManagerBase_await(_this.beginUpload(request, preUploadInfo, accountId), function (uploadInfo) {
2253
- var partCount = uploadInfo.uploadParts.count;
2254
- var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
2255
- var _this$makeCancellatio = _this.makeCancellationMethods(),
2256
- cancel = _this$makeCancellatio.cancel,
2257
- addCancellationHandler = _this$makeCancellatio.addCancellationHandler;
2258
- var intervalHandle = setInterval(_this.onIntervalTick(request, cancel), _this.intervalMs);
2259
- var uploadedParts;
2260
- return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
2261
- return UploadManagerBase_await(_this.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
2262
- return _this.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler, accountId);
2263
- })), function (_this$mapAsync) {
2264
- uploadedParts = _this$mapAsync;
2265
- return UploadManagerBase_awaitIgnored(_this.postUpload(init));
2266
- });
2267
- }, function (_wasThrown, _result) {
2268
- clearInterval(intervalHandle);
2269
- return UploadManagerBase_rethrow(_wasThrown, _result);
2270
- }), function () {
2271
- var etag = uploadedParts.flatMap(function (x) {
2272
- return x.status === "Completed" ? [x.etag] : [];
2273
- })[0];
2274
- return Object.assign(Object.assign({}, uploadInfo.file), {
2275
- etag: etag // The 'etag' in the original 'uploadInfo.file' will be null, so we set it to the final etag value here.
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(_for(function () {
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 use a scheduler to check wall-clock time every second and execute the callback at the scheduled time.
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.startInterval();
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.stopInterval();
3513
+ this.stopMonitoring();
3248
3514
  }
3249
3515
  }
3250
3516
  }, {
3251
- key: "startInterval",
3252
- value: function startInterval() {
3253
- var _this = this;
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 _this.checkCallbacks();
3523
+ return _this2.checkCallbacks();
3257
3524
  }, 1000);
3525
+ this.startListeningForResume();
3258
3526
  }
3259
3527
  }
3260
3528
  }, {
3261
- key: "stopInterval",
3262
- value: function stopInterval() {
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
@@ -3556,6 +3860,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3556
3860
  this.refreshBeforeExpirySeconds = 20;
3557
3861
  this.scheduler = new Scheduler();
3558
3862
  this.sourceScopedUrlPrefixMarker = "!bytescale-source-scoped!";
3863
+ this.requestScopedUrlPrefixMarker = "!bytescale-request-scoped!";
3559
3864
  this.authSessionMutex = AuthSessionState.getMutex();
3560
3865
  }
3561
3866
  return AuthManagerBrowser_createClass(AuthManagerImpl, [{
@@ -3602,10 +3907,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3602
3907
  authConfigs: configs.map(function (config) {
3603
3908
  return {
3604
3909
  accessToken: undefined,
3910
+ authenticationPromise: Promise.resolve(),
3605
3911
  config: config,
3606
3912
  expiresAt: undefined,
3607
3913
  jwt: undefined,
3608
- refreshHandle: undefined
3914
+ refreshHandle: undefined,
3915
+ refreshPromise: undefined
3609
3916
  };
3610
3917
  }),
3611
3918
  authServiceWorker: requiresServiceWorker && params.serviceWorkerScript !== undefined && canUseServiceWorkers ? {
@@ -3623,7 +3930,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3623
3930
  })), function (session) {
3624
3931
  return AuthManagerBrowser_catch(function () {
3625
3932
  return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_forOf((_a = session.authConfigs) !== null && _a !== void 0 ? _a : [], function (config) {
3626
- return AuthManagerBrowser_awaitIgnored(_this2.refreshAuthConfig(session, config, _this2.isV2Params(session.params)));
3933
+ return AuthManagerBrowser_awaitIgnored(_this2.refreshAuthConfig(session, config));
3627
3934
  }));
3628
3935
  }, function (e) {
3629
3936
  return AuthManagerBrowser_continue(AuthManagerBrowser_catch(function () {
@@ -3714,16 +4021,48 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3714
4021
  }, {
3715
4022
  key: "refreshAuthConfig",
3716
4023
  value: function refreshAuthConfig(session, state) {
3717
- var rejectInvalidInitialToken = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
3718
4024
  try {
4025
+ var _exit = false;
3719
4026
  var _this4 = this;
3720
- return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this4.authSessionMutex.safe(AuthManagerBrowser_async(function () {
4027
+ return AuthManagerBrowser_await(AuthManagerBrowser_invoke(function () {
4028
+ if (state.refreshPromise !== undefined) {
4029
+ return AuthManagerBrowser_await(state.refreshPromise, function () {
4030
+ _exit = true;
4031
+ });
4032
+ }
4033
+ }, function (_result2) {
4034
+ if (_exit) return _result2;
4035
+ // Publish the pending operation before provider code can run, including provider code that calls back into the SDK.
4036
+ var refreshPromise = Promise.resolve().then(AuthManagerBrowser_async(function () {
4037
+ return _this4.performRefreshAuthConfig(session, state);
4038
+ }));
4039
+ state.authenticationPromise = refreshPromise;
4040
+ state.refreshPromise = refreshPromise;
4041
+ var clearRefreshPromise = function clearRefreshPromise() {
4042
+ if (state.refreshPromise === refreshPromise) {
4043
+ state.refreshPromise = undefined;
4044
+ }
4045
+ };
4046
+ refreshPromise.then(clearRefreshPromise, clearRefreshPromise);
4047
+ return AuthManagerBrowser_awaitIgnored(refreshPromise);
4048
+ }));
4049
+ } catch (e) {
4050
+ return Promise.reject(e);
4051
+ }
4052
+ }
4053
+ }, {
4054
+ key: "performRefreshAuthConfig",
4055
+ value: function performRefreshAuthConfig(session, state) {
4056
+ try {
4057
+ var _this5 = this;
4058
+ return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
3721
4059
  var _a;
3722
4060
  if (!session.isActive) {
3723
4061
  return;
3724
4062
  }
3725
4063
  if (state.refreshHandle !== undefined) {
3726
- _this4.scheduler.unschedule(state.refreshHandle);
4064
+ _this5.scheduler.unschedule(state.refreshHandle);
4065
+ state.refreshHandle = undefined;
3727
4066
  }
3728
4067
  var previous = {
3729
4068
  accessToken: state.accessToken,
@@ -3731,27 +4070,27 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3731
4070
  jwt: state.jwt,
3732
4071
  serviceWorkerConfigured: session.serviceWorkerConfigured
3733
4072
  };
3734
- var refreshAt = Date.now() + _this4.retryAuthAfterErrorSeconds * 1000;
4073
+ var refreshAt = Date.now() + _this5.retryAuthAfterErrorSeconds * 1000;
3735
4074
  return AuthManagerBrowser_finallyRethrows(function () {
3736
4075
  return AuthManagerBrowser_catch(function () {
3737
- return AuthManagerBrowser_await(_this4.getAuthorizationToken(session.params, state.config), function (jwt) {
3738
- var setCookie = _this4.shouldSetCookie(session, state.config);
3739
- return AuthManagerBrowser_await(_this4.setAccessToken(session.params.options, _this4.getConfigCdnUrl(session.params, state.config), state.config.accountId, jwt, setCookie), function (token) {
4076
+ return AuthManagerBrowser_await(_this5.getAuthorizationToken(session.params, state.config), function (jwt) {
4077
+ var setCookie = _this5.shouldSetCookie(session, state.config);
4078
+ return AuthManagerBrowser_await(_this5.setAccessToken(session.params.options, _this5.getConfigCdnUrl(session.params, state.config), state.config.accountId, jwt, setCookie), function (token) {
3740
4079
  var expiresAt = Date.now() + token.ttlSeconds * 1000;
3741
4080
  state.accessToken = token.accessToken;
3742
4081
  state.expiresAt = expiresAt;
3743
4082
  state.jwt = jwt;
3744
4083
  return AuthManagerBrowser_invoke(function () {
3745
- if (session.authServiceWorker !== undefined && (_this4.isServiceWorkerEnabled(state.config) || session.serviceWorkerConfigured !== true)) {
3746
- return AuthManagerBrowser_await(_this4.sendCurrentServiceWorkerConfig(session), function () {
3747
- return AuthManagerBrowser_await(_this4.waitForServiceWorker(), function () {
4084
+ if (session.authServiceWorker !== undefined && (_this5.isServiceWorkerEnabled(state.config) || session.serviceWorkerConfigured !== true)) {
4085
+ return AuthManagerBrowser_await(_this5.sendCurrentServiceWorkerConfig(session), function () {
4086
+ return AuthManagerBrowser_await(_this5.waitForServiceWorker(), function () {
3748
4087
  session.serviceWorkerConfigured = true;
3749
4088
  });
3750
4089
  });
3751
4090
  }
3752
4091
  }, function () {
3753
- var desiredTtl = token.ttlSeconds - _this4.refreshBeforeExpirySeconds;
3754
- var actualTtl = Math.max(desiredTtl, _this4.minJwtTtlSeconds);
4092
+ var desiredTtl = token.ttlSeconds - _this5.refreshBeforeExpirySeconds;
4093
+ var actualTtl = Math.max(desiredTtl, _this5.minJwtTtlSeconds);
3755
4094
  if (desiredTtl !== actualTtl) {
3756
4095
  ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(actualTtl, " seconds before refreshing."));
3757
4096
  }
@@ -3765,18 +4104,18 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3765
4104
  state.jwt = previous.jwt;
3766
4105
  session.serviceWorkerConfigured = previous.serviceWorkerConfigured;
3767
4106
  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 (rejectInvalidInitialToken && e instanceof InvalidAuthTokenError) {
4107
+ if (_this5.isV2Params(session.params) && previous.accessToken === undefined && e instanceof InvalidAuthTokenError) {
3769
4108
  throw e;
3770
4109
  }
3771
4110
  });
3772
- }, function (_wasThrown, _result2) {
3773
- state.refreshHandle = _this4.scheduler.schedule(refreshAt, function () {
3774
- _this4.refreshAuthConfig(session, state).then(function () {}, function (e) {
4111
+ }, function (_wasThrown, _result3) {
4112
+ state.refreshHandle = _this5.scheduler.schedule(refreshAt, function () {
4113
+ _this5.refreshAuthConfig(session, state).then(function () {}, function (e) {
3775
4114
  return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
3776
4115
  });
3777
4116
  });
3778
- _this4.updateSessionState(session);
3779
- return AuthManagerBrowser_rethrow(_wasThrown, _result2);
4117
+ _this5.updateSessionState(session);
4118
+ return AuthManagerBrowser_rethrow(_wasThrown, _result3);
3780
4119
  });
3781
4120
  }))));
3782
4121
  } catch (e) {
@@ -3787,11 +4126,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3787
4126
  key: "sendCurrentServiceWorkerConfig",
3788
4127
  value: function sendCurrentServiceWorkerConfig(session) {
3789
4128
  try {
3790
- var _this5 = this;
4129
+ var _this6 = this;
3791
4130
  var _a;
3792
4131
  var now = Date.now();
3793
4132
  var config = ((_a = session.authConfigs) !== null && _a !== void 0 ? _a : []).flatMap(function (state) {
3794
- if (!_this5.isServiceWorkerEnabled(state.config) || state.jwt === undefined || state.expiresAt === undefined || state.expiresAt <= now) {
4133
+ if (!_this6.isServiceWorkerEnabled(state.config) || state.jwt === undefined || state.expiresAt === undefined || state.expiresAt <= now) {
3795
4134
  return [];
3796
4135
  }
3797
4136
  return [{
@@ -3800,11 +4139,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3800
4139
  key: "Authorization",
3801
4140
  value: "Bearer ".concat(state.jwt)
3802
4141
  }],
4142
+ requestUrlPrefixes: state.config.requestUrlPrefixes,
3803
4143
  sourceUrlPrefixes: state.config.sourceUrlPrefixes,
3804
- urlPrefix: "".concat(_this5.getConfigCdnUrl(session.params, state.config), "/").concat(state.config.accountId, "/")
4144
+ urlPrefix: "".concat(_this6.getConfigCdnUrl(session.params, state.config), "/").concat(state.config.accountId, "/")
3805
4145
  }];
3806
4146
  });
3807
- return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this5.sendServiceWorkerConfig(session, config, _this5.isV2Params(session.params) ? session.params.urlRewriteRules : undefined)));
4147
+ return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(_this6.sendServiceWorkerConfig(session, config, _this6.isV2Params(session.params) ? session.params.urlRewriteRules : undefined)));
3808
4148
  } catch (e) {
3809
4149
  return Promise.reject(e);
3810
4150
  }
@@ -3813,21 +4153,21 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3813
4153
  key: "sendServiceWorkerConfig",
3814
4154
  value: function sendServiceWorkerConfig(session, config, urlRewriteRules) {
3815
4155
  try {
3816
- var _this6 = this;
4156
+ var _this7 = this;
3817
4157
  if (session.authServiceWorker === undefined) {
3818
4158
  throw new Error("Service worker configuration cannot be applied because service workers are unavailable.");
3819
4159
  }
3820
- return AuthManagerBrowser_await(_this6.serviceWorkerUtils.sendMessage(Object.assign({
4160
+ return AuthManagerBrowser_await(_this7.serviceWorkerUtils.sendMessage(Object.assign({
3821
4161
  type: "SET_BYTESCALE_AUTH_CONFIG",
3822
4162
  config: config.map(function (entry) {
3823
4163
  return Object.assign(Object.assign({}, entry), {
3824
- urlPrefix: "".concat(entry.sourceUrlPrefixes === undefined ? "" : _this6.sourceScopedUrlPrefixMarker).concat(entry.urlPrefix)
4164
+ urlPrefix: "".concat(entry.requestUrlPrefixes === undefined ? "" : _this7.requestScopedUrlPrefixMarker).concat(entry.sourceUrlPrefixes === undefined ? "" : _this7.sourceScopedUrlPrefixMarker).concat(entry.urlPrefix)
3825
4165
  });
3826
4166
  })
3827
4167
  }, urlRewriteRules === undefined ? {} : {
3828
4168
  urlRewriteRules: urlRewriteRules
3829
- }), session.authServiceWorker, _this6.serviceWorkerScriptFieldName), function (_this6$serviceWorkerU) {
3830
- session.authServiceWorker = _this6$serviceWorkerU;
4169
+ }), session.authServiceWorker, _this7.serviceWorkerScriptFieldName), function (_this7$serviceWorkerU) {
4170
+ session.authServiceWorker = _this7$serviceWorkerU;
3831
4171
  });
3832
4172
  } catch (e) {
3833
4173
  return Promise.reject(e);
@@ -3843,6 +4183,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3843
4183
  }
3844
4184
  return configs.map(function (config) {
3845
4185
  return config === null || AuthManagerBrowser_typeof(config) !== "object" ? config : Object.assign(Object.assign({}, config), {
4186
+ requestUrlPrefixes: Array.isArray(config.requestUrlPrefixes) ? AuthManagerBrowser_toConsumableArray(config.requestUrlPrefixes) : config.requestUrlPrefixes,
3846
4187
  sourceUrlPrefixes: Array.isArray(config.sourceUrlPrefixes) ? AuthManagerBrowser_toConsumableArray(config.sourceUrlPrefixes) : config.sourceUrlPrefixes
3847
4188
  });
3848
4189
  });
@@ -3900,11 +4241,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3900
4241
  if (config.enableCookieAuth !== undefined && typeof config.enableCookieAuth !== "boolean" || config.enableServiceWorkerAuth !== undefined && typeof config.enableServiceWorkerAuth !== "boolean") {
3901
4242
  throw new Error("Authentication enablement flags must be booleans when provided.");
3902
4243
  }
3903
- if (config.sourceUrlPrefixes !== undefined && (!Array.isArray(config.sourceUrlPrefixes) || !config.sourceUrlPrefixes.every(function (prefix) {
3904
- return typeof prefix === "string";
3905
- }))) {
3906
- throw new Error("The 'sourceUrlPrefixes' field must be an array of strings.");
3907
- }
4244
+ this.validateUrlPrefixes(config.sourceUrlPrefixes, "sourceUrlPrefixes");
4245
+ this.validateUrlPrefixes(config.requestUrlPrefixes, "requestUrlPrefixes");
3908
4246
  var isManual = typeof config.getAuthorizationToken === "function";
3909
4247
  var isAutomatic = typeof config.authUrl === "string" && typeof config.authHeaders === "function";
3910
4248
  if (isManual === isAutomatic || isManual && (config.authUrl !== undefined || config.authHeaders !== undefined)) {
@@ -3946,6 +4284,15 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3946
4284
  }
3947
4285
  }
3948
4286
  }
4287
+ }, {
4288
+ key: "validateUrlPrefixes",
4289
+ value: function validateUrlPrefixes(prefixes, fieldName) {
4290
+ if (prefixes !== undefined && (!Array.isArray(prefixes) || !prefixes.every(function (prefix) {
4291
+ return typeof prefix === "string";
4292
+ }))) {
4293
+ throw new Error("The '".concat(fieldName, "' field must be an array of strings."));
4294
+ }
4295
+ }
3949
4296
  }, {
3950
4297
  key: "validateUrlRewriteRules",
3951
4298
  value: function validateUrlRewriteRules(rules) {
@@ -3958,7 +4305,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3958
4305
  }, {
3959
4306
  key: "updateSessionState",
3960
4307
  value: function updateSessionState(session) {
3961
- var _this7 = this;
4308
+ var _this8 = this;
3962
4309
  var _a;
3963
4310
  var configs = (_a = session.authConfigs) !== null && _a !== void 0 ? _a : [];
3964
4311
  var defaultConfig = configs.find(function (state) {
@@ -3968,7 +4315,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
3968
4315
  session.accessToken = exposeLegacyDefault && defaultConfig !== undefined && this.isConfigUsable(defaultConfig) ? defaultConfig.accessToken : undefined;
3969
4316
  session.accessTokenRefreshHandle = exposeLegacyDefault ? defaultConfig === null || defaultConfig === void 0 ? void 0 : defaultConfig.refreshHandle : undefined;
3970
4317
  session.isReady = configs.length > 0 && configs.every(function (state) {
3971
- return _this7.isConfigUsable(state);
4318
+ return _this8.isConfigUsable(state);
3972
4319
  }) && (session.authServiceWorker === undefined || session.serviceWorkerConfigured === true);
3973
4320
  }
3974
4321
  }, {
@@ -4030,8 +4377,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
4030
4377
  key: "deleteAccessToken",
4031
4378
  value: function deleteAccessToken(options, cdnUrl, accountId) {
4032
4379
  try {
4033
- var _this8 = this;
4034
- return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(cdnUrl, accountId, true), {
4380
+ var _this9 = this;
4381
+ return AuthManagerBrowser_await(AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this9.getAccessTokenUrl(cdnUrl, accountId, true), {
4035
4382
  method: "DELETE",
4036
4383
  credentials: "include",
4037
4384
  headers: {}
@@ -4047,14 +4394,14 @@ var AuthManagerImpl = /*#__PURE__*/function () {
4047
4394
  key: "setAccessToken",
4048
4395
  value: function setAccessToken(options, cdnUrl, accountId, jwt, setCookie) {
4049
4396
  try {
4050
- var _this9 = this;
4397
+ var _this0 = this;
4051
4398
  var request = {
4052
4399
  accessToken: jwt
4053
4400
  };
4054
- return AuthManagerBrowser_await(BaseAPI.fetch(_this9.getAccessTokenUrl(cdnUrl, accountId, setCookie), {
4401
+ return AuthManagerBrowser_await(BaseAPI.fetch(_this0.getAccessTokenUrl(cdnUrl, accountId, setCookie), {
4055
4402
  method: "PUT",
4056
4403
  credentials: "include",
4057
- headers: AuthManagerBrowser_defineProperty({}, _this9.contentType, _this9.contentTypeJson),
4404
+ headers: AuthManagerBrowser_defineProperty({}, _this0.contentType, _this0.contentTypeJson),
4058
4405
  body: JSON.stringify(request)
4059
4406
  }, {
4060
4407
  isBytescaleApi: true,
@@ -4075,20 +4422,20 @@ var AuthManagerImpl = /*#__PURE__*/function () {
4075
4422
  key: "getAuthorizationToken",
4076
4423
  value: function getAuthorizationToken(params, config) {
4077
4424
  try {
4078
- var _exit = false;
4079
- var _this0 = this;
4425
+ var _exit2 = false;
4426
+ var _this1 = this;
4080
4427
  var _a, _b;
4081
4428
  return AuthManagerBrowser_await(AuthManagerBrowser_invoke(function () {
4082
4429
  if (typeof config.getAuthorizationToken === "function") {
4083
- var _validateJwt = _this0.validateJwt;
4430
+ var _validateJwt = _this1.validateJwt;
4084
4431
  return AuthManagerBrowser_await(config.getAuthorizationToken(), function (_config$getAuthorizat) {
4085
- var _this0$validateJwt = _validateJwt.call(_this0, _config$getAuthorizat, "The 'getAuthorizationToken' callback");
4086
- _exit = true;
4087
- return _this0$validateJwt;
4432
+ var _this1$validateJwt = _validateJwt.call(_this1, _config$getAuthorizat, "The 'getAuthorizationToken' callback");
4433
+ _exit2 = true;
4434
+ return _this1$validateJwt;
4088
4435
  });
4089
4436
  }
4090
- }, function (_result3) {
4091
- if (_exit) return _result3;
4437
+ }, function (_result4) {
4438
+ if (_exit2) return _result4;
4092
4439
  var endpointName = "Your auth API endpoint";
4093
4440
  var _fetch = BaseAPI.fetch,
4094
4441
  _config$authUrl = config.authUrl;
@@ -4100,13 +4447,13 @@ var AuthManagerImpl = /*#__PURE__*/function () {
4100
4447
  isBytescaleApi: false,
4101
4448
  fetchApi: (_a = params.options) === null || _a === void 0 ? void 0 : _a.fetchApi
4102
4449
  }), function (result) {
4103
- var actualContentType = (_b = result.headers.get(_this0.contentType)) !== null && _b !== void 0 ? _b : "";
4104
- if (actualContentType.split(";")[0] !== _this0.contentTypeText) {
4105
- throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this0.contentType, " response header, but the Bytescale SDK requires \"").concat(_this0.contentTypeText, "\"."));
4450
+ var actualContentType = (_b = result.headers.get(_this1.contentType)) !== null && _b !== void 0 ? _b : "";
4451
+ if (actualContentType.split(";")[0] !== _this1.contentTypeText) {
4452
+ throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this1.contentType, " response header, but the Bytescale SDK requires \"").concat(_this1.contentTypeText, "\"."));
4106
4453
  }
4107
- var _validateJwt2 = _this0.validateJwt;
4454
+ var _validateJwt2 = _this1.validateJwt;
4108
4455
  return AuthManagerBrowser_await(result.text(), function (_result$text) {
4109
- return _validateJwt2.call(_this0, _result$text, endpointName);
4456
+ return _validateJwt2.call(_this1, _result$text, endpointName);
4110
4457
  });
4111
4458
  });
4112
4459
  });