@bytescale/sdk 3.0.0-alpha.17 → 3.0.0-alpha.19

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.
@@ -507,6 +507,9 @@ var BaseAPI = /*#__PURE__*/function () {
507
507
  this.config = config;
508
508
  BytescaleApiClientConfigUtils.validate(config);
509
509
  }
510
+ /**
511
+ * Returns a successful response (2**) else throws an error.
512
+ */
510
513
  runtime_createClass(BaseAPI, [{
511
514
  key: "request",
512
515
  value: function request(context, initOverrides, baseUrlOverride) {
@@ -525,64 +528,9 @@ var BaseAPI = /*#__PURE__*/function () {
525
528
  return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
526
529
  var url = _ref.url,
527
530
  init = _ref.init;
528
- return _this2.doFetch(url, init, true);
529
- });
530
- } catch (e) {
531
- return Promise.reject(e);
532
- }
533
- }
534
- /**
535
- * Returns a successful response (2**) else throws an error.
536
- */
537
- }, {
538
- key: "doFetch",
539
- value: function doFetch(url, init, isBytescaleApi) {
540
- try {
541
- var _exit3 = false;
542
- var _this4 = this;
543
- var _a, _b;
544
- var response;
545
- return runtime_continue(_catch(function () {
546
- return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
547
- // This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
548
- //
549
- // "fetch requests that use the POST method are also automatically cached."
550
- // - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
551
- //
552
- // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
553
- // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
554
- cache: "no-store"
555
- })), function (_BytescaleApiClientCo) {
556
- response = _BytescaleApiClientCo;
557
- });
558
- }, function (e) {
559
- // Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
560
- // HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
561
- throw new Error(isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
562
- }), function (_result) {
563
- var _exit2 = false;
564
- if (_exit3) return _result;
565
- return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
566
- if (isBytescaleApi) {
567
- var jsonError = undefined;
568
- return runtime_continue(_catch(function () {
569
- return runtime_await(response.json(), function (_response$json) {
570
- jsonError = _response$json;
571
- });
572
- }, runtime_empty), function () {
573
- if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
574
- throw new BytescaleApiError(jsonError);
575
- }
576
- // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
577
- // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
578
- // this error will appear from any intermediary service failure.
579
- throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
580
- });
581
- }
582
- }, function (_result2) {
583
- if (_exit2) return _result2;
584
- throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
585
- });
531
+ return BaseAPI.fetch(url, init, Object.assign(Object.assign({}, _this2.config), {
532
+ isBytescaleApi: true
533
+ }));
586
534
  });
587
535
  } catch (e) {
588
536
  return Promise.reject(e);
@@ -605,15 +553,15 @@ var BaseAPI = /*#__PURE__*/function () {
605
553
  key: "createFetchParams",
606
554
  value: function createFetchParams(context, initOverrides, baseUrlOverride) {
607
555
  try {
608
- var _this6 = this;
609
- var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this6.config)) + context.path;
556
+ var _this4 = this;
557
+ var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this4.config)) + context.path;
610
558
  if (context.query !== undefined && Object.keys(context.query).length !== 0) {
611
559
  // only add the querystring to the URL if there are query parameters.
612
560
  // this is done to avoid urls ending with a "?" character which buggy webservers
613
561
  // do not handle correctly sometimes.
614
562
  url += "?" + querystring(context.query);
615
563
  }
616
- var configHeaders = _this6.config.headers;
564
+ var configHeaders = _this4.config.headers;
617
565
  var _Object$assign3 = Object.assign({}, context.headers);
618
566
  return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
619
567
  var headers = Object.assign(_Object$assign3, _configHeaders);
@@ -647,6 +595,59 @@ var BaseAPI = /*#__PURE__*/function () {
647
595
  return Promise.reject(e);
648
596
  }
649
597
  }
598
+ }], [{
599
+ key: "fetch",
600
+ value: function fetch(url, init, config) {
601
+ try {
602
+ var _exit3 = false;
603
+ var _a, _b;
604
+ var response;
605
+ return runtime_continue(_catch(function () {
606
+ return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(config)(url, Object.assign(Object.assign({}, init), {
607
+ // This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
608
+ //
609
+ // "fetch requests that use the POST method are also automatically cached."
610
+ // - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
611
+ //
612
+ // However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
613
+ // or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
614
+ cache: "no-store"
615
+ })), function (_BytescaleApiClientCo) {
616
+ response = _BytescaleApiClientCo;
617
+ });
618
+ }, function (e) {
619
+ // Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
620
+ // HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
621
+ throw new Error(config.isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
622
+ }), function (_result) {
623
+ var _exit2 = false;
624
+ if (_exit3) return _result;
625
+ return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
626
+ if (config.isBytescaleApi) {
627
+ var jsonError = undefined;
628
+ return runtime_continue(_catch(function () {
629
+ return runtime_await(response.json(), function (_response$json) {
630
+ jsonError = _response$json;
631
+ });
632
+ }, runtime_empty), function () {
633
+ if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
634
+ throw new BytescaleApiError(jsonError);
635
+ }
636
+ // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
637
+ // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
638
+ // this error will appear from any intermediary service failure.
639
+ throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
640
+ });
641
+ }
642
+ }, function (_result2) {
643
+ if (_exit2) return _result2;
644
+ throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
645
+ });
646
+ });
647
+ } catch (e) {
648
+ return Promise.reject(e);
649
+ }
650
+ }
650
651
  }]);
651
652
  return BaseAPI;
652
653
  }();
@@ -654,11 +655,11 @@ var CancelledError = /*#__PURE__*/function (_Error) {
654
655
  _inherits(CancelledError, _Error);
655
656
  var _super = _createSuper(CancelledError);
656
657
  function CancelledError() {
657
- var _this7;
658
+ var _this5;
658
659
  runtime_classCallCheck(this, CancelledError);
659
- _this7 = _super.call(this, "Operation cancelled by caller.");
660
- _this7.name = "CancelledError";
661
- return _this7;
660
+ _this5 = _super.call(this, "Operation cancelled by caller.");
661
+ _this5.name = "CancelledError";
662
+ return _this5;
662
663
  }
663
664
  return runtime_createClass(CancelledError);
664
665
  }( /*#__PURE__*/_wrapNativeSuper(Error));
@@ -666,13 +667,13 @@ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
666
667
  _inherits(BytescaleApiError, _Error2);
667
668
  var _super2 = _createSuper(BytescaleApiError);
668
669
  function BytescaleApiError(response) {
669
- var _this8;
670
+ var _this6;
670
671
  runtime_classCallCheck(this, BytescaleApiError);
671
- _this8 = _super2.call(this, response.error.message);
672
- _this8.name = "BytescaleApiError";
673
- _this8.errorCode = response.error.code;
674
- _this8.details = response.error.details;
675
- return _this8;
672
+ _this6 = _super2.call(this, response.error.message);
673
+ _this6.name = "BytescaleApiError";
674
+ _this6.errorCode = response.error.code;
675
+ _this6.details = response.error.details;
676
+ return _this6;
676
677
  }
677
678
  return runtime_createClass(BytescaleApiError);
678
679
  }( /*#__PURE__*/_wrapNativeSuper(Error));
@@ -698,8 +699,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
698
699
  key: "value",
699
700
  value: function value() {
700
701
  try {
701
- var _this10 = this;
702
- return runtime_await(_this10.raw.json());
702
+ var _this8 = this;
703
+ return runtime_await(_this8.raw.json());
703
704
  } catch (e) {
704
705
  return Promise.reject(e);
705
706
  }
@@ -740,8 +741,8 @@ var BinaryResult = /*#__PURE__*/function () {
740
741
  key: "text",
741
742
  value: function text() {
742
743
  try {
743
- var _this12 = this;
744
- return runtime_await(_this12.raw.text());
744
+ var _this10 = this;
745
+ return runtime_await(_this10.raw.text());
745
746
  } catch (e) {
746
747
  return Promise.reject(e);
747
748
  }
@@ -750,8 +751,8 @@ var BinaryResult = /*#__PURE__*/function () {
750
751
  key: "blob",
751
752
  value: function blob() {
752
753
  try {
753
- var _this14 = this;
754
- return runtime_await(_this14.raw.blob());
754
+ var _this12 = this;
755
+ return runtime_await(_this12.raw.blob());
755
756
  } catch (e) {
756
757
  return Promise.reject(e);
757
758
  }
@@ -760,8 +761,8 @@ var BinaryResult = /*#__PURE__*/function () {
760
761
  key: "json",
761
762
  value: function json() {
762
763
  try {
763
- var _this16 = this;
764
- return runtime_await(_this16.raw.json());
764
+ var _this14 = this;
765
+ return runtime_await(_this14.raw.json());
765
766
  } catch (e) {
766
767
  return Promise.reject(e);
767
768
  }
@@ -2586,63 +2587,47 @@ function AuthManagerBrowser_defineProperties(target, props) { for (var i = 0; i
2586
2587
  function AuthManagerBrowser_createClass(Constructor, protoProps, staticProps) { if (protoProps) AuthManagerBrowser_defineProperties(Constructor.prototype, protoProps); if (staticProps) AuthManagerBrowser_defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
2587
2588
  function AuthManagerBrowser_toPropertyKey(arg) { var key = AuthManagerBrowser_toPrimitive(arg, "string"); return AuthManagerBrowser_typeof(key) === "symbol" ? key : String(key); }
2588
2589
  function AuthManagerBrowser_toPrimitive(input, hint) { if (AuthManagerBrowser_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthManagerBrowser_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2589
- function AuthManagerBrowser_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) AuthManagerBrowser_setPrototypeOf(subClass, superClass); }
2590
- function AuthManagerBrowser_setPrototypeOf(o, p) { AuthManagerBrowser_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return AuthManagerBrowser_setPrototypeOf(o, p); }
2591
- function AuthManagerBrowser_createSuper(Derived) { var hasNativeReflectConstruct = AuthManagerBrowser_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = AuthManagerBrowser_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = AuthManagerBrowser_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return AuthManagerBrowser_possibleConstructorReturn(this, result); }; }
2592
- function AuthManagerBrowser_possibleConstructorReturn(self, call) { if (call && (AuthManagerBrowser_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return AuthManagerBrowser_assertThisInitialized(self); }
2593
- function AuthManagerBrowser_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
2594
- function AuthManagerBrowser_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2595
- function AuthManagerBrowser_getPrototypeOf(o) { AuthManagerBrowser_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return AuthManagerBrowser_getPrototypeOf(o); }
2596
2590
 
2597
2591
 
2598
2592
 
2599
- var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2600
- AuthManagerBrowser_inherits(AuthManager, _BaseAPI);
2601
- var _super = AuthManagerBrowser_createSuper(AuthManager);
2602
- function AuthManager(config) {
2603
- var _this;
2604
- AuthManagerBrowser_classCallCheck(this, AuthManager);
2605
- _this = _super.call(this, config);
2606
- _this.contentType = "content-type";
2607
- _this.contentTypeJson = "application/json";
2608
- _this.contentTypeText = "text/plain";
2609
- _this.minJwtTtlSeconds = 10;
2610
- _this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
2611
- _this.retryAuthAfterErrorSeconds = 5;
2612
- _this.refreshBeforeExpirySeconds = 20;
2613
- var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl(config);
2614
- var accountId = BytescaleApiClientConfigUtils.getAccountId(config);
2615
- _this.accessTokenUrl = "".concat(cdnUrl, "/api/v1/access_tokens/").concat(accountId);
2616
- _this.authSessionMutex = AuthSessionState.getMutex();
2617
- return _this;
2618
- }
2619
- AuthManagerBrowser_createClass(AuthManager, [{
2593
+ var AuthManagerImpl = /*#__PURE__*/function () {
2594
+ function AuthManagerImpl() {
2595
+ AuthManagerBrowser_classCallCheck(this, AuthManagerImpl);
2596
+ this.contentType = "content-type";
2597
+ this.contentTypeJson = "application/json";
2598
+ this.contentTypeText = "text/plain";
2599
+ this.minJwtTtlSeconds = 10;
2600
+ this.maxJwtTtlSeconds = 2147483; // Max value for window.setTimeout is 2147483647ms -- if we go over this, the timeout fires immediately.
2601
+ this.retryAuthAfterErrorSeconds = 5;
2602
+ this.refreshBeforeExpirySeconds = 20;
2603
+ this.authSessionMutex = AuthSessionState.getMutex();
2604
+ }
2605
+ AuthManagerBrowser_createClass(AuthManagerImpl, [{
2620
2606
  key: "isAuthSessionActive",
2621
2607
  value: function isAuthSessionActive() {
2622
2608
  return AuthSessionState.getSession() !== undefined;
2623
2609
  }
2624
2610
  }, {
2625
2611
  key: "beginAuthSession",
2626
- value: function beginAuthSession(authUrl, authHeaders) {
2612
+ value: function beginAuthSession(params) {
2627
2613
  try {
2628
- var _this3 = this;
2614
+ var _this2 = this;
2629
2615
  var newSession = {
2630
2616
  accessToken: undefined,
2631
2617
  accessTokenRefreshHandle: undefined,
2632
- authUrl: authUrl,
2633
- authHeaders: authHeaders,
2618
+ params: params,
2634
2619
  isActive: true
2635
2620
  };
2636
- return AuthManagerBrowser_await(_this3.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2621
+ return AuthManagerBrowser_await(_this2.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2637
2622
  // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2638
- if (_this3.isAuthSessionActive()) {
2623
+ if (_this2.isAuthSessionActive()) {
2639
2624
  throw new Error("Auth session already active: see AuthManager.isAuthSessionActive(). Please call 'await endAuthSession()' and then 'await beginAuthSession(...)' if you want to start a new auth session.");
2640
2625
  }
2641
2626
  AuthSessionState.setSession(newSession);
2642
2627
  return AuthManagerBrowser_await();
2643
2628
  })), function () {
2644
2629
  // IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
2645
- return AuthManagerBrowser_awaitIgnored(_this3.refreshAccessToken(newSession));
2630
+ return AuthManagerBrowser_awaitIgnored(_this2.refreshAccessToken(newSession));
2646
2631
  });
2647
2632
  } catch (e) {
2648
2633
  return Promise.reject(e);
@@ -2652,8 +2637,8 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2652
2637
  key: "endAuthSession",
2653
2638
  value: function endAuthSession() {
2654
2639
  try {
2655
- var _this5 = this;
2656
- return AuthManagerBrowser_awaitIgnored(_this5.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2640
+ var _this4 = this;
2641
+ return AuthManagerBrowser_awaitIgnored(_this4.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2657
2642
  var session = AuthSessionState.getSession();
2658
2643
  if (session === undefined) {
2659
2644
  return;
@@ -2663,7 +2648,7 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2663
2648
  if (session.accessTokenRefreshHandle !== undefined) {
2664
2649
  clearTimeout(session.accessTokenRefreshHandle);
2665
2650
  }
2666
- return AuthManagerBrowser_awaitIgnored(_this5.deleteAccessToken());
2651
+ return AuthManagerBrowser_awaitIgnored(_this4.deleteAccessToken(session.params));
2667
2652
  })));
2668
2653
  } catch (e) {
2669
2654
  return Promise.reject(e);
@@ -2673,26 +2658,26 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2673
2658
  key: "refreshAccessToken",
2674
2659
  value: function refreshAccessToken(session) {
2675
2660
  try {
2676
- var _this7 = this;
2677
- return AuthManagerBrowser_awaitIgnored(_this7.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2661
+ var _this6 = this;
2662
+ return AuthManagerBrowser_awaitIgnored(_this6.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2678
2663
  if (!session.isActive) {
2679
2664
  return;
2680
2665
  }
2681
- var timeout = _this7.retryAuthAfterErrorSeconds;
2666
+ var timeout = _this6.retryAuthAfterErrorSeconds;
2682
2667
  return AuthManagerBrowser_continueIgnored(AuthManagerBrowser_finallyRethrows(function () {
2683
2668
  return AuthManagerBrowser_catch(function () {
2684
- var _getAccessToken = _this7.getAccessToken,
2685
- _session$authUrl = session.authUrl;
2686
- return AuthManagerBrowser_await(session.authHeaders(), function (_session$authHeaders) {
2687
- return AuthManagerBrowser_await(_getAccessToken.call(_this7, _session$authUrl, _session$authHeaders), function (jwt) {
2688
- return AuthManagerBrowser_await(_this7.setAccessToken(jwt), function (setTokenResult) {
2689
- var desiredTtl = setTokenResult.ttlSeconds - _this7.refreshBeforeExpirySeconds;
2690
- timeout = Math.max(desiredTtl, _this7.minJwtTtlSeconds);
2669
+ var _getAccessToken = _this6.getAccessToken,
2670
+ _session$params = session.params;
2671
+ return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
2672
+ return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
2673
+ return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt), function (setTokenResult) {
2674
+ var desiredTtl = setTokenResult.ttlSeconds - _this6.refreshBeforeExpirySeconds;
2675
+ timeout = Math.max(desiredTtl, _this6.minJwtTtlSeconds);
2691
2676
  if (desiredTtl !== timeout) {
2692
2677
  ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
2693
2678
  }
2694
2679
  // There's need to print a warning for this: it's OK to silently request the JWT before it expires. Also, this is 24 days in this case!
2695
- timeout = Math.min(timeout, _this7.maxJwtTtlSeconds);
2680
+ timeout = Math.min(timeout, _this6.maxJwtTtlSeconds);
2696
2681
  session.accessToken = setTokenResult.accessToken;
2697
2682
  });
2698
2683
  });
@@ -2703,7 +2688,7 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2703
2688
  });
2704
2689
  }, function (_wasThrown, _result) {
2705
2690
  session.accessTokenRefreshHandle = window.setTimeout(function () {
2706
- _this7.refreshAccessToken(session).then(function () {}, function (e) {
2691
+ _this6.refreshAccessToken(session).then(function () {}, function (e) {
2707
2692
  return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
2708
2693
  });
2709
2694
  }, timeout * 1000);
@@ -2714,34 +2699,47 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2714
2699
  return Promise.reject(e);
2715
2700
  }
2716
2701
  }
2702
+ }, {
2703
+ key: "getAccessTokenUrl",
2704
+ value: function getAccessTokenUrl(params) {
2705
+ var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl(params);
2706
+ var accountId = BytescaleApiClientConfigUtils.getAccountId(params);
2707
+ return "".concat(cdnUrl, "/api/v1/access_tokens/").concat(accountId);
2708
+ }
2717
2709
  }, {
2718
2710
  key: "deleteAccessToken",
2719
- value: function deleteAccessToken() {
2711
+ value: function deleteAccessToken(params) {
2720
2712
  try {
2721
- var _this9 = this;
2722
- return AuthManagerBrowser_awaitIgnored(_this9.doFetch(_this9.accessTokenUrl, {
2713
+ var _this8 = this;
2714
+ return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params), {
2723
2715
  method: "DELETE",
2724
2716
  credentials: "include",
2725
2717
  headers: {}
2726
- }, true));
2718
+ }, {
2719
+ isBytescaleApi: true,
2720
+ fetchApi: params.fetchApi
2721
+ }));
2727
2722
  } catch (e) {
2728
2723
  return Promise.reject(e);
2729
2724
  }
2730
2725
  }
2731
2726
  }, {
2732
2727
  key: "setAccessToken",
2733
- value: function setAccessToken(jwt) {
2728
+ value: function setAccessToken(params, jwt) {
2734
2729
  try {
2735
- var _this11 = this;
2730
+ var _this10 = this;
2736
2731
  var request = {
2737
2732
  accessToken: jwt
2738
2733
  };
2739
- return AuthManagerBrowser_await(_this11.doFetch(_this11.accessTokenUrl, {
2734
+ return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params), {
2740
2735
  method: "PUT",
2741
2736
  credentials: "include",
2742
- headers: AuthManagerBrowser_defineProperty({}, _this11.contentType, _this11.contentTypeJson),
2737
+ headers: AuthManagerBrowser_defineProperty({}, _this10.contentType, _this10.contentTypeJson),
2743
2738
  body: JSON.stringify(request)
2744
- }, true), function (response) {
2739
+ }, {
2740
+ isBytescaleApi: true,
2741
+ fetchApi: params.fetchApi
2742
+ }), function (response) {
2745
2743
  return AuthManagerBrowser_await(response.json());
2746
2744
  });
2747
2745
  } catch (e) {
@@ -2750,17 +2748,23 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2750
2748
  }
2751
2749
  }, {
2752
2750
  key: "getAccessToken",
2753
- value: function getAccessToken(authUrl, headers) {
2751
+ value: function getAccessToken(params, headers) {
2754
2752
  try {
2755
- var _this13 = this;
2753
+ var _this12 = this;
2754
+ var _a;
2756
2755
  var endpointName = "Your auth API endpoint";
2757
- var requiredContentType = _this13.contentTypeText;
2758
- return AuthManagerBrowser_await(_this13.doFetch(authUrl, {
2756
+ var requiredContentType = _this12.contentTypeText;
2757
+ return AuthManagerBrowser_await(BaseAPI.fetch(params.authUrl, {
2759
2758
  method: "GET",
2760
2759
  headers: headers
2761
- }, false), function (result) {
2762
- if (result.headers.get(_this13.contentType) !== requiredContentType) {
2763
- throw new Error("".concat(endpointName, " returned an unsupported '").concat(_this13.contentType, "' response header: please return '").concat(requiredContentType, "'."));
2760
+ }, {
2761
+ isBytescaleApi: false,
2762
+ fetchApi: params.fetchApi
2763
+ }), function (result) {
2764
+ var actualContentType = (_a = result.headers.get(_this12.contentType)) !== null && _a !== void 0 ? _a : "";
2765
+ // Support content types like "text/plain; charset=utf-8" and "text/plain"
2766
+ if (actualContentType.split(";")[0] !== requiredContentType) {
2767
+ throw new Error("".concat(endpointName, " returned \"").concat(actualContentType, "\" for the ").concat(_this12.contentType, " response header, but the Bytescale SDK requires \"").concat(requiredContentType, "\"."));
2764
2768
  }
2765
2769
  return AuthManagerBrowser_await(result.text(), function (jwt) {
2766
2770
  if (jwt.length === 0) {
@@ -2778,8 +2782,12 @@ var AuthManager = /*#__PURE__*/function (_BaseAPI) {
2778
2782
  }
2779
2783
  }
2780
2784
  }]);
2781
- return AuthManager;
2782
- }(BaseAPI);
2785
+ return AuthManagerImpl;
2786
+ }();
2787
+ /**
2788
+ * Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
2789
+ */
2790
+ var AuthManager = new AuthManagerImpl();
2783
2791
  ;// CONCATENATED MODULE: ./src/public/browser/index.ts
2784
2792
 
2785
2793