@ray-js/lock-sdk 1.1.0 → 1.1.1-beta.10

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.
@@ -27,4 +27,12 @@ export declare const fetchOfflineDpData: (deviceId: string) => Promise<{
27
27
  }[]>;
28
28
  export declare const publishOfflineDpData: (deviceId: string, dpData: Record<string, DpValue>) => Promise<unknown>;
29
29
  export declare const clearOfflineDpData: (deviceId: string) => Promise<unknown>;
30
+ export declare const getFileRemoteUrl: ({ biz, resources, }: {
31
+ biz: string;
32
+ resources: {
33
+ objectKey: string;
34
+ }[];
35
+ }) => Promise<{
36
+ signedUrls: Record<string, string>;
37
+ }>;
30
38
  export {};
package/lib/api/index.js CHANGED
@@ -70,3 +70,13 @@ export const clearOfflineDpData = async (deviceId) => {
70
70
  version: "1.0",
71
71
  });
72
72
  };
73
+ export const getFileRemoteUrl = ({ biz, resources, }) => {
74
+ return requestApi({
75
+ api: `${THING}.web.fastroute.download.sign`,
76
+ version: "2.0",
77
+ data: {
78
+ biz,
79
+ signedRequest: { resources },
80
+ },
81
+ });
82
+ };
package/lib/api/lock.d.ts CHANGED
@@ -124,4 +124,9 @@ interface BindUnlockMethodToUserByRecordParams {
124
124
  unlockIds: string[];
125
125
  }
126
126
  export declare const bindUnlockMethodToUserByRecord: (params: BindUnlockMethodToUserByRecordParams) => Promise<boolean>;
127
+ interface ValidatePasswordComplexityParams {
128
+ devId: string;
129
+ password: string;
130
+ }
131
+ export declare const validatePasswordComplexity: (params: ValidatePasswordComplexityParams) => Promise<boolean>;
127
132
  export {};
package/lib/api/lock.js CHANGED
@@ -116,3 +116,10 @@ export const bindUnlockMethodToUserByRecord = (params) => {
116
116
  data: params,
117
117
  });
118
118
  };
119
+ export const validatePasswordComplexity = (params) => {
120
+ return requestApi({
121
+ api: "m.lock.password.simplicity.check",
122
+ version: "1.0",
123
+ data: params,
124
+ });
125
+ };
package/lib/api/temp.js CHANGED
@@ -38,7 +38,7 @@ export const getTempPassword = (params) => {
38
38
  export const deleteTempPassword = (params) => {
39
39
  return requestApi({
40
40
  api: `${THING}.m.device.lock.temppwd.remove`,
41
- version: "2.0",
41
+ version: "5.0",
42
42
  data: params,
43
43
  });
44
44
  };
package/lib/api/user.d.ts CHANGED
@@ -102,6 +102,12 @@ interface UserDetail {
102
102
  userType: number;
103
103
  }
104
104
  export declare const getUserDetail: (params: GetUserDetailParams) => Promise<UserDetail>;
105
+ interface GetUserDetailQueryParams {
106
+ devId: string;
107
+ userId: string;
108
+ dpIds: string;
109
+ }
110
+ export declare const getUserDetailQuery: (params: GetUserDetailQueryParams) => Promise<UserListItem>;
105
111
  export interface RemovedUserData {
106
112
  userId: string;
107
113
  lockUserId: number;
package/lib/api/user.js CHANGED
@@ -40,8 +40,15 @@ export const getUserList = (params) => {
40
40
  };
41
41
  export const getUserDetail = (params) => {
42
42
  return requestApi({
43
- api: `${THING}.m.device.member.detail`,
44
- version: "4.0",
43
+ api: "m.lock.device.member.detail",
44
+ version: "1.0",
45
+ data: params,
46
+ });
47
+ };
48
+ export const getUserDetailQuery = (params) => {
49
+ return requestApi({
50
+ api: "m.lock.user.detail.query",
51
+ version: "1.0",
45
52
  data: params,
46
53
  });
47
54
  };
package/lib/capability.js CHANGED
@@ -45,6 +45,7 @@ export const getDeviceAdvancedAbilities = async () => {
45
45
  "tyabi4ucx5",
46
46
  "tyabis9tpe",
47
47
  "tyabiwxrn9",
48
+ "tyabipd4hh",
48
49
  ]),
49
50
  getDeviceAdvancedAbility(config.devInfo.devId),
50
51
  ]);
@@ -68,27 +69,52 @@ export const getDeviceAdvancedAbilities = async () => {
68
69
  support: false,
69
70
  config: {},
70
71
  },
72
+ unlockGuide: {
73
+ support: false,
74
+ config: {},
75
+ },
71
76
  };
72
77
  productAbilities.forEach((item) => {
73
- const data = JSON.parse(item.extConfig);
74
- if (item.abilityCode === "tyabi4ucx5" && item.isOpen) {
75
- deviceAdvanceAbilityCache.ai.config = data;
76
- const dataReport = data?.ai_data_report ?? false;
77
- const itemRecognition = data?.ai_recognition?.[0]?.item_recognition ?? false;
78
- const petRecognition = data?.ai_recognition?.[0]?.pet_recognition ?? false;
79
- const voice = data?.ai_voice ?? false;
80
- const message = data?.ai_message ?? false;
81
- deviceAdvanceAbilityCache.ai.support =
82
- dataReport || itemRecognition || petRecognition || voice || message;
83
- }
84
- else if (item.abilityCode === "tyabis9tpe" && item.isOpen) {
85
- deviceAdvanceAbilityCache.wechat.support = true;
86
- deviceAdvanceAbilityCache.wechat.config = data;
78
+ try {
79
+ if (item.isOpen) {
80
+ const data = JSON.parse(item.extConfig);
81
+ switch (item.abilityCode) {
82
+ case "tyabi4ucx5": {
83
+ deviceAdvanceAbilityCache.ai.config = data;
84
+ const dataReport = data?.ai_data_report ?? false;
85
+ const itemRecognition = data?.ai_recognition?.[0]?.item_recognition ?? false;
86
+ const petRecognition = data?.ai_recognition?.[0]?.pet_recognition ?? false;
87
+ const voice = data?.ai_voice ?? false;
88
+ const message = data?.ai_message ?? false;
89
+ deviceAdvanceAbilityCache.ai.support =
90
+ dataReport ||
91
+ itemRecognition ||
92
+ petRecognition ||
93
+ voice ||
94
+ message;
95
+ break;
96
+ }
97
+ case "tyabis9tpe": {
98
+ deviceAdvanceAbilityCache.wechat.support = true;
99
+ deviceAdvanceAbilityCache.wechat.config = data;
100
+ break;
101
+ }
102
+ case "tyabiwxrn9": {
103
+ deviceAdvanceAbilityCache.wechatVoip.support =
104
+ !!data?.voipType?.includes("0");
105
+ deviceAdvanceAbilityCache.wechatVoip.config = data;
106
+ break;
107
+ }
108
+ case "tyabipd4hh": {
109
+ deviceAdvanceAbilityCache.unlockGuide.support = true;
110
+ deviceAdvanceAbilityCache.unlockGuide.config = data;
111
+ break;
112
+ }
113
+ }
114
+ }
87
115
  }
88
- else if (item.abilityCode === "tyabiwxrn9" && item.isOpen) {
89
- deviceAdvanceAbilityCache.wechatVoip.support =
90
- !!data?.voipType?.includes("0");
91
- deviceAdvanceAbilityCache.wechatVoip.config = data;
116
+ catch (error) {
117
+ console.warn(`setting [${item.abilityCode}] config error`, error);
92
118
  }
93
119
  });
94
120
  return deviceAdvanceAbilityCache;
@@ -1,4 +1,5 @@
1
1
  declare const dpCodes: {
2
+ lockMotorState: string;
2
3
  remoteNoDpKey: string;
3
4
  remoteNoPdSetkey: string;
4
5
  synchMethodW: string;
@@ -1,4 +1,5 @@
1
1
  const dpCodes = {
2
+ lockMotorState: 'lock_motor_state',
2
3
  remoteNoDpKey: "remote_no_dp_key",
3
4
  remoteNoPdSetkey: "remote_no_pd_setkey",
4
5
  synchMethodW: "synch_method_w",
@@ -52,7 +52,7 @@ export const validConfigDpMap = {
52
52
  .slice(0, 7);
53
53
  },
54
54
  format: (value) => {
55
- const weekHex = parseInt(value.reverse().join(""), 2)
55
+ const weekHex = parseInt([...value].reverse().join(""), 2)
56
56
  .toString(16)
57
57
  .padStart(2, "0");
58
58
  return `000000${weekHex}`;
@@ -382,17 +382,16 @@ declare const reportAddTempPwd: ({
382
382
  name: string;
383
383
  bytes?: undefined;
384
384
  })[];
385
- declare const removeTempPwd: {
386
- name: string;
387
- bytes: number;
388
- }[];
389
- declare const reportRemoveTempPwd: ({
390
- name: string;
391
- bytes: number;
392
- } | {
393
- name: string;
394
- bytes?: undefined;
395
- })[];
385
+ declare const removeTempPwd: readonly [{
386
+ readonly name: "unlockId";
387
+ readonly bytes: 2;
388
+ }];
389
+ declare const reportRemoveTempPwd: readonly [{
390
+ readonly name: "unlockId";
391
+ readonly bytes: 2;
392
+ }, {
393
+ readonly name: "status";
394
+ }];
396
395
  declare const updateTempPwd: ({
397
396
  readonly name: "validConfig";
398
397
  readonly type: "child";
@@ -18,9 +18,10 @@ declare const config: {
18
18
  videoAngle: number;
19
19
  supportMultipleFace: boolean;
20
20
  supportOfflineDps: boolean;
21
+ preFetch: boolean;
21
22
  deviceStatus: DeviceStatus;
22
23
  };
23
- type UpdateConfigParams = Omit<LockSDKOption, "devInfo" | "deviceId">;
24
+ type UpdateConfigParams = Omit<LockSDKOption, "devInfo" | "deviceId" | "preFetch">;
24
25
  export declare const updateConfig: (options: UpdateConfigParams) => void;
25
26
  export declare const hasCapability: (capability: ProductCommunicationType) => boolean;
26
27
  export declare const hasDp: (dpCode: string) => boolean;
@@ -16,6 +16,7 @@ const config = {
16
16
  videoAngle: 0,
17
17
  supportMultipleFace: false,
18
18
  supportOfflineDps: false,
19
+ preFetch: false,
19
20
  deviceStatus: {
20
21
  type: "offline",
21
22
  connectEnable: false,
package/lib/index.js CHANGED
@@ -60,9 +60,10 @@ export const init = async (options) => {
60
60
  config.codesById = codesById;
61
61
  config.idsByCode = idsByCode;
62
62
  config.supportBigData = !!dpSchema[dpCodes.synchMethodW];
63
+ config.preFetch = options?.preFetch ?? false;
63
64
  config.communication = getCapabilities(devInfo.capability).map((item) => item.id);
64
- await initState();
65
65
  addEvents();
66
+ await initState();
66
67
  };
67
68
  export const destroy = () => {
68
69
  clearState();
@@ -10,6 +10,7 @@ export interface LockSDKOption {
10
10
  passwordSupportZero?: boolean;
11
11
  supportMultipleFace?: boolean;
12
12
  supportOfflineDps?: boolean;
13
+ preFetch?: boolean;
13
14
  }
14
15
  export interface ErrorData {
15
16
  errorCode: number;
@@ -81,7 +82,7 @@ export interface CurrentUser {
81
82
  permanent: boolean;
82
83
  }
83
84
  export interface UnlockMethodBaseInfo {
84
- unlockId: string;
85
+ unlockId: number;
85
86
  unlockName: string;
86
87
  isBound: boolean;
87
88
  id: number;
@@ -143,11 +144,13 @@ export type DpMapDataType<T extends DpMapType> = {
143
144
  };
144
145
  export interface NotifyInfo {
145
146
  appSend?: boolean;
147
+ msgSend?: boolean;
146
148
  msgPhone?: string;
147
149
  countryCode?: string;
148
150
  }
149
151
  export interface UnlockMethodDetail {
150
152
  isBound: boolean;
153
+ type: UnlockMethodType;
151
154
  phase: number;
152
155
  dpId: number;
153
156
  isSpecial: boolean;
@@ -185,6 +188,7 @@ export interface DeviceStatus {
185
188
  type: "offline" | "online" | "sleep";
186
189
  connectEnable: boolean;
187
190
  onlineType: "local" | "cloud" | "ble" | "none" | "unknown";
191
+ onlineTypes: Array<"local" | "cloud" | "ble" | "localMatter" | "unknown">;
188
192
  sleepPeriod?: {
189
193
  start: number;
190
194
  end: number;
@@ -311,6 +315,10 @@ export interface DeviceAdvancedAbility {
311
315
  support: boolean;
312
316
  config: Record<string, any>;
313
317
  };
318
+ unlockGuide: {
319
+ support: boolean;
320
+ config: Record<string, any>;
321
+ };
314
322
  }
315
323
  export interface OfflineDpInfo {
316
324
  value: DpValue;
@@ -319,4 +327,9 @@ export interface OfflineDpInfo {
319
327
  export interface OfflineDps {
320
328
  [code: string]: OfflineDpInfo;
321
329
  }
330
+ export interface UnlockGuide {
331
+ videoUrl: string;
332
+ picUrl: string;
333
+ expireTime: number;
334
+ }
322
335
  export {};
package/lib/log.js CHANGED
@@ -36,6 +36,12 @@ export const getLatestLogs = async () => {
36
36
  catch {
37
37
  }
38
38
  }
39
+ let userName = item.userName;
40
+ let unlockName = item.unlockName;
41
+ if (item.dpId === 89 || item.dpId === 69) {
42
+ unlockName = item.userName;
43
+ userName = "";
44
+ }
39
45
  return {
40
46
  type,
41
47
  logId: item.logId,
@@ -43,8 +49,8 @@ export const getLatestLogs = async () => {
43
49
  dpCode,
44
50
  data: itemData,
45
51
  userId: item.userId,
46
- userName: item.userName,
47
- unlockName: item.unlockName,
52
+ userName,
53
+ unlockName,
48
54
  mediaInfo: item.mediaInfoList,
49
55
  unionUnlockInfo: item.unionUnlockInfo?.map((item1) => {
50
56
  return {
@@ -142,6 +148,12 @@ export const getLogs = async (params) => {
142
148
  if (dpCode === dpCodes.lockLocalRecord) {
143
149
  type = "local_operation";
144
150
  }
151
+ let userName = record.userName;
152
+ let unlockName = record.unlockName;
153
+ if (record.dpId === 89 || record.dpId === 69) {
154
+ unlockName = record.userName;
155
+ userName = "";
156
+ }
145
157
  return {
146
158
  type,
147
159
  logId: record.historyId.toString(),
@@ -149,8 +161,8 @@ export const getLogs = async (params) => {
149
161
  dpId: record.dpId,
150
162
  data: dpValue,
151
163
  dpCode,
152
- userName: record.userName,
153
- unlockName: record.unlockName,
164
+ userName,
165
+ unlockName,
154
166
  mediaInfo: record.mediaInfoList,
155
167
  unionUnlockInfo: record.unionUnlockInfo?.map((item) => ({
156
168
  userId: item.userId,
package/lib/open.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import dpUtils from "@ray-js/tuya-dp-transform";
2
2
  import { getDoorKey, openDoorByCloud, isConfirmOpenDoorByWifiPro, } from "./api/lock";
3
- import config, { hasCapability } from "./config";
3
+ import config, { hasCapability, hasDp } from "./config";
4
4
  import { isUseNearChannel, parallelMerge, parallelOnly } from "./utils";
5
5
  import { decrypt, encrypt } from "./utils/device";
6
6
  import { publishDps } from "./utils/publishDps";
@@ -42,18 +42,18 @@ export const checkRemoteEnabled = parallelMerge(async () => {
42
42
  if (deviceStatus.type !== "online") {
43
43
  throw getError(1001);
44
44
  }
45
- if (deviceStatus.onlineType === "local") {
46
- if (!hasThread) {
47
- throw getError(1064);
48
- }
45
+ const isLocalOnline = deviceStatus.onlineTypes.length === 1 &&
46
+ deviceStatus.onlineTypes.includes("local");
47
+ const isThreadLocalOnline = hasThread && isLocalOnline;
48
+ if (isThreadLocalOnline || deviceStatus.onlineTypes.includes("ble")) {
49
+ return;
50
+ }
51
+ if (isLocalOnline) {
52
+ throw getError(1064);
49
53
  }
50
54
  if (dpSchema[dpCodes.remoteNoDpKey] === undefined) {
51
55
  throw getError(1045);
52
56
  }
53
- if ((hasThread && deviceStatus.onlineType === "local") ||
54
- deviceStatus.onlineType === "ble") {
55
- return;
56
- }
57
57
  if (!remoteOpenEnabled) {
58
58
  throw getError(1046);
59
59
  }
@@ -65,7 +65,7 @@ export const checkRemoteEnabled = parallelMerge(async () => {
65
65
  }
66
66
  });
67
67
  const _doAction = async (isOpen, timeout) => {
68
- const { devInfo, onlineType, capabilities, communication, dpSchema } = config;
68
+ const { devInfo, communication } = config;
69
69
  await checkRemoteEnabled();
70
70
  const deviceStatus = getDeviceStatus();
71
71
  const hasThread = hasCapability(ProductCommunicationType.THREAD);
@@ -73,9 +73,19 @@ const _doAction = async (isOpen, timeout) => {
73
73
  const currentUser = await getCurrentUser();
74
74
  const memberId = currentUser.lockUserId !== 0 ? currentUser.lockUserId : currentUser.userId;
75
75
  const checkReport = (dpData) => {
76
+ if (hasDp(dpCodes.lockMotorState)) {
77
+ if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
78
+ return {
79
+ status: 0,
80
+ };
81
+ }
82
+ }
76
83
  if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
77
84
  const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
78
85
  if (result.memberId === memberId) {
86
+ if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
87
+ return false;
88
+ }
79
89
  return result;
80
90
  }
81
91
  else {
@@ -84,7 +94,7 @@ const _doAction = async (isOpen, timeout) => {
84
94
  }
85
95
  return false;
86
96
  };
87
- if (hasThread && deviceStatus.onlineType === "local") {
97
+ if (hasThread && deviceStatus.onlineTypes.includes("local") && deviceStatus.onlineTypes.length === 1) {
88
98
  await publishDps({ [dpCodes.matterLanUnlock]: isOpen }, {
89
99
  checkReport: (dps) => {
90
100
  return typeof dps[dpCodes.matterLanUnlock] !== "undefined";
@@ -229,7 +239,7 @@ export const updateVoiceUnlockPwd = async (password) => {
229
239
  const encryptedPassword = await encrypt(config.devInfo.devId, password);
230
240
  return setVoicePwd({
231
241
  devId: config.devInfo.devId,
232
- open: false,
242
+ open: true,
233
243
  pwd: encryptedPassword,
234
244
  });
235
245
  };
package/lib/other.d.ts CHANGED
@@ -27,4 +27,5 @@ export declare const connectDevice: () => Promise<unknown>;
27
27
  export declare const gotoService: (params?: {
28
28
  tab?: "cloudStorage" | "AI";
29
29
  }) => Promise<unknown>;
30
+ export declare const validatePwdComplexity: (password: string) => Promise<boolean>;
30
31
  export {};
package/lib/other.js CHANGED
@@ -3,13 +3,14 @@ import config, { hasCapability, hasDp } from "./config";
3
3
  import dpCodes from "./config/dp-code";
4
4
  import { ProductCommunicationType } from "./constant";
5
5
  import { getDeviceStatus, getDpValue } from "./state";
6
- import { connectBLEDevice, getBLEOnlineState, navigateToMiniProgram, offBleChange, offOnlineChange, onBleChange, onOnlineChange, openPanel, } from "./utils/device";
6
+ import { connectBLEDevice, encrypt, getBLEOnlineState, navigateToMiniProgram, offBleChange, offOnlineChange, onBleChange, onOnlineChange, openPanel, } from "./utils/device";
7
7
  import { getError } from "./utils/errors";
8
8
  import { publishDps } from "./utils/publishDps";
9
9
  import ipc from "./utils/ipc";
10
10
  import { DPCHANGE } from "./utils/constant";
11
11
  import emitter from "./utils/event";
12
12
  import { getOfflineDpCache, publishOfflineDps } from "./offline-dps";
13
+ import { validatePasswordComplexity } from "./api/lock";
13
14
  const { alarmLock, unlockFingerprint, unlockPassword, unlockCard, unlockKey, unlockPhoneRemote, unlockTemporary, unlockDynamic, unlockFace, unlockHand, unlockEye, unlockFingerVein, unlockInside, doorOpened, unlockApp, unlockOfflinePd, openInside, lockRecord, unlockDoubleKit, lockLocalRecord, wirelessAwake, } = dpCodes;
14
15
  const abilityMap = {
15
16
  backHome: "supportBackHome",
@@ -71,26 +72,26 @@ export const openScene = async (options) => {
71
72
  });
72
73
  };
73
74
  export const isSupportBleControl = () => {
74
- const { devInfo, idsByCode, communication } = config;
75
- if (!idsByCode[dpCodes.unlockBle]) {
76
- return false;
77
- }
75
+ const { devInfo, idsByCode } = config;
78
76
  const hasThread = hasCapability(ProductCommunicationType.THREAD);
79
77
  const hasWifi = hasCapability(ProductCommunicationType.WIFI);
80
78
  const hasBle = hasCapability(ProductCommunicationType.BLUETOOTH);
81
79
  if (!hasBle) {
82
80
  return false;
83
81
  }
84
- if (hasThread) {
85
- if (!devInfo?.meta?.["threadWithBLE"]) {
82
+ if (hasWifi && hasBle) {
83
+ if (!hasDp(dpCodes.unlockBle)) {
86
84
  return false;
87
85
  }
88
- }
89
- if (hasWifi && hasBle) {
90
86
  if (devInfo.wifiEnableState === 1) {
91
87
  return true;
92
88
  }
93
89
  }
90
+ if (hasThread && hasBle) {
91
+ if (!devInfo?.meta?.["threadWithBLE"]) {
92
+ return false;
93
+ }
94
+ }
94
95
  const bleControlDp = idsByCode[dpCodes.bleControl];
95
96
  if (bleControlDp) {
96
97
  const reportTIme = devInfo?.dpsTime?.[bleControlDp];
@@ -101,7 +102,7 @@ export const isSupportBleControl = () => {
101
102
  }
102
103
  return getDpValue(dpCodes.bleControl);
103
104
  }
104
- return true;
105
+ return hasBle;
105
106
  };
106
107
  const periodDpMap = [
107
108
  { name: "startHour" },
@@ -281,3 +282,10 @@ export const gotoService = async (params) => {
281
282
  });
282
283
  });
283
284
  };
285
+ export const validatePwdComplexity = async (password) => {
286
+ const encryptedPassword = await encrypt(config.devInfo.devId, password);
287
+ return validatePasswordComplexity({
288
+ devId: config.devInfo.devId,
289
+ password: encryptedPassword,
290
+ });
291
+ };