@djust-b2b/djust-front-sdk 1.21.16 → 1.21.18
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,18 +113,24 @@ 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
|
-
|
|
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
|
|
125
|
+
const routeIsPublic = (path, method) => {
|
|
122
126
|
var _a;
|
|
123
|
-
if (publicRoutes.has(path) && ((_a = publicRoutes.get(path)) === null || _a === void 0 ? void 0 : _a.has(method)))
|
|
127
|
+
if (publicRoutes.has(path) && ((_a = publicRoutes.get(path)) === null || _a === void 0 ? void 0 : _a.has(method)))
|
|
124
128
|
return true;
|
|
125
|
-
}
|
|
126
129
|
return publicRoutePatterns.some((pattern) => path.startsWith(pattern));
|
|
127
130
|
};
|
|
131
|
+
const isHybridRoute = (path) => {
|
|
132
|
+
return hybridRoutePatterns.some((pattern) => path.startsWith(pattern));
|
|
133
|
+
};
|
|
128
134
|
const enhancedFetch = async ({ path, method, params = {}, body, }) => {
|
|
129
135
|
var _a, _b, _c, _d, _e, _f;
|
|
130
136
|
if (!isClientInitialized(clientConfig)) {
|
|
@@ -140,10 +146,18 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
|
|
|
140
146
|
"dj-api-key": apiKey,
|
|
141
147
|
"Content-Type": "application/json",
|
|
142
148
|
});
|
|
143
|
-
if (!
|
|
144
|
-
if (accessToken) {
|
|
145
|
-
|
|
149
|
+
if (!routeIsPublic(path, method) && !isHybridRoute) {
|
|
150
|
+
if (!accessToken) {
|
|
151
|
+
const error = new Error("[Djust SDK] Private route need accessToken.");
|
|
152
|
+
Sentry.captureException(error, {
|
|
153
|
+
tags: { env: clientConfig.env },
|
|
154
|
+
});
|
|
155
|
+
throw error;
|
|
146
156
|
}
|
|
157
|
+
requestHeaders.append("Authorization", `Bearer ${accessToken}`);
|
|
158
|
+
}
|
|
159
|
+
else if (isHybridRoute(path) && accessToken) {
|
|
160
|
+
requestHeaders.append("Authorization", `Bearer ${accessToken}`);
|
|
147
161
|
}
|
|
148
162
|
if (locale)
|
|
149
163
|
requestHeaders.append("locale", locale);
|