@ray-js/lock-sdk 1.2.0 → 1.2.1-beta.0
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 +4 -0
- package/lib/api/user.js +8 -0
- package/lib/feature/fit/method/internal/base.js +7 -16
- package/lib/feature/unlock/method/internal/base.js +6 -16
- package/lib/feature/user/user.js +25 -18
- package/lib/interface.d.ts +1 -0
- package/lib/utils/errors.js +1 -0
- package/lib/utils/index.d.ts +0 -12
- package/lib/utils/index.js +0 -14
- package/package.json +1 -1
package/lib/api/user.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ export interface UserListItem {
|
|
|
57
57
|
nickName: string;
|
|
58
58
|
offlineUnlock: boolean;
|
|
59
59
|
timeScheduleInfo: {
|
|
60
|
+
userTimeSet: string;
|
|
60
61
|
effectiveTime: number;
|
|
61
62
|
expiredTime: number;
|
|
62
63
|
permanent: boolean;
|
|
@@ -143,4 +144,7 @@ export interface LockShareAvailableResult {
|
|
|
143
144
|
errorCode: string;
|
|
144
145
|
}
|
|
145
146
|
export declare const checkLockShareAvailable: (params: LockShareAvailableParams) => Promise<LockShareAvailableResult>;
|
|
147
|
+
export declare const getPermanentValidTime: (devId: string) => Promise<{
|
|
148
|
+
timeSetHex: string;
|
|
149
|
+
}>;
|
|
146
150
|
export {};
|
package/lib/api/user.js
CHANGED
|
@@ -88,3 +88,11 @@ export const checkLockShareAvailable = (params) => {
|
|
|
88
88
|
data: { ...params },
|
|
89
89
|
});
|
|
90
90
|
};
|
|
91
|
+
export const getPermanentValidTime = (devId) => {
|
|
92
|
+
return requestApi({
|
|
93
|
+
logName: "getPermanentValidTime",
|
|
94
|
+
api: "m.lock.perm.time.get",
|
|
95
|
+
version: "1.0",
|
|
96
|
+
data: { devId, scene: "SCHEDULE" },
|
|
97
|
+
});
|
|
98
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import DpUtils from "@ray-js/tuya-dp-transform";
|
|
1
2
|
import dpCodes from "../../../../config/dp-code";
|
|
2
|
-
import { fitAdd, fitReportAdd } from "../../../../config/dp-map/unlock-method-fit";
|
|
3
|
-
import {
|
|
3
|
+
import { fitAdd, fitReportAdd, } from "../../../../config/dp-map/unlock-method-fit";
|
|
4
|
+
import { isAdmin } from "../../../../utils";
|
|
4
5
|
import { getError } from "../../../../utils/errors";
|
|
5
6
|
import { LoopTypes } from "../../../../utils/constant";
|
|
6
7
|
import { sdkLog } from "../../../../utils/sdk-log";
|
|
@@ -8,24 +9,14 @@ import { getUnlockMethodTypeByTypeForRuntime } from "../../../utils";
|
|
|
8
9
|
import { getUserInfoOnDevForRuntime } from "../../../user/user";
|
|
9
10
|
import { getBoundLockListForRuntime } from "../../list";
|
|
10
11
|
import { resolveSlaveId } from "../../resolve-slave-id";
|
|
12
|
+
import { validConfigDpMap } from "../../../../config/dp-map/common";
|
|
11
13
|
export function buildValidConfigFromTimeSchedule(timeScheduleInfo) {
|
|
12
14
|
if (!timeScheduleInfo) {
|
|
13
|
-
|
|
15
|
+
throw getError(1106);
|
|
14
16
|
}
|
|
15
|
-
const { permanent, effectiveTime, expiredTime, scheduleDetails } = timeScheduleInfo;
|
|
17
|
+
const { permanent, userTimeSet, effectiveTime, expiredTime, scheduleDetails, } = timeScheduleInfo;
|
|
16
18
|
if (permanent) {
|
|
17
|
-
return
|
|
18
|
-
startTime: effectiveTime ? Math.floor(effectiveTime / 1000) : 0x386cd300,
|
|
19
|
-
endTime: expiredTime ? Math.floor(expiredTime / 1000) : 0x72bc9b7f,
|
|
20
|
-
loop: LoopTypes.NONE,
|
|
21
|
-
loopConfig: 0,
|
|
22
|
-
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
23
|
-
days: [],
|
|
24
|
-
startHour: 0,
|
|
25
|
-
startMinute: 0,
|
|
26
|
-
endHour: 0,
|
|
27
|
-
endMinute: 0,
|
|
28
|
-
};
|
|
19
|
+
return DpUtils.parse(userTimeSet, validConfigDpMap.childMap);
|
|
29
20
|
}
|
|
30
21
|
return {
|
|
31
22
|
startTime: Math.floor((effectiveTime || +new Date()) / 1000),
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import DpUtils from "@ray-js/tuya-dp-transform";
|
|
1
2
|
import { fetchCreatePasswordSN } from "../../../../api/lock";
|
|
2
3
|
import dpCodes from "../../../../config/dp-code";
|
|
3
4
|
import { add as addMap, reportAdd as reportAddMap, } from "../../../../config/dp-map/unlock-method";
|
|
4
5
|
import { add as addBigMap, reportAdd as reportAddBigMap, } from "../../../../config/dp-map/unlock-method-big";
|
|
5
6
|
import { getUnlockMethodTypeByTypeForRuntime } from "../../../utils";
|
|
6
|
-
import {
|
|
7
|
+
import { isAdmin } from "../../../../utils";
|
|
7
8
|
import { LoopTypes } from "../../../../utils/constant";
|
|
8
9
|
import { getUserInfoForRuntime } from "../../../user/user";
|
|
10
|
+
import { getError } from "../../../../utils/errors";
|
|
11
|
+
import { validConfigDpMap } from "../../../../config/dp-map/common";
|
|
9
12
|
export async function getUnlockMethodBase(rt, type, userId) {
|
|
10
13
|
const { idsByCode, devInfo: { devId }, supportBigData, } = rt.config;
|
|
11
14
|
const unlockMethodConfig = getUnlockMethodTypeByTypeForRuntime(rt, type);
|
|
@@ -27,20 +30,7 @@ export async function getUnlockMethodBase(rt, type, userId) {
|
|
|
27
30
|
if (timeScheduleInfo) {
|
|
28
31
|
const { permanent, effectiveTime, expiredTime, scheduleDetails } = timeScheduleInfo;
|
|
29
32
|
if (permanent) {
|
|
30
|
-
validConfig =
|
|
31
|
-
startTime: effectiveTime
|
|
32
|
-
? Math.floor(effectiveTime / 1000)
|
|
33
|
-
: 0x386cd300,
|
|
34
|
-
endTime: expiredTime ? Math.floor(expiredTime / 1000) : 0x72bc9b7f,
|
|
35
|
-
loop: LoopTypes.NONE,
|
|
36
|
-
loopConfig: 0,
|
|
37
|
-
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
38
|
-
days: [],
|
|
39
|
-
startHour: 0,
|
|
40
|
-
startMinute: 0,
|
|
41
|
-
endHour: 0,
|
|
42
|
-
endMinute: 0,
|
|
43
|
-
};
|
|
33
|
+
validConfig = DpUtils.parse(timeScheduleInfo.userTimeSet, validConfigDpMap.childMap);
|
|
44
34
|
}
|
|
45
35
|
else {
|
|
46
36
|
validConfig = {
|
|
@@ -60,7 +50,7 @@ export async function getUnlockMethodBase(rt, type, userId) {
|
|
|
60
50
|
}
|
|
61
51
|
}
|
|
62
52
|
else {
|
|
63
|
-
|
|
53
|
+
throw getError(1106);
|
|
64
54
|
}
|
|
65
55
|
const dpData = {
|
|
66
56
|
type: unlockMethodConfig.id,
|
package/lib/feature/user/user.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCurrentUserInfo, getUserDetailQuery, getUserList, } from "../../api/user";
|
|
1
|
+
import { getCurrentUserInfo, getPermanentValidTime, getUserDetailQuery, getUserList, } from "../../api/user";
|
|
2
2
|
import { update as updateMap, reportUpdate as reportUpdateMap, } from "../../config/dp-map/unlock-method";
|
|
3
3
|
import { update as updateMapBig, reportUpdate as reportUpdateMapBig, } from "../../config/dp-map/unlock-method-big";
|
|
4
4
|
import { publishDpsForRuntime } from "../dp/publish-dps";
|
|
@@ -9,7 +9,7 @@ import { updateUserTimeSchedule, addNormalUser, removeNormalUser, } from "../../
|
|
|
9
9
|
import { validConfigDpMap } from "../../config/dp-map/common";
|
|
10
10
|
import { isUseNearChannelForRuntime } from "../misc/is-use-near-channel-for-runtime";
|
|
11
11
|
import { getUnlockMethodTypeByDpCodeForRuntime } from "../utils";
|
|
12
|
-
import { formatTimestampToMilliseconds, formatWeek,
|
|
12
|
+
import { formatTimestampToMilliseconds, formatWeek, isAdmin, parseWeek, validateEffectiveConfig, } from "../../utils";
|
|
13
13
|
import { getCurrentHomeInfo, isSupportShortLink } from "../../platform/device";
|
|
14
14
|
import { LoopTypes } from "../../utils/constant";
|
|
15
15
|
import { getCurrentUserForRuntime } from "./current-user";
|
|
@@ -21,6 +21,7 @@ const handleUserDetail = (rt, user) => {
|
|
|
21
21
|
const { timeScheduleInfo, unlockDetail, ...rest } = user;
|
|
22
22
|
let scheduleInfo = {
|
|
23
23
|
permanent: true,
|
|
24
|
+
userTimeSet: timeScheduleInfo.userTimeSet,
|
|
24
25
|
};
|
|
25
26
|
if (!timeScheduleInfo.permanent &&
|
|
26
27
|
timeScheduleInfo.scheduleDetails &&
|
|
@@ -214,6 +215,27 @@ export async function updateUserLimitTimeForRuntime(rt, params) {
|
|
|
214
215
|
?
|
|
215
216
|
LoopTypes[repeat.toUpperCase()]
|
|
216
217
|
: LoopTypes.NONE;
|
|
218
|
+
let validConfig;
|
|
219
|
+
if (permanent) {
|
|
220
|
+
const { timeSetHex } = await getPermanentValidTime(cfg.devInfo.devId);
|
|
221
|
+
validConfig = DpUtils.parse(timeSetHex, validConfigDpMap.childMap);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
validConfig = {
|
|
225
|
+
startTime: effective.effectiveDate,
|
|
226
|
+
endTime: effective.expiredDate,
|
|
227
|
+
loop: loopType,
|
|
228
|
+
loopConfig: 0,
|
|
229
|
+
weeks: effective?.repeat !== "week" || effective?.weeks === undefined
|
|
230
|
+
? [0, 0, 0, 0, 0, 0, 0]
|
|
231
|
+
: effective.weeks,
|
|
232
|
+
days: [],
|
|
233
|
+
startHour: Math.floor(effectiveTime / 60),
|
|
234
|
+
startMinute: effectiveTime % 60,
|
|
235
|
+
endHour: Math.floor(expiredTime / 60),
|
|
236
|
+
endMinute: expiredTime % 60,
|
|
237
|
+
};
|
|
238
|
+
}
|
|
217
239
|
const dpValue = {
|
|
218
240
|
type: 0,
|
|
219
241
|
stage: 0,
|
|
@@ -223,22 +245,7 @@ export async function updateUserLimitTimeForRuntime(rt, params) {
|
|
|
223
245
|
validNum: 0,
|
|
224
246
|
pwdLength: 0,
|
|
225
247
|
pwd: [],
|
|
226
|
-
validConfig
|
|
227
|
-
? getPermanentSetting()
|
|
228
|
-
: {
|
|
229
|
-
startTime: effective.effectiveDate,
|
|
230
|
-
endTime: effective.expiredDate,
|
|
231
|
-
loop: loopType,
|
|
232
|
-
loopConfig: 0,
|
|
233
|
-
weeks: effective?.repeat !== "week" || effective?.weeks === undefined
|
|
234
|
-
? [0, 0, 0, 0, 0, 0, 0]
|
|
235
|
-
: effective.weeks,
|
|
236
|
-
days: [],
|
|
237
|
-
startHour: Math.floor(effectiveTime / 60),
|
|
238
|
-
startMinute: effectiveTime % 60,
|
|
239
|
-
endHour: Math.floor(expiredTime / 60),
|
|
240
|
-
endMinute: expiredTime % 60,
|
|
241
|
-
},
|
|
248
|
+
validConfig,
|
|
242
249
|
};
|
|
243
250
|
const res = (await publishDpsForRuntime(rt, {
|
|
244
251
|
[dpCode]: DpUtils.format(dpValue, (cfg.supportBigData ? updateMapBig : updateMap)),
|
package/lib/interface.d.ts
CHANGED
package/lib/utils/errors.js
CHANGED
|
@@ -105,6 +105,7 @@ const errors = {
|
|
|
105
105
|
1103: "Binding failed",
|
|
106
106
|
1104: "Failed to switch cameras",
|
|
107
107
|
1105: "Camera switching is not supported",
|
|
108
|
+
1106: "No validity configuration data",
|
|
108
109
|
};
|
|
109
110
|
export const getError = (code, ...places) => {
|
|
110
111
|
if (errors[code]) {
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -123,18 +123,6 @@ export declare function getCapabilities(capability: number): ({
|
|
|
123
123
|
export declare const formatWeek: (value: number[]) => number;
|
|
124
124
|
export declare const formatCloudUnlockId: (dpId: number | string, sn: number) => string;
|
|
125
125
|
export declare const parseWeek: (value: number) => Week;
|
|
126
|
-
export declare const getPermanentSetting: () => {
|
|
127
|
-
startTime: number;
|
|
128
|
-
endTime: number;
|
|
129
|
-
loop: LoopTypes;
|
|
130
|
-
loopConfig: number;
|
|
131
|
-
weeks: number[];
|
|
132
|
-
days: never[];
|
|
133
|
-
startHour: number;
|
|
134
|
-
startMinute: number;
|
|
135
|
-
endHour: number;
|
|
136
|
-
endMinute: number;
|
|
137
|
-
};
|
|
138
126
|
export declare const isAdmin: (userType: UserType) => boolean;
|
|
139
127
|
export declare const validateEffectiveConfig: (effective?: EffectiveConfig) => void;
|
|
140
128
|
export declare const formatTimestampToMilliseconds: (timestamp: number) => number;
|
package/lib/utils/index.js
CHANGED
|
@@ -66,20 +66,6 @@ export const parseWeek = (value) => {
|
|
|
66
66
|
.map(Number)
|
|
67
67
|
.slice(0, 7);
|
|
68
68
|
};
|
|
69
|
-
export const getPermanentSetting = () => {
|
|
70
|
-
return {
|
|
71
|
-
startTime: 0x386cd300,
|
|
72
|
-
endTime: 0x72bc9b7f,
|
|
73
|
-
loop: LoopTypes.NONE,
|
|
74
|
-
loopConfig: 0,
|
|
75
|
-
weeks: [0, 0, 0, 0, 0, 0, 0],
|
|
76
|
-
days: [],
|
|
77
|
-
startHour: 0,
|
|
78
|
-
startMinute: 0,
|
|
79
|
-
endHour: 0,
|
|
80
|
-
endMinute: 0,
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
69
|
export const isAdmin = (userType) => userType === 10 || userType === 50 ? true : false;
|
|
84
70
|
export const validateEffectiveConfig = (effective) => {
|
|
85
71
|
if (!effective) {
|