@ray-js/lock-sdk 1.1.1-beta.10 → 1.1.1-beta.12

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/user.d.ts CHANGED
@@ -82,26 +82,6 @@ export declare const getUserList: (params: getUserListParams) => Promise<{
82
82
  user: UserListItem[];
83
83
  hasNext: boolean;
84
84
  }>;
85
- interface GetUserDetailParams {
86
- devId: string;
87
- userId: string;
88
- }
89
- interface UserDetail {
90
- allOpenType: number[];
91
- avatarUrl: string;
92
- lockUserId: number;
93
- nickName: string;
94
- phase: number;
95
- productAttribute: number;
96
- status: number;
97
- supportOpenType: number[];
98
- uid: string;
99
- userContact: string;
100
- userId: string;
101
- userTimeSet: string;
102
- userType: number;
103
- }
104
- export declare const getUserDetail: (params: GetUserDetailParams) => Promise<UserDetail>;
105
85
  interface GetUserDetailQueryParams {
106
86
  devId: string;
107
87
  userId: string;
package/lib/api/user.js CHANGED
@@ -38,13 +38,6 @@ export const getUserList = (params) => {
38
38
  data: params,
39
39
  });
40
40
  };
41
- export const getUserDetail = (params) => {
42
- return requestApi({
43
- api: "m.lock.device.member.detail",
44
- version: "1.0",
45
- data: params,
46
- });
47
- };
48
41
  export const getUserDetailQuery = (params) => {
49
42
  return requestApi({
50
43
  api: "m.lock.user.detail.query",
@@ -1,17 +1,15 @@
1
1
  import dpUtils from "@ray-js/tuya-dp-transform";
2
2
  import { bindUnlockMethodToUser, bindUnlockMethodToUserByRecord, checkFreeUnlockMethods, createUnlockMethod, removeUnlockMethod, editUnlockMethod, fetchCreatePasswordSN, fetchFreeUnlockMethods, getUnlockMethodInfo, unbindMemberUnlockMethod, } from "./api/lock";
3
- import { getUserDetail } from "./api/user";
4
3
  import config from "./config";
5
4
  import dpCodes from "./config/dp-code";
6
5
  import { add as addMap, reportAdd as reportAddMap, remove as removeMap, reportRemove as reportRemoveMap, } from "./config/dp-map/unlock-method";
7
6
  import { add as addBigMap, reportAdd as reportAddBigMap, remove as removeBigMap, reportRemove as reportRemoveBigMap, } from "./config/dp-map/unlock-method-big";
8
- import { validConfigDpMap } from "./config/dp-map/common";
9
7
  import { getPermanentSetting, getUnlockMethodTypeByDpCode, getUnlockMethodTypeByType, isAdmin, parallelOnly, sleep, } from "./utils";
10
8
  import { getError } from "./utils/errors";
11
9
  import { publishDps } from "./utils/publishDps";
12
10
  import { encrypt } from "./utils/device";
13
11
  import emitter from "./utils/event";
14
- import { DPCHANGE, UNLOCK_METHOD_EVENT } from "./utils/constant";
12
+ import { DPCHANGE, LoopTypes, UNLOCK_METHOD_EVENT } from "./utils/constant";
15
13
  import { getFileRemoteUrl, sendPhoneVerifyCode } from "./api";
16
14
  import { getUserInfo } from "./user";
17
15
  import { getDeviceAdvancedAbilities } from "./capability";
@@ -58,8 +56,7 @@ const getUnlockMethodBase = async (type, userId) => {
58
56
  : dpCodes.unlockMethodCreate;
59
57
  const dpId = idsByCode[unlockMethodConfig.code];
60
58
  const [user, sn] = await Promise.all([
61
- getUserDetail({
62
- devId: devId,
59
+ getUserInfo({
63
60
  userId: userId,
64
61
  }),
65
62
  fetchCreatePasswordSN({
@@ -67,10 +64,40 @@ const getUnlockMethodBase = async (type, userId) => {
67
64
  dpId,
68
65
  }),
69
66
  ]);
70
- const { userType, lockUserId, userTimeSet } = user;
67
+ const { userType, lockUserId, timeScheduleInfo } = user;
71
68
  let validConfig;
72
- if (userTimeSet) {
73
- validConfig = dpUtils.parse(userTimeSet, validConfigDpMap.childMap);
69
+ if (timeScheduleInfo) {
70
+ const { permanent, effectiveTime, expiredTime, scheduleDetails } = timeScheduleInfo;
71
+ if (permanent) {
72
+ validConfig = {
73
+ startTime: Math.floor((effectiveTime || +new Date()) / 1000),
74
+ endTime: Math.floor((expiredTime || 0x72bc9b7f) / 1000),
75
+ loop: LoopTypes.NONE,
76
+ loopConfig: 0,
77
+ weeks: [0, 0, 0, 0, 0, 0, 0],
78
+ days: [],
79
+ startHour: 0,
80
+ startMinute: 0,
81
+ endHour: 0,
82
+ endMinute: 0,
83
+ };
84
+ }
85
+ else {
86
+ validConfig = {
87
+ startTime: Math.floor((effectiveTime || +new Date()) / 1000),
88
+ endTime: Math.floor((expiredTime || 0x72bc9b7f) / 1000),
89
+ loop: scheduleDetails?.repeat ? LoopTypes.WEEK : LoopTypes.NONE,
90
+ loopConfig: 0,
91
+ weeks: scheduleDetails?.repeat
92
+ ? scheduleDetails?.weeks
93
+ : [0, 0, 0, 0, 0, 0, 0],
94
+ days: [],
95
+ startHour: Math.floor((scheduleDetails?.effectiveTime ?? 0) / 60),
96
+ startMinute: (scheduleDetails?.effectiveTime ?? 0) % 60,
97
+ endHour: Math.floor((scheduleDetails?.invalidTime ?? 0) / 60),
98
+ endMinute: (scheduleDetails?.invalidTime ?? 0) % 60,
99
+ };
100
+ }
74
101
  }
75
102
  else {
76
103
  validConfig = getPermanentSetting();
@@ -350,6 +377,7 @@ export const startAddUnlockMethod = async (params) => {
350
377
  const res = await publishDps({
351
378
  [addDpCode]: dpUtils.format(dpData, addDpMap),
352
379
  }, {
380
+ timeout: params.timeout,
353
381
  checkReport: (dpData) => {
354
382
  if (typeof dpData[addDpCode] !== "undefined") {
355
383
  const result = dpUtils.parse(dpData[addDpCode], addDpReportMap);
@@ -375,6 +403,7 @@ export const startAddUnlockMethod = async (params) => {
375
403
  });
376
404
  if (res.stage === 0) {
377
405
  monitoringAddReport({
406
+ timeout: params.timeout,
378
407
  unlockMethodConfig,
379
408
  total: res.total,
380
409
  dpCode: addDpCode,
package/lib/user.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { EffectiveConfig, UnlockMethodBaseInfo, UserInfo } from "./interface";
1
+ import { EffectiveConfig, UserInfo } from "./interface";
2
2
  interface getUsersParams {
3
3
  page?: number;
4
4
  pageSize?: number;
@@ -11,27 +11,7 @@ export declare const getUsers: (params?: getUsersParams) => Promise<{
11
11
  interface getUserInfoParams {
12
12
  userId: string;
13
13
  }
14
- export declare const getUserInfo: (params: getUserInfoParams) => Promise<{
15
- timeScheduleInfo: any;
16
- unlockDetails: {
17
- count: number;
18
- dpCode: string;
19
- dpId: number;
20
- type: import("./interface").UnlockMethodType;
21
- unlockList: UnlockMethodBaseInfo[];
22
- }[];
23
- isAccountUser: boolean;
24
- userId: string;
25
- lockUserId: number;
26
- avatarUrl: string;
27
- backHomeNotifyAttr: number;
28
- effectiveFlag: number;
29
- nickName: string;
30
- offlineUnlock: boolean;
31
- userContact: string;
32
- userType: 10 | 20 | 30 | 40 | 50;
33
- userListType: "panel_user" | "group_user";
34
- }>;
14
+ export declare const getUserInfo: (params: getUserInfoParams) => Promise<UserInfo>;
35
15
  interface updateUserLimitTimeParams {
36
16
  userId: string;
37
17
  lockUserId: number;
@@ -45,6 +25,6 @@ export declare const openFamilyUserDetail: (userId: string) => Promise<undefined
45
25
  interface AddUserParams {
46
26
  name: string;
47
27
  }
48
- export declare const addUser: (params: AddUserParams) => Promise<import("./api/user").AddNormalUserResponse>;
28
+ export declare const addUser: (params: AddUserParams) => Promise<void>;
49
29
  export declare const removeUser: (userId: string) => Promise<void>;
50
30
  export {};
package/lib/user.js CHANGED
@@ -1,4 +1,4 @@
1
- import { getUserDetail, getUserDetailQuery, getUserList, } from "./api/user";
1
+ import { getUserDetailQuery, getUserList } from "./api/user";
2
2
  import config from "./config";
3
3
  import { update as updateMap, reportUpdate as reportUpdateMap, } from "./config/dp-map/unlock-method";
4
4
  import { update as updateMapBig, reportUpdate as reportUpdateMapBig, } from "./config/dp-map/unlock-method-big";
@@ -118,8 +118,11 @@ export const updateUserLimitTime = async (params) => {
118
118
  if (!permanent) {
119
119
  validateEffectiveConfig(effective);
120
120
  }
121
- const { userType } = await getUserDetail({
122
- devId: config.devInfo.devId,
121
+ const currentUser = await getCurrentUser();
122
+ if (!isAdmin(currentUser.userType)) {
123
+ throw getError(1069);
124
+ }
125
+ const { userType } = await getUserInfo({
123
126
  userId,
124
127
  });
125
128
  if (isAdmin(userType)) {
@@ -259,17 +262,24 @@ export const addUser = async (params) => {
259
262
  if (!params.name) {
260
263
  throw getError(1009, "name");
261
264
  }
262
- return addNormalUser({
263
- devId: config.devInfo.devId,
264
- name: params.name,
265
- });
265
+ try {
266
+ await addNormalUser({
267
+ devId: config.devInfo.devId,
268
+ name: params.name,
269
+ });
270
+ }
271
+ catch (e) {
272
+ if (e?.innerError?.errorCode === "DEFINITION_PARAM_NAME_REPEAT") {
273
+ throw getError(1068);
274
+ }
275
+ throw e;
276
+ }
266
277
  };
267
278
  export const removeUser = async (userId) => {
268
279
  if (!config.supportBigData) {
269
280
  throw getError(1060);
270
281
  }
271
- const res = await getUserDetail({
272
- devId: config.devInfo.devId,
282
+ const res = await getUserInfo({
273
283
  userId,
274
284
  });
275
285
  if (isUseNearChannel()) {
@@ -66,6 +66,8 @@ const errors = {
66
66
  1065: "Cloud side has been deleted, but device side synchronization deletion failed",
67
67
  1066: "Phone number cannot be empty",
68
68
  1067: "Password limit reached within this period",
69
+ 1068: "There is already a member with the same name",
70
+ 1069: "No permission to modify member validity",
69
71
  };
70
72
  export const getError = (code, ...places) => {
71
73
  if (errors[code]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lock-sdk",
3
- "version": "1.1.1-beta.10",
3
+ "version": "1.1.1-beta.12",
4
4
  "files": [
5
5
  "lib",
6
6
  "LICENSE.md"