sysone-api-mapper 1.0.175 → 1.0.177
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/dist/axiosInstance.d.ts +3 -3
- package/dist/axiosInstance.js +10 -10
- package/dist/index.d.ts +8 -8
- package/dist/index.js +20 -20
- package/dist/services.d.ts +2 -2
- package/dist/services.js +100 -100
- package/dist/servicesData.d.ts +143 -143
- package/dist/servicesData.js +999 -999
- package/dist/src/adapters/billingAdapter.d.ts +6 -6
- package/dist/src/adapters/billingAdapter.js +11 -11
- package/dist/src/adapters/claimsAdapter.d.ts +3 -3
- package/dist/src/adapters/claimsAdapter.js +8 -8
- package/dist/src/adapters/collectionAdapter.d.ts +6 -6
- package/dist/src/adapters/collectionAdapter.js +11 -11
- package/dist/src/adapters/createApiAdapter.d.ts +57 -57
- package/dist/src/adapters/createApiAdapter.js +20 -20
- package/dist/src/adapters/financeAdapter.d.ts +6 -6
- package/dist/src/adapters/financeAdapter.js +11 -11
- package/dist/src/adapters/locationAdapter.d.ts +6 -6
- package/dist/src/adapters/locationAdapter.js +11 -11
- package/dist/src/adapters/partyAdapter.d.ts +17 -17
- package/dist/src/adapters/partyAdapter.js +22 -22
- package/dist/src/adapters/policyAdapter.d.ts +11 -11
- package/dist/src/adapters/policyAdapter.js +16 -16
- package/dist/src/components/notificationToast.js +35 -35
- package/dist/src/contexts/actionsContext.d.ts +6 -6
- package/dist/src/contexts/actionsContext.js +78 -78
- package/dist/src/contexts/apiContext.d.ts +3 -3
- package/dist/src/contexts/apiContext.js +12 -12
- package/dist/src/contexts/translationContext.d.ts +6 -6
- package/dist/src/contexts/translationContext.js +54 -54
- package/dist/src/mapper/Mapper.d.ts +2 -2
- package/dist/src/mapper/Mapper.js +115 -115
- package/dist/src/mapper/endpointsConfig.d.ts +2952 -2918
- package/dist/src/mapper/endpointsConfig.js +1050 -1034
- package/dist/src/mapper/helpers/mappingHelpers.d.ts +3 -3
- package/dist/src/mapper/helpers/mappingHelpers.js +30 -30
- package/dist/src/mapper/modules/billing/index.d.ts +20 -20
- package/dist/src/mapper/modules/billing/index.js +136 -136
- package/dist/src/mapper/modules/claim/index.d.ts +3 -3
- package/dist/src/mapper/modules/claim/index.js +19 -19
- package/dist/src/mapper/modules/general/index.d.ts +4 -4
- package/dist/src/mapper/modules/general/index.js +11 -11
- package/dist/src/mapper/modules/party/index.d.ts +32 -29
- package/dist/src/mapper/modules/party/index.js +143 -131
- package/dist/src/mapper/modules/policy/index.d.ts +366 -366
- package/dist/src/mapper/modules/policy/index.js +592 -592
- package/dist/src/mapper/modules/quotation/index.d.ts +297 -297
- package/dist/src/mapper/modules/quotation/index.js +494 -494
- package/dist/src/mapper/modules/request/index.d.ts +42 -42
- package/dist/src/mapper/modules/request/index.js +65 -65
- package/dist/src/public/index.d.ts +3 -3
- package/dist/src/public/index.js +7 -7
- package/dist/src/server.d.ts +1 -1
- package/dist/src/server.js +18 -18
- package/package.json +1 -1
|
@@ -1,80 +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
|
-
};
|
|
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
77
|
return (<ActionsContext.Provider value={{ actions, hasAction, ready }}>
|
|
78
78
|
{children}
|
|
79
|
-
</ActionsContext.Provider>);
|
|
80
|
-
}
|
|
79
|
+
</ActionsContext.Provider>);
|
|
80
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { Api } from "../adapters/createApiAdapter";
|
|
2
|
-
export declare const ApiContext: import("react").Context<Api | undefined>;
|
|
3
|
-
export declare const useApi: () => Api;
|
|
1
|
+
import type { Api } from "../adapters/createApiAdapter";
|
|
2
|
+
export declare const ApiContext: import("react").Context<Api | undefined>;
|
|
3
|
+
export declare const useApi: () => Api;
|
|
@@ -1,12 +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)(undefined);
|
|
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;
|
|
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)(undefined);
|
|
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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function useTranslation(): any;
|
|
2
|
-
export function TranslationProvider({ initialData, children }: {
|
|
3
|
-
initialData: any;
|
|
4
|
-
children: any;
|
|
5
|
-
}): React.JSX.Element;
|
|
6
|
-
import React from "react";
|
|
1
|
+
export function useTranslation(): any;
|
|
2
|
+
export function TranslationProvider({ initialData, children }: {
|
|
3
|
+
initialData: any;
|
|
4
|
+
children: any;
|
|
5
|
+
}): React.JSX.Element;
|
|
6
|
+
import React from "react";
|
|
@@ -1,56 +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
|
-
};
|
|
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
53
|
return (<TranslationContext.Provider value={{ translations, t }}>
|
|
54
54
|
{children}
|
|
55
|
-
</TranslationContext.Provider>);
|
|
56
|
-
}
|
|
55
|
+
</TranslationContext.Provider>);
|
|
56
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function configureApiMapper(config: any): void;
|
|
2
|
-
export function apiMapper(endpointCode: any, tenant: any, routeParams: any, params?: null, additionalHeaders?: {}): Promise<any>;
|
|
1
|
+
export function configureApiMapper(config: any): void;
|
|
2
|
+
export function apiMapper(endpointCode: any, tenant: any, routeParams: any, params?: null, additionalHeaders?: {}): Promise<any>;
|
|
@@ -1,115 +1,115 @@
|
|
|
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 < 400, // le bajo a 400 porque sino no tira error en los 4xx
|
|
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 { mappedParams, mappedBody, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
|
|
93
|
-
const response = await axiosInstance_1.default.put(url, mappedBody, {
|
|
94
|
-
...axiosConfig,
|
|
95
|
-
params: mappedParams,
|
|
96
|
-
headers: {
|
|
97
|
-
...axiosConfig.headers,
|
|
98
|
-
...requestHeaders,
|
|
99
|
-
},
|
|
100
|
-
...otherOptions,
|
|
101
|
-
});
|
|
102
|
-
return endpointData.responseMapper(response);
|
|
103
|
-
}
|
|
104
|
-
case endpointsConfig_1.methods.DELETE: {
|
|
105
|
-
const response = await axiosInstance_1.default.delete(url, {
|
|
106
|
-
...axiosConfig,
|
|
107
|
-
data: params,
|
|
108
|
-
});
|
|
109
|
-
return endpointData.responseMapper(response.data);
|
|
110
|
-
}
|
|
111
|
-
default:
|
|
112
|
-
throw new Error("HTTP method not supported");
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
exports.apiMapper = apiMapper;
|
|
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 < 400, // le bajo a 400 porque sino no tira error en los 4xx
|
|
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 { mappedParams, mappedBody, headers: requestHeaders, ...otherOptions } = endpointData.requestMapper(params);
|
|
93
|
+
const response = await axiosInstance_1.default.put(url, mappedBody, {
|
|
94
|
+
...axiosConfig,
|
|
95
|
+
params: mappedParams,
|
|
96
|
+
headers: {
|
|
97
|
+
...axiosConfig.headers,
|
|
98
|
+
...requestHeaders,
|
|
99
|
+
},
|
|
100
|
+
...otherOptions,
|
|
101
|
+
});
|
|
102
|
+
return endpointData.responseMapper(response);
|
|
103
|
+
}
|
|
104
|
+
case endpointsConfig_1.methods.DELETE: {
|
|
105
|
+
const response = await axiosInstance_1.default.delete(url, {
|
|
106
|
+
...axiosConfig,
|
|
107
|
+
data: params,
|
|
108
|
+
});
|
|
109
|
+
return endpointData.responseMapper(response.data);
|
|
110
|
+
}
|
|
111
|
+
default:
|
|
112
|
+
throw new Error("HTTP method not supported");
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.apiMapper = apiMapper;
|