sysone-api-mapper 1.0.71 → 1.0.73
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/package.json
CHANGED
package/src/mapper/Mapper.js
CHANGED
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import axiosInstance from "../../axiosInstance";
|
|
2
2
|
import { methods, tenantsConfig } from "./endpointsConfig";
|
|
3
|
-
import dotenv from "dotenv";
|
|
4
|
-
|
|
5
|
-
// Cargar variables de entorno
|
|
6
|
-
dotenv.config();
|
|
7
3
|
|
|
8
4
|
const getApiMapperConfig = () => {
|
|
9
|
-
// 1. Intentar desde variables de entorno compiladas
|
|
10
|
-
if (process.env.API_MAPPER
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
// 1. Intentar desde variables de entorno compiladas (Webpack DefinePlugin)
|
|
6
|
+
if (process.env.API_MAPPER) {
|
|
7
|
+
try {
|
|
8
|
+
// Si es un string, parsearlo
|
|
9
|
+
const parsed = typeof process.env.API_MAPPER === 'string'
|
|
10
|
+
? JSON.parse(process.env.API_MAPPER)
|
|
11
|
+
: process.env.API_MAPPER;
|
|
12
|
+
|
|
13
|
+
if (parsed && Object.keys(parsed).length > 0) {
|
|
14
|
+
console.log("✅ Usando API_MAPPER de process.env", parsed);
|
|
15
|
+
return parsed;
|
|
16
|
+
}
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error("❌ Error parseando API_MAPPER de process.env:", error);
|
|
19
|
+
}
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
// 2. Intentar desde variable global inyectada
|
|
16
23
|
if (window.__API_MAPPER__ && Object.keys(window.__API_MAPPER__).length > 0) {
|
|
17
|
-
console.log("Usando API_MAPPER de window");
|
|
24
|
+
console.log("✅ Usando API_MAPPER de window");
|
|
18
25
|
return window.__API_MAPPER__;
|
|
19
26
|
}
|
|
20
27
|
|
|
28
|
+
console.error("❌ No se pudo cargar API_MAPPER desde ninguna fuente");
|
|
29
|
+
return null;
|
|
21
30
|
};
|
|
22
31
|
|
|
23
32
|
const getSalesAgent = () => {
|
|
@@ -40,7 +49,7 @@ const getDynamicHeaders = (tenant) => {
|
|
|
40
49
|
configs.cnp.headers["X-Agent"];
|
|
41
50
|
|
|
42
51
|
const salesCode = getSalesAgent();
|
|
43
|
-
const salesChannel = getSalesChannel()
|
|
52
|
+
const salesChannel = getSalesChannel();
|
|
44
53
|
|
|
45
54
|
return {
|
|
46
55
|
"X-Agent": xAgent,
|
|
@@ -52,33 +61,36 @@ const getDynamicHeaders = (tenant) => {
|
|
|
52
61
|
};
|
|
53
62
|
|
|
54
63
|
const API_MAPPER = getApiMapperConfig();
|
|
55
|
-
|
|
64
|
+
|
|
65
|
+
if (!API_MAPPER) {
|
|
66
|
+
console.error("⚠️ API_MAPPER no está configurado");
|
|
67
|
+
}
|
|
56
68
|
|
|
57
69
|
const configs = {
|
|
58
70
|
default: {
|
|
59
|
-
baseURL: API_MAPPER
|
|
71
|
+
baseURL: API_MAPPER?.default?.baseURL || '',
|
|
60
72
|
headers: {
|
|
61
|
-
["X-Tenant"]: API_MAPPER
|
|
62
|
-
["X-User"]: API_MAPPER
|
|
63
|
-
["X-Api-Key"]: API_MAPPER
|
|
73
|
+
["X-Tenant"]: API_MAPPER?.default?.headers?.["X-Tenant"] || '',
|
|
74
|
+
["X-User"]: API_MAPPER?.default?.headers?.["X-User"] || '',
|
|
75
|
+
["X-Api-Key"]: API_MAPPER?.default?.headers?.["X-Api-Key"] || '',
|
|
64
76
|
["X-Origin"]: "sysone-api-mapper"
|
|
65
77
|
},
|
|
66
78
|
},
|
|
67
79
|
cnp: {
|
|
68
|
-
baseURL: API_MAPPER
|
|
80
|
+
baseURL: API_MAPPER?.cnp?.baseURL || '',
|
|
69
81
|
headers: {
|
|
70
|
-
["X-Channel"]: API_MAPPER
|
|
71
|
-
["X-Agent"]: API_MAPPER
|
|
72
|
-
["X-Client"]: API_MAPPER
|
|
73
|
-
["Ocp-Apim-Subscription-Key"]: API_MAPPER
|
|
82
|
+
["X-Channel"]: API_MAPPER?.cnp?.headers?.["X-Channel"] || '',
|
|
83
|
+
["X-Agent"]: API_MAPPER?.cnp?.headers?.["X-Agent"] || '',
|
|
84
|
+
["X-Client"]: API_MAPPER?.cnp?.headers?.["X-Client"] || '',
|
|
85
|
+
["Ocp-Apim-Subscription-Key"]: API_MAPPER?.cnp?.headers?.["Ocp-Apim-Subscription-Key"] || '',
|
|
74
86
|
["X-Origin"]: "sysone-api-mapper",
|
|
75
|
-
["X-Sales-Agent"]: API_MAPPER
|
|
76
|
-
["X-Sales-Channel"]: API_MAPPER
|
|
87
|
+
["X-Sales-Agent"]: API_MAPPER?.cnp?.headers?.["X-Agent"] || '',
|
|
88
|
+
["X-Sales-Channel"]: API_MAPPER?.cnp?.headers?.["X-Agent"] || '',
|
|
77
89
|
},
|
|
78
90
|
},
|
|
79
91
|
};
|
|
80
92
|
|
|
81
|
-
|
|
93
|
+
console.log("🔧 Configs inicializados:", configs);
|
|
82
94
|
|
|
83
95
|
export const apiMapper = async (
|
|
84
96
|
endpointCode,
|
|
@@ -110,6 +122,7 @@ export const apiMapper = async (
|
|
|
110
122
|
...additionalHeaders,
|
|
111
123
|
}
|
|
112
124
|
};
|
|
125
|
+
console.log("🔵 Usando configuración CNP:", config);
|
|
113
126
|
} else {
|
|
114
127
|
config = {
|
|
115
128
|
...configs.default,
|
|
@@ -120,6 +133,7 @@ export const apiMapper = async (
|
|
|
120
133
|
...additionalHeaders
|
|
121
134
|
},
|
|
122
135
|
};
|
|
136
|
+
console.log("🟢 Usando configuración DEFAULT para tenant:", tenant);
|
|
123
137
|
}
|
|
124
138
|
|
|
125
139
|
config = {
|
|
@@ -128,6 +142,8 @@ export const apiMapper = async (
|
|
|
128
142
|
};
|
|
129
143
|
|
|
130
144
|
const url = getUrl(endpointData.url, routeParams);
|
|
145
|
+
console.log("🌐 URL construida:", url);
|
|
146
|
+
console.log("📤 Request config:", config);
|
|
131
147
|
|
|
132
148
|
let response;
|
|
133
149
|
let request;
|
|
@@ -150,11 +166,13 @@ export const apiMapper = async (
|
|
|
150
166
|
});
|
|
151
167
|
return endpointData.responseMapper(response.data);
|
|
152
168
|
case methods.PUT:
|
|
153
|
-
|
|
154
|
-
response = await axiosInstance.put(url, params);
|
|
169
|
+
response = await axiosInstance.put(url, params, config);
|
|
155
170
|
return endpointData.responseMapper(response.data);
|
|
156
171
|
case methods.DELETE:
|
|
157
|
-
response = await axiosInstance.delete(url,
|
|
172
|
+
response = await axiosInstance.delete(url, {
|
|
173
|
+
...config,
|
|
174
|
+
data: params
|
|
175
|
+
});
|
|
158
176
|
return endpointData.responseMapper(response.data);
|
|
159
177
|
default:
|
|
160
178
|
response = null;
|
|
@@ -163,6 +181,7 @@ export const apiMapper = async (
|
|
|
163
181
|
);
|
|
164
182
|
}
|
|
165
183
|
} catch (e) {
|
|
184
|
+
console.error("❌ Error en apiMapper:", e);
|
|
166
185
|
throw e;
|
|
167
186
|
}
|
|
168
187
|
};
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
quotationStandardPlanCreationMapped,
|
|
35
35
|
quotationVariablePlanCreationMapped
|
|
36
36
|
} from "./modules/quotation";
|
|
37
|
+
import { getRequest_Params } from "./modules/request";
|
|
37
38
|
|
|
38
39
|
export const methods = {
|
|
39
40
|
GET: "GET",
|
|
@@ -648,6 +649,23 @@ const quotationModule = {
|
|
|
648
649
|
// REQUEST MODULE
|
|
649
650
|
// ============================================================================
|
|
650
651
|
const requestModule = {
|
|
652
|
+
GET_REQUESTS_LOOKUP: {
|
|
653
|
+
default: {
|
|
654
|
+
url: 'request/v1/requests',
|
|
655
|
+
method: methods.GET,
|
|
656
|
+
source: 'https://apidoc.sysone.com/quotation/v1/open-api.html#/paths/~1v1~1quotations/get',
|
|
657
|
+
requestMapper: (request) => ({ mappedParams: request }),
|
|
658
|
+
responseMapper: (response) => response
|
|
659
|
+
},
|
|
660
|
+
cnp: {
|
|
661
|
+
url: 'request/v1/request/savings',
|
|
662
|
+
method: methods.GET,
|
|
663
|
+
requestMapper: request => ({ mappedParams: getRequest_Params(request) }),
|
|
664
|
+
responseMapper: (response) => response
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
|
|
668
|
+
|
|
651
669
|
POST_SEND_REQUEST: {
|
|
652
670
|
cnp: {
|
|
653
671
|
url: '/request/v1/request/savings',
|