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