@ray-js/lock-sdk 1.2.2 → 1.2.3-beta.0

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 CHANGED
@@ -134,7 +134,7 @@ interface UpdateFitOpenModeParams {
134
134
  hijack: boolean;
135
135
  }
136
136
  export declare const updateFitOpenMode: (params: UpdateFitOpenModeParams) => Promise<unknown>;
137
- export declare const removeFitOpenMode: (fittingId: string, opModeId: string) => Promise<unknown>;
137
+ export declare const removeFitOpenMode: (fittingId: string, opModeId: number) => Promise<unknown>;
138
138
  export interface RawFitOpenModeScheduleItem {
139
139
  allDay: boolean;
140
140
  effectiveTime: number;
package/lib/api/log.js CHANGED
@@ -29,7 +29,10 @@ export const getLockLogList = (params) => {
29
29
  logName: "getLockLogList",
30
30
  api: `${THING}.m.device.lock.log.list`,
31
31
  version: "1.0",
32
- data: params,
32
+ data: {
33
+ ...params,
34
+ logCategories: params.logCategories?.join(","),
35
+ },
33
36
  });
34
37
  };
35
38
  export const uploadOperationLog = (params) => {
@@ -26,6 +26,7 @@ declare const dpCodes: {
26
26
  readonly unlockKey: "unlock_key";
27
27
  readonly unlockCard: "unlock_card";
28
28
  readonly unlockFace: "unlock_face";
29
+ readonly unlockPhoneKey: "unlock_phonekey";
29
30
  readonly unlockTemporary: "unlock_temporary";
30
31
  readonly unlockOfflinePd: "unlock_offline_pd";
31
32
  readonly unlockOfflineClear: "unlock_offline_clear";
@@ -26,6 +26,7 @@ const dpCodes = {
26
26
  unlockKey: "unlock_key",
27
27
  unlockCard: "unlock_card",
28
28
  unlockFace: "unlock_face",
29
+ unlockPhoneKey: "unlock_phonekey",
29
30
  unlockTemporary: "unlock_temporary",
30
31
  unlockOfflinePd: "unlock_offline_pd",
31
32
  unlockOfflineClear: "unlock_offline_clear",
@@ -27,3 +27,4 @@ export * from "./fit-sdk/binding";
27
27
  export * from "./fit-sdk/device";
28
28
  export * from "./fit-sdk/log";
29
29
  export * from "./fit-sdk/temp";
30
+ export * from "./yu-channel";
@@ -27,3 +27,4 @@ export * from "./fit-sdk/binding";
27
27
  export * from "./fit-sdk/device";
28
28
  export * from "./fit-sdk/log";
29
29
  export * from "./fit-sdk/temp";
30
+ export * from "./yu-channel";
@@ -1,8 +1,8 @@
1
1
  import type { DpMap } from "@ray-js/tuya-dp-transform";
2
2
  import { fitAdd } from "../../../../config/dp-map/unlock-method-fit";
3
- import type { DpMapDataType, UnlockMethodConfig, UnlockMethodType, UserInfo } from "../../../../interface";
3
+ import type { DpMapDataType, UnlockMethodConfig, UnlockMethodType } from "../../../../interface";
4
4
  import type { LockDeviceRuntime } from "../../../../runtime/LockDeviceRuntime";
5
- export declare function buildValidConfigFromTimeSchedule(timeScheduleInfo: UserInfo["timeScheduleInfo"] | null | undefined): DpMapDataType<typeof fitAdd>["validConfig"];
5
+ export declare function buildValidConfigFromUserTimeSet(userTimeSet: string | null | undefined): DpMapDataType<typeof fitAdd>["validConfig"];
6
6
  export interface FitUnlockMethodBase {
7
7
  unlockMethodConfig: UnlockMethodConfig;
8
8
  fittingId: string;
@@ -10,7 +10,6 @@ export interface FitUnlockMethodBase {
10
10
  slaveId: number;
11
11
  lockUserId: number;
12
12
  userType: number;
13
- lockUserInfo: UserInfo;
14
13
  addDpCode: string;
15
14
  addDpMap: DpMap;
16
15
  addDpReportMap: DpMap;
@@ -3,35 +3,17 @@ import dpCodes from "../../../../config/dp-code";
3
3
  import { fitAdd, fitReportAdd, } from "../../../../config/dp-map/unlock-method-fit";
4
4
  import { isAdmin } from "../../../../utils";
5
5
  import { getError } from "../../../../utils/errors";
6
- import { LoopTypes } from "../../../../utils/constant";
7
6
  import { sdkLog } from "../../../../utils/sdk-log";
8
7
  import { getUnlockMethodTypeByTypeForRuntime } from "../../../utils";
9
- import { getUserInfoOnDevForRuntime } from "../../../user/user";
10
8
  import { getBoundLockListForRuntime } from "../../list";
11
9
  import { resolveSlaveId } from "../../resolve-slave-id";
12
10
  import { validConfigDpMap } from "../../../../config/dp-map/common";
13
- export function buildValidConfigFromTimeSchedule(timeScheduleInfo) {
14
- if (!timeScheduleInfo) {
11
+ import { getFitUsersForRuntime } from "../../users";
12
+ export function buildValidConfigFromUserTimeSet(userTimeSet) {
13
+ if (!userTimeSet) {
15
14
  throw getError(1106);
16
15
  }
17
- const { permanent, userTimeSet, effectiveTime, expiredTime, scheduleDetails, } = timeScheduleInfo;
18
- if (permanent) {
19
- return DpUtils.parse(userTimeSet, validConfigDpMap.childMap);
20
- }
21
- return {
22
- startTime: Math.floor((effectiveTime || +new Date()) / 1000),
23
- endTime: expiredTime ? Math.floor(expiredTime / 1000) : 0x72bc9b7f,
24
- loop: scheduleDetails?.repeat ? LoopTypes.WEEK : LoopTypes.NONE,
25
- loopConfig: 0,
26
- weeks: scheduleDetails?.repeat
27
- ? scheduleDetails.weeks
28
- : [0, 0, 0, 0, 0, 0, 0],
29
- days: [],
30
- startHour: Math.floor((scheduleDetails?.effectiveTime ?? 0) / 60),
31
- startMinute: (scheduleDetails?.effectiveTime ?? 0) % 60,
32
- endHour: Math.floor((scheduleDetails?.invalidTime ?? 0) / 60),
33
- endMinute: (scheduleDetails?.invalidTime ?? 0) % 60,
34
- };
16
+ return DpUtils.parse(userTimeSet, validConfigDpMap.childMap);
35
17
  }
36
18
  async function resolveLockDevId(rt, lockDevId) {
37
19
  const list = await getBoundLockListForRuntime(rt);
@@ -80,12 +62,20 @@ export async function getFitUnlockMethodBase(rt, type, userId, lockDevId) {
80
62
  const unlockMethodConfig = getUnlockMethodTypeByTypeForRuntime(rt, type);
81
63
  const slaveId = await resolveSlaveId(rt, lockDevId);
82
64
  const resolvedLockDevId = await resolveLockDevId(rt, lockDevId);
83
- const lockUserInfo = await getUserInfoOnDevForRuntime(rt, {
84
- devId: resolvedLockDevId,
85
- userId,
86
- });
87
- const { lockUserId, userType, timeScheduleInfo } = lockUserInfo;
88
- const validConfig = buildValidConfigFromTimeSchedule(timeScheduleInfo);
65
+ const fitUsers = await getFitUsersForRuntime(rt);
66
+ const fitUserInfo = fitUsers.find((item) => item.userId === userId);
67
+ if (!fitUserInfo) {
68
+ const error = getError(1048);
69
+ sdkLog("warn", "fitUnlockMethod", "buildBaseUserNotFound", {
70
+ devId: rt.devId,
71
+ duration: Date.now() - startedAt,
72
+ data: { userId, userCount: fitUsers.length },
73
+ error,
74
+ });
75
+ throw error;
76
+ }
77
+ const { lockUserId, userType, userTimeSet } = fitUserInfo;
78
+ const validConfig = buildValidConfigFromUserTimeSet(userTimeSet);
89
79
  const dpData = {
90
80
  slaveId,
91
81
  type: unlockMethodConfig.id,
@@ -105,7 +95,6 @@ export async function getFitUnlockMethodBase(rt, type, userId, lockDevId) {
105
95
  slaveId,
106
96
  lockUserId,
107
97
  userType,
108
- lockUserInfo,
109
98
  addDpCode: dpCodes.unlockMethodCreate,
110
99
  addDpMap: fitAdd,
111
100
  addDpReportMap: fitReportAdd,
@@ -117,8 +106,9 @@ export async function getFitUnlockMethodBase(rt, type, userId, lockDevId) {
117
106
  data: {
118
107
  type,
119
108
  lockDevId: resolvedLockDevId,
109
+ lockUserId,
120
110
  userType,
121
- hasSchedule: !!timeScheduleInfo,
111
+ hasSchedule: !!userTimeSet,
122
112
  },
123
113
  });
124
114
  return result;
@@ -1,5 +1,5 @@
1
1
  import dpUtils from "@ray-js/tuya-dp-transform";
2
- import { getFitOpenModeList, removeFitOpenMode, updateFitOpenMode, } from "../../../api/fit";
2
+ import { getFitPasswordList, 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";
@@ -14,7 +14,29 @@ const FIT_DELETABLE_UNLOCK_METHOD_TYPES = [
14
14
  "hand",
15
15
  "fingerVein",
16
16
  ];
17
+ function isOperateNotSupported(error) {
18
+ if (!error || typeof error !== "object") {
19
+ return false;
20
+ }
21
+ const cloudError = error;
22
+ return (cloudError.innerError?.errorCode === "OPERATE_NOT_SUPPORTED" ||
23
+ cloudError.ext?.errorCode === "OPERATE_NOT_SUPPORTED" ||
24
+ cloudError.errorCode === "OPERATE_NOT_SUPPORTED");
25
+ }
17
26
  async function findFitOpenModeRawById(rt, id) {
27
+ let passwordConfig;
28
+ try {
29
+ passwordConfig = getUnlockMethodTypeByTypeForRuntime(rt, "password");
30
+ }
31
+ catch {
32
+ }
33
+ if (passwordConfig) {
34
+ const passwordList = await getFitPasswordList(rt.devId);
35
+ const password = (passwordList ?? []).find((item) => item.unlockBindingId === id && item.opModeType === 2);
36
+ if (password) {
37
+ return { raw: password, unlockMethodConfig: passwordConfig };
38
+ }
39
+ }
18
40
  for (const type of FIT_DELETABLE_UNLOCK_METHOD_TYPES) {
19
41
  let unlockMethodConfig;
20
42
  try {
@@ -27,7 +49,20 @@ async function findFitOpenModeRawById(rt, id) {
27
49
  if (!dpId) {
28
50
  continue;
29
51
  }
30
- const raw = await getFitOpenModeList(rt.devId, dpId);
52
+ let raw;
53
+ try {
54
+ raw = await getFitOpenModeList(rt.devId, dpId);
55
+ }
56
+ catch (error) {
57
+ if (!isOperateNotSupported(error)) {
58
+ throw error;
59
+ }
60
+ sdkLog("info", "fitUnlockMethod", "deleteLookupTypeUnsupported", {
61
+ devId: rt.devId,
62
+ data: { id, type, dpId },
63
+ });
64
+ continue;
65
+ }
31
66
  const hit = (raw ?? []).find((item) => item.unlockBindingId === id);
32
67
  if (hit) {
33
68
  return { raw: hit, unlockMethodConfig };
@@ -77,13 +112,12 @@ export const fitDeleteUnlockMethodForRuntime = parallelOnlyForRuntime(async func
77
112
  });
78
113
  const found = await findFitOpenModeRawById(rt, id);
79
114
  if (!found) {
80
- const error = getError(1040);
81
- sdkLog("warn", "fitUnlockMethod", "deleteRecordNotFound", {
115
+ sdkLog("info", "fitUnlockMethod", "deleteAlreadyAbsent", {
82
116
  devId: rt.devId,
117
+ duration: Date.now() - startedAt,
83
118
  data: { id },
84
- error,
85
119
  });
86
- throw error;
120
+ return;
87
121
  }
88
122
  const { raw, unlockMethodConfig } = found;
89
123
  const lockUserId = raw.lockUserId;
@@ -166,7 +200,7 @@ export const fitDeleteUnlockMethodForRuntime = parallelOnlyForRuntime(async func
166
200
  }
167
201
  }
168
202
  try {
169
- await removeFitOpenMode(rt.devId, String(id));
203
+ await removeFitOpenMode(rt.devId, id);
170
204
  sdkLog("info", "fitUnlockMethod", "deleteSuccess", {
171
205
  devId: rt.devId,
172
206
  duration: Date.now() - startedAt,
@@ -78,6 +78,20 @@ function handleLockLogs(list, cfg) {
78
78
  };
79
79
  break;
80
80
  }
81
+ case "offline_pwd_achieve": {
82
+ const [name, effectiveDate, expiredDate] = itemData;
83
+ tempPwdInfo = {
84
+ name: name,
85
+ effectiveConfig: {
86
+ effectiveDate: effectiveDate,
87
+ expiredDate: expiredDate,
88
+ },
89
+ };
90
+ break;
91
+ }
92
+ case "dynamic_pwd_achieve": {
93
+ break;
94
+ }
81
95
  case "offline_pwd_clear_achieve": {
82
96
  const [name, effectiveDate, expiredDate] = itemData;
83
97
  clearInfo = {
@@ -39,7 +39,21 @@ const handleUserDetail = (rt, user) => {
39
39
  },
40
40
  });
41
41
  }
42
- let unlockDetails = unlockDetail.map((detail) => {
42
+ const unlockDetails = unlockDetail.reduce((result, detail) => {
43
+ let unlockMethodConfig;
44
+ try {
45
+ unlockMethodConfig = getUnlockMethodTypeByDpCodeForRuntime(rt, detail.dpCode);
46
+ }
47
+ catch (error) {
48
+ if (error?.errorCode !== 1014) {
49
+ throw error;
50
+ }
51
+ sdkLog("debug", "user", "detailUnlockTypeSkipped", {
52
+ devId: rt.devId,
53
+ data: { dpCode: detail.dpCode },
54
+ });
55
+ return result;
56
+ }
43
57
  const unlockList = detail.unlockList.map((unlockItem) => {
44
58
  return {
45
59
  unlockId: +unlockItem.unlockId.split("-")[1],
@@ -50,15 +64,15 @@ const handleUserDetail = (rt, user) => {
50
64
  isSpecial: unlockItem.unlockAttr === 1,
51
65
  };
52
66
  });
53
- const unlockMethodConfig = getUnlockMethodTypeByDpCodeForRuntime(rt, detail.dpCode);
54
- return {
67
+ result.push({
55
68
  count: unlockList.length,
56
69
  dpCode: detail.dpCode,
57
70
  dpId: detail.dpId,
58
71
  type: unlockMethodConfig.type,
59
72
  unlockList,
60
- };
61
- });
73
+ });
74
+ return result;
75
+ }, []);
62
76
  return {
63
77
  ...rest,
64
78
  timeScheduleInfo: scheduleInfo,
@@ -32,6 +32,11 @@ const unlockMethodConfigs = [
32
32
  codes: [dpCodes.unlockFingerVein, dpCodes.unlockFingerVeinKit],
33
33
  id: 6,
34
34
  },
35
+ {
36
+ type: "phoneKey",
37
+ codes: [dpCodes.unlockPhoneKey],
38
+ id: 10,
39
+ },
35
40
  ];
36
41
  export const unlockMethodDpCodes = unlockMethodConfigs.reduce((res, item) => res.concat(item.codes), []);
37
42
  const getUnlockMethodTypeForRuntime = (rt, cb) => {
@@ -101,7 +101,7 @@ export interface UnlockMethodBaseInfo {
101
101
  photoUnlock: boolean;
102
102
  isSpecial: boolean;
103
103
  }
104
- export type UnlockMethodType = "finger" | "face" | "password" | "card" | "fingerVein" | "hand" | "eye";
104
+ export type UnlockMethodType = "finger" | "face" | "password" | "card" | "fingerVein" | "hand" | "eye" | "phoneKey";
105
105
  export interface UnlockMethodConfig {
106
106
  type: UnlockMethodType;
107
107
  code: string;
@@ -278,7 +278,7 @@ export interface MediaInfo {
278
278
  }
279
279
  export type LogType = "alarm_record" | "close_record" | "unlock_record" | "operation" | "local_operation";
280
280
  export type CloseValue = "UNDEFINED" | "VOICE_REMOTE" | "APP_REMOTE" | "AUTO" | "LOCAL_MANUAL" | "FITTINGS" | "APP" | "GEO_FENCE";
281
- export type OperationType = "dev_bind" | "member_schedule_update" | "unlock_add" | "unlock_del" | "temp_pwd_create" | "temp_pwd_del" | "temp_pwd_meta_update" | "temp_pwd_name_update" | "offline_pwd_achieve" | "offline_pwd_clear_achieve" | "offline_pwd_clear_single_achieve" | "offline_pwd_name_update" | "arming_switch" | "unlock_switch" | "automatic_lock" | "auto_lock_time" | "verify_lock_switch" | "do_not_disturb" | "special_control" | "special_function" | "beep_volume" | "remote_unlock_setting" | "remote_voice_pwd_setting";
281
+ export type OperationType = "dev_bind" | "member_schedule_update" | "unlock_add" | "unlock_del" | "temp_pwd_create" | "temp_pwd_del" | "temp_pwd_meta_update" | "temp_pwd_name_update" | "offline_pwd_achieve" | "offline_pwd_clear_achieve" | "offline_pwd_clear_single_achieve" | "offline_pwd_name_update" | "dynamic_pwd_achieve" | "arming_switch" | "unlock_switch" | "automatic_lock" | "auto_lock_time" | "verify_lock_switch" | "do_not_disturb" | "special_control" | "special_function" | "beep_volume" | "remote_unlock_setting" | "remote_voice_pwd_setting";
282
282
  export interface LogData {
283
283
  logId: string;
284
284
  time: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lock-sdk",
3
- "version": "1.2.2",
3
+ "version": "1.2.3-beta.0",
4
4
  "files": [
5
5
  "lib",
6
6
  "LICENSE.md"