sysone-api-mapper 1.0.148 → 1.0.149
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 → dist/axiosInstance.js} +5 -7
- package/dist/index.d.ts +2 -2
- package/{index.ts → dist/index.js} +7 -20
- package/dist/services.js +92 -0
- package/dist/servicesData.js +996 -0
- package/dist/src/adapters/createApiAdapter.js +8 -0
- package/{src → dist/src}/adapters/financeAdapter.js +4 -5
- package/{src → dist/src}/adapters/locationAdapter.js +5 -6
- package/{src → dist/src}/adapters/partyAdapter.js +7 -8
- package/{src → dist/src}/components/notificationToast.js +35 -37
- package/dist/src/contexts/actionsContext.js +43 -0
- package/{src → dist/src}/contexts/apiContext.js +8 -9
- package/dist/src/contexts/translationContext.js +19 -0
- package/dist/src/mapper/Mapper.js +98 -0
- package/{src → dist/src}/mapper/endpointsConfig.js +821 -915
- package/{src → dist/src}/mapper/helpers/mappingHelpers.js +24 -26
- package/{src → dist/src}/mapper/modules/billing/index.js +128 -131
- package/{src → dist/src}/mapper/modules/claim/index.js +15 -17
- package/{src → dist/src}/mapper/modules/general/index.js +6 -7
- package/{src → dist/src}/mapper/modules/party/index.js +119 -128
- package/dist/src/mapper/modules/policy/index.js +573 -0
- package/dist/src/mapper/modules/quotation/index.js +477 -0
- package/{src → dist/src}/mapper/modules/request/index.js +60 -67
- package/dist/src/public/index.js +7 -0
- package/{src → dist/src}/server.js +18 -23
- package/package.json +3 -3
- package/.babelrc +0 -4
- package/.gitlab-ci.yml +0 -42
- package/config/dist/index.js +0 -307
- package/config/dist/index.js.LICENSE.txt +0 -1
- package/config/dist/index.ts +0 -319
- package/config/webpack.dev.js +0 -63
- package/config/webpack.prod.js +0 -63
- package/index.d.ts +0 -5
- package/services.js +0 -105
- package/servicesData.js +0 -1013
- package/src/adapters/createApiAdapter.ts +0 -29
- package/src/contexts/actionsContext.js +0 -54
- package/src/contexts/translationContext.js +0 -29
- package/src/mapper/Mapper.js +0 -141
- package/src/mapper/modules/policy/index.js +0 -613
- package/src/mapper/modules/quotation/index.js +0 -480
- package/src/public/index.html +0 -15
- package/src/public/index.js +0 -9
- package/test/script.js +0 -0
- package/tsconfig.json +0 -9
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { financeAdapter } from "./financeAdapter";
|
|
2
|
-
import { locationAdapter } from "./locationAdapter";
|
|
3
|
-
import { partyAdapter } from "./partyAdapter";
|
|
4
|
-
|
|
5
|
-
export interface Api {
|
|
6
|
-
finance: {
|
|
7
|
-
getCurrencies: () => Promise<any>;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
party: {
|
|
11
|
-
getGenders: () => Promise<any>,
|
|
12
|
-
getMaritalStatus: () => Promise<any>,
|
|
13
|
-
getActivity: () => Promise<any>,
|
|
14
|
-
getIdentificationTypes: (country: string) => Promise<any>,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
location: {
|
|
18
|
-
getCountries: () => Promise<any>;
|
|
19
|
-
getProvinces: (country: string) => Promise<any>;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const createApiAdapter = (tenant = 'default'): Api => ({
|
|
24
|
-
finance: financeAdapter(tenant),
|
|
25
|
-
party: partyAdapter(tenant),
|
|
26
|
-
location: locationAdapter(tenant)
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useState, useEffect } from "react";
|
|
2
|
-
|
|
3
|
-
const ActionsContext = createContext();
|
|
4
|
-
|
|
5
|
-
export function useActions() {
|
|
6
|
-
return useContext(ActionsContext);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function ActionsProvider({ initialData, children }) {
|
|
10
|
-
const [actions, setActions] = useState([]);
|
|
11
|
-
const [ready, setReady] = useState(false);
|
|
12
|
-
|
|
13
|
-
let actns = [];
|
|
14
|
-
const extractActions = (menus) => {
|
|
15
|
-
menus.map((m) => {
|
|
16
|
-
if (m.actions) {
|
|
17
|
-
actns = [
|
|
18
|
-
...actns,
|
|
19
|
-
...m.actions.map((a) => {
|
|
20
|
-
return {
|
|
21
|
-
code: a.code,
|
|
22
|
-
name: a.name,
|
|
23
|
-
path: a.path,
|
|
24
|
-
menuCode: m.code,
|
|
25
|
-
};
|
|
26
|
-
}),
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
if (m.menus) extractActions(m.menus);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return actns;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
extractActions(initialData.menus);
|
|
37
|
-
setActions(actns);
|
|
38
|
-
setReady(true);
|
|
39
|
-
}, []);
|
|
40
|
-
|
|
41
|
-
const hasAction = (key) => {
|
|
42
|
-
const menuCode = key.split(".")[0];
|
|
43
|
-
const actionCode = key.split(".")[1];
|
|
44
|
-
return actions.some(
|
|
45
|
-
(el) => el.menuCode === menuCode && el.code === actionCode
|
|
46
|
-
);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<ActionsContext.Provider value={{ actions, hasAction, ready }}>
|
|
51
|
-
{children}
|
|
52
|
-
</ActionsContext.Provider>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useState } from "react";
|
|
2
|
-
|
|
3
|
-
const TranslationContext = createContext();
|
|
4
|
-
|
|
5
|
-
export function useTranslation() {
|
|
6
|
-
return useContext(TranslationContext);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function TranslationProvider({ initialData, children }) {
|
|
10
|
-
const [translations, setTranslationes] = useState(initialData);
|
|
11
|
-
|
|
12
|
-
const t = (key, ...args) => {
|
|
13
|
-
if (!translations) return key;
|
|
14
|
-
let translation =
|
|
15
|
-
translations.find(
|
|
16
|
-
(el) => el.code.toLowerCase().trim() === key.toLowerCase().trim()
|
|
17
|
-
)?.content || key;
|
|
18
|
-
args.forEach(
|
|
19
|
-
(a, index) => (translation = translation.replace(`#${index}#`, a))
|
|
20
|
-
);
|
|
21
|
-
return translation;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<TranslationContext.Provider value={{ translations, t }}>
|
|
26
|
-
{children}
|
|
27
|
-
</TranslationContext.Provider>
|
|
28
|
-
);
|
|
29
|
-
}
|
package/src/mapper/Mapper.js
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import axiosInstance from "../../axiosInstance";
|
|
2
|
-
import { methods, tenantsConfig } from "./endpointsConfig";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
let apiConfig = null;
|
|
6
|
-
|
|
7
|
-
export const configureApiMapper = (config) => {
|
|
8
|
-
apiConfig = {
|
|
9
|
-
...apiConfig,
|
|
10
|
-
...config,
|
|
11
|
-
headers: {
|
|
12
|
-
...(apiConfig?.headers || {}),
|
|
13
|
-
...(config?.headers || {}),
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const getConfig = () => {
|
|
19
|
-
if (!apiConfig) {
|
|
20
|
-
throw new Error(
|
|
21
|
-
"apiMapper not configured. Call configureApiMapper() first."
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
return apiConfig;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Normaliza tenant (ej: "cnp/foo" → "cnp")
|
|
29
|
-
*/
|
|
30
|
-
const normalizeTenant = (tenant) => {
|
|
31
|
-
if (!tenant || typeof tenant !== "string") return tenant;
|
|
32
|
-
return tenant.split("/")[0];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const getUrl = (serviceUrl, routeParams) => {
|
|
36
|
-
if (!routeParams || routeParams.length === 0) return serviceUrl;
|
|
37
|
-
|
|
38
|
-
return serviceUrl.replace(/{(\d+)}/g, (match, index) =>
|
|
39
|
-
routeParams[index] !== undefined ? routeParams[index] : match
|
|
40
|
-
);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export const apiMapper = async (
|
|
45
|
-
endpointCode,
|
|
46
|
-
tenant,
|
|
47
|
-
routeParams,
|
|
48
|
-
params = null,
|
|
49
|
-
additionalHeaders = {}
|
|
50
|
-
) => {
|
|
51
|
-
/* -------- Endpoint config -------- */
|
|
52
|
-
|
|
53
|
-
const configData = tenantsConfig[endpointCode];
|
|
54
|
-
if (!configData) {
|
|
55
|
-
throw new Error(`Endpoint no configurado: ${endpointCode}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const normalizedTenant = normalizeTenant(tenant);
|
|
59
|
-
|
|
60
|
-
const endpointData =
|
|
61
|
-
configData[normalizedTenant] ?? configData.default;
|
|
62
|
-
|
|
63
|
-
if (!endpointData) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`No hay configuración para endpoint ${endpointCode} y tenant ${normalizedTenant}`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/* -------- Axios config -------- */
|
|
70
|
-
|
|
71
|
-
const { baseURL, headers } = getConfig();
|
|
72
|
-
|
|
73
|
-
const axiosConfig = {
|
|
74
|
-
baseURL,
|
|
75
|
-
headers: {
|
|
76
|
-
...headers,
|
|
77
|
-
...additionalHeaders,
|
|
78
|
-
},
|
|
79
|
-
validateStatus: (s) => s < 500,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const url = getUrl(endpointData.url, routeParams);
|
|
83
|
-
|
|
84
|
-
/* -------- Request -------- */
|
|
85
|
-
|
|
86
|
-
switch (endpointData.method) {
|
|
87
|
-
case methods.GET: {
|
|
88
|
-
const {
|
|
89
|
-
mappedParams,
|
|
90
|
-
responseType,
|
|
91
|
-
headers: requestHeaders,
|
|
92
|
-
...otherOptions
|
|
93
|
-
} = endpointData.requestMapper(params);
|
|
94
|
-
|
|
95
|
-
const response = await axiosInstance.get(url, {
|
|
96
|
-
...axiosConfig,
|
|
97
|
-
params: mappedParams,
|
|
98
|
-
responseType,
|
|
99
|
-
headers: {
|
|
100
|
-
...axiosConfig.headers,
|
|
101
|
-
...requestHeaders,
|
|
102
|
-
},
|
|
103
|
-
...otherOptions,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
return endpointData.responseMapper(response);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
case methods.POST: {
|
|
110
|
-
const { mappedPostParams, mappedBody, headers: requestHeaders } =
|
|
111
|
-
endpointData.requestMapper(params);
|
|
112
|
-
|
|
113
|
-
const response = await axiosInstance.post(url, mappedBody, {
|
|
114
|
-
...axiosConfig,
|
|
115
|
-
params: mappedPostParams,
|
|
116
|
-
headers: {
|
|
117
|
-
...axiosConfig.headers,
|
|
118
|
-
...requestHeaders,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
return endpointData.responseMapper(response.data);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
case methods.PUT: {
|
|
126
|
-
const response = await axiosInstance.put(url, params, axiosConfig);
|
|
127
|
-
return endpointData.responseMapper(response.data);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
case methods.DELETE: {
|
|
131
|
-
const response = await axiosInstance.delete(url, {
|
|
132
|
-
...axiosConfig,
|
|
133
|
-
data: params,
|
|
134
|
-
});
|
|
135
|
-
return endpointData.responseMapper(response.data);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
default:
|
|
139
|
-
throw new Error("HTTP method not supported");
|
|
140
|
-
}
|
|
141
|
-
};
|