ismx-nexo-node-app 0.4.175 → 0.4.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.
@@ -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, _g, _h;
28
28
  // Especifica el método de la llamada HTTP al recurso.
29
29
  request.method = method;
30
30
  request.endpoint = endpoint;
@@ -45,8 +45,10 @@ class RepositoryRest extends Repository_1.default {
45
45
  for (const [header, value] of Object.entries((_e = request.headers) !== null && _e !== void 0 ? _e : {}))
46
46
  headers.set(header, (_g = (_f = request.headers) === null || _f === void 0 ? void 0 : _f[header]) !== null && _g !== void 0 ? _g : "");
47
47
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
48
- let call = fetch(request.url + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { body: method !== "GET" ? body : undefined, headers }));
48
+ const _fetch = (_h = this.options.fetch) !== null && _h !== void 0 ? _h : fetch;
49
+ let call = _fetch(request.url + QueryUtils_1.default.map(request.query), Object.assign(Object.assign({}, request), { body: method !== "GET" ? body : undefined, headers: headers }));
49
50
  // Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
51
+ // @ts-ignore
50
52
  return call.then((res) => __awaiter(this, void 0, void 0, function* () {
51
53
  var _a, _b, _c, _d, _e;
52
54
  let headers = {};
@@ -6,6 +6,7 @@ export interface RestOptions {
6
6
  onResponse?: (request: HttpRequest, response: HttpResponse) => void;
7
7
  onRawResponse?: (request: HttpRequest, response: string) => void;
8
8
  onError?: (request: HttpRequest, error: Error) => void;
9
+ fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
9
10
  }
10
11
  export default class RepositoryRest<Body = any, Res = any> extends Repository {
11
12
  private readonly baseUrl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.175",
3
+ "version": "0.4.177",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -9,14 +9,16 @@ export interface RestOptions {
9
9
  onResponse?: (request: HttpRequest, response: HttpResponse) => void;
10
10
  onRawResponse?: (request: HttpRequest, response: string) => void;
11
11
  onError?: (request: HttpRequest, error: Error) => void
12
+ fetch?: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>
12
13
  }
13
14
 
14
15
  export default class RepositoryRest<Body=any,Res=any> extends Repository
15
16
  {
16
17
  private readonly baseUrl: string;
18
+
17
19
  private readonly options: RestOptions
18
20
 
19
- constructor(baseUrl: string, options: RestOptions={}) {
21
+ constructor(baseUrl: string, options: RestOptions = {}) {
20
22
  super();
21
23
  this.baseUrl = baseUrl;
22
24
  this.options = options;
@@ -55,11 +57,13 @@ export default class RepositoryRest<Body=any,Res=any> extends Repository
55
57
  headers.set(header, request.headers?.[header] ?? "");
56
58
 
57
59
  // Realiza la llamada a la API con las cabeceras y la URL base de la llamada.
58
- let call = fetch(request.url + QueryUtils.map(request.query), {
59
- ...request, body: method !== "GET" ? body : undefined, headers
60
+ const _fetch = this.options.fetch ?? fetch;
61
+ let call = _fetch(request.url + QueryUtils.map(request.query), {
62
+ ...request, body: method !== "GET" ? body : undefined, headers: headers as unknown as Record<string, string>
60
63
  });
61
64
 
62
65
  // Añade información adicional a la respuesta y devuelve el resultado (o el error en su caso).
66
+ // @ts-ignore
63
67
  return call.then(async (res: Response) => {
64
68
  let headers: any = {}; res.headers.forEach((value, key) => headers[key.toLowerCase()] = value);
65
69
  let content: string | E = await res.text();