@ray-js/lock-sdk 1.1.1-beta.2 → 1.1.1-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/index.d.ts +8 -0
- package/lib/api/index.js +10 -0
- package/lib/api/lock.d.ts +5 -0
- package/lib/api/lock.js +7 -0
- package/lib/api/user.d.ts +3 -17
- package/lib/api/user.js +5 -5
- package/lib/capability.js +45 -19
- package/lib/config/dp-map/common.js +1 -1
- package/lib/config/dp-map/unlock-method-big.js +1 -1
- package/lib/config/dp-map/unlock-method.d.ts +4 -4
- package/lib/config/dp-map/unlock-method.js +1 -1
- package/lib/config/index.d.ts +2 -1
- package/lib/config/index.js +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +7 -2
- package/lib/interface.d.ts +13 -1
- package/lib/log.js +16 -4
- package/lib/offline-dps.js +4 -12
- package/lib/open/ble-dedicated-dp.d.ts +4 -0
- package/lib/open/ble-dedicated-dp.js +148 -0
- package/lib/open/ble-remote-no-dp-key.d.ts +4 -0
- package/lib/open/ble-remote-no-dp-key.js +69 -0
- package/lib/open/report-status.d.ts +1 -0
- package/lib/open/report-status.js +23 -0
- package/lib/open.js +10 -10
- package/lib/other.d.ts +1 -0
- package/lib/other.js +10 -2
- package/lib/state.js +25 -15
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/temp.js +1 -1
- package/lib/sync/unlock-method.js +16 -16
- package/lib/sync/user.js +24 -25
- package/lib/temporary.js +15 -33
- package/lib/unlock-method.d.ts +3 -1
- package/lib/unlock-method.js +103 -18
- package/lib/user.d.ts +2 -2
- package/lib/user.js +81 -71
- package/lib/utils/device.d.ts +1 -0
- package/lib/utils/device.js +6 -0
- package/lib/utils/errors.d.ts +1 -0
- package/lib/utils/errors.js +37 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +15 -12
- package/package.json +1 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
|
+
import { getDoorKey } from "../api/lock";
|
|
3
|
+
import config, { hasDp } from "../config";
|
|
4
|
+
import dpCodes from "../config/dp-code";
|
|
5
|
+
import { open as openMap, reportOpen as reportOpenMap, } from "../config/dp-map/open";
|
|
6
|
+
import { getCurrentUser } from "../state";
|
|
7
|
+
import syncRemoteSerectKey from "../sync/remote-serect-key";
|
|
8
|
+
import { stringToBytes } from "../utils/byte";
|
|
9
|
+
import { decrypt } from "../utils/device";
|
|
10
|
+
import { publishDps } from "../utils/publishDps";
|
|
11
|
+
import { mapRemoteOpenReportStatus } from "./report-status";
|
|
12
|
+
export const createRemoteNoDpKeyBleCheckReport = (memberId) => {
|
|
13
|
+
return (dpData) => {
|
|
14
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
15
|
+
if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
|
|
16
|
+
return {
|
|
17
|
+
status: 0,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
|
|
22
|
+
const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
|
|
23
|
+
if (result.memberId === memberId) {
|
|
24
|
+
if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.warn("An incorrect member id was returned");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const executeBleRemoteNoDpKeyAction = async (isOpen, timeout, memberId) => {
|
|
37
|
+
await syncRemoteSerectKey();
|
|
38
|
+
let pw = "";
|
|
39
|
+
try {
|
|
40
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
41
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
await syncRemoteSerectKey(true);
|
|
45
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
46
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
47
|
+
}
|
|
48
|
+
const response = (await publishDps({
|
|
49
|
+
[dpCodes.remoteNoDpKey]: dpUtils.format({
|
|
50
|
+
status: Number(isOpen),
|
|
51
|
+
memberId,
|
|
52
|
+
key: stringToBytes(pw),
|
|
53
|
+
type: 3,
|
|
54
|
+
}, openMap),
|
|
55
|
+
}, {
|
|
56
|
+
timeout,
|
|
57
|
+
checkReport: createRemoteNoDpKeyBleCheckReport(memberId),
|
|
58
|
+
}));
|
|
59
|
+
if (response.status !== 0) {
|
|
60
|
+
throw mapRemoteOpenReportStatus(response.status);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export const getOpenDoorMemberId = async () => {
|
|
64
|
+
const currentUser = await getCurrentUser();
|
|
65
|
+
if (currentUser.lockUserId !== 0) {
|
|
66
|
+
return Number(currentUser.lockUserId);
|
|
67
|
+
}
|
|
68
|
+
return Number(currentUser.userId);
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mapRemoteOpenReportStatus: (status: number) => import("..").ErrorData;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getError } from "../utils/errors";
|
|
2
|
+
export const mapRemoteOpenReportStatus = (status) => {
|
|
3
|
+
let error = getError(1004);
|
|
4
|
+
switch (status) {
|
|
5
|
+
case 0x02:
|
|
6
|
+
error = getError(1005);
|
|
7
|
+
break;
|
|
8
|
+
case 0x03:
|
|
9
|
+
error = getError(1006);
|
|
10
|
+
break;
|
|
11
|
+
case 0x04:
|
|
12
|
+
error = getError(1007);
|
|
13
|
+
break;
|
|
14
|
+
case 0x05:
|
|
15
|
+
error = getError(1008);
|
|
16
|
+
break;
|
|
17
|
+
case 0x06:
|
|
18
|
+
error = getError(1070);
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
}
|
|
22
|
+
return error;
|
|
23
|
+
};
|
package/lib/open.js
CHANGED
|
@@ -42,18 +42,18 @@ export const checkRemoteEnabled = parallelMerge(async () => {
|
|
|
42
42
|
if (deviceStatus.type !== "online") {
|
|
43
43
|
throw getError(1001);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const isLocalOnline = deviceStatus.onlineTypes.length === 1 &&
|
|
46
|
+
deviceStatus.onlineTypes.includes("local");
|
|
47
|
+
const isThreadLocalOnline = hasThread && isLocalOnline;
|
|
48
|
+
if (isThreadLocalOnline || deviceStatus.onlineTypes.includes("ble")) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (isLocalOnline) {
|
|
52
|
+
throw getError(1064);
|
|
49
53
|
}
|
|
50
54
|
if (dpSchema[dpCodes.remoteNoDpKey] === undefined) {
|
|
51
55
|
throw getError(1045);
|
|
52
56
|
}
|
|
53
|
-
if ((hasThread && deviceStatus.onlineType === "local") ||
|
|
54
|
-
deviceStatus.onlineType === "ble") {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
57
|
if (!remoteOpenEnabled) {
|
|
58
58
|
throw getError(1046);
|
|
59
59
|
}
|
|
@@ -65,7 +65,7 @@ export const checkRemoteEnabled = parallelMerge(async () => {
|
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
const _doAction = async (isOpen, timeout) => {
|
|
68
|
-
const { devInfo,
|
|
68
|
+
const { devInfo, communication } = config;
|
|
69
69
|
await checkRemoteEnabled();
|
|
70
70
|
const deviceStatus = getDeviceStatus();
|
|
71
71
|
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
@@ -94,7 +94,7 @@ const _doAction = async (isOpen, timeout) => {
|
|
|
94
94
|
}
|
|
95
95
|
return false;
|
|
96
96
|
};
|
|
97
|
-
if (hasThread && deviceStatus.
|
|
97
|
+
if (hasThread && deviceStatus.onlineTypes.includes("local") && deviceStatus.onlineTypes.length === 1) {
|
|
98
98
|
await publishDps({ [dpCodes.matterLanUnlock]: isOpen }, {
|
|
99
99
|
checkReport: (dps) => {
|
|
100
100
|
return typeof dps[dpCodes.matterLanUnlock] !== "undefined";
|
package/lib/other.d.ts
CHANGED
|
@@ -27,4 +27,5 @@ export declare const connectDevice: () => Promise<unknown>;
|
|
|
27
27
|
export declare const gotoService: (params?: {
|
|
28
28
|
tab?: "cloudStorage" | "AI";
|
|
29
29
|
}) => Promise<unknown>;
|
|
30
|
+
export declare const validatePwdComplexity: (password: string) => Promise<boolean>;
|
|
30
31
|
export {};
|
package/lib/other.js
CHANGED
|
@@ -3,13 +3,14 @@ import config, { hasCapability, hasDp } from "./config";
|
|
|
3
3
|
import dpCodes from "./config/dp-code";
|
|
4
4
|
import { ProductCommunicationType } from "./constant";
|
|
5
5
|
import { getDeviceStatus, getDpValue } from "./state";
|
|
6
|
-
import { connectBLEDevice, getBLEOnlineState, navigateToMiniProgram, offBleChange, offOnlineChange, onBleChange, onOnlineChange, openPanel, } from "./utils/device";
|
|
6
|
+
import { connectBLEDevice, encrypt, getBLEOnlineState, navigateToMiniProgram, offBleChange, offOnlineChange, onBleChange, onOnlineChange, openPanel, } from "./utils/device";
|
|
7
7
|
import { getError } from "./utils/errors";
|
|
8
8
|
import { publishDps } from "./utils/publishDps";
|
|
9
9
|
import ipc from "./utils/ipc";
|
|
10
10
|
import { DPCHANGE } from "./utils/constant";
|
|
11
11
|
import emitter from "./utils/event";
|
|
12
12
|
import { getOfflineDpCache, publishOfflineDps } from "./offline-dps";
|
|
13
|
+
import { validatePasswordComplexity } from "./api/lock";
|
|
13
14
|
const { alarmLock, unlockFingerprint, unlockPassword, unlockCard, unlockKey, unlockPhoneRemote, unlockTemporary, unlockDynamic, unlockFace, unlockHand, unlockEye, unlockFingerVein, unlockInside, doorOpened, unlockApp, unlockOfflinePd, openInside, lockRecord, unlockDoubleKit, lockLocalRecord, wirelessAwake, } = dpCodes;
|
|
14
15
|
const abilityMap = {
|
|
15
16
|
backHome: "supportBackHome",
|
|
@@ -259,7 +260,7 @@ export const connectDevice = async () => {
|
|
|
259
260
|
}
|
|
260
261
|
}
|
|
261
262
|
if (isSupportBleControl()) {
|
|
262
|
-
if (deviceStatus.type === "online" && deviceStatus.
|
|
263
|
+
if (deviceStatus.type === "online" && deviceStatus.onlineTypes.includes("ble")) {
|
|
263
264
|
return true;
|
|
264
265
|
}
|
|
265
266
|
return await connectBle();
|
|
@@ -281,3 +282,10 @@ export const gotoService = async (params) => {
|
|
|
281
282
|
});
|
|
282
283
|
});
|
|
283
284
|
};
|
|
285
|
+
export const validatePwdComplexity = async (password) => {
|
|
286
|
+
const encryptedPassword = await encrypt(config.devInfo.devId, password);
|
|
287
|
+
return validatePasswordComplexity({
|
|
288
|
+
devId: config.devInfo.devId,
|
|
289
|
+
password: encryptedPassword,
|
|
290
|
+
});
|
|
291
|
+
};
|
package/lib/state.js
CHANGED
|
@@ -38,7 +38,7 @@ const updateOnlineType = async () => {
|
|
|
38
38
|
updateDeviceStatus();
|
|
39
39
|
};
|
|
40
40
|
export const getDeviceStatus = () => {
|
|
41
|
-
const { onlineType,
|
|
41
|
+
const { onlineType, devInfo: { isCloudOnline, isOnline, wifiEnableState }, } = config;
|
|
42
42
|
const status = {
|
|
43
43
|
type: isOnline ? "online" : "offline",
|
|
44
44
|
connectEnable: false,
|
|
@@ -46,7 +46,7 @@ export const getDeviceStatus = () => {
|
|
|
46
46
|
onlineTypes: [],
|
|
47
47
|
isWifiActive: wifiEnableState !== 1,
|
|
48
48
|
};
|
|
49
|
-
const isBleOnline =
|
|
49
|
+
const isBleOnline = isOnlineByType(onlineType, 2);
|
|
50
50
|
const isLocalOnline = !isCloudOnline && isOnlineByType(onlineType, 1);
|
|
51
51
|
const supportWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
52
52
|
const supportBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
@@ -199,24 +199,29 @@ export const permissions = [
|
|
|
199
199
|
"everyOne",
|
|
200
200
|
"noOne",
|
|
201
201
|
];
|
|
202
|
+
var DeviceProperties;
|
|
203
|
+
(function (DeviceProperties) {
|
|
204
|
+
DeviceProperties["REMOTE_UNLOCK_AUTH"] = "REMOTE_UNLOCK_AUTH";
|
|
205
|
+
DeviceProperties["UNLOCK_PHONE_REMOTE"] = "UNLOCK_PHONE_REMOTE";
|
|
206
|
+
})(DeviceProperties || (DeviceProperties = {}));
|
|
207
|
+
const propsList = [
|
|
208
|
+
DeviceProperties.REMOTE_UNLOCK_AUTH,
|
|
209
|
+
DeviceProperties.UNLOCK_PHONE_REMOTE,
|
|
210
|
+
];
|
|
202
211
|
const fetchDeviceProperties = async (isForce) => {
|
|
203
212
|
let result = null;
|
|
204
213
|
if (isForce) {
|
|
205
|
-
result = await getDeviceProperties(config.devInfo.devId,
|
|
206
|
-
"REMOTE_UNLOCK_AUTH",
|
|
207
|
-
"UNLOCK_PHONE_REMOTE",
|
|
208
|
-
]);
|
|
214
|
+
result = await getDeviceProperties(config.devInfo.devId, propsList);
|
|
209
215
|
}
|
|
210
216
|
else {
|
|
211
217
|
result = await getDataWithPreFetch("getDeviceProperties", () => {
|
|
212
|
-
return getDeviceProperties(config.devInfo.devId,
|
|
213
|
-
"REMOTE_UNLOCK_AUTH",
|
|
214
|
-
"UNLOCK_PHONE_REMOTE",
|
|
215
|
-
]);
|
|
218
|
+
return getDeviceProperties(config.devInfo.devId, propsList);
|
|
216
219
|
});
|
|
217
220
|
}
|
|
218
|
-
config.remoteOpenEnabled =
|
|
219
|
-
|
|
221
|
+
config.remoteOpenEnabled =
|
|
222
|
+
result[DeviceProperties.UNLOCK_PHONE_REMOTE] === "true";
|
|
223
|
+
config.remoteOpenPermission =
|
|
224
|
+
permissions[+result[DeviceProperties.REMOTE_UNLOCK_AUTH] || 0];
|
|
220
225
|
};
|
|
221
226
|
export const initState = async () => {
|
|
222
227
|
const { devInfo: { dps, devId }, dpSchema, } = config;
|
|
@@ -238,12 +243,14 @@ export const initState = async () => {
|
|
|
238
243
|
fetchDeviceProperties();
|
|
239
244
|
getDeviceAdvancedAbilities();
|
|
240
245
|
syncRemoteSerectKey();
|
|
246
|
+
checkOfflineDpUpdate({}, true).then(() => {
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
syncOfflineDps();
|
|
249
|
+
}, 3000);
|
|
250
|
+
});
|
|
241
251
|
setTimeout(() => {
|
|
242
252
|
syncT0();
|
|
243
253
|
autoSyncUnlockMethod();
|
|
244
|
-
checkOfflineDpUpdate({}, true).then(() => {
|
|
245
|
-
syncOfflineDps();
|
|
246
|
-
});
|
|
247
254
|
}, 2000);
|
|
248
255
|
setTimeout(() => {
|
|
249
256
|
autoSyncTemp();
|
|
@@ -290,6 +297,9 @@ const handleAppShow = () => {
|
|
|
290
297
|
getCurrentUser(true);
|
|
291
298
|
fetchDeviceProperties();
|
|
292
299
|
checkOfflineDpUpdate({}, true);
|
|
300
|
+
setTimeout(() => {
|
|
301
|
+
syncDeleteUsers();
|
|
302
|
+
}, 1000);
|
|
293
303
|
};
|
|
294
304
|
const handleAppHide = () => { };
|
|
295
305
|
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;
|
package/lib/sync/temp.js
CHANGED
|
@@ -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,39 @@
|
|
|
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
|
-
|
|
17
|
+
isSyncing = true;
|
|
18
|
+
let count = 0;
|
|
19
|
+
const handleSync = async () => {
|
|
20
|
+
try {
|
|
21
|
+
const { removedUser = [] } = await getUsersSyncLockData(config.devInfo.devId);
|
|
22
|
+
await Promise.all(removedUser.map((item) => deleteUser(item).catch(() => { })));
|
|
23
|
+
isSyncing = false;
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
if (e?.innerError?.errorCode === "DEVICE_KEY_NOT_FOUND" && count < 3) {
|
|
27
|
+
count++;
|
|
28
|
+
setTimeout(async () => {
|
|
29
|
+
await handleSync();
|
|
30
|
+
}, 2000);
|
|
27
31
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
count++;
|
|
31
|
-
setTimeout(async () => {
|
|
32
|
-
await handleSync();
|
|
33
|
-
}, 2000);
|
|
34
|
-
}
|
|
32
|
+
else {
|
|
33
|
+
isSyncing = false;
|
|
35
34
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
handleSync();
|
|
39
38
|
};
|
|
40
39
|
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
|
};
|
|
@@ -83,7 +69,7 @@ export const createTempCustom = parallelOnly(async (params) => {
|
|
|
83
69
|
endTime: effective.expiredDate,
|
|
84
70
|
loop: loopType,
|
|
85
71
|
loopConfig: 0,
|
|
86
|
-
weeks: effective.weeks
|
|
72
|
+
weeks: effective.weeks ? effective.weeks : [0, 0, 0, 0, 0, 0, 0],
|
|
87
73
|
days: [],
|
|
88
74
|
startHour: Math.floor(effectiveTime / 60),
|
|
89
75
|
startMinute: effectiveTime % 60,
|
|
@@ -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.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ErrorData, UnBindUnlockMethodGroup, UnlockMethodDetail, UnlockMethodType } from "./interface";
|
|
1
|
+
import { ErrorData, UnBindUnlockMethodGroup, UnlockGuide, UnlockMethodDetail, UnlockMethodType } from "./interface";
|
|
2
2
|
export interface SpecialUnlockMethodInfo {
|
|
3
3
|
appSend?: boolean;
|
|
4
|
+
msgSend?: boolean;
|
|
4
5
|
msgPhone?: string;
|
|
5
6
|
verifyCode?: string;
|
|
6
7
|
countryCode?: string;
|
|
@@ -85,4 +86,5 @@ export type AddUnlockMethodEvent = StepEvent | SuccessEvent | ErrorEvent;
|
|
|
85
86
|
export type AddUnlockMethodListener = (event: AddUnlockMethodEvent) => void;
|
|
86
87
|
export declare const onAddUnlockMethod: (listener: AddUnlockMethodListener) => void;
|
|
87
88
|
export declare const offAddUnlockMethod: (listener: AddUnlockMethodListener) => void;
|
|
89
|
+
export declare const getUnlockGuide: (type: UnlockMethodType) => Promise<UnlockGuide | null>;
|
|
88
90
|
export {};
|