@ray-js/lock-sdk 1.0.0-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 (95) hide show
  1. package/lib/api/index.d.ts +5 -0
  2. package/lib/api/index.js +18 -0
  3. package/lib/api/linkage.d.ts +161 -0
  4. package/lib/api/linkage.js +74 -0
  5. package/lib/api/lock.d.ts +195 -0
  6. package/lib/api/lock.js +129 -0
  7. package/lib/api/log.d.ts +166 -0
  8. package/lib/api/log.js +44 -0
  9. package/lib/api/setting.d.ts +14 -0
  10. package/lib/api/setting.js +36 -0
  11. package/lib/api/temp.d.ts +211 -0
  12. package/lib/api/temp.js +130 -0
  13. package/lib/api/user.d.ts +154 -0
  14. package/lib/api/user.js +59 -0
  15. package/lib/api/video.d.ts +9 -0
  16. package/lib/api/video.js +17 -0
  17. package/lib/config/dp-code/index.d.ts +175 -0
  18. package/lib/config/dp-code/index.js +224 -0
  19. package/lib/config/dp-map/common.d.ts +102 -0
  20. package/lib/config/dp-map/common.js +120 -0
  21. package/lib/config/dp-map/normal.d.ts +6 -0
  22. package/lib/config/dp-map/normal.js +51 -0
  23. package/lib/config/dp-map/open.d.ts +21 -0
  24. package/lib/config/dp-map/open.js +62 -0
  25. package/lib/config/dp-map/unlock-method-big.d.ts +559 -0
  26. package/lib/config/dp-map/unlock-method-big.js +237 -0
  27. package/lib/config/dp-map/unlock-method.d.ts +551 -0
  28. package/lib/config/dp-map/unlock-method.js +231 -0
  29. package/lib/config/index.d.ts +46 -0
  30. package/lib/config/index.js +56 -0
  31. package/lib/constant.d.ts +101 -0
  32. package/lib/constant.js +136 -0
  33. package/lib/dp-interface.d.ts +7 -0
  34. package/lib/dp-interface.js +1 -0
  35. package/lib/event.d.ts +8 -0
  36. package/lib/event.js +9 -0
  37. package/lib/index.d.ts +25 -0
  38. package/lib/index.js +92 -0
  39. package/lib/interface.d.ts +807 -0
  40. package/lib/interface.js +1 -0
  41. package/lib/linkage.d.ts +26 -0
  42. package/lib/linkage.js +175 -0
  43. package/lib/log.d.ts +91 -0
  44. package/lib/log.js +314 -0
  45. package/lib/media.d.ts +43 -0
  46. package/lib/media.js +80 -0
  47. package/lib/open.d.ts +48 -0
  48. package/lib/open.js +247 -0
  49. package/lib/other.d.ts +36 -0
  50. package/lib/other.js +178 -0
  51. package/lib/parse/index.d.ts +6 -0
  52. package/lib/parse/index.js +22 -0
  53. package/lib/signal.d.ts +26 -0
  54. package/lib/signal.js +38 -0
  55. package/lib/sleep.d.ts +61 -0
  56. package/lib/sleep.js +121 -0
  57. package/lib/state.d.ts +54 -0
  58. package/lib/state.js +429 -0
  59. package/lib/sync/remote-serect-key.d.ts +5 -0
  60. package/lib/sync/remote-serect-key.js +60 -0
  61. package/lib/sync/t0.d.ts +5 -0
  62. package/lib/sync/t0.js +33 -0
  63. package/lib/sync/temp.d.ts +7 -0
  64. package/lib/sync/temp.js +88 -0
  65. package/lib/sync/unlock-mothod.d.ts +5 -0
  66. package/lib/sync/unlock-mothod.js +54 -0
  67. package/lib/temporary.d.ts +226 -0
  68. package/lib/temporary.js +637 -0
  69. package/lib/unlock-method.d.ts +269 -0
  70. package/lib/unlock-method.js +723 -0
  71. package/lib/user.d.ts +108 -0
  72. package/lib/user.js +361 -0
  73. package/lib/utils/base64-to-hex.d.ts +1 -0
  74. package/lib/utils/base64-to-hex.js +12 -0
  75. package/lib/utils/byte.d.ts +19 -0
  76. package/lib/utils/byte.js +74 -0
  77. package/lib/utils/constant.d.ts +11 -0
  78. package/lib/utils/constant.js +17 -0
  79. package/lib/utils/device.d.ts +207 -0
  80. package/lib/utils/device.js +353 -0
  81. package/lib/utils/errors.d.ts +2 -0
  82. package/lib/utils/errors.js +125 -0
  83. package/lib/utils/event.d.ts +23 -0
  84. package/lib/utils/event.js +144 -0
  85. package/lib/utils/hex-to-base64.d.ts +1 -0
  86. package/lib/utils/hex-to-base64.js +8 -0
  87. package/lib/utils/hex-to-bytes.d.ts +6 -0
  88. package/lib/utils/hex-to-bytes.js +16 -0
  89. package/lib/utils/index.d.ts +169 -0
  90. package/lib/utils/index.js +419 -0
  91. package/lib/utils/log.d.ts +5 -0
  92. package/lib/utils/log.js +78 -0
  93. package/lib/utils/publishDps.d.ts +11 -0
  94. package/lib/utils/publishDps.js +91 -0
  95. package/package.json +37 -0
package/lib/user.d.ts ADDED
@@ -0,0 +1,108 @@
1
+ import { EffectiveConfig, UserInfo } from "./interface";
2
+ interface getUsersParams {
3
+ /**
4
+ * 当前页码
5
+ * @default 1
6
+ */
7
+ page?: number;
8
+ /**
9
+ * 每页条数
10
+ * @default 10
11
+ */
12
+ pageSize?: number;
13
+ /**
14
+ * 搜索关键字
15
+ * @default ""
16
+ */
17
+ keyword?: string;
18
+ }
19
+ /**
20
+ * 获取门锁成员列表
21
+ * @param {getUsersParams} options
22
+ * @returns
23
+ */
24
+ export declare const getUsers: (params?: getUsersParams) => Promise<{
25
+ list: UserInfo[];
26
+ hasMore: boolean;
27
+ }>;
28
+ interface getUserInfoParams {
29
+ /**
30
+ * 用户id
31
+ */
32
+ userId: string;
33
+ /**
34
+ * 用户昵称
35
+ */
36
+ nickName: string;
37
+ }
38
+ /**
39
+ * 获取用户详细信息
40
+ * @param {getUserInfoParams} params
41
+ * @returns
42
+ */
43
+ export declare const getUserInfo: (params: getUserInfoParams) => Promise<UserInfo>;
44
+ /**
45
+ * 更新用户的有效性
46
+ */
47
+ interface updateUserLimitTimeParams {
48
+ /**
49
+ * 用户id
50
+ */
51
+ userId: string;
52
+ /**
53
+ * 锁端用户id
54
+ */
55
+ lockUserId: number;
56
+ /**
57
+ * 是否永久生效
58
+ */
59
+ permanent: boolean;
60
+ /**
61
+ * 生效时间配置
62
+ * 当为非永久生效时,需必传此配置
63
+ */
64
+ effective?: EffectiveConfig;
65
+ /**
66
+ * 是否支持离线开锁
67
+ * 仅蓝牙锁支持
68
+ */
69
+ offlineUnlock?: boolean;
70
+ }
71
+ /**
72
+ * 更新用户的时效性
73
+ * @param {updateUserLimitTimeParams} params
74
+ * @returns
75
+ */
76
+ export declare const updateUserLimitTime: (params: updateUserLimitTimeParams) => Promise<boolean>;
77
+ /**
78
+ * 跳转到添加家庭成员页面
79
+ * @returns
80
+ */
81
+ export declare const openAddFamilyUser: () => Promise<unknown>;
82
+ /**
83
+ * 查看家庭成员信息
84
+ * 支持编辑
85
+ * @param {string} userId 成员id
86
+ */
87
+ export declare const openFamilyUserDetail: (userId: string) => Promise<never>;
88
+ interface AddUserParams {
89
+ /**
90
+ * 用户名称
91
+ */
92
+ name: string;
93
+ }
94
+ /**
95
+ * 添加一个普通成员
96
+ * 注意,如果锁使用了小容量的方案,则不建议使用此 API
97
+ * @param {AddUserParams} params
98
+ * @returns
99
+ */
100
+ export declare const addUser: (params: AddUserParams) => Promise<unknown>;
101
+ /**
102
+ * 删除一个普通成员
103
+ * 注意,如果锁使用了小容量的方案,则不建议使用此 API
104
+ * @param {string} userId 成员id
105
+ * @returns
106
+ */
107
+ export declare const removeUser: (userId: string) => Promise<unknown>;
108
+ export {};
package/lib/user.js ADDED
@@ -0,0 +1,361 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ const _excluded = ["timeScheduleInfo", "unlockDetail"];
4
+ import "core-js/modules/esnext.iterator.constructor.js";
5
+ import "core-js/modules/esnext.iterator.find.js";
6
+ import "core-js/modules/esnext.iterator.map.js";
7
+ import "core-js/modules/esnext.iterator.reduce.js";
8
+ import { getUserDetail, getUserList } from "./api/user";
9
+ import config from "./config";
10
+ import { update as updateMap, reportUpdate as reportUpdateMap } from "./config/dp-map/unlock-method";
11
+ import { update as updateMapBig, reportUpdate as reportUpdateMapBig } from "./config/dp-map/unlock-method-big";
12
+ import { publishDps } from "./utils/publishDps";
13
+ import dpCodes from "./config/dp-code";
14
+ import DpUtils from "@ray-js/tuya-dp-transform";
15
+ import { getError } from "./utils/errors";
16
+ import { updateUserTimeSchedule, addNormalUser, removeNormalUser } from "./api/user";
17
+ import { validConfigDpMap } from "./config/dp-map/common";
18
+ import { formatTimestampToMilliseconds, formatWeek, isAdmin, parseWeek, unlockMethodConfigs, validateEffectiveConfig } from "./utils";
19
+ import { getCurrentHomeInfo, isSupportShortLink } from "./utils/device";
20
+ import { LoopTypes } from "./utils/constant";
21
+ import { getCurrentUser } from "./state";
22
+ /**
23
+ * 追加用户列表
24
+ * @param list
25
+ * @param result
26
+ * @returns
27
+ */
28
+ const concactUserList = (list, result) => {
29
+ return list.reduce((acc, item) => {
30
+ const {
31
+ timeScheduleInfo,
32
+ unlockDetail
33
+ } = item,
34
+ rest = _objectWithoutProperties(item, _excluded);
35
+ // 处理时效配置
36
+
37
+ if (!item.timeScheduleInfo.permanent && item.timeScheduleInfo.scheduleDetails && item.timeScheduleInfo.scheduleDetails.length > 0) {
38
+ // 如果不是永久有效,且有时间配置
39
+ Object.assign(timeScheduleInfo, {
40
+ effectiveTime: formatTimestampToMilliseconds(item.timeScheduleInfo.effectiveTime || 0),
41
+ expiredTime: formatTimestampToMilliseconds(item.timeScheduleInfo.expiredTime || 0),
42
+ scheduleDetails: {
43
+ repeat: !item.timeScheduleInfo.scheduleDetails[0].allDay,
44
+ effectiveTime: item.timeScheduleInfo.scheduleDetails[0].effectiveTime,
45
+ invalidTime: item.timeScheduleInfo.scheduleDetails[0].invalidTime,
46
+ timeZoneId: item.timeScheduleInfo.scheduleDetails[0].timeZoneId,
47
+ weeks: parseWeek(item.timeScheduleInfo.scheduleDetails[0].workingDay)
48
+ }
49
+ });
50
+ }
51
+ // 处理开锁方式
52
+ let unlockDetails = unlockDetail.map(detail => {
53
+ // 处理开锁方式的名称
54
+ const unlockList = detail.unlockList.map(unlockItem => {
55
+ return {
56
+ unlockId: unlockItem.unlockId.split("-")[1],
57
+ unlockName: unlockItem.unlockName,
58
+ id: unlockItem.opModeId,
59
+ isBound: unlockItem.allocateFlag === 1,
60
+ photoUnlock: unlockItem.photoUnlock,
61
+ isSpecial: unlockItem.unlockAttr === 1
62
+ };
63
+ });
64
+ const unlockMethodConfig = unlockMethodConfigs.find(item => item.code === detail.dpCode);
65
+ return {
66
+ count: unlockList.length,
67
+ dpCode: detail.dpCode,
68
+ dpId: detail.dpId,
69
+ type: unlockMethodConfig.type,
70
+ unlockList
71
+ };
72
+ });
73
+ acc.push(_objectSpread(_objectSpread({}, rest), {}, {
74
+ timeScheduleInfo: {
75
+ permanent: true // 默认永久有效
76
+ },
77
+ unlockDetails,
78
+ isAccountUser: item.userListType === "group_user"
79
+ }));
80
+ return acc;
81
+ }, result);
82
+ };
83
+
84
+ /**
85
+ * 获取门锁成员列表
86
+ * @param {getUsersParams} options
87
+ * @returns
88
+ */
89
+ export const getUsers = async params => {
90
+ const {
91
+ page = 1,
92
+ pageSize = 10,
93
+ keyword = ""
94
+ } = params || {};
95
+ const currentUser = await getCurrentUser();
96
+ const dps = [];
97
+ if (currentUser.allOpenDps) {
98
+ currentUser.allOpenDps.split(",").reduce((acc, cur) => {
99
+ const code = config.codesById[cur];
100
+ if (code) {
101
+ acc.push(code);
102
+ }
103
+ return acc;
104
+ }, dps);
105
+ }
106
+ const res = await getUserList({
107
+ dpCodes: dps.join(","),
108
+ devId: config.devInfo.devId,
109
+ offset: (page - 1) * pageSize,
110
+ limit: pageSize,
111
+ keyword
112
+ });
113
+ let list = [];
114
+ if (res.admin && res.admin.length > 0) {
115
+ concactUserList(res.admin, list);
116
+ }
117
+ if (res.user && res.user.length > 0) {
118
+ concactUserList(res.user, list);
119
+ }
120
+ return {
121
+ list,
122
+ hasMore: res.hasNext
123
+ };
124
+ };
125
+ /**
126
+ * 获取用户详细信息
127
+ * @param {getUserInfoParams} params
128
+ * @returns
129
+ */
130
+ export const getUserInfo = async params => {
131
+ const data = await getUsers({
132
+ keyword: params.nickName
133
+ });
134
+ const res = data.list.find(item => item.userId === params.userId);
135
+ if (res) {
136
+ return res;
137
+ }
138
+ throw getError(1048);
139
+ };
140
+
141
+ /**
142
+ * 更新用户的有效性
143
+ */
144
+
145
+ /**
146
+ * 更新用户的时效性
147
+ * @param {updateUserLimitTimeParams} params
148
+ * @returns
149
+ */
150
+ export const updateUserLimitTime = async params => {
151
+ const {
152
+ userId,
153
+ lockUserId,
154
+ permanent,
155
+ effective
156
+ } = params;
157
+
158
+ // 数据验证
159
+ if (!permanent) {
160
+ validateEffectiveConfig(effective);
161
+ }
162
+ const {
163
+ userType
164
+ } = await getUserDetail({
165
+ devId: config.devInfo.devId,
166
+ userId
167
+ });
168
+ if (isAdmin(userType)) {
169
+ // 如果是管理员,则不允许修改时效性
170
+ throw getError(1049);
171
+ }
172
+ const {
173
+ repeat,
174
+ effectiveTime = 0,
175
+ expiredTime = 1439
176
+ } = effective || {};
177
+
178
+ // 循环方式
179
+ const loopType = repeat ?
180
+ // @ts-expect-error
181
+ LoopTypes[repeat.toUpperCase()] : LoopTypes.NONE;
182
+
183
+ // 组装数据下发
184
+ const dpValue = {
185
+ type: 0,
186
+ stage: 0,
187
+ admin: false,
188
+ memberId: lockUserId,
189
+ unlockId: 255,
190
+ validNum: 0,
191
+ pwdLength: 0,
192
+ pwd: [],
193
+ validConfig: {
194
+ startTime: Math.floor(permanent ? +new Date() / 1000 : effective.effectiveDate),
195
+ // 如果是永久生效,则设置为 100 年后失效
196
+ endTime: Math.floor(permanent ? (+new Date() + 3153600000000) / 1000 : effective.expiredDate),
197
+ loop: permanent ? LoopTypes.NONE : loopType,
198
+ loopConfig: 0,
199
+ weeks: permanent || (effective === null || effective === void 0 ? void 0 : effective.repeat) !== "week" || (effective === null || effective === void 0 ? void 0 : effective.weeks) === undefined ? [0, 0, 0, 0, 0, 0, 0] : effective.weeks,
200
+ days: [],
201
+ startHour: permanent ? 0 : Math.floor(effectiveTime / 60),
202
+ startMinute: permanent ? 0 : effectiveTime % 60,
203
+ endHour: permanent ? 0 : Math.floor(expiredTime / 60),
204
+ endMinute: permanent ? 0 : expiredTime % 60
205
+ }
206
+ };
207
+ const dpCode = config.supportBigData ? dpCodes.unlockMethodEditW : dpCodes.unlockMethodEdit;
208
+
209
+ // 下发数据
210
+ const res = await publishDps({
211
+ [dpCode]: DpUtils.format(dpValue, config.supportBigData ? updateMapBig : updateMap)
212
+ }, {
213
+ checkReport: dps => {
214
+ if (typeof dps[dpCode] !== "undefined") {
215
+ const result = DpUtils.parse(dps[dpCode], config.supportBigData ? reportUpdateMapBig : reportUpdateMap);
216
+ console.log("reportUpdate result", result);
217
+ if (result.type === 0) {
218
+ if (result.memberId === lockUserId) {
219
+ return result;
220
+ } else {
221
+ // 提示可能返回了一个错误的成员id
222
+ console.warn("An incorrect member id was returned");
223
+ }
224
+ }
225
+ }
226
+ return false;
227
+ }
228
+ });
229
+ if (res.status !== 255) {
230
+ throw getError(1011);
231
+ }
232
+ // 更新云端数据
233
+ try {
234
+ console.log("dpValue.validConfig", dpValue.validConfig);
235
+ await updateUserTimeSchedule({
236
+ devId: config.devInfo.devId,
237
+ userId: userId,
238
+ timeScheduleInfo: {
239
+ permanent,
240
+ userTimeSet: DpUtils.format(dpValue.validConfig,
241
+ // @ts-expect-error
242
+ validConfigDpMap.childMap),
243
+ effectiveTime: dpValue.validConfig.startTime,
244
+ expiredTime: dpValue.validConfig.endTime,
245
+ scheduleDetails: [{
246
+ allDay: loopType === LoopTypes.NONE,
247
+ effectiveTime: permanent ? 0 : effectiveTime,
248
+ invalidTime: permanent ? 0 : expiredTime,
249
+ workingDay: permanent ? 0 : formatWeek(dpValue.validConfig.weeks)
250
+ }]
251
+ }
252
+ });
253
+ } catch (e) {
254
+ // 更新云端数据失败
255
+ throw getError(1012);
256
+ }
257
+ return true;
258
+ };
259
+
260
+ /**
261
+ * 跳转到添加家庭成员页面
262
+ * @returns
263
+ */
264
+ export const openAddFamilyUser = async () => {
265
+ const homeInfo = await getCurrentHomeInfo();
266
+ let link = await isSupportShortLink("tysh_family_add_member_rn");
267
+ if (!link) {
268
+ link = await isSupportShortLink("thingsh_family_add_member_rn");
269
+ }
270
+ if (link) {
271
+ const url = `tuyaSmart://${link}?homeId=${homeInfo.homeId}`;
272
+ return new Promise((resolve, reject) => {
273
+ ty.router({
274
+ url: url,
275
+ success: () => {
276
+ resolve(true);
277
+ },
278
+ fail: e => {
279
+ reject(e);
280
+ }
281
+ });
282
+ });
283
+ }
284
+
285
+ // 不支持跳转
286
+ return Promise.reject(getError(1013));
287
+ };
288
+ const userTypeMap = {
289
+ "10": 1,
290
+ "20": 0,
291
+ "40": -1,
292
+ "50": 2
293
+ };
294
+
295
+ /**
296
+ * 查看家庭成员信息
297
+ * 支持编辑
298
+ * @param {string} userId 成员id
299
+ */
300
+ export const openFamilyUserDetail = async userId => {
301
+ const homeId = await getCurrentHomeInfo();
302
+ const {
303
+ userType: currentUserType
304
+ } = await getCurrentUser();
305
+ const role = userTypeMap[currentUserType];
306
+ let link = await isSupportShortLink("member_info");
307
+ if (link) {
308
+ ty.canIUseRouter({
309
+ url: "member_info",
310
+ success: res => {
311
+ if (res !== null && res !== void 0 && res.result) {
312
+ ty.router({
313
+ url: `tuyaSmart://member_info?homeId=${homeId}&memberId=${userId}&role=${role}`,
314
+ success: () => {
315
+ console.log("跳转成员详情页成功");
316
+ },
317
+ fail: e => {
318
+ console.log("跳转成员详情页失败", e);
319
+ }
320
+ });
321
+ }
322
+ },
323
+ fail: err => {
324
+ console.log(err);
325
+ }
326
+ });
327
+ }
328
+
329
+ // 不支持跳转
330
+ return Promise.reject(getError(1013));
331
+ };
332
+ /**
333
+ * 添加一个普通成员
334
+ * 注意,如果锁使用了小容量的方案,则不建议使用此 API
335
+ * @param {AddUserParams} params
336
+ * @returns
337
+ */
338
+ export const addUser = async params => {
339
+ if (!params.name) {
340
+ throw getError(1009, "name");
341
+ }
342
+ return addNormalUser({
343
+ devId: config.devInfo.devId,
344
+ name: params.name
345
+ });
346
+ };
347
+
348
+ /**
349
+ * 删除一个普通成员
350
+ * 注意,如果锁使用了小容量的方案,则不建议使用此 API
351
+ * @param {string} userId 成员id
352
+ * @returns
353
+ */
354
+ export const removeUser = async userId => {
355
+ return removeNormalUser({
356
+ devId: config.devInfo.devId,
357
+ userId,
358
+ shouldDeleteUnlockInfo: true,
359
+ issueDp: true
360
+ });
361
+ };
@@ -0,0 +1 @@
1
+ export default function base64ToHex(base64: string): string;
@@ -0,0 +1,12 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.reduce.js";
3
+ import { Base64 } from 'js-base64';
4
+ export default function base64ToHex(base64) {
5
+ if (!base64) {
6
+ return '';
7
+ }
8
+ return Base64.toUint8Array(base64).reduce((res, cur) => {
9
+ res.push(cur.toString(16).padStart(2, '0'));
10
+ return res;
11
+ }, []).join('');
12
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 大端格式 字节数组转为无符号位数据
3
+ *
4
+ * @param data
5
+ * @returns
6
+ */
7
+ export declare function bytesToUint(data: Uint8Array): number;
8
+ /**
9
+ * 大端格式 字节转为16进制字符串
10
+ * @param data
11
+ * @returns
12
+ */
13
+ export declare function bytesToHex(data: Uint8Array): string;
14
+ /**
15
+ * 字符串转为字节
16
+ * @param str
17
+ * @returns
18
+ */
19
+ export declare function stringToBytes(str: string): Uint8Array<ArrayBuffer>;
@@ -0,0 +1,74 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.reduce.js";
3
+ /**
4
+ * 大端格式 字节数组转为无符号位数据
5
+ *
6
+ * @param data
7
+ * @returns
8
+ */
9
+ export function bytesToUint(data) {
10
+ const view = new DataView(data.buffer);
11
+ switch (data.length) {
12
+ case 0:
13
+ throw new Error("data of Uint8Array is empty");
14
+ case 1:
15
+ return view.getUint8(0);
16
+ case 2:
17
+ return view.getUint16(0);
18
+ case 3:
19
+ return data.reduce((res, value) => {
20
+ return res << 8 | value;
21
+ }, 0);
22
+ case 4:
23
+ return view.getUint32(0);
24
+ default:
25
+ return parseInt(bytesToHex(data), 16);
26
+ }
27
+ }
28
+
29
+ /**
30
+ * 大端格式 字节转为16进制字符串
31
+ * @param data
32
+ * @returns
33
+ */
34
+ export function bytesToHex(data) {
35
+ if (!data.length) {
36
+ return "";
37
+ }
38
+ if (data.length <= 4) {
39
+ return bytesToUint(data).toString(16).padStart(data.length * 2, "0").toUpperCase();
40
+ }
41
+ return data.reduce((res, value) => {
42
+ res.push(value.toString(16).padStart(2, "0"));
43
+ return res;
44
+ }, []).join("").toUpperCase();
45
+ }
46
+
47
+ /**
48
+ * 字符串转为字节
49
+ * @param str
50
+ * @returns
51
+ */
52
+ export function stringToBytes(str) {
53
+ const bytes = [];
54
+ const len = str.length;
55
+ for (let i = 0; i < len; i++) {
56
+ const c = str.charCodeAt(i);
57
+ if (c >= 0x010000 && c <= 0x10ffff) {
58
+ bytes.push(c >> 18 & 0x07 | 0xf0);
59
+ bytes.push(c >> 12 & 0x3f | 0x80);
60
+ bytes.push(c >> 6 & 0x3f | 0x80);
61
+ bytes.push(c & 0x3f | 0x80);
62
+ } else if (c >= 0x000800 && c <= 0x00ffff) {
63
+ bytes.push(c >> 12 & 0x0f | 0xe0);
64
+ bytes.push(c >> 6 & 0x3f | 0x80);
65
+ bytes.push(c & 0x3f | 0x80);
66
+ } else if (c >= 0x000080 && c <= 0x0007ff) {
67
+ bytes.push(c >> 6 & 0x1f | 0xc0);
68
+ bytes.push(c & 0x3f | 0x80);
69
+ } else {
70
+ bytes.push(c & 0xff);
71
+ }
72
+ }
73
+ return new Uint8Array(bytes);
74
+ }
@@ -0,0 +1,11 @@
1
+ declare const THING: string;
2
+ export { THING };
3
+ export declare const DPCHANGE = "dpChange";
4
+ export declare const LOGCHANGE = "logChange";
5
+ export declare const UNLOCK_METHOD_EVENT = "UMEvent";
6
+ export declare enum LoopTypes {
7
+ NONE = 0,
8
+ DAY = 1,
9
+ WEEK = 2,
10
+ MONTH = 3
11
+ }
@@ -0,0 +1,17 @@
1
+ import { Base64 } from "js-base64";
2
+ const THING = Base64.decode("dHV5YQ==");
3
+ export { THING };
4
+ export const DPCHANGE = "dpChange";
5
+ export const LOGCHANGE = "logChange";
6
+ export const UNLOCK_METHOD_EVENT = "UMEvent";
7
+ export let LoopTypes = /*#__PURE__*/function (LoopTypes) {
8
+ // 不循环
9
+ LoopTypes[LoopTypes["NONE"] = 0] = "NONE";
10
+ // 天循环
11
+ LoopTypes[LoopTypes["DAY"] = 1] = "DAY";
12
+ // 周循环
13
+ LoopTypes[LoopTypes["WEEK"] = 2] = "WEEK";
14
+ // 月循环
15
+ LoopTypes[LoopTypes["MONTH"] = 3] = "MONTH";
16
+ return LoopTypes;
17
+ }({});