@ray-js/lock-sdk 1.1.1-beta.2 → 1.1.1-beta.20
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/index.d.ts +8 -0
- package/lib/api/index.js +10 -0
- package/lib/api/lock.d.ts +5 -0
- package/lib/api/lock.js +7 -0
- package/lib/api/user.d.ts +3 -17
- package/lib/api/user.js +5 -5
- package/lib/capability.js +45 -19
- package/lib/config/dp-map/common.js +1 -1
- package/lib/config/dp-map/unlock-method-big.js +1 -1
- package/lib/config/dp-map/unlock-method.d.ts +4 -4
- package/lib/config/dp-map/unlock-method.js +1 -1
- package/lib/config/index.d.ts +2 -1
- package/lib/config/index.js +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +7 -2
- package/lib/interface.d.ts +13 -1
- package/lib/log.js +16 -4
- package/lib/offline-dps.js +4 -12
- package/lib/open/ble-dedicated-dp.d.ts +4 -0
- package/lib/open/ble-dedicated-dp.js +148 -0
- package/lib/open/ble-remote-no-dp-key.d.ts +4 -0
- package/lib/open/ble-remote-no-dp-key.js +69 -0
- package/lib/open/report-status.d.ts +1 -0
- package/lib/open/report-status.js +23 -0
- package/lib/open.js +10 -10
- package/lib/other.d.ts +1 -0
- package/lib/other.js +10 -2
- package/lib/state.js +25 -15
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/temp.js +1 -1
- package/lib/sync/unlock-method.js +16 -16
- package/lib/sync/user.js +24 -25
- package/lib/temporary.js +15 -33
- package/lib/unlock-method.d.ts +3 -1
- package/lib/unlock-method.js +103 -18
- package/lib/user.d.ts +2 -2
- package/lib/user.js +81 -71
- package/lib/utils/device.d.ts +1 -0
- package/lib/utils/device.js +6 -0
- package/lib/utils/errors.d.ts +1 -0
- package/lib/utils/errors.js +37 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +15 -12
- package/package.json +1 -1
package/lib/unlock-method.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
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";
|
|
15
|
-
import { sendPhoneVerifyCode } from "./api";
|
|
12
|
+
import { DPCHANGE, LoopTypes, UNLOCK_METHOD_EVENT } from "./utils/constant";
|
|
13
|
+
import { getFileRemoteUrl, sendPhoneVerifyCode } from "./api";
|
|
16
14
|
import { getUserInfo } from "./user";
|
|
15
|
+
import { getDeviceAdvancedAbilities } from "./capability";
|
|
17
16
|
const getAddUnlockError = (status) => {
|
|
18
17
|
if (status >= 0 && status <= 10) {
|
|
19
18
|
return getError(1015 + status);
|
|
@@ -21,7 +20,10 @@ const getAddUnlockError = (status) => {
|
|
|
21
20
|
if (status === 0xfe) {
|
|
22
21
|
return getError(1026);
|
|
23
22
|
}
|
|
24
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
...getError(1016),
|
|
25
|
+
devCode: status,
|
|
26
|
+
};
|
|
25
27
|
};
|
|
26
28
|
export const getUnlockMethodDetail = async (id) => {
|
|
27
29
|
const cloudData = await getUnlockMethodInfo({
|
|
@@ -30,6 +32,7 @@ export const getUnlockMethodDetail = async (id) => {
|
|
|
30
32
|
});
|
|
31
33
|
const detail = {
|
|
32
34
|
isBound: cloudData.allocateFlag === 1,
|
|
35
|
+
type: getUnlockMethodTypeByDpCode(config.codesById[Number(cloudData.opmode)])?.type,
|
|
33
36
|
phase: cloudData.phase,
|
|
34
37
|
dpId: Number(cloudData.opmode),
|
|
35
38
|
isSpecial: cloudData.unlockAttr === 1,
|
|
@@ -41,6 +44,7 @@ export const getUnlockMethodDetail = async (id) => {
|
|
|
41
44
|
userType: cloudData.userType,
|
|
42
45
|
notifyInfo: {
|
|
43
46
|
appSend: !!cloudData.notifyInfo?.appSend,
|
|
47
|
+
msgSend: !!cloudData.notifyInfo?.msgPhone,
|
|
44
48
|
msgPhone: cloudData.notifyInfo?.msgPhone,
|
|
45
49
|
countryCode: cloudData.notifyInfo?.countryCode,
|
|
46
50
|
},
|
|
@@ -48,15 +52,14 @@ export const getUnlockMethodDetail = async (id) => {
|
|
|
48
52
|
return detail;
|
|
49
53
|
};
|
|
50
54
|
const getUnlockMethodBase = async (type, userId) => {
|
|
51
|
-
const { idsByCode, devInfo: { devId }, supportBigData,
|
|
55
|
+
const { idsByCode, devInfo: { devId }, supportBigData, } = config;
|
|
52
56
|
const unlockMethodConfig = getUnlockMethodTypeByType(type);
|
|
53
57
|
const addDpCode = supportBigData
|
|
54
58
|
? dpCodes.unlockMethodCreateW
|
|
55
59
|
: dpCodes.unlockMethodCreate;
|
|
56
60
|
const dpId = idsByCode[unlockMethodConfig.code];
|
|
57
61
|
const [user, sn] = await Promise.all([
|
|
58
|
-
|
|
59
|
-
devId: devId,
|
|
62
|
+
getUserInfo({
|
|
60
63
|
userId: userId,
|
|
61
64
|
}),
|
|
62
65
|
fetchCreatePasswordSN({
|
|
@@ -64,10 +67,40 @@ const getUnlockMethodBase = async (type, userId) => {
|
|
|
64
67
|
dpId,
|
|
65
68
|
}),
|
|
66
69
|
]);
|
|
67
|
-
const { userType, lockUserId,
|
|
70
|
+
const { userType, lockUserId, timeScheduleInfo } = user;
|
|
68
71
|
let validConfig;
|
|
69
|
-
if (
|
|
70
|
-
|
|
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
|
+
}
|
|
71
104
|
}
|
|
72
105
|
else {
|
|
73
106
|
validConfig = getPermanentSetting();
|
|
@@ -104,11 +137,14 @@ const checkSpecial = (isSpecial, params, oldSetting) => {
|
|
|
104
137
|
if (!supportedPhone) {
|
|
105
138
|
throw getError(1057);
|
|
106
139
|
}
|
|
107
|
-
else if (!params?.
|
|
140
|
+
else if (!params?.msgSend) {
|
|
108
141
|
throw getError(1058);
|
|
109
142
|
}
|
|
110
143
|
}
|
|
111
|
-
if (supportedPhone && params?.
|
|
144
|
+
if (supportedPhone && params?.msgSend) {
|
|
145
|
+
if (!params.msgPhone) {
|
|
146
|
+
throw getError(1066);
|
|
147
|
+
}
|
|
112
148
|
if (!params.countryCode) {
|
|
113
149
|
throw getError(1056);
|
|
114
150
|
}
|
|
@@ -121,9 +157,9 @@ const checkSpecial = (isSpecial, params, oldSetting) => {
|
|
|
121
157
|
unlockAttr: isSpecial ? 1 : 0,
|
|
122
158
|
notifyInfo: {
|
|
123
159
|
appSend: !!params?.appSend,
|
|
124
|
-
msgPhone: supportedPhone ? params?.msgPhone : undefined,
|
|
125
|
-
countryCode: supportedPhone ? params?.countryCode : undefined,
|
|
126
|
-
msgPhoneVerifyCode: supportedPhone ? params?.verifyCode : undefined,
|
|
160
|
+
msgPhone: supportedPhone && params?.msgSend ? params?.msgPhone : undefined,
|
|
161
|
+
countryCode: supportedPhone && params?.msgSend ? params?.countryCode : undefined,
|
|
162
|
+
msgPhoneVerifyCode: supportedPhone && params?.msgSend ? params?.verifyCode : undefined,
|
|
127
163
|
},
|
|
128
164
|
};
|
|
129
165
|
};
|
|
@@ -305,7 +341,8 @@ const handleAddReport = async (dps) => {
|
|
|
305
341
|
};
|
|
306
342
|
}
|
|
307
343
|
}
|
|
308
|
-
catch {
|
|
344
|
+
catch (err) {
|
|
345
|
+
console.warn("AddUnlockMethod failed", err);
|
|
309
346
|
eventData = {
|
|
310
347
|
stage: "fail",
|
|
311
348
|
type,
|
|
@@ -344,6 +381,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
344
381
|
const res = await publishDps({
|
|
345
382
|
[addDpCode]: dpUtils.format(dpData, addDpMap),
|
|
346
383
|
}, {
|
|
384
|
+
timeout: params.timeout,
|
|
347
385
|
checkReport: (dpData) => {
|
|
348
386
|
if (typeof dpData[addDpCode] !== "undefined") {
|
|
349
387
|
const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
|
|
@@ -369,6 +407,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
369
407
|
});
|
|
370
408
|
if (res.stage === 0) {
|
|
371
409
|
monitoringAddReport({
|
|
410
|
+
timeout: params.timeout,
|
|
372
411
|
unlockMethodConfig,
|
|
373
412
|
total: res.total,
|
|
374
413
|
dpCode: addDpCode,
|
|
@@ -440,7 +479,7 @@ export const deleteUnlockMethod = parallelOnly(async (id) => {
|
|
|
440
479
|
admin: isAdmin(userType),
|
|
441
480
|
memberId: lockUserId,
|
|
442
481
|
unlockId,
|
|
443
|
-
|
|
482
|
+
operation: 1,
|
|
444
483
|
};
|
|
445
484
|
const res = await publishDps({
|
|
446
485
|
[removeDPCode]: dpUtils.format(dpData, (config.supportBigData ? removeBigMap : removeMap)),
|
|
@@ -560,3 +599,49 @@ export const onAddUnlockMethod = (listener) => {
|
|
|
560
599
|
export const offAddUnlockMethod = (listener) => {
|
|
561
600
|
emitter.off(UNLOCK_METHOD_EVENT, listener);
|
|
562
601
|
};
|
|
602
|
+
const guileTypeMap = {
|
|
603
|
+
card: ["addCard", "addCardPic"],
|
|
604
|
+
finger: ["addFingerprint", "addFingerprintPic"],
|
|
605
|
+
face: ["addFace", "addFacePic"],
|
|
606
|
+
fingerVein: ["addFingervein", "addFingerveinPic"],
|
|
607
|
+
hand: ["addPalmvein", "addPalmveinPic"],
|
|
608
|
+
eye: ["addIris", "addIrisPic"],
|
|
609
|
+
};
|
|
610
|
+
export const getUnlockGuide = async (type) => {
|
|
611
|
+
if (type === "password") {
|
|
612
|
+
return null;
|
|
613
|
+
}
|
|
614
|
+
const { unlockGuide } = await getDeviceAdvancedAbilities();
|
|
615
|
+
if (unlockGuide.support) {
|
|
616
|
+
const [videoKey, picKey] = guileTypeMap[type] || ["", ""];
|
|
617
|
+
const resources = [];
|
|
618
|
+
let videoUrlPath = "";
|
|
619
|
+
let picUrlPath = "";
|
|
620
|
+
if (unlockGuide.config[picKey]) {
|
|
621
|
+
picUrlPath = unlockGuide.config[picKey].url;
|
|
622
|
+
resources.push({
|
|
623
|
+
objectKey: picUrlPath,
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
if (unlockGuide.config[videoKey]) {
|
|
627
|
+
videoUrlPath = unlockGuide.config[videoKey].url;
|
|
628
|
+
resources.push({
|
|
629
|
+
objectKey: videoUrlPath,
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
if (resources.length === 0) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
const { signedUrls } = await getFileRemoteUrl({
|
|
636
|
+
biz: "hulk_video_tutorial_video",
|
|
637
|
+
resources,
|
|
638
|
+
});
|
|
639
|
+
const expireTime = Date.now() + 30 * 60 * 1000;
|
|
640
|
+
return {
|
|
641
|
+
videoUrl: signedUrls[videoUrlPath],
|
|
642
|
+
picUrl: signedUrls[picUrlPath],
|
|
643
|
+
expireTime,
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
return null;
|
|
647
|
+
};
|
package/lib/user.d.ts
CHANGED
|
@@ -19,12 +19,12 @@ interface updateUserLimitTimeParams {
|
|
|
19
19
|
effective?: EffectiveConfig;
|
|
20
20
|
offlineUnlock?: boolean;
|
|
21
21
|
}
|
|
22
|
-
export declare const updateUserLimitTime: (params: updateUserLimitTimeParams) => Promise<
|
|
22
|
+
export declare const updateUserLimitTime: (params: updateUserLimitTimeParams) => Promise<true | undefined>;
|
|
23
23
|
export declare const openAddFamilyUser: () => Promise<unknown>;
|
|
24
24
|
export declare const openFamilyUserDetail: (userId: string) => Promise<undefined>;
|
|
25
25
|
interface AddUserParams {
|
|
26
26
|
name: string;
|
|
27
27
|
}
|
|
28
|
-
export declare const addUser: (params: AddUserParams) => Promise<
|
|
28
|
+
export declare const addUser: (params: AddUserParams) => Promise<void>;
|
|
29
29
|
export declare const removeUser: (userId: string) => Promise<void>;
|
|
30
30
|
export {};
|
package/lib/user.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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";
|
|
5
5
|
import { publishDps } from "./utils/publishDps";
|
|
6
6
|
import dpCodes from "./config/dp-code";
|
|
7
7
|
import DpUtils from "@ray-js/tuya-dp-transform";
|
|
8
|
-
import { getError } from "./utils/errors";
|
|
8
|
+
import { getError, handleCloudError } from "./utils/errors";
|
|
9
9
|
import { updateUserTimeSchedule, addNormalUser, removeNormalUser, } from "./api/user";
|
|
10
10
|
import { validConfigDpMap } from "./config/dp-map/common";
|
|
11
11
|
import { formatTimestampToMilliseconds, formatWeek, getPermanentSetting, isAdmin, isUseNearChannel, parseWeek, unlockMethodConfigs, validateEffectiveConfig, } from "./utils";
|
|
@@ -14,58 +14,61 @@ import { LoopTypes } from "./utils/constant";
|
|
|
14
14
|
import { getCurrentUser } from "./state";
|
|
15
15
|
import { deleteUser } from "./utils/user";
|
|
16
16
|
import { UserType } from "./constant";
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
unlockId: unlockItem.unlockId.split("-")[1],
|
|
42
|
-
unlockName: unlockItem.unlockName,
|
|
43
|
-
id: unlockItem.opModeId,
|
|
44
|
-
isBound: unlockItem.allocateFlag === 1,
|
|
45
|
-
photoUnlock: unlockItem.photoUnlock,
|
|
46
|
-
isSpecial: unlockItem.unlockAttr === 1,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
const unlockMethodConfig = unlockMethodConfigs.find((item) => item.code === detail.dpCode);
|
|
17
|
+
const handleUserDetail = (user) => {
|
|
18
|
+
const { timeScheduleInfo, unlockDetail, ...rest } = user;
|
|
19
|
+
let scheduleInfo = {
|
|
20
|
+
permanent: true,
|
|
21
|
+
};
|
|
22
|
+
if (!timeScheduleInfo.permanent &&
|
|
23
|
+
timeScheduleInfo.scheduleDetails &&
|
|
24
|
+
timeScheduleInfo.scheduleDetails.length > 0) {
|
|
25
|
+
Object.assign(scheduleInfo, {
|
|
26
|
+
permanent: false,
|
|
27
|
+
effectiveTime: formatTimestampToMilliseconds(timeScheduleInfo.effectiveTime || 0),
|
|
28
|
+
expiredTime: formatTimestampToMilliseconds(timeScheduleInfo.expiredTime || 0),
|
|
29
|
+
scheduleDetails: {
|
|
30
|
+
repeat: !timeScheduleInfo.scheduleDetails[0].allDay,
|
|
31
|
+
effectiveTime: timeScheduleInfo.scheduleDetails[0].effectiveTime,
|
|
32
|
+
invalidTime: timeScheduleInfo.scheduleDetails[0].invalidTime,
|
|
33
|
+
timeZoneId: timeScheduleInfo.scheduleDetails[0].timeZoneId,
|
|
34
|
+
weeks: parseWeek(timeScheduleInfo.scheduleDetails[0].workingDay),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
let unlockDetails = unlockDetail.map((detail) => {
|
|
39
|
+
const unlockList = detail.unlockList.map((unlockItem) => {
|
|
50
40
|
return {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
41
|
+
unlockId: +unlockItem.unlockId.split("-")[1],
|
|
42
|
+
unlockName: unlockItem.unlockName,
|
|
43
|
+
id: unlockItem.opModeId,
|
|
44
|
+
isBound: unlockItem.allocateFlag === 1,
|
|
45
|
+
photoUnlock: unlockItem.photoUnlock,
|
|
46
|
+
isSpecial: unlockItem.unlockAttr === 1,
|
|
56
47
|
};
|
|
57
48
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
const unlockMethodConfig = unlockMethodConfigs.find((item) => item.code === detail.dpCode);
|
|
50
|
+
return {
|
|
51
|
+
count: unlockList.length,
|
|
52
|
+
dpCode: detail.dpCode,
|
|
53
|
+
dpId: detail.dpId,
|
|
54
|
+
type: unlockMethodConfig.type,
|
|
55
|
+
unlockList,
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
...rest,
|
|
60
|
+
timeScheduleInfo: scheduleInfo,
|
|
61
|
+
unlockDetails,
|
|
62
|
+
isAccountUser: user.userListType === "group_user",
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
const concactUserList = (list, result) => {
|
|
66
|
+
return list.reduce((acc, item) => {
|
|
67
|
+
acc.push(handleUserDetail(item));
|
|
64
68
|
return acc;
|
|
65
69
|
}, result);
|
|
66
70
|
};
|
|
67
|
-
|
|
68
|
-
const { page = 1, pageSize = 10, keyword = "" } = params || {};
|
|
71
|
+
const getUserDpCodes = async () => {
|
|
69
72
|
const currentUser = await getCurrentUser();
|
|
70
73
|
const dps = [];
|
|
71
74
|
if (currentUser.allOpenDps) {
|
|
@@ -77,6 +80,11 @@ export const getUsers = async (params) => {
|
|
|
77
80
|
return acc;
|
|
78
81
|
}, dps);
|
|
79
82
|
}
|
|
83
|
+
return dps;
|
|
84
|
+
};
|
|
85
|
+
export const getUsers = async (params) => {
|
|
86
|
+
const { page = 1, pageSize = 10, keyword = "" } = params || {};
|
|
87
|
+
const dps = await getUserDpCodes();
|
|
80
88
|
const res = await getUserList({
|
|
81
89
|
dpCodes: dps.join(","),
|
|
82
90
|
devId: config.devInfo.devId,
|
|
@@ -97,26 +105,24 @@ export const getUsers = async (params) => {
|
|
|
97
105
|
};
|
|
98
106
|
};
|
|
99
107
|
export const getUserInfo = async (params) => {
|
|
100
|
-
const
|
|
108
|
+
const currentUser = await getCurrentUser();
|
|
109
|
+
const res = await getUserDetailQuery({
|
|
101
110
|
devId: config.devInfo.devId,
|
|
102
111
|
userId: params.userId,
|
|
112
|
+
dpIds: currentUser.allOpenDps,
|
|
103
113
|
});
|
|
104
|
-
|
|
105
|
-
keyword: user.nickName,
|
|
106
|
-
});
|
|
107
|
-
const res = data.list.find((item) => item.userId === params.userId);
|
|
108
|
-
if (res) {
|
|
109
|
-
return res;
|
|
110
|
-
}
|
|
111
|
-
throw getError(1048);
|
|
114
|
+
return handleUserDetail(res);
|
|
112
115
|
};
|
|
113
116
|
export const updateUserLimitTime = async (params) => {
|
|
114
117
|
const { userId, lockUserId, permanent, effective } = params;
|
|
115
118
|
if (!permanent) {
|
|
116
119
|
validateEffectiveConfig(effective);
|
|
117
120
|
}
|
|
118
|
-
const
|
|
119
|
-
|
|
121
|
+
const currentUser = await getCurrentUser();
|
|
122
|
+
if (!isAdmin(currentUser.userType)) {
|
|
123
|
+
throw getError(1069);
|
|
124
|
+
}
|
|
125
|
+
const { userType } = await getUserInfo({
|
|
120
126
|
userId,
|
|
121
127
|
});
|
|
122
128
|
if (isAdmin(userType)) {
|
|
@@ -198,11 +204,11 @@ export const updateUserLimitTime = async (params) => {
|
|
|
198
204
|
],
|
|
199
205
|
},
|
|
200
206
|
});
|
|
207
|
+
return true;
|
|
201
208
|
}
|
|
202
209
|
catch (e) {
|
|
203
|
-
|
|
210
|
+
handleCloudError(e, 1012);
|
|
204
211
|
}
|
|
205
|
-
return true;
|
|
206
212
|
};
|
|
207
213
|
export const openAddFamilyUser = async () => {
|
|
208
214
|
const homeInfo = await getCurrentHomeInfo();
|
|
@@ -241,11 +247,8 @@ export const openFamilyUserDetail = async (userId) => {
|
|
|
241
247
|
const url = `tuyaSmart://member_info?homeId=${homeId}&memberId=${userId}&role=${role}`;
|
|
242
248
|
ty.router({
|
|
243
249
|
url: url,
|
|
244
|
-
success: (d) => {
|
|
245
|
-
console.log("openFamilyUserDetail success");
|
|
246
|
-
},
|
|
247
250
|
fail: (e) => {
|
|
248
|
-
console.
|
|
251
|
+
console.error("openFamilyUserDetail fail", e);
|
|
249
252
|
},
|
|
250
253
|
});
|
|
251
254
|
return;
|
|
@@ -259,17 +262,24 @@ export const addUser = async (params) => {
|
|
|
259
262
|
if (!params.name) {
|
|
260
263
|
throw getError(1009, "name");
|
|
261
264
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
try {
|
|
266
|
+
await addNormalUser({
|
|
267
|
+
devId: config.devInfo.devId,
|
|
268
|
+
name: params.name,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
if (e?.innerError?.errorCode === "DEFINITION_PARAM_NAME_REPEAT") {
|
|
273
|
+
throw getError(1068);
|
|
274
|
+
}
|
|
275
|
+
throw e;
|
|
276
|
+
}
|
|
266
277
|
};
|
|
267
278
|
export const removeUser = async (userId) => {
|
|
268
279
|
if (!config.supportBigData) {
|
|
269
280
|
throw getError(1060);
|
|
270
281
|
}
|
|
271
|
-
const res = await
|
|
272
|
-
devId: config.devInfo.devId,
|
|
282
|
+
const res = await getUserInfo({
|
|
273
283
|
userId,
|
|
274
284
|
});
|
|
275
285
|
if (isUseNearChannel()) {
|
package/lib/utils/device.d.ts
CHANGED
|
@@ -176,4 +176,5 @@ export declare const onAppShow: (cb: () => void) => void;
|
|
|
176
176
|
export declare const offAppShow: (cb: () => void) => void;
|
|
177
177
|
export declare const onAppHide: (cb: () => void) => void;
|
|
178
178
|
export declare const offAppHide: (cb: () => void) => void;
|
|
179
|
+
export declare const trackEvent: (event: string, data: Record<string, any>) => void;
|
|
179
180
|
export {};
|
package/lib/utils/device.js
CHANGED
package/lib/utils/errors.d.ts
CHANGED
package/lib/utils/errors.js
CHANGED
|
@@ -64,6 +64,10 @@ const errors = {
|
|
|
64
64
|
1063: "Password length only supports 4-6 digits",
|
|
65
65
|
1064: "Non-thread device, not supported in LAN connection to open and close locks",
|
|
66
66
|
1065: "Cloud side has been deleted, but device side synchronization deletion failed",
|
|
67
|
+
1066: "Phone number cannot be empty",
|
|
68
|
+
1067: "Password limit reached within this period",
|
|
69
|
+
1068: "There is already a member with the same name",
|
|
70
|
+
1069: "No permission to modify member validity",
|
|
67
71
|
};
|
|
68
72
|
export const getError = (code, ...places) => {
|
|
69
73
|
if (errors[code]) {
|
|
@@ -83,3 +87,36 @@ export const getError = (code, ...places) => {
|
|
|
83
87
|
errorMsg: "unknow error",
|
|
84
88
|
};
|
|
85
89
|
};
|
|
90
|
+
export const handleCloudError = (err, code) => {
|
|
91
|
+
if (err?.innerError?.errorCode) {
|
|
92
|
+
let error;
|
|
93
|
+
switch (err.innerError.errorCode) {
|
|
94
|
+
case "USER_PWD_ALREADY_EXIST":
|
|
95
|
+
error = getError(1037);
|
|
96
|
+
break;
|
|
97
|
+
case "LOCK_PWD_NAME_REPEAT":
|
|
98
|
+
case "OFFLINE_PWD_NAME_REPEAT":
|
|
99
|
+
error = getError(1038);
|
|
100
|
+
break;
|
|
101
|
+
case "START_END_DATE_NOT_RIGHT":
|
|
102
|
+
error = getError(1039);
|
|
103
|
+
break;
|
|
104
|
+
case "RECORD_NOT_EXIST":
|
|
105
|
+
error = getError(1040);
|
|
106
|
+
break;
|
|
107
|
+
case "OFFLINE_PWD_EXAUST_IN_PERIOD":
|
|
108
|
+
error = getError(1067);
|
|
109
|
+
break;
|
|
110
|
+
default:
|
|
111
|
+
}
|
|
112
|
+
if (error) {
|
|
113
|
+
error.errorMsg = err.innerError.errorMsg;
|
|
114
|
+
error.innerError = err.innerError;
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (code) {
|
|
119
|
+
throw getError(code);
|
|
120
|
+
}
|
|
121
|
+
throw err;
|
|
122
|
+
};
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -107,7 +107,7 @@ export declare const parseOfflinePassword: (value: string) => string;
|
|
|
107
107
|
export declare const formatTimestampToMilliseconds: (timestamp: number) => number;
|
|
108
108
|
export declare const unlockMethodConfigs: UnlockMethodConfig[];
|
|
109
109
|
export declare const getUnlockMethodTypeByDpCode: (dpCode: string) => UnlockMethodConfig;
|
|
110
|
-
export declare const getUnlockMethodTypeById: (id: number) => UnlockMethodConfig;
|
|
110
|
+
export declare const getUnlockMethodTypeById: (id: number | string) => UnlockMethodConfig;
|
|
111
111
|
export declare const getUnlockMethodTypeByType: (type: string) => UnlockMethodConfig;
|
|
112
112
|
export declare const parallelMerge: <T extends (...args: any[]) => Promise<any>>(cb: T) => (...args: Parameters<T>) => ReturnType<T>;
|
|
113
113
|
export declare const parallelOnly: <T extends (...args: any[]) => Promise<any>>(cb: T) => (...args: Parameters<T>) => ReturnType<T>;
|
package/lib/utils/index.js
CHANGED
|
@@ -49,7 +49,8 @@ export function getCapabilities(capability) {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
export const formatWeek = (value) => {
|
|
52
|
-
|
|
52
|
+
const temp = value.slice(0, 7);
|
|
53
|
+
return parseInt(temp.reverse().join(""), 2);
|
|
53
54
|
};
|
|
54
55
|
export const parseWeek = (value) => {
|
|
55
56
|
return Number(value)
|
|
@@ -258,18 +259,20 @@ onBackgroundFetchData(preFetchKeys, (res) => {
|
|
|
258
259
|
});
|
|
259
260
|
});
|
|
260
261
|
export const getDataWithPreFetch = async (key, apiCb) => {
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
result
|
|
268
|
-
|
|
269
|
-
|
|
262
|
+
if (config.preFetch) {
|
|
263
|
+
if (preFetchData[key]) {
|
|
264
|
+
return preFetchData[key];
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
const result = await getBackgroundFetchData([key]);
|
|
268
|
+
if (result &&
|
|
269
|
+
result.fetchedData[key] &&
|
|
270
|
+
result.fetchedData[key].fetchedData) {
|
|
271
|
+
return result.fetchedData[key].fetchedData;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
270
275
|
}
|
|
271
|
-
}
|
|
272
|
-
catch {
|
|
273
276
|
}
|
|
274
277
|
return apiCb();
|
|
275
278
|
};
|