@shopsbuilder/auth-sdk 1.2.6 → 1.2.8
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/SaleorAccessTokenStorageHandler.d.mts +1 -0
- package/dist/SaleorAccessTokenStorageHandler.d.ts +1 -0
- package/dist/SaleorAccessTokenStorageHandler.js +7 -0
- package/dist/SaleorAccessTokenStorageHandler.mjs +1 -1
- package/dist/SaleorAuthClient.js +29 -9
- package/dist/SaleorAuthClient.mjs +2 -2
- package/dist/{chunk-BZFBMGPG.mjs → chunk-B326YIV6.mjs} +7 -0
- package/dist/{chunk-QFUROJ4G.mjs → chunk-X3MKOESH.mjs} +23 -10
- package/dist/index.js +29 -9
- package/dist/index.mjs +2 -2
- package/dist/react/SaleorAuthProvider.mjs +2 -2
- package/dist/react/context.mjs +2 -2
- package/dist/react/index.mjs +2 -2
- package/package.json +1 -1
|
@@ -4,6 +4,7 @@ declare const getAccessTokenKey: (prefix?: string) => string;
|
|
|
4
4
|
declare class SaleorAccessTokenStorageHandler {
|
|
5
5
|
private storage;
|
|
6
6
|
private prefix?;
|
|
7
|
+
private cachedToken;
|
|
7
8
|
constructor(storage: StorageRepository, prefix?: string | undefined);
|
|
8
9
|
getAccessToken: () => string | null;
|
|
9
10
|
setAccessToken: (token: string) => void;
|
|
@@ -4,6 +4,7 @@ declare const getAccessTokenKey: (prefix?: string) => string;
|
|
|
4
4
|
declare class SaleorAccessTokenStorageHandler {
|
|
5
5
|
private storage;
|
|
6
6
|
private prefix?;
|
|
7
|
+
private cachedToken;
|
|
7
8
|
constructor(storage: StorageRepository, prefix?: string | undefined);
|
|
8
9
|
getAccessToken: () => string | null;
|
|
9
10
|
setAccessToken: (token: string) => void;
|
|
@@ -30,15 +30,22 @@ var SaleorAccessTokenStorageHandler = class {
|
|
|
30
30
|
this.storage = storage;
|
|
31
31
|
this.prefix = prefix;
|
|
32
32
|
}
|
|
33
|
+
// In-memory cache so the token is available even when the storage
|
|
34
|
+
// backend is read-only (e.g. Next.js cookies during render).
|
|
35
|
+
cachedToken = null;
|
|
33
36
|
getAccessToken = () => {
|
|
37
|
+
if (this.cachedToken)
|
|
38
|
+
return this.cachedToken;
|
|
34
39
|
const key = getAccessTokenKey(this.prefix);
|
|
35
40
|
return this.storage.getItem(key);
|
|
36
41
|
};
|
|
37
42
|
setAccessToken = (token) => {
|
|
43
|
+
this.cachedToken = token;
|
|
38
44
|
const key = getAccessTokenKey(this.prefix);
|
|
39
45
|
return this.storage.setItem(key, token);
|
|
40
46
|
};
|
|
41
47
|
clearAuthStorage = () => {
|
|
48
|
+
this.cachedToken = null;
|
|
42
49
|
const key = getAccessTokenKey(this.prefix);
|
|
43
50
|
return this.storage.removeItem(key);
|
|
44
51
|
};
|
package/dist/SaleorAuthClient.js
CHANGED
|
@@ -239,15 +239,22 @@ var SaleorAccessTokenStorageHandler = class {
|
|
|
239
239
|
this.storage = storage;
|
|
240
240
|
this.prefix = prefix;
|
|
241
241
|
}
|
|
242
|
+
// In-memory cache so the token is available even when the storage
|
|
243
|
+
// backend is read-only (e.g. Next.js cookies during render).
|
|
244
|
+
cachedToken = null;
|
|
242
245
|
getAccessToken = () => {
|
|
246
|
+
if (this.cachedToken)
|
|
247
|
+
return this.cachedToken;
|
|
243
248
|
const key = getAccessTokenKey(this.prefix);
|
|
244
249
|
return this.storage.getItem(key);
|
|
245
250
|
};
|
|
246
251
|
setAccessToken = (token) => {
|
|
252
|
+
this.cachedToken = token;
|
|
247
253
|
const key = getAccessTokenKey(this.prefix);
|
|
248
254
|
return this.storage.setItem(key, token);
|
|
249
255
|
};
|
|
250
256
|
clearAuthStorage = () => {
|
|
257
|
+
this.cachedToken = null;
|
|
251
258
|
const key = getAccessTokenKey(this.prefix);
|
|
252
259
|
return this.storage.removeItem(key);
|
|
253
260
|
};
|
|
@@ -325,6 +332,14 @@ var SaleorAuthClient = class {
|
|
|
325
332
|
if (this.tokenRefreshPromise) {
|
|
326
333
|
const response = await this.tokenRefreshPromise;
|
|
327
334
|
const responseClone = response.clone();
|
|
335
|
+
const rawText = await response.clone().text();
|
|
336
|
+
console.log("[auth-sdk] Token refresh raw response:", JSON.stringify({
|
|
337
|
+
status: response.status,
|
|
338
|
+
statusText: response.statusText,
|
|
339
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
340
|
+
bodyLength: rawText.length,
|
|
341
|
+
body: rawText.slice(0, 500)
|
|
342
|
+
}));
|
|
328
343
|
let res;
|
|
329
344
|
try {
|
|
330
345
|
res = await responseClone.json();
|
|
@@ -356,7 +371,9 @@ var SaleorAuthClient = class {
|
|
|
356
371
|
this.tokenRefreshPromise = null;
|
|
357
372
|
return this.runAuthorizedRequest(input, requestInit, additionalParams);
|
|
358
373
|
}
|
|
359
|
-
const refreshHeaders = {
|
|
374
|
+
const refreshHeaders = {
|
|
375
|
+
"Content-Type": "application/json"
|
|
376
|
+
};
|
|
360
377
|
if (requestInit?.headers) {
|
|
361
378
|
const origHeaders = new Headers(requestInit.headers);
|
|
362
379
|
for (const [key, value] of origHeaders.entries()) {
|
|
@@ -365,18 +382,21 @@ var SaleorAuthClient = class {
|
|
|
365
382
|
}
|
|
366
383
|
}
|
|
367
384
|
}
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
385
|
+
const refreshBody = JSON.stringify({
|
|
386
|
+
query: TOKEN_REFRESH.toString(),
|
|
387
|
+
variables: { refreshToken }
|
|
371
388
|
});
|
|
372
389
|
console.log("[auth-sdk] Token refresh request:", JSON.stringify({
|
|
373
390
|
url: this.saleorApiUrl,
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
bodyPreview: refreshRequestData.body?.slice(0, 200)
|
|
391
|
+
headers: refreshHeaders,
|
|
392
|
+
bodyLength: refreshBody.length,
|
|
393
|
+
bodyPreview: refreshBody.slice(0, 200)
|
|
378
394
|
}));
|
|
379
|
-
this.tokenRefreshPromise = fetch(this.saleorApiUrl,
|
|
395
|
+
this.tokenRefreshPromise = fetch(this.saleorApiUrl, {
|
|
396
|
+
method: "POST",
|
|
397
|
+
headers: refreshHeaders,
|
|
398
|
+
body: refreshBody
|
|
399
|
+
});
|
|
380
400
|
return this.fetchWithAuth(input, requestInit, additionalParams);
|
|
381
401
|
};
|
|
382
402
|
handleSignIn = async (response) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SaleorAuthClient,
|
|
3
3
|
createSaleorAuthClient
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-X3MKOESH.mjs";
|
|
5
|
+
import "./chunk-B326YIV6.mjs";
|
|
6
6
|
import "./chunk-263DHBMK.mjs";
|
|
7
7
|
import "./chunk-UDLCOX6B.mjs";
|
|
8
8
|
import "./chunk-7JTFMRQS.mjs";
|
|
@@ -5,15 +5,22 @@ var SaleorAccessTokenStorageHandler = class {
|
|
|
5
5
|
this.storage = storage;
|
|
6
6
|
this.prefix = prefix;
|
|
7
7
|
}
|
|
8
|
+
// In-memory cache so the token is available even when the storage
|
|
9
|
+
// backend is read-only (e.g. Next.js cookies during render).
|
|
10
|
+
cachedToken = null;
|
|
8
11
|
getAccessToken = () => {
|
|
12
|
+
if (this.cachedToken)
|
|
13
|
+
return this.cachedToken;
|
|
9
14
|
const key = getAccessTokenKey(this.prefix);
|
|
10
15
|
return this.storage.getItem(key);
|
|
11
16
|
};
|
|
12
17
|
setAccessToken = (token) => {
|
|
18
|
+
this.cachedToken = token;
|
|
13
19
|
const key = getAccessTokenKey(this.prefix);
|
|
14
20
|
return this.storage.setItem(key, token);
|
|
15
21
|
};
|
|
16
22
|
clearAuthStorage = () => {
|
|
23
|
+
this.cachedToken = null;
|
|
17
24
|
const key = getAccessTokenKey(this.prefix);
|
|
18
25
|
return this.storage.removeItem(key);
|
|
19
26
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SaleorAccessTokenStorageHandler
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-B326YIV6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
SaleorRefreshTokenStorageHandler
|
|
6
6
|
} from "./chunk-263DHBMK.mjs";
|
|
@@ -88,6 +88,14 @@ var SaleorAuthClient = class {
|
|
|
88
88
|
if (this.tokenRefreshPromise) {
|
|
89
89
|
const response = await this.tokenRefreshPromise;
|
|
90
90
|
const responseClone = response.clone();
|
|
91
|
+
const rawText = await response.clone().text();
|
|
92
|
+
console.log("[auth-sdk] Token refresh raw response:", JSON.stringify({
|
|
93
|
+
status: response.status,
|
|
94
|
+
statusText: response.statusText,
|
|
95
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
96
|
+
bodyLength: rawText.length,
|
|
97
|
+
body: rawText.slice(0, 500)
|
|
98
|
+
}));
|
|
91
99
|
let res;
|
|
92
100
|
try {
|
|
93
101
|
res = await responseClone.json();
|
|
@@ -119,7 +127,9 @@ var SaleorAuthClient = class {
|
|
|
119
127
|
this.tokenRefreshPromise = null;
|
|
120
128
|
return this.runAuthorizedRequest(input, requestInit, additionalParams);
|
|
121
129
|
}
|
|
122
|
-
const refreshHeaders = {
|
|
130
|
+
const refreshHeaders = {
|
|
131
|
+
"Content-Type": "application/json"
|
|
132
|
+
};
|
|
123
133
|
if (requestInit?.headers) {
|
|
124
134
|
const origHeaders = new Headers(requestInit.headers);
|
|
125
135
|
for (const [key, value] of origHeaders.entries()) {
|
|
@@ -128,18 +138,21 @@ var SaleorAuthClient = class {
|
|
|
128
138
|
}
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
141
|
+
const refreshBody = JSON.stringify({
|
|
142
|
+
query: TOKEN_REFRESH.toString(),
|
|
143
|
+
variables: { refreshToken }
|
|
134
144
|
});
|
|
135
145
|
console.log("[auth-sdk] Token refresh request:", JSON.stringify({
|
|
136
146
|
url: this.saleorApiUrl,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
bodyPreview: refreshRequestData.body?.slice(0, 200)
|
|
147
|
+
headers: refreshHeaders,
|
|
148
|
+
bodyLength: refreshBody.length,
|
|
149
|
+
bodyPreview: refreshBody.slice(0, 200)
|
|
141
150
|
}));
|
|
142
|
-
this.tokenRefreshPromise = fetch(this.saleorApiUrl,
|
|
151
|
+
this.tokenRefreshPromise = fetch(this.saleorApiUrl, {
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers: refreshHeaders,
|
|
154
|
+
body: refreshBody
|
|
155
|
+
});
|
|
143
156
|
return this.fetchWithAuth(input, requestInit, additionalParams);
|
|
144
157
|
};
|
|
145
158
|
handleSignIn = async (response) => {
|
package/dist/index.js
CHANGED
|
@@ -242,15 +242,22 @@ var SaleorAccessTokenStorageHandler = class {
|
|
|
242
242
|
this.storage = storage;
|
|
243
243
|
this.prefix = prefix;
|
|
244
244
|
}
|
|
245
|
+
// In-memory cache so the token is available even when the storage
|
|
246
|
+
// backend is read-only (e.g. Next.js cookies during render).
|
|
247
|
+
cachedToken = null;
|
|
245
248
|
getAccessToken = () => {
|
|
249
|
+
if (this.cachedToken)
|
|
250
|
+
return this.cachedToken;
|
|
246
251
|
const key = getAccessTokenKey(this.prefix);
|
|
247
252
|
return this.storage.getItem(key);
|
|
248
253
|
};
|
|
249
254
|
setAccessToken = (token) => {
|
|
255
|
+
this.cachedToken = token;
|
|
250
256
|
const key = getAccessTokenKey(this.prefix);
|
|
251
257
|
return this.storage.setItem(key, token);
|
|
252
258
|
};
|
|
253
259
|
clearAuthStorage = () => {
|
|
260
|
+
this.cachedToken = null;
|
|
254
261
|
const key = getAccessTokenKey(this.prefix);
|
|
255
262
|
return this.storage.removeItem(key);
|
|
256
263
|
};
|
|
@@ -328,6 +335,14 @@ var SaleorAuthClient = class {
|
|
|
328
335
|
if (this.tokenRefreshPromise) {
|
|
329
336
|
const response = await this.tokenRefreshPromise;
|
|
330
337
|
const responseClone = response.clone();
|
|
338
|
+
const rawText = await response.clone().text();
|
|
339
|
+
console.log("[auth-sdk] Token refresh raw response:", JSON.stringify({
|
|
340
|
+
status: response.status,
|
|
341
|
+
statusText: response.statusText,
|
|
342
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
343
|
+
bodyLength: rawText.length,
|
|
344
|
+
body: rawText.slice(0, 500)
|
|
345
|
+
}));
|
|
331
346
|
let res;
|
|
332
347
|
try {
|
|
333
348
|
res = await responseClone.json();
|
|
@@ -359,7 +374,9 @@ var SaleorAuthClient = class {
|
|
|
359
374
|
this.tokenRefreshPromise = null;
|
|
360
375
|
return this.runAuthorizedRequest(input, requestInit, additionalParams);
|
|
361
376
|
}
|
|
362
|
-
const refreshHeaders = {
|
|
377
|
+
const refreshHeaders = {
|
|
378
|
+
"Content-Type": "application/json"
|
|
379
|
+
};
|
|
363
380
|
if (requestInit?.headers) {
|
|
364
381
|
const origHeaders = new Headers(requestInit.headers);
|
|
365
382
|
for (const [key, value] of origHeaders.entries()) {
|
|
@@ -368,18 +385,21 @@ var SaleorAuthClient = class {
|
|
|
368
385
|
}
|
|
369
386
|
}
|
|
370
387
|
}
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
388
|
+
const refreshBody = JSON.stringify({
|
|
389
|
+
query: TOKEN_REFRESH.toString(),
|
|
390
|
+
variables: { refreshToken }
|
|
374
391
|
});
|
|
375
392
|
console.log("[auth-sdk] Token refresh request:", JSON.stringify({
|
|
376
393
|
url: this.saleorApiUrl,
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
bodyPreview: refreshRequestData.body?.slice(0, 200)
|
|
394
|
+
headers: refreshHeaders,
|
|
395
|
+
bodyLength: refreshBody.length,
|
|
396
|
+
bodyPreview: refreshBody.slice(0, 200)
|
|
381
397
|
}));
|
|
382
|
-
this.tokenRefreshPromise = fetch(this.saleorApiUrl,
|
|
398
|
+
this.tokenRefreshPromise = fetch(this.saleorApiUrl, {
|
|
399
|
+
method: "POST",
|
|
400
|
+
headers: refreshHeaders,
|
|
401
|
+
body: refreshBody
|
|
402
|
+
});
|
|
383
403
|
return this.fetchWithAuth(input, requestInit, additionalParams);
|
|
384
404
|
};
|
|
385
405
|
handleSignIn = async (response) => {
|
package/dist/index.mjs
CHANGED
|
@@ -2,8 +2,8 @@ import {
|
|
|
2
2
|
SaleorAuthProvider
|
|
3
3
|
} from "../chunk-74GMXOK4.mjs";
|
|
4
4
|
import "../chunk-NAQNA6DI.mjs";
|
|
5
|
-
import "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
import "../chunk-X3MKOESH.mjs";
|
|
6
|
+
import "../chunk-B326YIV6.mjs";
|
|
7
7
|
import "../chunk-263DHBMK.mjs";
|
|
8
8
|
import "../chunk-UDLCOX6B.mjs";
|
|
9
9
|
import "../chunk-7JTFMRQS.mjs";
|
package/dist/react/context.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
createSafeContext,
|
|
4
4
|
useSaleorAuthContext
|
|
5
5
|
} from "../chunk-NAQNA6DI.mjs";
|
|
6
|
-
import "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-X3MKOESH.mjs";
|
|
7
|
+
import "../chunk-B326YIV6.mjs";
|
|
8
8
|
import "../chunk-263DHBMK.mjs";
|
|
9
9
|
import "../chunk-UDLCOX6B.mjs";
|
|
10
10
|
import "../chunk-7JTFMRQS.mjs";
|
package/dist/react/index.mjs
CHANGED
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
useSaleorExternalAuth
|
|
14
14
|
} from "../chunk-Q3UFWDCC.mjs";
|
|
15
|
-
import "../chunk-
|
|
16
|
-
import "../chunk-
|
|
15
|
+
import "../chunk-X3MKOESH.mjs";
|
|
16
|
+
import "../chunk-B326YIV6.mjs";
|
|
17
17
|
import "../chunk-263DHBMK.mjs";
|
|
18
18
|
import "../chunk-T35JF4IS.mjs";
|
|
19
19
|
import "../chunk-KLIEZ4V4.mjs";
|