@ray-js/lock-sdk 1.2.0-beta.23 → 1.2.0-beta.25
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/log.d.ts +31 -0
- package/lib/api/log.js +22 -0
- package/lib/api/product.d.ts +8 -0
- package/lib/api/product.js +10 -0
- package/lib/api/temp.d.ts +21 -0
- package/lib/api/temp.js +24 -0
- package/lib/entries/fit/bootstrap/bootstrap-lock-instance.js +2 -0
- package/lib/entries/fit/bootstrap/bootstrap.js +1 -0
- package/lib/entries/fit/build-instance.js +2 -0
- package/lib/entries/fit/exports/binding.d.ts +4 -3
- package/lib/entries/fit/exports/device.d.ts +8 -7
- package/lib/entries/fit/exports/device.js +12 -12
- package/lib/entries/fit/exports/index.d.ts +3 -0
- package/lib/entries/fit/exports/index.js +3 -0
- package/lib/entries/fit/exports/log.d.ts +7 -0
- package/lib/entries/fit/exports/log.js +15 -0
- package/lib/entries/fit/exports/misc.d.ts +5 -0
- package/lib/entries/fit/exports/misc.js +9 -0
- package/lib/entries/fit/exports/setting.d.ts +4 -0
- package/lib/entries/fit/exports/setting.js +8 -0
- package/lib/entries/fit/exports/state.d.ts +4 -0
- package/lib/entries/fit/exports/state.js +12 -0
- package/lib/entries/fit/exports/temp.d.ts +24 -3
- package/lib/entries/fit/exports/temp.js +43 -2
- package/lib/entries/fit/index.js +2 -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/misc.d.ts +3 -1
- package/lib/entries/main/exports/misc.js +2 -2
- package/lib/feature/fit/bind-lock-to-fit.js +41 -1
- 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 +11 -2
- package/lib/feature/fit/list.js +44 -5
- package/lib/feature/fit/log.d.ts +7 -0
- package/lib/feature/fit/log.js +123 -0
- 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/product.d.ts +5 -0
- package/lib/feature/fit/product.js +11 -0
- package/lib/feature/fit/security-channel.d.ts +2 -0
- package/lib/feature/fit/security-channel.js +15 -0
- package/lib/feature/fit/sync.d.ts +4 -2
- package/lib/feature/fit/sync.js +56 -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/log/log.d.ts +5 -1
- package/lib/feature/log/log.js +6 -4
- package/lib/feature/misc/ble-control.js +1 -1
- package/lib/feature/misc/connect-device.d.ts +1 -1
- package/lib/feature/misc/connect-device.js +5 -5
- package/lib/feature/password/temporary/offline-create.d.ts +14 -0
- package/lib/feature/password/temporary/offline-create.js +77 -1
- package/lib/feature/state/clear.js +1 -0
- package/lib/feature/state/platform-routing.js +4 -0
- package/lib/feature/state/sync/remote-serect-key.js +7 -0
- package/lib/feature/utils/index.d.ts +1 -0
- package/lib/feature/utils/index.js +1 -0
- package/lib/interface.d.ts +12 -0
- package/lib/runtime/LockDeviceRuntime.js +3 -0
- package/lib/runtime/lock-config.d.ts +1 -0
- package/lib/runtime/lock-config.js +2 -1
- package/lib/runtime/runtime-state-types.d.ts +6 -0
- package/package.json +1 -1
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import { getFitPasswordListForRuntime } from "../../../feature/fit/password-list";
|
|
1
|
+
import { getFitPasswordListForRuntime, getFitOnlinePasswordListForRuntime, getFitOfflinePasswordListForRuntime, } from "../../../feature/fit/password-list";
|
|
2
2
|
import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
|
|
3
|
-
import { fitAddTempPwdForRuntime, fitRemoveTempPwdForRuntime, fitRenameTempPwdForRuntime, fitUpdateTempPwdForRuntime, } from "../../../feature/fit/temp-password";
|
|
3
|
+
import { fitAddTempPwdForRuntime, fitRemoveTempPwdForRuntime, fitRenameTempPwdForRuntime, fitRenameOfflineTempPwdForRuntime, fitRevokeOfflineTempPwdForRuntime, fitResendTempPwdForRuntime, fitUpdateTempPwdForRuntime, } from "../../../feature/fit/temp-password";
|
|
4
|
+
import { clearFitInvalidPwdForRuntime, getFitInvalidPwdListForRuntime, } from "../../../feature/fit/invalid-password";
|
|
5
|
+
import { createTempDynamicForRuntime, createFitOfflineOnceForRuntime, createFitOfflineLimitForRuntime, createFitOfflineClearAllForRuntime, getFitOfflineRevocableListForRuntime, getFitOfflinePwdAvailableForRuntime, } from "../../../feature/password/temporary/offline-create";
|
|
4
6
|
export function getFitPasswordList() {
|
|
5
7
|
return getFitPasswordListForRuntime(resolveRuntimeFromExportThis(this));
|
|
6
8
|
}
|
|
9
|
+
export function getFitOnlinePasswordList() {
|
|
10
|
+
return getFitOnlinePasswordListForRuntime(resolveRuntimeFromExportThis(this));
|
|
11
|
+
}
|
|
12
|
+
export function getFitOfflinePasswordList() {
|
|
13
|
+
return getFitOfflinePasswordListForRuntime(resolveRuntimeFromExportThis(this));
|
|
14
|
+
}
|
|
7
15
|
export function addFitTempPwd(params) {
|
|
8
16
|
return fitAddTempPwdForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
9
17
|
}
|
|
@@ -16,3 +24,36 @@ export function updateFitTempPwd(params) {
|
|
|
16
24
|
export function renameFitTempPwd(params) {
|
|
17
25
|
return fitRenameTempPwdForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
18
26
|
}
|
|
27
|
+
export function renameFitOfflineTempPwd(params) {
|
|
28
|
+
return fitRenameOfflineTempPwdForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
29
|
+
}
|
|
30
|
+
export function revokeFitOfflineTempPwd(params) {
|
|
31
|
+
return fitRevokeOfflineTempPwdForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
32
|
+
}
|
|
33
|
+
export function resendFitTempPwd(params) {
|
|
34
|
+
return fitResendTempPwdForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
35
|
+
}
|
|
36
|
+
export function getFitInvalidPwdList(params) {
|
|
37
|
+
return getFitInvalidPwdListForRuntime(resolveRuntimeFromExportThis(this), params ?? {});
|
|
38
|
+
}
|
|
39
|
+
export function clearFitInvalidPwd(params) {
|
|
40
|
+
return clearFitInvalidPwdForRuntime(resolveRuntimeFromExportThis(this), params ?? {});
|
|
41
|
+
}
|
|
42
|
+
export function getFitDynamicPassword() {
|
|
43
|
+
return createTempDynamicForRuntime(resolveRuntimeFromExportThis(this));
|
|
44
|
+
}
|
|
45
|
+
export function getFitOfflineOncePassword() {
|
|
46
|
+
return createFitOfflineOnceForRuntime(resolveRuntimeFromExportThis(this));
|
|
47
|
+
}
|
|
48
|
+
export function getFitOfflineLimitPassword(params) {
|
|
49
|
+
return createFitOfflineLimitForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
50
|
+
}
|
|
51
|
+
export function getFitOfflineClearAllCode() {
|
|
52
|
+
return createFitOfflineClearAllForRuntime(resolveRuntimeFromExportThis(this));
|
|
53
|
+
}
|
|
54
|
+
export function getFitOfflineRevocableList() {
|
|
55
|
+
return getFitOfflineRevocableListForRuntime(resolveRuntimeFromExportThis(this));
|
|
56
|
+
}
|
|
57
|
+
export function getFitOfflinePwdAvailable(pwdType) {
|
|
58
|
+
return getFitOfflinePwdAvailableForRuntime(resolveRuntimeFromExportThis(this), pwdType);
|
|
59
|
+
}
|
package/lib/entries/fit/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { clearPrimaryFitSDKInstance, setPrimaryFitSDKInstance, } from "./bootstr
|
|
|
5
5
|
import { clearAllRuntimes, listRegisteredRuntimes, } from "../../runtime/registry";
|
|
6
6
|
import { getLaunchOptionsSync } from "../../platform/device";
|
|
7
7
|
import { getError } from "../../utils/errors";
|
|
8
|
+
import { stopFitSyncReportForRuntime } from "../../feature/fit/sync";
|
|
8
9
|
export * from "./exports";
|
|
9
10
|
export const createFitSDK = async (options) => {
|
|
10
11
|
const { instance } = await bootstrapRegisteredFitInstance({
|
|
@@ -29,6 +30,7 @@ export const initFit = async (options) => {
|
|
|
29
30
|
export const destroyFit = () => {
|
|
30
31
|
removeEvents();
|
|
31
32
|
for (const rt of listRegisteredRuntimes()) {
|
|
33
|
+
stopFitSyncReportForRuntime(rt);
|
|
32
34
|
clearStateForRuntime(rt);
|
|
33
35
|
}
|
|
34
36
|
clearAllRuntimes();
|
|
@@ -8,3 +8,5 @@ export declare function getLogs(params?: GetLogsParams): Promise<import("../../.
|
|
|
8
8
|
export declare function getAlarms(params?: GetAlarmsParams): Promise<import("../../../feature/log/log").GetAlarmsResult>;
|
|
9
9
|
export declare function getAlbums(params?: GetAlbumsParams): Promise<import("../../../feature/log/log").GetAlbumsResult>;
|
|
10
10
|
export declare function getLockLogList(params: GetLockLogListParams): Promise<import("../../../feature/log/log").GetLockLogListResult>;
|
|
11
|
+
export declare function getAlarmUnreadCount(): Promise<number>;
|
|
12
|
+
export declare function getActivePeriod(): Promise<number>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
|
|
2
|
-
import { getLatestLogsForRuntime, getLogsForRuntime, getAlarmsForRuntime, getAlbumsForRuntime, onLogsRefreshForRuntime, offLogsRefreshForRuntime, getLockLogListForRuntime, } from "../../../feature/log/log";
|
|
2
|
+
import { getLatestLogsForRuntime, getLogsForRuntime, getAlarmsForRuntime, getAlbumsForRuntime, onLogsRefreshForRuntime, offLogsRefreshForRuntime, getLockLogListForRuntime, getAlarmUnreadCountForRuntime, getActivePeriodForRuntime, } from "../../../feature/log/log";
|
|
3
3
|
export function onLogsRefresh(cb) {
|
|
4
4
|
onLogsRefreshForRuntime(resolveRuntimeFromExportThis(this), cb);
|
|
5
5
|
}
|
|
@@ -22,3 +22,9 @@ export async function getAlbums(params) {
|
|
|
22
22
|
export async function getLockLogList(params) {
|
|
23
23
|
return getLockLogListForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
24
24
|
}
|
|
25
|
+
export async function getAlarmUnreadCount() {
|
|
26
|
+
return getAlarmUnreadCountForRuntime(resolveRuntimeFromExportThis(this));
|
|
27
|
+
}
|
|
28
|
+
export async function getActivePeriod() {
|
|
29
|
+
return getActivePeriodForRuntime(resolveRuntimeFromExportThis(this));
|
|
30
|
+
}
|
|
@@ -13,6 +13,8 @@ export interface UpdateDpPeriodTimeOption {
|
|
|
13
13
|
offlineDp?: boolean;
|
|
14
14
|
}
|
|
15
15
|
export declare function updateDpPeriodTime(dpCode: string, data: UpdateDpPeriodTimeParams, option?: UpdateDpPeriodTimeOption): Promise<void>;
|
|
16
|
-
export declare function connectDevice(
|
|
16
|
+
export declare function connectDevice(options?: {
|
|
17
|
+
timeout?: number;
|
|
18
|
+
}): Promise<true>;
|
|
17
19
|
export declare function gotoService(params?: GotoServiceParams): Promise<void>;
|
|
18
20
|
export declare function validatePwdComplexity(password: string): Promise<boolean>;
|
|
@@ -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);
|
|
@@ -1,9 +1,48 @@
|
|
|
1
1
|
import { bindLockAndFit, unbindFitFromLockCloud, unbindLockFromFitCloud, } from "../../api/fit";
|
|
2
2
|
import { getUsersSyncLockData } from "../../api/user";
|
|
3
|
-
import { offDpDataChange, onDpDataChange, publishDeviceDps, } from "../../platform/device";
|
|
3
|
+
import { getDeviceProperties, offDpDataChange, onDpDataChange, publishDeviceDps, setDeviceProperty, } from "../../platform/device";
|
|
4
4
|
import { getError } from "../../utils/errors";
|
|
5
5
|
import { sdkLog } from "../../utils/sdk-log";
|
|
6
|
+
import { isFitSecurityChannelEnabledForRuntime } from "./security-channel";
|
|
6
7
|
import { FIT_BIND_TIMEOUT_MS, FIT_OPERATION_CODE, normalizeHex, buildLockCheckCodeTemplate, publishFitTransparentFlow, } from "./shared";
|
|
8
|
+
const markSecurityUpdated = async (runtime, lock) => {
|
|
9
|
+
if (!lock.isSupportScy || !isFitSecurityChannelEnabledForRuntime(runtime)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const fittingId = runtime.devId;
|
|
13
|
+
try {
|
|
14
|
+
const props = await getDeviceProperties(fittingId);
|
|
15
|
+
const raw = props?.["SECURITY_UPDATED"];
|
|
16
|
+
let list = [];
|
|
17
|
+
if (typeof raw === "string") {
|
|
18
|
+
try {
|
|
19
|
+
list = JSON.parse(raw).value || [];
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
list = [];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
else if (raw && typeof raw === "object") {
|
|
26
|
+
list =
|
|
27
|
+
raw.value ||
|
|
28
|
+
(Array.isArray(raw) ? raw : []);
|
|
29
|
+
}
|
|
30
|
+
if (list.includes(lock.devId)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
await setDeviceProperty(fittingId, "SECURITY_UPDATED", {
|
|
34
|
+
key: fittingId,
|
|
35
|
+
value: [...list, lock.devId],
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
sdkLog("warn", "fit", "markSecurityUpdatedError", {
|
|
40
|
+
devId: fittingId,
|
|
41
|
+
data: { lockDevId: lock.devId },
|
|
42
|
+
error: e,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
};
|
|
7
46
|
const CHECK_CODE_SET_DP_ID = "70";
|
|
8
47
|
const delay = (ms) => new Promise((resolve) => {
|
|
9
48
|
setTimeout(resolve, ms);
|
|
@@ -104,6 +143,7 @@ export async function bindLockToFitForRuntime(runtime, lock) {
|
|
|
104
143
|
devId: runtime.devId,
|
|
105
144
|
data: { lockDevId: lock.devId },
|
|
106
145
|
});
|
|
146
|
+
await markSecurityUpdated(runtime, lock);
|
|
107
147
|
await publishToLock(runtime, "bind", lock);
|
|
108
148
|
const result = await bindLockAndFit({
|
|
109
149
|
devId: lock.devId,
|
|
@@ -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,12 @@
|
|
|
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
|
+
}
|
|
11
|
+
export declare function getBoundLockListForRuntime(runtime: LockDeviceRuntime): Promise<BoundLockListItem[]>;
|
|
12
|
+
export declare function getUnbindLockListForRuntime(runtime: LockDeviceRuntime): Promise<UnbindLockListItem[]>;
|
package/lib/feature/fit/list.js
CHANGED
|
@@ -1,28 +1,67 @@
|
|
|
1
1
|
import { getBoundLockListApi, getUnbindLockListApi, } from "../../api/fit";
|
|
2
2
|
import { sdkLog } from "../../utils/sdk-log";
|
|
3
|
+
import { getFitDeviceBvForRuntime } from "./device-bv";
|
|
4
|
+
import { 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 items = (Array.isArray(list) ? list : []).map((lock) => ({
|
|
23
|
+
...lock,
|
|
24
|
+
securityVersionMismatch: isSecurityVersionMismatch(runtime, lock),
|
|
25
|
+
}));
|
|
9
26
|
sdkLog("info", "fit", "getBoundLockListSuccess", {
|
|
10
27
|
devId: runtime.devId,
|
|
11
28
|
duration: Date.now() - startedAt,
|
|
12
|
-
data: {
|
|
29
|
+
data: {
|
|
30
|
+
count: items.length,
|
|
31
|
+
securityMismatchCount: items.filter((item) => item.securityVersionMismatch).length,
|
|
32
|
+
},
|
|
13
33
|
});
|
|
14
|
-
return
|
|
34
|
+
return items;
|
|
15
35
|
}
|
|
16
36
|
export async function getUnbindLockListForRuntime(runtime) {
|
|
17
37
|
const startedAt = Date.now();
|
|
18
38
|
sdkLog("info", "fit", "getUnbindLockListStart", {
|
|
19
39
|
devId: runtime.devId,
|
|
20
40
|
});
|
|
21
|
-
const list = await
|
|
41
|
+
const [list, fitBv] = await Promise.all([
|
|
42
|
+
getUnbindLockListApi(runtime.devId),
|
|
43
|
+
getFitDeviceBvForRuntime(runtime).catch((error) => {
|
|
44
|
+
sdkLog("warn", "fit", "getUnbindLockListBvFailed", {
|
|
45
|
+
devId: runtime.devId,
|
|
46
|
+
error,
|
|
47
|
+
});
|
|
48
|
+
return 0;
|
|
49
|
+
}),
|
|
50
|
+
]);
|
|
51
|
+
const items = (Array.isArray(list) ? list : []).map((lock) => {
|
|
52
|
+
const unbindableReason = resolveUnbindableReason(runtime, lock, fitBv);
|
|
53
|
+
return unbindableReason
|
|
54
|
+
? { ...lock, bindable: false, unbindableReason }
|
|
55
|
+
: { ...lock, bindable: true };
|
|
56
|
+
});
|
|
22
57
|
sdkLog("info", "fit", "getUnbindLockListSuccess", {
|
|
23
58
|
devId: runtime.devId,
|
|
24
59
|
duration: Date.now() - startedAt,
|
|
25
|
-
data: {
|
|
60
|
+
data: {
|
|
61
|
+
count: items.length,
|
|
62
|
+
fitBv,
|
|
63
|
+
bindableCount: items.filter((item) => item.bindable).length,
|
|
64
|
+
},
|
|
26
65
|
});
|
|
27
|
-
return
|
|
66
|
+
return items;
|
|
28
67
|
}
|
|
@@ -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>;
|