@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.
Files changed (86) hide show
  1. package/lib/api/index.js +13 -15
  2. package/lib/api/linkage.d.ts +0 -18
  3. package/lib/api/linkage.js +61 -81
  4. package/lib/api/lock.d.ts +0 -69
  5. package/lib/api/lock.js +91 -113
  6. package/lib/api/log.d.ts +0 -33
  7. package/lib/api/log.js +33 -38
  8. package/lib/api/setting.d.ts +0 -11
  9. package/lib/api/setting.js +17 -30
  10. package/lib/api/temp.d.ts +0 -48
  11. package/lib/api/temp.js +85 -115
  12. package/lib/api/user.d.ts +5 -54
  13. package/lib/api/user.js +40 -52
  14. package/lib/api/video.d.ts +0 -5
  15. package/lib/api/video.js +9 -15
  16. package/lib/config/dp-code/index.d.ts +0 -117
  17. package/lib/config/dp-code/index.js +79 -221
  18. package/lib/config/dp-map/common.d.ts +0 -3
  19. package/lib/config/dp-map/common.js +101 -116
  20. package/lib/config/dp-map/normal.js +29 -50
  21. package/lib/config/dp-map/open.d.ts +0 -16
  22. package/lib/config/dp-map/open.js +62 -63
  23. package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
  24. package/lib/config/dp-map/unlock-method-big.js +196 -233
  25. package/lib/config/dp-map/unlock-method.d.ts +0 -63
  26. package/lib/config/dp-map/unlock-method.js +189 -227
  27. package/lib/config/index.d.ts +0 -25
  28. package/lib/config/index.js +21 -54
  29. package/lib/constant.d.ts +12 -40
  30. package/lib/constant.js +83 -136
  31. package/lib/event.d.ts +0 -6
  32. package/lib/event.js +1 -8
  33. package/lib/index.d.ts +0 -7
  34. package/lib/index.js +45 -71
  35. package/lib/interface.d.ts +0 -523
  36. package/lib/interface.js +1 -1
  37. package/lib/linkage.d.ts +0 -18
  38. package/lib/linkage.js +125 -162
  39. package/lib/log.d.ts +0 -50
  40. package/lib/log.js +255 -290
  41. package/lib/media.d.ts +0 -34
  42. package/lib/media.js +6 -77
  43. package/lib/open.d.ts +0 -35
  44. package/lib/open.js +129 -224
  45. package/lib/other.d.ts +8 -26
  46. package/lib/other.js +107 -159
  47. package/lib/parse/index.d.ts +0 -4
  48. package/lib/parse/index.js +13 -19
  49. package/lib/signal.d.ts +0 -13
  50. package/lib/signal.js +17 -31
  51. package/lib/sleep.d.ts +0 -42
  52. package/lib/sleep.js +41 -98
  53. package/lib/state.d.ts +0 -38
  54. package/lib/state.js +223 -369
  55. package/lib/sync/remote-serect-key.d.ts +0 -4
  56. package/lib/sync/remote-serect-key.js +33 -49
  57. package/lib/sync/t0.d.ts +0 -3
  58. package/lib/sync/t0.js +14 -21
  59. package/lib/sync/temp.d.ts +0 -5
  60. package/lib/sync/temp.js +68 -77
  61. package/lib/sync/unlock-mothod.d.ts +0 -3
  62. package/lib/sync/unlock-mothod.js +28 -40
  63. package/lib/temporary.d.ts +0 -149
  64. package/lib/temporary.js +469 -593
  65. package/lib/unlock-method.d.ts +0 -185
  66. package/lib/unlock-method.js +479 -650
  67. package/lib/user.d.ts +2 -81
  68. package/lib/user.js +202 -336
  69. package/lib/utils/base64-to-hex.js +10 -10
  70. package/lib/utils/byte.d.ts +0 -16
  71. package/lib/utils/byte.js +57 -68
  72. package/lib/utils/constant.js +7 -11
  73. package/lib/utils/device.d.ts +46 -83
  74. package/lib/utils/device.js +294 -322
  75. package/lib/utils/errors.js +75 -122
  76. package/lib/utils/event.js +79 -135
  77. package/lib/utils/hex-to-base64.js +5 -5
  78. package/lib/utils/hex-to-bytes.d.ts +0 -5
  79. package/lib/utils/hex-to-bytes.js +10 -15
  80. package/lib/utils/index.d.ts +0 -42
  81. package/lib/utils/index.js +247 -377
  82. package/lib/utils/log.d.ts +1 -4
  83. package/lib/utils/log.js +71 -74
  84. package/lib/utils/publishDps.d.ts +0 -5
  85. package/lib/utils/publishDps.js +58 -80
  86. 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 { bytesToUint } from "./byte";
2
+ import base64ToHex from "./base64-to-hex";
7
3
  import hexToBytes from "./hex-to-bytes";
8
- const localRecordUnlock = [LocalOperateCategory.ADD_UNLOCK_METHOD, LocalOperateCategory.DELETE_UNLOCK_METHOD, LocalOperateCategory.MODIFY_UNLOCK_METHOD];
9
- const localRecordUserOperate = [LocalOperateCategory.ADD_USER, LocalOperateCategory.DELETE_USER];
10
- const unlockMethodMap = ["finger", "face", "password", "card", "fingerVein", "hand", "eye", "remoteControl"];
11
- export const handleLocalOperation = log => {
12
- if (!log) {
13
- return;
14
- }
15
- const {
16
- operClassify,
17
- userId,
18
- userType,
19
- operType,
20
- operDetail,
21
- toUserType,
22
- toUserId
23
- } = log;
24
- const data = hexToBytes(operDetail);
25
- const viewData = new DataView(data.buffer);
26
- /**
27
- * 开锁方式操作
28
- */
29
- if (localRecordUnlock.includes(operClassify)) {
30
- const unlockId = viewData.getInt16(0);
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
- category: operClassify,
33
- unlockMethod: unlockMethodMap[operType],
34
- unlockId,
35
- isRemoveAll: unlockId === 0xffff,
36
- userId,
37
- userType,
38
- toUserId,
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;
@@ -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
- * 执行下发 dp
14
- * @param dpData
15
- * @returns
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
- return acc;
37
- }, {});
38
- if (Object.keys(dps).length > 0) {
39
- await publishDeviceDps(_objectSpread({
40
- deviceId: devInfo.devId,
41
- dps
42
- }, option));
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
- } else {
67
- Object.keys(dpCodes).forEach(code => {
68
- const eixst = codes.indexOf(code);
69
- if (eixst > -1) {
70
- codes.splice(eixst, 1)[0];
71
- result[code] = dpCodes[code];
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
- // 所有 dp 都上报了
75
- if (codes.length === 0) {
76
- emitter.off(DPCHANGE, handleChangeDp);
77
- clearTimeout(timer);
78
- resolve(result);
79
- }
80
- }
81
- };
82
- // 超时处理
83
- const timer = setTimeout(() => {
84
- emitter.off(DPCHANGE, handleChangeDp);
85
- reject(getError(1002));
86
- }, timeout);
87
- emitter.on(DPCHANGE, handleChangeDp);
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": "ray build --type=component",
12
- "compile": "ray build --type=component",
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": [