sysone-api-mapper 1.0.135 → 1.0.137
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 +2 -1
- package/src/mapper/Mapper.js +20 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sysone-api-mapper",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.137",
|
|
4
4
|
"description": "Paquete mapper para portal de productores",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
18
18
|
"@babel/preset-env": "^7.20.2",
|
|
19
19
|
"@babel/preset-react": "^7.18.6",
|
|
20
|
+
"@sysone/components": "^1.0.166-dev",
|
|
20
21
|
"antd": "^4.21.4",
|
|
21
22
|
"axios": "^1.6.0",
|
|
22
23
|
"babel-loader": "^9.1.2",
|
package/src/mapper/Mapper.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import axiosInstance from "../../axiosInstance";
|
|
2
2
|
import { methods, tenantsConfig } from "./endpointsConfig";
|
|
3
|
+
import {
|
|
4
|
+
SecurityManager,
|
|
5
|
+
} from "@sysone/components";
|
|
3
6
|
|
|
4
7
|
const getApiMapperConfig = () => {
|
|
5
8
|
// 1. Intentar desde variables de entorno compiladas (Webpack DefinePlugin)
|
|
@@ -30,22 +33,18 @@ const getApiMapperConfig = () => {
|
|
|
30
33
|
};
|
|
31
34
|
|
|
32
35
|
const getSalesAgent = () => {
|
|
33
|
-
return
|
|
34
|
-
window.__INTERMEDIARY_CODE__ ||
|
|
35
|
-
null;
|
|
36
|
+
return SecurityManager.getExtra("salesAgent") || null;
|
|
36
37
|
};
|
|
37
38
|
|
|
38
39
|
const getSalesChannel = () => {
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
null;
|
|
40
|
+
return SecurityManager.getExtra("salesAgent") || null;
|
|
41
|
+
// si "sales-channel" no tiene su propio campo en extras, usa el mismo que agent
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
const getDynamicHeaders = (tenant) => {
|
|
45
45
|
if (tenant === "cnp") {
|
|
46
46
|
// Intenta obtener el X-Agent de localStorage (inyectado desde el front)
|
|
47
|
-
const xAgent =
|
|
48
|
-
window.__INTERMEDIARY_CODE__ ||
|
|
47
|
+
const xAgent = SecurityManager.getExtra("intermediaryCode") ||
|
|
49
48
|
configs.cnp.headers["X-Agent"];
|
|
50
49
|
|
|
51
50
|
const salesCode = getSalesAgent();
|
|
@@ -99,6 +98,13 @@ const getUrl = (serviceUrl, routeParams) => {
|
|
|
99
98
|
});
|
|
100
99
|
};
|
|
101
100
|
|
|
101
|
+
const normalizeTenant = (tenant) => {
|
|
102
|
+
if (!tenant || typeof tenant !== "string") return tenant;
|
|
103
|
+
|
|
104
|
+
// Toma solo lo que está antes del primer "/"
|
|
105
|
+
return tenant.split("/")[0];
|
|
106
|
+
};
|
|
107
|
+
|
|
102
108
|
|
|
103
109
|
export const apiMapper = async (
|
|
104
110
|
endpointCode,
|
|
@@ -109,10 +115,11 @@ export const apiMapper = async (
|
|
|
109
115
|
) => {
|
|
110
116
|
try {
|
|
111
117
|
const configData = tenantsConfig[endpointCode];
|
|
118
|
+
const normalizedTenant = normalizeTenant(tenant);
|
|
112
119
|
if (!configData)
|
|
113
120
|
throw new Error(`Endpoint no configurado: ${endpointCode}`);
|
|
114
121
|
|
|
115
|
-
const endpointData = configData[
|
|
122
|
+
const endpointData = configData[normalizedTenant] ?? configData.default;
|
|
116
123
|
|
|
117
124
|
if (endpointData === null) {
|
|
118
125
|
console.warn(`⚠️ No hay configuración para el endpoint ${endpointCode} y tenant ${tenant}, y no existe configuración por defecto.`);
|
|
@@ -125,9 +132,9 @@ export const apiMapper = async (
|
|
|
125
132
|
throw new Error("No se pudo cargar la configuración del API Mapper");
|
|
126
133
|
}
|
|
127
134
|
|
|
128
|
-
const dynamicHeaders = getDynamicHeaders(
|
|
135
|
+
const dynamicHeaders = getDynamicHeaders(normalizedTenant);
|
|
129
136
|
|
|
130
|
-
if (
|
|
137
|
+
if (normalizedTenant === "cnp") {
|
|
131
138
|
config = {
|
|
132
139
|
...configs.cnp,
|
|
133
140
|
headers: {
|
|
@@ -141,8 +148,8 @@ export const apiMapper = async (
|
|
|
141
148
|
...configs.default,
|
|
142
149
|
headers: {
|
|
143
150
|
...configs.default.headers,
|
|
144
|
-
["X-Tenant"]:
|
|
145
|
-
["X-User"]:
|
|
151
|
+
["X-Tenant"]: normalizedTenant,
|
|
152
|
+
["X-User"]: normalizedTenant,
|
|
146
153
|
...additionalHeaders
|
|
147
154
|
},
|
|
148
155
|
};
|