@djust-b2b/djust-front-sdk 1.26.0 → 1.26.1

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.
@@ -102,28 +102,17 @@ const serializeParams = (params, useRepeat) => {
102
102
  }
103
103
  return qs.stringify(params, { arrayFormat: "bracket", skipNull: true });
104
104
  };
105
- // Liste des routes publiques (sans JWT)
106
- const publicRoutes = new Map([
107
- ["/auth/token", new Set(["POST"])],
108
- ["/auth/refresh-token", new Set(["POST"])],
109
- ["/auth/reset-password", new Set(["POST"])],
110
- ["/auth/send-reset-password-email", new Set(["POST"])],
111
- ["/v1/shop/assets", new Set(["GET"])],
112
- ["/v1/shop/customer-accounts", new Set(["POST"])], // Seulement POST est public
113
- ["/v1/shop/attributes", new Set(["GET"])],
114
- ["/v1/shop/custom-fields", new Set(["GET"])],
115
- ]);
116
- const publicRoutePatterns = [
117
- "/v1/shop/navigation-category/",
118
- "/v1/shop/products/",
119
- "/v1/shop/product-variants/",
120
- ];
121
- const isPublicRoute = (path, method) => {
122
- var _a;
123
- if (publicRoutes.has(path) && ((_a = publicRoutes.get(path)) === null || _a === void 0 ? void 0 : _a.has(method))) {
124
- return true;
105
+ const isTokenValid = (token) => {
106
+ if (!token)
107
+ return false;
108
+ try {
109
+ const payload = JSON.parse(atob(token.split(".")[1]));
110
+ const now = Math.floor(Date.now() / 1000);
111
+ return payload.exp && payload.exp > now;
112
+ }
113
+ catch (_a) {
114
+ return false;
125
115
  }
126
- return publicRoutePatterns.some((pattern) => path.startsWith(pattern));
127
116
  };
128
117
  const enhancedFetch = async ({ path, method, params = {}, body, }) => {
129
118
  var _a, _b, _c, _d, _e, _f;
@@ -140,10 +129,8 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
140
129
  "dj-api-key": apiKey,
141
130
  "Content-Type": "application/json",
142
131
  });
143
- if (!isPublicRoute(path, method)) {
144
- if (accessToken) {
145
- requestHeaders.append("Authorization", `Bearer ${accessToken}`);
146
- }
132
+ if (isTokenValid(accessToken)) {
133
+ requestHeaders.append("Authorization", `Bearer ${accessToken}`);
147
134
  }
148
135
  if (locale)
149
136
  requestHeaders.append("locale", locale);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djust-b2b/djust-front-sdk",
3
- "version": "1.26.0",
3
+ "version": "1.26.1",
4
4
  "description": "DJUST Front SDK is a versatile JavaScript Software Development Kit (SDK)",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",