@ray-js/lock-sdk 1.1.1-beta.9 → 1.1.2-beta.1
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/log.d.ts +10 -0
- package/lib/api/user.d.ts +0 -20
- package/lib/api/user.js +2 -9
- package/lib/capability.js +1 -1
- package/lib/config/dp-code/index.d.ts +1 -0
- package/lib/config/dp-code/index.js +2 -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/index.d.ts +2 -1
- package/lib/index.js +6 -2
- package/lib/interface.d.ts +7 -0
- package/lib/log.js +19 -2
- 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 +12 -1
- package/lib/other.js +1 -1
- package/lib/state.js +23 -9
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/unlock-method.js +16 -16
- package/lib/sync/user.js +49 -21
- package/lib/temporary.js +14 -32
- package/lib/unlock-method.js +46 -11
- package/lib/user.d.ts +4 -24
- package/lib/user.js +47 -37
- package/lib/utils/device.d.ts +1 -0
- package/lib/utils/device.js +18 -0
- package/lib/utils/errors.d.ts +1 -0
- package/lib/utils/errors.js +36 -0
- package/lib/utils/index.js +1 -2
- package/lib/utils/publishDps.js +6 -1
- package/package.json +1 -1
package/lib/state.js
CHANGED
|
@@ -38,19 +38,21 @@ const updateOnlineType = async () => {
|
|
|
38
38
|
updateDeviceStatus();
|
|
39
39
|
};
|
|
40
40
|
export const getDeviceStatus = () => {
|
|
41
|
-
const { onlineType, devInfo: { isCloudOnline, isOnline, wifiEnableState }, } = config;
|
|
41
|
+
const { onlineType, devInfo: { isCloudOnline, isOnline, wifiEnableState, isMatter }, } = config;
|
|
42
|
+
const supportWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
43
|
+
const supportBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
44
|
+
const supportThread = hasCapability(ProductCommunicationType.THREAD);
|
|
42
45
|
const status = {
|
|
43
46
|
type: isOnline ? "online" : "offline",
|
|
44
47
|
connectEnable: false,
|
|
45
48
|
onlineType: "unknown",
|
|
46
49
|
onlineTypes: [],
|
|
47
50
|
isWifiActive: wifiEnableState !== 1,
|
|
51
|
+
isWifiMatter: !!isMatter && supportWifi,
|
|
48
52
|
};
|
|
49
53
|
const isBleOnline = isOnlineByType(onlineType, 2);
|
|
54
|
+
const isMatterLocal = isOnlineByType(onlineType, 8);
|
|
50
55
|
const isLocalOnline = !isCloudOnline && isOnlineByType(onlineType, 1);
|
|
51
|
-
const supportWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
52
|
-
const supportBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
53
|
-
const supportThread = hasCapability(ProductCommunicationType.THREAD);
|
|
54
56
|
const hasWirelessAwakeDp = hasDp(dpCodes.wirelessAwake);
|
|
55
57
|
const wirelessAwake = getDpValue(dpCodes.wirelessAwake);
|
|
56
58
|
status.connectEnable = isSupportBleControl() && !isOnline;
|
|
@@ -76,9 +78,14 @@ export const getDeviceStatus = () => {
|
|
|
76
78
|
status.onlineTypes.push("cloud");
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
if (isLocalOnline) {
|
|
80
82
|
status.onlineTypes.push("local");
|
|
81
83
|
}
|
|
84
|
+
if (isMatterLocal) {
|
|
85
|
+
if (!status.onlineTypes.includes("local")) {
|
|
86
|
+
status.onlineTypes.push("local");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
82
89
|
if (isBleOnline) {
|
|
83
90
|
status.onlineTypes.push("ble");
|
|
84
91
|
}
|
|
@@ -89,7 +96,9 @@ export const getDeviceStatus = () => {
|
|
|
89
96
|
if (supportThread && supportBle) {
|
|
90
97
|
const isShareThread = isShareThead();
|
|
91
98
|
if (isShareThread && isOnline) {
|
|
92
|
-
status.onlineTypes
|
|
99
|
+
if (!status.onlineTypes.includes("local")) {
|
|
100
|
+
status.onlineTypes = ["local"];
|
|
101
|
+
}
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
if (status.onlineTypes.includes("ble")) {
|
|
@@ -243,12 +252,14 @@ export const initState = async () => {
|
|
|
243
252
|
fetchDeviceProperties();
|
|
244
253
|
getDeviceAdvancedAbilities();
|
|
245
254
|
syncRemoteSerectKey();
|
|
255
|
+
checkOfflineDpUpdate({}, true).then(() => {
|
|
256
|
+
setTimeout(() => {
|
|
257
|
+
syncOfflineDps();
|
|
258
|
+
}, 3000);
|
|
259
|
+
});
|
|
246
260
|
setTimeout(() => {
|
|
247
261
|
syncT0();
|
|
248
262
|
autoSyncUnlockMethod();
|
|
249
|
-
checkOfflineDpUpdate({}, true).then(() => {
|
|
250
|
-
syncOfflineDps();
|
|
251
|
-
});
|
|
252
263
|
}, 2000);
|
|
253
264
|
setTimeout(() => {
|
|
254
265
|
autoSyncTemp();
|
|
@@ -295,6 +306,9 @@ const handleAppShow = () => {
|
|
|
295
306
|
getCurrentUser(true);
|
|
296
307
|
fetchDeviceProperties();
|
|
297
308
|
checkOfflineDpUpdate({}, true);
|
|
309
|
+
setTimeout(() => {
|
|
310
|
+
syncDeleteUsers();
|
|
311
|
+
}, 1000);
|
|
298
312
|
};
|
|
299
313
|
const handleAppHide = () => { };
|
|
300
314
|
export const addEvents = () => {
|
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;
|
|
@@ -18,25 +18,25 @@ export const syncUnlockMethod = async () => {
|
|
|
18
18
|
const dpCode = config.supportBigData
|
|
19
19
|
? dpCodes.synchMethodW
|
|
20
20
|
: dpCodes.synchMethod;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
try {
|
|
22
|
+
await publishDps({ [dpCode]: ins }, {
|
|
23
|
+
checkReport: (dpData) => {
|
|
24
|
+
if (typeof dpData[dpCode] !== "undefined") {
|
|
25
|
+
const result = dpUtils.parse(dpData[dpCode], config.supportBigData ? reportSyncBigMap : reportSyncMap);
|
|
26
|
+
if (result.stage === 1) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
};
|
|
34
38
|
export const autoSyncUnlockMethod = async () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
await syncUnlockMethod();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
39
|
+
if (syncUnlockMethodFirst) {
|
|
40
|
+
await syncUnlockMethod();
|
|
41
41
|
}
|
|
42
42
|
};
|
package/lib/sync/user.js
CHANGED
|
@@ -1,40 +1,68 @@
|
|
|
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 { isUseNearChannel } from "../utils";
|
|
6
|
+
let isSyncing = false;
|
|
7
7
|
const syncDeleteUsers = async () => {
|
|
8
8
|
const deviceStatus = getDeviceStatus();
|
|
9
9
|
if (deviceStatus.isWifiActive) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
if (hasThread &&
|
|
14
|
-
(deviceStatus.onlineType === "local" || deviceStatus.onlineType === "cloud")) {
|
|
12
|
+
if (deviceStatus.isWifiMatter) {
|
|
15
13
|
return;
|
|
16
14
|
}
|
|
17
|
-
if (
|
|
15
|
+
if (!isUseNearChannel()) {
|
|
18
16
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
}
|
|
18
|
+
if (isSyncing)
|
|
19
|
+
return;
|
|
20
|
+
isSyncing = true;
|
|
21
|
+
let count = 0;
|
|
22
|
+
const handleSync = async () => {
|
|
23
|
+
try {
|
|
24
|
+
const { removedUser = [] } = await getUsersSyncLockData(config.devInfo.devId);
|
|
25
|
+
const deleteSerialCollectFailures = async (users) => {
|
|
26
|
+
const failed = [];
|
|
27
|
+
for (const item of users) {
|
|
28
|
+
try {
|
|
29
|
+
await deleteUser(item);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
failed.push(item);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return failed;
|
|
36
|
+
};
|
|
37
|
+
let failed = await deleteSerialCollectFailures(removedUser);
|
|
38
|
+
if (failed.length > 0) {
|
|
39
|
+
failed = await deleteSerialCollectFailures(failed);
|
|
40
|
+
if (failed.length > 0 && count < 3) {
|
|
30
41
|
count++;
|
|
31
42
|
setTimeout(async () => {
|
|
32
43
|
await handleSync();
|
|
33
44
|
}, 2000);
|
|
34
45
|
}
|
|
46
|
+
else {
|
|
47
|
+
isSyncing = false;
|
|
48
|
+
}
|
|
35
49
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
else {
|
|
51
|
+
isSyncing = false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
if (e?.innerError?.errorCode === "DEVICE_KEY_NOT_FOUND" && count < 3) {
|
|
56
|
+
count++;
|
|
57
|
+
setTimeout(async () => {
|
|
58
|
+
await handleSync();
|
|
59
|
+
}, 2000);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
isSyncing = false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
handleSync();
|
|
39
67
|
};
|
|
40
68
|
export default syncDeleteUsers;
|
package/lib/temporary.js
CHANGED
|
@@ -3,31 +3,17 @@ import config from "./config";
|
|
|
3
3
|
import { formatWeek, isUseNearChannel, parallelOnly, parseOfflinePassword, parseWeek, validateEffectiveConfig, } from "./utils";
|
|
4
4
|
import { LoopTypes } from "./utils/constant";
|
|
5
5
|
import { encrypt } from "./utils/device";
|
|
6
|
-
import { getError } from "./utils/errors";
|
|
6
|
+
import { getError, handleCloudError } from "./utils/errors";
|
|
7
7
|
import { addTempPwd as addTempPwdDpMap, reportAddTempPwd as reportAddTempPwdDpMap, removeTempPwd as removeTempPwdDpMap, reportRemoveTempPwd as reportRemoveTempPwdDpMap, } from "./config/dp-map/unlock-method";
|
|
8
8
|
import { addTempPwd as addTempPwdBigDpMap, reportAddTempPwd as reportAddTempPwdDBigpMap, removeTempPwd as removeTempPwdBigDpMap, reportRemoveTempPwd as reportRemoveTempPwdBigDpMap, } from "./config/dp-map/unlock-method-big";
|
|
9
9
|
import { publishDps } from "./utils/publishDps";
|
|
10
10
|
import dpCodes from "./config/dp-code";
|
|
11
11
|
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
12
12
|
const PASSWORD_REGEX = /^[0-9]+$/;
|
|
13
|
-
const handleError = (cloudError) => {
|
|
14
|
-
switch (cloudError.errorCode) {
|
|
15
|
-
case "USER_PWD_ALREADY_EXIST":
|
|
16
|
-
throw getError(1037);
|
|
17
|
-
case "LOCK_PWD_NAME_REPEAT":
|
|
18
|
-
throw getError(1038);
|
|
19
|
-
case "START_END_DATE_NOT_RIGHT":
|
|
20
|
-
throw getError(1039);
|
|
21
|
-
case "RECORD_NOT_EXIST":
|
|
22
|
-
throw getError(1040);
|
|
23
|
-
default:
|
|
24
|
-
throw cloudError;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
13
|
const isValidPassword = async (params) => {
|
|
28
14
|
const validateResult = await validateTempPwd(params);
|
|
29
15
|
if (!validateResult.valid) {
|
|
30
|
-
|
|
16
|
+
handleCloudError(validateResult);
|
|
31
17
|
}
|
|
32
18
|
return true;
|
|
33
19
|
};
|
|
@@ -144,7 +130,7 @@ export const createTempCustom = parallelOnly(async (params) => {
|
|
|
144
130
|
};
|
|
145
131
|
}
|
|
146
132
|
catch (error) {
|
|
147
|
-
throw
|
|
133
|
+
throw handleCloudError(error);
|
|
148
134
|
}
|
|
149
135
|
}
|
|
150
136
|
});
|
|
@@ -186,7 +172,7 @@ export const removeTempCustom = async (params) => {
|
|
|
186
172
|
}
|
|
187
173
|
}
|
|
188
174
|
catch (e) {
|
|
189
|
-
|
|
175
|
+
handleCloudError(e);
|
|
190
176
|
}
|
|
191
177
|
};
|
|
192
178
|
export const updateTempCustom = async (params) => {
|
|
@@ -220,19 +206,15 @@ export const updateTempCustom = async (params) => {
|
|
|
220
206
|
});
|
|
221
207
|
}
|
|
222
208
|
catch (error) {
|
|
223
|
-
|
|
209
|
+
handleCloudError(error);
|
|
224
210
|
}
|
|
225
211
|
};
|
|
226
212
|
const getOfflinePassword = async (params) => {
|
|
227
213
|
try {
|
|
228
|
-
|
|
229
|
-
return {
|
|
230
|
-
...res,
|
|
231
|
-
pwd: parseOfflinePassword(res.pwd),
|
|
232
|
-
};
|
|
214
|
+
return await createOfflinePassword(params);
|
|
233
215
|
}
|
|
234
216
|
catch (error) {
|
|
235
|
-
throw
|
|
217
|
+
throw handleCloudError(error);
|
|
236
218
|
}
|
|
237
219
|
};
|
|
238
220
|
export const createTempLimit = async (params) => {
|
|
@@ -500,7 +482,7 @@ const changePasswordPhase = async (unlockBindingId, phase) => {
|
|
|
500
482
|
});
|
|
501
483
|
}
|
|
502
484
|
catch (e) {
|
|
503
|
-
|
|
485
|
+
handleCloudError(e);
|
|
504
486
|
}
|
|
505
487
|
return true;
|
|
506
488
|
};
|
|
@@ -536,7 +518,7 @@ export const renameTemp = async (params) => {
|
|
|
536
518
|
}
|
|
537
519
|
}
|
|
538
520
|
catch (e) {
|
|
539
|
-
|
|
521
|
+
handleCloudError(e);
|
|
540
522
|
}
|
|
541
523
|
};
|
|
542
524
|
export const saveTempOnlineUnlimited = async (params) => {
|
|
@@ -582,7 +564,7 @@ export const saveTempOnlineUnlimited = async (params) => {
|
|
|
582
564
|
};
|
|
583
565
|
}
|
|
584
566
|
catch (error) {
|
|
585
|
-
throw
|
|
567
|
+
throw handleCloudError(error);
|
|
586
568
|
}
|
|
587
569
|
};
|
|
588
570
|
export const createTempOffline = async (params) => {
|
|
@@ -640,7 +622,7 @@ export const removeTempOnlineUnlimited = async (id) => {
|
|
|
640
622
|
});
|
|
641
623
|
}
|
|
642
624
|
catch (error) {
|
|
643
|
-
throw
|
|
625
|
+
throw handleCloudError(error);
|
|
644
626
|
}
|
|
645
627
|
};
|
|
646
628
|
const onLinePasswordStatusMap = {
|
|
@@ -674,7 +656,7 @@ export const getTempOnlineUnlimitedList = async () => {
|
|
|
674
656
|
return newPswList;
|
|
675
657
|
}
|
|
676
658
|
catch (error) {
|
|
677
|
-
throw
|
|
659
|
+
throw handleCloudError(error);
|
|
678
660
|
}
|
|
679
661
|
};
|
|
680
662
|
const offlinePasswordTypeMap = {
|
|
@@ -693,7 +675,7 @@ export const getTempOfflineEffectiveList = async (pwdTypeCode) => {
|
|
|
693
675
|
return offLineValidPswList;
|
|
694
676
|
}
|
|
695
677
|
catch (error) {
|
|
696
|
-
throw
|
|
678
|
+
throw handleCloudError(error);
|
|
697
679
|
}
|
|
698
680
|
};
|
|
699
681
|
export const getTempOfflineInvalidList = async (pwdTypeCode) => {
|
|
@@ -706,6 +688,6 @@ export const getTempOfflineInvalidList = async (pwdTypeCode) => {
|
|
|
706
688
|
return offLineFailurePswList;
|
|
707
689
|
}
|
|
708
690
|
catch (error) {
|
|
709
|
-
throw
|
|
691
|
+
throw handleCloudError(error);
|
|
710
692
|
}
|
|
711
693
|
};
|
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,42 @@ 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: effectiveTime
|
|
77
|
+
? Math.floor(effectiveTime / 1000)
|
|
78
|
+
: 0x386cd300,
|
|
79
|
+
endTime: expiredTime ? Math.floor(expiredTime / 1000) : 0x72bc9b7f,
|
|
80
|
+
loop: LoopTypes.NONE,
|
|
81
|
+
loopConfig: 0,
|
|
82
|
+
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
83
|
+
days: [],
|
|
84
|
+
startHour: 0,
|
|
85
|
+
startMinute: 0,
|
|
86
|
+
endHour: 0,
|
|
87
|
+
endMinute: 0,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
validConfig = {
|
|
92
|
+
startTime: Math.floor((effectiveTime || +new Date()) / 1000),
|
|
93
|
+
endTime: expiredTime ? Math.floor(expiredTime / 1000) : 0x72bc9b7f,
|
|
94
|
+
loop: scheduleDetails?.repeat ? LoopTypes.WEEK : LoopTypes.NONE,
|
|
95
|
+
loopConfig: 0,
|
|
96
|
+
weeks: scheduleDetails?.repeat
|
|
97
|
+
? scheduleDetails?.weeks
|
|
98
|
+
: [0, 0, 0, 0, 0, 0, 0],
|
|
99
|
+
days: [],
|
|
100
|
+
startHour: Math.floor((scheduleDetails?.effectiveTime ?? 0) / 60),
|
|
101
|
+
startMinute: (scheduleDetails?.effectiveTime ?? 0) % 60,
|
|
102
|
+
endHour: Math.floor((scheduleDetails?.invalidTime ?? 0) / 60),
|
|
103
|
+
endMinute: (scheduleDetails?.invalidTime ?? 0) % 60,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
74
106
|
}
|
|
75
107
|
else {
|
|
76
108
|
validConfig = getPermanentSetting();
|
|
@@ -311,7 +343,8 @@ const handleAddReport = async (dps) => {
|
|
|
311
343
|
};
|
|
312
344
|
}
|
|
313
345
|
}
|
|
314
|
-
catch {
|
|
346
|
+
catch (err) {
|
|
347
|
+
console.warn("AddUnlockMethod failed", err);
|
|
315
348
|
eventData = {
|
|
316
349
|
stage: "fail",
|
|
317
350
|
type,
|
|
@@ -350,6 +383,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
350
383
|
const res = await publishDps({
|
|
351
384
|
[addDpCode]: dpUtils.format(dpData, addDpMap),
|
|
352
385
|
}, {
|
|
386
|
+
timeout: params.timeout,
|
|
353
387
|
checkReport: (dpData) => {
|
|
354
388
|
if (typeof dpData[addDpCode] !== "undefined") {
|
|
355
389
|
const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
|
|
@@ -375,6 +409,7 @@ export const startAddUnlockMethod = async (params) => {
|
|
|
375
409
|
});
|
|
376
410
|
if (res.stage === 0) {
|
|
377
411
|
monitoringAddReport({
|
|
412
|
+
timeout: params.timeout,
|
|
378
413
|
unlockMethodConfig,
|
|
379
414
|
total: res.total,
|
|
380
415
|
dpCode: addDpCode,
|
|
@@ -446,7 +481,7 @@ export const deleteUnlockMethod = parallelOnly(async (id) => {
|
|
|
446
481
|
admin: isAdmin(userType),
|
|
447
482
|
memberId: lockUserId,
|
|
448
483
|
unlockId,
|
|
449
|
-
|
|
484
|
+
operation: 1,
|
|
450
485
|
};
|
|
451
486
|
const res = await publishDps({
|
|
452
487
|
[removeDPCode]: dpUtils.format(dpData, (config.supportBigData ? removeBigMap : removeMap)),
|
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;
|
|
@@ -39,12 +19,12 @@ interface updateUserLimitTimeParams {
|
|
|
39
19
|
effective?: EffectiveConfig;
|
|
40
20
|
offlineUnlock?: boolean;
|
|
41
21
|
}
|
|
42
|
-
export declare const updateUserLimitTime: (params: updateUserLimitTimeParams) => Promise<
|
|
22
|
+
export declare const updateUserLimitTime: (params: updateUserLimitTimeParams) => Promise<true | undefined>;
|
|
43
23
|
export declare const openAddFamilyUser: () => Promise<unknown>;
|
|
44
24
|
export declare const openFamilyUserDetail: (userId: string) => Promise<undefined>;
|
|
45
25
|
interface AddUserParams {
|
|
46
26
|
name: string;
|
|
47
27
|
}
|
|
48
|
-
export declare const addUser: (params: AddUserParams) => Promise<
|
|
28
|
+
export declare const addUser: (params: AddUserParams) => Promise<void>;
|
|
49
29
|
export declare const removeUser: (userId: string) => Promise<void>;
|
|
50
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";
|
|
@@ -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)) {
|
|
@@ -156,33 +159,33 @@ export const updateUserLimitTime = async (params) => {
|
|
|
156
159
|
endMinute: expiredTime % 60,
|
|
157
160
|
},
|
|
158
161
|
};
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (result.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
console.warn("An incorrect member id was returned");
|
|
177
|
-
}
|
|
162
|
+
const dpCode = config.supportBigData
|
|
163
|
+
? dpCodes.unlockMethodEditW
|
|
164
|
+
: dpCodes.unlockMethodEdit;
|
|
165
|
+
const res = (await publishDps({
|
|
166
|
+
[dpCode]: DpUtils.format(dpValue, (config.supportBigData ? updateMapBig : updateMap)),
|
|
167
|
+
}, {
|
|
168
|
+
checkReport: (dps) => {
|
|
169
|
+
if (typeof dps[dpCode] !== "undefined") {
|
|
170
|
+
const result = DpUtils.parse(dps[dpCode], (config.supportBigData
|
|
171
|
+
? reportUpdateMapBig
|
|
172
|
+
: reportUpdateMap));
|
|
173
|
+
if (result.type === 0) {
|
|
174
|
+
if (result.memberId === lockUserId) {
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
console.warn("An incorrect member id was returned");
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
},
|
|
184
|
+
}));
|
|
185
|
+
if (res.status !== 255) {
|
|
186
|
+
throw getError(1011);
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
186
189
|
await updateUserTimeSchedule({
|
|
187
190
|
devId: config.devInfo.devId,
|
|
188
191
|
userId: userId,
|
|
@@ -201,11 +204,11 @@ export const updateUserLimitTime = async (params) => {
|
|
|
201
204
|
],
|
|
202
205
|
},
|
|
203
206
|
});
|
|
207
|
+
return true;
|
|
204
208
|
}
|
|
205
209
|
catch (e) {
|
|
206
|
-
|
|
210
|
+
handleCloudError(e, 1012);
|
|
207
211
|
}
|
|
208
|
-
return true;
|
|
209
212
|
};
|
|
210
213
|
export const openAddFamilyUser = async () => {
|
|
211
214
|
const homeInfo = await getCurrentHomeInfo();
|
|
@@ -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 {};
|