@vigneshreddy/cms-sdk 1.0.4 → 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.
@@ -10,7 +10,9 @@ class CMS {
10
10
  if (!config.apiKey) {
11
11
  throw new Error("CMS SDK: apiKey is required.");
12
12
  }
13
- const basePath = "www.app.dev.cutmeshort.com/sdk";
13
+ // Absolute base URL for the CMS SDK – we intentionally do NOT append
14
+ // per-endpoint paths like /track/lead; callers just hit this base.
15
+ const basePath = "http://localhost:5000/sdk";
14
16
  // Retry configuration with sensible defaults
15
17
  this.maxRetries = (_a = config.maxRetries) !== null && _a !== void 0 ? _a : 2;
16
18
  this.retryDelayMs = (_b = config.retryDelayMs) !== null && _b !== void 0 ? _b : 500;
@@ -24,7 +26,6 @@ class CMS {
24
26
  // Ensure generated client uses the same timeout & headers
25
27
  timeout: (_e = config.timeout) !== null && _e !== void 0 ? _e : 10000,
26
28
  headers: {
27
- 'User-Agent': 'CMS-Node-SDK/1.0.0',
28
29
  'Content-Type': 'application/json'
29
30
  },
30
31
  },
@@ -34,7 +34,9 @@ const EventsApiAxiosParamCreator = function (configuration) {
34
34
  trackLead: async (trackLeadRequest, options = {}) => {
35
35
  // verify required parameter 'trackLeadRequest' is not null or undefined
36
36
  (0, common_1.assertParamExists)('trackLead', 'trackLeadRequest', trackLeadRequest);
37
- const localVarPath = `/track/lead`;
37
+ // We already include the full `/sdk` URL in the SDK's basePath,
38
+ // so we do not append any additional path segments here.
39
+ const localVarPath = ``;
38
40
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
39
41
  const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
40
42
  let baseOptions;
@@ -68,7 +70,9 @@ const EventsApiAxiosParamCreator = function (configuration) {
68
70
  trackSale: async (trackSaleRequest, options = {}) => {
69
71
  // verify required parameter 'trackSaleRequest' is not null or undefined
70
72
  (0, common_1.assertParamExists)('trackSale', 'trackSaleRequest', trackSaleRequest);
71
- const localVarPath = `/track/sale`;
73
+ // We already include the full `/sdk` URL in the SDK's basePath,
74
+ // so we do not append any additional path segments here.
75
+ const localVarPath = ``;
72
76
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
73
77
  const localVarUrlObj = new URL(localVarPath, common_1.DUMMY_BASE_URL);
74
78
  let baseOptions;
@@ -196,8 +200,9 @@ exports.EventsApi = EventsApi;
196
200
  * operate without changes.
197
201
  */
198
202
  async function performFetchRequest(requestArgs, basePath) {
203
+ var _a;
199
204
  const url = (basePath !== null && basePath !== void 0 ? basePath : base_1.BASE_PATH).replace(/\/+$/, "") + requestArgs.url;
200
- const { timeout, ...restOptions } = requestArgs.options;
205
+ const { timeout, data, ...restOptions } = requestArgs.options;
201
206
  if (typeof fetch !== "function") {
202
207
  throw new Error("Global fetch API is not available. Please provide a fetch polyfill in this environment.");
203
208
  }
@@ -208,20 +213,35 @@ async function performFetchRequest(requestArgs, basePath) {
208
213
  timeoutId = setTimeout(() => controller.abort(), timeout);
209
214
  }
210
215
  try {
211
- const response = await fetch(url, { ...restOptions, signal });
212
- const contentType = response.headers.get("content-type") || "";
213
- const isJson = contentType.toLowerCase().includes("application/json");
214
- const data = isJson ? await response.json() : await response.text();
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();
215
235
  if (!response.ok) {
216
236
  const error = new Error(`Request failed with status code ${response.status}`);
217
237
  error.response = {
218
238
  status: response.status,
219
239
  statusText: response.statusText,
220
- data,
240
+ data: dataResult,
221
241
  };
222
242
  throw error;
223
243
  }
224
- return data;
244
+ return dataResult;
225
245
  }
226
246
  catch (err) {
227
247
  // Normalize fetch/AbortError/network errors into an Axios-style shape
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vigneshreddy/cms-sdk",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Official TypeScript SDK for CutMeShort CMS API",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",