@djust-b2b/djust-front-sdk 1.21.16 → 1.21.17

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.
@@ -113,17 +113,22 @@ const publicRoutes = new Map([
113
113
  ["/v1/shop/attributes", new Set(["GET"])],
114
114
  ["/v1/shop/custom-fields", new Set(["GET"])],
115
115
  ]);
116
- const publicRoutePatterns = [
117
- "/v1/shop/navigation-category/",
116
+ const publicRoutePatterns = ["/v1/shop/navigation-category/"];
117
+ // Liste des routes pouvant être à la fois publique et privée
118
+ const hybridRoutePatterns = [
119
+ "/v1/shop/offer-inventories",
118
120
  "/v1/shop/products/",
119
121
  "/v1/shop/product-variants/",
122
+ "/v2/shop/autocomplete",
123
+ "/v2/shop/search",
120
124
  ];
121
- const isPublicRoute = (path, method) => {
125
+ const routeNeedToken = (path, method) => {
122
126
  var _a;
123
- if (publicRoutes.has(path) && ((_a = publicRoutes.get(path)) === null || _a === void 0 ? void 0 : _a.has(method))) {
124
- return true;
125
- }
126
- return publicRoutePatterns.some((pattern) => path.startsWith(pattern));
127
+ return (!publicRoutePatterns.some((pattern) => path.startsWith(pattern)) ||
128
+ !((_a = publicRoutes.get(path)) === null || _a === void 0 ? void 0 : _a.has(method)));
129
+ };
130
+ const isHybridRoute = (path) => {
131
+ return hybridRoutePatterns.some((pattern) => path.startsWith(pattern));
127
132
  };
128
133
  const enhancedFetch = async ({ path, method, params = {}, body, }) => {
129
134
  var _a, _b, _c, _d, _e, _f;
@@ -140,10 +145,18 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
140
145
  "dj-api-key": apiKey,
141
146
  "Content-Type": "application/json",
142
147
  });
143
- if (!isPublicRoute(path, method)) {
144
- if (accessToken) {
145
- requestHeaders.append("Authorization", `Bearer ${accessToken}`);
148
+ if (routeNeedToken(path, method)) {
149
+ if (!accessToken) {
150
+ const error = new Error("[Djust SDK] Private route need accessToken.");
151
+ Sentry.captureException(error, {
152
+ tags: { env: clientConfig.env },
153
+ });
154
+ throw error;
146
155
  }
156
+ requestHeaders.append("Authorization", `Bearer ${accessToken}`);
157
+ }
158
+ else if (isHybridRoute(path) && accessToken) {
159
+ requestHeaders.append("Authorization", `Bearer ${accessToken}`);
147
160
  }
148
161
  if (locale)
149
162
  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.21.16",
3
+ "version": "1.21.17",
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",