@ray-js/lock-sdk 1.0.1 → 1.0.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.
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 +0 -24
  46. package/lib/other.js +98 -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/interface.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/lib/linkage.d.ts CHANGED
@@ -1,26 +1,8 @@
1
- /**
2
- * 获取剩余通知次数
3
- * @returns {Promise<{message: number, phone: number}>}
4
- */
5
1
  export declare const getRemainingInfo: () => Promise<{
6
2
  message: number;
7
3
  phone: number;
8
4
  }>;
9
- /**
10
- * 获取门铃通知服务信息
11
- * @returns {Promise<boolean>}
12
- */
13
5
  export declare const getDoorbellService: () => Promise<import("./api/linkage").LinkageRule | undefined>;
14
- /**
15
- * 启用门铃通知服务
16
- * 注意: 首次开通时,会先进入创建动作的页面,创建完成后,会自动启用门铃通知服务
17
- */
18
6
  export declare const enableDoorbellService: () => Promise<void>;
19
- /**
20
- * 禁用门铃通知服务
21
- */
22
7
  export declare const disableDoorbellService: () => Promise<void>;
23
- /**
24
- * 去配置门铃通知服务
25
- */
26
8
  export declare const toSetDoorbellService: () => Promise<void>;
package/lib/linkage.js CHANGED
@@ -1,180 +1,143 @@
1
- import "core-js/modules/esnext.iterator.constructor.js";
2
- import "core-js/modules/esnext.iterator.find.js";
3
- import "core-js/modules/esnext.iterator.map.js";
4
- import { disableLinkage, enableLinkage, getLinkageList, getRemainingMessage, getRemainingPhone, saveLinkage } from "./api/linkage";
1
+ import { disableLinkage, enableLinkage, getLinkageList, getRemainingMessage, getRemainingPhone, saveLinkage, } from "./api/linkage";
5
2
  import config from "./config";
6
3
  import { getHomeInfo } from "./utils";
7
4
  import { createAction, editAction } from "./utils/device";
8
5
  import { getError } from "./utils/errors";
9
6
  const DOORBELL_RING_TYPE = "doorbell_ring";
10
- const TARGET_KEY = "appPushTrigger"; // 用于从筛选出的配置对象中 筛选出需要的规则
11
- const ACTION_TYPE = "kafkaSend"; // 新增的action类型
12
- const MOBILE_TYPE = "mobileVoiceSend"; // actions对象的actionExecutor属性的类型
13
- const MESSAGE_TYPE = "smsSend"; // actions对象的actionExecutor属性的类型
14
-
15
- /**
16
- * 获取剩余通知次数
17
- * @returns {Promise<{message: number, phone: number}>}
18
- */
7
+ const TARGET_KEY = "appPushTrigger";
8
+ const ACTION_TYPE = "kafkaSend";
9
+ const MOBILE_TYPE = "mobileVoiceSend";
10
+ const MESSAGE_TYPE = "smsSend";
19
11
  export const getRemainingInfo = async () => {
20
- const homeInfo = await getHomeInfo();
21
- const [message, phone] = await Promise.all([getRemainingMessage(homeInfo.homeId), getRemainingPhone(homeInfo.homeId)]);
22
- return {
23
- message,
24
- phone
25
- };
12
+ const homeInfo = await getHomeInfo();
13
+ const [message, phone] = await Promise.all([
14
+ getRemainingMessage(homeInfo.homeId),
15
+ getRemainingPhone(homeInfo.homeId),
16
+ ]);
17
+ return {
18
+ message,
19
+ phone,
20
+ };
26
21
  };
27
-
28
- /**
29
- * 获取门铃通知服务信息
30
- * @returns {Promise<boolean>}
31
- */
32
22
  export const getDoorbellService = async () => {
33
- const homeInfo = await getHomeInfo();
34
- const list = await getLinkageList(config.devInfo.devId, homeInfo.homeId);
35
- return list.find(item => item.code === DOORBELL_RING_TYPE && item.ruleId);
23
+ const homeInfo = await getHomeInfo();
24
+ const list = await getLinkageList(config.devInfo.devId, homeInfo.homeId);
25
+ return list.find((item) => item.code === DOORBELL_RING_TYPE && item.ruleId);
36
26
  };
37
27
  const createDoorbellService = async () => {
38
- const actions = await createAction({
39
- createType: "remind",
40
- smartType: "auto"
41
- });
42
- await saveDoorbellService(actions);
28
+ const actions = await createAction({
29
+ createType: "remind",
30
+ smartType: "auto",
31
+ });
32
+ await saveDoorbellService(actions);
43
33
  };
44
- const saveDoorbellService = async actions => {
45
- const homeInfo = await getHomeInfo();
46
- // 保存配置
47
- saveLinkage({
48
- devId: config.devInfo.devId,
49
- ownerId: homeInfo.homeId,
50
- name: "doorbell",
51
- enabled: true,
52
- extraInfo: {
53
- code: DOORBELL_RING_TYPE
54
- },
55
- bizType: "3",
56
- logicRuleList: [{
57
- name: "doorbell",
58
- // 规则名称
59
- matchType: 2,
60
- // MatchType枚举,1:任意条件触发,2:全部条件满足触发,3:通过expr来判断整个条件的匹配情况
61
- enabled: true,
62
- // 规则启用/禁用
63
- scenarioRule: false,
64
- // 是否在场景列表中展示
65
- preConditions: [],
66
- coverIcon: "",
67
- displayColor: "0084FF",
68
- background: "",
69
- conditions: [{
70
- entityType: 23,
71
- // entityType=23,表示kafka 消息触发类型
72
- entityId: config.devInfo.devId,
73
- // 可以是设备ID,或者产品id等,根据实际的业务需求来
74
- entitySubIds: "",
75
- // 无 根据实际的需求来 可以是dpIds
76
- iconUrl: "",
77
- // 图片
78
- expr: [],
79
- // 为空 传递JSONArray
34
+ const saveDoorbellService = async (actions) => {
35
+ const homeInfo = await getHomeInfo();
36
+ saveLinkage({
37
+ devId: config.devInfo.devId,
38
+ ownerId: homeInfo.homeId,
39
+ name: "doorbell",
40
+ enabled: true,
80
41
  extraInfo: {
81
- businessType: DOORBELL_RING_TYPE // 门铃呼叫的43协议
82
- }
83
- }],
84
- actions: actions.map(item => {
85
- // 电话提醒处理
86
- if ((item === null || item === void 0 ? void 0 : item.actionExecutor) === MOBILE_TYPE) {
87
- const executorProperty = {
88
- topic: 1,
89
- customParameters: {
90
- type: 1
91
- }
92
- };
93
- return {
94
- actionExecutor: ACTION_TYPE,
95
- entityName: "notify_phone",
96
- // 根据实际的业务来,作为面板展示使用
97
- extraProperty: executorProperty,
98
- executorProperty
99
- };
100
- }
101
- // 短信提醒处理
102
- if ((item === null || item === void 0 ? void 0 : item.actionExecutor) === MESSAGE_TYPE) {
103
- const executorProperty = {
104
- topic: 2,
105
- customParameters: {
106
- type: 2
107
- }
108
- };
109
- return {
110
- actionExecutor: ACTION_TYPE,
111
- entityName: "notify_message",
112
- // 根据实际的业务来,作为面板展示使用
113
- extraProperty: executorProperty,
114
- executorProperty
115
- };
116
- }
117
- return item;
118
- })
119
- }]
120
- }, homeInfo.homeId);
42
+ code: DOORBELL_RING_TYPE,
43
+ },
44
+ bizType: "3",
45
+ logicRuleList: [
46
+ {
47
+ name: "doorbell",
48
+ matchType: 2,
49
+ enabled: true,
50
+ scenarioRule: false,
51
+ preConditions: [],
52
+ coverIcon: "",
53
+ displayColor: "0084FF",
54
+ background: "",
55
+ conditions: [
56
+ {
57
+ entityType: 23,
58
+ entityId: config.devInfo.devId,
59
+ entitySubIds: "",
60
+ iconUrl: "",
61
+ expr: [],
62
+ extraInfo: {
63
+ businessType: DOORBELL_RING_TYPE,
64
+ },
65
+ },
66
+ ],
67
+ actions: actions.map((item) => {
68
+ if (item?.actionExecutor === MOBILE_TYPE) {
69
+ const executorProperty = {
70
+ topic: 1,
71
+ customParameters: {
72
+ type: 1,
73
+ },
74
+ };
75
+ return {
76
+ actionExecutor: ACTION_TYPE,
77
+ entityName: "notify_phone",
78
+ extraProperty: executorProperty,
79
+ executorProperty,
80
+ };
81
+ }
82
+ if (item?.actionExecutor === MESSAGE_TYPE) {
83
+ const executorProperty = {
84
+ topic: 2,
85
+ customParameters: {
86
+ type: 2,
87
+ },
88
+ };
89
+ return {
90
+ actionExecutor: ACTION_TYPE,
91
+ entityName: "notify_message",
92
+ extraProperty: executorProperty,
93
+ executorProperty,
94
+ };
95
+ }
96
+ return item;
97
+ }),
98
+ },
99
+ ],
100
+ }, homeInfo.homeId);
121
101
  };
122
-
123
- /**
124
- * 启用门铃通知服务
125
- * 注意: 首次开通时,会先进入创建动作的页面,创建完成后,会自动启用门铃通知服务
126
- */
127
102
  export const enableDoorbellService = async () => {
128
- const homeInfo = await getHomeInfo();
129
- const service = await getDoorbellService();
130
- if (service && service.ruleId) {
131
- await enableLinkage(service.ruleId, homeInfo.homeId);
132
- } else {
133
- await createDoorbellService();
134
- }
103
+ const homeInfo = await getHomeInfo();
104
+ const service = await getDoorbellService();
105
+ if (service && service.ruleId) {
106
+ await enableLinkage(service.ruleId, homeInfo.homeId);
107
+ }
108
+ else {
109
+ await createDoorbellService();
110
+ }
135
111
  };
136
-
137
- /**
138
- * 禁用门铃通知服务
139
- */
140
112
  export const disableDoorbellService = async () => {
141
- const homeInfo = await getHomeInfo();
142
- const service = await getDoorbellService();
143
- if (service && service.ruleId) {
144
- await disableLinkage(service.ruleId, homeInfo.homeId);
145
- return;
146
- }
147
- throw getError(1059);
113
+ const homeInfo = await getHomeInfo();
114
+ const service = await getDoorbellService();
115
+ if (service && service.ruleId) {
116
+ await disableLinkage(service.ruleId, homeInfo.homeId);
117
+ return;
118
+ }
119
+ throw getError(1059);
148
120
  };
149
-
150
- /**
151
- * 去配置门铃通知服务
152
- */
153
121
  export const toSetDoorbellService = async () => {
154
- const service = await getDoorbellService();
155
- if (service && service.ruleId && service.ruleVO) {
156
- const findIndex = service.ruleVO.actions.findIndex(item => item.actionExecutor === TARGET_KEY || item.actionExecutor === ACTION_TYPE);
157
- // 去编辑
158
- const actions = await editAction({
159
- editIndex: findIndex > -1 ? findIndex : 0,
160
- smartType: "auto",
161
- actionArray: service.ruleVO.actions.map(item => {
162
- if (item.actionExecutor === ACTION_TYPE) {
163
- const {
164
- customParameters: {
165
- type
166
- }
167
- } = item.executorProperty;
168
- const actionType = type === 1 ? MOBILE_TYPE : MESSAGE_TYPE;
169
- // eslint-disable-next-line no-param-reassign
170
- item.actionExecutor = actionType;
171
- }
172
- return item;
173
- })
174
- });
175
- await saveDoorbellService(actions);
176
- } else {
177
- // 去创建
178
- await createDoorbellService();
179
- }
180
- };
122
+ const service = await getDoorbellService();
123
+ if (service && service.ruleId && service.ruleVO) {
124
+ const findIndex = service.ruleVO.actions.findIndex((item) => item.actionExecutor === TARGET_KEY ||
125
+ item.actionExecutor === ACTION_TYPE);
126
+ const actions = await editAction({
127
+ editIndex: findIndex > -1 ? findIndex : 0,
128
+ smartType: "auto",
129
+ actionArray: service.ruleVO.actions.map((item) => {
130
+ if (item.actionExecutor === ACTION_TYPE) {
131
+ const { customParameters: { type }, } = item.executorProperty;
132
+ const actionType = type === 1 ? MOBILE_TYPE : MESSAGE_TYPE;
133
+ item.actionExecutor = actionType;
134
+ }
135
+ return item;
136
+ }),
137
+ });
138
+ await saveDoorbellService(actions);
139
+ }
140
+ else {
141
+ await createDoorbellService();
142
+ }
143
+ };
package/lib/log.d.ts CHANGED
@@ -1,86 +1,36 @@
1
1
  import { AlbumMessage, LogData, UnlockMethodType } from "./interface";
2
- /**
3
- * 开锁 DP 映射开锁类型
4
- */
5
2
  export declare const unlockDp2Type: Record<string, UnlockMethodType>;
6
- /**
7
- * 获取最近2条记录
8
- */
9
3
  export declare const getLatestLogs: () => Promise<{
10
4
  data: LogData[];
11
5
  unreadCount: number;
12
6
  }>;
13
- /**
14
- * 注册通知可刷新日志事件
15
- * @param cb
16
- */
17
7
  export declare const onLogsRefresh: (cb: () => void) => void;
18
- /**
19
- * 注销通知可刷新日志事件
20
- * @param cb
21
- */
22
8
  export declare const offLogsRefresh: (cb: () => void) => void;
23
9
  interface GetLogsParams {
24
- /**
25
- * 页码,默认 1
26
- */
27
10
  page?: number;
28
- /**
29
- * 每页数量,默认为 50
30
- */
31
11
  pageSize?: number;
32
12
  }
33
13
  export declare const openDps: string[];
34
- /**
35
- * 获取日志记录列表
36
- * @param {GetLogsParams} params
37
- */
38
14
  export declare const getLogs: (params?: GetLogsParams) => Promise<{
39
15
  list: LogData[];
40
16
  hasMore: boolean;
41
17
  total: number;
42
18
  }>;
43
19
  interface GetAlarmsParams {
44
- /**
45
- * 页码,默认 1
46
- */
47
20
  page?: number;
48
- /**
49
- * 页码,默认 50
50
- */
51
21
  pageSize?: number;
52
22
  }
53
- /**
54
- * 获取告警列表
55
- * @param {GetAlarmsParams} params
56
- */
57
23
  export declare const getAlarms: (params?: GetAlarmsParams) => Promise<{
58
24
  list: LogData[];
59
25
  hasMore: boolean;
60
26
  total: number;
61
27
  }>;
62
28
  interface GetAlbumsParams {
63
- /**
64
- * 页码,默认 1
65
- */
66
29
  page?: number;
67
- /**
68
- * 每页数量,默认为 20
69
- */
70
30
  pageSize?: number;
71
- /**
72
- * 开始时间,单位为毫秒
73
- */
74
31
  startTime?: number;
75
- /**
76
- * 结束时间,单位为毫秒
77
- */
78
32
  endTime?: number;
79
33
  }
80
- /**
81
- * 获取相册日志
82
- * 仅支持视对讲设备
83
- */
84
34
  export declare const getAlbums: (params?: GetAlbumsParams) => Promise<{
85
35
  hasMore: boolean;
86
36
  list: AlbumMessage[];