@bytescale/sdk 3.10.0 → 3.12.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.
@@ -2372,15 +2372,20 @@ var ConsoleUtils = /*#__PURE__*/function () {
2372
2372
  ConsoleUtils_classCallCheck(this, ConsoleUtils);
2373
2373
  }
2374
2374
  ConsoleUtils_createClass(ConsoleUtils, null, [{
2375
- key: "error",
2376
- value: function error(message) {
2377
- console.error(ConsoleUtils.prefix(message));
2375
+ key: "debug",
2376
+ value: function debug(message) {
2377
+ console.log(ConsoleUtils.prefix(message));
2378
2378
  }
2379
2379
  }, {
2380
2380
  key: "warn",
2381
2381
  value: function warn(message) {
2382
2382
  console.warn(ConsoleUtils.prefix(message));
2383
2383
  }
2384
+ }, {
2385
+ key: "error",
2386
+ value: function error(message) {
2387
+ console.error(ConsoleUtils.prefix(message));
2388
+ }
2384
2389
  }, {
2385
2390
  key: "prefix",
2386
2391
  value: function prefix(message) {
@@ -2480,22 +2485,25 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2480
2485
  value: function beginAuthSession(params) {
2481
2486
  try {
2482
2487
  var _this2 = this;
2483
- var newSession = {
2484
- accessToken: undefined,
2485
- accessTokenRefreshHandle: undefined,
2486
- params: params,
2487
- isActive: true
2488
- };
2489
2488
  return AuthManagerBrowser_await(_this2.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2490
2489
  // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2491
2490
  if (_this2.isAuthSessionActive()) {
2492
2491
  throw new Error("Auth session already active. Please call 'await endAuthSession()' and then call 'await beginAuthSession(...)' to start a new auth session.");
2493
2492
  }
2494
- AuthSessionState.setSession(newSession);
2495
- return AuthManagerBrowser_await();
2496
- })), function () {
2493
+ return AuthManagerBrowser_await(_this2.registerAuthServiceWorker(params), function (_this2$registerAuthSe) {
2494
+ var newSession = {
2495
+ accessToken: undefined,
2496
+ accessTokenRefreshHandle: undefined,
2497
+ params: params,
2498
+ isActive: true,
2499
+ authServiceWorker: _this2$registerAuthSe
2500
+ };
2501
+ AuthSessionState.setSession(newSession);
2502
+ return newSession;
2503
+ });
2504
+ })), function (session) {
2497
2505
  // IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
2498
- return AuthManagerBrowser_awaitIgnored(_this2.refreshAccessToken(newSession));
2506
+ return AuthManagerBrowser_awaitIgnored(_this2.refreshAccessToken(session));
2499
2507
  });
2500
2508
  } catch (e) {
2501
2509
  return Promise.reject(e);
@@ -2516,12 +2524,55 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2516
2524
  if (session.accessTokenRefreshHandle !== undefined) {
2517
2525
  clearTimeout(session.accessTokenRefreshHandle);
2518
2526
  }
2519
- return AuthManagerBrowser_awaitIgnored(_this4.deleteAccessToken(session.params));
2527
+ return AuthManagerBrowser_await(_this4.deleteAccessToken(session.params), function () {
2528
+ _this4.setServiceWorkerConfig(session, []); // Prevent service worker from authorizing subsequent requests.
2529
+ });
2520
2530
  })));
2521
2531
  } catch (e) {
2522
2532
  return Promise.reject(e);
2523
2533
  }
2524
2534
  }
2535
+ /**
2536
+ * Idempotent.
2537
+ *
2538
+ * Only returns once the service worker has been activated.
2539
+ *
2540
+ * We don't need to unregister it: we just need to clear the config when auth ends.
2541
+ */
2542
+ }, {
2543
+ key: "registerAuthServiceWorker",
2544
+ value: function registerAuthServiceWorker(_ref) {
2545
+ var serviceWorkerScript = _ref.serviceWorkerScript;
2546
+ try {
2547
+ if (serviceWorkerScript === undefined) {
2548
+ return undefined;
2549
+ }
2550
+ return AuthManagerBrowser_catch(function () {
2551
+ if ("serviceWorker" in navigator) {
2552
+ return AuthManagerBrowser_await(navigator.serviceWorker.register(serviceWorkerScript), function (registration) {
2553
+ return registration.active !== null ? registration.active : AuthManagerBrowser_awaitIgnored(new Promise(function (resolve) {
2554
+ registration.addEventListener("updatefound", function () {
2555
+ var newWorker = registration.installing;
2556
+ if (newWorker !== null) {
2557
+ newWorker.addEventListener("statechange", function () {
2558
+ if (newWorker.state === "activated") {
2559
+ resolve(newWorker);
2560
+ }
2561
+ });
2562
+ }
2563
+ });
2564
+ }));
2565
+ }); // Occurs when: (service worker is already registered AND there's been no code changes) OR (service worker was not previously registered).
2566
+ } else {
2567
+ ConsoleUtils.warn("Service workers not supported by browser. Falling back to Bytescale CDN cookies for auth. These are third-party cookies, which some modern browsers block.");
2568
+ }
2569
+ }, function (e) {
2570
+ throw new Error("Failed to install Bytescale Auth Service Worker (SW). ".concat(e.name, ": ").concat(e.message));
2571
+ });
2572
+ } catch (e) {
2573
+ return Promise.reject(e);
2574
+ }
2575
+ }
2525
2576
  }, {
2526
2577
  key: "refreshAccessToken",
2527
2578
  value: function refreshAccessToken(session) {
@@ -2539,40 +2590,64 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2539
2590
  return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
2540
2591
  return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
2541
2592
  return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt), function (setTokenResult) {
2593
+ _this6.setServiceWorkerConfig(session, [{
2594
+ headers: [{
2595
+ key: "Authorization-Token",
2596
+ value: jwt
2597
+ }],
2598
+ expires: Date.now() + setTokenResult.ttlSeconds * 1000,
2599
+ urlPrefix: "".concat(_this6.getCdnUrl(session.params), "/").concat(session.params.accountId, "/")
2600
+ }]);
2542
2601
  var desiredTtl = setTokenResult.ttlSeconds - _this6.refreshBeforeExpirySeconds;
2543
2602
  timeout = Math.max(desiredTtl, _this6.minJwtTtlSeconds);
2544
2603
  if (desiredTtl !== timeout) {
2545
2604
  ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
2546
2605
  }
2547
- // 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!
2606
+ // There's no 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!
2548
2607
  timeout = Math.min(timeout, _this6.maxJwtTtlSeconds);
2549
2608
  session.accessToken = setTokenResult.accessToken;
2550
2609
  });
2551
2610
  });
2552
2611
  });
2553
2612
  }, function (e) {
2554
- // Use 'error' instead of 'debug' so that the user sees error messages.
2555
- ConsoleUtils.error("Error when refreshing access token: ".concat(e));
2613
+ // Use 'warn' instead of 'error' since this happens frequently, i.e. user goes through a tunnel, and some customers report these errors to systems like Sentry, so we don't want to spam.
2614
+ ConsoleUtils.warn("Unable to refresh JWT access token: ".concat(e));
2556
2615
  });
2557
- }, function (_wasThrown, _result) {
2616
+ }, function (_wasThrown, _result3) {
2558
2617
  session.accessTokenRefreshHandle = window.setTimeout(function () {
2559
- _this6.refreshAccessToken(session).then(function () {}, function (e) {
2560
- return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
2618
+ _this6.refreshAccessToken(session).then(function () {},
2619
+ // Should not occur, as this method shouldn't throw errors.
2620
+ function (e) {
2621
+ return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
2561
2622
  });
2562
2623
  }, timeout * 1000);
2563
- return AuthManagerBrowser_rethrow(_wasThrown, _result);
2624
+ return AuthManagerBrowser_rethrow(_wasThrown, _result3);
2564
2625
  }));
2565
2626
  })));
2566
2627
  } catch (e) {
2567
2628
  return Promise.reject(e);
2568
2629
  }
2569
2630
  }
2631
+ }, {
2632
+ key: "setServiceWorkerConfig",
2633
+ value: function setServiceWorkerConfig(session, config) {
2634
+ var _a;
2635
+ var message = {
2636
+ type: "SET_CONFIG",
2637
+ config: config
2638
+ };
2639
+ (_a = session.authServiceWorker) === null || _a === void 0 ? void 0 : _a.postMessage(message);
2640
+ }
2570
2641
  }, {
2571
2642
  key: "getAccessTokenUrl",
2572
2643
  value: function getAccessTokenUrl(params) {
2644
+ return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId);
2645
+ }
2646
+ }, {
2647
+ key: "getCdnUrl",
2648
+ value: function getCdnUrl(params) {
2573
2649
  var _a;
2574
- var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl((_a = params.options) !== null && _a !== void 0 ? _a : {});
2575
- return "".concat(cdnUrl, "/api/v1/access_tokens/").concat(params.accountId);
2650
+ return BytescaleApiClientConfigUtils.getCdnUrl((_a = params.options) !== null && _a !== void 0 ? _a : {});
2576
2651
  }
2577
2652
  }, {
2578
2653
  key: "deleteAccessToken",
@@ -2357,15 +2357,20 @@ var ConsoleUtils = /*#__PURE__*/function () {
2357
2357
  ConsoleUtils_classCallCheck(this, ConsoleUtils);
2358
2358
  }
2359
2359
  ConsoleUtils_createClass(ConsoleUtils, null, [{
2360
- key: "error",
2361
- value: function error(message) {
2362
- console.error(ConsoleUtils.prefix(message));
2360
+ key: "debug",
2361
+ value: function debug(message) {
2362
+ console.log(ConsoleUtils.prefix(message));
2363
2363
  }
2364
2364
  }, {
2365
2365
  key: "warn",
2366
2366
  value: function warn(message) {
2367
2367
  console.warn(ConsoleUtils.prefix(message));
2368
2368
  }
2369
+ }, {
2370
+ key: "error",
2371
+ value: function error(message) {
2372
+ console.error(ConsoleUtils.prefix(message));
2373
+ }
2369
2374
  }, {
2370
2375
  key: "prefix",
2371
2376
  value: function prefix(message) {
@@ -2465,22 +2470,25 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2465
2470
  value: function beginAuthSession(params) {
2466
2471
  try {
2467
2472
  var _this2 = this;
2468
- var newSession = {
2469
- accessToken: undefined,
2470
- accessTokenRefreshHandle: undefined,
2471
- params: params,
2472
- isActive: true
2473
- };
2474
2473
  return AuthManagerBrowser_await(_this2.authSessionMutex.safe(AuthManagerBrowser_async(function () {
2475
2474
  // We check both 'session' and 'sessionDisposing' here, as we don't want to call 'beginAuthSession' until the session is fully disposed.
2476
2475
  if (_this2.isAuthSessionActive()) {
2477
2476
  throw new Error("Auth session already active. Please call 'await endAuthSession()' and then call 'await beginAuthSession(...)' to start a new auth session.");
2478
2477
  }
2479
- AuthSessionState.setSession(newSession);
2480
- return AuthManagerBrowser_await();
2481
- })), function () {
2478
+ return AuthManagerBrowser_await(_this2.registerAuthServiceWorker(params), function (_this2$registerAuthSe) {
2479
+ var newSession = {
2480
+ accessToken: undefined,
2481
+ accessTokenRefreshHandle: undefined,
2482
+ params: params,
2483
+ isActive: true,
2484
+ authServiceWorker: _this2$registerAuthSe
2485
+ };
2486
+ AuthSessionState.setSession(newSession);
2487
+ return newSession;
2488
+ });
2489
+ })), function (session) {
2482
2490
  // IMPORTANT: must be called outside the above, else re-entrant deadlock will occur.
2483
- return AuthManagerBrowser_awaitIgnored(_this2.refreshAccessToken(newSession));
2491
+ return AuthManagerBrowser_awaitIgnored(_this2.refreshAccessToken(session));
2484
2492
  });
2485
2493
  } catch (e) {
2486
2494
  return Promise.reject(e);
@@ -2501,12 +2509,55 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2501
2509
  if (session.accessTokenRefreshHandle !== undefined) {
2502
2510
  clearTimeout(session.accessTokenRefreshHandle);
2503
2511
  }
2504
- return AuthManagerBrowser_awaitIgnored(_this4.deleteAccessToken(session.params));
2512
+ return AuthManagerBrowser_await(_this4.deleteAccessToken(session.params), function () {
2513
+ _this4.setServiceWorkerConfig(session, []); // Prevent service worker from authorizing subsequent requests.
2514
+ });
2505
2515
  })));
2506
2516
  } catch (e) {
2507
2517
  return Promise.reject(e);
2508
2518
  }
2509
2519
  }
2520
+ /**
2521
+ * Idempotent.
2522
+ *
2523
+ * Only returns once the service worker has been activated.
2524
+ *
2525
+ * We don't need to unregister it: we just need to clear the config when auth ends.
2526
+ */
2527
+ }, {
2528
+ key: "registerAuthServiceWorker",
2529
+ value: function registerAuthServiceWorker(_ref) {
2530
+ var serviceWorkerScript = _ref.serviceWorkerScript;
2531
+ try {
2532
+ if (serviceWorkerScript === undefined) {
2533
+ return undefined;
2534
+ }
2535
+ return AuthManagerBrowser_catch(function () {
2536
+ if ("serviceWorker" in navigator) {
2537
+ return AuthManagerBrowser_await(navigator.serviceWorker.register(serviceWorkerScript), function (registration) {
2538
+ return registration.active !== null ? registration.active : AuthManagerBrowser_awaitIgnored(new Promise(function (resolve) {
2539
+ registration.addEventListener("updatefound", function () {
2540
+ var newWorker = registration.installing;
2541
+ if (newWorker !== null) {
2542
+ newWorker.addEventListener("statechange", function () {
2543
+ if (newWorker.state === "activated") {
2544
+ resolve(newWorker);
2545
+ }
2546
+ });
2547
+ }
2548
+ });
2549
+ }));
2550
+ }); // Occurs when: (service worker is already registered AND there's been no code changes) OR (service worker was not previously registered).
2551
+ } else {
2552
+ ConsoleUtils.warn("Service workers not supported by browser. Falling back to Bytescale CDN cookies for auth. These are third-party cookies, which some modern browsers block.");
2553
+ }
2554
+ }, function (e) {
2555
+ throw new Error("Failed to install Bytescale Auth Service Worker (SW). ".concat(e.name, ": ").concat(e.message));
2556
+ });
2557
+ } catch (e) {
2558
+ return Promise.reject(e);
2559
+ }
2560
+ }
2510
2561
  }, {
2511
2562
  key: "refreshAccessToken",
2512
2563
  value: function refreshAccessToken(session) {
@@ -2524,40 +2575,64 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2524
2575
  return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
2525
2576
  return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
2526
2577
  return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt), function (setTokenResult) {
2578
+ _this6.setServiceWorkerConfig(session, [{
2579
+ headers: [{
2580
+ key: "Authorization-Token",
2581
+ value: jwt
2582
+ }],
2583
+ expires: Date.now() + setTokenResult.ttlSeconds * 1000,
2584
+ urlPrefix: "".concat(_this6.getCdnUrl(session.params), "/").concat(session.params.accountId, "/")
2585
+ }]);
2527
2586
  var desiredTtl = setTokenResult.ttlSeconds - _this6.refreshBeforeExpirySeconds;
2528
2587
  timeout = Math.max(desiredTtl, _this6.minJwtTtlSeconds);
2529
2588
  if (desiredTtl !== timeout) {
2530
2589
  ConsoleUtils.warn("JWT expiration is too short: waiting for ".concat(timeout, " seconds before refreshing."));
2531
2590
  }
2532
- // 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!
2591
+ // There's no 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!
2533
2592
  timeout = Math.min(timeout, _this6.maxJwtTtlSeconds);
2534
2593
  session.accessToken = setTokenResult.accessToken;
2535
2594
  });
2536
2595
  });
2537
2596
  });
2538
2597
  }, function (e) {
2539
- // Use 'error' instead of 'debug' so that the user sees error messages.
2540
- ConsoleUtils.error("Error when refreshing access token: ".concat(e));
2598
+ // Use 'warn' instead of 'error' since this happens frequently, i.e. user goes through a tunnel, and some customers report these errors to systems like Sentry, so we don't want to spam.
2599
+ ConsoleUtils.warn("Unable to refresh JWT access token: ".concat(e));
2541
2600
  });
2542
- }, function (_wasThrown, _result) {
2601
+ }, function (_wasThrown, _result3) {
2543
2602
  session.accessTokenRefreshHandle = window.setTimeout(function () {
2544
- _this6.refreshAccessToken(session).then(function () {}, function (e) {
2545
- return ConsoleUtils.error("Unexpected error when refreshing access token: ".concat(e));
2603
+ _this6.refreshAccessToken(session).then(function () {},
2604
+ // Should not occur, as this method shouldn't throw errors.
2605
+ function (e) {
2606
+ return ConsoleUtils.error("Unexpected error when refreshing JWT access token: ".concat(e));
2546
2607
  });
2547
2608
  }, timeout * 1000);
2548
- return AuthManagerBrowser_rethrow(_wasThrown, _result);
2609
+ return AuthManagerBrowser_rethrow(_wasThrown, _result3);
2549
2610
  }));
2550
2611
  })));
2551
2612
  } catch (e) {
2552
2613
  return Promise.reject(e);
2553
2614
  }
2554
2615
  }
2616
+ }, {
2617
+ key: "setServiceWorkerConfig",
2618
+ value: function setServiceWorkerConfig(session, config) {
2619
+ var _a;
2620
+ var message = {
2621
+ type: "SET_CONFIG",
2622
+ config: config
2623
+ };
2624
+ (_a = session.authServiceWorker) === null || _a === void 0 ? void 0 : _a.postMessage(message);
2625
+ }
2555
2626
  }, {
2556
2627
  key: "getAccessTokenUrl",
2557
2628
  value: function getAccessTokenUrl(params) {
2629
+ return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId);
2630
+ }
2631
+ }, {
2632
+ key: "getCdnUrl",
2633
+ value: function getCdnUrl(params) {
2558
2634
  var _a;
2559
- var cdnUrl = BytescaleApiClientConfigUtils.getCdnUrl((_a = params.options) !== null && _a !== void 0 ? _a : {});
2560
- return "".concat(cdnUrl, "/api/v1/access_tokens/").concat(params.accountId);
2635
+ return BytescaleApiClientConfigUtils.getCdnUrl((_a = params.options) !== null && _a !== void 0 ? _a : {});
2561
2636
  }
2562
2637
  }, {
2563
2638
  key: "deleteAccessToken",
@@ -1,5 +1,6 @@
1
1
  export declare class ConsoleUtils {
2
- static error(message: string): void;
2
+ static debug(message: string): void;
3
3
  static warn(message: string): void;
4
+ static error(message: string): void;
4
5
  private static prefix;
5
6
  }
@@ -0,0 +1,2 @@
1
+ import { AuthSwConfigEntryDto } from "./AuthSwConfigEntryDto";
2
+ export declare type AuthSwConfigDto = AuthSwConfigEntryDto[];
@@ -0,0 +1,6 @@
1
+ import { AuthSwHeaderDto } from "./AuthSwHeaderDto";
2
+ export interface AuthSwConfigEntryDto {
3
+ expires: number | undefined;
4
+ headers: AuthSwHeaderDto[];
5
+ urlPrefix: string;
6
+ }
@@ -0,0 +1,4 @@
1
+ export interface AuthSwHeaderDto {
2
+ key: string;
3
+ value: string;
4
+ }
@@ -0,0 +1,5 @@
1
+ import { AuthSwConfigDto } from "./AuthSwConfigDto";
2
+ export interface AuthSwSetConfigDto {
3
+ config: AuthSwConfigDto;
4
+ type: "SET_CONFIG";
5
+ }
@@ -18,6 +18,48 @@ export interface BeginAuthSessionParams {
18
18
  * Optional configuration.
19
19
  */
20
20
  options?: Pick<BytescaleApiClientConfig, "fetchApi" | "cdnUrl">;
21
+ /**
22
+ * The Bytescale Auth Service Worker enables JWT-based auth for browsers that block third-party cookies.
23
+ *
24
+ * You must set this field if you need to support browsers that block third-party cookies (like Safari).
25
+ *
26
+ * This feature works by running a "service worker" in the background that adds "Authorization" and "Authorization-Token"
27
+ * request headers to HTTP requests made to the Bytescale CDN. This allows the Bytescale CDN to authorize requests
28
+ * to private files using JWTs issued by your application. Historically, these requests have been authorized using
29
+ * JWT cookies (i.e. JWTs sent to the Bytescale CDN via the "Cookies" header). However, modern browsers are starting
30
+ * to block these cookies, meaning "Authorization" request headers must be used instead. Authorization headers can
31
+ * only be added to requests originating from page elements like "<img>" elements through the use of service workers.
32
+ *
33
+ * Usage:
34
+ *
35
+ * 1. Create a JavaScript file that contains the following line:
36
+ *
37
+ * importScripts("https://js.bytescale.com/auth-sw/v1");
38
+ *
39
+ * 2. Host this JavaScript file from your website:
40
+ *
41
+ * 2a. It MUST be under the ROOT directory of your website.
42
+ * (e.g. "/bytescale-auth-sw.js")
43
+ *
44
+ * 2b. It MUST be on the SAME DOMAIN as your website.
45
+ * (e.g. "www.example.com" and not "assets.example.com")
46
+ *
47
+ * 3. Specify the absolute path to your JavaScript file in the 'beginAuthSession' call.
48
+ * (e.g. { ..., serviceWorkerScript: "/bytescale-auth-sw.js" })
49
+ *
50
+ * Examples:
51
+ *
52
+ * - CORRECT: "/bytescale-auth-sw.js"
53
+ * - INCORRECT: "bytescale-auth-sw.js"
54
+ * - INCORRECT: "/scripts/bytescale-auth-sw.js"
55
+ * - INCORRECT: "https://example.com/bytescale-auth-sw.js"
56
+ *
57
+ * Why does the script need to be hosted on the website's domain, under the root directory?:
58
+ *
59
+ * Service workers can only interact with events raised by pages at the same level or below them, hence why your
60
+ * script must be hosted on your website's domain in the root directory.
61
+ */
62
+ serviceWorkerScript: string | undefined;
21
63
  }
22
64
  export interface AuthManagerInterface {
23
65
  /**
@@ -2,6 +2,7 @@ import { BeginAuthSessionParams } from "./AuthManagerInterface";
2
2
  export interface AuthSession {
3
3
  accessToken: string | undefined;
4
4
  accessTokenRefreshHandle: number | undefined;
5
+ authServiceWorker: ServiceWorker | undefined;
5
6
  isActive: boolean;
6
7
  params: BeginAuthSessionParams;
7
8
  }
@@ -12,8 +12,18 @@ declare class AuthManagerImpl implements AuthManagerInterface {
12
12
  isAuthSessionActive(): boolean;
13
13
  beginAuthSession(params: BeginAuthSessionParams): Promise<void>;
14
14
  endAuthSession(): Promise<void>;
15
+ /**
16
+ * Idempotent.
17
+ *
18
+ * Only returns once the service worker has been activated.
19
+ *
20
+ * We don't need to unregister it: we just need to clear the config when auth ends.
21
+ */
22
+ private registerAuthServiceWorker;
15
23
  private refreshAccessToken;
24
+ private setServiceWorkerConfig;
16
25
  private getAccessTokenUrl;
26
+ private getCdnUrl;
17
27
  private deleteAccessToken;
18
28
  private setAccessToken;
19
29
  private getAccessToken;
@@ -24,11 +24,11 @@ export interface BytescaleApiClientConfig {
24
24
  */
25
25
  apiKey: string;
26
26
  /**
27
- * The base URL of the Bytescale API.
27
+ * The base URL of the Bytescale API. (Excludes trailing "/".)
28
28
  */
29
29
  apiUrl?: string;
30
30
  /**
31
- * The base URL of the Bytescale CDN.
31
+ * The base URL of the Bytescale CDN. (Excludes trailing "/".)
32
32
  */
33
33
  cdnUrl?: string;
34
34
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.10.0",
3
+ "version": "3.12.0",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -67,7 +67,9 @@
67
67
  "publish:executeIfReleaseCommit": "bash -c 'COMMIT=$(git log -1 --pretty=%B) && [ \"${COMMIT:0:8}\" != \"Release \" ] || npm run publish:execute'",
68
68
  "publish:execute": "npm run publish:cdn && npm publish && npm run publish:createGitHubRelease",
69
69
  "publish:createGitHubRelease": "gh release create v$(node -p \"require('./package.json').version\")",
70
- "publish:cdn": "npm run prepack:cdn && aws s3 cp --recursive --content-type application/javascript dist/ s3://upload-js-releases/sdk/ && aws cloudfront create-invalidation --distribution-id E250290WAJ43YY --paths '/sdk/*'"
70
+ "publish:cdn": "npm run publish:cdn:sdk && npm run publish:cdn:authSw",
71
+ "publish:cdn:sdk": "npm run prepack:cdn && aws s3 cp --recursive --content-type text/javascript dist/ s3://upload-js-releases/sdk/ && aws cloudfront create-invalidation --distribution-id E250290WAJ43YY --paths '/sdk/*'",
72
+ "publish:cdn:authSw": "aws s3 cp --content-type text/javascript src/index.auth-sw.js s3://upload-js-releases/auth-sw/v1 && aws cloudfront create-invalidation --distribution-id E250290WAJ43YY --paths '/auth-sw/*'"
71
73
  },
72
74
  "husky": {
73
75
  "hooks": {