@djust-b2b/djust-front-sdk 2.18.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 +2 -1
- package/lib/services/logistic-order/definitions.d.ts +19 -0
- package/lib/services/logistic-order/index.d.ts +39 -1
- package/lib/services/logistic-order/index.js +47 -0
- package/lib/services/product/definitions.d.ts +1 -0
- package/lib/services/product/index.d.ts +6 -5
- package/lib/services/product/index.js +7 -5
- package/lib/settings/fetch-instance.js +26 -4
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ export declare const DjustSDK: {
|
|
|
74
74
|
getLogisticOrderDocumentUrl({ orderId, documentId, }: import("./interfaces").GetLogisticOrderDocumentUrlParameters): Promise<string[]>;
|
|
75
75
|
getLogisticOrderLines({ orderId, page, size, sort, locale, }: import("./interfaces").GetLogisticOrderLinesParameters): Promise<import("./interfaces").GetLogisticOrderLinesResponse>;
|
|
76
76
|
updateOnHoldLogisticOrderLines({ orderId, lines, }: import("./interfaces").UpdateOnHoldLogisticOrderLinesParameters): Promise<import("./interfaces").UpdateOnHoldLogisticOrderLinesResponse>;
|
|
77
|
+
bulkUpdateLogisticOrderLinesCustomFields({ logisticOrderId, lines, }: import("./interfaces").BulkUpdateLogisticOrderLinesCustomFieldsParameters): Promise<import("./interfaces").BulkUpdateLogisticOrderLinesCustomFieldsResponse>;
|
|
77
78
|
updateLogisticOrderLineCustomFields({ orderId, lineId, locale, customFields, }: import("./interfaces").UpdateLogisticOrderLineCustomFieldsParameters): Promise<import("./interfaces").UpdateLogisticOrderLineCustomFieldsResponse>;
|
|
78
79
|
updateOnHoldLogisticOrderLine({ orderId, orderLineId, quantity, }: import("./interfaces").UpdateOnHoldLogisticOrderLineParameters): Promise<void>;
|
|
79
80
|
updateLogisticOrderShippingAddress({ orderId, shippingAddressId, }: import("./interfaces").UpdateLogisticOrderShippingAddressParameters): Promise<void>;
|
|
@@ -114,7 +115,7 @@ export declare const DjustSDK: {
|
|
|
114
115
|
getProductVariantAttributes({ productIdentifier, productIdType, locale, }: import("./services/product-variant/definitions").GetProductVariantAttributesParameters): Promise<import("./services/product-variant/definitions").GetProductVariantAttributesResponse>;
|
|
115
116
|
getProductVariant({ productVariantId, locale, }: import("./services/product-variant/definitions").GetProductVariantParameters): Promise<import("./services/product-variant/definitions").GetProductVariantResponse>;
|
|
116
117
|
autoCompleteSearchProducts({ input, locale, currency, pageable, aggregation, productTags, }: import("./interfaces").AutoCompleteSearchProductsParameters): Promise<import("./interfaces").SearchProductsResponse>;
|
|
117
|
-
getProductsList({ locale, filters, pageable, }: import("./interfaces").GetProductsListParameters): Promise<import("./interfaces").GetProductsListResponse>;
|
|
118
|
+
getProductsList({ locale, filters, pageable, hasOfferPrice, }: import("./interfaces").GetProductsListParameters): Promise<import("./interfaces").GetProductsListResponse>;
|
|
118
119
|
getProductVariantOffers({ productIdentifier, productIdType, currency, withoutPrice, }: import("./interfaces").GetProductVariantOffersParameters): Promise<import("./interfaces").GetProductVariantOffersResponse>;
|
|
119
120
|
getProduct({ productIdentifier, productIdType, locale, }: import("./interfaces").GetProductParameters): Promise<import("./interfaces").GetProductsListResponse>;
|
|
120
121
|
getProductOffers({ productIdentifier, productIdType, locale, currency, withoutPrice, }: import("./interfaces").GetProductOffersParameters): Promise<import("./interfaces").GetProductOffersResponse>;
|
|
@@ -124,6 +124,25 @@ export interface UpdateOnHoldLogisticOrderLinesParameters {
|
|
|
124
124
|
orderId: string;
|
|
125
125
|
lines: OrderLogisticLineUpdate[];
|
|
126
126
|
}
|
|
127
|
+
/** ORDER-251 — one entry per logistic order line in the bulk PATCH body. */
|
|
128
|
+
export interface BulkUpdateLogisticOrderLinesCustomFieldsLineItem {
|
|
129
|
+
customFieldValues: CustomFieldValueRequest[];
|
|
130
|
+
logisticOrderLineId: string;
|
|
131
|
+
}
|
|
132
|
+
export interface BulkUpdateLogisticOrderLinesCustomFieldsParameters {
|
|
133
|
+
/** Logistic order reference (e.g. OL-2025-001234). Requires dj-client: ACCOUNT. */
|
|
134
|
+
logisticOrderId: string;
|
|
135
|
+
lines: BulkUpdateLogisticOrderLinesCustomFieldsLineItem[];
|
|
136
|
+
}
|
|
137
|
+
/** Per-line warning when bulk update runs in partial success mode (ORDER-251). */
|
|
138
|
+
export interface LogisticOrderLineBulkCustomFieldWarning {
|
|
139
|
+
code: string;
|
|
140
|
+
logisticOrderLineId: string;
|
|
141
|
+
message: string;
|
|
142
|
+
}
|
|
143
|
+
export interface BulkUpdateLogisticOrderLinesCustomFieldsResponse {
|
|
144
|
+
warnings: LogisticOrderLineBulkCustomFieldWarning[];
|
|
145
|
+
}
|
|
127
146
|
export interface UpdateLogisticOrderLineCustomFieldsParameters {
|
|
128
147
|
orderId: string;
|
|
129
148
|
lineId: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddLogisticOrderReviewParameters, AddLogisticOrderReviewResponse, ApproveLogisticOrderParameters, ApproveLogisticOrderResponse, CancelLogisticOrderParameters, CancelLogisticOrderResponse, ConfirmLogisticOrderReceptionParameters, ConfirmLogisticOrderReceptionResponse, CreateLogisticOrderParameters, CreateLogisticOrderThreadParameters, GetPaginatedLogisticOrdersParameters, GetPaginatedLogisticOrdersResponse, CreateLogisticOrderThreadResponse, DisapproveLogisticOrderParameters, DisapproveLogisticOrderResponse, GetLogisticOrderAccountingDocumentsParameters, GetLogisticOrderAccountingDocumentsResponse, GetLogisticOrderAccountingDocumentUrlParameters, GetLogisticOrderApproversParameters, GetLogisticOrderApproversResponse, GetLogisticOrderCustomFieldsParameters, GetLogisticOrderCustomFieldsResponse, GetLogisticOrderDocumentsParameters, GetLogisticOrderDocumentsResponse, GetLogisticOrderDocumentUrlParameters, GetLogisticOrderLineCustomFieldsParameters, GetLogisticOrderLineCustomFieldsResponse, GetLogisticOrderLinesParameters, GetLogisticOrderLinesResponse, GetLogisticOrderParameters, GetLogisticOrderResponse, GetLogisticOrderReviewParameters, GetLogisticOrderReviewResponse, GetLogisticOrderShippingAddressParameters, GetLogisticOrderShippingAddressResponse, GetLogisticOrdersParameters, GetLogisticOrdersResponse, GetThreadReasonTypesResponse, GetThreadSubReasonsParameters, GetThreadSubReasonsResponse, UpdateLogisticOrderBillingInformationParameters, UpdateLogisticOrderCustomFieldsParameters, UpdateLogisticOrderCustomFieldsResponse, UpdateLogisticOrderLineCustomFieldsParameters, UpdateLogisticOrderLineCustomFieldsResponse, UpdateLogisticOrderShippingAddressParameters, UpdateLogisticOrderShippingInformationParameters, UpdateLogisticOrderShippingTypeParameters, UpdateOnHoldLogisticOrderLineParameters, UpdateOnHoldLogisticOrderLinesParameters, UpdateOnHoldLogisticOrderLinesResponse, CreateLogisticOrderIncidentThreadsParams, CreateLogisticOrderIncidentThreadsResponse, GetLogisticOrderIncidentThreadParams, GetLogisticOrderIncidentThreadResponse, CreateLogisticOrderIncidentThreadMessagesParams, CreateLogisticOrderIncidentThreadMessagesResponse, UpdateLogisticOrderIncidentThreadMessageParams, GetLogisticOrderThreadsParams, GetLogisticOrderThreadsResponse, CreateLogisticOrderThreadParametersV2, CreateLogisticOrderThreadResponseV2, GetLogisticOrderThreadParams, GetLogisticOrderThreadResponse, CreateLogisticOrderThreadMessagesParams, CreateLogisticOrderThreadMessagesResponse, UpdateLogisticOrderThreadMessageParams } from "./definitions";
|
|
1
|
+
import { AddLogisticOrderReviewParameters, AddLogisticOrderReviewResponse, ApproveLogisticOrderParameters, ApproveLogisticOrderResponse, CancelLogisticOrderParameters, CancelLogisticOrderResponse, ConfirmLogisticOrderReceptionParameters, ConfirmLogisticOrderReceptionResponse, CreateLogisticOrderParameters, CreateLogisticOrderThreadParameters, GetPaginatedLogisticOrdersParameters, GetPaginatedLogisticOrdersResponse, CreateLogisticOrderThreadResponse, DisapproveLogisticOrderParameters, DisapproveLogisticOrderResponse, GetLogisticOrderAccountingDocumentsParameters, GetLogisticOrderAccountingDocumentsResponse, GetLogisticOrderAccountingDocumentUrlParameters, GetLogisticOrderApproversParameters, GetLogisticOrderApproversResponse, GetLogisticOrderCustomFieldsParameters, GetLogisticOrderCustomFieldsResponse, GetLogisticOrderDocumentsParameters, GetLogisticOrderDocumentsResponse, GetLogisticOrderDocumentUrlParameters, GetLogisticOrderLineCustomFieldsParameters, GetLogisticOrderLineCustomFieldsResponse, GetLogisticOrderLinesParameters, GetLogisticOrderLinesResponse, GetLogisticOrderParameters, GetLogisticOrderResponse, GetLogisticOrderReviewParameters, GetLogisticOrderReviewResponse, GetLogisticOrderShippingAddressParameters, GetLogisticOrderShippingAddressResponse, GetLogisticOrdersParameters, GetLogisticOrdersResponse, GetThreadReasonTypesResponse, GetThreadSubReasonsParameters, GetThreadSubReasonsResponse, UpdateLogisticOrderBillingInformationParameters, UpdateLogisticOrderCustomFieldsParameters, UpdateLogisticOrderCustomFieldsResponse, UpdateLogisticOrderLineCustomFieldsParameters, UpdateLogisticOrderLineCustomFieldsResponse, UpdateLogisticOrderShippingAddressParameters, UpdateLogisticOrderShippingInformationParameters, UpdateLogisticOrderShippingTypeParameters, UpdateOnHoldLogisticOrderLineParameters, UpdateOnHoldLogisticOrderLinesParameters, UpdateOnHoldLogisticOrderLinesResponse, BulkUpdateLogisticOrderLinesCustomFieldsParameters, BulkUpdateLogisticOrderLinesCustomFieldsResponse, CreateLogisticOrderIncidentThreadsParams, CreateLogisticOrderIncidentThreadsResponse, GetLogisticOrderIncidentThreadParams, GetLogisticOrderIncidentThreadResponse, CreateLogisticOrderIncidentThreadMessagesParams, CreateLogisticOrderIncidentThreadMessagesResponse, UpdateLogisticOrderIncidentThreadMessageParams, GetLogisticOrderThreadsParams, GetLogisticOrderThreadsResponse, CreateLogisticOrderThreadParametersV2, CreateLogisticOrderThreadResponseV2, GetLogisticOrderThreadParams, GetLogisticOrderThreadResponse, CreateLogisticOrderThreadMessagesParams, CreateLogisticOrderThreadMessagesResponse, UpdateLogisticOrderThreadMessageParams } from "./definitions";
|
|
2
2
|
/**
|
|
3
3
|
* @deprecated
|
|
4
4
|
* 🚚 Gets logistic orders.
|
|
@@ -639,6 +639,44 @@ export declare function getLogisticOrderLines({ orderId, page, size, sort, local
|
|
|
639
639
|
* @returns {Promise<UpdateOnHoldLogisticOrderLinesResponse>} A promise resolving to the response containing the error report.
|
|
640
640
|
*/
|
|
641
641
|
export declare function updateOnHoldLogisticOrderLines({ orderId, lines, }: UpdateOnHoldLogisticOrderLinesParameters): Promise<UpdateOnHoldLogisticOrderLinesResponse>;
|
|
642
|
+
/**
|
|
643
|
+
* 🚚 Bulk-updates custom field values on multiple lines of a logistic order (partial success).
|
|
644
|
+
*
|
|
645
|
+
* Each line is processed independently: valid lines are updated; failures appear in `warnings`.
|
|
646
|
+
* An empty `warnings` array means every line succeeded. Requires `dj-client: ACCOUNT`; the order
|
|
647
|
+
* must belong to the authenticated customer. `logisticOrderId` is the order **reference**
|
|
648
|
+
* (e.g. OL-2025-001234), not necessarily an internal id.
|
|
649
|
+
*
|
|
650
|
+
* 🛠 **Endpoint**: `PATCH /v1/shop/logistic-orders/${logisticOrderId}/lines [ORDER-251]`
|
|
651
|
+
*
|
|
652
|
+
* | Parameter | Type | Required | Description |
|
|
653
|
+
* |--------------------|---------------------------------------------------|----------|--------------------------------------------------|
|
|
654
|
+
* | `logisticOrderId` | `string` | ✅ | Logistic order reference. |
|
|
655
|
+
* | `lines` | `BulkUpdateLogisticOrderLinesCustomFieldsLineItem[]` | ✅ | Lines with `logisticOrderLineId` and `customFieldValues`. Max 100 entries, no duplicates (422 if invalid). |
|
|
656
|
+
*
|
|
657
|
+
* 📤 **Returns**:
|
|
658
|
+
* A `Promise` resolving to `BulkUpdateLogisticOrderLinesCustomFieldsResponse` (`warnings` only lists lines that failed validation).
|
|
659
|
+
*
|
|
660
|
+
* 🛠 **Example usage**:
|
|
661
|
+
* ```ts
|
|
662
|
+
* const { warnings } = await bulkUpdateLogisticOrderLinesCustomFields({
|
|
663
|
+
* logisticOrderId: "OL-2025-001234",
|
|
664
|
+
* lines: [
|
|
665
|
+
* {
|
|
666
|
+
* logisticOrderLineId: "LOG-LINE-001",
|
|
667
|
+
* customFieldValues: [
|
|
668
|
+
* { customFieldId: "cf-1", customFieldValue: "value1" },
|
|
669
|
+
* ],
|
|
670
|
+
* },
|
|
671
|
+
* ],
|
|
672
|
+
* });
|
|
673
|
+
* ```
|
|
674
|
+
*
|
|
675
|
+
* @param {BulkUpdateLogisticOrderLinesCustomFieldsParameters} params - Path id and line payloads.
|
|
676
|
+
* @throws {Error} If `logisticOrderId` or `lines` is missing.
|
|
677
|
+
* @returns {Promise<BulkUpdateLogisticOrderLinesCustomFieldsResponse>}
|
|
678
|
+
*/
|
|
679
|
+
export declare function bulkUpdateLogisticOrderLinesCustomFields({ logisticOrderId, lines, }: BulkUpdateLogisticOrderLinesCustomFieldsParameters): Promise<BulkUpdateLogisticOrderLinesCustomFieldsResponse>;
|
|
642
680
|
/**
|
|
643
681
|
* 🚚 Updates specific logistic order line's customFields.
|
|
644
682
|
*
|
|
@@ -19,6 +19,7 @@ exports.getLogisticOrderDocuments = getLogisticOrderDocuments;
|
|
|
19
19
|
exports.getLogisticOrderDocumentUrl = getLogisticOrderDocumentUrl;
|
|
20
20
|
exports.getLogisticOrderLines = getLogisticOrderLines;
|
|
21
21
|
exports.updateOnHoldLogisticOrderLines = updateOnHoldLogisticOrderLines;
|
|
22
|
+
exports.bulkUpdateLogisticOrderLinesCustomFields = bulkUpdateLogisticOrderLinesCustomFields;
|
|
22
23
|
exports.updateLogisticOrderLineCustomFields = updateLogisticOrderLineCustomFields;
|
|
23
24
|
exports.updateOnHoldLogisticOrderLine = updateOnHoldLogisticOrderLine;
|
|
24
25
|
exports.updateLogisticOrderShippingAddress = updateLogisticOrderShippingAddress;
|
|
@@ -900,6 +901,52 @@ async function updateOnHoldLogisticOrderLines({ orderId, lines, }) {
|
|
|
900
901
|
});
|
|
901
902
|
return data;
|
|
902
903
|
}
|
|
904
|
+
/**
|
|
905
|
+
* 🚚 Bulk-updates custom field values on multiple lines of a logistic order (partial success).
|
|
906
|
+
*
|
|
907
|
+
* Each line is processed independently: valid lines are updated; failures appear in `warnings`.
|
|
908
|
+
* An empty `warnings` array means every line succeeded. Requires `dj-client: ACCOUNT`; the order
|
|
909
|
+
* must belong to the authenticated customer. `logisticOrderId` is the order **reference**
|
|
910
|
+
* (e.g. OL-2025-001234), not necessarily an internal id.
|
|
911
|
+
*
|
|
912
|
+
* 🛠 **Endpoint**: `PATCH /v1/shop/logistic-orders/${logisticOrderId}/lines [ORDER-251]`
|
|
913
|
+
*
|
|
914
|
+
* | Parameter | Type | Required | Description |
|
|
915
|
+
* |--------------------|---------------------------------------------------|----------|--------------------------------------------------|
|
|
916
|
+
* | `logisticOrderId` | `string` | ✅ | Logistic order reference. |
|
|
917
|
+
* | `lines` | `BulkUpdateLogisticOrderLinesCustomFieldsLineItem[]` | ✅ | Lines with `logisticOrderLineId` and `customFieldValues`. Max 100 entries, no duplicates (422 if invalid). |
|
|
918
|
+
*
|
|
919
|
+
* 📤 **Returns**:
|
|
920
|
+
* A `Promise` resolving to `BulkUpdateLogisticOrderLinesCustomFieldsResponse` (`warnings` only lists lines that failed validation).
|
|
921
|
+
*
|
|
922
|
+
* 🛠 **Example usage**:
|
|
923
|
+
* ```ts
|
|
924
|
+
* const { warnings } = await bulkUpdateLogisticOrderLinesCustomFields({
|
|
925
|
+
* logisticOrderId: "OL-2025-001234",
|
|
926
|
+
* lines: [
|
|
927
|
+
* {
|
|
928
|
+
* logisticOrderLineId: "LOG-LINE-001",
|
|
929
|
+
* customFieldValues: [
|
|
930
|
+
* { customFieldId: "cf-1", customFieldValue: "value1" },
|
|
931
|
+
* ],
|
|
932
|
+
* },
|
|
933
|
+
* ],
|
|
934
|
+
* });
|
|
935
|
+
* ```
|
|
936
|
+
*
|
|
937
|
+
* @param {BulkUpdateLogisticOrderLinesCustomFieldsParameters} params - Path id and line payloads.
|
|
938
|
+
* @throws {Error} If `logisticOrderId` or `lines` is missing.
|
|
939
|
+
* @returns {Promise<BulkUpdateLogisticOrderLinesCustomFieldsResponse>}
|
|
940
|
+
*/
|
|
941
|
+
async function bulkUpdateLogisticOrderLinesCustomFields({ logisticOrderId, lines, }) {
|
|
942
|
+
(0, parameters_validation_1.required)({ logisticOrderId, lines });
|
|
943
|
+
const { data } = await (0, fetch_instance_1.enhancedFetch)({
|
|
944
|
+
method: "PATCH",
|
|
945
|
+
path: `/v1/shop/logistic-orders/${logisticOrderId}/lines`,
|
|
946
|
+
body: JSON.stringify(lines),
|
|
947
|
+
});
|
|
948
|
+
return data;
|
|
949
|
+
}
|
|
903
950
|
/**
|
|
904
951
|
* 🚚 Updates specific logistic order line's customFields.
|
|
905
952
|
*
|
|
@@ -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
|
}
|