@ray-js/lock-sdk 1.1.0 → 1.1.1-beta.2
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/temp.js +1 -1
- package/lib/config/dp-code/index.d.ts +1 -0
- package/lib/config/dp-code/index.js +1 -0
- package/lib/config/dp-map/unlock-method-big.d.ts +10 -11
- package/lib/index.js +1 -1
- package/lib/interface.d.ts +1 -0
- package/lib/open.js +12 -2
- package/lib/other.js +9 -9
- package/lib/state.js +48 -61
- package/lib/sync/user.js +2 -38
- package/lib/temporary.d.ts +2 -1
- package/lib/temporary.js +41 -13
- package/lib/user.js +30 -19
- package/lib/utils/device.d.ts +1 -0
- package/lib/utils/device.js +1 -1
- package/lib/utils/errors.js +1 -0
- package/lib/utils/index.js +1 -1
- package/lib/utils/publishDps.js +1 -1
- package/lib/utils/user.d.ts +2 -0
- package/lib/utils/user.js +39 -0
- package/package.json +1 -1
- package/lib/dp-interface.d.ts +0 -7
- package/lib/dp-interface.js +0 -1
- package/lib/sync/unlock-mothod.d.ts +0 -2
- package/lib/sync/unlock-mothod.js +0 -42
package/lib/api/temp.js
CHANGED
|
@@ -382,17 +382,16 @@ declare const reportAddTempPwd: ({
|
|
|
382
382
|
name: string;
|
|
383
383
|
bytes?: undefined;
|
|
384
384
|
})[];
|
|
385
|
-
declare const removeTempPwd: {
|
|
386
|
-
name:
|
|
387
|
-
bytes:
|
|
388
|
-
}
|
|
389
|
-
declare const reportRemoveTempPwd:
|
|
390
|
-
name:
|
|
391
|
-
bytes:
|
|
392
|
-
}
|
|
393
|
-
name:
|
|
394
|
-
|
|
395
|
-
})[];
|
|
385
|
+
declare const removeTempPwd: readonly [{
|
|
386
|
+
readonly name: "unlockId";
|
|
387
|
+
readonly bytes: 2;
|
|
388
|
+
}];
|
|
389
|
+
declare const reportRemoveTempPwd: readonly [{
|
|
390
|
+
readonly name: "unlockId";
|
|
391
|
+
readonly bytes: 2;
|
|
392
|
+
}, {
|
|
393
|
+
readonly name: "status";
|
|
394
|
+
}];
|
|
396
395
|
declare const updateTempPwd: ({
|
|
397
396
|
readonly name: "validConfig";
|
|
398
397
|
readonly type: "child";
|
package/lib/index.js
CHANGED
|
@@ -61,8 +61,8 @@ export const init = async (options) => {
|
|
|
61
61
|
config.idsByCode = idsByCode;
|
|
62
62
|
config.supportBigData = !!dpSchema[dpCodes.synchMethodW];
|
|
63
63
|
config.communication = getCapabilities(devInfo.capability).map((item) => item.id);
|
|
64
|
-
await initState();
|
|
65
64
|
addEvents();
|
|
65
|
+
await initState();
|
|
66
66
|
};
|
|
67
67
|
export const destroy = () => {
|
|
68
68
|
clearState();
|
package/lib/interface.d.ts
CHANGED
|
@@ -185,6 +185,7 @@ export interface DeviceStatus {
|
|
|
185
185
|
type: "offline" | "online" | "sleep";
|
|
186
186
|
connectEnable: boolean;
|
|
187
187
|
onlineType: "local" | "cloud" | "ble" | "none" | "unknown";
|
|
188
|
+
onlineTypes: Array<"local" | "cloud" | "ble" | "localMatter" | "unknown">;
|
|
188
189
|
sleepPeriod?: {
|
|
189
190
|
start: number;
|
|
190
191
|
end: number;
|
package/lib/open.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
2
|
import { getDoorKey, openDoorByCloud, isConfirmOpenDoorByWifiPro, } from "./api/lock";
|
|
3
|
-
import config, { hasCapability } from "./config";
|
|
3
|
+
import config, { hasCapability, hasDp } from "./config";
|
|
4
4
|
import { isUseNearChannel, parallelMerge, parallelOnly } from "./utils";
|
|
5
5
|
import { decrypt, encrypt } from "./utils/device";
|
|
6
6
|
import { publishDps } from "./utils/publishDps";
|
|
@@ -73,9 +73,19 @@ const _doAction = async (isOpen, timeout) => {
|
|
|
73
73
|
const currentUser = await getCurrentUser();
|
|
74
74
|
const memberId = currentUser.lockUserId !== 0 ? currentUser.lockUserId : currentUser.userId;
|
|
75
75
|
const checkReport = (dpData) => {
|
|
76
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
77
|
+
if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
|
|
78
|
+
return {
|
|
79
|
+
status: 0,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
76
83
|
if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
|
|
77
84
|
const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
|
|
78
85
|
if (result.memberId === memberId) {
|
|
86
|
+
if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
79
89
|
return result;
|
|
80
90
|
}
|
|
81
91
|
else {
|
|
@@ -229,7 +239,7 @@ export const updateVoiceUnlockPwd = async (password) => {
|
|
|
229
239
|
const encryptedPassword = await encrypt(config.devInfo.devId, password);
|
|
230
240
|
return setVoicePwd({
|
|
231
241
|
devId: config.devInfo.devId,
|
|
232
|
-
open:
|
|
242
|
+
open: true,
|
|
233
243
|
pwd: encryptedPassword,
|
|
234
244
|
});
|
|
235
245
|
};
|
package/lib/other.js
CHANGED
|
@@ -71,26 +71,26 @@ export const openScene = async (options) => {
|
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
73
|
export const isSupportBleControl = () => {
|
|
74
|
-
const { devInfo, idsByCode
|
|
75
|
-
if (!idsByCode[dpCodes.unlockBle]) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
74
|
+
const { devInfo, idsByCode } = config;
|
|
78
75
|
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
79
76
|
const hasWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
80
77
|
const hasBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
81
78
|
if (!hasBle) {
|
|
82
79
|
return false;
|
|
83
80
|
}
|
|
84
|
-
if (
|
|
85
|
-
if (!
|
|
81
|
+
if (hasWifi && hasBle) {
|
|
82
|
+
if (!hasDp(dpCodes.unlockBle)) {
|
|
86
83
|
return false;
|
|
87
84
|
}
|
|
88
|
-
}
|
|
89
|
-
if (hasWifi && hasBle) {
|
|
90
85
|
if (devInfo.wifiEnableState === 1) {
|
|
91
86
|
return true;
|
|
92
87
|
}
|
|
93
88
|
}
|
|
89
|
+
if (hasThread && hasBle) {
|
|
90
|
+
if (!devInfo?.meta?.["threadWithBLE"]) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
94
|
const bleControlDp = idsByCode[dpCodes.bleControl];
|
|
95
95
|
if (bleControlDp) {
|
|
96
96
|
const reportTIme = devInfo?.dpsTime?.[bleControlDp];
|
|
@@ -101,7 +101,7 @@ export const isSupportBleControl = () => {
|
|
|
101
101
|
}
|
|
102
102
|
return getDpValue(dpCodes.bleControl);
|
|
103
103
|
}
|
|
104
|
-
return
|
|
104
|
+
return hasBle;
|
|
105
105
|
};
|
|
106
106
|
const periodDpMap = [
|
|
107
107
|
{ name: "startHour" },
|
package/lib/state.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import config, { hasCapability } from "./config";
|
|
1
|
+
import config, { hasCapability, hasDp } from "./config";
|
|
2
2
|
import { onDpDataChange, onDeviceInfoUpdated, offDeviceInfoUpdated, offDpDataChange, registerDevice, getDeviceOnlineType, onOnlineChange, offOnlineChange, onBleChange, offBleChange, registerBleStatus, getDeviceInfo, onMqttMessage, registerMQTTDeviceListener, registerMQTTProtocolListener, offMqttMessage, onAppShow, onAppHide, } from "./utils/device";
|
|
3
3
|
import { getDeviceProperties } from "./api/setting";
|
|
4
4
|
import { parseCapabilities } from "./parse";
|
|
@@ -43,6 +43,7 @@ export const getDeviceStatus = () => {
|
|
|
43
43
|
type: isOnline ? "online" : "offline",
|
|
44
44
|
connectEnable: false,
|
|
45
45
|
onlineType: "unknown",
|
|
46
|
+
onlineTypes: [],
|
|
46
47
|
isWifiActive: wifiEnableState !== 1,
|
|
47
48
|
};
|
|
48
49
|
const isBleOnline = !isCloudOnline && isOnlineByType(onlineType, 2);
|
|
@@ -50,75 +51,62 @@ export const getDeviceStatus = () => {
|
|
|
50
51
|
const supportWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
51
52
|
const supportBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
52
53
|
const supportThread = hasCapability(ProductCommunicationType.THREAD);
|
|
53
|
-
const hasWirelessAwakeDp =
|
|
54
|
+
const hasWirelessAwakeDp = hasDp(dpCodes.wirelessAwake);
|
|
54
55
|
const wirelessAwake = getDpValue(dpCodes.wirelessAwake);
|
|
55
|
-
const isDeviceOnline = hasWirelessAwakeDp
|
|
56
|
-
? wirelessAwake && isCloudOnline
|
|
57
|
-
: isCloudOnline;
|
|
58
56
|
status.connectEnable = isSupportBleControl() && !isOnline;
|
|
59
57
|
if (supportWifi) {
|
|
60
58
|
if (!status.connectEnable) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
switch (communication.length) {
|
|
66
|
-
case 1: {
|
|
67
|
-
if (supportWifi) {
|
|
68
|
-
if (isDeviceOnline) {
|
|
69
|
-
status.type = "online";
|
|
70
|
-
status.onlineType = "cloud";
|
|
71
|
-
}
|
|
72
|
-
if (isSleep()) {
|
|
73
|
-
status.type = "sleep";
|
|
74
|
-
}
|
|
59
|
+
if (isCloudOnline) {
|
|
60
|
+
status.connectEnable =
|
|
61
|
+
hasWirelessAwakeDp && wirelessAwake === false && !isBleOnline;
|
|
75
62
|
}
|
|
76
|
-
else if (supportBle) {
|
|
77
|
-
status.connectEnable = true;
|
|
78
|
-
if (isOnline) {
|
|
79
|
-
status.type = "online";
|
|
80
|
-
status.onlineType = "ble";
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
break;
|
|
84
63
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
status.type = "online";
|
|
96
|
-
status.onlineType = "cloud";
|
|
97
|
-
}
|
|
98
|
-
if (isSleep()) {
|
|
99
|
-
status.type = "sleep";
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
if (supportThread && supportBle) {
|
|
104
|
-
const isShareThread = isShareThead();
|
|
105
|
-
if (isLocalOnline || (isShareThread && isOnline)) {
|
|
106
|
-
status.type = "online";
|
|
107
|
-
status.onlineType = "local";
|
|
108
|
-
}
|
|
109
|
-
else if (isCloudOnline) {
|
|
110
|
-
status.type = "online";
|
|
111
|
-
status.onlineType = "cloud";
|
|
112
|
-
}
|
|
113
|
-
else if (isBleOnline) {
|
|
114
|
-
status.type = "online";
|
|
115
|
-
status.onlineType = "ble";
|
|
64
|
+
}
|
|
65
|
+
if (isOnline) {
|
|
66
|
+
if (isCloudOnline) {
|
|
67
|
+
if (hasWirelessAwakeDp) {
|
|
68
|
+
if (wirelessAwake) {
|
|
69
|
+
status.onlineTypes.push("cloud");
|
|
116
70
|
}
|
|
117
71
|
else {
|
|
118
72
|
status.type = "offline";
|
|
119
73
|
}
|
|
120
74
|
}
|
|
121
|
-
|
|
75
|
+
else {
|
|
76
|
+
status.onlineTypes.push("cloud");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if (isLocalOnline) {
|
|
80
|
+
status.onlineTypes.push("local");
|
|
81
|
+
}
|
|
82
|
+
if (isBleOnline) {
|
|
83
|
+
status.onlineTypes.push("ble");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (status.onlineTypes.length === 0 && isOnline) {
|
|
87
|
+
status.onlineTypes.push("unknown");
|
|
88
|
+
}
|
|
89
|
+
if (supportThread && supportBle) {
|
|
90
|
+
const isShareThread = isShareThead();
|
|
91
|
+
if (isShareThread && isOnline) {
|
|
92
|
+
status.onlineTypes = ["local"];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (status.onlineTypes.includes("ble")) {
|
|
96
|
+
status.onlineType = "ble";
|
|
97
|
+
}
|
|
98
|
+
else if (status.onlineTypes.includes("cloud")) {
|
|
99
|
+
status.onlineType = "cloud";
|
|
100
|
+
}
|
|
101
|
+
else if (status.onlineTypes.includes("local")) {
|
|
102
|
+
status.onlineType = "local";
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
status.onlineType = "unknown";
|
|
106
|
+
}
|
|
107
|
+
if (!isOnline) {
|
|
108
|
+
if (isSleep()) {
|
|
109
|
+
status.type = "sleep";
|
|
122
110
|
}
|
|
123
111
|
}
|
|
124
112
|
if (status.type === "sleep") {
|
|
@@ -247,8 +235,7 @@ export const initState = async () => {
|
|
|
247
235
|
]);
|
|
248
236
|
config.imageAngle = rotateInfo.angle;
|
|
249
237
|
config.videoAngle = rotateInfo.actualAngle;
|
|
250
|
-
fetchDeviceProperties()
|
|
251
|
-
});
|
|
238
|
+
fetchDeviceProperties();
|
|
252
239
|
getDeviceAdvancedAbilities();
|
|
253
240
|
syncRemoteSerectKey();
|
|
254
241
|
setTimeout(() => {
|
package/lib/sync/user.js
CHANGED
|
@@ -1,44 +1,8 @@
|
|
|
1
1
|
import { getDeviceStatus } from "../state";
|
|
2
2
|
import { ProductCommunicationType } from "../constant";
|
|
3
3
|
import config, { hasCapability } from "../config";
|
|
4
|
-
import { getUsersSyncLockData
|
|
5
|
-
import
|
|
6
|
-
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
7
|
-
import { remove as removeBigMap, reportRemove as reportRemoveBigMap, } from "../config/dp-map/unlock-method-big";
|
|
8
|
-
import { remove as removeMap, reportRemove as reportRemoveMap, } from "../config/dp-map/unlock-method";
|
|
9
|
-
import { publishDps } from "../utils/publishDps";
|
|
10
|
-
const deleteUser = async (data) => {
|
|
11
|
-
const { admin, lockUserId, userId } = data;
|
|
12
|
-
const dpCode = config.supportBigData
|
|
13
|
-
? dpCodes.unlockMethodDelW
|
|
14
|
-
: dpCodes.unlockMethodDel;
|
|
15
|
-
const dpData = {
|
|
16
|
-
type: 0,
|
|
17
|
-
stage: 0,
|
|
18
|
-
admin: !!admin,
|
|
19
|
-
memberId: lockUserId,
|
|
20
|
-
unlockId: config.supportBigData ? 0xffff : 0xff,
|
|
21
|
-
category: 0,
|
|
22
|
-
};
|
|
23
|
-
await publishDps({
|
|
24
|
-
[dpCode]: dpUtils.format(dpData, (config.supportBigData ? removeBigMap : removeMap)),
|
|
25
|
-
}, {
|
|
26
|
-
checkReport: (dps) => {
|
|
27
|
-
if (dps[dpCode]) {
|
|
28
|
-
const dpValue = dpUtils.parse(dps[dpCode], (config.supportBigData
|
|
29
|
-
? reportRemoveBigMap
|
|
30
|
-
: reportRemoveMap));
|
|
31
|
-
if (dpValue.type === 0 &&
|
|
32
|
-
dpValue.status == 255 &&
|
|
33
|
-
dpValue.memberId === lockUserId) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return false;
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
await removeUser(config.devInfo.devId, userId);
|
|
41
|
-
};
|
|
4
|
+
import { getUsersSyncLockData } from "../api/user";
|
|
5
|
+
import { deleteUser } from "../utils/user";
|
|
42
6
|
let isSyncDone = false;
|
|
43
7
|
const syncDeleteUsers = async () => {
|
|
44
8
|
const deviceStatus = getDeviceStatus();
|
package/lib/temporary.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ interface CreateCustomParams {
|
|
|
7
7
|
export declare const createTempCustom: (params: CreateCustomParams) => Promise<TempPasswordResult>;
|
|
8
8
|
interface RemoveCustomProps {
|
|
9
9
|
unlockBindingId: string;
|
|
10
|
+
sn: number;
|
|
10
11
|
}
|
|
11
|
-
export declare const removeTempCustom: (params: RemoveCustomProps) => Promise<
|
|
12
|
+
export declare const removeTempCustom: (params: RemoveCustomProps) => Promise<true | undefined>;
|
|
12
13
|
interface UpdateTempPasswordParams {
|
|
13
14
|
unlockBindingId: string;
|
|
14
15
|
name: string;
|
package/lib/temporary.js
CHANGED
|
@@ -4,8 +4,8 @@ import { formatWeek, isUseNearChannel, parallelOnly, parseOfflinePassword, parse
|
|
|
4
4
|
import { LoopTypes } from "./utils/constant";
|
|
5
5
|
import { encrypt } from "./utils/device";
|
|
6
6
|
import { getError } from "./utils/errors";
|
|
7
|
-
import { addTempPwd as addTempPwdDpMap, reportAddTempPwd as reportAddTempPwdDpMap, } from "./config/dp-map/unlock-method";
|
|
8
|
-
import { addTempPwd as addTempPwdBigDpMap, reportAddTempPwd as reportAddTempPwdDBigpMap, } from "./config/dp-map/unlock-method-big";
|
|
7
|
+
import { addTempPwd as addTempPwdDpMap, reportAddTempPwd as reportAddTempPwdDpMap, removeTempPwd as removeTempPwdDpMap, reportRemoveTempPwd as reportRemoveTempPwdDpMap, } from "./config/dp-map/unlock-method";
|
|
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";
|
|
@@ -144,21 +144,49 @@ export const createTempCustom = parallelOnly(async (params) => {
|
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
catch (error) {
|
|
147
|
-
throw handleError(error);
|
|
147
|
+
throw handleError(error?.innerError ?? error);
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
});
|
|
151
151
|
export const removeTempCustom = async (params) => {
|
|
152
152
|
try {
|
|
153
|
-
|
|
153
|
+
await deleteTempPassword({
|
|
154
154
|
devId: config.devInfo.devId,
|
|
155
155
|
unlockBindingId: params.unlockBindingId,
|
|
156
156
|
symbolic: false,
|
|
157
157
|
dpTunnel: 2,
|
|
158
158
|
});
|
|
159
|
+
if (isUseNearChannel()) {
|
|
160
|
+
const dpCode = config.supportBigData
|
|
161
|
+
? dpCodes.tempPwdDelW
|
|
162
|
+
: dpCodes.tempPwdDel;
|
|
163
|
+
const dpData = {
|
|
164
|
+
unlockId: params.sn,
|
|
165
|
+
};
|
|
166
|
+
const result = await publishDps({
|
|
167
|
+
[dpCode]: dpUtils.format(dpData, (config.supportBigData
|
|
168
|
+
? removeTempPwdBigDpMap
|
|
169
|
+
: removeTempPwdDpMap)),
|
|
170
|
+
}, {
|
|
171
|
+
checkReport: (dpData) => {
|
|
172
|
+
const reportData = dpData[dpCode];
|
|
173
|
+
if (reportData) {
|
|
174
|
+
const data = dpUtils.parse(reportData, (config.supportBigData
|
|
175
|
+
? reportRemoveTempPwdBigDpMap
|
|
176
|
+
: reportRemoveTempPwdDpMap));
|
|
177
|
+
return data;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
if (result.status === 0) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
throw getError(1065);
|
|
186
|
+
}
|
|
159
187
|
}
|
|
160
188
|
catch (e) {
|
|
161
|
-
handleError(e);
|
|
189
|
+
handleError(e?.innerError ?? e);
|
|
162
190
|
}
|
|
163
191
|
};
|
|
164
192
|
export const updateTempCustom = async (params) => {
|
|
@@ -192,7 +220,7 @@ export const updateTempCustom = async (params) => {
|
|
|
192
220
|
});
|
|
193
221
|
}
|
|
194
222
|
catch (error) {
|
|
195
|
-
handleError(error);
|
|
223
|
+
handleError(error?.innerError ?? error);
|
|
196
224
|
}
|
|
197
225
|
};
|
|
198
226
|
const getOfflinePassword = async (params) => {
|
|
@@ -204,7 +232,7 @@ const getOfflinePassword = async (params) => {
|
|
|
204
232
|
};
|
|
205
233
|
}
|
|
206
234
|
catch (error) {
|
|
207
|
-
throw handleError(error);
|
|
235
|
+
throw handleError(error?.innerError ?? error);
|
|
208
236
|
}
|
|
209
237
|
};
|
|
210
238
|
export const createTempLimit = async (params) => {
|
|
@@ -472,7 +500,7 @@ const changePasswordPhase = async (unlockBindingId, phase) => {
|
|
|
472
500
|
});
|
|
473
501
|
}
|
|
474
502
|
catch (e) {
|
|
475
|
-
handleError(e);
|
|
503
|
+
handleError(e?.innerError ?? e);
|
|
476
504
|
}
|
|
477
505
|
return true;
|
|
478
506
|
};
|
|
@@ -554,7 +582,7 @@ export const saveTempOnlineUnlimited = async (params) => {
|
|
|
554
582
|
};
|
|
555
583
|
}
|
|
556
584
|
catch (error) {
|
|
557
|
-
throw handleError(error);
|
|
585
|
+
throw handleError(error?.innerError ?? error);
|
|
558
586
|
}
|
|
559
587
|
};
|
|
560
588
|
export const createTempOffline = async (params) => {
|
|
@@ -612,7 +640,7 @@ export const removeTempOnlineUnlimited = async (id) => {
|
|
|
612
640
|
});
|
|
613
641
|
}
|
|
614
642
|
catch (error) {
|
|
615
|
-
throw handleError(error);
|
|
643
|
+
throw handleError(error?.innerError ?? error);
|
|
616
644
|
}
|
|
617
645
|
};
|
|
618
646
|
const onLinePasswordStatusMap = {
|
|
@@ -646,7 +674,7 @@ export const getTempOnlineUnlimitedList = async () => {
|
|
|
646
674
|
return newPswList;
|
|
647
675
|
}
|
|
648
676
|
catch (error) {
|
|
649
|
-
throw handleError(error);
|
|
677
|
+
throw handleError(error?.innerError ?? error);
|
|
650
678
|
}
|
|
651
679
|
};
|
|
652
680
|
const offlinePasswordTypeMap = {
|
|
@@ -665,7 +693,7 @@ export const getTempOfflineEffectiveList = async (pwdTypeCode) => {
|
|
|
665
693
|
return offLineValidPswList;
|
|
666
694
|
}
|
|
667
695
|
catch (error) {
|
|
668
|
-
throw handleError(error);
|
|
696
|
+
throw handleError(error?.innerError ?? error);
|
|
669
697
|
}
|
|
670
698
|
};
|
|
671
699
|
export const getTempOfflineInvalidList = async (pwdTypeCode) => {
|
|
@@ -678,6 +706,6 @@ export const getTempOfflineInvalidList = async (pwdTypeCode) => {
|
|
|
678
706
|
return offLineFailurePswList;
|
|
679
707
|
}
|
|
680
708
|
catch (error) {
|
|
681
|
-
throw handleError(error);
|
|
709
|
+
throw handleError(error?.innerError ?? error);
|
|
682
710
|
}
|
|
683
711
|
};
|
package/lib/user.js
CHANGED
|
@@ -8,10 +8,12 @@ import DpUtils from "@ray-js/tuya-dp-transform";
|
|
|
8
8
|
import { getError } from "./utils/errors";
|
|
9
9
|
import { updateUserTimeSchedule, addNormalUser, removeNormalUser, } from "./api/user";
|
|
10
10
|
import { validConfigDpMap } from "./config/dp-map/common";
|
|
11
|
-
import { formatTimestampToMilliseconds, formatWeek, isAdmin, parseWeek, unlockMethodConfigs, validateEffectiveConfig, } from "./utils";
|
|
11
|
+
import { formatTimestampToMilliseconds, formatWeek, getPermanentSetting, isAdmin, isUseNearChannel, parseWeek, unlockMethodConfigs, validateEffectiveConfig, } from "./utils";
|
|
12
12
|
import { getCurrentHomeInfo, isSupportShortLink } from "./utils/device";
|
|
13
13
|
import { LoopTypes } from "./utils/constant";
|
|
14
14
|
import { getCurrentUser } from "./state";
|
|
15
|
+
import { deleteUser } from "./utils/user";
|
|
16
|
+
import { UserType } from "./constant";
|
|
15
17
|
const concactUserList = (list, result) => {
|
|
16
18
|
return list.reduce((acc, item) => {
|
|
17
19
|
const { timeScheduleInfo, unlockDetail, ...rest } = item;
|
|
@@ -134,24 +136,22 @@ export const updateUserLimitTime = async (params) => {
|
|
|
134
136
|
validNum: 0,
|
|
135
137
|
pwdLength: 0,
|
|
136
138
|
pwd: [],
|
|
137
|
-
validConfig:
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
: effective.expiredDate
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
endMinute: permanent ? 0 : expiredTime % 60,
|
|
154
|
-
},
|
|
139
|
+
validConfig: permanent
|
|
140
|
+
? getPermanentSetting()
|
|
141
|
+
: {
|
|
142
|
+
startTime: effective.effectiveDate,
|
|
143
|
+
endTime: effective.expiredDate,
|
|
144
|
+
loop: loopType,
|
|
145
|
+
loopConfig: 0,
|
|
146
|
+
weeks: effective?.repeat !== "week" || effective?.weeks === undefined
|
|
147
|
+
? [0, 0, 0, 0, 0, 0, 0]
|
|
148
|
+
: effective.weeks,
|
|
149
|
+
days: [],
|
|
150
|
+
startHour: Math.floor(effectiveTime / 60),
|
|
151
|
+
startMinute: effectiveTime % 60,
|
|
152
|
+
endHour: Math.floor(expiredTime / 60),
|
|
153
|
+
endMinute: expiredTime % 60,
|
|
154
|
+
},
|
|
155
155
|
};
|
|
156
156
|
const dpCode = config.supportBigData
|
|
157
157
|
? dpCodes.unlockMethodEditW
|
|
@@ -268,6 +268,17 @@ export const removeUser = async (userId) => {
|
|
|
268
268
|
if (!config.supportBigData) {
|
|
269
269
|
throw getError(1060);
|
|
270
270
|
}
|
|
271
|
+
const res = await getUserDetail({
|
|
272
|
+
devId: config.devInfo.devId,
|
|
273
|
+
userId,
|
|
274
|
+
});
|
|
275
|
+
if (isUseNearChannel()) {
|
|
276
|
+
return deleteUser({
|
|
277
|
+
userId,
|
|
278
|
+
lockUserId: res.lockUserId,
|
|
279
|
+
admin: res.userType === UserType.ADMIN || res.userType === UserType.OWNER,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
271
282
|
return removeNormalUser({
|
|
272
283
|
devId: config.devInfo.devId,
|
|
273
284
|
userId,
|
package/lib/utils/device.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare const setDeviceProperty: (devId: string, code: string, value: str
|
|
|
5
5
|
export declare const publishDeviceDps: (params: {
|
|
6
6
|
deviceId: string;
|
|
7
7
|
dps: Record<string, boolean | number | string>;
|
|
8
|
+
pipelines?: number[];
|
|
8
9
|
}) => Promise<unknown>;
|
|
9
10
|
export declare const registerDevice: (devIds: string[]) => void;
|
|
10
11
|
export declare const registerBleStatus: (devId: string) => void;
|
package/lib/utils/device.js
CHANGED
package/lib/utils/errors.js
CHANGED
|
@@ -63,6 +63,7 @@ const errors = {
|
|
|
63
63
|
1062: "Device does not support active connection",
|
|
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
|
+
1065: "Cloud side has been deleted, but device side synchronization deletion failed",
|
|
66
67
|
};
|
|
67
68
|
export const getError = (code, ...places) => {
|
|
68
69
|
if (errors[code]) {
|
package/lib/utils/index.js
CHANGED
package/lib/utils/publishDps.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getError } from "./errors";
|
|
|
7
7
|
export const publishDpsOnly = async (dpData) => {
|
|
8
8
|
const { devInfo, idsByCode } = config;
|
|
9
9
|
const option = {};
|
|
10
|
-
if (config.
|
|
10
|
+
if (config.deviceStatus.type === "offline") {
|
|
11
11
|
throw getError(1001);
|
|
12
12
|
}
|
|
13
13
|
if (isOnlineByType(config.onlineType, 2)) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { removeUser } from "../api/user";
|
|
2
|
+
import dpCodes from "../config/dp-code";
|
|
3
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
4
|
+
import { remove as removeBigMap, reportRemove as reportRemoveBigMap, } from "../config/dp-map/unlock-method-big";
|
|
5
|
+
import { remove as removeMap, reportRemove as reportRemoveMap, } from "../config/dp-map/unlock-method";
|
|
6
|
+
import { publishDps } from "../utils/publishDps";
|
|
7
|
+
import config from "../config";
|
|
8
|
+
export const deleteUser = async (data) => {
|
|
9
|
+
const { admin, lockUserId, userId } = data;
|
|
10
|
+
const dpCode = config.supportBigData
|
|
11
|
+
? dpCodes.unlockMethodDelW
|
|
12
|
+
: dpCodes.unlockMethodDel;
|
|
13
|
+
const dpData = {
|
|
14
|
+
type: 0,
|
|
15
|
+
stage: 0,
|
|
16
|
+
admin: !!admin,
|
|
17
|
+
memberId: lockUserId,
|
|
18
|
+
unlockId: config.supportBigData ? 0xffff : 0xff,
|
|
19
|
+
category: 0,
|
|
20
|
+
};
|
|
21
|
+
await publishDps({
|
|
22
|
+
[dpCode]: dpUtils.format(dpData, (config.supportBigData ? removeBigMap : removeMap)),
|
|
23
|
+
}, {
|
|
24
|
+
checkReport: (dps) => {
|
|
25
|
+
if (dps[dpCode]) {
|
|
26
|
+
const dpValue = dpUtils.parse(dps[dpCode], (config.supportBigData
|
|
27
|
+
? reportRemoveBigMap
|
|
28
|
+
: reportRemoveMap));
|
|
29
|
+
if (dpValue.type === 0 &&
|
|
30
|
+
dpValue.status == 255 &&
|
|
31
|
+
dpValue.memberId === lockUserId) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
await removeUser(config.devInfo.devId, userId);
|
|
39
|
+
};
|
package/package.json
CHANGED
package/lib/dp-interface.d.ts
DELETED
package/lib/dp-interface.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { fetchSyncUnlockMethodInfo } from "../api/lock";
|
|
2
|
-
import config from "../config";
|
|
3
|
-
import dpCodes from "../config/dp-code";
|
|
4
|
-
import { getCurrentUser } from "../state";
|
|
5
|
-
import { publishDps } from "../utils/publishDps";
|
|
6
|
-
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
7
|
-
import { reportSync as reportSyncMap } from "../config/dp-map/unlock-method";
|
|
8
|
-
import { reportSync as reportSyncBigMap } from "../config/dp-map/unlock-method-big";
|
|
9
|
-
let syncUnlockMethodFirst = true;
|
|
10
|
-
export const syncUnlockMethod = async () => {
|
|
11
|
-
syncUnlockMethodFirst = false;
|
|
12
|
-
const { allOpenDps = "" } = await getCurrentUser();
|
|
13
|
-
const { ins = "", distributed = false } = await fetchSyncUnlockMethodInfo({
|
|
14
|
-
devId: config.devInfo.devId,
|
|
15
|
-
dpIds: allOpenDps.split(","),
|
|
16
|
-
});
|
|
17
|
-
if (ins && distributed) {
|
|
18
|
-
const dpCode = config.supportBigData
|
|
19
|
-
? dpCodes.synchMethodW
|
|
20
|
-
: dpCodes.synchMethod;
|
|
21
|
-
await publishDps({ [dpCode]: ins }, {
|
|
22
|
-
checkReport: (dpData) => {
|
|
23
|
-
if (typeof dpData[dpCode] !== "undefined") {
|
|
24
|
-
const result = dpUtils.parse(dpData[dpCode], config.supportBigData ? reportSyncBigMap : reportSyncMap);
|
|
25
|
-
if (result.stage === 1) {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
export const autoSyncUnlockMethod = async () => {
|
|
35
|
-
try {
|
|
36
|
-
if (syncUnlockMethodFirst) {
|
|
37
|
-
await syncUnlockMethod();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
41
|
-
}
|
|
42
|
-
};
|