@shopsbuilder/auth-sdk 1.2.0 → 1.2.2

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.
@@ -324,15 +324,29 @@ var SaleorAuthClient = class {
324
324
  this.onAuthRefresh?.(true);
325
325
  if (this.tokenRefreshPromise) {
326
326
  const response = await this.tokenRefreshPromise;
327
- const res = await response.clone().json();
328
- const {
329
- errors: graphqlErrors,
330
- data: {
331
- tokenRefresh: { errors, token }
332
- }
333
- } = res;
327
+ const responseClone = response.clone();
328
+ let res;
329
+ try {
330
+ res = await responseClone.json();
331
+ } catch {
332
+ console.error("[auth-sdk] Token refresh response is not valid JSON, status:", response.status);
333
+ this.onAuthRefresh?.(false);
334
+ this.tokenRefreshPromise = null;
335
+ this.refreshTokenStorage?.clearAuthStorage();
336
+ return fetch(input, requestInit);
337
+ }
338
+ const graphqlErrors = res.errors;
339
+ const token = res.data?.tokenRefresh?.token;
340
+ const refreshErrors = res.data?.tokenRefresh?.errors;
334
341
  this.onAuthRefresh?.(false);
335
- if (errors?.length || graphqlErrors?.length || !token) {
342
+ if (refreshErrors?.length || graphqlErrors?.length || !token) {
343
+ console.warn("[auth-sdk] Token refresh failed:", JSON.stringify({
344
+ graphqlErrors: graphqlErrors ?? [],
345
+ refreshErrors: refreshErrors ?? [],
346
+ hasToken: Boolean(token),
347
+ httpStatus: response.status,
348
+ rawData: res.data ?? null
349
+ }));
336
350
  this.tokenRefreshPromise = null;
337
351
  this.refreshTokenStorage?.clearAuthStorage();
338
352
  return fetch(input, requestInit);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SaleorAuthClient,
3
3
  createSaleorAuthClient
4
- } from "./chunk-STBUJJV4.mjs";
4
+ } from "./chunk-SLTPGWX3.mjs";
5
5
  import "./chunk-BZFBMGPG.mjs";
6
6
  import "./chunk-263DHBMK.mjs";
7
7
  import "./chunk-UDLCOX6B.mjs";
@@ -87,15 +87,29 @@ var SaleorAuthClient = class {
87
87
  this.onAuthRefresh?.(true);
88
88
  if (this.tokenRefreshPromise) {
89
89
  const response = await this.tokenRefreshPromise;
90
- const res = await response.clone().json();
91
- const {
92
- errors: graphqlErrors,
93
- data: {
94
- tokenRefresh: { errors, token }
95
- }
96
- } = res;
90
+ const responseClone = response.clone();
91
+ let res;
92
+ try {
93
+ res = await responseClone.json();
94
+ } catch {
95
+ console.error("[auth-sdk] Token refresh response is not valid JSON, status:", response.status);
96
+ this.onAuthRefresh?.(false);
97
+ this.tokenRefreshPromise = null;
98
+ this.refreshTokenStorage?.clearAuthStorage();
99
+ return fetch(input, requestInit);
100
+ }
101
+ const graphqlErrors = res.errors;
102
+ const token = res.data?.tokenRefresh?.token;
103
+ const refreshErrors = res.data?.tokenRefresh?.errors;
97
104
  this.onAuthRefresh?.(false);
98
- if (errors?.length || graphqlErrors?.length || !token) {
105
+ if (refreshErrors?.length || graphqlErrors?.length || !token) {
106
+ console.warn("[auth-sdk] Token refresh failed:", JSON.stringify({
107
+ graphqlErrors: graphqlErrors ?? [],
108
+ refreshErrors: refreshErrors ?? [],
109
+ hasToken: Boolean(token),
110
+ httpStatus: response.status,
111
+ rawData: res.data ?? null
112
+ }));
99
113
  this.tokenRefreshPromise = null;
100
114
  this.refreshTokenStorage?.clearAuthStorage();
101
115
  return fetch(input, requestInit);
package/dist/index.js CHANGED
@@ -327,15 +327,29 @@ var SaleorAuthClient = class {
327
327
  this.onAuthRefresh?.(true);
328
328
  if (this.tokenRefreshPromise) {
329
329
  const response = await this.tokenRefreshPromise;
330
- const res = await response.clone().json();
331
- const {
332
- errors: graphqlErrors,
333
- data: {
334
- tokenRefresh: { errors, token }
335
- }
336
- } = res;
330
+ const responseClone = response.clone();
331
+ let res;
332
+ try {
333
+ res = await responseClone.json();
334
+ } catch {
335
+ console.error("[auth-sdk] Token refresh response is not valid JSON, status:", response.status);
336
+ this.onAuthRefresh?.(false);
337
+ this.tokenRefreshPromise = null;
338
+ this.refreshTokenStorage?.clearAuthStorage();
339
+ return fetch(input, requestInit);
340
+ }
341
+ const graphqlErrors = res.errors;
342
+ const token = res.data?.tokenRefresh?.token;
343
+ const refreshErrors = res.data?.tokenRefresh?.errors;
337
344
  this.onAuthRefresh?.(false);
338
- if (errors?.length || graphqlErrors?.length || !token) {
345
+ if (refreshErrors?.length || graphqlErrors?.length || !token) {
346
+ console.warn("[auth-sdk] Token refresh failed:", JSON.stringify({
347
+ graphqlErrors: graphqlErrors ?? [],
348
+ refreshErrors: refreshErrors ?? [],
349
+ hasToken: Boolean(token),
350
+ httpStatus: response.status,
351
+ rawData: res.data ?? null
352
+ }));
339
353
  this.tokenRefreshPromise = null;
340
354
  this.refreshTokenStorage?.clearAuthStorage();
341
355
  return fetch(input, requestInit);
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SaleorAuthClient,
3
3
  createSaleorAuthClient
4
- } from "./chunk-STBUJJV4.mjs";
4
+ } from "./chunk-SLTPGWX3.mjs";
5
5
  import "./chunk-BZFBMGPG.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-STBUJJV4.mjs";
5
+ import "../chunk-SLTPGWX3.mjs";
6
6
  import "../chunk-BZFBMGPG.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-STBUJJV4.mjs";
6
+ import "../chunk-SLTPGWX3.mjs";
7
7
  import "../chunk-BZFBMGPG.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-STBUJJV4.mjs";
15
+ import "../chunk-SLTPGWX3.mjs";
16
16
  import "../chunk-BZFBMGPG.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.0",
3
+ "version": "1.2.2",
4
4
  "description": "Auth SDK for Saleor",
5
5
  "sideEffects": false,
6
6
  "files": ["dist/", "README.md"],