ismx-nexo-node-app 0.4.43 → 0.4.44

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.
@@ -40,15 +40,6 @@ class BusinessProxy {
40
40
  setModules(modules) {
41
41
  this.modules = modules;
42
42
  }
43
- callFormal(tag, method, endpoint, request) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- let response = yield this.call(tag, method, endpoint, request);
46
- if ((response === null || response === void 0 ? void 0 : response.code) === "0")
47
- return response.data;
48
- else
49
- throw response;
50
- });
51
- }
52
43
  call(tag, method, endpoint, request) {
53
44
  return __awaiter(this, void 0, void 0, function* () {
54
45
  let module = this.modules[tag];
@@ -62,7 +53,7 @@ class BusinessProxy {
62
53
  headers.set(header, request.headers[header]);
63
54
  let response = null;
64
55
  try {
65
- response = yield (0, node_fetch_1.default)(`${module.host}${endpoint}${this.map(request.query)}`, {
56
+ return yield (0, node_fetch_1.default)(`${module.host}${endpoint}${this.map(request.query)}`, {
66
57
  method: method,
67
58
  body: method !== "GET" ? JSON.stringify(request.body) : undefined,
68
59
  headers: headers,
@@ -71,14 +62,6 @@ class BusinessProxy {
71
62
  catch (error) {
72
63
  throw new Error(`Module ${tag} is not responding`);
73
64
  }
74
- if (response.ok) {
75
- if (response.headers.get('Content-Type') === 'application/json')
76
- return yield response.json();
77
- else
78
- return yield response.text();
79
- }
80
- else
81
- throw yield response.json();
82
65
  });
83
66
  }
84
67
  map(query = {}) {
@@ -1,4 +1,5 @@
1
1
  import { HttpRequest } from "../api/Service";
2
+ import fetch from 'node-fetch';
2
3
  export interface Module {
3
4
  id: string;
4
5
  tag: string;
@@ -9,7 +10,6 @@ export default class BusinessProxy {
9
10
  setModules(modules: {
10
11
  [key: string]: Module;
11
12
  }): void;
12
- callFormal<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<Res | undefined>;
13
- call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<Res>;
13
+ call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response>;
14
14
  private map;
15
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ismx-nexo-node-app",
3
- "version": "0.4.43",
3
+ "version": "0.4.44",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "build": "rm -rf ./dist && npx tsc",
@@ -16,13 +16,7 @@ export default class BusinessProxy
16
16
  this.modules = modules
17
17
  }
18
18
 
19
- async callFormal<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<Res | undefined> {
20
- let response = await this.call<Req, Wrapper<Res>>(tag, method, endpoint, request);
21
- if (response?.code === "0") return response.data;
22
- else throw response;
23
- }
24
-
25
- async call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<Res> {
19
+ async call<Req, Res>(tag: string, method: string, endpoint: string, request: HttpRequest<Req>): Promise<fetch.Response> {
26
20
  let module = this.modules[tag];
27
21
  if (!module) throw new Error(`Module ${tag} does not exist`);
28
22
 
@@ -35,18 +29,12 @@ export default class BusinessProxy
35
29
 
36
30
  let response = null;
37
31
  try {
38
- response = await fetch(`${module.host}${endpoint}${this.map(request.query)}`, {
32
+ return await fetch(`${module.host}${endpoint}${this.map(request.query)}`, {
39
33
  method: method,
40
34
  body: method !== "GET" ? JSON.stringify(request.body) : undefined,
41
35
  headers: headers,
42
36
  });
43
37
  } catch (error) { throw new Error(`Module ${tag} is not responding`); }
44
-
45
- if (response.ok) {
46
- if (response.headers.get('Content-Type') === 'application/json') return await response.json();
47
- else return await response.text() as Res;
48
- }
49
- else throw await response.json();
50
38
  }
51
39
 
52
40
  private map(query: { [key:string]: string } = {}) {