@onekeyfe/hd-common-connect-sdk 1.2.8-alpha.10 → 1.2.8-alpha.100
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/__tests__/device-state-events.test.ts +13 -2
- package/dist/index.js +10 -7
- package/package.json +9 -9
- package/src/index.ts +3 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from 'fs';
|
|
2
2
|
import { resolve } from 'path';
|
|
3
3
|
import EventEmitter from 'events';
|
|
4
|
-
import { CORE_EVENT, initCore } from '@onekeyfe/hd-core';
|
|
5
|
-
import { createDeferred } from '@onekeyfe/hd-shared';
|
|
4
|
+
import { CORE_EVENT, UI_REQUEST, initCore } from '@onekeyfe/hd-core';
|
|
5
|
+
import { HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
|
|
6
6
|
|
|
7
7
|
import sdkExport, { messagePromises } from '../src';
|
|
8
8
|
|
|
@@ -56,6 +56,17 @@ describe('SDK request cleanup', () => {
|
|
|
56
56
|
await sdk.dispose();
|
|
57
57
|
});
|
|
58
58
|
|
|
59
|
+
test.each([
|
|
60
|
+
[HardwareErrorCode.BlePoweredOff, UI_REQUEST.BLUETOOTH_POWERED_OFF],
|
|
61
|
+
[HardwareErrorCode.BleUnsupported, UI_REQUEST.BLUETOOTH_UNSUPPORTED],
|
|
62
|
+
[HardwareErrorCode.BleLocationError, UI_REQUEST.LOCATION_PERMISSION],
|
|
63
|
+
])('emits the adapter UI request for error %s', async (code, type) => {
|
|
64
|
+
const response = { success: false, payload: { code, error: 'Adapter unavailable' } };
|
|
65
|
+
core.handleMessage.mockResolvedValueOnce(response);
|
|
66
|
+
await expect(sdk.call({ method: 'searchDevices' })).resolves.toEqual(response);
|
|
67
|
+
expect(core.handleMessage).toHaveBeenNthCalledWith(2, expect.objectContaining({ type }));
|
|
68
|
+
});
|
|
69
|
+
|
|
59
70
|
test('removes only the completed request when calls settle out of order', async () => {
|
|
60
71
|
const first = createDeferred<unknown>();
|
|
61
72
|
const second = createDeferred<unknown>();
|
package/dist/index.js
CHANGED
|
@@ -736,18 +736,18 @@ var init = function (settings, _, plugin) { return __awaiter(void 0, void 0, voi
|
|
|
736
736
|
}); };
|
|
737
737
|
var call = function (params) { return __awaiter(void 0, void 0, void 0, function () {
|
|
738
738
|
var blockLog, response, error_2;
|
|
739
|
-
var _a, _b, _c;
|
|
740
|
-
return __generator(this, function (
|
|
741
|
-
switch (
|
|
739
|
+
var _a, _b, _c, _d;
|
|
740
|
+
return __generator(this, function (_e) {
|
|
741
|
+
switch (_e.label) {
|
|
742
742
|
case 0:
|
|
743
743
|
blockLog = HardwareSdk.getLogBlockLabel(params);
|
|
744
744
|
Log.debug('call: ', blockLog !== null && blockLog !== void 0 ? blockLog : params);
|
|
745
|
-
|
|
745
|
+
_e.label = 1;
|
|
746
746
|
case 1:
|
|
747
|
-
|
|
747
|
+
_e.trys.push([1, 3, , 4]);
|
|
748
748
|
return [4 /*yield*/, postMessage({ event: HardwareSdk.IFRAME.CALL, type: HardwareSdk.IFRAME.CALL, payload: params })];
|
|
749
749
|
case 2:
|
|
750
|
-
response =
|
|
750
|
+
response = _e.sent();
|
|
751
751
|
if (response) {
|
|
752
752
|
Log.debug('response: ', blockLog ? '[REDACTED]' : response);
|
|
753
753
|
if (!response.success) {
|
|
@@ -760,12 +760,15 @@ var call = function (params) { return __awaiter(void 0, void 0, void 0, function
|
|
|
760
760
|
if (((_c = response.payload) === null || _c === void 0 ? void 0 : _c.code) === hdShared.HardwareErrorCode.BlePermissionError) {
|
|
761
761
|
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.BLUETOOTH_PERMISSION), false);
|
|
762
762
|
}
|
|
763
|
+
if (((_d = response.payload) === null || _d === void 0 ? void 0 : _d.code) === hdShared.HardwareErrorCode.BleLocationError) {
|
|
764
|
+
postMessage(HardwareSdk.createUiMessage(HardwareSdk.UI_REQUEST.LOCATION_PERMISSION), false);
|
|
765
|
+
}
|
|
763
766
|
}
|
|
764
767
|
return [2 /*return*/, response];
|
|
765
768
|
}
|
|
766
769
|
return [2 /*return*/, HardwareSdk.createErrorMessage(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNotResponse))];
|
|
767
770
|
case 3:
|
|
768
|
-
error_2 =
|
|
771
|
+
error_2 = _e.sent();
|
|
769
772
|
Log.error('__call error: ', error_2);
|
|
770
773
|
return [2 /*return*/, HardwareSdk.createErrorMessage(error_2)];
|
|
771
774
|
case 4: return [2 /*return*/];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-common-connect-sdk",
|
|
3
|
-
"version": "1.2.8-alpha.
|
|
3
|
+
"version": "1.2.8-alpha.100",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "ISC",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"lint:fix": "eslint . --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-core": "1.2.8-alpha.
|
|
25
|
-
"@onekeyfe/hd-shared": "1.2.8-alpha.
|
|
26
|
-
"@onekeyfe/hd-transport-emulator": "1.2.8-alpha.
|
|
27
|
-
"@onekeyfe/hd-transport-http": "1.2.8-alpha.
|
|
28
|
-
"@onekeyfe/hd-transport-lowlevel": "1.2.8-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport-usb": "1.2.8-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport-web-device": "1.2.8-alpha.
|
|
24
|
+
"@onekeyfe/hd-core": "1.2.8-alpha.100",
|
|
25
|
+
"@onekeyfe/hd-shared": "1.2.8-alpha.100",
|
|
26
|
+
"@onekeyfe/hd-transport-emulator": "1.2.8-alpha.100",
|
|
27
|
+
"@onekeyfe/hd-transport-http": "1.2.8-alpha.100",
|
|
28
|
+
"@onekeyfe/hd-transport-lowlevel": "1.2.8-alpha.100",
|
|
29
|
+
"@onekeyfe/hd-transport-usb": "1.2.8-alpha.100",
|
|
30
|
+
"@onekeyfe/hd-transport-web-device": "1.2.8-alpha.100"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "53ada5b79a51f0edf8a7392f70c8da063144d33c"
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -188,6 +188,9 @@ const call = async (params: any) => {
|
|
|
188
188
|
if (response.payload?.code === HardwareErrorCode.BlePermissionError) {
|
|
189
189
|
postMessage(createUiMessage(UI_REQUEST.BLUETOOTH_PERMISSION), false);
|
|
190
190
|
}
|
|
191
|
+
if (response.payload?.code === HardwareErrorCode.BleLocationError) {
|
|
192
|
+
postMessage(createUiMessage(UI_REQUEST.LOCATION_PERMISSION), false);
|
|
193
|
+
}
|
|
191
194
|
}
|
|
192
195
|
|
|
193
196
|
return response;
|