@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.
Files changed (73) hide show
  1. package/lib/api/fit.d.ts +55 -2
  2. package/lib/api/fit.js +43 -1
  3. package/lib/api/log.d.ts +31 -0
  4. package/lib/api/log.js +22 -0
  5. package/lib/api/product.d.ts +8 -0
  6. package/lib/api/product.js +10 -0
  7. package/lib/api/temp.d.ts +21 -0
  8. package/lib/api/temp.js +24 -0
  9. package/lib/entries/fit/bootstrap/bootstrap-lock-instance.js +2 -0
  10. package/lib/entries/fit/bootstrap/bootstrap.js +1 -0
  11. package/lib/entries/fit/build-instance.js +2 -0
  12. package/lib/entries/fit/exports/binding.d.ts +4 -3
  13. package/lib/entries/fit/exports/device.d.ts +8 -7
  14. package/lib/entries/fit/exports/device.js +12 -12
  15. package/lib/entries/fit/exports/index.d.ts +3 -0
  16. package/lib/entries/fit/exports/index.js +3 -0
  17. package/lib/entries/fit/exports/log.d.ts +7 -0
  18. package/lib/entries/fit/exports/log.js +15 -0
  19. package/lib/entries/fit/exports/misc.d.ts +5 -0
  20. package/lib/entries/fit/exports/misc.js +9 -0
  21. package/lib/entries/fit/exports/setting.d.ts +4 -0
  22. package/lib/entries/fit/exports/setting.js +8 -0
  23. package/lib/entries/fit/exports/state.d.ts +4 -0
  24. package/lib/entries/fit/exports/state.js +12 -0
  25. package/lib/entries/fit/exports/temp.d.ts +24 -3
  26. package/lib/entries/fit/exports/temp.js +43 -2
  27. package/lib/entries/fit/index.js +2 -0
  28. package/lib/entries/main/exports/log.d.ts +2 -0
  29. package/lib/entries/main/exports/log.js +7 -1
  30. package/lib/entries/main/exports/misc.d.ts +3 -1
  31. package/lib/entries/main/exports/misc.js +2 -2
  32. package/lib/feature/fit/bind-lock-to-fit.js +41 -1
  33. package/lib/feature/fit/ble-key.d.ts +10 -4
  34. package/lib/feature/fit/ble-key.js +145 -4
  35. package/lib/feature/fit/device-bv.d.ts +2 -0
  36. package/lib/feature/fit/device-bv.js +15 -0
  37. package/lib/feature/fit/invalid-password.d.ts +10 -0
  38. package/lib/feature/fit/invalid-password.js +43 -0
  39. package/lib/feature/fit/list.d.ts +11 -2
  40. package/lib/feature/fit/list.js +44 -5
  41. package/lib/feature/fit/log.d.ts +7 -0
  42. package/lib/feature/fit/log.js +123 -0
  43. package/lib/feature/fit/method/update-remove.js +40 -14
  44. package/lib/feature/fit/password-list.d.ts +37 -0
  45. package/lib/feature/fit/password-list.js +44 -1
  46. package/lib/feature/fit/product.d.ts +5 -0
  47. package/lib/feature/fit/product.js +11 -0
  48. package/lib/feature/fit/security-channel.d.ts +2 -0
  49. package/lib/feature/fit/security-channel.js +15 -0
  50. package/lib/feature/fit/sync.d.ts +4 -2
  51. package/lib/feature/fit/sync.js +56 -22
  52. package/lib/feature/fit/temp-password.d.ts +23 -0
  53. package/lib/feature/fit/temp-password.js +95 -3
  54. package/lib/feature/fit/users.d.ts +1 -0
  55. package/lib/feature/fit/users.js +1 -0
  56. package/lib/feature/log/log.d.ts +5 -1
  57. package/lib/feature/log/log.js +6 -4
  58. package/lib/feature/misc/ble-control.js +1 -1
  59. package/lib/feature/misc/connect-device.d.ts +1 -1
  60. package/lib/feature/misc/connect-device.js +5 -5
  61. package/lib/feature/password/temporary/offline-create.d.ts +14 -0
  62. package/lib/feature/password/temporary/offline-create.js +77 -1
  63. package/lib/feature/state/clear.js +1 -0
  64. package/lib/feature/state/platform-routing.js +4 -0
  65. package/lib/feature/state/sync/remote-serect-key.js +7 -0
  66. package/lib/feature/utils/index.d.ts +1 -0
  67. package/lib/feature/utils/index.js +1 -0
  68. package/lib/interface.d.ts +12 -0
  69. package/lib/runtime/LockDeviceRuntime.js +3 -0
  70. package/lib/runtime/lock-config.d.ts +1 -0
  71. package/lib/runtime/lock-config.js +2 -1
  72. package/lib/runtime/runtime-state-types.d.ts +6 -0
  73. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ import { getFitRecordListApi } from "../../api/log";
2
+ import { closeTypes, dpIdsForUsernameToUnlockName, unlockDp2Type, } from "../log/log";
3
+ import dpCodes from "../../config/dp-code";
4
+ import base64ToHex from "../../utils/base64-to-hex";
5
+ import { handleLocalOperation } from "../../utils/log";
6
+ import { getCurrentUserForRuntime } from "../user/current-user";
7
+ const fitRecordDps = [
8
+ dpCodes.bluetoothUnlockKit,
9
+ dpCodes.unlockPasswordKit,
10
+ dpCodes.unlockCardKit,
11
+ dpCodes.unlockFingerprintKit,
12
+ dpCodes.unlockFaceKit,
13
+ dpCodes.unlockEyeKit,
14
+ dpCodes.unlockHandKit,
15
+ dpCodes.unlockFingerVeinKit,
16
+ dpCodes.unlockTemporaryKit,
17
+ dpCodes.unlockDoubleKit,
18
+ dpCodes.unlockOfflinePd,
19
+ dpCodes.unlockDynamic,
20
+ dpCodes.lockRecord,
21
+ ];
22
+ function parseFitRecord(cfg, raw, currentUserId) {
23
+ const historyId = raw.historyId ?? raw.id;
24
+ const time = raw.gmtCreate ?? Number(raw.time);
25
+ const dpId = typeof raw.dpId === "string" ? Number(raw.dpId) : raw.dpId;
26
+ let closeValue = undefined;
27
+ let dpValue = raw.dpValue;
28
+ const dpCode = cfg.codesById[dpId];
29
+ let type = dpCode === dpCodes.lockRecord ? "close_record" : "unlock_record";
30
+ const dpSchema = cfg.dpSchema[dpCode];
31
+ if (dpSchema?.type === "raw" && typeof dpValue === "string") {
32
+ try {
33
+ dpValue = base64ToHex(dpValue);
34
+ }
35
+ catch {
36
+ }
37
+ }
38
+ if (type === "close_record") {
39
+ const rawCloseValue = typeof dpValue === "string" ? dpValue : "";
40
+ const closeType = parseInt(rawCloseValue.slice(0, 2), 16);
41
+ closeValue = closeTypes[closeType] || closeTypes[0];
42
+ }
43
+ if (dpCode === dpCodes.lockLocalRecord) {
44
+ type = "local_operation";
45
+ }
46
+ let userName = raw.userName;
47
+ let unlockName = raw.unlockName;
48
+ if (dpIdsForUsernameToUnlockName.includes(dpId)) {
49
+ unlockName = raw.userName;
50
+ userName = "";
51
+ }
52
+ const log = {
53
+ type,
54
+ logId: String(historyId),
55
+ userId: raw.userId,
56
+ dpId,
57
+ data: dpValue,
58
+ dpCode,
59
+ userName: userName || "",
60
+ unlockName: unlockName || "",
61
+ avatarUrl: raw.avatarUrl,
62
+ relateDevName: raw.relateDevName,
63
+ mediaInfo: raw.mediaInfoList?.map?.((item) => {
64
+ return {
65
+ mediaPath: item.mediaPath,
66
+ fileKey: item.fileKey,
67
+ fileUrl: item.fileUrl,
68
+ mediaBucket: item.mediaBucket,
69
+ mediaKey: item.mediaKey,
70
+ width: item.positionWidth,
71
+ height: item.positionHeight,
72
+ angle: item.positionAngle,
73
+ isVR: !!item.positionVr,
74
+ position: item.position,
75
+ };
76
+ }),
77
+ unionUnlockInfo: raw.unionUnlockInfo?.map((item) => ({
78
+ userId: item.userId,
79
+ userName: item.userName,
80
+ unlockName: item.unlockName,
81
+ sn: item.sn,
82
+ type: unlockDp2Type[item.opMode],
83
+ })),
84
+ closeValue,
85
+ time,
86
+ currentUser: +raw.userId === +currentUserId,
87
+ bindable: raw.memberBindableFlag === 1,
88
+ unlockMethod: type === "unlock_record" ? unlockDp2Type[dpCode] : undefined,
89
+ localRecord: handleLocalOperation(raw.localOperateRecordInfo, dpValue),
90
+ };
91
+ if (raw.matterRecordInfo) {
92
+ log.matterRecord = {
93
+ sn: raw.matterRecordInfo.matterSn,
94
+ type: raw.matterRecordInfo.matterType,
95
+ source: raw.matterRecordInfo.matterSource,
96
+ };
97
+ }
98
+ return log;
99
+ }
100
+ export async function getFitLogsForRuntime(rt, params) {
101
+ const cfg = rt.config;
102
+ const { page = 1, pageSize = 50 } = params || {};
103
+ const currentUser = await getCurrentUserForRuntime(rt);
104
+ const data = await getFitRecordListApi({
105
+ devId: cfg.devInfo.devId,
106
+ dpIds: fitRecordDps.reduce((res, item) => {
107
+ if (cfg.idsByCode[item]) {
108
+ res.push(cfg.idsByCode[item]);
109
+ }
110
+ return res;
111
+ }, []),
112
+ offset: (page - 1) * pageSize,
113
+ limit: pageSize,
114
+ });
115
+ if (!data?.datas?.length) {
116
+ return { list: [], hasMore: false, total: 0 };
117
+ }
118
+ return {
119
+ list: data.datas.map((raw) => parseFitRecord(cfg, raw, currentUser.userId)),
120
+ hasMore: data.hasNext,
121
+ total: data.totalCount,
122
+ };
123
+ }
@@ -1,14 +1,40 @@
1
1
  import dpUtils from "@ray-js/tuya-dp-transform";
2
- import { removeFitOpenMode, updateFitOpenMode } from "../../../api/fit";
2
+ import { getFitOpenModeList, removeFitOpenMode, updateFitOpenMode, } from "../../../api/fit";
3
3
  import dpCodes from "../../../config/dp-code";
4
4
  import { fitRemove, fitReportRemove, } from "../../../config/dp-map/unlock-method-fit";
5
5
  import { isAdmin } from "../../../utils";
6
6
  import { getError, handleCloudError } from "../../../utils/errors";
7
7
  import { publishDpsForRuntime } from "../../dp/publish-dps";
8
- import { getUnlockMethodTypeByDpCodeForRuntime, parallelOnlyForRuntime, } from "../../utils";
9
- import { getUnlockMethodDetailForRuntime } from "../../unlock/method/detail";
10
- import { resolveSlaveId } from "../resolve-slave-id";
8
+ import { getUnlockMethodTypeByTypeForRuntime, parallelOnlyForRuntime, } from "../../utils";
11
9
  import { sdkLog } from "../../../utils/sdk-log";
10
+ const FIT_DELETABLE_UNLOCK_METHOD_TYPES = [
11
+ "card",
12
+ "finger",
13
+ "face",
14
+ "hand",
15
+ "fingerVein",
16
+ ];
17
+ async function findFitOpenModeRawById(rt, id) {
18
+ for (const type of FIT_DELETABLE_UNLOCK_METHOD_TYPES) {
19
+ let unlockMethodConfig;
20
+ try {
21
+ unlockMethodConfig = getUnlockMethodTypeByTypeForRuntime(rt, type);
22
+ }
23
+ catch {
24
+ continue;
25
+ }
26
+ const dpId = rt.config.idsByCode[unlockMethodConfig.code];
27
+ if (!dpId) {
28
+ continue;
29
+ }
30
+ const raw = await getFitOpenModeList(rt.devId, dpId);
31
+ const hit = (raw ?? []).find((item) => item.unlockBindingId === id);
32
+ if (hit) {
33
+ return { raw: hit, unlockMethodConfig };
34
+ }
35
+ }
36
+ return null;
37
+ }
12
38
  export async function fitUpdateUnlockMethodForRuntime(rt, params) {
13
39
  const startedAt = Date.now();
14
40
  sdkLog("info", "fitUnlockMethod", "updateStart", {
@@ -49,19 +75,20 @@ export const fitDeleteUnlockMethodForRuntime = parallelOnlyForRuntime(async func
49
75
  devId: rt.devId,
50
76
  data: { id, hasLockDevId: typeof lockDevId === "string" },
51
77
  });
52
- const detail = await getUnlockMethodDetailForRuntime(rt, id);
53
- const { lockUserId, unlockId, userType, dpId } = detail;
54
- const code = cfg.codesById[dpId];
55
- if (!code) {
56
- const error = getError(1014);
57
- sdkLog("warn", "fitUnlockMethod", "deleteMissingDpCode", {
78
+ const found = await findFitOpenModeRawById(rt, id);
79
+ if (!found) {
80
+ const error = getError(1040);
81
+ sdkLog("warn", "fitUnlockMethod", "deleteRecordNotFound", {
58
82
  devId: rt.devId,
59
- data: { id, dpId },
83
+ data: { id },
60
84
  error,
61
85
  });
62
86
  throw error;
63
87
  }
64
- const unlockMethodConfig = getUnlockMethodTypeByDpCodeForRuntime(rt, code);
88
+ const { raw, unlockMethodConfig } = found;
89
+ const lockUserId = raw.lockUserId;
90
+ const unlockId = raw.sn;
91
+ const slaveId = parseInt(raw.devUnlockId, 16);
65
92
  const removeDpCode = dpCodes.unlockMethodDel;
66
93
  if (!cfg.dpSchema[removeDpCode]) {
67
94
  const error = getError(1014);
@@ -72,12 +99,11 @@ export const fitDeleteUnlockMethodForRuntime = parallelOnlyForRuntime(async func
72
99
  });
73
100
  throw error;
74
101
  }
75
- const slaveId = await resolveSlaveId(rt, lockDevId);
76
102
  const dpData = {
77
103
  slaveId,
78
104
  type: unlockMethodConfig.id,
79
105
  stage: 0,
80
- admin: isAdmin(userType),
106
+ admin: isAdmin(raw.userType),
81
107
  memberId: lockUserId,
82
108
  unlockId,
83
109
  operation: 1,
@@ -1,3 +1,4 @@
1
+ import { type RawFitOpenModeScheduleItem } from "../../api/fit";
1
2
  import { EffectiveConfig, UnlockMethodType } from "../../interface";
2
3
  import { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
3
4
  export interface FitPasswordItem {
@@ -22,3 +23,39 @@ export declare const getFitPasswordListForRuntime: (runtime: LockDeviceRuntime)
22
23
  devLockId: string;
23
24
  effective: EffectiveConfig;
24
25
  }[]>;
26
+ export interface FitOnlinePasswordItem {
27
+ id: number;
28
+ pwdId: number;
29
+ sn: number;
30
+ gmtCreate: number;
31
+ opModeType: number;
32
+ opModeSubType: number;
33
+ name: string;
34
+ userName: string;
35
+ mobile: string;
36
+ hijack: boolean;
37
+ operate: number;
38
+ effectiveTime: number;
39
+ invalidTime: number;
40
+ devNameList: string[];
41
+ scheduleDetails: RawFitOpenModeScheduleItem[];
42
+ }
43
+ export interface FitOfflinePasswordItem {
44
+ id: number | string;
45
+ pwdId: number;
46
+ sn: number;
47
+ gmtCreate: number;
48
+ opModeType: number;
49
+ opModeSubType: number;
50
+ pwdName: string;
51
+ mayExpired: boolean;
52
+ gmtStart: number;
53
+ gmtExpired: number;
54
+ devNameList: string[];
55
+ scheduleDetails: RawFitOpenModeScheduleItem[];
56
+ revokedPwdName: string;
57
+ revokedPwdEffectiveTime: number;
58
+ revokedPwdInvalidTime: number;
59
+ }
60
+ export declare const getFitOnlinePasswordListForRuntime: (runtime: LockDeviceRuntime) => Promise<FitOnlinePasswordItem[]>;
61
+ export declare const getFitOfflinePasswordListForRuntime: (runtime: LockDeviceRuntime) => Promise<FitOfflinePasswordItem[]>;
@@ -1,4 +1,4 @@
1
- import { getFitPasswordList } from "../../api/fit";
1
+ import { getFitPasswordList, getFitOfflinePasswordList, } from "../../api/fit";
2
2
  import { parseWeek } from "../../utils";
3
3
  export const getFitPasswordListForRuntime = async (runtime) => {
4
4
  const list = await getFitPasswordList(runtime.devId);
@@ -29,3 +29,46 @@ export const getFitPasswordListForRuntime = async (runtime) => {
29
29
  };
30
30
  });
31
31
  };
32
+ export const getFitOnlinePasswordListForRuntime = async (runtime) => {
33
+ const list = await getFitPasswordList(runtime.devId);
34
+ return (list ?? []).map((item) => ({
35
+ id: item.unlockBindingId,
36
+ pwdId: item.pwdId,
37
+ sn: item.sn,
38
+ gmtCreate: item.gmtCreate,
39
+ opModeType: item.opModeType,
40
+ opModeSubType: item.opModeSubType,
41
+ name: item.name,
42
+ userName: item.userName,
43
+ mobile: item.mobile,
44
+ hijack: item.hijack,
45
+ operate: item.operate,
46
+ effectiveTime: item.effectiveTime,
47
+ invalidTime: item.invalidTime,
48
+ devNameList: item.devNameList ?? [],
49
+ scheduleDetails: item.scheduleDetails ?? [],
50
+ }));
51
+ };
52
+ export const getFitOfflinePasswordListForRuntime = async (runtime) => {
53
+ const res = await getFitOfflinePasswordList(runtime.devId);
54
+ const list = Array.isArray(res)
55
+ ? res
56
+ : (res?.datas ?? []);
57
+ return list.map((item) => ({
58
+ id: item.unlockBindingId ?? item.pwdId,
59
+ pwdId: item.pwdId,
60
+ sn: item.sn,
61
+ gmtCreate: item.gmtCreate,
62
+ opModeType: item.opModeType ?? 3,
63
+ opModeSubType: item.opModeSubType,
64
+ pwdName: item.pwdName,
65
+ mayExpired: item.mayExpired,
66
+ gmtStart: item.gmtStart,
67
+ gmtExpired: item.gmtExpired,
68
+ devNameList: item.devNameList ?? [],
69
+ scheduleDetails: item.scheduleDetails ?? [],
70
+ revokedPwdName: item.revokedPwdName,
71
+ revokedPwdEffectiveTime: item.revokedPwdEffectiveTime,
72
+ revokedPwdInvalidTime: item.revokedPwdInvalidTime,
73
+ }));
74
+ };
@@ -0,0 +1,5 @@
1
+ import { type ProductSpecResult } from "../../api/product";
2
+ import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
3
+ export declare const getProductSpecForRuntime: (runtime: LockDeviceRuntime, configItem: string) => Promise<ProductSpecResult>;
4
+ export declare const getProductInstVideoForRuntime: (runtime: LockDeviceRuntime) => Promise<ProductSpecResult>;
5
+ export declare const getProductEBookForRuntime: (runtime: LockDeviceRuntime) => Promise<ProductSpecResult>;
@@ -0,0 +1,11 @@
1
+ import { configCheck, } from "../../api/product";
2
+ export const getProductSpecForRuntime = (runtime, configItem) => {
3
+ const { devId, productId } = runtime.config.devInfo;
4
+ return configCheck(devId, productId, configItem);
5
+ };
6
+ export const getProductInstVideoForRuntime = (runtime) => {
7
+ return getProductSpecForRuntime(runtime, "product_inst_video");
8
+ };
9
+ export const getProductEBookForRuntime = (runtime) => {
10
+ return getProductSpecForRuntime(runtime, "product_manual");
11
+ };
@@ -0,0 +1,2 @@
1
+ import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
+ export declare const isFitSecurityChannelEnabledForRuntime: (rt: LockDeviceRuntime) => boolean;
@@ -0,0 +1,15 @@
1
+ export const isFitSecurityChannelEnabledForRuntime = (rt) => {
2
+ const raw = rt.config.devInfo?.meta?.["btScyChannel"];
3
+ if (!raw) {
4
+ return false;
5
+ }
6
+ try {
7
+ const parsed = typeof raw === "string"
8
+ ? JSON.parse(raw)
9
+ : raw;
10
+ return parsed?.enable === 1;
11
+ }
12
+ catch {
13
+ return false;
14
+ }
15
+ };
@@ -1,4 +1,6 @@
1
1
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
+ import { type SyncOpenModeRiseResult } from "../../api/fit";
2
3
  export declare function syncFitBindingsForRuntime(runtime: LockDeviceRuntime): Promise<void>;
3
- export declare function syncFitReportForRuntime(runtime: LockDeviceRuntime, ins: string): Promise<unknown>;
4
- export declare function syncOpenModeRiseForRuntime(runtime: LockDeviceRuntime, dpIds: string): Promise<unknown>;
4
+ export declare function startFitSyncReportForRuntime(runtime: LockDeviceRuntime): void;
5
+ export declare function stopFitSyncReportForRuntime(runtime: LockDeviceRuntime): void;
6
+ export declare function syncOpenModeRiseForRuntime(runtime: LockDeviceRuntime, dpCodes?: string[]): Promise<SyncOpenModeRiseResult>;
@@ -1,5 +1,6 @@
1
1
  import { syncFitToLockRise, syncFitReport as syncFitReportApi, syncOpenModeRise as syncOpenModeRiseApi, } from "../../api/fit";
2
- import { publishBLETransparentData, subscribeBLETransparentDataReport, } from "../../platform/device";
2
+ import { unlockMethodDpCodes } from "../utils";
3
+ import { offBLETransparentDataReport, onBLETransparentDataReport, publishBLETransparentData, subscribeBLETransparentDataReport, } from "../../platform/device";
3
4
  import { sdkLog } from "../../utils/sdk-log";
4
5
  export async function syncFitBindingsForRuntime(runtime) {
5
6
  const startedAt = Date.now();
@@ -7,6 +8,14 @@ export async function syncFitBindingsForRuntime(runtime) {
7
8
  sdkLog("info", "fit", "syncBindingsStart", {
8
9
  devId: runtime.devId,
9
10
  });
11
+ if (runtime.sync.fitBindingsSyncStarted) {
12
+ sdkLog("info", "fit", "syncBindingsSkip", {
13
+ devId: runtime.devId,
14
+ data: { reason: "already_started" },
15
+ });
16
+ return;
17
+ }
18
+ runtime.sync.fitBindingsSyncStarted = true;
10
19
  try {
11
20
  const result = await syncFitToLockRise(fittingId);
12
21
  const instructions = Array.isArray(result.ins) ? result.ins : [];
@@ -29,6 +38,7 @@ export async function syncFitBindingsForRuntime(runtime) {
29
38
  });
30
39
  }
31
40
  catch (error) {
41
+ runtime.sync.fitBindingsSyncStarted = false;
32
42
  sdkLog("error", "fit", "syncBindingsFail", {
33
43
  devId: runtime.devId,
34
44
  duration: Date.now() - startedAt,
@@ -37,35 +47,59 @@ export async function syncFitBindingsForRuntime(runtime) {
37
47
  throw error;
38
48
  }
39
49
  }
40
- export async function syncFitReportForRuntime(runtime, ins) {
41
- const startedAt = Date.now();
42
- sdkLog("info", "fit", "syncReportStart", {
43
- devId: runtime.devId,
44
- data: { hasInstruction: !!ins },
45
- });
46
- try {
47
- const result = await syncFitReportApi(runtime.devId, ins);
48
- sdkLog("info", "fit", "syncReportSuccess", {
49
- devId: runtime.devId,
50
- duration: Date.now() - startedAt,
51
- });
52
- return result;
50
+ export function startFitSyncReportForRuntime(runtime) {
51
+ if (runtime.sync.fitSyncReportHandler) {
52
+ return;
53
53
  }
54
- catch (error) {
55
- sdkLog("error", "fit", "syncReportFail", {
56
- devId: runtime.devId,
57
- duration: Date.now() - startedAt,
58
- error,
54
+ const devId = runtime.devId;
55
+ subscribeBLETransparentDataReport(devId);
56
+ const handler = (params) => {
57
+ if (params?.deviceId !== devId || !params?.data) {
58
+ return;
59
+ }
60
+ syncFitReportApi(devId, params.data).catch((e) => {
61
+ sdkLog("warn", "fit", "syncReportAutoError", {
62
+ devId,
63
+ error: e,
64
+ });
59
65
  });
60
- throw error;
66
+ };
67
+ runtime.sync.fitSyncReportHandler = handler;
68
+ onBLETransparentDataReport(handler);
69
+ sdkLog("info", "fit", "startSyncReport", { devId });
70
+ }
71
+ export function stopFitSyncReportForRuntime(runtime) {
72
+ const handler = runtime.sync.fitSyncReportHandler;
73
+ if (handler) {
74
+ offBLETransparentDataReport(handler);
75
+ runtime.sync.fitSyncReportHandler = null;
61
76
  }
77
+ runtime.sync.fitBindingsSyncStarted = false;
78
+ sdkLog("info", "fit", "stopSyncReport", { devId: runtime.devId });
62
79
  }
63
- export async function syncOpenModeRiseForRuntime(runtime, dpIds) {
80
+ export async function syncOpenModeRiseForRuntime(runtime, dpCodes) {
64
81
  const startedAt = Date.now();
82
+ const codes = dpCodes?.length ? dpCodes : unlockMethodDpCodes;
83
+ const dpIds = [
84
+ ...new Set(codes.reduce((res, code) => {
85
+ const id = runtime.config.idsByCode[code];
86
+ if (id) {
87
+ res.push(String(id));
88
+ }
89
+ return res;
90
+ }, [])),
91
+ ];
65
92
  sdkLog("info", "fit", "syncOpenModeRiseStart", {
66
93
  devId: runtime.devId,
67
- data: { hasDpIds: !!dpIds },
94
+ data: { isAll: !dpCodes?.length, dpIdCount: dpIds.length },
68
95
  });
96
+ if (!dpIds.length) {
97
+ sdkLog("info", "fit", "syncOpenModeRiseSkip", {
98
+ devId: runtime.devId,
99
+ data: { reason: "no_matched_dp" },
100
+ });
101
+ return { ins: "", distributed: false };
102
+ }
69
103
  try {
70
104
  const result = await syncOpenModeRiseApi(runtime.devId, dpIds);
71
105
  sdkLog("info", "fit", "syncOpenModeRiseSuccess", {
@@ -25,3 +25,26 @@ export interface RenameFitTempPwdParams {
25
25
  name: string;
26
26
  }
27
27
  export declare const fitRenameTempPwdForRuntime: (runtime: LockDeviceRuntime, params: RenameFitTempPwdParams) => Promise<void>;
28
+ export interface RenameFitOfflineTempPwdParams {
29
+ pwdId: number;
30
+ name: string;
31
+ }
32
+ export declare const fitRenameOfflineTempPwdForRuntime: (runtime: LockDeviceRuntime, params: RenameFitOfflineTempPwdParams) => Promise<void>;
33
+ export interface RevokeFitOfflineTempPwdParams {
34
+ pwdId: number;
35
+ name?: string;
36
+ }
37
+ export interface FitOfflineClearCodeResult {
38
+ password: string;
39
+ pwdId: string;
40
+ name: string;
41
+ effectiveConfig: {
42
+ effectiveDate: number;
43
+ expiredDate: number;
44
+ };
45
+ }
46
+ export declare const fitRevokeOfflineTempPwdForRuntime: (runtime: LockDeviceRuntime, params: RevokeFitOfflineTempPwdParams) => Promise<FitOfflineClearCodeResult>;
47
+ export interface ResendFitTempPwdParams {
48
+ id: number;
49
+ }
50
+ export declare const fitResendTempPwdForRuntime: (runtime: LockDeviceRuntime, params: ResendFitTempPwdParams) => Promise<boolean>;
@@ -3,11 +3,13 @@ import dpCodes from "../../config/dp-code";
3
3
  import { fitAddTempPwd, fitReportAddTempPwd, fitRemoveTempPwd, fitReportRemoveTempPwd, fitUpdateTempPwd, fitReportUpdateTempPwd, fitBlePswCreate, fitBlePswDelete, fitBlePswCreateReport, fitBlePswDeleteReport, fitBlePswUpdate, fitBlePswUpdateReport, } from "../../config/dp-map/temp-pwd-fit";
4
4
  import { publishDpsForRuntime } from "../dp/publish-dps";
5
5
  import { resolveSlaveId } from "./resolve-slave-id";
6
- import { getError } from "../../utils/errors";
6
+ import { getError, handleCloudError } from "../../utils/errors";
7
7
  import { sdkLog } from "../../utils/sdk-log";
8
- import { addFitOnlineTempPwd, addFitOnlineTempPwdCloud, getFitPasswordList, removeFitOnlineTempPwd, renameFitOnlineTempPwd, updateFitOnlineTempPwd, } from "../../api/fit";
8
+ import { addFitOnlineTempPwd, addFitOnlineTempPwdCloud, getFitPasswordList, removeFitOnlineTempPwd, renameFitOnlineTempPwd, resendFitOnlineTempPwd, updateFitOnlineTempPwd, } from "../../api/fit";
9
+ import { reNameOfflineByPwdId, revokeOfflinePasswordByPwdId } from "../../api/temp";
9
10
  import { decrypt, encrypt } from "../../platform";
10
11
  import { formatPasswordToList, formatWeek, getAppUser, parseWeek, sleep, transformEffectiveConfigToValidConfig, validateEffectiveConfig, } from "../../utils";
12
+ import { parseOfflinePasswordForRuntime } from "../utils";
11
13
  import { hasDpForRuntime } from "../dp/has-dp";
12
14
  export async function fitAddTempPwdForRuntime(runtime, params) {
13
15
  const startedAt = Date.now();
@@ -180,7 +182,7 @@ export async function fitRemoveTempPwdForRuntime(runtime, params) {
180
182
  data: { id: params.id, status: res.status, strategy: "device_first" },
181
183
  });
182
184
  if (res.status === 0x00 || res.status === 0x02) {
183
- await removeFitOnlineTempPwd(runtime.devId, exist.pwdId);
185
+ await removeFitOnlineTempPwd(runtime.devId, exist.unlockBindingId);
184
186
  }
185
187
  else {
186
188
  throw getError(1028);
@@ -426,3 +428,93 @@ export const fitRenameTempPwdForRuntime = async (runtime, params) => {
426
428
  throw error;
427
429
  }
428
430
  };
431
+ export const fitRenameOfflineTempPwdForRuntime = async (runtime, params) => {
432
+ const startedAt = Date.now();
433
+ sdkLog("info", "fitTempPassword", "renameOfflineStart", {
434
+ devId: runtime.devId,
435
+ data: { pwdId: params.pwdId, hasName: typeof params.name === "string" },
436
+ });
437
+ try {
438
+ await reNameOfflineByPwdId({
439
+ devId: runtime.devId,
440
+ pwdName: params.name,
441
+ pwdId: params.pwdId,
442
+ });
443
+ sdkLog("info", "fitTempPassword", "renameOfflineSuccess", {
444
+ devId: runtime.devId,
445
+ duration: Date.now() - startedAt,
446
+ data: { pwdId: params.pwdId },
447
+ });
448
+ }
449
+ catch (error) {
450
+ sdkLog("error", "fitTempPassword", "renameOfflineFail", {
451
+ devId: runtime.devId,
452
+ duration: Date.now() - startedAt,
453
+ data: { pwdId: params.pwdId },
454
+ error,
455
+ });
456
+ throw error;
457
+ }
458
+ };
459
+ export const fitRevokeOfflineTempPwdForRuntime = async (runtime, params) => {
460
+ const startedAt = Date.now();
461
+ sdkLog("info", "fitTempPassword", "revokeOfflineStart", {
462
+ devId: runtime.devId,
463
+ data: { pwdId: params.pwdId, hasName: typeof params.name === "string" },
464
+ });
465
+ try {
466
+ const res = await revokeOfflinePasswordByPwdId({
467
+ devId: runtime.devId,
468
+ pwdId: params.pwdId,
469
+ name: params.name,
470
+ });
471
+ sdkLog("info", "fitTempPassword", "revokeOfflineSuccess", {
472
+ devId: runtime.devId,
473
+ duration: Date.now() - startedAt,
474
+ data: { pwdId: params.pwdId },
475
+ });
476
+ return {
477
+ password: parseOfflinePasswordForRuntime(runtime, res.pwd),
478
+ pwdId: res.pwdId,
479
+ name: res.pwdName,
480
+ effectiveConfig: {
481
+ effectiveDate: res.gmtStart,
482
+ expiredDate: res.gmtExpired,
483
+ },
484
+ };
485
+ }
486
+ catch (error) {
487
+ sdkLog("error", "fitTempPassword", "revokeOfflineFail", {
488
+ devId: runtime.devId,
489
+ duration: Date.now() - startedAt,
490
+ data: { pwdId: params.pwdId },
491
+ error,
492
+ });
493
+ throw handleCloudError(error);
494
+ }
495
+ };
496
+ export const fitResendTempPwdForRuntime = async (runtime, params) => {
497
+ const startedAt = Date.now();
498
+ sdkLog("info", "fitTempPassword", "resendStart", {
499
+ devId: runtime.devId,
500
+ data: { id: params.id },
501
+ });
502
+ try {
503
+ const result = await resendFitOnlineTempPwd(runtime.devId, params.id);
504
+ sdkLog("info", "fitTempPassword", "resendSuccess", {
505
+ devId: runtime.devId,
506
+ duration: Date.now() - startedAt,
507
+ data: { id: params.id },
508
+ });
509
+ return result;
510
+ }
511
+ catch (error) {
512
+ sdkLog("error", "fitTempPassword", "resendFail", {
513
+ devId: runtime.devId,
514
+ duration: Date.now() - startedAt,
515
+ data: { id: params.id },
516
+ error,
517
+ });
518
+ throw error;
519
+ }
520
+ };
@@ -7,6 +7,7 @@ export interface FitUserItem {
7
7
  nickName: string;
8
8
  userType: UserType;
9
9
  userContact: string;
10
+ userTimeSet: string;
10
11
  phase: number;
11
12
  }
12
13
  export declare function getFitUsersForRuntime(runtime: LockDeviceRuntime): Promise<FitUserItem[]>;
@@ -7,6 +7,7 @@ const pickFitUserItem = (raw) => ({
7
7
  nickName: raw.nickName,
8
8
  userType: raw.userType,
9
9
  userContact: raw.userContact,
10
+ userTimeSet: raw.userTimeSet,
10
11
  phase: raw.phase,
11
12
  });
12
13
  export async function getFitUsersForRuntime(runtime) {
@@ -1,5 +1,5 @@
1
1
  import { LockLogCategory } from "../../api/log";
2
- import { AlbumMessage, LogData, UnlockMethodType } from "../../interface";
2
+ import { AlbumMessage, CloseValue, LogData, UnlockMethodType } from "../../interface";
3
3
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
4
4
  export type LogsRefreshListener = () => void;
5
5
  export declare function getLogsRefreshEvent(runtime: LockDeviceRuntime): string;
@@ -16,11 +16,13 @@ export interface GetLogsParams {
16
16
  pageSize?: number;
17
17
  }
18
18
  export declare const openDps: ("unlock_matter_kw" | "unlock_password" | "unlock_fingerprint" | "unlock_finger_vein" | "unlock_hand" | "unlock_dynamic" | "unlock_key" | "unlock_card" | "unlock_face" | "unlock_temporary" | "unlock_offline_pd" | "unlock_phone_remote" | "unlock_voice_remote" | "lock_record" | "unlock_ble" | "unlock_eye" | "unlock_double_kit" | "unlock_double_kit_w" | "open_inside" | "lock_local_record" | "unlock_inside" | "door_opened" | "unlock_app")[];
19
+ export declare const closeTypes: CloseValue[];
19
20
  export interface GetLogsResult {
20
21
  list: LogData[];
21
22
  hasMore: boolean;
22
23
  total: number;
23
24
  }
25
+ export declare const dpIdsForUsernameToUnlockName: number[];
24
26
  export declare function getLogsForRuntime(rt: LockDeviceRuntime, params?: GetLogsParams): Promise<GetLogsResult>;
25
27
  export interface GetAlarmsParams {
26
28
  page?: number;
@@ -61,3 +63,5 @@ export interface GetLockLogListResult {
61
63
  lastRowKey: string;
62
64
  }
63
65
  export declare const getLockLogListForRuntime: (rt: LockDeviceRuntime, params: GetLockLogListParams) => Promise<GetLockLogListResult>;
66
+ export declare const getAlarmUnreadCountForRuntime: (rt: LockDeviceRuntime) => Promise<number>;
67
+ export declare const getActivePeriodForRuntime: (rt: LockDeviceRuntime) => Promise<number>;