@ray-js/lock-sdk 1.2.0-beta.3 → 1.2.0-beta.30
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/lib/api/fit.d.ts +55 -2
- package/lib/api/fit.js +43 -1
- package/lib/api/gesture.d.ts +11 -0
- package/lib/api/gesture.js +18 -0
- package/lib/api/log.d.ts +52 -4
- package/lib/api/log.js +22 -0
- package/lib/api/notify.d.ts +28 -0
- package/lib/api/notify.js +17 -0
- package/lib/api/service.d.ts +26 -0
- package/lib/api/service.js +25 -0
- package/lib/api/temp.d.ts +21 -0
- package/lib/api/temp.js +24 -0
- package/lib/api/video.d.ts +9 -0
- package/lib/api/video.js +30 -0
- package/lib/api/voip.d.ts +10 -0
- package/lib/api/voip.js +17 -0
- package/lib/config/dp-code/index.d.ts +2 -1
- package/lib/config/dp-code/index.js +2 -0
- package/lib/config/dp-map/media.d.ts +13 -0
- package/lib/config/dp-map/media.js +19 -0
- package/lib/entries/main/bootstrap/bootstrap-lock-instance.d.ts +2 -1
- package/lib/entries/main/bootstrap/bootstrap-lock-instance.js +23 -8
- package/lib/entries/main/bootstrap/bootstrap.d.ts +3 -2
- package/lib/entries/main/bootstrap/bootstrap.js +10 -6
- package/lib/entries/main/bootstrap/primary-instance.d.ts +1 -2
- package/lib/entries/main/bootstrap/primary-instance.js +1 -1
- package/lib/entries/main/bootstrap/resolve-runtime-from-export-this.js +1 -1
- package/lib/entries/main/build-instance.d.ts +6 -3
- package/lib/entries/main/build-instance.js +13 -1
- package/lib/entries/main/exports/capability.d.ts +2 -0
- package/lib/entries/main/exports/capability.js +7 -1
- package/lib/entries/main/exports/fit-sdk/binding.d.ts +10 -0
- package/lib/entries/{fit/exports → main/exports/fit-sdk}/binding.js +6 -3
- package/lib/entries/{fit/exports → main/exports/fit-sdk}/device.d.ts +11 -10
- package/lib/entries/{fit/exports → main/exports/fit-sdk}/device.js +20 -20
- package/lib/entries/{fit/exports → main/exports/fit-sdk}/index.d.ts +1 -0
- package/lib/entries/{fit/exports → main/exports/fit-sdk}/index.js +1 -0
- package/lib/entries/main/exports/fit-sdk/log.d.ts +3 -0
- package/lib/entries/main/exports/fit-sdk/log.js +5 -0
- package/lib/entries/main/exports/fit-sdk/temp.d.ts +40 -0
- package/lib/entries/main/exports/fit-sdk/temp.js +59 -0
- package/lib/entries/main/exports/gesture.d.ts +6 -0
- package/lib/entries/main/exports/gesture.js +8 -0
- package/lib/entries/main/exports/index.d.ts +8 -0
- package/lib/entries/main/exports/index.js +8 -0
- package/lib/entries/main/exports/log.d.ts +2 -0
- package/lib/entries/main/exports/log.js +7 -1
- package/lib/entries/main/exports/media.d.ts +10 -1
- package/lib/entries/main/exports/media.js +29 -1
- package/lib/entries/main/exports/misc.d.ts +4 -2
- package/lib/entries/main/exports/misc.js +2 -2
- package/lib/entries/main/exports/notify.d.ts +7 -0
- package/lib/entries/main/exports/notify.js +8 -0
- package/lib/entries/main/exports/service.d.ts +4 -0
- package/lib/entries/main/exports/service.js +11 -0
- package/lib/entries/main/exports/voip.d.ts +3 -0
- package/lib/entries/main/exports/voip.js +8 -0
- package/lib/entries/main/index.d.ts +3 -3
- package/lib/entries/main/index.js +11 -5
- package/lib/feature/fit/bind-lock-to-fit.d.ts +1 -0
- package/lib/feature/fit/bind-lock-to-fit.js +53 -0
- package/lib/feature/fit/ble-key.d.ts +10 -4
- package/lib/feature/fit/ble-key.js +145 -4
- package/lib/feature/fit/device-bv.d.ts +2 -0
- package/lib/feature/fit/device-bv.js +15 -0
- package/lib/feature/fit/invalid-password.d.ts +10 -0
- package/lib/feature/fit/invalid-password.js +43 -0
- package/lib/feature/fit/list.d.ts +12 -2
- package/lib/feature/fit/list.js +54 -5
- package/lib/feature/fit/log.d.ts +7 -0
- package/lib/feature/fit/log.js +123 -0
- package/lib/feature/fit/method/add-flow.js +2 -2
- package/lib/feature/fit/method/add-password.js +2 -2
- package/lib/feature/fit/method/update-remove.js +40 -14
- package/lib/feature/fit/password-list.d.ts +37 -0
- package/lib/feature/fit/password-list.js +44 -1
- package/lib/feature/fit/security-channel.d.ts +3 -0
- package/lib/feature/fit/security-channel.js +43 -0
- package/lib/feature/fit/shared.d.ts +8 -0
- package/lib/feature/fit/shared.js +40 -1
- package/lib/feature/fit/sync.d.ts +4 -2
- package/lib/feature/fit/sync.js +63 -22
- package/lib/feature/fit/temp-password.d.ts +23 -0
- package/lib/feature/fit/temp-password.js +95 -3
- package/lib/feature/fit/users.d.ts +1 -0
- package/lib/feature/fit/users.js +1 -0
- package/lib/feature/gesture/gesture.d.ts +6 -0
- package/lib/feature/gesture/gesture.js +3 -0
- package/lib/feature/log/log.d.ts +5 -1
- package/lib/feature/log/log.js +53 -6
- package/lib/feature/media/camera.d.ts +18 -0
- package/lib/feature/media/camera.js +36 -0
- package/lib/feature/media/media.d.ts +10 -0
- package/lib/feature/media/media.js +31 -0
- package/lib/feature/misc/ble-control.js +2 -2
- package/lib/feature/misc/capability.d.ts +2 -0
- package/lib/feature/misc/capability.js +84 -11
- package/lib/feature/misc/connect-device.d.ts +1 -1
- package/lib/feature/misc/connect-device.js +7 -6
- package/lib/feature/misc/is-use-near-channel-for-runtime.js +8 -1
- package/lib/feature/notify/notify.d.ts +4 -0
- package/lib/feature/notify/notify.js +3 -0
- package/lib/feature/password/temporary/custom-dp.js +59 -54
- package/lib/feature/password/temporary/offline-create.d.ts +14 -0
- package/lib/feature/password/temporary/offline-create.js +77 -1
- package/lib/feature/service/goto-service.d.ts +3 -2
- package/lib/feature/service/goto-service.js +7 -1
- package/lib/feature/service/value-added.d.ts +4 -0
- package/lib/feature/service/value-added.js +4 -0
- package/lib/feature/state/clear.js +1 -0
- package/lib/feature/state/device-status.js +17 -6
- package/lib/feature/state/init-state.js +20 -12
- package/lib/feature/state/platform-routing.js +12 -3
- package/lib/feature/state/remote-permissions.js +17 -0
- package/lib/feature/state/sync/remote-serect-key.js +7 -0
- package/lib/feature/storage/index.d.ts +5 -0
- package/lib/feature/storage/index.js +32 -0
- package/lib/feature/storage/swr-cache.d.ts +7 -0
- package/lib/feature/storage/swr-cache.js +54 -0
- package/lib/feature/unlock/method/add-flow.js +2 -2
- package/lib/feature/unlock/method/add-password.js +2 -2
- package/lib/feature/unlock/sync/unlock-method.js +3 -0
- package/lib/feature/user/sync-user.js +4 -2
- package/lib/feature/utils/index.d.ts +1 -0
- package/lib/feature/utils/index.js +1 -0
- package/lib/feature/voip/voip.d.ts +3 -0
- package/lib/feature/voip/voip.js +3 -0
- package/lib/interface.d.ts +42 -1
- package/lib/platform/device.d.ts +4 -3
- package/lib/platform/index.d.ts +1 -0
- package/lib/platform/index.js +1 -0
- package/lib/platform/ipc.d.ts +3 -0
- package/lib/platform/ipc.js +13 -0
- package/lib/platform/storage.d.ts +3 -0
- package/lib/platform/storage.js +9 -0
- package/lib/runtime/LockDeviceRuntime.js +3 -0
- package/lib/runtime/lock-config.d.ts +5 -1
- package/lib/runtime/lock-config.js +6 -0
- package/lib/runtime/runtime-state-types.d.ts +6 -0
- package/lib/utils/constant.d.ts +1 -0
- package/lib/utils/constant.js +6 -0
- package/lib/utils/errors.js +3 -1
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +1 -0
- package/lib/utils/parse.js +1 -1
- package/package.json +1 -11
- package/lib/bootstrap/bootstrap-lock-instance.d.ts +0 -7
- package/lib/bootstrap/bootstrap-lock-instance.js +0 -16
- package/lib/bootstrap/bootstrap.d.ts +0 -4
- package/lib/bootstrap/bootstrap.js +0 -53
- package/lib/bootstrap/lock-instance-runtime-ref.d.ts +0 -3
- package/lib/bootstrap/lock-instance-runtime-ref.js +0 -7
- package/lib/bootstrap/primary-instance.d.ts +0 -6
- package/lib/bootstrap/primary-instance.js +0 -24
- package/lib/bootstrap/resolve-runtime-from-export-this.d.ts +0 -5
- package/lib/bootstrap/resolve-runtime-from-export-this.js +0 -29
- package/lib/bootstrap/top-level-runtime.d.ts +0 -2
- package/lib/bootstrap/top-level-runtime.js +0 -9
- package/lib/entries/ble/bootstrap/bootstrap-lock-instance.d.ts +0 -7
- package/lib/entries/ble/bootstrap/bootstrap-lock-instance.js +0 -12
- package/lib/entries/ble/bootstrap/bootstrap.d.ts +0 -4
- package/lib/entries/ble/bootstrap/bootstrap.js +0 -53
- package/lib/entries/ble/bootstrap/lock-instance-runtime-ref.d.ts +0 -3
- package/lib/entries/ble/bootstrap/lock-instance-runtime-ref.js +0 -7
- package/lib/entries/ble/bootstrap/primary-instance.d.ts +0 -6
- package/lib/entries/ble/bootstrap/primary-instance.js +0 -24
- package/lib/entries/ble/bootstrap/resolve-runtime-from-export-this.d.ts +0 -5
- package/lib/entries/ble/bootstrap/resolve-runtime-from-export-this.js +0 -29
- package/lib/entries/ble/bootstrap/top-level-runtime.d.ts +0 -2
- package/lib/entries/ble/bootstrap/top-level-runtime.js +0 -9
- package/lib/entries/ble/build-instance.d.ts +0 -9
- package/lib/entries/ble/build-instance.js +0 -50
- package/lib/entries/ble/exports/capability.d.ts +0 -6
- package/lib/entries/ble/exports/capability.js +0 -17
- package/lib/entries/ble/exports/config.d.ts +0 -3
- package/lib/entries/ble/exports/config.js +0 -5
- package/lib/entries/ble/exports/dp.d.ts +0 -9
- package/lib/entries/ble/exports/dp.js +0 -13
- package/lib/entries/ble/exports/index.d.ts +0 -16
- package/lib/entries/ble/exports/index.js +0 -16
- package/lib/entries/ble/exports/linkage.d.ts +0 -5
- package/lib/entries/ble/exports/linkage.js +0 -15
- package/lib/entries/ble/exports/log.d.ts +0 -9
- package/lib/entries/ble/exports/log.js +0 -21
- package/lib/entries/ble/exports/media.d.ts +0 -4
- package/lib/entries/ble/exports/media.js +0 -12
- package/lib/entries/ble/exports/misc.d.ts +0 -19
- package/lib/entries/ble/exports/misc.js +0 -30
- package/lib/entries/ble/exports/offline-dps.d.ts +0 -8
- package/lib/entries/ble/exports/offline-dps.js +0 -24
- package/lib/entries/ble/exports/open/do-open-close-action.d.ts +0 -2
- package/lib/entries/ble/exports/open/do-open-close-action.js +0 -36
- package/lib/entries/ble/exports/open/index.d.ts +0 -18
- package/lib/entries/ble/exports/open/index.js +0 -45
- package/lib/entries/ble/exports/signal.d.ts +0 -6
- package/lib/entries/ble/exports/signal.js +0 -14
- package/lib/entries/ble/exports/sleep.d.ts +0 -13
- package/lib/entries/ble/exports/sleep.js +0 -31
- package/lib/entries/ble/exports/state.d.ts +0 -6
- package/lib/entries/ble/exports/state.js +0 -19
- package/lib/entries/ble/exports/temporary.d.ts +0 -31
- package/lib/entries/ble/exports/temporary.js +0 -91
- package/lib/entries/ble/exports/unlock/sync.d.ts +0 -1
- package/lib/entries/ble/exports/unlock/sync.js +0 -5
- package/lib/entries/ble/exports/unlock-method.d.ts +0 -19
- package/lib/entries/ble/exports/unlock-method.js +0 -58
- package/lib/entries/ble/exports/user/index.d.ts +0 -23
- package/lib/entries/ble/exports/user/index.js +0 -22
- package/lib/entries/ble/exports/user/sync.d.ts +0 -1
- package/lib/entries/ble/exports/user/sync.js +0 -5
- package/lib/entries/ble/index.d.ts +0 -8
- package/lib/entries/ble/index.js +0 -39
- package/lib/entries/fit/bootstrap/bootstrap-lock-instance.d.ts +0 -7
- package/lib/entries/fit/bootstrap/bootstrap-lock-instance.js +0 -12
- package/lib/entries/fit/bootstrap/bootstrap.d.ts +0 -4
- package/lib/entries/fit/bootstrap/bootstrap.js +0 -69
- package/lib/entries/fit/bootstrap/lock-instance-runtime-ref.d.ts +0 -3
- package/lib/entries/fit/bootstrap/lock-instance-runtime-ref.js +0 -7
- package/lib/entries/fit/bootstrap/primary-instance.d.ts +0 -6
- package/lib/entries/fit/bootstrap/primary-instance.js +0 -24
- package/lib/entries/fit/bootstrap/resolve-runtime-from-export-this.d.ts +0 -5
- package/lib/entries/fit/bootstrap/resolve-runtime-from-export-this.js +0 -29
- package/lib/entries/fit/bootstrap/top-level-runtime.d.ts +0 -2
- package/lib/entries/fit/bootstrap/top-level-runtime.js +0 -9
- package/lib/entries/fit/build-instance.d.ts +0 -9
- package/lib/entries/fit/build-instance.js +0 -57
- package/lib/entries/fit/exports/binding.d.ts +0 -8
- package/lib/entries/fit/exports/temp.d.ts +0 -19
- package/lib/entries/fit/exports/temp.js +0 -18
- package/lib/entries/fit/index.d.ts +0 -8
- package/lib/entries/fit/index.js +0 -36
- package/lib/entries/main/exports/open.d.ts +0 -16
- package/lib/entries/main/exports/open.js +0 -44
- package/lib/entries/screen/bootstrap/bootstrap-lock-instance.d.ts +0 -7
- package/lib/entries/screen/bootstrap/bootstrap-lock-instance.js +0 -12
- package/lib/entries/screen/bootstrap/bootstrap.d.ts +0 -4
- package/lib/entries/screen/bootstrap/bootstrap.js +0 -69
- package/lib/entries/screen/bootstrap/lock-instance-runtime-ref.d.ts +0 -3
- package/lib/entries/screen/bootstrap/lock-instance-runtime-ref.js +0 -7
- package/lib/entries/screen/bootstrap/primary-instance.d.ts +0 -6
- package/lib/entries/screen/bootstrap/primary-instance.js +0 -24
- package/lib/entries/screen/bootstrap/resolve-runtime-from-export-this.d.ts +0 -5
- package/lib/entries/screen/bootstrap/resolve-runtime-from-export-this.js +0 -29
- package/lib/entries/screen/bootstrap/top-level-runtime.d.ts +0 -2
- package/lib/entries/screen/bootstrap/top-level-runtime.js +0 -9
- package/lib/entries/screen/build-instance.d.ts +0 -9
- package/lib/entries/screen/build-instance.js +0 -57
- package/lib/entries/screen/exports/bind-events.d.ts +0 -4
- package/lib/entries/screen/exports/bind-events.js +0 -8
- package/lib/entries/screen/exports/binding.d.ts +0 -6
- package/lib/entries/screen/exports/binding.js +0 -15
- package/lib/entries/screen/exports/device.d.ts +0 -16
- package/lib/entries/screen/exports/device.js +0 -41
- package/lib/entries/screen/exports/event.d.ts +0 -3
- package/lib/entries/screen/exports/event.js +0 -5
- package/lib/entries/screen/exports/index.d.ts +0 -5
- package/lib/entries/screen/exports/index.js +0 -5
- package/lib/entries/screen/exports/user.d.ts +0 -2
- package/lib/entries/screen/exports/user.js +0 -8
- package/lib/entries/screen/index.d.ts +0 -8
- package/lib/entries/screen/index.js +0 -36
- package/lib/feature/unlock/door/door-action.d.ts +0 -2
- package/lib/feature/unlock/door/door-action.js +0 -32
- package/lib/fit.d.ts +0 -4
- package/lib/fit.js +0 -3
- package/lib/runtime/device-status/compute-device-status.d.ts +0 -25
- package/lib/runtime/device-status/compute-device-status.js +0 -94
- package/lib/screen.d.ts +0 -4
- package/lib/screen.js +0 -3
|
@@ -19,8 +19,8 @@ export function getDpPeriodTime(dpCode) {
|
|
|
19
19
|
export function updateDpPeriodTime(dpCode, data, option) {
|
|
20
20
|
return updateDpPeriodTimeForRuntime(resolveRuntimeFromExportThis(this), dpCode, data, option);
|
|
21
21
|
}
|
|
22
|
-
export async function connectDevice() {
|
|
23
|
-
return connectDeviceForRuntime(resolveRuntimeFromExportThis(this));
|
|
22
|
+
export async function connectDevice(options) {
|
|
23
|
+
return connectDeviceForRuntime(resolveRuntimeFromExportThis(this), options?.timeout);
|
|
24
24
|
}
|
|
25
25
|
export async function gotoService(params) {
|
|
26
26
|
return gotoServiceForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { VasNotifyConfig, VasNotifyScene, VasNotifyPushConfig, UpdateVasNotifyConfigParams, } from "../../../api/notify";
|
|
2
|
+
export declare function getVasNotifyConfig(): Promise<import("../../../api/notify").VasNotifyConfig>;
|
|
3
|
+
export declare function updateVasNotifyConfig(params: {
|
|
4
|
+
key: string;
|
|
5
|
+
enable: boolean;
|
|
6
|
+
userId?: string;
|
|
7
|
+
}): Promise<import("../../../api/notify").VasNotifyConfig>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
|
|
2
|
+
import { getVasNotifyConfigForRuntime, updateVasNotifyConfigForRuntime, } from "../../../feature/notify/notify";
|
|
3
|
+
export async function getVasNotifyConfig() {
|
|
4
|
+
return getVasNotifyConfigForRuntime(resolveRuntimeFromExportThis(this));
|
|
5
|
+
}
|
|
6
|
+
export async function updateVasNotifyConfig(params) {
|
|
7
|
+
return updateVasNotifyConfigForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
8
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { CloudServiceStatus, ServiceBenefitPopupItem, ClaimResultItem, } from "../../../api/service";
|
|
2
|
+
export declare function getCloudServiceStatus(): Promise<import("../../../api/service").CloudServiceStatus>;
|
|
3
|
+
export declare function getServicePopupList(): Promise<import("../../../api/service").ServiceBenefitPopupItem[]>;
|
|
4
|
+
export declare function claimService(batchId: string): Promise<import("../../../api/service").ClaimResultItem[]>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
|
|
2
|
+
import { getCloudServiceStatusForRuntime, getServicePopupListForRuntime, claimServiceForRuntime, } from "../../../feature/service/value-added";
|
|
3
|
+
export async function getCloudServiceStatus() {
|
|
4
|
+
return getCloudServiceStatusForRuntime(resolveRuntimeFromExportThis(this));
|
|
5
|
+
}
|
|
6
|
+
export async function getServicePopupList() {
|
|
7
|
+
return getServicePopupListForRuntime(resolveRuntimeFromExportThis(this));
|
|
8
|
+
}
|
|
9
|
+
export async function claimService(batchId) {
|
|
10
|
+
return claimServiceForRuntime(resolveRuntimeFromExportThis(this), batchId);
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
|
|
2
|
+
import { getVoipAuthForRuntime, saveVoipAuthForRuntime, } from "../../../feature/voip/voip";
|
|
3
|
+
export async function getVoipAuth() {
|
|
4
|
+
return getVoipAuthForRuntime(resolveRuntimeFromExportThis(this));
|
|
5
|
+
}
|
|
6
|
+
export async function saveVoipAuth(userId) {
|
|
7
|
+
return saveVoipAuthForRuntime(resolveRuntimeFromExportThis(this), userId);
|
|
8
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { LockSDKOption } from "../../interface";
|
|
2
|
-
import type { LockSDKInstance } from "./build-instance";
|
|
2
|
+
import type { LockSDKInstance, FitSDKInstance } from "./build-instance";
|
|
3
3
|
export * from "./exports";
|
|
4
|
-
export type { LockSDKInstance };
|
|
4
|
+
export type { LockSDKInstance, FitSDKInstance };
|
|
5
5
|
export type { LockSdkBoundExportThis } from "./bootstrap/resolve-runtime-from-export-this";
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const createSDK: (options?: Omit<LockSDKOption, "preFetch">) => Promise<LockSDKInstance>;
|
|
7
7
|
export declare const init: (options?: LockSDKOption) => Promise<void>;
|
|
8
8
|
export declare const destroy: () => void;
|
|
@@ -1,34 +1,40 @@
|
|
|
1
1
|
import { clearStateForRuntime } from "../../feature/state/clear";
|
|
2
2
|
import { removeEvents } from "../../feature/state/platform-routing";
|
|
3
|
-
import {
|
|
3
|
+
import { bootstrapRegisteredInstance } from "./bootstrap/bootstrap-lock-instance";
|
|
4
4
|
import { clearPrimaryLockSDKInstance, setPrimaryLockSDKInstance, } from "./bootstrap/primary-instance";
|
|
5
5
|
import { clearAllRuntimes, listRegisteredRuntimes, } from "../../runtime/registry";
|
|
6
6
|
import { getLaunchOptionsSync } from "../../platform/device";
|
|
7
|
+
import { stopFitSyncReportForRuntime } from "../../feature/fit/sync";
|
|
7
8
|
import { getError } from "../../utils/errors";
|
|
8
9
|
export * from "./exports";
|
|
9
|
-
export const
|
|
10
|
-
const
|
|
10
|
+
export const createSDK = async (options) => {
|
|
11
|
+
const kind = options?.kind ?? "lock";
|
|
12
|
+
const { instance } = await bootstrapRegisteredInstance(kind, {
|
|
11
13
|
...options,
|
|
12
14
|
preFetch: false,
|
|
13
15
|
});
|
|
14
16
|
return instance;
|
|
15
17
|
};
|
|
16
18
|
export const init = async (options) => {
|
|
19
|
+
const kind = options?.kind ?? "lock";
|
|
17
20
|
const opts = { ...options };
|
|
18
21
|
const { devInfo, deviceId } = opts;
|
|
19
22
|
if (!devInfo && !deviceId) {
|
|
20
23
|
const { query } = getLaunchOptionsSync();
|
|
21
|
-
opts.deviceId = query
|
|
24
|
+
opts.deviceId = query['deviceId'];
|
|
22
25
|
if (!opts.deviceId) {
|
|
23
26
|
throw getError(1000);
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
|
-
const { instance } = await
|
|
29
|
+
const { instance } = await bootstrapRegisteredInstance(kind, opts);
|
|
27
30
|
setPrimaryLockSDKInstance(instance);
|
|
28
31
|
};
|
|
29
32
|
export const destroy = () => {
|
|
30
33
|
removeEvents();
|
|
31
34
|
for (const rt of listRegisteredRuntimes()) {
|
|
35
|
+
if (rt.config.isFitting) {
|
|
36
|
+
stopFitSyncReportForRuntime(rt);
|
|
37
|
+
}
|
|
32
38
|
clearStateForRuntime(rt);
|
|
33
39
|
}
|
|
34
40
|
clearAllRuntimes();
|
|
@@ -2,3 +2,4 @@ import { BoundFitLockItem, LockFitItemBase } from "../../api/fit";
|
|
|
2
2
|
import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
|
|
3
3
|
export declare function bindLockToFitForRuntime(runtime: LockDeviceRuntime, lock: LockFitItemBase): Promise<unknown>;
|
|
4
4
|
export declare function unbindLockToFitForRuntime(runtime: LockDeviceRuntime, lock: BoundFitLockItem): Promise<unknown>;
|
|
5
|
+
export declare function activateLockToFitForRuntime(runtime: LockDeviceRuntime, lock: LockFitItemBase): Promise<void>;
|
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
import { bindLockAndFit, unbindFitFromLockCloud, unbindLockFromFitCloud, } from "../../api/fit";
|
|
2
|
+
import { setDeviceProperties } from "../../api/setting";
|
|
2
3
|
import { getUsersSyncLockData } from "../../api/user";
|
|
3
4
|
import { offDpDataChange, onDpDataChange, publishDeviceDps, } from "../../platform/device";
|
|
4
5
|
import { getError } from "../../utils/errors";
|
|
5
6
|
import { sdkLog } from "../../utils/sdk-log";
|
|
7
|
+
import { getSecurityUpdatedLockIds, isFitSecurityChannelEnabledForRuntime, } from "./security-channel";
|
|
6
8
|
import { FIT_BIND_TIMEOUT_MS, FIT_OPERATION_CODE, normalizeHex, buildLockCheckCodeTemplate, publishFitTransparentFlow, } from "./shared";
|
|
9
|
+
const markSecurityUpdated = async (runtime, lock) => {
|
|
10
|
+
if (!lock.isSupportScy || !isFitSecurityChannelEnabledForRuntime(runtime)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const fittingId = runtime.devId;
|
|
14
|
+
try {
|
|
15
|
+
const list = await getSecurityUpdatedLockIds(fittingId);
|
|
16
|
+
if (list.includes(lock.devId)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
await setDeviceProperties(fittingId, {
|
|
20
|
+
SECURITY_UPDATED: JSON.stringify({
|
|
21
|
+
key: fittingId,
|
|
22
|
+
value: [...list, lock.devId],
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
sdkLog("warn", "fit", "markSecurityUpdatedError", {
|
|
28
|
+
devId: fittingId,
|
|
29
|
+
data: { lockDevId: lock.devId },
|
|
30
|
+
error: e,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
7
34
|
const CHECK_CODE_SET_DP_ID = "70";
|
|
8
35
|
const delay = (ms) => new Promise((resolve) => {
|
|
9
36
|
setTimeout(resolve, ms);
|
|
@@ -104,6 +131,7 @@ export async function bindLockToFitForRuntime(runtime, lock) {
|
|
|
104
131
|
devId: runtime.devId,
|
|
105
132
|
data: { lockDevId: lock.devId },
|
|
106
133
|
});
|
|
134
|
+
await markSecurityUpdated(runtime, lock);
|
|
107
135
|
await publishToLock(runtime, "bind", lock);
|
|
108
136
|
const result = await bindLockAndFit({
|
|
109
137
|
devId: lock.devId,
|
|
@@ -165,3 +193,28 @@ export async function unbindLockToFitForRuntime(runtime, lock) {
|
|
|
165
193
|
throw error;
|
|
166
194
|
}
|
|
167
195
|
}
|
|
196
|
+
export async function activateLockToFitForRuntime(runtime, lock) {
|
|
197
|
+
const startedAt = Date.now();
|
|
198
|
+
sdkLog("info", "fit", "activateLockToFitStart", {
|
|
199
|
+
devId: runtime.devId,
|
|
200
|
+
data: { lockDevId: lock.devId },
|
|
201
|
+
});
|
|
202
|
+
try {
|
|
203
|
+
await publishToFitting(runtime, "bind", lock);
|
|
204
|
+
await markSecurityUpdated(runtime, lock);
|
|
205
|
+
sdkLog("info", "fit", "activateLockToFitSuccess", {
|
|
206
|
+
devId: runtime.devId,
|
|
207
|
+
duration: Date.now() - startedAt,
|
|
208
|
+
data: { lockDevId: lock.devId },
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
sdkLog("error", "fit", "activateLockToFitFail", {
|
|
213
|
+
devId: runtime.devId,
|
|
214
|
+
duration: Date.now() - startedAt,
|
|
215
|
+
data: { lockDevId: lock.devId },
|
|
216
|
+
error,
|
|
217
|
+
});
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
|
|
2
|
-
import { EffectiveConfig } from "../../interface";
|
|
3
|
-
export declare function getFitBleKeyListForRuntime(runtime: LockDeviceRuntime): Promise<
|
|
2
|
+
import { EffectiveConfig, FitBleKeyItem } from "../../interface";
|
|
3
|
+
export declare function getFitBleKeyListForRuntime(runtime: LockDeviceRuntime): Promise<FitBleKeyItem[]>;
|
|
4
|
+
export interface CreateTemporaryBleKeyParams {
|
|
5
|
+
name?: string;
|
|
6
|
+
effective: EffectiveConfig;
|
|
7
|
+
}
|
|
8
|
+
export declare function createFitPermanentBleKeyForRuntime(runtime: LockDeviceRuntime, userId: string): Promise<unknown>;
|
|
9
|
+
export declare function createFitTemporaryBleKeyForRuntime(runtime: LockDeviceRuntime, params: CreateTemporaryBleKeyParams): Promise<unknown>;
|
|
4
10
|
export declare function addFitBleKeyForRuntime(runtime: LockDeviceRuntime, params: Record<string, unknown>): Promise<unknown>;
|
|
5
|
-
export interface
|
|
11
|
+
export interface UpdateTemporaryBleKeyParams {
|
|
6
12
|
id: string;
|
|
7
13
|
name: string;
|
|
8
14
|
effective: EffectiveConfig;
|
|
9
15
|
}
|
|
10
|
-
export declare function
|
|
16
|
+
export declare function updateFitTemporaryBleKeyForRuntime(runtime: LockDeviceRuntime, params: UpdateTemporaryBleKeyParams): Promise<unknown>;
|
|
11
17
|
export declare function removeFitBleKeyForRuntime(runtime: LockDeviceRuntime, unlockBindingId: string): Promise<unknown>;
|
|
12
18
|
export interface RenameFitBleKeyParams {
|
|
13
19
|
id: string;
|
|
@@ -1,18 +1,141 @@
|
|
|
1
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
1
2
|
import { getFitBleKeyListApi, addFitBleKeyApi, updateFitBleKeyApi, removeFitBleKeyApi, renameFitBleKeyApi, } from "../../api/fit";
|
|
3
|
+
import dpCodes from "../../config/dp-code";
|
|
4
|
+
import { fitAddBleKey, fitModifyBleKey } from "../../config/dp-map/ble-key-fit";
|
|
5
|
+
import { publishDpsForRuntime } from "../dp/publish-dps";
|
|
6
|
+
import { getError } from "../../utils/errors";
|
|
2
7
|
import { sdkLog } from "../../utils/sdk-log";
|
|
3
|
-
import {
|
|
8
|
+
import { UserType } from "../../constant";
|
|
9
|
+
import { getFitUsersForRuntime } from "./users";
|
|
10
|
+
import { formatWeek, parseWeek, transformEffectiveConfigToValidConfig, validateEffectiveConfig, } from "../../utils";
|
|
11
|
+
function normalizeBleKey(item) {
|
|
12
|
+
const effectiveConfig = {
|
|
13
|
+
effectiveDate: item.effectiveTime,
|
|
14
|
+
expiredDate: item.invalidTime,
|
|
15
|
+
};
|
|
16
|
+
const schedule = item.scheduleDetails?.[0];
|
|
17
|
+
if (schedule) {
|
|
18
|
+
if (schedule.allDay === false) {
|
|
19
|
+
effectiveConfig.repeat = "week";
|
|
20
|
+
effectiveConfig.weeks = parseWeek(schedule.workingDay);
|
|
21
|
+
effectiveConfig.effectiveTime = schedule.effectiveTime;
|
|
22
|
+
effectiveConfig.expiredTime = schedule.invalidTime;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
effectiveConfig.repeat = "none";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
id: item.id,
|
|
30
|
+
unlockBindingId: item.unlockBindingId,
|
|
31
|
+
name: item.name,
|
|
32
|
+
opModeSubType: item.opModeSubType,
|
|
33
|
+
effectiveConfig,
|
|
34
|
+
sn: item.sn,
|
|
35
|
+
userName: item.userName,
|
|
36
|
+
devNameList: item.devNameList,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
4
39
|
export async function getFitBleKeyListForRuntime(runtime) {
|
|
5
40
|
const startedAt = Date.now();
|
|
6
41
|
sdkLog("info", "fit", "getBleKeyListStart", {
|
|
7
42
|
devId: runtime.devId,
|
|
8
43
|
});
|
|
9
44
|
const list = await getFitBleKeyListApi(runtime.devId);
|
|
45
|
+
const result = (list || []).map(normalizeBleKey);
|
|
10
46
|
sdkLog("info", "fit", "getBleKeyListSuccess", {
|
|
11
47
|
devId: runtime.devId,
|
|
12
48
|
duration: Date.now() - startedAt,
|
|
13
|
-
data: { count:
|
|
49
|
+
data: { count: result.length },
|
|
50
|
+
});
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
async function createFitBleKeyWithPayload(runtime, keyType, startedAt, payload, addToCloud) {
|
|
54
|
+
const report = await publishDpsForRuntime(runtime, { [dpCodes.bleKeyCreate]: payload }, {
|
|
55
|
+
checkReport: (dps) => {
|
|
56
|
+
const raw = dps[dpCodes.bleKeyCreate];
|
|
57
|
+
if (!raw || raw.length < 44)
|
|
58
|
+
return false;
|
|
59
|
+
return { sn: raw.slice(4, 6), status: raw.slice(42, 44) };
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
if (report.status !== "00") {
|
|
63
|
+
sdkLog("warn", "fit", "createBleKeyDeviceFail", {
|
|
64
|
+
devId: runtime.devId,
|
|
65
|
+
data: { type: keyType, status: report.status },
|
|
66
|
+
});
|
|
67
|
+
throw getError(1042);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const result = await addToCloud(parseInt(report.sn, 16));
|
|
71
|
+
sdkLog("info", "fit", "createBleKeySuccess", {
|
|
72
|
+
devId: runtime.devId,
|
|
73
|
+
duration: Date.now() - startedAt,
|
|
74
|
+
data: { type: keyType },
|
|
75
|
+
});
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
publishDpsForRuntime(runtime, { [dpCodes.bleKeyDelete]: "0000" }, { timeout: 5000 }).catch(() => {
|
|
80
|
+
});
|
|
81
|
+
sdkLog("error", "fit", "createBleKeyCloudFail", {
|
|
82
|
+
devId: runtime.devId,
|
|
83
|
+
duration: Date.now() - startedAt,
|
|
84
|
+
data: { type: keyType },
|
|
85
|
+
error,
|
|
86
|
+
});
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
export async function createFitPermanentBleKeyForRuntime(runtime, userId) {
|
|
91
|
+
const startedAt = Date.now();
|
|
92
|
+
sdkLog("info", "fit", "createBleKeyStart", {
|
|
93
|
+
devId: runtime.devId,
|
|
94
|
+
data: { type: "permanent" },
|
|
95
|
+
});
|
|
96
|
+
const users = await getFitUsersForRuntime(runtime);
|
|
97
|
+
const user = users.find((item) => item.userId === userId);
|
|
98
|
+
if (!user) {
|
|
99
|
+
sdkLog("warn", "fit", "createBleKeyUserNotFound", {
|
|
100
|
+
devId: runtime.devId,
|
|
101
|
+
duration: Date.now() - startedAt,
|
|
102
|
+
data: { userCount: users.length },
|
|
103
|
+
});
|
|
104
|
+
throw getError(1048);
|
|
105
|
+
}
|
|
106
|
+
const admin = user.userType === UserType.ADMIN;
|
|
107
|
+
const payload = `000000${admin ? "01" : "00"}${user.userTimeSet}`;
|
|
108
|
+
return createFitBleKeyWithPayload(runtime, "permanent", startedAt, payload, (sn) => addFitBleKeyApi(runtime.devId, { sn, userId, timeSetType: 10 }));
|
|
109
|
+
}
|
|
110
|
+
export async function createFitTemporaryBleKeyForRuntime(runtime, params) {
|
|
111
|
+
const startedAt = Date.now();
|
|
112
|
+
sdkLog("info", "fit", "createBleKeyStart", {
|
|
113
|
+
devId: runtime.devId,
|
|
114
|
+
data: { type: "temporary" },
|
|
14
115
|
});
|
|
15
|
-
|
|
116
|
+
validateEffectiveConfig(params.effective);
|
|
117
|
+
const { effective } = params;
|
|
118
|
+
const payload = dpUtils.format({
|
|
119
|
+
slaveId: 0,
|
|
120
|
+
memberId: 0,
|
|
121
|
+
admin: false,
|
|
122
|
+
validConfig: transformEffectiveConfigToValidConfig(effective),
|
|
123
|
+
}, fitAddBleKey);
|
|
124
|
+
return createFitBleKeyWithPayload(runtime, "temporary", startedAt, payload, (sn) => addFitBleKeyApi(runtime.devId, {
|
|
125
|
+
sn,
|
|
126
|
+
effectiveTime: effective.effectiveDate,
|
|
127
|
+
invalidTime: effective.expiredDate,
|
|
128
|
+
schedule: [
|
|
129
|
+
{
|
|
130
|
+
allDay: effective.repeat !== "week",
|
|
131
|
+
effectiveTime: effective.effectiveTime ?? 0,
|
|
132
|
+
invalidTime: effective.expiredTime ?? 0,
|
|
133
|
+
workingDay: formatWeek(effective.weeks ?? [0]),
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
name: params.name,
|
|
137
|
+
timeSetType: effective.repeat !== "week" ? 20 : 30,
|
|
138
|
+
}));
|
|
16
139
|
}
|
|
17
140
|
export async function addFitBleKeyForRuntime(runtime, params) {
|
|
18
141
|
const startedAt = Date.now();
|
|
@@ -31,7 +154,7 @@ export async function addFitBleKeyForRuntime(runtime, params) {
|
|
|
31
154
|
});
|
|
32
155
|
return result;
|
|
33
156
|
}
|
|
34
|
-
export async function
|
|
157
|
+
export async function updateFitTemporaryBleKeyForRuntime(runtime, params) {
|
|
35
158
|
const startedAt = Date.now();
|
|
36
159
|
const logParams = params ?? {};
|
|
37
160
|
sdkLog("info", "fit", "updateBleKeyStart", {
|
|
@@ -41,6 +164,24 @@ export async function updateFitBleKeyForRuntime(runtime, params) {
|
|
|
41
164
|
hasId: typeof logParams["id"] === "string",
|
|
42
165
|
},
|
|
43
166
|
});
|
|
167
|
+
validateEffectiveConfig(params.effective);
|
|
168
|
+
const validConfig = transformEffectiveConfigToValidConfig(params.effective);
|
|
169
|
+
const payload = dpUtils.format({ slaveId: 0, memberId: 0, admin: false, validConfig }, fitModifyBleKey);
|
|
170
|
+
const report = await publishDpsForRuntime(runtime, { [dpCodes.bleKeyModify]: payload }, {
|
|
171
|
+
checkReport: (dps) => {
|
|
172
|
+
const raw = dps[dpCodes.bleKeyModify];
|
|
173
|
+
if (!raw || raw.length < 44)
|
|
174
|
+
return false;
|
|
175
|
+
return { status: raw.slice(42, 44) };
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
if (report.status !== "00") {
|
|
179
|
+
sdkLog("warn", "fit", "updateBleKeyDeviceFail", {
|
|
180
|
+
devId: runtime.devId,
|
|
181
|
+
data: { status: report.status },
|
|
182
|
+
});
|
|
183
|
+
throw getError(1042);
|
|
184
|
+
}
|
|
44
185
|
const schedule = [
|
|
45
186
|
{
|
|
46
187
|
allDay: params.effective.repeat !== "week",
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getFitDeviceBVApi } from "../../api/fit";
|
|
2
|
+
export const getFitDeviceBvForRuntime = (runtime) => {
|
|
3
|
+
const cached = runtime.cache.fitDeviceBvCache;
|
|
4
|
+
if (cached) {
|
|
5
|
+
return cached;
|
|
6
|
+
}
|
|
7
|
+
const pending = getFitDeviceBVApi(runtime.devId).catch((error) => {
|
|
8
|
+
if (runtime.cache.fitDeviceBvCache === pending) {
|
|
9
|
+
runtime.cache.fitDeviceBvCache = undefined;
|
|
10
|
+
}
|
|
11
|
+
throw error;
|
|
12
|
+
});
|
|
13
|
+
runtime.cache.fitDeviceBvCache = pending;
|
|
14
|
+
return pending;
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
|
|
2
|
+
import { type FitInvalidPwdQuery, type FitInvalidPwdListResult } from "../../api/fit";
|
|
3
|
+
export type { FitInvalidPwdQuery, FitInvalidPwdListResult };
|
|
4
|
+
export interface GetFitInvalidPwdListParams extends FitInvalidPwdQuery {
|
|
5
|
+
}
|
|
6
|
+
export interface ClearFitInvalidPwdParams {
|
|
7
|
+
opMode?: number | string;
|
|
8
|
+
}
|
|
9
|
+
export declare function getFitInvalidPwdListForRuntime(runtime: LockDeviceRuntime, params?: GetFitInvalidPwdListParams): Promise<FitInvalidPwdListResult>;
|
|
10
|
+
export declare function clearFitInvalidPwdForRuntime(runtime: LockDeviceRuntime, params?: ClearFitInvalidPwdParams): Promise<boolean>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { clearFitInvalidPwdApi, getFitInvalidPwdListApi, } from "../../api/fit";
|
|
2
|
+
import { getError } from "../../utils/errors";
|
|
3
|
+
import { sdkLog } from "../../utils/sdk-log";
|
|
4
|
+
export async function getFitInvalidPwdListForRuntime(runtime, params = {}) {
|
|
5
|
+
const startedAt = Date.now();
|
|
6
|
+
sdkLog("info", "fitInvalidPwd", "getListStart", {
|
|
7
|
+
devId: runtime.devId,
|
|
8
|
+
data: { hasOpMode: params.opMode !== undefined },
|
|
9
|
+
});
|
|
10
|
+
try {
|
|
11
|
+
const result = await getFitInvalidPwdListApi(runtime.devId, params);
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export async function clearFitInvalidPwdForRuntime(runtime, params = {}) {
|
|
19
|
+
const startedAt = Date.now();
|
|
20
|
+
sdkLog("info", "fitInvalidPwd", "clearStart", {
|
|
21
|
+
devId: runtime.devId,
|
|
22
|
+
data: { hasOpMode: params.opMode !== undefined },
|
|
23
|
+
});
|
|
24
|
+
try {
|
|
25
|
+
const result = await clearFitInvalidPwdApi(runtime.devId, params.opMode);
|
|
26
|
+
sdkLog("info", "fitInvalidPwd", "clearSuccess", {
|
|
27
|
+
devId: runtime.devId,
|
|
28
|
+
duration: Date.now() - startedAt,
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
sdkLog("error", "fitInvalidPwd", "clearFail", {
|
|
34
|
+
devId: runtime.devId,
|
|
35
|
+
duration: Date.now() - startedAt,
|
|
36
|
+
error,
|
|
37
|
+
});
|
|
38
|
+
if (typeof error?.errorCode === "number") {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
throw getError(1028);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { type BoundFitLockItem, type UnbindLockItem } from "../../api/fit";
|
|
1
2
|
import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
3
|
+
export type FitLockUnbindableReason = "ble_version_mismatch" | "security_version_mismatch";
|
|
4
|
+
export interface UnbindLockListItem extends UnbindLockItem {
|
|
5
|
+
bindable: boolean;
|
|
6
|
+
unbindableReason?: FitLockUnbindableReason;
|
|
7
|
+
}
|
|
8
|
+
export interface BoundLockListItem extends BoundFitLockItem {
|
|
9
|
+
securityVersionMismatch: boolean;
|
|
10
|
+
securityNeedUpdate: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function getBoundLockListForRuntime(runtime: LockDeviceRuntime): Promise<BoundLockListItem[]>;
|
|
13
|
+
export declare function getUnbindLockListForRuntime(runtime: LockDeviceRuntime): Promise<UnbindLockListItem[]>;
|
package/lib/feature/fit/list.js
CHANGED
|
@@ -1,28 +1,77 @@
|
|
|
1
1
|
import { getBoundLockListApi, getUnbindLockListApi, } from "../../api/fit";
|
|
2
2
|
import { sdkLog } from "../../utils/sdk-log";
|
|
3
|
+
import { getFitDeviceBvForRuntime } from "./device-bv";
|
|
4
|
+
import { getSecurityUpdatedLockIds, isFitSecurityChannelEnabledForRuntime, } from "./security-channel";
|
|
5
|
+
const isSecurityVersionMismatch = (runtime, lock) => !!lock.isSupportScy && !isFitSecurityChannelEnabledForRuntime(runtime);
|
|
6
|
+
const resolveUnbindableReason = (runtime, lock, fitBv) => {
|
|
7
|
+
const lockBv = Number(lock.protocolVersion) || 0;
|
|
8
|
+
if (lockBv && fitBv && lockBv !== fitBv) {
|
|
9
|
+
return "ble_version_mismatch";
|
|
10
|
+
}
|
|
11
|
+
if (isSecurityVersionMismatch(runtime, lock)) {
|
|
12
|
+
return "security_version_mismatch";
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
3
16
|
export async function getBoundLockListForRuntime(runtime) {
|
|
4
17
|
const startedAt = Date.now();
|
|
5
18
|
sdkLog("info", "fit", "getBoundLockListStart", {
|
|
6
19
|
devId: runtime.devId,
|
|
7
20
|
});
|
|
8
21
|
const list = await getBoundLockListApi(runtime.devId);
|
|
22
|
+
const rawItems = Array.isArray(list) ? list : [];
|
|
23
|
+
const securityEnabled = isFitSecurityChannelEnabledForRuntime(runtime);
|
|
24
|
+
const securityUpdatedIds = securityEnabled && rawItems.some((lock) => lock.isSupportScy)
|
|
25
|
+
? await getSecurityUpdatedLockIds(runtime.devId)
|
|
26
|
+
: [];
|
|
27
|
+
const items = rawItems.map((lock) => ({
|
|
28
|
+
...lock,
|
|
29
|
+
securityVersionMismatch: isSecurityVersionMismatch(runtime, lock),
|
|
30
|
+
securityNeedUpdate: securityEnabled &&
|
|
31
|
+
!!lock.isSupportScy &&
|
|
32
|
+
!securityUpdatedIds.includes(lock.devId),
|
|
33
|
+
}));
|
|
9
34
|
sdkLog("info", "fit", "getBoundLockListSuccess", {
|
|
10
35
|
devId: runtime.devId,
|
|
11
36
|
duration: Date.now() - startedAt,
|
|
12
|
-
data: {
|
|
37
|
+
data: {
|
|
38
|
+
count: items.length,
|
|
39
|
+
securityMismatchCount: items.filter((item) => item.securityVersionMismatch).length,
|
|
40
|
+
securityNeedUpdateCount: items.filter((item) => item.securityNeedUpdate)
|
|
41
|
+
.length,
|
|
42
|
+
},
|
|
13
43
|
});
|
|
14
|
-
return
|
|
44
|
+
return items;
|
|
15
45
|
}
|
|
16
46
|
export async function getUnbindLockListForRuntime(runtime) {
|
|
17
47
|
const startedAt = Date.now();
|
|
18
48
|
sdkLog("info", "fit", "getUnbindLockListStart", {
|
|
19
49
|
devId: runtime.devId,
|
|
20
50
|
});
|
|
21
|
-
const list = await
|
|
51
|
+
const [list, fitBv] = await Promise.all([
|
|
52
|
+
getUnbindLockListApi(runtime.devId),
|
|
53
|
+
getFitDeviceBvForRuntime(runtime).catch((error) => {
|
|
54
|
+
sdkLog("warn", "fit", "getUnbindLockListBvFailed", {
|
|
55
|
+
devId: runtime.devId,
|
|
56
|
+
error,
|
|
57
|
+
});
|
|
58
|
+
return 0;
|
|
59
|
+
}),
|
|
60
|
+
]);
|
|
61
|
+
const items = (Array.isArray(list) ? list : []).map((lock) => {
|
|
62
|
+
const unbindableReason = resolveUnbindableReason(runtime, lock, fitBv);
|
|
63
|
+
return unbindableReason
|
|
64
|
+
? { ...lock, bindable: false, unbindableReason }
|
|
65
|
+
: { ...lock, bindable: true };
|
|
66
|
+
});
|
|
22
67
|
sdkLog("info", "fit", "getUnbindLockListSuccess", {
|
|
23
68
|
devId: runtime.devId,
|
|
24
69
|
duration: Date.now() - startedAt,
|
|
25
|
-
data: {
|
|
70
|
+
data: {
|
|
71
|
+
count: items.length,
|
|
72
|
+
fitBv,
|
|
73
|
+
bindableCount: items.filter((item) => item.bindable).length,
|
|
74
|
+
},
|
|
26
75
|
});
|
|
27
|
-
return
|
|
76
|
+
return items;
|
|
28
77
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type GetLogsResult } from "../log/log";
|
|
2
|
+
import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
|
|
3
|
+
export interface GetFitLogsParams {
|
|
4
|
+
page?: number;
|
|
5
|
+
pageSize?: number;
|
|
6
|
+
}
|
|
7
|
+
export declare function getFitLogsForRuntime(rt: LockDeviceRuntime, params?: GetFitLogsParams): Promise<GetLogsResult>;
|