@ray-js/lock-sdk 1.1.1-beta.12 → 1.1.1-beta.13
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/capability.js +1 -1
- package/lib/offline-dps.js +4 -12
- package/lib/other.js +1 -1
- package/lib/state.js +5 -3
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/unlock-method.js +2 -6
- package/lib/sync/user.js +28 -25
- package/lib/unlock-method.js +6 -2
- package/package.json +1 -1
package/lib/capability.js
CHANGED
|
@@ -8,7 +8,7 @@ export const isActiveThread = async () => {
|
|
|
8
8
|
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
9
9
|
if (hasThread) {
|
|
10
10
|
const deviceStatus = getDeviceStatus();
|
|
11
|
-
if (deviceStatus.
|
|
11
|
+
if (deviceStatus.onlineTypes.includes("cloud") ||
|
|
12
12
|
config.communication.length === 1) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
package/lib/offline-dps.js
CHANGED
|
@@ -29,14 +29,14 @@ export const checkOfflineDpUpdate = async (dps, isForce) => {
|
|
|
29
29
|
if (!config.supportOfflineDps) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const hasOne = Object.keys(dps).some((code) => cache[code]?.pushStatus === false);
|
|
32
|
+
const hasOne = Object.keys(dps).some((code) => cache?.[code]?.pushStatus === false);
|
|
33
33
|
if (hasOne || isForce) {
|
|
34
34
|
const res = await getOfflineDps(true);
|
|
35
35
|
emitter.emit(OFFLINE_DPS_UPDATE, res);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
export const getOfflineDpCache = (code) => {
|
|
39
|
-
return cache[code];
|
|
39
|
+
return cache?.[code];
|
|
40
40
|
};
|
|
41
41
|
export const publishOfflineDps = async (dps) => {
|
|
42
42
|
const { devInfo, dpSchema } = config;
|
|
@@ -52,20 +52,12 @@ export const publishOfflineDps = async (dps) => {
|
|
|
52
52
|
return acc;
|
|
53
53
|
}, {});
|
|
54
54
|
await publishOfflineDpData(devInfo.devId, dpData);
|
|
55
|
-
|
|
56
|
-
await checkOfflineDpUpdate({}, true);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
}
|
|
55
|
+
checkOfflineDpUpdate({}, true);
|
|
60
56
|
};
|
|
61
57
|
export const clearOfflineDps = async () => {
|
|
62
58
|
const { devInfo } = config;
|
|
63
59
|
await clearOfflineDpData(devInfo.devId);
|
|
64
|
-
|
|
65
|
-
await checkOfflineDpUpdate({}, true);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
}
|
|
60
|
+
checkOfflineDpUpdate({}, true);
|
|
69
61
|
};
|
|
70
62
|
const OFFLINE_DPS_UPDATE = "offline_dps_update";
|
|
71
63
|
export const onOfflineDpsUpdate = (callback) => {
|
package/lib/other.js
CHANGED
|
@@ -260,7 +260,7 @@ export const connectDevice = async () => {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
if (isSupportBleControl()) {
|
|
263
|
-
if (deviceStatus.type === "online" && deviceStatus.
|
|
263
|
+
if (deviceStatus.type === "online" && deviceStatus.onlineTypes.includes("ble")) {
|
|
264
264
|
return true;
|
|
265
265
|
}
|
|
266
266
|
return await connectBle();
|
package/lib/state.js
CHANGED
|
@@ -243,12 +243,14 @@ export const initState = async () => {
|
|
|
243
243
|
fetchDeviceProperties();
|
|
244
244
|
getDeviceAdvancedAbilities();
|
|
245
245
|
syncRemoteSerectKey();
|
|
246
|
+
checkOfflineDpUpdate({}, true).then(() => {
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
syncOfflineDps();
|
|
249
|
+
}, 3000);
|
|
250
|
+
});
|
|
246
251
|
setTimeout(() => {
|
|
247
252
|
syncT0();
|
|
248
253
|
autoSyncUnlockMethod();
|
|
249
|
-
checkOfflineDpUpdate({}, true).then(() => {
|
|
250
|
-
syncOfflineDps();
|
|
251
|
-
});
|
|
252
254
|
}, 2000);
|
|
253
255
|
setTimeout(() => {
|
|
254
256
|
autoSyncTemp();
|
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;
|
|
@@ -32,11 +32,7 @@ export const syncUnlockMethod = async () => {
|
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
export const autoSyncUnlockMethod = async () => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
await syncUnlockMethod();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (e) {
|
|
35
|
+
if (syncUnlockMethodFirst) {
|
|
36
|
+
await syncUnlockMethod();
|
|
41
37
|
}
|
|
42
38
|
};
|
package/lib/sync/user.js
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
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 { onAppShow } from "../utils/device";
|
|
6
|
+
import { isUseNearChannel } from "../utils";
|
|
7
|
+
let isSyncing = false;
|
|
8
|
+
onAppShow(() => {
|
|
9
|
+
syncDeleteUsers();
|
|
10
|
+
});
|
|
7
11
|
const syncDeleteUsers = async () => {
|
|
8
12
|
const deviceStatus = getDeviceStatus();
|
|
9
13
|
if (deviceStatus.isWifiActive) {
|
|
10
14
|
return;
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
if (hasThread &&
|
|
14
|
-
(deviceStatus.onlineType === "local" || deviceStatus.onlineType === "cloud")) {
|
|
16
|
+
if (!isUseNearChannel()) {
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
|
-
if (
|
|
19
|
+
if (isSyncing)
|
|
18
20
|
return;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
isSyncing = true;
|
|
22
|
+
let count = 0;
|
|
23
|
+
const handleSync = async () => {
|
|
24
|
+
try {
|
|
25
|
+
const { removedUser = [] } = await getUsersSyncLockData(config.devInfo.devId);
|
|
26
|
+
await Promise.all(removedUser.map((item) => deleteUser(item).catch(() => { })));
|
|
27
|
+
isSyncing = false;
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
if (e?.innerError?.errorCode === "DEVICE_KEY_NOT_FOUND" && count < 3) {
|
|
31
|
+
count++;
|
|
32
|
+
setTimeout(async () => {
|
|
33
|
+
await handleSync();
|
|
34
|
+
}, 2000);
|
|
27
35
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
count++;
|
|
31
|
-
setTimeout(async () => {
|
|
32
|
-
await handleSync();
|
|
33
|
-
}, 2000);
|
|
34
|
-
}
|
|
36
|
+
else {
|
|
37
|
+
isSyncing = false;
|
|
35
38
|
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
handleSync();
|
|
39
42
|
};
|
|
40
43
|
export default syncDeleteUsers;
|
package/lib/unlock-method.js
CHANGED
|
@@ -20,7 +20,10 @@ const getAddUnlockError = (status) => {
|
|
|
20
20
|
if (status === 0xfe) {
|
|
21
21
|
return getError(1026);
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
...getError(1016),
|
|
25
|
+
devCode: status,
|
|
26
|
+
};
|
|
24
27
|
};
|
|
25
28
|
export const getUnlockMethodDetail = async (id) => {
|
|
26
29
|
const cloudData = await getUnlockMethodInfo({
|
|
@@ -338,7 +341,8 @@ const handleAddReport = async (dps) => {
|
|
|
338
341
|
};
|
|
339
342
|
}
|
|
340
343
|
}
|
|
341
|
-
catch {
|
|
344
|
+
catch (err) {
|
|
345
|
+
console.warn("AddUnlockMethod failed", err);
|
|
342
346
|
eventData = {
|
|
343
347
|
stage: "fail",
|
|
344
348
|
type,
|