ismx-nexo-node-app 0.4.46 → 0.4.47
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.
|
@@ -31,8 +31,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
31
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
34
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
38
|
const node_fetch_1 = __importStar(require("node-fetch"));
|
|
39
|
+
const QueryUtils_1 = __importDefault(require("../repository/utils/QueryUtils"));
|
|
36
40
|
class BusinessProxy {
|
|
37
41
|
constructor() {
|
|
38
42
|
this.modules = {};
|
|
@@ -42,36 +46,29 @@ class BusinessProxy {
|
|
|
42
46
|
}
|
|
43
47
|
call(tag, method, endpoint, request) {
|
|
44
48
|
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
var _a, _b, _c;
|
|
45
50
|
let module = this.modules[tag];
|
|
46
51
|
if (!module)
|
|
47
52
|
throw new Error(`Module ${tag} does not exist`);
|
|
48
|
-
|
|
53
|
+
// Completa la información de las cabeceras con cabeceras comunes por llamada a API.
|
|
54
|
+
let headers = new node_fetch_1.Headers(request.headers);
|
|
49
55
|
headers.set('Content-Type', 'application/json');
|
|
50
56
|
headers.set('Cache-Control', 'no-cache');
|
|
51
57
|
headers.set('Pragma', 'no-cache');
|
|
52
|
-
for (
|
|
53
|
-
headers.set(header, request.headers[header]);
|
|
54
|
-
|
|
58
|
+
for (const header of Object.keys(headers))
|
|
59
|
+
headers.set(header, (_b = (_a = request.headers) === null || _a === void 0 ? void 0 : _a[header]) !== null && _b !== void 0 ? _b : "");
|
|
60
|
+
// Si el body especificado es un objeto, lo convierte a JSON.
|
|
61
|
+
let body = request.body;
|
|
62
|
+
if ((_c = headers.get('Content-Type')) === null || _c === void 0 ? void 0 : _c.startsWith('application/json'))
|
|
63
|
+
body = JSON.stringify(request.body);
|
|
64
|
+
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
55
65
|
try {
|
|
56
|
-
return
|
|
57
|
-
method: method,
|
|
58
|
-
body: method !== "GET" ? JSON.stringify(request.body) : undefined,
|
|
59
|
-
headers: headers,
|
|
60
|
-
});
|
|
66
|
+
return (0, node_fetch_1.default)(module.host + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { method, body: method !== "GET" ? body : undefined, headers }));
|
|
61
67
|
}
|
|
62
68
|
catch (error) {
|
|
63
69
|
throw new Error(`Module ${tag} is not responding`);
|
|
64
70
|
}
|
|
65
71
|
});
|
|
66
72
|
}
|
|
67
|
-
map(query = {}) {
|
|
68
|
-
let queryString = "?";
|
|
69
|
-
for (const param in query) {
|
|
70
|
-
if (query[param] === undefined)
|
|
71
|
-
continue;
|
|
72
|
-
queryString += `${param}=${query[param]}&`;
|
|
73
|
-
}
|
|
74
|
-
return queryString;
|
|
75
|
-
}
|
|
76
73
|
}
|
|
77
74
|
exports.default = BusinessProxy;
|
|
@@ -37,10 +37,11 @@ class RepositoryRest extends Repository_1.default {
|
|
|
37
37
|
headers.set('Pragma', 'no-cache');
|
|
38
38
|
for (const header of Object.keys(headers))
|
|
39
39
|
headers.set(header, (_e = (_d = request.headers) === null || _d === void 0 ? void 0 : _d[header]) !== null && _e !== void 0 ? _e : "");
|
|
40
|
-
//
|
|
40
|
+
// Si el body especificado es un objeto, lo convierte a JSON.
|
|
41
41
|
let body = request.body;
|
|
42
42
|
if ((_f = headers.get('Content-Type')) === null || _f === void 0 ? void 0 : _f.startsWith('application/json'))
|
|
43
43
|
body = JSON.stringify(request.body);
|
|
44
|
+
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
44
45
|
let call = fetch(this.baseUrl + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { body: method !== "GET" ? body : undefined, headers }));
|
|
45
46
|
// Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
|
|
46
47
|
return call.then((res) => __awaiter(this, void 0, void 0, function* () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HttpResponse, HttpRequest } from "../api/Service"
|
|
2
2
|
import fetch, {Body, Headers} from 'node-fetch';
|
|
3
3
|
import {Wrapper} from "../api/ServiceRestFormal";
|
|
4
|
+
import QueryUtils from "../repository/utils/QueryUtils";
|
|
4
5
|
|
|
5
6
|
export interface Module {
|
|
6
7
|
id: string;
|
|
@@ -20,29 +21,26 @@ export default class BusinessProxy
|
|
|
20
21
|
let module = this.modules[tag];
|
|
21
22
|
if (!module) throw new Error(`Module ${tag} does not exist`);
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
|
|
25
|
+
// Completa la información de las cabeceras con cabeceras comunes por llamada a API.
|
|
26
|
+
let headers = new Headers(request.headers);
|
|
24
27
|
headers.set('Content-Type', 'application/json');
|
|
25
28
|
headers.set('Cache-Control', 'no-cache');
|
|
26
29
|
headers.set('Pragma', 'no-cache');
|
|
27
|
-
for (
|
|
28
|
-
headers.set(header, request.headers[header]);
|
|
30
|
+
for (const header of Object.keys(headers))
|
|
31
|
+
headers.set(header, request.headers?.[header] ?? "");
|
|
32
|
+
|
|
33
|
+
// Si el body especificado es un objeto, lo convierte a JSON.
|
|
34
|
+
let body: string = request.body as string;
|
|
35
|
+
if (headers.get('Content-Type')?.startsWith('application/json'))
|
|
36
|
+
body = JSON.stringify(request.body);
|
|
29
37
|
|
|
30
|
-
|
|
38
|
+
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
31
39
|
try {
|
|
32
|
-
return
|
|
33
|
-
method: method,
|
|
34
|
-
body: method !== "GET" ? JSON.stringify(request.body) : undefined,
|
|
35
|
-
headers: headers,
|
|
40
|
+
return fetch(module.host + endpoint + QueryUtils.map(request.query), {
|
|
41
|
+
...request, method, body: method !== "GET" ? body : undefined, headers
|
|
36
42
|
});
|
|
37
|
-
} catch (error) { throw new Error(`Module ${tag} is not responding`); }
|
|
38
|
-
}
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
let queryString = "?"
|
|
42
|
-
for (const param in query) {
|
|
43
|
-
if (query[param] === undefined) continue;
|
|
44
|
-
queryString += `${param}=${query[param]}&`
|
|
45
|
-
}
|
|
46
|
-
return queryString;
|
|
44
|
+
} catch (error) { throw new Error(`Module ${tag} is not responding`); }
|
|
47
45
|
}
|
|
48
46
|
}
|
|
@@ -46,11 +46,12 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
|
|
|
46
46
|
for (const header of Object.keys(headers))
|
|
47
47
|
headers.set(header, request.headers?.[header] ?? "");
|
|
48
48
|
|
|
49
|
-
//
|
|
49
|
+
// Si el body especificado es un objeto, lo convierte a JSON.
|
|
50
50
|
let body: string = request.body as string;
|
|
51
51
|
if (headers.get('Content-Type')?.startsWith('application/json'))
|
|
52
52
|
body = JSON.stringify(request.body);
|
|
53
53
|
|
|
54
|
+
// Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
|
|
54
55
|
let call = fetch(this.baseUrl + endpoint + QueryUtils.map(request.query), {
|
|
55
56
|
...request, body: method !== "GET" ? body : undefined, headers
|
|
56
57
|
});
|