@onekeyfe/hd-transport-http 0.1.12 → 0.1.16

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 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
@@ -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;CACxB,CAAC;AAwBF,wBAAsB,OAAO,CAAC,OAAO,EAAE,kBAAkB,gBAsBxD"}
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[]>;
@@ -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;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;gBAEA,GAAG,CAAC,EAAE,MAAM;IAIxB,KAAK,CAAC,OAAO,EAAE,wBAAwB;IAWjC,IAAI;IAKJ,WAAW;IASjB,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;IA4BjE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,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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) {
@@ -94,8 +96,9 @@ class HttpTransport {
94
96
  }
95
97
  return request(Object.assign(Object.assign({}, options), { method: 'POST', url: this.url + options.url }));
96
98
  }
97
- init() {
99
+ init(logger) {
98
100
  return __awaiter(this, void 0, void 0, function* () {
101
+ this.Log = logger;
99
102
  const bridgeVersion = yield this._silentInit();
100
103
  return bridgeVersion;
101
104
  });
@@ -105,6 +108,7 @@ class HttpTransport {
105
108
  const infoS = yield request({
106
109
  url: this.url,
107
110
  method: 'POST',
111
+ timeout: 3000,
108
112
  });
109
113
  const info = check.info(infoS);
110
114
  return info.version;
@@ -163,7 +167,7 @@ class HttpTransport {
163
167
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured);
164
168
  }
165
169
  const messages = this._messages;
166
- console.log('transport-http', 'call-', 'messages: ', messages, ' name: ', name, ' data: ', data);
170
+ this.Log.debug('call-', ' name: ', name, ' data: ', data);
167
171
  const o = buildOne(messages, name, data);
168
172
  const outData = o.toString('hex');
169
173
  const resData = yield this._post({
@@ -213,7 +217,7 @@ class HttpTransport {
213
217
  this.stopped = true;
214
218
  }
215
219
  cancel() {
216
- console.log('transport-http canceled');
220
+ this.Log.debug('canceled');
217
221
  }
218
222
  }
219
223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-transport-http",
3
- "version": "0.1.12",
3
+ "version": "0.1.16",
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.12",
28
- "@onekeyfe/hd-transport": "^0.1.12",
27
+ "@onekeyfe/hd-shared": "^0.1.16",
28
+ "@onekeyfe/hd-transport": "^0.1.16",
29
29
  "axios": "^0.27.2"
30
30
  },
31
- "gitHead": "38d4f8d711d212de8617f217a0148dcf3cdcc477"
31
+ "gitHead": "e87fdbab30d6daa4f32e28259bd221d75b5d6aad"
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
@@ -20,6 +20,8 @@ export default class HttpTransport {
20
20
 
21
21
  url: string;
22
22
 
23
+ Log?: any;
24
+
23
25
  constructor(url?: string) {
24
26
  this.url = url == null ? DEFAULT_URL : url;
25
27
  }
@@ -35,7 +37,8 @@ export default class HttpTransport {
35
37
  });
36
38
  }
37
39
 
38
- async init() {
40
+ async init(logger: any) {
41
+ this.Log = logger;
39
42
  const bridgeVersion = await this._silentInit();
40
43
  return bridgeVersion;
41
44
  }
@@ -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
- console.log(
104
- 'transport-http',
105
- 'call-',
106
- 'messages: ',
107
- messages,
108
- ' name: ',
109
- name,
110
- ' data: ',
111
- data
112
- );
107
+ this.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
- console.log('transport-http canceled');
158
+ this.Log.debug('canceled');
164
159
  }
165
160
  }