ismx-nexo-node-app 0.4.49 → 0.4.50

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.
@@ -46,21 +46,22 @@ class BusinessProxy {
46
46
  }
47
47
  call(tag, method, endpoint, request) {
48
48
  return __awaiter(this, void 0, void 0, function* () {
49
- var _a, _b, _c, _d;
49
+ var _a, _b, _c;
50
50
  let module = this.modules[tag];
51
51
  if (!module)
52
52
  throw new Error(`Module ${tag} does not exist`);
53
53
  // Completa la información de las cabeceras con cabeceras comunes por llamada a API.
54
54
  let headers = new node_fetch_1.Headers(request.headers);
55
- headers.set('Content-Type', 'application/json');
56
55
  headers.set('Cache-Control', 'no-cache');
57
56
  headers.set('Pragma', 'no-cache');
58
57
  for (const header of Object.keys(headers))
59
58
  headers.set(header, (_b = (_a = request.headers) === null || _a === void 0 ? void 0 : _a[header]) !== null && _b !== void 0 ? _b : "");
60
59
  // Si el body especificado es un objeto, lo convierte a JSON.
61
60
  let body = (_c = request.body) === null || _c === void 0 ? void 0 : _c.toString();
62
- if (request.body && ((_d = headers.get('Content-Type')) === null || _d === void 0 ? void 0 : _d.startsWith('application/json')))
61
+ if (request.body && typeof request.body !== 'string') {
62
+ headers.set('Content-Type', 'application/json');
63
63
  body = JSON.stringify(request.body);
64
+ }
64
65
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
65
66
  try {
66
67
  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 }));
@@ -24,7 +24,7 @@ class RepositoryRest extends Repository_1.default {
24
24
  }
25
25
  call() {
26
26
  return __awaiter(this, arguments, void 0, function* (method = 'GET', endpoint = '/', request = {}) {
27
- var _a, _b, _c, _d, _e, _f, _g;
27
+ var _a, _b, _c, _d, _e, _f;
28
28
  // Especifica el método de la llamada HTTP al recurso.
29
29
  request.method = method;
30
30
  request.endpoint = endpoint;
@@ -32,15 +32,16 @@ class RepositoryRest extends Repository_1.default {
32
32
  request = (_c = (_b = (_a = this.options).interceptor) === null || _b === void 0 ? void 0 : _b.call(_a, endpoint, request)) !== null && _c !== void 0 ? _c : request;
33
33
  // Completa la información de las cabeceras con cabeceras comunes por llamada a API.
34
34
  let headers = new Headers(request.headers);
35
- headers.set('Content-Type', 'application/json');
36
35
  headers.set('Cache-Control', 'no-cache');
37
36
  headers.set('Pragma', 'no-cache');
38
37
  for (const header of Object.keys(headers))
39
38
  headers.set(header, (_e = (_d = request.headers) === null || _d === void 0 ? void 0 : _d[header]) !== null && _e !== void 0 ? _e : "");
40
39
  // Si el body especificado es un objeto, lo convierte a JSON.
41
40
  let body = (_f = request.body) === null || _f === void 0 ? void 0 : _f.toString();
42
- if (request.body && ((_g = headers.get('Content-Type')) === null || _g === void 0 ? void 0 : _g.startsWith('application/json')))
41
+ if (request.body && typeof request.body !== 'string') {
42
+ headers.set('Content-Type', 'application/json');
43
43
  body = JSON.stringify(request.body);
44
+ }
44
45
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
45
46
  let call = fetch(this.baseUrl + endpoint + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { body: method !== "GET" ? body : undefined, headers }));
46
47
  // Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.49",
3
+ "version": "0.4.50",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -1,6 +1,7 @@
1
1
  import { HttpResponse, HttpRequest } from "../api/Service"
2
2
  import fetch, {Body, Headers} from 'node-fetch';
3
3
  import QueryUtils from "../repository/utils/QueryUtils";
4
+ import {json} from "express";
4
5
 
5
6
  export interface Module {
6
7
  id: string;
@@ -22,7 +23,6 @@ export default class BusinessProxy
22
23
 
23
24
  // Completa la información de las cabeceras con cabeceras comunes por llamada a API.
24
25
  let headers = new Headers(request.headers);
25
- headers.set('Content-Type', 'application/json');
26
26
  headers.set('Cache-Control', 'no-cache');
27
27
  headers.set('Pragma', 'no-cache');
28
28
  for (const header of Object.keys(headers))
@@ -30,8 +30,10 @@ export default class BusinessProxy
30
30
 
31
31
  // Si el body especificado es un objeto, lo convierte a JSON.
32
32
  let body: string | undefined = request.body?.toString();
33
- if (request.body && headers.get('Content-Type')?.startsWith('application/json'))
33
+ if (request.body && typeof request.body !== 'string') {
34
+ headers.set('Content-Type', 'application/json');
34
35
  body = JSON.stringify(request.body);
36
+ }
35
37
 
36
38
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
37
39
  try {
@@ -40,7 +40,6 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
40
40
 
41
41
  // Completa la información de las cabeceras con cabeceras comunes por llamada a API.
42
42
  let headers = new Headers(request.headers);
43
- headers.set('Content-Type', 'application/json');
44
43
  headers.set('Cache-Control', 'no-cache');
45
44
  headers.set('Pragma', 'no-cache');
46
45
  for (const header of Object.keys(headers))
@@ -48,8 +47,10 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
48
47
 
49
48
  // Si el body especificado es un objeto, lo convierte a JSON.
50
49
  let body: string | undefined = request.body?.toString();
51
- if (request.body && headers.get('Content-Type')?.startsWith('application/json'))
50
+ if (request.body && typeof request.body !== 'string') {
51
+ headers.set('Content-Type', 'application/json');
52
52
  body = JSON.stringify(request.body);
53
+ }
53
54
 
54
55
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
55
56
  let call = fetch(this.baseUrl + endpoint + QueryUtils.map(request.query), {