@shopsbuilder/auth-sdk 1.2.10 → 1.2.12

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.
@@ -20,6 +20,7 @@ declare class SaleorAuthClient {
20
20
  private tokenRefreshPromise;
21
21
  private onAuthRefresh?;
22
22
  private saleorApiUrl;
23
+ private storageKeyPrefix;
23
24
  /**
24
25
  * Persistent storage (for refresh token)
25
26
  */
@@ -20,6 +20,7 @@ declare class SaleorAuthClient {
20
20
  private tokenRefreshPromise;
21
21
  private onAuthRefresh?;
22
22
  private saleorApiUrl;
23
+ private storageKeyPrefix;
23
24
  /**
24
25
  * Persistent storage (for refresh token)
25
26
  */
@@ -272,6 +272,7 @@ var SaleorAuthClient = class {
272
272
  tokenRefreshPromise = null;
273
273
  onAuthRefresh;
274
274
  saleorApiUrl;
275
+ storageKeyPrefix;
275
276
  /**
276
277
  * Persistent storage (for refresh token)
277
278
  */
@@ -307,7 +308,8 @@ var SaleorAuthClient = class {
307
308
  }
308
309
  this.onAuthRefresh = onAuthRefresh;
309
310
  this.saleorApiUrl = saleorApiUrl;
310
- const keyPrefix = storageKeyPrefix ?? saleorApiUrl;
311
+ this.storageKeyPrefix = storageKeyPrefix ?? saleorApiUrl;
312
+ const keyPrefix = this.storageKeyPrefix;
311
313
  const refreshTokenRepo = refreshTokenStorage ?? (typeof window !== "undefined" ? window.localStorage : void 0);
312
314
  this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo, keyPrefix) : null;
313
315
  const accessTokenRepo = accessTokenStorage ?? getInMemoryAccessTokenStorage();
@@ -321,7 +323,7 @@ var SaleorAuthClient = class {
321
323
  if (!token) {
322
324
  return fetch(input, init);
323
325
  }
324
- const headers = init?.headers || {};
326
+ const headers = new Headers(init?.headers);
325
327
  const getURL = (input2) => {
326
328
  if (typeof input2 === "string") {
327
329
  return input2;
@@ -332,7 +334,8 @@ var SaleorAuthClient = class {
332
334
  }
333
335
  };
334
336
  const iss = getTokenIss(token);
335
- const issuerAndDomainMatch = getURL(input) === iss;
337
+ const requestUrl = getURL(input);
338
+ const issuerAndDomainMatch = requestUrl === iss || this.storageKeyPrefix === iss;
336
339
  const shouldAddAuthorizationHeader = issuerAndDomainMatch || additionalParams?.allowPassingTokenToThirdPartyDomains;
337
340
  if (!issuerAndDomainMatch) {
338
341
  if (shouldAddAuthorizationHeader) {
@@ -345,10 +348,10 @@ var SaleorAuthClient = class {
345
348
  );
346
349
  }
347
350
  }
348
- return fetch(input, {
349
- ...init,
350
- headers: shouldAddAuthorizationHeader ? { ...headers, Authorization: `Bearer ${token}` } : headers
351
- });
351
+ if (shouldAddAuthorizationHeader) {
352
+ headers.set("Authorization", `Bearer ${token}`);
353
+ }
354
+ return fetch(input, { ...init, headers });
352
355
  };
353
356
  handleRequestWithTokenRefresh = async (input, requestInit, additionalParams) => {
354
357
  const refreshToken = this.refreshTokenStorage?.getRefreshToken();
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SaleorAuthClient,
3
3
  createSaleorAuthClient
4
- } from "./chunk-3UGMWVQN.mjs";
4
+ } from "./chunk-E4ERLV5W.mjs";
5
5
  import "./chunk-B326YIV6.mjs";
6
6
  import "./chunk-263DHBMK.mjs";
7
7
  import "./chunk-UDLCOX6B.mjs";
@@ -25,6 +25,7 @@ var SaleorAuthClient = class {
25
25
  tokenRefreshPromise = null;
26
26
  onAuthRefresh;
27
27
  saleorApiUrl;
28
+ storageKeyPrefix;
28
29
  /**
29
30
  * Persistent storage (for refresh token)
30
31
  */
@@ -60,7 +61,8 @@ var SaleorAuthClient = class {
60
61
  }
61
62
  this.onAuthRefresh = onAuthRefresh;
62
63
  this.saleorApiUrl = saleorApiUrl;
63
- const keyPrefix = storageKeyPrefix ?? saleorApiUrl;
64
+ this.storageKeyPrefix = storageKeyPrefix ?? saleorApiUrl;
65
+ const keyPrefix = this.storageKeyPrefix;
64
66
  const refreshTokenRepo = refreshTokenStorage ?? (typeof window !== "undefined" ? window.localStorage : void 0);
65
67
  this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo, keyPrefix) : null;
66
68
  const accessTokenRepo = accessTokenStorage ?? getInMemoryAccessTokenStorage();
@@ -74,7 +76,7 @@ var SaleorAuthClient = class {
74
76
  if (!token) {
75
77
  return fetch(input, init);
76
78
  }
77
- const headers = init?.headers || {};
79
+ const headers = new Headers(init?.headers);
78
80
  const getURL = (input2) => {
79
81
  if (typeof input2 === "string") {
80
82
  return input2;
@@ -85,7 +87,8 @@ var SaleorAuthClient = class {
85
87
  }
86
88
  };
87
89
  const iss = getTokenIss(token);
88
- const issuerAndDomainMatch = getURL(input) === iss;
90
+ const requestUrl = getURL(input);
91
+ const issuerAndDomainMatch = requestUrl === iss || this.storageKeyPrefix === iss;
89
92
  const shouldAddAuthorizationHeader = issuerAndDomainMatch || additionalParams?.allowPassingTokenToThirdPartyDomains;
90
93
  if (!issuerAndDomainMatch) {
91
94
  if (shouldAddAuthorizationHeader) {
@@ -98,10 +101,10 @@ var SaleorAuthClient = class {
98
101
  );
99
102
  }
100
103
  }
101
- return fetch(input, {
102
- ...init,
103
- headers: shouldAddAuthorizationHeader ? { ...headers, Authorization: `Bearer ${token}` } : headers
104
- });
104
+ if (shouldAddAuthorizationHeader) {
105
+ headers.set("Authorization", `Bearer ${token}`);
106
+ }
107
+ return fetch(input, { ...init, headers });
105
108
  };
106
109
  handleRequestWithTokenRefresh = async (input, requestInit, additionalParams) => {
107
110
  const refreshToken = this.refreshTokenStorage?.getRefreshToken();
package/dist/index.js CHANGED
@@ -275,6 +275,7 @@ var SaleorAuthClient = class {
275
275
  tokenRefreshPromise = null;
276
276
  onAuthRefresh;
277
277
  saleorApiUrl;
278
+ storageKeyPrefix;
278
279
  /**
279
280
  * Persistent storage (for refresh token)
280
281
  */
@@ -310,7 +311,8 @@ var SaleorAuthClient = class {
310
311
  }
311
312
  this.onAuthRefresh = onAuthRefresh;
312
313
  this.saleorApiUrl = saleorApiUrl;
313
- const keyPrefix = storageKeyPrefix ?? saleorApiUrl;
314
+ this.storageKeyPrefix = storageKeyPrefix ?? saleorApiUrl;
315
+ const keyPrefix = this.storageKeyPrefix;
314
316
  const refreshTokenRepo = refreshTokenStorage ?? (typeof window !== "undefined" ? window.localStorage : void 0);
315
317
  this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo, keyPrefix) : null;
316
318
  const accessTokenRepo = accessTokenStorage ?? getInMemoryAccessTokenStorage();
@@ -324,7 +326,7 @@ var SaleorAuthClient = class {
324
326
  if (!token) {
325
327
  return fetch(input, init);
326
328
  }
327
- const headers = init?.headers || {};
329
+ const headers = new Headers(init?.headers);
328
330
  const getURL = (input2) => {
329
331
  if (typeof input2 === "string") {
330
332
  return input2;
@@ -335,7 +337,8 @@ var SaleorAuthClient = class {
335
337
  }
336
338
  };
337
339
  const iss = getTokenIss(token);
338
- const issuerAndDomainMatch = getURL(input) === iss;
340
+ const requestUrl = getURL(input);
341
+ const issuerAndDomainMatch = requestUrl === iss || this.storageKeyPrefix === iss;
339
342
  const shouldAddAuthorizationHeader = issuerAndDomainMatch || additionalParams?.allowPassingTokenToThirdPartyDomains;
340
343
  if (!issuerAndDomainMatch) {
341
344
  if (shouldAddAuthorizationHeader) {
@@ -348,10 +351,10 @@ var SaleorAuthClient = class {
348
351
  );
349
352
  }
350
353
  }
351
- return fetch(input, {
352
- ...init,
353
- headers: shouldAddAuthorizationHeader ? { ...headers, Authorization: `Bearer ${token}` } : headers
354
- });
354
+ if (shouldAddAuthorizationHeader) {
355
+ headers.set("Authorization", `Bearer ${token}`);
356
+ }
357
+ return fetch(input, { ...init, headers });
355
358
  };
356
359
  handleRequestWithTokenRefresh = async (input, requestInit, additionalParams) => {
357
360
  const refreshToken = this.refreshTokenStorage?.getRefreshToken();
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SaleorAuthClient,
3
3
  createSaleorAuthClient
4
- } from "./chunk-3UGMWVQN.mjs";
4
+ } from "./chunk-E4ERLV5W.mjs";
5
5
  import "./chunk-B326YIV6.mjs";
6
6
  import "./chunk-263DHBMK.mjs";
7
7
  import {
@@ -2,7 +2,7 @@ import {
2
2
  SaleorAuthProvider
3
3
  } from "../chunk-74GMXOK4.mjs";
4
4
  import "../chunk-NAQNA6DI.mjs";
5
- import "../chunk-3UGMWVQN.mjs";
5
+ import "../chunk-E4ERLV5W.mjs";
6
6
  import "../chunk-B326YIV6.mjs";
7
7
  import "../chunk-263DHBMK.mjs";
8
8
  import "../chunk-UDLCOX6B.mjs";
@@ -3,7 +3,7 @@ import {
3
3
  createSafeContext,
4
4
  useSaleorAuthContext
5
5
  } from "../chunk-NAQNA6DI.mjs";
6
- import "../chunk-3UGMWVQN.mjs";
6
+ import "../chunk-E4ERLV5W.mjs";
7
7
  import "../chunk-B326YIV6.mjs";
8
8
  import "../chunk-263DHBMK.mjs";
9
9
  import "../chunk-UDLCOX6B.mjs";
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  useSaleorExternalAuth
14
14
  } from "../chunk-Q3UFWDCC.mjs";
15
- import "../chunk-3UGMWVQN.mjs";
15
+ import "../chunk-E4ERLV5W.mjs";
16
16
  import "../chunk-B326YIV6.mjs";
17
17
  import "../chunk-263DHBMK.mjs";
18
18
  import "../chunk-T35JF4IS.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopsbuilder/auth-sdk",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "description": "Auth SDK for Saleor",
5
5
  "sideEffects": false,
6
6
  "files": ["dist/", "README.md"],