@onekeyfe/hd-transport-http 0.1.13 → 0.1.17
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 +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/package.json +4 -4
- package/src/http.ts +2 -0
- package/src/index.ts +8 -7
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
CHANGED
|
@@ -10,9 +10,10 @@ declare class HttpTransport {
|
|
|
10
10
|
configured: boolean;
|
|
11
11
|
stopped: boolean;
|
|
12
12
|
url: string;
|
|
13
|
+
Log?: any;
|
|
13
14
|
constructor(url?: string);
|
|
14
15
|
_post(options: IncompleteRequestOptions): Promise<any>;
|
|
15
|
-
init(): Promise<string>;
|
|
16
|
+
init(logger: any): Promise<string>;
|
|
16
17
|
_silentInit(): Promise<string>;
|
|
17
18
|
configure(signedData: any): void;
|
|
18
19
|
listen(old?: Array<OneKeyDeviceInfoWithSession>): Promise<OneKeyDeviceInfoWithSession[]>;
|
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;AAEF,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;IAEZ,GAAG,CAAC,EAAE,GAAG,CAAC;gBAEE,GAAG,CAAC,EAAE,MAAM;IAIxB,KAAK,CAAC,OAAO,EAAE,wBAAwB;IAWjC,IAAI,CAAC,MAAM,EAAE,GAAG;IAMhB,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,13 +84,11 @@ function request(options) {
|
|
|
82
84
|
const DEFAULT_URL = 'http://localhost:21320';
|
|
83
85
|
|
|
84
86
|
const { check, buildOne, receiveOne, parseConfigure } = transport__default["default"];
|
|
85
|
-
const Log = hdShared.initLog('@onekey/hd-transport-http');
|
|
86
87
|
class HttpTransport {
|
|
87
88
|
constructor(url) {
|
|
88
89
|
this.configured = false;
|
|
89
90
|
this.stopped = false;
|
|
90
91
|
this.url = url == null ? DEFAULT_URL : url;
|
|
91
|
-
hdShared.enableLog(true);
|
|
92
92
|
}
|
|
93
93
|
_post(options) {
|
|
94
94
|
if (this.stopped) {
|
|
@@ -96,8 +96,9 @@ class HttpTransport {
|
|
|
96
96
|
}
|
|
97
97
|
return request(Object.assign(Object.assign({}, options), { method: 'POST', url: this.url + options.url }));
|
|
98
98
|
}
|
|
99
|
-
init() {
|
|
99
|
+
init(logger) {
|
|
100
100
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
this.Log = logger;
|
|
101
102
|
const bridgeVersion = yield this._silentInit();
|
|
102
103
|
return bridgeVersion;
|
|
103
104
|
});
|
|
@@ -107,6 +108,7 @@ class HttpTransport {
|
|
|
107
108
|
const infoS = yield request({
|
|
108
109
|
url: this.url,
|
|
109
110
|
method: 'POST',
|
|
111
|
+
timeout: 3000,
|
|
110
112
|
});
|
|
111
113
|
const info = check.info(infoS);
|
|
112
114
|
return info.version;
|
|
@@ -165,7 +167,7 @@ class HttpTransport {
|
|
|
165
167
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
|
|
166
168
|
}
|
|
167
169
|
const messages = this._messages;
|
|
168
|
-
Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
170
|
+
this.Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
169
171
|
const o = buildOne(messages, name, data);
|
|
170
172
|
const outData = o.toString('hex');
|
|
171
173
|
const resData = yield this._post({
|
|
@@ -215,7 +217,7 @@ class HttpTransport {
|
|
|
215
217
|
this.stopped = true;
|
|
216
218
|
}
|
|
217
219
|
cancel() {
|
|
218
|
-
Log.debug('canceled');
|
|
220
|
+
this.Log.debug('canceled');
|
|
219
221
|
}
|
|
220
222
|
}
|
|
221
223
|
|
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.17",
|
|
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.17",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.1.17",
|
|
29
29
|
"axios": "^0.27.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "65350a66c7f2b1e80cb1d413ee56da4aef507fa3"
|
|
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
|
|
2
|
+
import { ERRORS, HardwareErrorCode } 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,8 +11,6 @@ type IncompleteRequestOptions = {
|
|
|
11
11
|
url: string;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const Log = initLog('@onekey/hd-transport-http');
|
|
15
|
-
|
|
16
14
|
export default class HttpTransport {
|
|
17
15
|
_messages: ReturnType<typeof transport.parseConfigure> | undefined;
|
|
18
16
|
|
|
@@ -22,9 +20,10 @@ export default class HttpTransport {
|
|
|
22
20
|
|
|
23
21
|
url: string;
|
|
24
22
|
|
|
23
|
+
Log?: any;
|
|
24
|
+
|
|
25
25
|
constructor(url?: string) {
|
|
26
26
|
this.url = url == null ? DEFAULT_URL : url;
|
|
27
|
-
enableLog(true);
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
_post(options: IncompleteRequestOptions) {
|
|
@@ -38,7 +37,8 @@ export default class HttpTransport {
|
|
|
38
37
|
});
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
async init() {
|
|
40
|
+
async init(logger: any) {
|
|
41
|
+
this.Log = logger;
|
|
42
42
|
const bridgeVersion = await this._silentInit();
|
|
43
43
|
return bridgeVersion;
|
|
44
44
|
}
|
|
@@ -47,6 +47,7 @@ export default class HttpTransport {
|
|
|
47
47
|
const infoS = await http({
|
|
48
48
|
url: this.url,
|
|
49
49
|
method: 'POST',
|
|
50
|
+
timeout: 3000,
|
|
50
51
|
});
|
|
51
52
|
const info = check.info(infoS);
|
|
52
53
|
return info.version;
|
|
@@ -103,7 +104,7 @@ export default class HttpTransport {
|
|
|
103
104
|
throw ERRORS.TypedError(HardwareErrorCode.TransportNotConfigured);
|
|
104
105
|
}
|
|
105
106
|
const messages = this._messages;
|
|
106
|
-
Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
107
|
+
this.Log.debug('call-', ' name: ', name, ' data: ', data);
|
|
107
108
|
const o = buildOne(messages, name, data);
|
|
108
109
|
const outData = o.toString('hex');
|
|
109
110
|
const resData = await this._post({
|
|
@@ -154,6 +155,6 @@ export default class HttpTransport {
|
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
cancel() {
|
|
157
|
-
Log.debug('canceled');
|
|
158
|
+
this.Log.debug('canceled');
|
|
158
159
|
}
|
|
159
160
|
}
|