sysone-api-mapper 1.0.89 → 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 +19 -2
- package/package.json +1 -1
- package/src/mapper/Mapper.js +20 -19
- package/src/mapper/endpointsConfig.js +4 -4
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
package/src/mapper/Mapper.js
CHANGED
|
@@ -117,7 +117,7 @@ export const apiMapper = async (
|
|
|
117
117
|
...configs.cnp,
|
|
118
118
|
headers: {
|
|
119
119
|
...configs.cnp.headers,
|
|
120
|
-
...dynamicHeaders,
|
|
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
|
|
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(
|
|
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(
|
|
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(
|
|
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(
|
|
175
|
-
|
|
176
|
-
|
|
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
|
};
|
|
@@ -709,9 +709,7 @@ const requestModule = {
|
|
|
709
709
|
method: methods.GET,
|
|
710
710
|
requestMapper: (request) => ({
|
|
711
711
|
mappedParams: request,
|
|
712
|
-
|
|
713
|
-
'Accept': 'application/json',
|
|
714
|
-
}
|
|
712
|
+
responseType: "arraybuffer"
|
|
715
713
|
}),
|
|
716
714
|
responseMapper: (response) => response
|
|
717
715
|
},
|
|
@@ -720,7 +718,9 @@ const requestModule = {
|
|
|
720
718
|
method: methods.GET,
|
|
721
719
|
requestMapper: (request) => ({
|
|
722
720
|
mappedParams: request,
|
|
723
|
-
|
|
721
|
+
headers: {
|
|
722
|
+
'Accept': 'application/json',
|
|
723
|
+
}
|
|
724
724
|
}),
|
|
725
725
|
responseMapper: (response) => response
|
|
726
726
|
}
|