@bytescale/sdk 3.59.0 → 3.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -155,6 +155,177 @@ var FairMutex = /*#__PURE__*/function () {
155
155
  }]);
156
156
  }();
157
157
  ;// ./src/private/AuthSessionState.ts
158
+ function AuthSessionState_empty() {}
159
+ function AuthSessionState_awaitIgnored(value, direct) {
160
+ if (!direct) {
161
+ return value && value.then ? value.then(AuthSessionState_empty) : Promise.resolve();
162
+ }
163
+ }
164
+ function AuthSessionState_invoke(body, then) {
165
+ var result = body();
166
+ if (result && result.then) {
167
+ return result.then(then);
168
+ }
169
+ return then(result);
170
+ }
171
+ function _settle(pact, state, value) {
172
+ if (!pact.s) {
173
+ if (value instanceof _Pact) {
174
+ if (value.s) {
175
+ if (state & 1) {
176
+ state = value.s;
177
+ }
178
+ value = value.v;
179
+ } else {
180
+ value.o = _settle.bind(null, pact, state);
181
+ return;
182
+ }
183
+ }
184
+ if (value && value.then) {
185
+ value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
186
+ return;
187
+ }
188
+ pact.s = state;
189
+ pact.v = value;
190
+ var observer = pact.o;
191
+ if (observer) {
192
+ observer(pact);
193
+ }
194
+ }
195
+ }
196
+ var _Pact = /*#__PURE__*/function () {
197
+ function _Pact() {}
198
+ _Pact.prototype.then = function (onFulfilled, onRejected) {
199
+ var result = new _Pact();
200
+ var state = this.s;
201
+ if (state) {
202
+ var callback = state & 1 ? onFulfilled : onRejected;
203
+ if (callback) {
204
+ try {
205
+ _settle(result, 1, callback(this.v));
206
+ } catch (e) {
207
+ _settle(result, 2, e);
208
+ }
209
+ return result;
210
+ } else {
211
+ return this;
212
+ }
213
+ }
214
+ this.o = function (_this) {
215
+ try {
216
+ var value = _this.v;
217
+ if (_this.s & 1) {
218
+ _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
219
+ } else if (onRejected) {
220
+ _settle(result, 1, onRejected(value));
221
+ } else {
222
+ _settle(result, 2, value);
223
+ }
224
+ } catch (e) {
225
+ _settle(result, 2, e);
226
+ }
227
+ };
228
+ return result;
229
+ };
230
+ return _Pact;
231
+ }();
232
+ function _isSettledPact(thenable) {
233
+ return thenable instanceof _Pact && thenable.s & 1;
234
+ }
235
+ function _for(test, update, body) {
236
+ var stage;
237
+ for (;;) {
238
+ var shouldContinue = test();
239
+ if (_isSettledPact(shouldContinue)) {
240
+ shouldContinue = shouldContinue.v;
241
+ }
242
+ if (!shouldContinue) {
243
+ return result;
244
+ }
245
+ if (shouldContinue.then) {
246
+ stage = 0;
247
+ break;
248
+ }
249
+ var result = body();
250
+ if (result && result.then) {
251
+ if (_isSettledPact(result)) {
252
+ result = result.s;
253
+ } else {
254
+ stage = 1;
255
+ break;
256
+ }
257
+ }
258
+ if (update) {
259
+ var updateValue = update();
260
+ if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
261
+ stage = 2;
262
+ break;
263
+ }
264
+ }
265
+ }
266
+ var pact = new _Pact();
267
+ var reject = _settle.bind(null, pact, 2);
268
+ (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
269
+ return pact;
270
+ function _resumeAfterBody(value) {
271
+ result = value;
272
+ do {
273
+ if (update) {
274
+ updateValue = update();
275
+ if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
276
+ updateValue.then(_resumeAfterUpdate).then(void 0, reject);
277
+ return;
278
+ }
279
+ }
280
+ shouldContinue = test();
281
+ if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
282
+ _settle(pact, 1, result);
283
+ return;
284
+ }
285
+ if (shouldContinue.then) {
286
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
287
+ return;
288
+ }
289
+ result = body();
290
+ if (_isSettledPact(result)) {
291
+ result = result.v;
292
+ }
293
+ } while (!result || !result.then);
294
+ result.then(_resumeAfterBody).then(void 0, reject);
295
+ }
296
+ function _resumeAfterTest(shouldContinue) {
297
+ if (shouldContinue) {
298
+ result = body();
299
+ if (result && result.then) {
300
+ result.then(_resumeAfterBody).then(void 0, reject);
301
+ } else {
302
+ _resumeAfterBody(result);
303
+ }
304
+ } else {
305
+ _settle(pact, 1, result);
306
+ }
307
+ }
308
+ function _resumeAfterUpdate() {
309
+ if (shouldContinue = test()) {
310
+ if (shouldContinue.then) {
311
+ shouldContinue.then(_resumeAfterTest).then(void 0, reject);
312
+ } else {
313
+ _resumeAfterTest(shouldContinue);
314
+ }
315
+ } else {
316
+ _settle(pact, 1, result);
317
+ }
318
+ }
319
+ }
320
+ function AuthSessionState_await(value, then, direct) {
321
+ if (direct) {
322
+ return then ? then(value) : value;
323
+ }
324
+ if (!value || !value.then) {
325
+ value = Promise.resolve(value);
326
+ }
327
+ return then ? value.then(then) : value;
328
+ }
158
329
  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); }
159
330
  function AuthSessionState_classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
160
331
  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); } }
@@ -261,6 +432,54 @@ var AuthSessionState = /*#__PURE__*/function () {
261
432
  jwt: undefined
262
433
  };
263
434
  }
435
+ /** Waits for request-time auth to be current before resolving it. */
436
+ }, {
437
+ key: "resolveAuthConfigAsync",
438
+ value: function resolveAuthConfigAsync(authConfigId, requireReadyDefault) {
439
+ try {
440
+ var _exit = false;
441
+ var _a, _b;
442
+ if (authConfigId === false) {
443
+ return AuthSessionState_await(undefined);
444
+ }
445
+ return AuthSessionState_await(_for(function () {
446
+ return !_exit;
447
+ }, void 0, function () {
448
+ var session = AuthSessionState.getSession();
449
+ if (session === undefined || !session.isActive || !Array.isArray(session.authConfigs)) {
450
+ var _AuthSessionState$res = AuthSessionState.resolveAuthConfig(authConfigId, requireReadyDefault);
451
+ _exit = true;
452
+ return _AuthSessionState$res;
453
+ }
454
+ var state = session.authConfigs.find(function (config) {
455
+ return config.config.authConfigId === authConfigId;
456
+ });
457
+ if (state === undefined) {
458
+ var _AuthSessionState$res2 = AuthSessionState.resolveAuthConfig(authConfigId, requireReadyDefault);
459
+ _exit = true;
460
+ return _AuthSessionState$res2;
461
+ }
462
+ var authenticationPromise = (_a = state.authenticationPromise) !== null && _a !== void 0 ? _a : state.refreshPromise;
463
+ return AuthSessionState_invoke(function () {
464
+ if (authenticationPromise !== undefined) {
465
+ return AuthSessionState_awaitIgnored(authenticationPromise);
466
+ }
467
+ }, function () {
468
+ if (AuthSessionState.getSession() !== session || !session.isActive) {
469
+ return;
470
+ }
471
+ var currentAuthenticationPromise = (_b = state.authenticationPromise) !== null && _b !== void 0 ? _b : state.refreshPromise;
472
+ if (currentAuthenticationPromise === undefined || currentAuthenticationPromise === authenticationPromise) {
473
+ var _AuthSessionState$res3 = AuthSessionState.resolveAuthConfig(authConfigId, true);
474
+ _exit = true;
475
+ return _AuthSessionState$res3;
476
+ }
477
+ });
478
+ }));
479
+ } catch (e) {
480
+ return Promise.reject(e);
481
+ }
482
+ }
264
483
  }]);
265
484
  }();
266
485
  AuthSessionState.stateKey = "BytescaleSessionState";
@@ -406,12 +625,43 @@ var BytescaleApiClientConfigUtils = /*#__PURE__*/function () {
406
625
  value: function getAccountId(config) {
407
626
  return BytescaleApiClientConfigUtils.resolveAuthentication(config).accountId;
408
627
  }
628
+ }, {
629
+ key: "getAccountIdAsync",
630
+ value: function getAccountIdAsync(config) {
631
+ try {
632
+ return runtime_await(BytescaleApiClientConfigUtils.resolveAuthenticationAsync(config), function (_BytescaleApiClientCo) {
633
+ return _BytescaleApiClientCo.accountId;
634
+ });
635
+ } catch (e) {
636
+ return Promise.reject(e);
637
+ }
638
+ }
409
639
  }, {
410
640
  key: "resolveAuthentication",
411
641
  value: function resolveAuthentication(config) {
412
- var _a, _b;
642
+ var _a;
413
643
  var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
414
644
  var authConfig = AuthSessionState.resolveAuthConfig(config.authConfigId, apiKey === undefined);
645
+ return BytescaleApiClientConfigUtils.resolveAuthenticationWithAuthConfig(config, authConfig);
646
+ }
647
+ }, {
648
+ key: "resolveAuthenticationAsync",
649
+ value: function resolveAuthenticationAsync(config) {
650
+ try {
651
+ var _a;
652
+ var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
653
+ return runtime_await(AuthSessionState.resolveAuthConfigAsync(config.authConfigId, apiKey === undefined), function (authConfig) {
654
+ return BytescaleApiClientConfigUtils.resolveAuthenticationWithAuthConfig(config, authConfig);
655
+ });
656
+ } catch (e) {
657
+ return Promise.reject(e);
658
+ }
659
+ }
660
+ }, {
661
+ key: "resolveAuthenticationWithAuthConfig",
662
+ value: function resolveAuthenticationWithAuthConfig(config, authConfig) {
663
+ var _a, _b;
664
+ var apiKey = (_a = config.apiKey) !== null && _a !== void 0 ? _a : undefined;
415
665
  var apiKeyAccountId = apiKey === undefined ? undefined : BytescaleApiClientConfigUtils.getApiKeyAccountId(apiKey);
416
666
  if (apiKeyAccountId !== undefined && authConfig !== undefined && apiKeyAccountId !== authConfig.accountId) {
417
667
  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, "'."));
@@ -498,7 +748,6 @@ var BaseAPI = /*#__PURE__*/function () {
498
748
  try {
499
749
  var _this = this;
500
750
  var _a;
501
- Object.assign(context.headers, BytescaleApiClientConfigUtils.resolveAuthentication(_this.config).headers);
502
751
  // Key: any possible value for 'baseUrlOverride'
503
752
  // Value: user-overridden value for that base URL from the config.
504
753
  var nonDefaultBasePaths = _defineProperty({}, BytescaleApiClientConfigUtils.defaultCdnUrl, BytescaleApiClientConfigUtils.getCdnUrl(_this.config));
@@ -539,44 +788,48 @@ var BaseAPI = /*#__PURE__*/function () {
539
788
  }
540
789
  var configHeaders = _this2.config.headers;
541
790
  return runtime_await(runtime_await(configHeaders === undefined ? {} : typeof configHeaders === "function" ? configHeaders() : configHeaders, function (resolvedConfigHeaders) {
542
- for (var _i = 0, _Object$keys = Object.keys(resolvedConfigHeaders); _i < _Object$keys.length; _i++) {
543
- var key = _Object$keys[_i];
544
- if (key.toLowerCase() === "authorization" || key.toLowerCase() === "authorization-token") {
545
- for (var _i2 = 0, _Object$keys2 = Object.keys(context.headers); _i2 < _Object$keys2.length; _i2++) {
546
- var generatedKey = _Object$keys2[_i2];
547
- if (generatedKey.toLowerCase() === key.toLowerCase()) {
548
- // Custom auth headers have documented precedence; remove the generated spelling to make that deterministic.
549
- // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
550
- delete context.headers[generatedKey];
791
+ var _context$headers = context.headers;
792
+ return runtime_await(BytescaleApiClientConfigUtils.resolveAuthenticationAsync(_this2.config), function (_BytescaleApiClientCo2) {
793
+ Object.assign(_context$headers, _BytescaleApiClientCo2.headers);
794
+ for (var _i = 0, _Object$keys = Object.keys(resolvedConfigHeaders); _i < _Object$keys.length; _i++) {
795
+ var key = _Object$keys[_i];
796
+ if (key.toLowerCase() === "authorization" || key.toLowerCase() === "authorization-token") {
797
+ for (var _i2 = 0, _Object$keys2 = Object.keys(context.headers); _i2 < _Object$keys2.length; _i2++) {
798
+ var generatedKey = _Object$keys2[_i2];
799
+ if (generatedKey.toLowerCase() === key.toLowerCase()) {
800
+ // Custom auth headers have documented precedence; remove the generated spelling to make that deterministic.
801
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
802
+ delete context.headers[generatedKey];
803
+ }
551
804
  }
552
805
  }
553
806
  }
554
- }
555
- var headers = Object.assign(Object.assign({}, context.headers), resolvedConfigHeaders);
556
- Object.keys(headers).forEach(function (key) {
557
- return headers[key] === undefined ? delete headers[key] : {};
558
- });
559
- var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
560
- return runtime_await(initOverrides);
561
- };
562
- var initParams = {
563
- method: context.method,
564
- headers: headers,
565
- body: context.body
566
- };
567
- var _Object$assign = Object.assign({}, initParams);
568
- return runtime_await(initOverrideFn({
569
- init: initParams,
570
- context: context
571
- }), function (_initOverrideFn) {
572
- var overriddenInit = Object.assign(_Object$assign, _initOverrideFn);
573
- var init = Object.assign(Object.assign({}, overriddenInit), {
574
- body: JSON.stringify(overriddenInit.body)
807
+ var headers = Object.assign(Object.assign({}, context.headers), resolvedConfigHeaders);
808
+ Object.keys(headers).forEach(function (key) {
809
+ return headers[key] === undefined ? delete headers[key] : {};
575
810
  });
576
- return {
577
- url: url,
578
- init: init
811
+ var initOverrideFn = typeof initOverrides === "function" ? initOverrides : function () {
812
+ return runtime_await(initOverrides);
579
813
  };
814
+ var initParams = {
815
+ method: context.method,
816
+ headers: headers,
817
+ body: context.body
818
+ };
819
+ var _Object$assign = Object.assign({}, initParams);
820
+ return runtime_await(initOverrideFn({
821
+ init: initParams,
822
+ context: context
823
+ }), function (_initOverrideFn) {
824
+ var overriddenInit = Object.assign(_Object$assign, _initOverrideFn);
825
+ var init = Object.assign(Object.assign({}, overriddenInit), {
826
+ body: JSON.stringify(overriddenInit.body)
827
+ });
828
+ return {
829
+ url: url,
830
+ init: init
831
+ };
832
+ });
580
833
  });
581
834
  }, configHeaders === undefined || !(typeof configHeaders === "function")));
582
835
  } catch (e) {
@@ -604,8 +857,8 @@ var BaseAPI = /*#__PURE__*/function () {
604
857
  // unless the following is set.
605
858
  // https://github.com/nodejs/node/issues/46221#issuecomment-1383246036
606
859
  duplex: "half"
607
- })), function (_BytescaleApiClientCo) {
608
- response = _BytescaleApiClientCo;
860
+ })), function (_BytescaleApiClientCo3) {
861
+ response = _BytescaleApiClientCo3;
609
862
  });
610
863
  }, function (e) {
611
864
  // Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
@@ -2016,21 +2269,21 @@ function _invokeIgnored(body) {
2016
2269
  return result.then(UploadManagerBase_empty);
2017
2270
  }
2018
2271
  }
2019
- function _settle(pact, state, value) {
2272
+ function UploadManagerBase_settle(pact, state, value) {
2020
2273
  if (!pact.s) {
2021
- if (value instanceof _Pact) {
2274
+ if (value instanceof UploadManagerBase_Pact) {
2022
2275
  if (value.s) {
2023
2276
  if (state & 1) {
2024
2277
  state = value.s;
2025
2278
  }
2026
2279
  value = value.v;
2027
2280
  } else {
2028
- value.o = _settle.bind(null, pact, state);
2281
+ value.o = UploadManagerBase_settle.bind(null, pact, state);
2029
2282
  return;
2030
2283
  }
2031
2284
  }
2032
2285
  if (value && value.then) {
2033
- value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
2286
+ value.then(UploadManagerBase_settle.bind(null, pact, state), UploadManagerBase_settle.bind(null, pact, 2));
2034
2287
  return;
2035
2288
  }
2036
2289
  pact.s = state;
@@ -2041,7 +2294,7 @@ function _settle(pact, state, value) {
2041
2294
  }
2042
2295
  }
2043
2296
  }
2044
- var _Pact = /*#__PURE__*/function () {
2297
+ var UploadManagerBase_Pact = /*#__PURE__*/function () {
2045
2298
  function _Pact() {}
2046
2299
  _Pact.prototype.then = function (onFulfilled, onRejected) {
2047
2300
  var result = new _Pact();
@@ -2050,9 +2303,9 @@ var _Pact = /*#__PURE__*/function () {
2050
2303
  var callback = state & 1 ? onFulfilled : onRejected;
2051
2304
  if (callback) {
2052
2305
  try {
2053
- _settle(result, 1, callback(this.v));
2306
+ UploadManagerBase_settle(result, 1, callback(this.v));
2054
2307
  } catch (e) {
2055
- _settle(result, 2, e);
2308
+ UploadManagerBase_settle(result, 2, e);
2056
2309
  }
2057
2310
  return result;
2058
2311
  } else {
@@ -2063,28 +2316,28 @@ var _Pact = /*#__PURE__*/function () {
2063
2316
  try {
2064
2317
  var value = _this.v;
2065
2318
  if (_this.s & 1) {
2066
- _settle(result, 1, onFulfilled ? onFulfilled(value) : value);
2319
+ UploadManagerBase_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
2067
2320
  } else if (onRejected) {
2068
- _settle(result, 1, onRejected(value));
2321
+ UploadManagerBase_settle(result, 1, onRejected(value));
2069
2322
  } else {
2070
- _settle(result, 2, value);
2323
+ UploadManagerBase_settle(result, 2, value);
2071
2324
  }
2072
2325
  } catch (e) {
2073
- _settle(result, 2, e);
2326
+ UploadManagerBase_settle(result, 2, e);
2074
2327
  }
2075
2328
  };
2076
2329
  return result;
2077
2330
  };
2078
2331
  return _Pact;
2079
2332
  }();
2080
- function _isSettledPact(thenable) {
2081
- return thenable instanceof _Pact && thenable.s & 1;
2333
+ function UploadManagerBase_isSettledPact(thenable) {
2334
+ return thenable instanceof UploadManagerBase_Pact && thenable.s & 1;
2082
2335
  }
2083
- function _for(test, update, body) {
2336
+ function UploadManagerBase_for(test, update, body) {
2084
2337
  var stage;
2085
2338
  for (;;) {
2086
2339
  var shouldContinue = test();
2087
- if (_isSettledPact(shouldContinue)) {
2340
+ if (UploadManagerBase_isSettledPact(shouldContinue)) {
2088
2341
  shouldContinue = shouldContinue.v;
2089
2342
  }
2090
2343
  if (!shouldContinue) {
@@ -2096,7 +2349,7 @@ function _for(test, update, body) {
2096
2349
  }
2097
2350
  var result = body();
2098
2351
  if (result && result.then) {
2099
- if (_isSettledPact(result)) {
2352
+ if (UploadManagerBase_isSettledPact(result)) {
2100
2353
  result = result.s;
2101
2354
  } else {
2102
2355
  stage = 1;
@@ -2105,14 +2358,14 @@ function _for(test, update, body) {
2105
2358
  }
2106
2359
  if (update) {
2107
2360
  var updateValue = update();
2108
- if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
2361
+ if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
2109
2362
  stage = 2;
2110
2363
  break;
2111
2364
  }
2112
2365
  }
2113
2366
  }
2114
- var pact = new _Pact();
2115
- var reject = _settle.bind(null, pact, 2);
2367
+ var pact = new UploadManagerBase_Pact();
2368
+ var reject = UploadManagerBase_settle.bind(null, pact, 2);
2116
2369
  (stage === 0 ? shouldContinue.then(_resumeAfterTest) : stage === 1 ? result.then(_resumeAfterBody) : updateValue.then(_resumeAfterUpdate)).then(void 0, reject);
2117
2370
  return pact;
2118
2371
  function _resumeAfterBody(value) {
@@ -2120,14 +2373,14 @@ function _for(test, update, body) {
2120
2373
  do {
2121
2374
  if (update) {
2122
2375
  updateValue = update();
2123
- if (updateValue && updateValue.then && !_isSettledPact(updateValue)) {
2376
+ if (updateValue && updateValue.then && !UploadManagerBase_isSettledPact(updateValue)) {
2124
2377
  updateValue.then(_resumeAfterUpdate).then(void 0, reject);
2125
2378
  return;
2126
2379
  }
2127
2380
  }
2128
2381
  shouldContinue = test();
2129
- if (!shouldContinue || _isSettledPact(shouldContinue) && !shouldContinue.v) {
2130
- _settle(pact, 1, result);
2382
+ if (!shouldContinue || UploadManagerBase_isSettledPact(shouldContinue) && !shouldContinue.v) {
2383
+ UploadManagerBase_settle(pact, 1, result);
2131
2384
  return;
2132
2385
  }
2133
2386
  if (shouldContinue.then) {
@@ -2135,7 +2388,7 @@ function _for(test, update, body) {
2135
2388
  return;
2136
2389
  }
2137
2390
  result = body();
2138
- if (_isSettledPact(result)) {
2391
+ if (UploadManagerBase_isSettledPact(result)) {
2139
2392
  result = result.v;
2140
2393
  }
2141
2394
  } while (!result || !result.then);
@@ -2150,7 +2403,7 @@ function _for(test, update, body) {
2150
2403
  _resumeAfterBody(result);
2151
2404
  }
2152
2405
  } else {
2153
- _settle(pact, 1, result);
2406
+ UploadManagerBase_settle(pact, 1, result);
2154
2407
  }
2155
2408
  }
2156
2409
  function _resumeAfterUpdate() {
@@ -2161,7 +2414,7 @@ function _for(test, update, body) {
2161
2414
  _resumeAfterTest(shouldContinue);
2162
2415
  }
2163
2416
  } else {
2164
- _settle(pact, 1, result);
2417
+ UploadManagerBase_settle(pact, 1, result);
2165
2418
  }
2166
2419
  }
2167
2420
  }
@@ -2201,40 +2454,41 @@ var UploadManagerBase = /*#__PURE__*/function () {
2201
2454
  try {
2202
2455
  var _this = this;
2203
2456
  _this.assertNotCancelled(request);
2204
- var accountId = BytescaleApiClientConfigUtils.getAccountId(_this.config);
2205
- var source = _this.processUploadSource(request.data);
2206
- var preUploadInfo = _this.getPreUploadInfo(request, source);
2207
- var bytesTotal = preUploadInfo.size;
2208
- var makeOnProgressForPart = _this.makeOnProgressForPartFactory(request, bytesTotal);
2209
- var init = _this.preUpload(source);
2210
- // Raise initial progress event SYNCHRONOUSLY.
2211
- if (request.onProgress !== undefined) {
2212
- request.onProgress(_this.makeProgressEvent(0, bytesTotal));
2213
- }
2214
- return UploadManagerBase_await(_this.beginUpload(request, preUploadInfo, accountId), function (uploadInfo) {
2215
- var partCount = uploadInfo.uploadParts.count;
2216
- var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
2217
- var _this$makeCancellatio = _this.makeCancellationMethods(),
2218
- cancel = _this$makeCancellatio.cancel,
2219
- addCancellationHandler = _this$makeCancellatio.addCancellationHandler;
2220
- var intervalHandle = setInterval(_this.onIntervalTick(request, cancel), _this.intervalMs);
2221
- var uploadedParts;
2222
- return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
2223
- return UploadManagerBase_await(_this.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
2224
- return _this.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler, accountId);
2225
- })), function (_this$mapAsync) {
2226
- uploadedParts = _this$mapAsync;
2227
- return UploadManagerBase_awaitIgnored(_this.postUpload(init));
2228
- });
2229
- }, function (_wasThrown, _result) {
2230
- clearInterval(intervalHandle);
2231
- return UploadManagerBase_rethrow(_wasThrown, _result);
2232
- }), function () {
2233
- var etag = uploadedParts.flatMap(function (x) {
2234
- return x.status === "Completed" ? [x.etag] : [];
2235
- })[0];
2236
- return Object.assign(Object.assign({}, uploadInfo.file), {
2237
- etag: etag // The 'etag' in the original 'uploadInfo.file' will be null, so we set it to the final etag value here.
2457
+ return UploadManagerBase_await(BytescaleApiClientConfigUtils.getAccountIdAsync(_this.config), function (accountId) {
2458
+ var source = _this.processUploadSource(request.data);
2459
+ var preUploadInfo = _this.getPreUploadInfo(request, source);
2460
+ var bytesTotal = preUploadInfo.size;
2461
+ var makeOnProgressForPart = _this.makeOnProgressForPartFactory(request, bytesTotal);
2462
+ var init = _this.preUpload(source);
2463
+ // Raise initial progress event SYNCHRONOUSLY.
2464
+ if (request.onProgress !== undefined) {
2465
+ request.onProgress(_this.makeProgressEvent(0, bytesTotal));
2466
+ }
2467
+ return UploadManagerBase_await(_this.beginUpload(request, preUploadInfo, accountId), function (uploadInfo) {
2468
+ var partCount = uploadInfo.uploadParts.count;
2469
+ var parts = UploadManagerBase_toConsumableArray(Array(partCount).keys());
2470
+ var _this$makeCancellatio = _this.makeCancellationMethods(),
2471
+ cancel = _this$makeCancellatio.cancel,
2472
+ addCancellationHandler = _this$makeCancellatio.addCancellationHandler;
2473
+ var intervalHandle = setInterval(_this.onIntervalTick(request, cancel), _this.intervalMs);
2474
+ var uploadedParts;
2475
+ return UploadManagerBase_continue(UploadManagerBase_finallyRethrows(function () {
2476
+ return UploadManagerBase_await(_this.mapAsync(parts, preUploadInfo.maxConcurrentUploadParts, _async(function (part) {
2477
+ return _this.uploadPart(request, source, part, uploadInfo, makeOnProgressForPart(), addCancellationHandler, accountId);
2478
+ })), function (_this$mapAsync) {
2479
+ uploadedParts = _this$mapAsync;
2480
+ return UploadManagerBase_awaitIgnored(_this.postUpload(init));
2481
+ });
2482
+ }, function (_wasThrown, _result) {
2483
+ clearInterval(intervalHandle);
2484
+ return UploadManagerBase_rethrow(_wasThrown, _result);
2485
+ }), function () {
2486
+ var etag = uploadedParts.flatMap(function (x) {
2487
+ return x.status === "Completed" ? [x.etag] : [];
2488
+ })[0];
2489
+ return Object.assign(Object.assign({}, uploadInfo.file), {
2490
+ etag: etag // The 'etag' in the original 'uploadInfo.file' will be null, so we set it to the final etag value here.
2491
+ });
2238
2492
  });
2239
2493
  });
2240
2494
  });
@@ -2441,7 +2695,7 @@ var UploadManagerBase = /*#__PURE__*/function () {
2441
2695
  var result = [];
2442
2696
  var workQueue = UploadManagerBase_toConsumableArray(items);
2443
2697
  return UploadManagerBase_await(Promise.all(UploadManagerBase_toConsumableArray(Array(concurrency).keys()).map(_async(function () {
2444
- return _continueIgnored(_for(function () {
2698
+ return _continueIgnored(UploadManagerBase_for(function () {
2445
2699
  return workQueue.length > 0;
2446
2700
  }, void 0, function () {
2447
2701
  var work = workQueue.shift(); // IMPORTANT: use 'shift' instead of 'pop' to ensure 'items' are processed in order when 'concurrency = 1'.
@@ -34,4 +34,6 @@ export declare class AuthSessionState {
34
34
  static getSession(): AuthSession | undefined;
35
35
  /** Resolves request-time auth while remaining compatible with the single-token session used by SDK 3.54.0. */
36
36
  static resolveAuthConfig(authConfigId: string | false | undefined, requireReadyDefault: boolean): ResolvedAuthSessionConfig | undefined;
37
+ /** Waits for request-time auth to be current before resolving it. */
38
+ static resolveAuthConfigAsync(authConfigId: string | false | undefined, requireReadyDefault: boolean): Promise<ResolvedAuthSessionConfig | undefined>;
37
39
  }
@@ -3,16 +3,25 @@
3
3
  * Q: Why not use 'setTimeout'?
4
4
  * -------------------------
5
5
  * A: setTimeout can be paused (e.g., during hibernation), risking JWT expiration before it triggers.
6
- * We therefore use a scheduler to check wall-clock time every second and execute the callback at the scheduled time.
6
+ * We therefore check wall-clock time every second and on browser resume events. A backwards clock adjustment runs
7
+ * scheduled callbacks immediately so authentication can be safely re-established against the server-provided TTL.
7
8
  * -------------------------
8
9
  */
9
10
  export declare class Scheduler {
11
+ private readonly clockRollbackToleranceMilliseconds;
10
12
  private callbacks;
13
+ private documentEventTarget;
11
14
  private nextId;
12
15
  private intervalId;
16
+ private lastObservedEpoch;
17
+ private windowEventTarget;
13
18
  schedule(epoch: number, callback: () => void): number;
14
19
  unschedule(handle: number): void;
15
- private startInterval;
16
- private stopInterval;
20
+ private readonly checkAfterResume;
21
+ private readonly checkAfterVisibilityChange;
22
+ private startMonitoring;
23
+ private stopMonitoring;
17
24
  private checkCallbacks;
25
+ private startListeningForResume;
26
+ private stopListeningForResume;
18
27
  }
@@ -3,10 +3,14 @@ import { BeginAuthSessionParams } from "./BeginAuthSessionParams";
3
3
  import { AuthSessionConfig } from "./AuthSessionConfig";
4
4
  export interface AuthSessionConfigState {
5
5
  accessToken: string | undefined;
6
+ /** The latest AuthManager-owned authentication operation; settled while idle and pending during refresh. */
7
+ authenticationPromise?: Promise<void>;
6
8
  config: AuthSessionConfig;
7
9
  expiresAt: number | undefined;
8
10
  jwt: string | undefined;
9
11
  refreshHandle: number | undefined;
12
+ /** Present only while AuthManager is refreshing, so concurrent manager refresh attempts can be deduplicated. */
13
+ refreshPromise?: Promise<void>;
10
14
  }
11
15
  export interface AuthSession {
12
16
  /** Legacy default-token fields retained for SDK 3.54.0 bundles sharing this global state. */