ismx-nexo-node-app 0.4.42 → 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
|
-
|
|
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,10 +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
|
-
return yield response.json();
|
|
76
|
-
else
|
|
77
|
-
throw yield response.json();
|
|
78
65
|
});
|
|
79
66
|
}
|
|
80
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
|
-
|
|
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
|
@@ -16,13 +16,7 @@ export default class BusinessProxy
|
|
|
16
16
|
this.modules = modules
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
async
|
|
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,15 +29,12 @@ export default class BusinessProxy
|
|
|
35
29
|
|
|
36
30
|
let response = null;
|
|
37
31
|
try {
|
|
38
|
-
|
|
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) return await response.json();
|
|
46
|
-
else throw await response.json();
|
|
47
38
|
}
|
|
48
39
|
|
|
49
40
|
private map(query: { [key:string]: string } = {}) {
|