@ray-js/lock-sdk 1.1.1-beta.8 → 1.1.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/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 +4 -4
- package/lib/capability.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/index.d.ts +2 -1
- package/lib/index.js +6 -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/other.d.ts +1 -0
- package/lib/other.js +10 -2
- package/lib/state.js +8 -3
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/unlock-method.js +16 -16
- package/lib/sync/user.js +46 -21
- package/lib/temporary.js +14 -32
- package/lib/unlock-method.js +46 -11
- package/lib/user.d.ts +2 -2
- package/lib/user.js +105 -93
- 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 +36 -0
- package/lib/utils/index.js +1 -2
- package/package.json +1 -1
package/lib/sync/user.js
CHANGED
|
@@ -1,40 +1,65 @@
|
|
|
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 (!isUseNearChannel()) {
|
|
15
13
|
return;
|
|
16
14
|
}
|
|
17
|
-
if (
|
|
15
|
+
if (isSyncing)
|
|
18
16
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
isSyncing = true;
|
|
18
|
+
let count = 0;
|
|
19
|
+
const handleSync = async () => {
|
|
20
|
+
try {
|
|
21
|
+
const { removedUser = [] } = await getUsersSyncLockData(config.devInfo.devId);
|
|
22
|
+
const deleteSerialCollectFailures = async (users) => {
|
|
23
|
+
const failed = [];
|
|
24
|
+
for (const item of users) {
|
|
25
|
+
try {
|
|
26
|
+
await deleteUser(item);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
failed.push(item);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return failed;
|
|
33
|
+
};
|
|
34
|
+
let failed = await deleteSerialCollectFailures(removedUser);
|
|
35
|
+
if (failed.length > 0) {
|
|
36
|
+
failed = await deleteSerialCollectFailures(failed);
|
|
37
|
+
if (failed.length > 0 && count < 3) {
|
|
30
38
|
count++;
|
|
31
39
|
setTimeout(async () => {
|
|
32
40
|
await handleSync();
|
|
33
41
|
}, 2000);
|
|
34
42
|
}
|
|
43
|
+
else {
|
|
44
|
+
isSyncing = false;
|
|
45
|
+
}
|
|
35
46
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
else {
|
|
48
|
+
isSyncing = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
if (e?.innerError?.errorCode === "DEVICE_KEY_NOT_FOUND" && count < 3) {
|
|
53
|
+
count++;
|
|
54
|
+
setTimeout(async () => {
|
|
55
|
+
await handleSync();
|
|
56
|
+
}, 2000);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
isSyncing = false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
handleSync();
|
|
39
64
|
};
|
|
40
65
|
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
|
@@ -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,59 +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
|
-
const unlockList = detail.unlockList.map((unlockItem) => {
|
|
41
|
-
return {
|
|
42
|
-
unlockId: +unlockItem.unlockId.split("-")[1],
|
|
43
|
-
unlockName: unlockItem.unlockName,
|
|
44
|
-
id: unlockItem.opModeId,
|
|
45
|
-
isBound: unlockItem.allocateFlag === 1,
|
|
46
|
-
photoUnlock: unlockItem.photoUnlock,
|
|
47
|
-
isSpecial: unlockItem.unlockAttr === 1,
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
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) => {
|
|
51
40
|
return {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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,
|
|
57
47
|
};
|
|
58
48
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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));
|
|
65
68
|
return acc;
|
|
66
69
|
}, result);
|
|
67
70
|
};
|
|
68
|
-
|
|
69
|
-
const { page = 1, pageSize = 10, keyword = "" } = params || {};
|
|
71
|
+
const getUserDpCodes = async () => {
|
|
70
72
|
const currentUser = await getCurrentUser();
|
|
71
73
|
const dps = [];
|
|
72
74
|
if (currentUser.allOpenDps) {
|
|
@@ -78,6 +80,11 @@ export const getUsers = async (params) => {
|
|
|
78
80
|
return acc;
|
|
79
81
|
}, dps);
|
|
80
82
|
}
|
|
83
|
+
return dps;
|
|
84
|
+
};
|
|
85
|
+
export const getUsers = async (params) => {
|
|
86
|
+
const { page = 1, pageSize = 10, keyword = "" } = params || {};
|
|
87
|
+
const dps = await getUserDpCodes();
|
|
81
88
|
const res = await getUserList({
|
|
82
89
|
dpCodes: dps.join(","),
|
|
83
90
|
devId: config.devInfo.devId,
|
|
@@ -98,26 +105,24 @@ export const getUsers = async (params) => {
|
|
|
98
105
|
};
|
|
99
106
|
};
|
|
100
107
|
export const getUserInfo = async (params) => {
|
|
101
|
-
const
|
|
108
|
+
const currentUser = await getCurrentUser();
|
|
109
|
+
const res = await getUserDetailQuery({
|
|
102
110
|
devId: config.devInfo.devId,
|
|
103
111
|
userId: params.userId,
|
|
112
|
+
dpIds: currentUser.allOpenDps,
|
|
104
113
|
});
|
|
105
|
-
|
|
106
|
-
keyword: user.nickName,
|
|
107
|
-
});
|
|
108
|
-
const res = data.list.find((item) => item.userId === params.userId);
|
|
109
|
-
if (res) {
|
|
110
|
-
return res;
|
|
111
|
-
}
|
|
112
|
-
throw getError(1048);
|
|
114
|
+
return handleUserDetail(res);
|
|
113
115
|
};
|
|
114
116
|
export const updateUserLimitTime = async (params) => {
|
|
115
117
|
const { userId, lockUserId, permanent, effective } = params;
|
|
116
118
|
if (!permanent) {
|
|
117
119
|
validateEffectiveConfig(effective);
|
|
118
120
|
}
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
+
const currentUser = await getCurrentUser();
|
|
122
|
+
if (!isAdmin(currentUser.userType)) {
|
|
123
|
+
throw getError(1069);
|
|
124
|
+
}
|
|
125
|
+
const { userType } = await getUserInfo({
|
|
121
126
|
userId,
|
|
122
127
|
});
|
|
123
128
|
if (isAdmin(userType)) {
|
|
@@ -154,33 +159,33 @@ export const updateUserLimitTime = async (params) => {
|
|
|
154
159
|
endMinute: expiredTime % 60,
|
|
155
160
|
},
|
|
156
161
|
};
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (result.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
console.warn("An incorrect member id was returned");
|
|
175
|
-
}
|
|
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");
|
|
176
179
|
}
|
|
177
180
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
},
|
|
184
|
+
}));
|
|
185
|
+
if (res.status !== 255) {
|
|
186
|
+
throw getError(1011);
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
184
189
|
await updateUserTimeSchedule({
|
|
185
190
|
devId: config.devInfo.devId,
|
|
186
191
|
userId: userId,
|
|
@@ -199,11 +204,11 @@ export const updateUserLimitTime = async (params) => {
|
|
|
199
204
|
],
|
|
200
205
|
},
|
|
201
206
|
});
|
|
207
|
+
return true;
|
|
202
208
|
}
|
|
203
209
|
catch (e) {
|
|
204
|
-
|
|
210
|
+
handleCloudError(e, 1012);
|
|
205
211
|
}
|
|
206
|
-
return true;
|
|
207
212
|
};
|
|
208
213
|
export const openAddFamilyUser = async () => {
|
|
209
214
|
const homeInfo = await getCurrentHomeInfo();
|
|
@@ -257,17 +262,24 @@ export const addUser = async (params) => {
|
|
|
257
262
|
if (!params.name) {
|
|
258
263
|
throw getError(1009, "name");
|
|
259
264
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
+
}
|
|
264
277
|
};
|
|
265
278
|
export const removeUser = async (userId) => {
|
|
266
279
|
if (!config.supportBigData) {
|
|
267
280
|
throw getError(1060);
|
|
268
281
|
}
|
|
269
|
-
const res = await
|
|
270
|
-
devId: config.devInfo.devId,
|
|
282
|
+
const res = await getUserInfo({
|
|
271
283
|
userId,
|
|
272
284
|
});
|
|
273
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