@djust-b2b/djust-front-sdk 2.19.0 → 2.19.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.
package/lib/index.d.ts
CHANGED
|
@@ -115,7 +115,7 @@ export declare const DjustSDK: {
|
|
|
115
115
|
getProductVariantAttributes({ productIdentifier, productIdType, locale, }: import("./services/product-variant/definitions").GetProductVariantAttributesParameters): Promise<import("./services/product-variant/definitions").GetProductVariantAttributesResponse>;
|
|
116
116
|
getProductVariant({ productVariantId, locale, }: import("./services/product-variant/definitions").GetProductVariantParameters): Promise<import("./services/product-variant/definitions").GetProductVariantResponse>;
|
|
117
117
|
autoCompleteSearchProducts({ input, locale, currency, pageable, aggregation, productTags, }: import("./interfaces").AutoCompleteSearchProductsParameters): Promise<import("./interfaces").SearchProductsResponse>;
|
|
118
|
-
getProductsList({ locale, filters, pageable, }: import("./interfaces").GetProductsListParameters): Promise<import("./interfaces").GetProductsListResponse>;
|
|
118
|
+
getProductsList({ locale, filters, pageable, hasOfferPrice, }: import("./interfaces").GetProductsListParameters): Promise<import("./interfaces").GetProductsListResponse>;
|
|
119
119
|
getProductVariantOffers({ productIdentifier, productIdType, currency, withoutPrice, }: import("./interfaces").GetProductVariantOffersParameters): Promise<import("./interfaces").GetProductVariantOffersResponse>;
|
|
120
120
|
getProduct({ productIdentifier, productIdType, locale, }: import("./interfaces").GetProductParameters): Promise<import("./interfaces").GetProductsListResponse>;
|
|
121
121
|
getProductOffers({ productIdentifier, productIdType, locale, currency, withoutPrice, }: import("./interfaces").GetProductOffersParameters): Promise<import("./interfaces").GetProductOffersResponse>;
|
|
@@ -38,10 +38,11 @@ export declare function autoCompleteSearchProducts({ input, locale, currency, pa
|
|
|
38
38
|
*
|
|
39
39
|
* | Parameter | Type | Required | Description |
|
|
40
40
|
* |-----------------|--------------|----------|---------------------------------------------|
|
|
41
|
-
* | `locale`
|
|
42
|
-
* | `
|
|
43
|
-
* | `
|
|
44
|
-
* | `pageable.
|
|
41
|
+
* | `locale` | `string` | ✅ | The locale for product data. |
|
|
42
|
+
* | `hasOfferPrice` | `boolean` | ❌ | If `true`, only products with an offer price. Default `false`. |
|
|
43
|
+
* | `filters` | `object` | ❌ | Filters for narrowing down search results. |
|
|
44
|
+
* | `pageable.page` | `number` | ❌ | The page number to fetch (0-based index). |
|
|
45
|
+
* | `pageable.size` | `number` | ❌ | The number of items per page. |
|
|
45
46
|
*
|
|
46
47
|
* 📤 **Returns**:
|
|
47
48
|
* A `Promise` resolving to a `GetProductsListResponse` containing the products and their metadata.
|
|
@@ -56,7 +57,7 @@ export declare function autoCompleteSearchProducts({ input, locale, currency, pa
|
|
|
56
57
|
* console.log(products);
|
|
57
58
|
* ```
|
|
58
59
|
*/
|
|
59
|
-
export declare function getProductsList({ locale, filters, pageable, }: GetProductsListParameters): Promise<GetProductsListResponse>;
|
|
60
|
+
export declare function getProductsList({ locale, filters, pageable, hasOfferPrice, }: GetProductsListParameters): Promise<GetProductsListResponse>;
|
|
60
61
|
/**
|
|
61
62
|
* 📄 Fetches offers for a specific product variant.
|
|
62
63
|
*
|
|
@@ -71,10 +71,11 @@ async function autoCompleteSearchProducts({ input, locale, currency, pageable, a
|
|
|
71
71
|
*
|
|
72
72
|
* | Parameter | Type | Required | Description |
|
|
73
73
|
* |-----------------|--------------|----------|---------------------------------------------|
|
|
74
|
-
* | `locale`
|
|
75
|
-
* | `
|
|
76
|
-
* | `
|
|
77
|
-
* | `pageable.
|
|
74
|
+
* | `locale` | `string` | ✅ | The locale for product data. |
|
|
75
|
+
* | `hasOfferPrice` | `boolean` | ❌ | If `true`, only products with an offer price. Default `false`. |
|
|
76
|
+
* | `filters` | `object` | ❌ | Filters for narrowing down search results. |
|
|
77
|
+
* | `pageable.page` | `number` | ❌ | The page number to fetch (0-based index). |
|
|
78
|
+
* | `pageable.size` | `number` | ❌ | The number of items per page. |
|
|
78
79
|
*
|
|
79
80
|
* 📤 **Returns**:
|
|
80
81
|
* A `Promise` resolving to a `GetProductsListResponse` containing the products and their metadata.
|
|
@@ -89,7 +90,7 @@ async function autoCompleteSearchProducts({ input, locale, currency, pageable, a
|
|
|
89
90
|
* console.log(products);
|
|
90
91
|
* ```
|
|
91
92
|
*/
|
|
92
|
-
async function getProductsList({ locale, filters, pageable, }) {
|
|
93
|
+
async function getProductsList({ locale, filters, pageable, hasOfferPrice = false, }) {
|
|
93
94
|
(0, parameters_validation_1.required)({ locale });
|
|
94
95
|
const { data } = await (0, fetch_instance_1.enhancedFetch)({
|
|
95
96
|
method: "GET",
|
|
@@ -100,6 +101,7 @@ async function getProductsList({ locale, filters, pageable, }) {
|
|
|
100
101
|
page: pageable === null || pageable === void 0 ? void 0 : pageable.page,
|
|
101
102
|
size: pageable === null || pageable === void 0 ? void 0 : pageable.size,
|
|
102
103
|
sort: pageable === null || pageable === void 0 ? void 0 : pageable.sort,
|
|
104
|
+
hasOfferPrice,
|
|
103
105
|
},
|
|
104
106
|
});
|
|
105
107
|
return data;
|
|
@@ -129,7 +129,7 @@ const isTokenValid = (token) => {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
const enhancedFetch = async ({ path, method, params = {}, body, }) => {
|
|
132
|
-
var _a, _b, _c, _d, _e, _f;
|
|
132
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
133
133
|
if (!isClientInitialized(clientConfig)) {
|
|
134
134
|
const error = new Error("[Djust SDK] SDK not initialized.");
|
|
135
135
|
Sentry.captureException(error, {
|
|
@@ -206,11 +206,33 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
|
|
|
206
206
|
const responseText = await response.text();
|
|
207
207
|
let data;
|
|
208
208
|
if (isJsonResponse && responseText) {
|
|
209
|
-
|
|
209
|
+
try {
|
|
210
|
+
data = JSON.parse(responseText);
|
|
211
|
+
}
|
|
212
|
+
catch (parseError) {
|
|
213
|
+
const responseLength = responseText.length;
|
|
214
|
+
const errorPosition = (_f = (_e = parseError === null || parseError === void 0 ? void 0 : parseError.message) === null || _e === void 0 ? void 0 : _e.match(/position (\d+)/)) === null || _f === void 0 ? void 0 : _f[1];
|
|
215
|
+
const contextStart = errorPosition
|
|
216
|
+
? Math.max(0, Number(errorPosition) - 100)
|
|
217
|
+
: responseLength - 200;
|
|
218
|
+
const contextSnippet = responseText.slice(contextStart, contextStart + 200);
|
|
219
|
+
const enrichedError = new Error(`[API] JSON parse error on ${method} ${fullPath} — response length: ${responseLength} bytes. ${parseError === null || parseError === void 0 ? void 0 : parseError.message}. Context around error: ...${contextSnippet}...`);
|
|
220
|
+
Sentry.captureException(enrichedError, {
|
|
221
|
+
extra: {
|
|
222
|
+
url: fullPath,
|
|
223
|
+
method,
|
|
224
|
+
responseLength,
|
|
225
|
+
errorPosition,
|
|
226
|
+
contextSnippet,
|
|
227
|
+
env: clientConfig.env,
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
throw enrichedError;
|
|
231
|
+
}
|
|
210
232
|
// Check if response data contains new accessToken and update configuration
|
|
211
|
-
if (data && ((
|
|
233
|
+
if (data && ((_g = data === null || data === void 0 ? void 0 : data.token) === null || _g === void 0 ? void 0 : _g.accessToken)) {
|
|
212
234
|
(0, exports.updateConfiguration)({
|
|
213
|
-
accessToken: (
|
|
235
|
+
accessToken: (_h = data === null || data === void 0 ? void 0 : data.token) === null || _h === void 0 ? void 0 : _h.accessToken,
|
|
214
236
|
});
|
|
215
237
|
}
|
|
216
238
|
}
|