@napp/dti-client 4.5.2 → 4.5.4
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.
- package/builder.js +5 -3
- package/bundler.d.ts +3 -1
- package/bundler.js +52 -39
- package/caller.d.ts +6 -2
- package/caller.js +69 -55
- package/client.js +29 -19
- package/errorhandle.js +49 -38
- package/esm/bundler.d.ts +3 -1
- package/esm/bundler.js +7 -7
- package/esm/caller.d.ts +6 -2
- package/esm/caller.js +4 -4
- package/package.json +2 -2
- package/route.js +0 -2
- package/tree.js +2 -5
package/builder.js
CHANGED
|
@@ -4,8 +4,11 @@ exports.DtiClientBuilder = void 0;
|
|
|
4
4
|
const tree_1 = require("./tree");
|
|
5
5
|
const client_1 = require("./client");
|
|
6
6
|
class DtiClientBuilder {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
constructor() {
|
|
8
|
+
this._baseUrls = new tree_1.TreeNamer("root");
|
|
9
|
+
this._headers = new tree_1.TreeNamer("root");
|
|
10
|
+
this.signatureSecretResolver = undefined;
|
|
11
|
+
}
|
|
9
12
|
baseUrl(route, url) {
|
|
10
13
|
this._baseUrls.set(route.getFullname(), url);
|
|
11
14
|
return this;
|
|
@@ -28,7 +31,6 @@ class DtiClientBuilder {
|
|
|
28
31
|
}
|
|
29
32
|
return undefined;
|
|
30
33
|
}
|
|
31
|
-
signatureSecretResolver = undefined;
|
|
32
34
|
signatureSecret(resolver) {
|
|
33
35
|
this.signatureSecretResolver = resolver;
|
|
34
36
|
return this;
|
package/bundler.d.ts
CHANGED
package/bundler.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DtiClientBandler = void 0;
|
|
4
13
|
const dti_core_1 = require("@napp/dti-core");
|
|
@@ -6,12 +15,10 @@ const exception_1 = require("@napp/exception");
|
|
|
6
15
|
const cross_fetch_1 = require("cross-fetch");
|
|
7
16
|
const errorhandle_1 = require("./errorhandle");
|
|
8
17
|
class DtiClientBandler {
|
|
9
|
-
bundleMetas;
|
|
10
|
-
builder;
|
|
11
|
-
base62 = new dti_core_1.Base62();
|
|
12
18
|
constructor(bundleMetas, builder) {
|
|
13
19
|
this.bundleMetas = bundleMetas;
|
|
14
20
|
this.builder = builder;
|
|
21
|
+
this.base62 = new dti_core_1.Base62();
|
|
15
22
|
}
|
|
16
23
|
validate() {
|
|
17
24
|
for (let it of this.bundleMetas) {
|
|
@@ -51,49 +58,55 @@ class DtiClientBandler {
|
|
|
51
58
|
for (let it of this.bundleMetas) {
|
|
52
59
|
let _headers = this.builder.getHeader(it.meta.getRoute().getFullname());
|
|
53
60
|
if (_headers) {
|
|
54
|
-
headers = {
|
|
61
|
+
headers = Object.assign(Object.assign({}, headers), _headers);
|
|
55
62
|
}
|
|
56
63
|
}
|
|
57
64
|
headers["Content-Type"] = "application/json";
|
|
58
65
|
return headers;
|
|
59
66
|
}
|
|
60
|
-
|
|
61
|
-
this
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
call(opt) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
this.validate();
|
|
70
|
+
let method = this.getMethod();
|
|
71
|
+
if (method === 'get') {
|
|
72
|
+
return yield this.callGet(opt);
|
|
73
|
+
}
|
|
74
|
+
return yield this.callPost(opt);
|
|
75
|
+
});
|
|
67
76
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
callGet(opt) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
try {
|
|
80
|
+
let baseUrl = this.getBase();
|
|
81
|
+
let param = this.getParam();
|
|
82
|
+
let headers = this.getHeaders();
|
|
83
|
+
let p = this.base62.encode(JSON.stringify(param));
|
|
84
|
+
let q = new URLSearchParams({ p }).toString();
|
|
85
|
+
let resp = yield (0, cross_fetch_1.fetch)(`${baseUrl}/__bundler_get__?${q}`, {
|
|
86
|
+
method: 'get', headers, signal: opt === null || opt === void 0 ? void 0 : opt.signal
|
|
87
|
+
});
|
|
88
|
+
return yield (0, errorhandle_1.responseHandle)(resp);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw exception_1.Exception.from(error);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
83
94
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
callPost(opt) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
try {
|
|
98
|
+
let baseUrl = this.getBase();
|
|
99
|
+
let param = this.getParam();
|
|
100
|
+
let headers = this.getHeaders();
|
|
101
|
+
let resp = yield (0, cross_fetch_1.fetch)(`${baseUrl}/__bundler_post__`, {
|
|
102
|
+
method: 'post', headers, body: JSON.stringify(param), signal: opt === null || opt === void 0 ? void 0 : opt.signal
|
|
103
|
+
});
|
|
104
|
+
return yield (0, errorhandle_1.responseHandle)(resp);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw exception_1.Exception.from(error);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
97
110
|
}
|
|
98
111
|
}
|
|
99
112
|
exports.DtiClientBandler = DtiClientBandler;
|
package/caller.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export declare class DtiClientCaller<RESULT, PARAM> {
|
|
|
15
15
|
private signature;
|
|
16
16
|
private getUrl;
|
|
17
17
|
bundler(param: PARAM): BundleMeta<RESULT, PARAM>;
|
|
18
|
-
call(param: PARAM
|
|
19
|
-
|
|
18
|
+
call(param: PARAM, opt?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<RESULT>;
|
|
21
|
+
callRaw(param: PARAM, opt?: {
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}): Promise<Response>;
|
|
20
24
|
}
|
package/caller.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DtiClientCaller = void 0;
|
|
4
13
|
const dti_core_1 = require("@napp/dti-core");
|
|
@@ -11,24 +20,23 @@ function getRandomInt(min, max) {
|
|
|
11
20
|
// The maximum is exclusive and the minimum is inclusive
|
|
12
21
|
return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled);
|
|
13
22
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
function hmacSignBase64(secret, data) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const enc = new TextEncoder();
|
|
26
|
+
const key = yield crypto.subtle.importKey("raw", enc.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
27
|
+
const sigBuf = yield crypto.subtle.sign("HMAC", key, enc.encode(data));
|
|
28
|
+
const sigBytes = new Uint8Array(sigBuf);
|
|
29
|
+
// base64 encode
|
|
30
|
+
let bin = "";
|
|
31
|
+
sigBytes.forEach(b => (bin += String.fromCharCode(b)));
|
|
32
|
+
return btoa(bin);
|
|
33
|
+
});
|
|
23
34
|
}
|
|
24
35
|
class DtiClientCaller {
|
|
25
|
-
meta;
|
|
26
|
-
builder;
|
|
27
|
-
base62 = new dti_core_1.Base62();
|
|
28
|
-
routeClient;
|
|
29
36
|
constructor(meta, builder) {
|
|
30
37
|
this.meta = meta;
|
|
31
38
|
this.builder = builder;
|
|
39
|
+
this.base62 = new dti_core_1.Base62();
|
|
32
40
|
this.routeClient = new route_1.DtiClientRoute(meta.getRoute(), builder);
|
|
33
41
|
}
|
|
34
42
|
validate(param) {
|
|
@@ -80,7 +88,7 @@ class DtiClientCaller {
|
|
|
80
88
|
let confHeaderBuilder = this.builder.getHeader(this.meta.getRoute().getFullname());
|
|
81
89
|
if (confHeaderBuilder) {
|
|
82
90
|
let confHeaders = confHeaderBuilder(this.meta);
|
|
83
|
-
headers = {
|
|
91
|
+
headers = Object.assign(Object.assign({}, headers), confHeaders);
|
|
84
92
|
}
|
|
85
93
|
if (m === dti_core_1.DtiMode.BFrom) {
|
|
86
94
|
headers["Content-Type"] = "application/x-www-form-urlencoded";
|
|
@@ -90,23 +98,25 @@ class DtiClientCaller {
|
|
|
90
98
|
}
|
|
91
99
|
return headers;
|
|
92
100
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
signature(data) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const nonce = '' + getRandomInt(10000, 99999);
|
|
104
|
+
const timestamp = '' + Math.round(Date.now() / 1000);
|
|
105
|
+
const secretResolver = this.builder.getSignatureResolver();
|
|
106
|
+
if (secretResolver) {
|
|
107
|
+
const secret = yield secretResolver();
|
|
108
|
+
if (secret) {
|
|
109
|
+
const signature = yield hmacSignBase64(secret, `${timestamp}.${nonce}.${data}`);
|
|
110
|
+
return {
|
|
111
|
+
nonce, timestamp, signature
|
|
112
|
+
};
|
|
113
|
+
}
|
|
104
114
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
};
|
|
115
|
+
return {
|
|
116
|
+
nonce, timestamp,
|
|
117
|
+
signature: ''
|
|
118
|
+
};
|
|
119
|
+
});
|
|
110
120
|
}
|
|
111
121
|
getUrl() {
|
|
112
122
|
return this.routeClient.buildUrl(this.meta.getPath());
|
|
@@ -114,33 +124,37 @@ class DtiClientCaller {
|
|
|
114
124
|
bundler(param) {
|
|
115
125
|
return { meta: this.meta, param };
|
|
116
126
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
call(param, opt) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
129
|
+
let resp = yield this.callRaw(param, opt);
|
|
130
|
+
return yield (0, errorhandle_1.responseHandle)(resp);
|
|
131
|
+
});
|
|
120
132
|
}
|
|
121
|
-
|
|
122
|
-
this
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
callRaw(param, opt) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
this.validate(param);
|
|
136
|
+
let url = this.getUrl();
|
|
137
|
+
let query = this.getQeury(param);
|
|
138
|
+
let method = this.getMethod();
|
|
139
|
+
let headers = this.getHeaders(param);
|
|
140
|
+
let body = this.getBody(param);
|
|
141
|
+
const signData = this.meta.sign(param);
|
|
142
|
+
if (signData) {
|
|
143
|
+
const { nonce, signature, timestamp } = yield this.signature(signData);
|
|
144
|
+
if (signature) {
|
|
145
|
+
// console.log('method', method)
|
|
146
|
+
// console.log('------------method', method, this.meta.getFullname())
|
|
147
|
+
// console.log('timestamp', timestamp)
|
|
148
|
+
// console.log('nonce', nonce)
|
|
149
|
+
// console.log('signature', signature)
|
|
150
|
+
headers["X-DTI-Timestamp"] = timestamp;
|
|
151
|
+
headers["X-DTI-Nonce"] = nonce;
|
|
152
|
+
headers["X-DTI-Signature"] = signature;
|
|
153
|
+
}
|
|
140
154
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
155
|
+
return yield (0, cross_fetch_1.fetch)(url + (query ? `?${query}` : ''), {
|
|
156
|
+
method, headers, body, signal: opt === null || opt === void 0 ? void 0 : opt.signal
|
|
157
|
+
});
|
|
144
158
|
});
|
|
145
159
|
}
|
|
146
160
|
}
|
package/client.js
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.DtiClient = void 0;
|
|
4
13
|
const route_1 = require("./route");
|
|
5
14
|
const caller_1 = require("./caller");
|
|
6
15
|
const bundler_1 = require("./bundler");
|
|
7
16
|
class DtiClient {
|
|
8
|
-
builder;
|
|
9
17
|
constructor(builder) {
|
|
10
18
|
this.builder = builder;
|
|
11
19
|
}
|
|
@@ -15,24 +23,26 @@ class DtiClient {
|
|
|
15
23
|
buildUrl(route, actionPath) {
|
|
16
24
|
return new route_1.DtiClientRoute(route, this.builder).buildUrl(actionPath);
|
|
17
25
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
bundle(m1, m2, m3, m4, m5, m6) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
let bundleMetas = [m1];
|
|
29
|
+
if (m2) {
|
|
30
|
+
bundleMetas.push(m2);
|
|
31
|
+
}
|
|
32
|
+
if (m3) {
|
|
33
|
+
bundleMetas.push(m3);
|
|
34
|
+
}
|
|
35
|
+
if (m4) {
|
|
36
|
+
bundleMetas.push(m4);
|
|
37
|
+
}
|
|
38
|
+
if (m5) {
|
|
39
|
+
bundleMetas.push(m5);
|
|
40
|
+
}
|
|
41
|
+
if (m6) {
|
|
42
|
+
bundleMetas.push(m6);
|
|
43
|
+
}
|
|
44
|
+
return yield new bundler_1.DtiClientBandler(bundleMetas, this.builder).call();
|
|
45
|
+
});
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
48
|
exports.DtiClient = DtiClient;
|
package/errorhandle.js
CHANGED
|
@@ -1,54 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.responseHandle = void 0;
|
|
4
13
|
const exception_1 = require("@napp/exception");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
function responseHandle(resp, parser) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
let rsu = yield resp.text();
|
|
18
|
+
if (resp.ok) {
|
|
19
|
+
if (rsu) {
|
|
20
|
+
try {
|
|
21
|
+
let value = JSON.parse(rsu);
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
throw new exception_1.Exception(rsu, {
|
|
26
|
+
kind: 'serviceunavailable',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
18
29
|
}
|
|
30
|
+
return void 0;
|
|
19
31
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
if (rsu) {
|
|
33
|
+
let err;
|
|
34
|
+
try {
|
|
35
|
+
let errObject = JSON.parse(rsu);
|
|
36
|
+
if (parser) {
|
|
37
|
+
let e1 = parser(errObject);
|
|
38
|
+
if (e1) {
|
|
39
|
+
err = e1;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
err = exception_1.Exception.from(errObject);
|
|
43
|
+
}
|
|
30
44
|
}
|
|
31
45
|
else {
|
|
32
46
|
err = exception_1.Exception.from(errObject);
|
|
33
47
|
}
|
|
34
48
|
}
|
|
35
|
-
|
|
36
|
-
err = exception_1.Exception
|
|
49
|
+
catch (error) {
|
|
50
|
+
err = new exception_1.Exception(rsu, {
|
|
51
|
+
kind: 'serviceunavailable',
|
|
52
|
+
});
|
|
37
53
|
}
|
|
54
|
+
throw err;
|
|
38
55
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
throw
|
|
56
|
+
throw new exception_1.Exception(`status=${resp.status}. ${resp.statusText}`, {
|
|
57
|
+
kind: 'serviceunavailable',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw exception_1.Exception.from(error);
|
|
45
62
|
}
|
|
46
|
-
|
|
47
|
-
kind: 'serviceunavailable',
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
throw exception_1.Exception.from(error);
|
|
52
|
-
}
|
|
63
|
+
});
|
|
53
64
|
}
|
|
54
65
|
exports.responseHandle = responseHandle;
|
package/esm/bundler.d.ts
CHANGED
package/esm/bundler.js
CHANGED
|
@@ -54,15 +54,15 @@ export class DtiClientBandler {
|
|
|
54
54
|
headers["Content-Type"] = "application/json";
|
|
55
55
|
return headers;
|
|
56
56
|
}
|
|
57
|
-
async call() {
|
|
57
|
+
async call(opt) {
|
|
58
58
|
this.validate();
|
|
59
59
|
let method = this.getMethod();
|
|
60
60
|
if (method === 'get') {
|
|
61
|
-
return await this.callGet();
|
|
61
|
+
return await this.callGet(opt);
|
|
62
62
|
}
|
|
63
|
-
return await this.callPost();
|
|
63
|
+
return await this.callPost(opt);
|
|
64
64
|
}
|
|
65
|
-
async callGet() {
|
|
65
|
+
async callGet(opt) {
|
|
66
66
|
try {
|
|
67
67
|
let baseUrl = this.getBase();
|
|
68
68
|
let param = this.getParam();
|
|
@@ -70,7 +70,7 @@ export class DtiClientBandler {
|
|
|
70
70
|
let p = this.base62.encode(JSON.stringify(param));
|
|
71
71
|
let q = new URLSearchParams({ p }).toString();
|
|
72
72
|
let resp = await fetch(`${baseUrl}/__bundler_get__?${q}`, {
|
|
73
|
-
method: 'get', headers
|
|
73
|
+
method: 'get', headers, signal: opt?.signal
|
|
74
74
|
});
|
|
75
75
|
return await responseHandle(resp);
|
|
76
76
|
}
|
|
@@ -78,13 +78,13 @@ export class DtiClientBandler {
|
|
|
78
78
|
throw Exception.from(error);
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
async callPost() {
|
|
81
|
+
async callPost(opt) {
|
|
82
82
|
try {
|
|
83
83
|
let baseUrl = this.getBase();
|
|
84
84
|
let param = this.getParam();
|
|
85
85
|
let headers = this.getHeaders();
|
|
86
86
|
let resp = await fetch(`${baseUrl}/__bundler_post__`, {
|
|
87
|
-
method: 'post', headers, body: JSON.stringify(param)
|
|
87
|
+
method: 'post', headers, body: JSON.stringify(param), signal: opt?.signal
|
|
88
88
|
});
|
|
89
89
|
return await responseHandle(resp);
|
|
90
90
|
}
|
package/esm/caller.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ export declare class DtiClientCaller<RESULT, PARAM> {
|
|
|
15
15
|
private signature;
|
|
16
16
|
private getUrl;
|
|
17
17
|
bundler(param: PARAM): BundleMeta<RESULT, PARAM>;
|
|
18
|
-
call(param: PARAM
|
|
19
|
-
|
|
18
|
+
call(param: PARAM, opt?: {
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
}): Promise<RESULT>;
|
|
21
|
+
callRaw(param: PARAM, opt?: {
|
|
22
|
+
signal?: AbortSignal;
|
|
23
|
+
}): Promise<Response>;
|
|
20
24
|
}
|
package/esm/caller.js
CHANGED
|
@@ -111,11 +111,11 @@ export class DtiClientCaller {
|
|
|
111
111
|
bundler(param) {
|
|
112
112
|
return { meta: this.meta, param };
|
|
113
113
|
}
|
|
114
|
-
async call(param) {
|
|
115
|
-
let resp = await this.callRaw(param);
|
|
114
|
+
async call(param, opt) {
|
|
115
|
+
let resp = await this.callRaw(param, opt);
|
|
116
116
|
return await responseHandle(resp);
|
|
117
117
|
}
|
|
118
|
-
async callRaw(param) {
|
|
118
|
+
async callRaw(param, opt) {
|
|
119
119
|
this.validate(param);
|
|
120
120
|
let url = this.getUrl();
|
|
121
121
|
let query = this.getQeury(param);
|
|
@@ -137,7 +137,7 @@ export class DtiClientCaller {
|
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
return await fetch(url + (query ? `?${query}` : ''), {
|
|
140
|
-
method, headers, body
|
|
140
|
+
method, headers, body, signal: opt?.signal
|
|
141
141
|
});
|
|
142
142
|
}
|
|
143
143
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napp/dti-client",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.4",
|
|
4
4
|
"description": "data transaction interface client library",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"author": "Farcek <farcek@gmail.com>",
|
|
25
25
|
"license": "ISC",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@napp/dti-core": "4.5.
|
|
27
|
+
"@napp/dti-core": "4.5.4"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@napp/exception": "^9.1.4",
|
package/route.js
CHANGED
package/tree.js
CHANGED
|
@@ -2,14 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TreeNamer = void 0;
|
|
4
4
|
class TreeNamer {
|
|
5
|
-
name;
|
|
6
|
-
parent;
|
|
7
5
|
constructor(name, parent) {
|
|
8
6
|
this.name = name;
|
|
9
7
|
this.parent = parent;
|
|
10
8
|
}
|
|
11
|
-
value;
|
|
12
|
-
childs;
|
|
13
9
|
set(name, value) {
|
|
14
10
|
let names = (name || '').split('.').filter(it => !!it);
|
|
15
11
|
let curr = this;
|
|
@@ -69,9 +65,10 @@ class TreeNamer {
|
|
|
69
65
|
return this.childs[name] = new TreeNamer(name, this);
|
|
70
66
|
}
|
|
71
67
|
toObj() {
|
|
68
|
+
var _a;
|
|
72
69
|
let obj = {
|
|
73
70
|
name: this.name,
|
|
74
|
-
parent: this.parent
|
|
71
|
+
parent: (_a = this.parent) === null || _a === void 0 ? void 0 : _a.name,
|
|
75
72
|
value: this.value
|
|
76
73
|
};
|
|
77
74
|
if (this.childs) {
|