@ray-js/lock-sdk 1.1.1-beta.11 → 1.1.1-beta.13
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/user.d.ts +0 -20
- package/lib/api/user.js +0 -7
- package/lib/capability.js +1 -1
- package/lib/offline-dps.js +4 -12
- package/lib/other.js +1 -1
- package/lib/state.js +5 -3
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/unlock-method.js +2 -6
- package/lib/sync/user.js +28 -25
- package/lib/unlock-method.js +43 -10
- package/lib/user.d.ts +2 -22
- package/lib/user.js +7 -5
- package/lib/utils/errors.js +1 -0
- package/package.json +1 -1
package/lib/api/user.d.ts
CHANGED
|
@@ -82,26 +82,6 @@ export declare const getUserList: (params: getUserListParams) => Promise<{
|
|
|
82
82
|
user: UserListItem[];
|
|
83
83
|
hasNext: boolean;
|
|
84
84
|
}>;
|
|
85
|
-
interface GetUserDetailParams {
|
|
86
|
-
devId: string;
|
|
87
|
-
userId: string;
|
|
88
|
-
}
|
|
89
|
-
interface UserDetail {
|
|
90
|
-
allOpenType: number[];
|
|
91
|
-
avatarUrl: string;
|
|
92
|
-
lockUserId: number;
|
|
93
|
-
nickName: string;
|
|
94
|
-
phase: number;
|
|
95
|
-
productAttribute: number;
|
|
96
|
-
status: number;
|
|
97
|
-
supportOpenType: number[];
|
|
98
|
-
uid: string;
|
|
99
|
-
userContact: string;
|
|
100
|
-
userId: string;
|
|
101
|
-
userTimeSet: string;
|
|
102
|
-
userType: number;
|
|
103
|
-
}
|
|
104
|
-
export declare const getUserDetail: (params: GetUserDetailParams) => Promise<UserDetail>;
|
|
105
85
|
interface GetUserDetailQueryParams {
|
|
106
86
|
devId: string;
|
|
107
87
|
userId: string;
|
package/lib/api/user.js
CHANGED
|
@@ -38,13 +38,6 @@ export const getUserList = (params) => {
|
|
|
38
38
|
data: params,
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
export const getUserDetail = (params) => {
|
|
42
|
-
return requestApi({
|
|
43
|
-
api: "m.lock.device.member.detail",
|
|
44
|
-
version: "1.0",
|
|
45
|
-
data: params,
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
41
|
export const getUserDetailQuery = (params) => {
|
|
49
42
|
return requestApi({
|
|
50
43
|
api: "m.lock.user.detail.query",
|
package/lib/capability.js
CHANGED
|
@@ -8,7 +8,7 @@ export const isActiveThread = async () => {
|
|
|
8
8
|
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
9
9
|
if (hasThread) {
|
|
10
10
|
const deviceStatus = getDeviceStatus();
|
|
11
|
-
if (deviceStatus.
|
|
11
|
+
if (deviceStatus.onlineTypes.includes("cloud") ||
|
|
12
12
|
config.communication.length === 1) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
package/lib/offline-dps.js
CHANGED
|
@@ -29,14 +29,14 @@ export const checkOfflineDpUpdate = async (dps, isForce) => {
|
|
|
29
29
|
if (!config.supportOfflineDps) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const hasOne = Object.keys(dps).some((code) => cache[code]?.pushStatus === false);
|
|
32
|
+
const hasOne = Object.keys(dps).some((code) => cache?.[code]?.pushStatus === false);
|
|
33
33
|
if (hasOne || isForce) {
|
|
34
34
|
const res = await getOfflineDps(true);
|
|
35
35
|
emitter.emit(OFFLINE_DPS_UPDATE, res);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
export const getOfflineDpCache = (code) => {
|
|
39
|
-
return cache[code];
|
|
39
|
+
return cache?.[code];
|
|
40
40
|
};
|
|
41
41
|
export const publishOfflineDps = async (dps) => {
|
|
42
42
|
const { devInfo, dpSchema } = config;
|
|
@@ -52,20 +52,12 @@ export const publishOfflineDps = async (dps) => {
|
|
|
52
52
|
return acc;
|
|
53
53
|
}, {});
|
|
54
54
|
await publishOfflineDpData(devInfo.devId, dpData);
|
|
55
|
-
|
|
56
|
-
await checkOfflineDpUpdate({}, true);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
}
|
|
55
|
+
checkOfflineDpUpdate({}, true);
|
|
60
56
|
};
|
|
61
57
|
export const clearOfflineDps = async () => {
|
|
62
58
|
const { devInfo } = config;
|
|
63
59
|
await clearOfflineDpData(devInfo.devId);
|
|
64
|
-
|
|
65
|
-
await checkOfflineDpUpdate({}, true);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
}
|
|
60
|
+
checkOfflineDpUpdate({}, true);
|
|
69
61
|
};
|
|
70
62
|
const OFFLINE_DPS_UPDATE = "offline_dps_update";
|
|
71
63
|
export const onOfflineDpsUpdate = (callback) => {
|
package/lib/other.js
CHANGED
|
@@ -260,7 +260,7 @@ export const connectDevice = async () => {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
if (isSupportBleControl()) {
|
|
263
|
-
if (deviceStatus.type === "online" && deviceStatus.
|
|
263
|
+
if (deviceStatus.type === "online" && deviceStatus.onlineTypes.includes("ble")) {
|
|
264
264
|
return true;
|
|
265
265
|
}
|
|
266
266
|
return await connectBle();
|
package/lib/state.js
CHANGED
|
@@ -243,12 +243,14 @@ export const initState = async () => {
|
|
|
243
243
|
fetchDeviceProperties();
|
|
244
244
|
getDeviceAdvancedAbilities();
|
|
245
245
|
syncRemoteSerectKey();
|
|
246
|
+
checkOfflineDpUpdate({}, true).then(() => {
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
syncOfflineDps();
|
|
249
|
+
}, 3000);
|
|
250
|
+
});
|
|
246
251
|
setTimeout(() => {
|
|
247
252
|
syncT0();
|
|
248
253
|
autoSyncUnlockMethod();
|
|
249
|
-
checkOfflineDpUpdate({}, true).then(() => {
|
|
250
|
-
syncOfflineDps();
|
|
251
|
-
});
|
|
252
254
|
}, 2000);
|
|
253
255
|
setTimeout(() => {
|
|
254
256
|
autoSyncTemp();
|
package/lib/sync/offline-dps.js
CHANGED
|
@@ -12,12 +12,7 @@ export const syncOfflineDps = async () => {
|
|
|
12
12
|
if (Object.keys(offlineDps).length) {
|
|
13
13
|
const hasTask = Object.keys(offlineDps).some((code) => offlineDps[code].pushStatus === false);
|
|
14
14
|
if (hasTask) {
|
|
15
|
-
|
|
16
|
-
await clearOfflineDpData(config.devInfo.devId);
|
|
17
|
-
}
|
|
18
|
-
catch (error) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
15
|
+
clearOfflineDpData(config.devInfo.devId);
|
|
21
16
|
const dpData = Object.keys(offlineDps).reduce((acc, code) => {
|
|
22
17
|
acc[code] = offlineDps[code].value;
|
|
23
18
|
return acc;
|
|
@@ -32,11 +32,7 @@ export const syncUnlockMethod = async () => {
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
export const autoSyncUnlockMethod = async () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
await syncUnlockMethod();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
35
|
+
if (syncUnlockMethodFirst) {
|
|
36
|
+
await syncUnlockMethod();
|
|
41
37
|
}
|
|
42
38
|
};
|
package/lib/sync/user.js
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
import { getDeviceStatus } from "../state";
|
|
2
|
-
import
|
|
3
|
-
import config, { hasCapability } from "../config";
|
|
2
|
+
import config from "../config";
|
|
4
3
|
import { getUsersSyncLockData } from "../api/user";
|
|
5
4
|
import { deleteUser } from "../utils/user";
|
|
6
|
-
|
|
5
|
+
import { onAppShow } from "../utils/device";
|
|
6
|
+
import { isUseNearChannel } from "../utils";
|
|
7
|
+
let isSyncing = false;
|
|
8
|
+
onAppShow(() => {
|
|
9
|
+
syncDeleteUsers();
|
|
10
|
+
});
|
|
7
11
|
const syncDeleteUsers = async () => {
|
|
8
12
|
const deviceStatus = getDeviceStatus();
|
|
9
13
|
if (deviceStatus.isWifiActive) {
|
|
10
14
|
return;
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
if (hasThread &&
|
|
14
|
-
(deviceStatus.onlineType === "local" || deviceStatus.onlineType === "cloud")) {
|
|
16
|
+
if (!isUseNearChannel()) {
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
|
-
if (
|
|
19
|
+
if (isSyncing)
|
|
18
20
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
isSyncing = true;
|
|
22
|
+
let count = 0;
|
|
23
|
+
const handleSync = async () => {
|
|
24
|
+
try {
|
|
25
|
+
const { removedUser = [] } = await getUsersSyncLockData(config.devInfo.devId);
|
|
26
|
+
await Promise.all(removedUser.map((item) => deleteUser(item).catch(() => { })));
|
|
27
|
+
isSyncing = false;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e?.innerError?.errorCode === "DEVICE_KEY_NOT_FOUND" && count < 3) {
|
|
31
|
+
count++;
|
|
32
|
+
setTimeout(async () => {
|
|
33
|
+
await handleSync();
|
|
34
|
+
}, 2000);
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
count++;
|
|
31
|
-
setTimeout(async () => {
|
|
32
|
-
await handleSync();
|
|
33
|
-
}, 2000);
|
|
34
|
-
}
|
|
36
|
+
else {
|
|
37
|
+
isSyncing = false;
|
|
35
38
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
handleSync();
|
|
39
42
|
};
|
|
40
43
|
export default syncDeleteUsers;
|
package/lib/unlock-method.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
2
|
import { bindUnlockMethodToUser, bindUnlockMethodToUserByRecord, checkFreeUnlockMethods, createUnlockMethod, removeUnlockMethod, editUnlockMethod, fetchCreatePasswordSN, fetchFreeUnlockMethods, getUnlockMethodInfo, unbindMemberUnlockMethod, } from "./api/lock";
|
|
3
|
-
import { getUserDetail } from "./api/user";
|
|
4
3
|
import config from "./config";
|
|
5
4
|
import dpCodes from "./config/dp-code";
|
|
6
5
|
import { add as addMap, reportAdd as reportAddMap, remove as removeMap, reportRemove as reportRemoveMap, } from "./config/dp-map/unlock-method";
|
|
7
6
|
import { add as addBigMap, reportAdd as reportAddBigMap, remove as removeBigMap, reportRemove as reportRemoveBigMap, } from "./config/dp-map/unlock-method-big";
|
|
8
|
-
import { validConfigDpMap } from "./config/dp-map/common";
|
|
9
7
|
import { getPermanentSetting, getUnlockMethodTypeByDpCode, getUnlockMethodTypeByType, isAdmin, parallelOnly, sleep, } from "./utils";
|
|
10
8
|
import { getError } from "./utils/errors";
|
|
11
9
|
import { publishDps } from "./utils/publishDps";
|
|
12
10
|
import { encrypt } from "./utils/device";
|
|
13
11
|
import emitter from "./utils/event";
|
|
14
|
-
import { DPCHANGE, UNLOCK_METHOD_EVENT } from "./utils/constant";
|
|
12
|
+
import { DPCHANGE, LoopTypes, UNLOCK_METHOD_EVENT } from "./utils/constant";
|
|
15
13
|
import { getFileRemoteUrl, sendPhoneVerifyCode } from "./api";
|
|
16
14
|
import { getUserInfo } from "./user";
|
|
17
15
|
import { getDeviceAdvancedAbilities } from "./capability";
|
|
@@ -22,7 +20,10 @@ const getAddUnlockError = (status) => {
|
|
|
22
20
|
if (status === 0xfe) {
|
|
23
21
|
return getError(1026);
|
|
24
22
|
}
|
|
25
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
...getError(1016),
|
|
25
|
+
devCode: status,
|
|
26
|
+
};
|
|
26
27
|
};
|
|
27
28
|
export const getUnlockMethodDetail = async (id) => {
|
|
28
29
|
const cloudData = await getUnlockMethodInfo({
|
|
@@ -58,8 +59,7 @@ const getUnlockMethodBase = async (type, userId) => {
|
|
|
58
59
|
: dpCodes.unlockMethodCreate;
|
|
59
60
|
const dpId = idsByCode[unlockMethodConfig.code];
|
|
60
61
|
const [user, sn] = await Promise.all([
|
|
61
|
-
|
|
62
|
-
devId: devId,
|
|
62
|
+
getUserInfo({
|
|
63
63
|
userId: userId,
|
|
64
64
|
}),
|
|
65
65
|
fetchCreatePasswordSN({
|
|
@@ -67,10 +67,40 @@ const getUnlockMethodBase = async (type, userId) => {
|
|
|
67
67
|
dpId,
|
|
68
68
|
}),
|
|
69
69
|
]);
|
|
70
|
-
const { userType, lockUserId,
|
|
70
|
+
const { userType, lockUserId, timeScheduleInfo } = user;
|
|
71
71
|
let validConfig;
|
|
72
|
-
if (
|
|
73
|
-
|
|
72
|
+
if (timeScheduleInfo) {
|
|
73
|
+
const { permanent, effectiveTime, expiredTime, scheduleDetails } = timeScheduleInfo;
|
|
74
|
+
if (permanent) {
|
|
75
|
+
validConfig = {
|
|
76
|
+
startTime: Math.floor((effectiveTime || +new Date()) / 1000),
|
|
77
|
+
endTime: Math.floor((expiredTime || 0x72bc9b7f) / 1000),
|
|
78
|
+
loop: LoopTypes.NONE,
|
|
79
|
+
loopConfig: 0,
|
|
80
|
+
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
81
|
+
days: [],
|
|
82
|
+
startHour: 0,
|
|
83
|
+
startMinute: 0,
|
|
84
|
+
endHour: 0,
|
|
85
|
+
endMinute: 0,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
validConfig = {
|
|
90
|
+
startTime: Math.floor((effectiveTime || +new Date()) / 1000),
|
|
91
|
+
endTime: Math.floor((expiredTime || 0x72bc9b7f) / 1000),
|
|
92
|
+
loop: scheduleDetails?.repeat ? LoopTypes.WEEK : LoopTypes.NONE,
|
|
93
|
+
loopConfig: 0,
|
|
94
|
+
weeks: scheduleDetails?.repeat
|
|
95
|
+
? scheduleDetails?.weeks
|
|
96
|
+
: [0, 0, 0, 0, 0, 0, 0],
|
|
97
|
+
days: [],
|
|
98
|
+
startHour: Math.floor((scheduleDetails?.effectiveTime ?? 0) / 60),
|
|
99
|
+
startMinute: (scheduleDetails?.effectiveTime ?? 0) % 60,
|
|
100
|
+
endHour: Math.floor((scheduleDetails?.invalidTime ?? 0) / 60),
|
|
101
|
+
endMinute: (scheduleDetails?.invalidTime ?? 0) % 60,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
74
104
|
}
|
|
75
105
|
else {
|
|
76
106
|
validConfig = getPermanentSetting();
|
|
@@ -311,7 +341,8 @@ const handleAddReport = async (dps) => {
|
|
|
311
341
|
};
|
|
312
342
|
}
|
|
313
343
|
}
|
|
314
|
-
catch {
|
|
344
|
+
catch (err) {
|
|
345
|
+
console.warn("AddUnlockMethod failed", err);
|
|
315
346
|
eventData = {
|
|
316
347
|
stage: "fail",
|
|
317
348
|
type,
|
|
@@ -350,6 +381,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
350
381
|
const res = await publishDps({
|
|
351
382
|
[addDpCode]: dpUtils.format(dpData, addDpMap),
|
|
352
383
|
}, {
|
|
384
|
+
timeout: params.timeout,
|
|
353
385
|
checkReport: (dpData) => {
|
|
354
386
|
if (typeof dpData[addDpCode] !== "undefined") {
|
|
355
387
|
const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
|
|
@@ -375,6 +407,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
375
407
|
});
|
|
376
408
|
if (res.stage === 0) {
|
|
377
409
|
monitoringAddReport({
|
|
410
|
+
timeout: params.timeout,
|
|
378
411
|
unlockMethodConfig,
|
|
379
412
|
total: res.total,
|
|
380
413
|
dpCode: addDpCode,
|
package/lib/user.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EffectiveConfig,
|
|
1
|
+
import { EffectiveConfig, UserInfo } from "./interface";
|
|
2
2
|
interface getUsersParams {
|
|
3
3
|
page?: number;
|
|
4
4
|
pageSize?: number;
|
|
@@ -11,27 +11,7 @@ export declare const getUsers: (params?: getUsersParams) => Promise<{
|
|
|
11
11
|
interface getUserInfoParams {
|
|
12
12
|
userId: string;
|
|
13
13
|
}
|
|
14
|
-
export declare const getUserInfo: (params: getUserInfoParams) => Promise<
|
|
15
|
-
timeScheduleInfo: any;
|
|
16
|
-
unlockDetails: {
|
|
17
|
-
count: number;
|
|
18
|
-
dpCode: string;
|
|
19
|
-
dpId: number;
|
|
20
|
-
type: import("./interface").UnlockMethodType;
|
|
21
|
-
unlockList: UnlockMethodBaseInfo[];
|
|
22
|
-
}[];
|
|
23
|
-
isAccountUser: boolean;
|
|
24
|
-
userId: string;
|
|
25
|
-
lockUserId: number;
|
|
26
|
-
avatarUrl: string;
|
|
27
|
-
backHomeNotifyAttr: number;
|
|
28
|
-
effectiveFlag: number;
|
|
29
|
-
nickName: string;
|
|
30
|
-
offlineUnlock: boolean;
|
|
31
|
-
userContact: string;
|
|
32
|
-
userType: 10 | 20 | 30 | 40 | 50;
|
|
33
|
-
userListType: "panel_user" | "group_user";
|
|
34
|
-
}>;
|
|
14
|
+
export declare const getUserInfo: (params: getUserInfoParams) => Promise<UserInfo>;
|
|
35
15
|
interface updateUserLimitTimeParams {
|
|
36
16
|
userId: string;
|
|
37
17
|
lockUserId: number;
|
package/lib/user.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getUserDetailQuery, getUserList } from "./api/user";
|
|
2
2
|
import config from "./config";
|
|
3
3
|
import { update as updateMap, reportUpdate as reportUpdateMap, } from "./config/dp-map/unlock-method";
|
|
4
4
|
import { update as updateMapBig, reportUpdate as reportUpdateMapBig, } from "./config/dp-map/unlock-method-big";
|
|
@@ -118,8 +118,11 @@ export const updateUserLimitTime = async (params) => {
|
|
|
118
118
|
if (!permanent) {
|
|
119
119
|
validateEffectiveConfig(effective);
|
|
120
120
|
}
|
|
121
|
-
const
|
|
122
|
-
|
|
121
|
+
const currentUser = await getCurrentUser();
|
|
122
|
+
if (!isAdmin(currentUser.userType)) {
|
|
123
|
+
throw getError(1069);
|
|
124
|
+
}
|
|
125
|
+
const { userType } = await getUserInfo({
|
|
123
126
|
userId,
|
|
124
127
|
});
|
|
125
128
|
if (isAdmin(userType)) {
|
|
@@ -276,8 +279,7 @@ export const removeUser = async (userId) => {
|
|
|
276
279
|
if (!config.supportBigData) {
|
|
277
280
|
throw getError(1060);
|
|
278
281
|
}
|
|
279
|
-
const res = await
|
|
280
|
-
devId: config.devInfo.devId,
|
|
282
|
+
const res = await getUserInfo({
|
|
281
283
|
userId,
|
|
282
284
|
});
|
|
283
285
|
if (isUseNearChannel()) {
|
package/lib/utils/errors.js
CHANGED
|
@@ -67,6 +67,7 @@ const errors = {
|
|
|
67
67
|
1066: "Phone number cannot be empty",
|
|
68
68
|
1067: "Password limit reached within this period",
|
|
69
69
|
1068: "There is already a member with the same name",
|
|
70
|
+
1069: "No permission to modify member validity",
|
|
70
71
|
};
|
|
71
72
|
export const getError = (code, ...places) => {
|
|
72
73
|
if (errors[code]) {
|