@shopsbuilder/auth-sdk 1.2.9 → 1.2.11
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.
- package/dist/SaleorAuthClient.d.mts +9 -1
- package/dist/SaleorAuthClient.d.ts +9 -1
- package/dist/SaleorAuthClient.js +8 -3
- package/dist/SaleorAuthClient.mjs +1 -1
- package/dist/{chunk-GFXR244N.mjs → chunk-CKQ223DC.mjs} +8 -3
- package/dist/{chunk-WJVMUY3P.mjs → chunk-FY2QDW7J.mjs} +5 -4
- package/dist/index.js +8 -3
- package/dist/index.mjs +1 -1
- package/dist/react/SaleorAuthProvider.mjs +1 -1
- package/dist/react/context.mjs +1 -1
- package/dist/react/index.js +5 -4
- package/dist/react/index.mjs +2 -2
- package/dist/react/useAuthChange.d.mts +2 -1
- package/dist/react/useAuthChange.d.ts +2 -1
- package/dist/react/useAuthChange.js +5 -4
- package/dist/react/useAuthChange.mjs +1 -1
- package/package.json +1 -1
|
@@ -3,6 +3,13 @@ import { StorageRepository, FetchWithAdditionalParams, PasswordResetVariables, P
|
|
|
3
3
|
interface SaleorAuthClientProps {
|
|
4
4
|
onAuthRefresh?: (isAuthenticating: boolean) => void;
|
|
5
5
|
saleorApiUrl: string;
|
|
6
|
+
/**
|
|
7
|
+
* Override the key prefix used for storage/cookies.
|
|
8
|
+
* Defaults to `saleorApiUrl`. Useful when the server uses a different
|
|
9
|
+
* internal URL (e.g. `http://api:8000`) while the client uses the public
|
|
10
|
+
* URL — pass the client URL here so cookie names match.
|
|
11
|
+
*/
|
|
12
|
+
storageKeyPrefix?: string;
|
|
6
13
|
refreshTokenStorage?: StorageRepository;
|
|
7
14
|
accessTokenStorage?: StorageRepository;
|
|
8
15
|
tokenGracePeriod?: number;
|
|
@@ -13,6 +20,7 @@ declare class SaleorAuthClient {
|
|
|
13
20
|
private tokenRefreshPromise;
|
|
14
21
|
private onAuthRefresh?;
|
|
15
22
|
private saleorApiUrl;
|
|
23
|
+
private storageKeyPrefix;
|
|
16
24
|
/**
|
|
17
25
|
* Persistent storage (for refresh token)
|
|
18
26
|
*/
|
|
@@ -33,7 +41,7 @@ declare class SaleorAuthClient {
|
|
|
33
41
|
* }, [])
|
|
34
42
|
* ```
|
|
35
43
|
*/
|
|
36
|
-
constructor({ saleorApiUrl, refreshTokenStorage, accessTokenStorage, onAuthRefresh, tokenGracePeriod, defaultRequestInit, }: SaleorAuthClientProps);
|
|
44
|
+
constructor({ saleorApiUrl, storageKeyPrefix, refreshTokenStorage, accessTokenStorage, onAuthRefresh, tokenGracePeriod, defaultRequestInit, }: SaleorAuthClientProps);
|
|
37
45
|
cleanup: () => void;
|
|
38
46
|
private runAuthorizedRequest;
|
|
39
47
|
private handleRequestWithTokenRefresh;
|
|
@@ -3,6 +3,13 @@ import { StorageRepository, FetchWithAdditionalParams, PasswordResetVariables, P
|
|
|
3
3
|
interface SaleorAuthClientProps {
|
|
4
4
|
onAuthRefresh?: (isAuthenticating: boolean) => void;
|
|
5
5
|
saleorApiUrl: string;
|
|
6
|
+
/**
|
|
7
|
+
* Override the key prefix used for storage/cookies.
|
|
8
|
+
* Defaults to `saleorApiUrl`. Useful when the server uses a different
|
|
9
|
+
* internal URL (e.g. `http://api:8000`) while the client uses the public
|
|
10
|
+
* URL — pass the client URL here so cookie names match.
|
|
11
|
+
*/
|
|
12
|
+
storageKeyPrefix?: string;
|
|
6
13
|
refreshTokenStorage?: StorageRepository;
|
|
7
14
|
accessTokenStorage?: StorageRepository;
|
|
8
15
|
tokenGracePeriod?: number;
|
|
@@ -13,6 +20,7 @@ declare class SaleorAuthClient {
|
|
|
13
20
|
private tokenRefreshPromise;
|
|
14
21
|
private onAuthRefresh?;
|
|
15
22
|
private saleorApiUrl;
|
|
23
|
+
private storageKeyPrefix;
|
|
16
24
|
/**
|
|
17
25
|
* Persistent storage (for refresh token)
|
|
18
26
|
*/
|
|
@@ -33,7 +41,7 @@ declare class SaleorAuthClient {
|
|
|
33
41
|
* }, [])
|
|
34
42
|
* ```
|
|
35
43
|
*/
|
|
36
|
-
constructor({ saleorApiUrl, refreshTokenStorage, accessTokenStorage, onAuthRefresh, tokenGracePeriod, defaultRequestInit, }: SaleorAuthClientProps);
|
|
44
|
+
constructor({ saleorApiUrl, storageKeyPrefix, refreshTokenStorage, accessTokenStorage, onAuthRefresh, tokenGracePeriod, defaultRequestInit, }: SaleorAuthClientProps);
|
|
37
45
|
cleanup: () => void;
|
|
38
46
|
private runAuthorizedRequest;
|
|
39
47
|
private handleRequestWithTokenRefresh;
|
package/dist/SaleorAuthClient.js
CHANGED
|
@@ -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
|
*/
|
|
@@ -294,6 +295,7 @@ var SaleorAuthClient = class {
|
|
|
294
295
|
*/
|
|
295
296
|
constructor({
|
|
296
297
|
saleorApiUrl,
|
|
298
|
+
storageKeyPrefix,
|
|
297
299
|
refreshTokenStorage,
|
|
298
300
|
accessTokenStorage,
|
|
299
301
|
onAuthRefresh,
|
|
@@ -306,10 +308,12 @@ var SaleorAuthClient = class {
|
|
|
306
308
|
}
|
|
307
309
|
this.onAuthRefresh = onAuthRefresh;
|
|
308
310
|
this.saleorApiUrl = saleorApiUrl;
|
|
311
|
+
this.storageKeyPrefix = storageKeyPrefix ?? saleorApiUrl;
|
|
312
|
+
const keyPrefix = this.storageKeyPrefix;
|
|
309
313
|
const refreshTokenRepo = refreshTokenStorage ?? (typeof window !== "undefined" ? window.localStorage : void 0);
|
|
310
|
-
this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo,
|
|
314
|
+
this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo, keyPrefix) : null;
|
|
311
315
|
const accessTokenRepo = accessTokenStorage ?? getInMemoryAccessTokenStorage();
|
|
312
|
-
this.accessTokenStorage = new SaleorAccessTokenStorageHandler(accessTokenRepo,
|
|
316
|
+
this.accessTokenStorage = new SaleorAccessTokenStorageHandler(accessTokenRepo, keyPrefix);
|
|
313
317
|
}
|
|
314
318
|
cleanup = () => {
|
|
315
319
|
this.refreshTokenStorage?.cleanup();
|
|
@@ -330,7 +334,8 @@ var SaleorAuthClient = class {
|
|
|
330
334
|
}
|
|
331
335
|
};
|
|
332
336
|
const iss = getTokenIss(token);
|
|
333
|
-
const
|
|
337
|
+
const requestUrl = getURL(input);
|
|
338
|
+
const issuerAndDomainMatch = requestUrl === iss || this.storageKeyPrefix === iss;
|
|
334
339
|
const shouldAddAuthorizationHeader = issuerAndDomainMatch || additionalParams?.allowPassingTokenToThirdPartyDomains;
|
|
335
340
|
if (!issuerAndDomainMatch) {
|
|
336
341
|
if (shouldAddAuthorizationHeader) {
|
|
@@ -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
|
*/
|
|
@@ -47,6 +48,7 @@ var SaleorAuthClient = class {
|
|
|
47
48
|
*/
|
|
48
49
|
constructor({
|
|
49
50
|
saleorApiUrl,
|
|
51
|
+
storageKeyPrefix,
|
|
50
52
|
refreshTokenStorage,
|
|
51
53
|
accessTokenStorage,
|
|
52
54
|
onAuthRefresh,
|
|
@@ -59,10 +61,12 @@ var SaleorAuthClient = class {
|
|
|
59
61
|
}
|
|
60
62
|
this.onAuthRefresh = onAuthRefresh;
|
|
61
63
|
this.saleorApiUrl = saleorApiUrl;
|
|
64
|
+
this.storageKeyPrefix = storageKeyPrefix ?? saleorApiUrl;
|
|
65
|
+
const keyPrefix = this.storageKeyPrefix;
|
|
62
66
|
const refreshTokenRepo = refreshTokenStorage ?? (typeof window !== "undefined" ? window.localStorage : void 0);
|
|
63
|
-
this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo,
|
|
67
|
+
this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo, keyPrefix) : null;
|
|
64
68
|
const accessTokenRepo = accessTokenStorage ?? getInMemoryAccessTokenStorage();
|
|
65
|
-
this.accessTokenStorage = new SaleorAccessTokenStorageHandler(accessTokenRepo,
|
|
69
|
+
this.accessTokenStorage = new SaleorAccessTokenStorageHandler(accessTokenRepo, keyPrefix);
|
|
66
70
|
}
|
|
67
71
|
cleanup = () => {
|
|
68
72
|
this.refreshTokenStorage?.cleanup();
|
|
@@ -83,7 +87,8 @@ var SaleorAuthClient = class {
|
|
|
83
87
|
}
|
|
84
88
|
};
|
|
85
89
|
const iss = getTokenIss(token);
|
|
86
|
-
const
|
|
90
|
+
const requestUrl = getURL(input);
|
|
91
|
+
const issuerAndDomainMatch = requestUrl === iss || this.storageKeyPrefix === iss;
|
|
87
92
|
const shouldAddAuthorizationHeader = issuerAndDomainMatch || additionalParams?.allowPassingTokenToThirdPartyDomains;
|
|
88
93
|
if (!issuerAndDomainMatch) {
|
|
89
94
|
if (shouldAddAuthorizationHeader) {
|
|
@@ -4,9 +4,10 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/react/useAuthChange.ts
|
|
6
6
|
import { useEffect } from "react";
|
|
7
|
-
var useAuthChange = ({ saleorApiUrl, onSignedOut, onSignedIn }) => {
|
|
7
|
+
var useAuthChange = ({ saleorApiUrl, storageKeyPrefix, onSignedOut, onSignedIn }) => {
|
|
8
|
+
const keyPrefix = storageKeyPrefix ?? saleorApiUrl;
|
|
8
9
|
const handleAuthChange = (event) => {
|
|
9
|
-
const isCustomAuthEvent = event?.type === getStorageAuthEventKey(
|
|
10
|
+
const isCustomAuthEvent = event?.type === getStorageAuthEventKey(keyPrefix);
|
|
10
11
|
if (!isCustomAuthEvent) {
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
@@ -21,9 +22,9 @@ var useAuthChange = ({ saleorApiUrl, onSignedOut, onSignedIn }) => {
|
|
|
21
22
|
if (typeof window === "undefined") {
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
|
-
window.addEventListener(getStorageAuthEventKey(
|
|
25
|
+
window.addEventListener(getStorageAuthEventKey(keyPrefix), handleAuthChange);
|
|
25
26
|
return () => {
|
|
26
|
-
window.removeEventListener(getStorageAuthEventKey(
|
|
27
|
+
window.removeEventListener(getStorageAuthEventKey(keyPrefix), handleAuthChange);
|
|
27
28
|
};
|
|
28
29
|
}, []);
|
|
29
30
|
};
|
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
|
*/
|
|
@@ -297,6 +298,7 @@ var SaleorAuthClient = class {
|
|
|
297
298
|
*/
|
|
298
299
|
constructor({
|
|
299
300
|
saleorApiUrl,
|
|
301
|
+
storageKeyPrefix,
|
|
300
302
|
refreshTokenStorage,
|
|
301
303
|
accessTokenStorage,
|
|
302
304
|
onAuthRefresh,
|
|
@@ -309,10 +311,12 @@ var SaleorAuthClient = class {
|
|
|
309
311
|
}
|
|
310
312
|
this.onAuthRefresh = onAuthRefresh;
|
|
311
313
|
this.saleorApiUrl = saleorApiUrl;
|
|
314
|
+
this.storageKeyPrefix = storageKeyPrefix ?? saleorApiUrl;
|
|
315
|
+
const keyPrefix = this.storageKeyPrefix;
|
|
312
316
|
const refreshTokenRepo = refreshTokenStorage ?? (typeof window !== "undefined" ? window.localStorage : void 0);
|
|
313
|
-
this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo,
|
|
317
|
+
this.refreshTokenStorage = refreshTokenRepo ? new SaleorRefreshTokenStorageHandler(refreshTokenRepo, keyPrefix) : null;
|
|
314
318
|
const accessTokenRepo = accessTokenStorage ?? getInMemoryAccessTokenStorage();
|
|
315
|
-
this.accessTokenStorage = new SaleorAccessTokenStorageHandler(accessTokenRepo,
|
|
319
|
+
this.accessTokenStorage = new SaleorAccessTokenStorageHandler(accessTokenRepo, keyPrefix);
|
|
316
320
|
}
|
|
317
321
|
cleanup = () => {
|
|
318
322
|
this.refreshTokenStorage?.cleanup();
|
|
@@ -333,7 +337,8 @@ var SaleorAuthClient = class {
|
|
|
333
337
|
}
|
|
334
338
|
};
|
|
335
339
|
const iss = getTokenIss(token);
|
|
336
|
-
const
|
|
340
|
+
const requestUrl = getURL(input);
|
|
341
|
+
const issuerAndDomainMatch = requestUrl === iss || this.storageKeyPrefix === iss;
|
|
337
342
|
const shouldAddAuthorizationHeader = issuerAndDomainMatch || additionalParams?.allowPassingTokenToThirdPartyDomains;
|
|
338
343
|
if (!issuerAndDomainMatch) {
|
|
339
344
|
if (shouldAddAuthorizationHeader) {
|
package/dist/index.mjs
CHANGED
package/dist/react/context.mjs
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -177,9 +177,10 @@ var SaleorAuthProvider = ({ children, client }) => {
|
|
|
177
177
|
|
|
178
178
|
// src/react/useAuthChange.ts
|
|
179
179
|
var import_react2 = require("react");
|
|
180
|
-
var useAuthChange = ({ saleorApiUrl, onSignedOut, onSignedIn }) => {
|
|
180
|
+
var useAuthChange = ({ saleorApiUrl, storageKeyPrefix, onSignedOut, onSignedIn }) => {
|
|
181
|
+
const keyPrefix = storageKeyPrefix ?? saleorApiUrl;
|
|
181
182
|
const handleAuthChange = (event) => {
|
|
182
|
-
const isCustomAuthEvent = event?.type === getStorageAuthEventKey(
|
|
183
|
+
const isCustomAuthEvent = event?.type === getStorageAuthEventKey(keyPrefix);
|
|
183
184
|
if (!isCustomAuthEvent) {
|
|
184
185
|
return;
|
|
185
186
|
}
|
|
@@ -194,9 +195,9 @@ var useAuthChange = ({ saleorApiUrl, onSignedOut, onSignedIn }) => {
|
|
|
194
195
|
if (typeof window === "undefined") {
|
|
195
196
|
return;
|
|
196
197
|
}
|
|
197
|
-
window.addEventListener(getStorageAuthEventKey(
|
|
198
|
+
window.addEventListener(getStorageAuthEventKey(keyPrefix), handleAuthChange);
|
|
198
199
|
return () => {
|
|
199
|
-
window.removeEventListener(getStorageAuthEventKey(
|
|
200
|
+
window.removeEventListener(getStorageAuthEventKey(keyPrefix), handleAuthChange);
|
|
200
201
|
};
|
|
201
202
|
}, []);
|
|
202
203
|
};
|
package/dist/react/index.mjs
CHANGED
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
} from "../chunk-NAQNA6DI.mjs";
|
|
9
9
|
import {
|
|
10
10
|
useAuthChange
|
|
11
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-FY2QDW7J.mjs";
|
|
12
12
|
import {
|
|
13
13
|
useSaleorExternalAuth
|
|
14
14
|
} from "../chunk-Q3UFWDCC.mjs";
|
|
15
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-CKQ223DC.mjs";
|
|
16
16
|
import "../chunk-B326YIV6.mjs";
|
|
17
17
|
import "../chunk-263DHBMK.mjs";
|
|
18
18
|
import "../chunk-T35JF4IS.mjs";
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
interface UseAuthChangeProps {
|
|
2
2
|
saleorApiUrl: string;
|
|
3
|
+
storageKeyPrefix?: string;
|
|
3
4
|
onSignedIn?: () => void;
|
|
4
5
|
onSignedOut?: () => void;
|
|
5
6
|
}
|
|
6
|
-
declare const useAuthChange: ({ saleorApiUrl, onSignedOut, onSignedIn }: UseAuthChangeProps) => void;
|
|
7
|
+
declare const useAuthChange: ({ saleorApiUrl, storageKeyPrefix, onSignedOut, onSignedIn }: UseAuthChangeProps) => void;
|
|
7
8
|
|
|
8
9
|
export { useAuthChange };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
interface UseAuthChangeProps {
|
|
2
2
|
saleorApiUrl: string;
|
|
3
|
+
storageKeyPrefix?: string;
|
|
3
4
|
onSignedIn?: () => void;
|
|
4
5
|
onSignedOut?: () => void;
|
|
5
6
|
}
|
|
6
|
-
declare const useAuthChange: ({ saleorApiUrl, onSignedOut, onSignedIn }: UseAuthChangeProps) => void;
|
|
7
|
+
declare const useAuthChange: ({ saleorApiUrl, storageKeyPrefix, onSignedOut, onSignedIn }: UseAuthChangeProps) => void;
|
|
7
8
|
|
|
8
9
|
export { useAuthChange };
|
|
@@ -29,9 +29,10 @@ var import_react = require("react");
|
|
|
29
29
|
var getStorageAuthEventKey = (prefix) => [prefix, "saleor_storage_auth_change"].filter(Boolean).join("+");
|
|
30
30
|
|
|
31
31
|
// src/react/useAuthChange.ts
|
|
32
|
-
var useAuthChange = ({ saleorApiUrl, onSignedOut, onSignedIn }) => {
|
|
32
|
+
var useAuthChange = ({ saleorApiUrl, storageKeyPrefix, onSignedOut, onSignedIn }) => {
|
|
33
|
+
const keyPrefix = storageKeyPrefix ?? saleorApiUrl;
|
|
33
34
|
const handleAuthChange = (event) => {
|
|
34
|
-
const isCustomAuthEvent = event?.type === getStorageAuthEventKey(
|
|
35
|
+
const isCustomAuthEvent = event?.type === getStorageAuthEventKey(keyPrefix);
|
|
35
36
|
if (!isCustomAuthEvent) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
@@ -46,9 +47,9 @@ var useAuthChange = ({ saleorApiUrl, onSignedOut, onSignedIn }) => {
|
|
|
46
47
|
if (typeof window === "undefined") {
|
|
47
48
|
return;
|
|
48
49
|
}
|
|
49
|
-
window.addEventListener(getStorageAuthEventKey(
|
|
50
|
+
window.addEventListener(getStorageAuthEventKey(keyPrefix), handleAuthChange);
|
|
50
51
|
return () => {
|
|
51
|
-
window.removeEventListener(getStorageAuthEventKey(
|
|
52
|
+
window.removeEventListener(getStorageAuthEventKey(keyPrefix), handleAuthChange);
|
|
52
53
|
};
|
|
53
54
|
}, []);
|
|
54
55
|
};
|