@djust-b2b/djust-front-sdk 2.5.6 → 2.5.7

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.
@@ -91,6 +91,7 @@ async function postMediaCustomField(params) {
91
91
  const { data } = await (0, fetch_instance_1.enhancedFetch)({
92
92
  method: "POST",
93
93
  path: `/v1/shop/custom-fields/${id}/media`,
94
+ body: "",
94
95
  params: { customFieldIdType, sealedTarget, fileName, fileSize },
95
96
  });
96
97
  return data;
@@ -187,32 +187,23 @@ const enhancedFetch = async ({ path, method, params = {}, body, }) => {
187
187
  }
188
188
  const isJsonResponse = (_d = headers
189
189
  .get("content-type")) === null || _d === void 0 ? void 0 : _d.includes("application/json");
190
- // Additional check: ensure the response has content before attempting to parse JSON
191
- let responseText = await response.text();
192
- function isJsonString(str) {
193
- if (typeof str !== "string")
194
- return false;
195
- try {
196
- const parsed = JSON.parse(str);
197
- return typeof parsed === "object" && parsed !== null;
190
+ // Always read raw text; parse only if JSON
191
+ const responseText = await response.text();
192
+ let data;
193
+ if (isJsonResponse && responseText) {
194
+ data = JSON.parse(responseText);
195
+ // Check if response data contains new accessToken and update configuration
196
+ if (data && ((_e = data === null || data === void 0 ? void 0 : data.token) === null || _e === void 0 ? void 0 : _e.accessToken)) {
197
+ (0, exports.updateConfiguration)({
198
+ accessToken: (_f = data === null || data === void 0 ? void 0 : data.token) === null || _f === void 0 ? void 0 : _f.accessToken,
199
+ });
198
200
  }
199
- catch (_a) {
200
- return false;
201
- }
202
- }
203
- if (!isJsonString(responseText)) {
204
- responseText = `{"data":"${responseText}"}`;
205
201
  }
206
- const data = isJsonResponse && responseText
207
- ? JSON.parse(responseText)
208
- : {};
209
- // Check if response data contains new accessToken and update configuration
210
- if (data && ((_e = data === null || data === void 0 ? void 0 : data.token) === null || _e === void 0 ? void 0 : _e.accessToken)) {
211
- (0, exports.updateConfiguration)({
212
- accessToken: (_f = data === null || data === void 0 ? void 0 : data.token) === null || _f === void 0 ? void 0 : _f.accessToken,
213
- });
202
+ else {
203
+ // Non-JSON responses should return raw text
204
+ data = responseText;
214
205
  }
215
- return { data, headers, status };
206
+ return { data: data, headers, status };
216
207
  }
217
208
  catch (error) {
218
209
  Sentry.captureException(error, { tags: { env: clientConfig.env } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djust-b2b/djust-front-sdk",
3
- "version": "2.5.6",
3
+ "version": "2.5.7",
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",