sysone-api-mapper 1.0.147 → 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 +4 -4
- 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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { financeAdapter } from "./financeAdapter";
|
|
2
|
+
import { locationAdapter } from "./locationAdapter";
|
|
3
|
+
import { partyAdapter } from "./partyAdapter";
|
|
4
|
+
export const createApiAdapter = (tenant = 'default') => ({
|
|
5
|
+
finance: financeAdapter(tenant),
|
|
6
|
+
party: partyAdapter(tenant),
|
|
7
|
+
location: locationAdapter(tenant)
|
|
8
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { apiMapper } from "../mapper/Mapper";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
1
|
+
import { apiMapper } from "../mapper/Mapper";
|
|
2
|
+
export const financeAdapter = (tenant) => ({
|
|
3
|
+
getCurrencies: () => apiMapper("GET_CURRENCIES", tenant),
|
|
4
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { apiMapper } from "../mapper/Mapper";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
});
|
|
1
|
+
import { apiMapper } from "../mapper/Mapper";
|
|
2
|
+
export const locationAdapter = (tenant) => ({
|
|
3
|
+
getCountries: () => apiMapper("GET_COUNTRIES", tenant),
|
|
4
|
+
getProvinces: (countryCode) => apiMapper("GET_PROVINCES", tenant, [countryCode]),
|
|
5
|
+
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { apiMapper } from "../mapper/Mapper";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
1
|
+
import { apiMapper } from "../mapper/Mapper";
|
|
2
|
+
export const partyAdapter = (tenant) => ({
|
|
3
|
+
getGenders: () => apiMapper("GET_GENDERS", tenant),
|
|
4
|
+
getMaritalStatus: () => apiMapper("GET_MARITAL_STATUS", tenant),
|
|
5
|
+
getActivity: () => apiMapper("GET_ACTIVITY", tenant),
|
|
6
|
+
getIdentificationTypes: (countryCode) => apiMapper("GET_IDENTIFICATION_TYPES", tenant, [countryCode]),
|
|
7
|
+
});
|
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
// import
|
|
3
|
-
|
|
4
|
-
// const TYPE = {
|
|
5
|
-
// SUCCESS: "success",
|
|
6
|
-
// ERROR: "error",
|
|
7
|
-
// INFO: "info",
|
|
8
|
-
// WARNING: "warning",
|
|
9
|
-
// };
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// <
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
// )
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
//
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
// };
|
|
37
|
-
// export { openNotificationWithIcon, TYPE };
|
|
1
|
+
"use strict";
|
|
2
|
+
// import React from "react";
|
|
3
|
+
// import { notification } from "antd";
|
|
4
|
+
// const TYPE = {
|
|
5
|
+
// SUCCESS: "success",
|
|
6
|
+
// ERROR: "error",
|
|
7
|
+
// INFO: "info",
|
|
8
|
+
// WARNING: "warning",
|
|
9
|
+
// };
|
|
10
|
+
// const openNotificationWithIcon = (type, message, description, subErrors) => {
|
|
11
|
+
// return notification[type]({
|
|
12
|
+
// message,
|
|
13
|
+
// style: {
|
|
14
|
+
// minHeight:
|
|
15
|
+
// description || (subErrors && subErrors.length > 0) ? "0" : "70px",
|
|
16
|
+
// },
|
|
17
|
+
// description: (
|
|
18
|
+
// <>
|
|
19
|
+
// {description ? (
|
|
20
|
+
// <>
|
|
21
|
+
// <div style={{ fontSize: "13px" }}>{description}</div>
|
|
22
|
+
// <br />
|
|
23
|
+
// </>
|
|
24
|
+
// ) : null}
|
|
25
|
+
// {subErrors?.map((e, idx) => (
|
|
26
|
+
// <React.Fragment key={`sub_error_${idx}`}>
|
|
27
|
+
// <div style={{ fontSize: "16px" }}>- {e}</div>
|
|
28
|
+
// <br />
|
|
29
|
+
// </React.Fragment>
|
|
30
|
+
// ))}
|
|
31
|
+
// </>
|
|
32
|
+
// ),
|
|
33
|
+
// });
|
|
34
|
+
// };
|
|
35
|
+
// export { openNotificationWithIcon, TYPE };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, useEffect } from "react";
|
|
2
|
+
const ActionsContext = createContext();
|
|
3
|
+
export function useActions() {
|
|
4
|
+
return useContext(ActionsContext);
|
|
5
|
+
}
|
|
6
|
+
export function ActionsProvider({ initialData, children }) {
|
|
7
|
+
const [actions, setActions] = useState([]);
|
|
8
|
+
const [ready, setReady] = useState(false);
|
|
9
|
+
let actns = [];
|
|
10
|
+
const extractActions = (menus) => {
|
|
11
|
+
menus.map((m) => {
|
|
12
|
+
if (m.actions) {
|
|
13
|
+
actns = [
|
|
14
|
+
...actns,
|
|
15
|
+
...m.actions.map((a) => {
|
|
16
|
+
return {
|
|
17
|
+
code: a.code,
|
|
18
|
+
name: a.name,
|
|
19
|
+
path: a.path,
|
|
20
|
+
menuCode: m.code,
|
|
21
|
+
};
|
|
22
|
+
}),
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
if (m.menus)
|
|
26
|
+
extractActions(m.menus);
|
|
27
|
+
});
|
|
28
|
+
return actns;
|
|
29
|
+
};
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
extractActions(initialData.menus);
|
|
32
|
+
setActions(actns);
|
|
33
|
+
setReady(true);
|
|
34
|
+
}, []);
|
|
35
|
+
const hasAction = (key) => {
|
|
36
|
+
const menuCode = key.split(".")[0];
|
|
37
|
+
const actionCode = key.split(".")[1];
|
|
38
|
+
return actions.some((el) => el.menuCode === menuCode && el.code === actionCode);
|
|
39
|
+
};
|
|
40
|
+
return (<ActionsContext.Provider value={{ actions, hasAction, ready }}>
|
|
41
|
+
{children}
|
|
42
|
+
</ActionsContext.Provider>);
|
|
43
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react';
|
|
2
|
-
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export const ApiContext = createContext(null);
|
|
3
|
+
export const useApi = () => {
|
|
4
|
+
const ctx = useContext(ApiContext);
|
|
5
|
+
if (!ctx)
|
|
6
|
+
throw new Error("ApiContext not found");
|
|
7
|
+
return ctx;
|
|
8
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState } from "react";
|
|
2
|
+
const TranslationContext = createContext();
|
|
3
|
+
export function useTranslation() {
|
|
4
|
+
return useContext(TranslationContext);
|
|
5
|
+
}
|
|
6
|
+
export function TranslationProvider({ initialData, children }) {
|
|
7
|
+
const [translations, setTranslationes] = useState(initialData);
|
|
8
|
+
const t = (key, ...args) => {
|
|
9
|
+
var _a;
|
|
10
|
+
if (!translations)
|
|
11
|
+
return key;
|
|
12
|
+
let translation = ((_a = translations.find((el) => el.code.toLowerCase().trim() === key.toLowerCase().trim())) === null || _a === void 0 ? void 0 : _a.content) || key;
|
|
13
|
+
args.forEach((a, index) => (translation = translation.replace(`#${index}#`, a)));
|
|
14
|
+
return translation;
|
|
15
|
+
};
|
|
16
|
+
return (<TranslationContext.Provider value={{ translations, t }}>
|
|
17
|
+
{children}
|
|
18
|
+
</TranslationContext.Provider>);
|
|
19
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import axiosInstance from "../../axiosInstance";
|
|
2
|
+
import { methods, tenantsConfig } from "./endpointsConfig";
|
|
3
|
+
let apiConfig = null;
|
|
4
|
+
export const configureApiMapper = (config) => {
|
|
5
|
+
apiConfig = {
|
|
6
|
+
...apiConfig,
|
|
7
|
+
...config,
|
|
8
|
+
headers: {
|
|
9
|
+
...((apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.headers) || {}),
|
|
10
|
+
...((config === null || config === void 0 ? void 0 : config.headers) || {}),
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const getConfig = () => {
|
|
15
|
+
if (!apiConfig) {
|
|
16
|
+
throw new Error("apiMapper not configured. Call configureApiMapper() first.");
|
|
17
|
+
}
|
|
18
|
+
return apiConfig;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Normaliza tenant (ej: "cnp/foo" → "cnp")
|
|
22
|
+
*/
|
|
23
|
+
const normalizeTenant = (tenant) => {
|
|
24
|
+
if (!tenant || typeof tenant !== "string")
|
|
25
|
+
return tenant;
|
|
26
|
+
return tenant.split("/")[0];
|
|
27
|
+
};
|
|
28
|
+
const getUrl = (serviceUrl, routeParams) => {
|
|
29
|
+
if (!routeParams || routeParams.length === 0)
|
|
30
|
+
return serviceUrl;
|
|
31
|
+
return serviceUrl.replace(/{(\d+)}/g, (match, index) => routeParams[index] !== undefined ? routeParams[index] : match);
|
|
32
|
+
};
|
|
33
|
+
export const apiMapper = async (endpointCode, tenant, routeParams, params = null, additionalHeaders = {}) => {
|
|
34
|
+
/* -------- Endpoint config -------- */
|
|
35
|
+
var _a;
|
|
36
|
+
const configData = tenantsConfig[endpointCode];
|
|
37
|
+
if (!configData) {
|
|
38
|
+
throw new Error(`Endpoint no configurado: ${endpointCode}`);
|
|
39
|
+
}
|
|
40
|
+
const normalizedTenant = normalizeTenant(tenant);
|
|
41
|
+
const endpointData = (_a = configData[normalizedTenant]) !== null && _a !== void 0 ? _a : configData.default;
|
|
42
|
+
if (!endpointData) {
|
|
43
|
+
throw new Error(`No hay configuración para endpoint ${endpointCode} y tenant ${normalizedTenant}`);
|
|
44
|
+
}
|
|
45
|
+
/* -------- Axios config -------- */
|
|
46
|
+
const { baseURL, headers } = getConfig();
|
|
47
|
+
const axiosConfig = {
|
|
48
|
+
baseURL,
|
|
49
|
+
headers: {
|
|
50
|
+
...headers,
|
|
51
|
+
...additionalHeaders,
|
|
52
|
+
},
|
|
53
|
+
validateStatus: (s) => s < 500,
|
|
54
|
+
};
|
|
55
|
+
const url = getUrl(endpointData.url, routeParams);
|
|
56
|
+
/* -------- Request -------- */
|
|
57
|
+
switch (endpointData.method) {
|
|
58
|
+
case methods.GET: {
|
|
59
|
+
const { mappedParams, responseType, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
|
|
60
|
+
const response = await axiosInstance.get(url, {
|
|
61
|
+
...axiosConfig,
|
|
62
|
+
params: mappedParams,
|
|
63
|
+
responseType,
|
|
64
|
+
headers: {
|
|
65
|
+
...axiosConfig.headers,
|
|
66
|
+
...requestHeaders,
|
|
67
|
+
},
|
|
68
|
+
...otherOptions,
|
|
69
|
+
});
|
|
70
|
+
return endpointData.responseMapper(response);
|
|
71
|
+
}
|
|
72
|
+
case methods.POST: {
|
|
73
|
+
const { mappedPostParams, mappedBody, headers: requestHeaders } = endpointData.requestMapper(params);
|
|
74
|
+
const response = await axiosInstance.post(url, mappedBody, {
|
|
75
|
+
...axiosConfig,
|
|
76
|
+
params: mappedPostParams,
|
|
77
|
+
headers: {
|
|
78
|
+
...axiosConfig.headers,
|
|
79
|
+
...requestHeaders,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
return endpointData.responseMapper(response.data);
|
|
83
|
+
}
|
|
84
|
+
case methods.PUT: {
|
|
85
|
+
const response = await axiosInstance.put(url, params, axiosConfig);
|
|
86
|
+
return endpointData.responseMapper(response.data);
|
|
87
|
+
}
|
|
88
|
+
case methods.DELETE: {
|
|
89
|
+
const response = await axiosInstance.delete(url, {
|
|
90
|
+
...axiosConfig,
|
|
91
|
+
data: params,
|
|
92
|
+
});
|
|
93
|
+
return endpointData.responseMapper(response.data);
|
|
94
|
+
}
|
|
95
|
+
default:
|
|
96
|
+
throw new Error("HTTP method not supported");
|
|
97
|
+
}
|
|
98
|
+
};
|