@bytescale/sdk 3.16.0 → 3.17.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.
@@ -2597,7 +2597,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2597
2597
  _session$params = session.params;
2598
2598
  return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
2599
2599
  return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
2600
- return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt), function (setTokenResult) {
2600
+ // We don't use cookie-based auth if the browser supports service worker-based auth, as using both will cause
2601
+ // confusion for us in the future (i.e. we may question "do we need to use both together? was there a reason?").
2602
+ // Also: if the user has omitted "allowedOrigins" from their JWT, then service worker-based auth is more secure
2603
+ // than cookie-based auth, which is another reason to prevent these cookies from being set unless required.
2604
+ var setCookie = !_this6.isUsingServiceWorker(session);
2605
+ return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt, setCookie), function (setTokenResult) {
2601
2606
  _this6.setServiceWorkerConfig(session, [{
2602
2607
  headers: [{
2603
2608
  key: "Authorization",
@@ -2636,6 +2641,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2636
2641
  return Promise.reject(e);
2637
2642
  }
2638
2643
  }
2644
+ }, {
2645
+ key: "isUsingServiceWorker",
2646
+ value: function isUsingServiceWorker(session) {
2647
+ return session.authServiceWorker !== undefined;
2648
+ }
2639
2649
  }, {
2640
2650
  key: "setServiceWorkerConfig",
2641
2651
  value: function setServiceWorkerConfig(session, config) {
@@ -2648,8 +2658,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2648
2658
  }
2649
2659
  }, {
2650
2660
  key: "getAccessTokenUrl",
2651
- value: function getAccessTokenUrl(params) {
2652
- return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId);
2661
+ value: function getAccessTokenUrl(params, setCookie) {
2662
+ return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId, "?set-cookie=").concat(setCookie ? "true" : "false");
2653
2663
  }
2654
2664
  }, {
2655
2665
  key: "getCdnUrl",
@@ -2663,7 +2673,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2663
2673
  try {
2664
2674
  var _this8 = this;
2665
2675
  var _a;
2666
- return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params), {
2676
+ return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params, true), {
2667
2677
  method: "DELETE",
2668
2678
  credentials: "include",
2669
2679
  headers: {}
@@ -2677,14 +2687,14 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2677
2687
  }
2678
2688
  }, {
2679
2689
  key: "setAccessToken",
2680
- value: function setAccessToken(params, jwt) {
2690
+ value: function setAccessToken(params, jwt, setCookie) {
2681
2691
  try {
2682
2692
  var _this10 = this;
2683
2693
  var _a;
2684
2694
  var request = {
2685
2695
  accessToken: jwt
2686
2696
  };
2687
- return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params), {
2697
+ return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params, setCookie), {
2688
2698
  method: "PUT",
2689
2699
  credentials: "include",
2690
2700
  headers: AuthManagerBrowser_defineProperty({}, _this10.contentType, _this10.contentTypeJson),
@@ -2582,7 +2582,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2582
2582
  _session$params = session.params;
2583
2583
  return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
2584
2584
  return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
2585
- return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt), function (setTokenResult) {
2585
+ // We don't use cookie-based auth if the browser supports service worker-based auth, as using both will cause
2586
+ // confusion for us in the future (i.e. we may question "do we need to use both together? was there a reason?").
2587
+ // Also: if the user has omitted "allowedOrigins" from their JWT, then service worker-based auth is more secure
2588
+ // than cookie-based auth, which is another reason to prevent these cookies from being set unless required.
2589
+ var setCookie = !_this6.isUsingServiceWorker(session);
2590
+ return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt, setCookie), function (setTokenResult) {
2586
2591
  _this6.setServiceWorkerConfig(session, [{
2587
2592
  headers: [{
2588
2593
  key: "Authorization",
@@ -2621,6 +2626,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2621
2626
  return Promise.reject(e);
2622
2627
  }
2623
2628
  }
2629
+ }, {
2630
+ key: "isUsingServiceWorker",
2631
+ value: function isUsingServiceWorker(session) {
2632
+ return session.authServiceWorker !== undefined;
2633
+ }
2624
2634
  }, {
2625
2635
  key: "setServiceWorkerConfig",
2626
2636
  value: function setServiceWorkerConfig(session, config) {
@@ -2633,8 +2643,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2633
2643
  }
2634
2644
  }, {
2635
2645
  key: "getAccessTokenUrl",
2636
- value: function getAccessTokenUrl(params) {
2637
- return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId);
2646
+ value: function getAccessTokenUrl(params, setCookie) {
2647
+ return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId, "?set-cookie=").concat(setCookie ? "true" : "false");
2638
2648
  }
2639
2649
  }, {
2640
2650
  key: "getCdnUrl",
@@ -2648,7 +2658,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2648
2658
  try {
2649
2659
  var _this8 = this;
2650
2660
  var _a;
2651
- return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params), {
2661
+ return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params, true), {
2652
2662
  method: "DELETE",
2653
2663
  credentials: "include",
2654
2664
  headers: {}
@@ -2662,14 +2672,14 @@ var AuthManagerImpl = /*#__PURE__*/function () {
2662
2672
  }
2663
2673
  }, {
2664
2674
  key: "setAccessToken",
2665
- value: function setAccessToken(params, jwt) {
2675
+ value: function setAccessToken(params, jwt, setCookie) {
2666
2676
  try {
2667
2677
  var _this10 = this;
2668
2678
  var _a;
2669
2679
  var request = {
2670
2680
  accessToken: jwt
2671
2681
  };
2672
- return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params), {
2682
+ return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params, setCookie), {
2673
2683
  method: "PUT",
2674
2684
  credentials: "include",
2675
2685
  headers: AuthManagerBrowser_defineProperty({}, _this10.contentType, _this10.contentTypeJson),
@@ -21,6 +21,7 @@ declare class AuthManagerImpl implements AuthManagerInterface {
21
21
  */
22
22
  private registerAuthServiceWorker;
23
23
  private refreshAccessToken;
24
+ private isUsingServiceWorker;
24
25
  private setServiceWorkerConfig;
25
26
  private getAccessTokenUrl;
26
27
  private getCdnUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",