sysone-api-mapper 1.0.90 → 1.0.92
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 +29 -18
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
|
@@ -90,6 +90,15 @@ const configs = {
|
|
|
90
90
|
},
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
const getUrl = (serviceUrl, routeParams) => {
|
|
94
|
+
if (!routeParams || routeParams.length === 0) return serviceUrl;
|
|
95
|
+
return serviceUrl.replace(/{(\d+)}/g, function (match, routeParamNumber) {
|
|
96
|
+
return routeParams[routeParamNumber]
|
|
97
|
+
? routeParams[routeParamNumber]
|
|
98
|
+
: match;
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
93
102
|
|
|
94
103
|
export const apiMapper = async (
|
|
95
104
|
endpointCode,
|
|
@@ -117,7 +126,7 @@ export const apiMapper = async (
|
|
|
117
126
|
...configs.cnp,
|
|
118
127
|
headers: {
|
|
119
128
|
...configs.cnp.headers,
|
|
120
|
-
...dynamicHeaders,
|
|
129
|
+
...dynamicHeaders,
|
|
121
130
|
...additionalHeaders,
|
|
122
131
|
}
|
|
123
132
|
};
|
|
@@ -138,7 +147,8 @@ export const apiMapper = async (
|
|
|
138
147
|
validateStatus: (status) => status < 500,
|
|
139
148
|
};
|
|
140
149
|
|
|
141
|
-
const
|
|
150
|
+
const urlWithParams = getUrl(endpointData.url, routeParams);
|
|
151
|
+
const fullUrl = `${config.baseURL}${urlWithParams}`.replace(/([^:]\/)\/+/g, "$1");
|
|
142
152
|
|
|
143
153
|
let response;
|
|
144
154
|
let request;
|
|
@@ -148,7 +158,7 @@ export const apiMapper = async (
|
|
|
148
158
|
request = endpointData.requestMapper(params);
|
|
149
159
|
const { mappedParams, responseType, headers: requestHeaders, ...otherOptions } = request;
|
|
150
160
|
|
|
151
|
-
response = await axiosInstance.get(
|
|
161
|
+
response = await axiosInstance.get(fullUrl, {
|
|
152
162
|
...config,
|
|
153
163
|
params: mappedParams,
|
|
154
164
|
responseType: responseType,
|
|
@@ -156,26 +166,36 @@ export const apiMapper = async (
|
|
|
156
166
|
...config.headers,
|
|
157
167
|
...requestHeaders
|
|
158
168
|
},
|
|
169
|
+
validateStatus: config.validateStatus,
|
|
159
170
|
...otherOptions
|
|
160
171
|
});
|
|
161
172
|
return endpointData.responseMapper(response);
|
|
173
|
+
|
|
162
174
|
case methods.POST:
|
|
163
175
|
request = endpointData.requestMapper(params);
|
|
164
176
|
const { mappedPostParams, mappedBody } = request;
|
|
165
|
-
response = await axiosInstance.post(
|
|
166
|
-
...config,
|
|
177
|
+
response = await axiosInstance.post(fullUrl, mappedBody, {
|
|
167
178
|
params: mappedPostParams,
|
|
179
|
+
headers: config.headers,
|
|
180
|
+
validateStatus: config.validateStatus,
|
|
168
181
|
});
|
|
169
182
|
return endpointData.responseMapper(response.data);
|
|
183
|
+
|
|
170
184
|
case methods.PUT:
|
|
171
|
-
response = await axiosInstance.put(
|
|
185
|
+
response = await axiosInstance.put(fullUrl, params, {
|
|
186
|
+
headers: config.headers,
|
|
187
|
+
validateStatus: config.validateStatus,
|
|
188
|
+
});
|
|
172
189
|
return endpointData.responseMapper(response.data);
|
|
190
|
+
|
|
173
191
|
case methods.DELETE:
|
|
174
|
-
response = await axiosInstance.delete(
|
|
175
|
-
|
|
176
|
-
|
|
192
|
+
response = await axiosInstance.delete(fullUrl, {
|
|
193
|
+
data: params,
|
|
194
|
+
headers: config.headers,
|
|
195
|
+
validateStatus: config.validateStatus,
|
|
177
196
|
});
|
|
178
197
|
return endpointData.responseMapper(response.data);
|
|
198
|
+
|
|
179
199
|
default:
|
|
180
200
|
response = null;
|
|
181
201
|
throw new Error(
|
|
@@ -186,13 +206,4 @@ export const apiMapper = async (
|
|
|
186
206
|
console.error("❌ Error en apiMapper:", e);
|
|
187
207
|
throw e;
|
|
188
208
|
}
|
|
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
209
|
};
|