@ray-js/lock-sdk 1.0.1 → 1.0.3-beta-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/index.js +13 -15
- package/lib/api/linkage.d.ts +0 -18
- package/lib/api/linkage.js +61 -81
- package/lib/api/lock.d.ts +0 -69
- package/lib/api/lock.js +91 -113
- package/lib/api/log.d.ts +0 -33
- package/lib/api/log.js +33 -38
- package/lib/api/setting.d.ts +0 -11
- package/lib/api/setting.js +17 -30
- package/lib/api/temp.d.ts +0 -48
- package/lib/api/temp.js +85 -115
- package/lib/api/user.d.ts +5 -54
- package/lib/api/user.js +40 -52
- package/lib/api/video.d.ts +0 -5
- package/lib/api/video.js +9 -15
- package/lib/config/dp-code/index.d.ts +0 -117
- package/lib/config/dp-code/index.js +79 -221
- package/lib/config/dp-map/common.d.ts +0 -3
- package/lib/config/dp-map/common.js +101 -116
- package/lib/config/dp-map/normal.js +29 -50
- package/lib/config/dp-map/open.d.ts +0 -16
- package/lib/config/dp-map/open.js +62 -63
- package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
- package/lib/config/dp-map/unlock-method-big.js +196 -233
- package/lib/config/dp-map/unlock-method.d.ts +0 -63
- package/lib/config/dp-map/unlock-method.js +189 -227
- package/lib/config/index.d.ts +0 -25
- package/lib/config/index.js +21 -54
- package/lib/constant.d.ts +12 -40
- package/lib/constant.js +83 -136
- package/lib/event.d.ts +0 -6
- package/lib/event.js +1 -8
- package/lib/index.d.ts +0 -7
- package/lib/index.js +45 -71
- package/lib/interface.d.ts +0 -523
- package/lib/interface.js +1 -1
- package/lib/linkage.d.ts +0 -18
- package/lib/linkage.js +125 -162
- package/lib/log.d.ts +0 -50
- package/lib/log.js +255 -290
- package/lib/media.d.ts +0 -34
- package/lib/media.js +6 -77
- package/lib/open.d.ts +0 -35
- package/lib/open.js +129 -224
- package/lib/other.d.ts +8 -26
- package/lib/other.js +107 -159
- package/lib/parse/index.d.ts +0 -4
- package/lib/parse/index.js +13 -19
- package/lib/signal.d.ts +0 -13
- package/lib/signal.js +17 -31
- package/lib/sleep.d.ts +0 -42
- package/lib/sleep.js +41 -98
- package/lib/state.d.ts +0 -38
- package/lib/state.js +223 -369
- package/lib/sync/remote-serect-key.d.ts +0 -4
- package/lib/sync/remote-serect-key.js +33 -49
- package/lib/sync/t0.d.ts +0 -3
- package/lib/sync/t0.js +14 -21
- package/lib/sync/temp.d.ts +0 -5
- package/lib/sync/temp.js +68 -77
- package/lib/sync/unlock-mothod.d.ts +0 -3
- package/lib/sync/unlock-mothod.js +28 -40
- package/lib/temporary.d.ts +0 -149
- package/lib/temporary.js +469 -593
- package/lib/unlock-method.d.ts +0 -185
- package/lib/unlock-method.js +479 -650
- package/lib/user.d.ts +2 -81
- package/lib/user.js +202 -336
- package/lib/utils/base64-to-hex.js +10 -10
- package/lib/utils/byte.d.ts +0 -16
- package/lib/utils/byte.js +57 -68
- package/lib/utils/constant.js +7 -11
- package/lib/utils/device.d.ts +46 -83
- package/lib/utils/device.js +294 -322
- package/lib/utils/errors.js +75 -122
- package/lib/utils/event.js +79 -135
- package/lib/utils/hex-to-base64.js +5 -5
- package/lib/utils/hex-to-bytes.d.ts +0 -5
- package/lib/utils/hex-to-bytes.js +10 -15
- package/lib/utils/index.d.ts +0 -42
- package/lib/utils/index.js +247 -377
- package/lib/utils/log.d.ts +1 -4
- package/lib/utils/log.js +71 -74
- package/lib/utils/publishDps.d.ts +0 -5
- package/lib/utils/publishDps.js +58 -80
- package/package.json +3 -4
package/lib/utils/log.js
CHANGED
|
@@ -1,78 +1,75 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 处理日志数据
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
1
|
import { LocalOperateCategory } from "../constant";
|
|
6
|
-
import
|
|
2
|
+
import base64ToHex from "./base64-to-hex";
|
|
7
3
|
import hexToBytes from "./hex-to-bytes";
|
|
8
|
-
const localRecordUnlock = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
const localRecordUnlock = [
|
|
5
|
+
LocalOperateCategory.ADD_UNLOCK_METHOD,
|
|
6
|
+
LocalOperateCategory.DELETE_UNLOCK_METHOD,
|
|
7
|
+
LocalOperateCategory.MODIFY_UNLOCK_METHOD,
|
|
8
|
+
];
|
|
9
|
+
const localRecordUserOperate = [
|
|
10
|
+
LocalOperateCategory.ADD_USER,
|
|
11
|
+
LocalOperateCategory.DELETE_USER,
|
|
12
|
+
];
|
|
13
|
+
const unlockMethodMap = [
|
|
14
|
+
"finger",
|
|
15
|
+
"face",
|
|
16
|
+
"password",
|
|
17
|
+
"card",
|
|
18
|
+
"fingerVein",
|
|
19
|
+
"hand",
|
|
20
|
+
"eye",
|
|
21
|
+
"remoteControl",
|
|
22
|
+
];
|
|
23
|
+
export const handleLocalOperation = (log, dpValue) => {
|
|
24
|
+
if (!log) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { operClassify, userId, userType, operType, operDetail, toUserType, toUserId, } = log;
|
|
28
|
+
if (localRecordUnlock.includes(operClassify)) {
|
|
29
|
+
const unlockId = Number(operDetail);
|
|
30
|
+
return {
|
|
31
|
+
category: operClassify,
|
|
32
|
+
unlockMethod: unlockMethodMap[operType],
|
|
33
|
+
unlockId,
|
|
34
|
+
isRemoveAll: unlockId === 0xffff,
|
|
35
|
+
userId,
|
|
36
|
+
userType,
|
|
37
|
+
toUserId,
|
|
38
|
+
toUserType,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
if (localRecordUserOperate.includes(operClassify)) {
|
|
42
|
+
return {
|
|
43
|
+
category: operClassify,
|
|
44
|
+
userId,
|
|
45
|
+
userType,
|
|
46
|
+
toUserId,
|
|
47
|
+
toUserType,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const allData = dpValue ? hexToBytes(base64ToHex(dpValue)) : new Uint8Array();
|
|
51
|
+
const dataView = new DataView(allData.buffer);
|
|
52
|
+
const dataLen = dataView.getInt8(5) - 3;
|
|
53
|
+
const originData = allData.slice(6, dataLen);
|
|
54
|
+
if (operClassify === LocalOperateCategory.SETTING) {
|
|
55
|
+
return {
|
|
56
|
+
category: LocalOperateCategory.SETTING,
|
|
57
|
+
userId,
|
|
58
|
+
userType,
|
|
59
|
+
toUserId,
|
|
60
|
+
toUserType,
|
|
61
|
+
type: operType,
|
|
62
|
+
data: +operDetail,
|
|
63
|
+
originData,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
31
66
|
return {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
toUserType
|
|
67
|
+
category: operClassify,
|
|
68
|
+
type: operType,
|
|
69
|
+
data: originData,
|
|
70
|
+
userId,
|
|
71
|
+
userType,
|
|
72
|
+
toUserId,
|
|
73
|
+
toUserType,
|
|
40
74
|
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 添加用户操作
|
|
44
|
-
*/
|
|
45
|
-
if (localRecordUserOperate.includes(operClassify)) {
|
|
46
|
-
return {
|
|
47
|
-
category: operClassify,
|
|
48
|
-
userId,
|
|
49
|
-
userType,
|
|
50
|
-
toUserId,
|
|
51
|
-
toUserType
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 本地设置操作
|
|
56
|
-
*/
|
|
57
|
-
if (operClassify === LocalOperateCategory.SETTING) {
|
|
58
|
-
return {
|
|
59
|
-
category: LocalOperateCategory.SETTING,
|
|
60
|
-
userId,
|
|
61
|
-
userType,
|
|
62
|
-
toUserId,
|
|
63
|
-
toUserType,
|
|
64
|
-
type: operType,
|
|
65
|
-
data: data.length <= 4 ? bytesToUint(data) : data,
|
|
66
|
-
originData: data
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
category: operClassify,
|
|
71
|
-
type: operType,
|
|
72
|
-
data: data,
|
|
73
|
-
userId,
|
|
74
|
-
userType,
|
|
75
|
-
toUserId,
|
|
76
|
-
toUserType
|
|
77
|
-
};
|
|
78
|
-
};
|
|
75
|
+
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
import { DpValue } from "../interface";
|
|
2
|
-
/**
|
|
3
|
-
* 执行下发 dp
|
|
4
|
-
* @param dpData
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
2
|
export declare const publishDpsOnly: (dpData: Record<string, string | number | boolean>) => Promise<void>;
|
|
8
3
|
export declare const publishDps: (dpData: Record<string, DpValue>, option?: {
|
|
9
4
|
timeout?: number;
|
package/lib/utils/publishDps.js
CHANGED
|
@@ -1,89 +1,67 @@
|
|
|
1
|
-
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
-
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
|
-
import "core-js/modules/esnext.iterator.for-each.js";
|
|
4
|
-
import "core-js/modules/esnext.iterator.reduce.js";
|
|
5
1
|
import config from "../config";
|
|
6
2
|
import { isOnlineByType } from ".";
|
|
7
3
|
import { publishDeviceDps } from "./device";
|
|
8
4
|
import emitter from "./event";
|
|
9
5
|
import { DPCHANGE } from "./constant";
|
|
10
6
|
import { getError } from "./errors";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
export const publishDpsOnly = async dpData => {
|
|
18
|
-
const {
|
|
19
|
-
devInfo,
|
|
20
|
-
idsByCode
|
|
21
|
-
} = config;
|
|
22
|
-
const option = {};
|
|
23
|
-
if (config.onlineType === 0) {
|
|
24
|
-
// 设备离线
|
|
25
|
-
throw getError(1001);
|
|
26
|
-
}
|
|
27
|
-
if (isOnlineByType(config.onlineType, 2)) {
|
|
28
|
-
// 由于设备只能支持wifi 或蓝牙在线,wifi 在线又可能为假在线,因此当蓝牙在线时,优先走蓝牙通道
|
|
29
|
-
option.pipelines = [3];
|
|
30
|
-
}
|
|
31
|
-
const dps = Object.keys(dpData).reduce((acc, key) => {
|
|
32
|
-
const id = idsByCode[key];
|
|
33
|
-
if (id) {
|
|
34
|
-
acc[id] = dpData[key];
|
|
7
|
+
export const publishDpsOnly = async (dpData) => {
|
|
8
|
+
const { devInfo, idsByCode } = config;
|
|
9
|
+
const option = {};
|
|
10
|
+
if (config.onlineType === 0) {
|
|
11
|
+
throw getError(1001);
|
|
35
12
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// 发送 dp 并等待上报
|
|
47
|
-
export const publishDps = async (dpData, option) => {
|
|
48
|
-
await publishDpsOnly(dpData);
|
|
49
|
-
// 默认 15s 超时
|
|
50
|
-
const {
|
|
51
|
-
timeout = 15000,
|
|
52
|
-
checkReport
|
|
53
|
-
} = option || {};
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
const codes = Object.keys(dpData);
|
|
56
|
-
const result = {};
|
|
57
|
-
const handleChangeDp = dpCodes => {
|
|
58
|
-
// 是否自定义检查上报数据
|
|
59
|
-
if (checkReport) {
|
|
60
|
-
const pass = checkReport(dpCodes);
|
|
61
|
-
if (pass) {
|
|
62
|
-
emitter.off(DPCHANGE, handleChangeDp);
|
|
63
|
-
clearTimeout(timer);
|
|
64
|
-
resolve(typeof pass !== "boolean" ? pass : dpCodes);
|
|
13
|
+
if (isOnlineByType(config.onlineType, 2)) {
|
|
14
|
+
option.pipelines = [3];
|
|
15
|
+
}
|
|
16
|
+
const dps = Object.keys(dpData).reduce((acc, key) => {
|
|
17
|
+
const id = idsByCode[key];
|
|
18
|
+
if (id) {
|
|
19
|
+
acc[id] = dpData[key];
|
|
65
20
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
21
|
+
return acc;
|
|
22
|
+
}, {});
|
|
23
|
+
if (Object.keys(dps).length > 0) {
|
|
24
|
+
await publishDeviceDps({
|
|
25
|
+
deviceId: devInfo.devId,
|
|
26
|
+
dps,
|
|
27
|
+
...option,
|
|
73
28
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const publishDps = async (dpData, option) => {
|
|
32
|
+
await publishDpsOnly(dpData);
|
|
33
|
+
const { timeout = 15000, checkReport } = option || {};
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
const codes = Object.keys(dpData);
|
|
36
|
+
const result = {};
|
|
37
|
+
const handleChangeDp = (dpCodes) => {
|
|
38
|
+
if (checkReport) {
|
|
39
|
+
const pass = checkReport(dpCodes);
|
|
40
|
+
if (pass) {
|
|
41
|
+
emitter.off(DPCHANGE, handleChangeDp);
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
resolve(typeof pass !== "boolean" ? pass : dpCodes);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
Object.keys(dpCodes).forEach((code) => {
|
|
48
|
+
const eixst = codes.indexOf(code);
|
|
49
|
+
if (eixst > -1) {
|
|
50
|
+
codes.splice(eixst, 1)[0];
|
|
51
|
+
result[code] = dpCodes[code];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (codes.length === 0) {
|
|
55
|
+
emitter.off(DPCHANGE, handleChangeDp);
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
resolve(result);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const timer = setTimeout(() => {
|
|
62
|
+
emitter.off(DPCHANGE, handleChangeDp);
|
|
63
|
+
reject(getError(1002));
|
|
64
|
+
}, timeout);
|
|
65
|
+
emitter.on(DPCHANGE, handleChangeDp);
|
|
66
|
+
});
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/lock-sdk",
|
|
3
|
-
"version": "1.0.1",
|
|
3
|
+
"version": "1.0.3-beta-1",
|
|
4
4
|
"files": [
|
|
5
5
|
"lib",
|
|
6
6
|
"LICENSE.md"
|
|
@@ -8,10 +8,9 @@
|
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"types": "lib/index.d.ts",
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "
|
|
12
|
-
"compile": "
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"compile": "tsc",
|
|
13
13
|
"lint": "eslint . --max-warnings 0",
|
|
14
|
-
"generate:component": "turbo gen react-component",
|
|
15
14
|
"check-types": "tsc --noEmit"
|
|
16
15
|
},
|
|
17
16
|
"maintainers": [
|