@vigneshreddy/cms-sdk 1.0.5 → 1.0.6
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/dist/src/client.js +1 -2
- package/dist/src/generated/api.js +23 -7
- package/package.json +1 -1
package/dist/src/client.js
CHANGED
|
@@ -12,7 +12,7 @@ class CMS {
|
|
|
12
12
|
}
|
|
13
13
|
// Absolute base URL for the CMS SDK – we intentionally do NOT append
|
|
14
14
|
// per-endpoint paths like /track/lead; callers just hit this base.
|
|
15
|
-
const basePath = "
|
|
15
|
+
const basePath = "http://localhost:5000/sdk";
|
|
16
16
|
// Retry configuration with sensible defaults
|
|
17
17
|
this.maxRetries = (_a = config.maxRetries) !== null && _a !== void 0 ? _a : 2;
|
|
18
18
|
this.retryDelayMs = (_b = config.retryDelayMs) !== null && _b !== void 0 ? _b : 500;
|
|
@@ -26,7 +26,6 @@ class CMS {
|
|
|
26
26
|
// Ensure generated client uses the same timeout & headers
|
|
27
27
|
timeout: (_e = config.timeout) !== null && _e !== void 0 ? _e : 10000,
|
|
28
28
|
headers: {
|
|
29
|
-
'User-Agent': 'CMS-Node-SDK/1.0.0',
|
|
30
29
|
'Content-Type': 'application/json'
|
|
31
30
|
},
|
|
32
31
|
},
|
|
@@ -200,8 +200,9 @@ exports.EventsApi = EventsApi;
|
|
|
200
200
|
* operate without changes.
|
|
201
201
|
*/
|
|
202
202
|
async function performFetchRequest(requestArgs, basePath) {
|
|
203
|
+
var _a;
|
|
203
204
|
const url = (basePath !== null && basePath !== void 0 ? basePath : base_1.BASE_PATH).replace(/\/+$/, "") + requestArgs.url;
|
|
204
|
-
const { timeout, ...restOptions } = requestArgs.options;
|
|
205
|
+
const { timeout, data, ...restOptions } = requestArgs.options;
|
|
205
206
|
if (typeof fetch !== "function") {
|
|
206
207
|
throw new Error("Global fetch API is not available. Please provide a fetch polyfill in this environment.");
|
|
207
208
|
}
|
|
@@ -212,20 +213,35 @@ async function performFetchRequest(requestArgs, basePath) {
|
|
|
212
213
|
timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
213
214
|
}
|
|
214
215
|
try {
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
const fetchOptions = { ...restOptions, signal };
|
|
217
|
+
// The generated client stores the request payload on `data` (Axios-style),
|
|
218
|
+
// but the fetch API expects it on `body`. Translate between the two.
|
|
219
|
+
if (typeof data !== "undefined") {
|
|
220
|
+
const headers = ((_a = fetchOptions.headers) !== null && _a !== void 0 ? _a : {});
|
|
221
|
+
const requestContentType = Object.keys(headers).find((h) => h.toLowerCase() === "content-type");
|
|
222
|
+
// If Content-Type is JSON (our default), ensure the body is a JSON string.
|
|
223
|
+
if (requestContentType && headers[requestContentType].includes("application/json")) {
|
|
224
|
+
fetchOptions.body =
|
|
225
|
+
typeof data === "string" ? data : JSON.stringify(data);
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
fetchOptions.body = data;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const response = await fetch(url, fetchOptions);
|
|
232
|
+
const responseContentType = response.headers.get("content-type") || "";
|
|
233
|
+
const isJson = responseContentType.toLowerCase().includes("application/json");
|
|
234
|
+
const dataResult = isJson ? await response.json() : await response.text();
|
|
219
235
|
if (!response.ok) {
|
|
220
236
|
const error = new Error(`Request failed with status code ${response.status}`);
|
|
221
237
|
error.response = {
|
|
222
238
|
status: response.status,
|
|
223
239
|
statusText: response.statusText,
|
|
224
|
-
data,
|
|
240
|
+
data: dataResult,
|
|
225
241
|
};
|
|
226
242
|
throw error;
|
|
227
243
|
}
|
|
228
|
-
return
|
|
244
|
+
return dataResult;
|
|
229
245
|
}
|
|
230
246
|
catch (err) {
|
|
231
247
|
// Normalize fetch/AbortError/network errors into an Axios-style shape
|