@onekeyfe/hd-transport-http 0.1.11 → 0.1.14
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/dist/http.d.ts +1 -0
- package/dist/http.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -2
- package/package.json +4 -4
- package/src/http.ts +2 -0
- package/src/index.ts +7 -12
package/dist/http.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare type HttpRequestOptions = {
|
|
|
2
2
|
body?: Array<any> | Record<string, unknown> | string;
|
|
3
3
|
url: string;
|
|
4
4
|
method: 'POST' | 'GET';
|
|
5
|
+
timeout?: number;
|
|
5
6
|
};
|
|
6
7
|
export declare function request(options: HttpRequestOptions): Promise<any>;
|
|
7
8
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAGA,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAGA,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACrD,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAwBF,wBAAsB,OAAO,CAAC,OAAO,EAAE,kBAAkB,gBAuBxD"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAMxF,aAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACrD,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,wBAAwB,CAAC;AAMxF,aAAK,wBAAwB,GAAG;IAC9B,IAAI,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IACrD,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAIF,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,SAAS,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,cAAc,CAAC,GAAG,SAAS,CAAC;IAEnE,UAAU,UAAS;IAEnB,OAAO,UAAS;IAEhB,GAAG,EAAE,MAAM,CAAC;gBAEA,GAAG,CAAC,EAAE,MAAM;IAKxB,KAAK,CAAC,OAAO,EAAE,wBAAwB;IAWjC,IAAI;IAKJ,WAAW;IAUjB,SAAS,CAAC,UAAU,EAAE,GAAG;IAMnB,MAAM,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,2BAA2B,CAAC;IAY/C,SAAS;IAMf,aAAa,CAAC,KAAK,EAAE,YAAY;IAO3B,OAAO,CAAC,KAAK,EAAE,YAAY;IAK3B,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;IAUzC,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAmBjE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAYjE,IAAI,CAAC,OAAO,EAAE,MAAM;IAe1B,aAAa;IAKb,IAAI;IAIJ,MAAM;CAGP"}
|
package/dist/index.js
CHANGED
|
@@ -55,6 +55,7 @@ function parseResult(text) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
function request(options) {
|
|
58
|
+
var _a;
|
|
58
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
60
|
const fetchOptions = {
|
|
60
61
|
url: options.url,
|
|
@@ -64,6 +65,7 @@ function request(options) {
|
|
|
64
65
|
headers: {
|
|
65
66
|
'Content-Type': contentType(options.body == null ? '' : options.body),
|
|
66
67
|
},
|
|
68
|
+
timeout: (_a = options.timeout) !== null && _a !== void 0 ? _a : undefined,
|
|
67
69
|
};
|
|
68
70
|
const res = yield axios__default["default"].request(fetchOptions);
|
|
69
71
|
if (+res.status === 200) {
|
|
@@ -82,11 +84,13 @@ function request(options) {
|
|
|
82
84
|
const DEFAULT_URL = 'http://localhost:21320';
|
|
83
85
|
|
|
84
86
|
const { check, buildOne, receiveOne, parseConfigure } = transport__default["default"];
|
|
87
|
+
const Log = hdShared.initLog('@onekey/hd-transport-http');
|
|
85
88
|
class HttpTransport {
|
|
86
89
|
constructor(url) {
|
|
87
90
|
this.configured = false;
|
|
88
91
|
this.stopped = false;
|
|
89
92
|
this.url = url == null ? DEFAULT_URL : url;
|
|
93
|
+
hdShared.enableLog(true);
|
|
90
94
|
}
|
|
91
95
|
_post(options) {
|
|
92
96
|
if (this.stopped) {
|
|
@@ -105,6 +109,7 @@ class HttpTransport {
|
|
|
105
109
|
const infoS = yield request({
|
|
106
110
|
url: this.url,
|
|
107
111
|
method: 'POST',
|
|
112
|
+
timeout: 3000,
|
|
108
113
|
});
|
|
109
114
|
const info = check.info(infoS);
|
|
110
115
|
return info.version;
|
|
@@ -163,7 +168,7 @@ class HttpTransport {
|
|
|
163
168
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
164
169
|
}
|
|
165
170
|
const messages = this._messages;
|
|
166
|
-
|
|
171
|
+
Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
167
172
|
const o = buildOne(messages, name, data);
|
|
168
173
|
const outData = o.toString('hex');
|
|
169
174
|
const resData = yield this._post({
|
|
@@ -213,7 +218,7 @@ class HttpTransport {
|
|
|
213
218
|
this.stopped = true;
|
|
214
219
|
}
|
|
215
220
|
cancel() {
|
|
216
|
-
|
|
221
|
+
Log.debug('canceled');
|
|
217
222
|
}
|
|
218
223
|
}
|
|
219
224
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-transport-http",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "hardware http transport",
|
|
5
5
|
"author": "OneKey",
|
|
6
6
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@onekeyfe/hd-shared": "^0.1.
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.1.
|
|
27
|
+
"@onekeyfe/hd-shared": "^0.1.14",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.1.14",
|
|
29
29
|
"axios": "^0.27.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "216fee1795067013da0d68f4fc25f583509bb509"
|
|
32
32
|
}
|
package/src/http.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type HttpRequestOptions = {
|
|
|
5
5
|
body?: Array<any> | Record<string, unknown> | string;
|
|
6
6
|
url: string;
|
|
7
7
|
method: 'POST' | 'GET';
|
|
8
|
+
timeout?: number;
|
|
8
9
|
};
|
|
9
10
|
|
|
10
11
|
function contentType(body: any) {
|
|
@@ -38,6 +39,7 @@ export async function request(options: HttpRequestOptions) {
|
|
|
38
39
|
headers: {
|
|
39
40
|
'Content-Type': contentType(options.body == null ? '' : options.body),
|
|
40
41
|
},
|
|
42
|
+
timeout: options.timeout ?? undefined,
|
|
41
43
|
};
|
|
42
44
|
|
|
43
45
|
const res = await axios.request(fetchOptions);
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import transport from '@onekeyfe/hd-transport';
|
|
2
|
-
import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
|
|
2
|
+
import { ERRORS, HardwareErrorCode, enableLog, initLog } from '@onekeyfe/hd-shared';
|
|
3
3
|
import type { AcquireInput, OneKeyDeviceInfoWithSession } from '@onekeyfe/hd-transport';
|
|
4
4
|
import { request as http } from './http';
|
|
5
5
|
import { DEFAULT_URL } from './constants';
|
|
@@ -11,6 +11,8 @@ type IncompleteRequestOptions = {
|
|
|
11
11
|
url: string;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const Log = initLog('@onekey/hd-transport-http');
|
|
15
|
+
|
|
14
16
|
export default class HttpTransport {
|
|
15
17
|
_messages: ReturnType<typeof transport.parseConfigure> | undefined;
|
|
16
18
|
|
|
@@ -22,6 +24,7 @@ export default class HttpTransport {
|
|
|
22
24
|
|
|
23
25
|
constructor(url?: string) {
|
|
24
26
|
this.url = url == null ? DEFAULT_URL : url;
|
|
27
|
+
enableLog(true);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
_post(options: IncompleteRequestOptions) {
|
|
@@ -44,6 +47,7 @@ export default class HttpTransport {
|
|
|
44
47
|
const infoS = await http({
|
|
45
48
|
url: this.url,
|
|
46
49
|
method: 'POST',
|
|
50
|
+
timeout: 3000,
|
|
47
51
|
});
|
|
48
52
|
const info = check.info(infoS);
|
|
49
53
|
return info.version;
|
|
@@ -100,16 +104,7 @@ export default class HttpTransport {
|
|
|
100
104
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
101
105
|
}
|
|
102
106
|
const messages = this._messages;
|
|
103
|
-
|
|
104
|
-
'transport-http',
|
|
105
|
-
'call-',
|
|
106
|
-
'messages: ',
|
|
107
|
-
messages,
|
|
108
|
-
' name: ',
|
|
109
|
-
name,
|
|
110
|
-
' data: ',
|
|
111
|
-
data
|
|
112
|
-
);
|
|
107
|
+
Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
113
108
|
const o = buildOne(messages, name, data);
|
|
114
109
|
const outData = o.toString('hex');
|
|
115
110
|
const resData = await this._post({
|
|
@@ -160,6 +155,6 @@ export default class HttpTransport {
|
|
|
160
155
|
}
|
|
161
156
|
|
|
162
157
|
cancel() {
|
|
163
|
-
|
|
158
|
+
Log.debug('canceled');
|
|
164
159
|
}
|
|
165
160
|
}
|