sysone-api-mapper 1.0.90 → 1.0.91

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/axiosInstance.js CHANGED
@@ -1,6 +1,23 @@
1
1
  import axios from "axios";
2
2
 
3
- const axiosInstance = axios.create({});
3
+ const axiosInstance = axios.create({
4
+ baseURL: '',
5
+ });
4
6
 
7
+ // Agregar interceptor para debug
8
+ axiosInstance.interceptors.request.use(
9
+ (config) => {
10
+ console.log("📡 Request desde apiMapper:", {
11
+ baseURL: config.baseURL,
12
+ url: config.url,
13
+ fullURL: `${config.baseURL}${config.url}`,
14
+ headers: config.headers
15
+ });
16
+ return config;
17
+ },
18
+ (error) => {
19
+ return Promise.reject(error);
20
+ }
21
+ );
5
22
 
6
- export default axiosInstance;
23
+ export default axiosInstance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sysone-api-mapper",
3
- "version": "1.0.90",
3
+ "version": "1.0.91",
4
4
  "description": "Paquete mapper para portal de productores",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -117,7 +117,7 @@ export const apiMapper = async (
117
117
  ...configs.cnp,
118
118
  headers: {
119
119
  ...configs.cnp.headers,
120
- ...dynamicHeaders, // Headers dinámicos (incluye X-Sales-Channel y X-Sales-Agent)
120
+ ...dynamicHeaders,
121
121
  ...additionalHeaders,
122
122
  }
123
123
  };
@@ -138,7 +138,8 @@ export const apiMapper = async (
138
138
  validateStatus: (status) => status < 500,
139
139
  };
140
140
 
141
- const url = getUrl(endpointData.url, routeParams);
141
+ const fullUrl = `${config.baseURL}${endpointData.url}`.replace(/([^:]\/)\/+/g, "$1");
142
+ console.log("URL completa:", fullUrl);
142
143
 
143
144
  let response;
144
145
  let request;
@@ -148,34 +149,43 @@ export const apiMapper = async (
148
149
  request = endpointData.requestMapper(params);
149
150
  const { mappedParams, responseType, headers: requestHeaders, ...otherOptions } = request;
150
151
 
151
- response = await axiosInstance.get(url, {
152
- ...config,
152
+ response = await axiosInstance.get(fullUrl, {
153
153
  params: mappedParams,
154
154
  responseType: responseType,
155
155
  headers: {
156
156
  ...config.headers,
157
157
  ...requestHeaders
158
158
  },
159
+ validateStatus: config.validateStatus,
159
160
  ...otherOptions
160
161
  });
161
162
  return endpointData.responseMapper(response);
163
+
162
164
  case methods.POST:
163
165
  request = endpointData.requestMapper(params);
164
166
  const { mappedPostParams, mappedBody } = request;
165
- response = await axiosInstance.post(url, mappedBody, {
166
- ...config,
167
+ response = await axiosInstance.post(fullUrl, mappedBody, {
167
168
  params: mappedPostParams,
169
+ headers: config.headers,
170
+ validateStatus: config.validateStatus,
168
171
  });
169
172
  return endpointData.responseMapper(response.data);
173
+
170
174
  case methods.PUT:
171
- response = await axiosInstance.put(url, params, config);
175
+ response = await axiosInstance.put(fullUrl, params, {
176
+ headers: config.headers,
177
+ validateStatus: config.validateStatus,
178
+ });
172
179
  return endpointData.responseMapper(response.data);
180
+
173
181
  case methods.DELETE:
174
- response = await axiosInstance.delete(url, {
175
- ...config,
176
- data: params
182
+ response = await axiosInstance.delete(fullUrl, {
183
+ data: params,
184
+ headers: config.headers,
185
+ validateStatus: config.validateStatus,
177
186
  });
178
187
  return endpointData.responseMapper(response.data);
188
+
179
189
  default:
180
190
  response = null;
181
191
  throw new Error(
@@ -186,13 +196,4 @@ export const apiMapper = async (
186
196
  console.error("❌ Error en apiMapper:", e);
187
197
  throw e;
188
198
  }
189
- };
190
-
191
- const getUrl = (serviceUrl, routeParams) => {
192
- if (!routeParams) return serviceUrl;
193
- return serviceUrl.replace(/{(\d+)}/g, function (match, routeParamNumber) {
194
- return routeParams[routeParamNumber]
195
- ? routeParams[routeParamNumber]
196
- : match;
197
- });
198
199
  };