sysone-api-mapper 1.0.148 → 1.0.150

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.
Files changed (60) hide show
  1. package/dist/axiosInstance.d.ts +2 -1
  2. package/dist/axiosInstance.js +10 -0
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +20 -0
  5. package/dist/services.js +100 -0
  6. package/dist/servicesData.js +999 -0
  7. package/dist/src/adapters/createApiAdapter.d.ts +1 -0
  8. package/dist/src/adapters/createApiAdapter.js +12 -0
  9. package/dist/src/adapters/financeAdapter.d.ts +1 -0
  10. package/dist/src/adapters/financeAdapter.js +9 -0
  11. package/dist/src/adapters/locationAdapter.js +9 -0
  12. package/dist/src/adapters/partyAdapter.js +11 -0
  13. package/{src → dist/src}/components/notificationToast.js +35 -37
  14. package/dist/src/contexts/actionsContext.js +80 -0
  15. package/dist/src/contexts/apiContext.js +12 -0
  16. package/dist/src/contexts/translationContext.js +56 -0
  17. package/dist/src/mapper/Mapper.js +106 -0
  18. package/{src → dist/src}/mapper/endpointsConfig.js +824 -915
  19. package/dist/src/mapper/helpers/mappingHelpers.js +30 -0
  20. package/dist/src/mapper/modules/billing/index.js +136 -0
  21. package/dist/src/mapper/modules/claim/index.js +19 -0
  22. package/dist/src/mapper/modules/general/index.js +11 -0
  23. package/dist/src/mapper/modules/party/index.js +131 -0
  24. package/dist/src/mapper/modules/policy/index.js +592 -0
  25. package/dist/src/mapper/modules/quotation/index.js +494 -0
  26. package/{src → dist/src}/mapper/modules/request/index.js +65 -67
  27. package/dist/src/public/index.js +7 -0
  28. package/{src → dist/src}/server.js +18 -23
  29. package/package.json +3 -3
  30. package/.babelrc +0 -4
  31. package/.gitlab-ci.yml +0 -42
  32. package/axiosInstance.js +0 -7
  33. package/config/dist/index.js +0 -307
  34. package/config/dist/index.js.LICENSE.txt +0 -1
  35. package/config/dist/index.ts +0 -319
  36. package/config/webpack.dev.js +0 -63
  37. package/config/webpack.prod.js +0 -63
  38. package/index.d.ts +0 -5
  39. package/index.ts +0 -20
  40. package/services.js +0 -105
  41. package/servicesData.js +0 -1013
  42. package/src/adapters/createApiAdapter.ts +0 -29
  43. package/src/adapters/financeAdapter.js +0 -5
  44. package/src/adapters/locationAdapter.js +0 -6
  45. package/src/adapters/partyAdapter.js +0 -8
  46. package/src/contexts/actionsContext.js +0 -54
  47. package/src/contexts/apiContext.js +0 -9
  48. package/src/contexts/translationContext.js +0 -29
  49. package/src/mapper/Mapper.js +0 -141
  50. package/src/mapper/helpers/mappingHelpers.js +0 -26
  51. package/src/mapper/modules/billing/index.js +0 -131
  52. package/src/mapper/modules/claim/index.js +0 -17
  53. package/src/mapper/modules/general/index.js +0 -7
  54. package/src/mapper/modules/party/index.js +0 -128
  55. package/src/mapper/modules/policy/index.js +0 -613
  56. package/src/mapper/modules/quotation/index.js +0 -480
  57. package/src/public/index.html +0 -15
  58. package/src/public/index.js +0 -9
  59. package/test/script.js +0 -0
  60. package/tsconfig.json +0 -9
@@ -1,6 +1,7 @@
1
1
  export interface Api {
2
2
  finance: {
3
3
  getCurrencies: () => Promise<any>;
4
+ getPaymentFrecuencies: () => Promise<any>;
4
5
  };
5
6
  party: {
6
7
  getGenders: () => Promise<any>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createApiAdapter = void 0;
4
+ const financeAdapter_1 = require("./financeAdapter");
5
+ const locationAdapter_1 = require("./locationAdapter");
6
+ const partyAdapter_1 = require("./partyAdapter");
7
+ const createApiAdapter = (tenant = 'default') => ({
8
+ finance: (0, financeAdapter_1.financeAdapter)(tenant),
9
+ party: (0, partyAdapter_1.partyAdapter)(tenant),
10
+ location: (0, locationAdapter_1.locationAdapter)(tenant)
11
+ });
12
+ exports.createApiAdapter = createApiAdapter;
@@ -1,3 +1,4 @@
1
1
  export function financeAdapter(tenant: any): {
2
2
  getCurrencies: () => Promise<any>;
3
+ getPaymentFrecuencies: () => Promise<any>;
3
4
  };
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.financeAdapter = void 0;
4
+ const Mapper_1 = require("../mapper/Mapper");
5
+ const financeAdapter = (tenant) => ({
6
+ getCurrencies: () => (0, Mapper_1.apiMapper)("GET_CURRENCIES", tenant),
7
+ getPaymentFrecuencies: () => (0, Mapper_1.apiMapper)("GET_PAYMENT_FRECUENCIES", tenant)
8
+ });
9
+ exports.financeAdapter = financeAdapter;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.locationAdapter = void 0;
4
+ const Mapper_1 = require("../mapper/Mapper");
5
+ const locationAdapter = (tenant) => ({
6
+ getCountries: () => (0, Mapper_1.apiMapper)("GET_COUNTRIES", tenant),
7
+ getProvinces: (countryCode) => (0, Mapper_1.apiMapper)("GET_PROVINCES", tenant, [countryCode]),
8
+ });
9
+ exports.locationAdapter = locationAdapter;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.partyAdapter = void 0;
4
+ const Mapper_1 = require("../mapper/Mapper");
5
+ const partyAdapter = (tenant) => ({
6
+ getGenders: () => (0, Mapper_1.apiMapper)("GET_GENDERS", tenant),
7
+ getMaritalStatus: () => (0, Mapper_1.apiMapper)("GET_MARITAL_STATUS", tenant),
8
+ getActivity: () => (0, Mapper_1.apiMapper)("GET_ACTIVITY", tenant),
9
+ getIdentificationTypes: (countryCode) => (0, Mapper_1.apiMapper)("GET_IDENTIFICATION_TYPES", tenant, [countryCode]),
10
+ });
11
+ exports.partyAdapter = partyAdapter;
@@ -1,37 +1,35 @@
1
- // import React from "react";
2
- // import { notification } from "antd";
3
-
4
- // const TYPE = {
5
- // SUCCESS: "success",
6
- // ERROR: "error",
7
- // INFO: "info",
8
- // WARNING: "warning",
9
- // };
10
-
11
- // const openNotificationWithIcon = (type, message, description, subErrors) => {
12
- // return notification[type]({
13
- // message,
14
- // style: {
15
- // minHeight:
16
- // description || (subErrors && subErrors.length > 0) ? "0" : "70px",
17
- // },
18
- // description: (
19
- // <>
20
- // {description ? (
21
- // <>
22
- // <div style={{ fontSize: "13px" }}>{description}</div>
23
- // <br />
24
- // </>
25
- // ) : null}
26
-
27
- // {subErrors?.map((e, idx) => (
28
- // <React.Fragment key={`sub_error_${idx}`}>
29
- // <div style={{ fontSize: "16px" }}>- {e}</div>
30
- // <br />
31
- // </React.Fragment>
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,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useActions = useActions;
37
+ exports.ActionsProvider = ActionsProvider;
38
+ const react_1 = __importStar(require("react"));
39
+ const ActionsContext = (0, react_1.createContext)();
40
+ function useActions() {
41
+ return (0, react_1.useContext)(ActionsContext);
42
+ }
43
+ function ActionsProvider({ initialData, children }) {
44
+ const [actions, setActions] = (0, react_1.useState)([]);
45
+ const [ready, setReady] = (0, react_1.useState)(false);
46
+ let actns = [];
47
+ const extractActions = (menus) => {
48
+ menus.map((m) => {
49
+ if (m.actions) {
50
+ actns = [
51
+ ...actns,
52
+ ...m.actions.map((a) => {
53
+ return {
54
+ code: a.code,
55
+ name: a.name,
56
+ path: a.path,
57
+ menuCode: m.code,
58
+ };
59
+ }),
60
+ ];
61
+ }
62
+ if (m.menus)
63
+ extractActions(m.menus);
64
+ });
65
+ return actns;
66
+ };
67
+ (0, react_1.useEffect)(() => {
68
+ extractActions(initialData.menus);
69
+ setActions(actns);
70
+ setReady(true);
71
+ }, []);
72
+ const hasAction = (key) => {
73
+ const menuCode = key.split(".")[0];
74
+ const actionCode = key.split(".")[1];
75
+ return actions.some((el) => el.menuCode === menuCode && el.code === actionCode);
76
+ };
77
+ return (<ActionsContext.Provider value={{ actions, hasAction, ready }}>
78
+ {children}
79
+ </ActionsContext.Provider>);
80
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useApi = exports.ApiContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.ApiContext = (0, react_1.createContext)(null);
6
+ const useApi = () => {
7
+ const ctx = (0, react_1.useContext)(exports.ApiContext);
8
+ if (!ctx)
9
+ throw new Error("ApiContext not found");
10
+ return ctx;
11
+ };
12
+ exports.useApi = useApi;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.useTranslation = useTranslation;
37
+ exports.TranslationProvider = TranslationProvider;
38
+ const react_1 = __importStar(require("react"));
39
+ const TranslationContext = (0, react_1.createContext)();
40
+ function useTranslation() {
41
+ return (0, react_1.useContext)(TranslationContext);
42
+ }
43
+ function TranslationProvider({ initialData, children }) {
44
+ const [translations, setTranslationes] = (0, react_1.useState)(initialData);
45
+ const t = (key, ...args) => {
46
+ var _a;
47
+ if (!translations)
48
+ return key;
49
+ let translation = ((_a = translations.find((el) => el.code.toLowerCase().trim() === key.toLowerCase().trim())) === null || _a === void 0 ? void 0 : _a.content) || key;
50
+ args.forEach((a, index) => (translation = translation.replace(`#${index}#`, a)));
51
+ return translation;
52
+ };
53
+ return (<TranslationContext.Provider value={{ translations, t }}>
54
+ {children}
55
+ </TranslationContext.Provider>);
56
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.apiMapper = exports.configureApiMapper = void 0;
7
+ const axiosInstance_1 = __importDefault(require("../../axiosInstance"));
8
+ const endpointsConfig_1 = require("./endpointsConfig");
9
+ let apiConfig = null;
10
+ const configureApiMapper = (config) => {
11
+ apiConfig = {
12
+ ...apiConfig,
13
+ ...config,
14
+ headers: {
15
+ ...((apiConfig === null || apiConfig === void 0 ? void 0 : apiConfig.headers) || {}),
16
+ ...((config === null || config === void 0 ? void 0 : config.headers) || {}),
17
+ },
18
+ };
19
+ };
20
+ exports.configureApiMapper = configureApiMapper;
21
+ const getConfig = () => {
22
+ if (!apiConfig) {
23
+ throw new Error("apiMapper not configured. Call configureApiMapper() first.");
24
+ }
25
+ return apiConfig;
26
+ };
27
+ /**
28
+ * Normaliza tenant (ej: "cnp/foo" → "cnp")
29
+ */
30
+ const normalizeTenant = (tenant) => {
31
+ if (!tenant || typeof tenant !== "string")
32
+ return tenant;
33
+ return tenant.split("/")[0];
34
+ };
35
+ const getUrl = (serviceUrl, routeParams) => {
36
+ if (!routeParams || routeParams.length === 0)
37
+ return serviceUrl;
38
+ return serviceUrl.replace(/{(\d+)}/g, (match, index) => routeParams[index] !== undefined ? routeParams[index] : match);
39
+ };
40
+ const apiMapper = async (endpointCode, tenant, routeParams, params = null, additionalHeaders = {}) => {
41
+ /* -------- Endpoint config -------- */
42
+ var _a;
43
+ const configData = endpointsConfig_1.tenantsConfig[endpointCode];
44
+ if (!configData) {
45
+ throw new Error(`Endpoint no configurado: ${endpointCode}`);
46
+ }
47
+ const normalizedTenant = normalizeTenant(tenant);
48
+ const endpointData = (_a = configData[normalizedTenant]) !== null && _a !== void 0 ? _a : configData.default;
49
+ if (!endpointData) {
50
+ throw new Error(`No hay configuración para endpoint ${endpointCode} y tenant ${normalizedTenant}`);
51
+ }
52
+ /* -------- Axios config -------- */
53
+ const { baseURL, headers } = getConfig();
54
+ const axiosConfig = {
55
+ baseURL,
56
+ headers: {
57
+ ...headers,
58
+ ...additionalHeaders,
59
+ },
60
+ validateStatus: (s) => s < 500,
61
+ };
62
+ const url = getUrl(endpointData.url, routeParams);
63
+ /* -------- Request -------- */
64
+ switch (endpointData.method) {
65
+ case endpointsConfig_1.methods.GET: {
66
+ const { mappedParams, responseType, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
67
+ const response = await axiosInstance_1.default.get(url, {
68
+ ...axiosConfig,
69
+ params: mappedParams,
70
+ responseType,
71
+ headers: {
72
+ ...axiosConfig.headers,
73
+ ...requestHeaders,
74
+ },
75
+ ...otherOptions,
76
+ });
77
+ return endpointData.responseMapper(response);
78
+ }
79
+ case endpointsConfig_1.methods.POST: {
80
+ const { mappedPostParams, mappedBody, headers: requestHeaders } = endpointData.requestMapper(params);
81
+ const response = await axiosInstance_1.default.post(url, mappedBody, {
82
+ ...axiosConfig,
83
+ params: mappedPostParams,
84
+ headers: {
85
+ ...axiosConfig.headers,
86
+ ...requestHeaders,
87
+ },
88
+ });
89
+ return endpointData.responseMapper(response.data);
90
+ }
91
+ case endpointsConfig_1.methods.PUT: {
92
+ const response = await axiosInstance_1.default.put(url, params, axiosConfig);
93
+ return endpointData.responseMapper(response.data);
94
+ }
95
+ case endpointsConfig_1.methods.DELETE: {
96
+ const response = await axiosInstance_1.default.delete(url, {
97
+ ...axiosConfig,
98
+ data: params,
99
+ });
100
+ return endpointData.responseMapper(response.data);
101
+ }
102
+ default:
103
+ throw new Error("HTTP method not supported");
104
+ }
105
+ };
106
+ exports.apiMapper = apiMapper;