@ray-js/lock-sdk 1.0.0-beta-1 → 1.0.0-beta-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.
- package/LICENSE.md +9 -0
- package/lib/sleep.js +2 -1
- package/lib/unlock-method.d.ts +5 -1
- package/lib/unlock-method.js +7 -25
- package/lib/user.js +6 -0
- package/lib/utils/errors.js +3 -1
- package/package.json +3 -2
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright © 2014-2022 Tuya.inc
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/sleep.js
CHANGED
|
@@ -30,7 +30,8 @@ export const hasSleepAbility = () => {
|
|
|
30
30
|
const {
|
|
31
31
|
dpSchema
|
|
32
32
|
} = config;
|
|
33
|
-
|
|
33
|
+
console.log('dpSchema', dpSchema[dpCodes.dormantSwitch], dpSchema[dpCodes.dormantTimeSet]);
|
|
34
|
+
return (typeof dpSchema[dpCodes.dormantSwitch] !== "undefined" || typeof dpSchema[dpCodes.onlineSwitch] !== "undefined") && typeof dpSchema[dpCodes.dormantTimeSet] !== "undefined";
|
|
34
35
|
};
|
|
35
36
|
const setSleepStatus = async status => {
|
|
36
37
|
const {
|
package/lib/unlock-method.d.ts
CHANGED
|
@@ -57,7 +57,6 @@ export interface updateUnlockMethodParams {
|
|
|
57
57
|
/**
|
|
58
58
|
* 是否特殊开锁方式,配置与劫持告警 dp 相关
|
|
59
59
|
* 当开启特殊开锁方式时,appSend 和 msgPhone 必须有一个
|
|
60
|
-
* 注意:门卡与人脸不支持特殊开锁方式配置
|
|
61
60
|
*/
|
|
62
61
|
isSpecial?: boolean;
|
|
63
62
|
/**
|
|
@@ -92,6 +91,11 @@ interface StartAddUnlockMethodParams {
|
|
|
92
91
|
* 用户 id
|
|
93
92
|
*/
|
|
94
93
|
userId: string;
|
|
94
|
+
/**
|
|
95
|
+
* 每个步骤的超时时间
|
|
96
|
+
* 默认 15000 毫秒
|
|
97
|
+
*/
|
|
98
|
+
timeout?: number;
|
|
95
99
|
}
|
|
96
100
|
export declare const startAddUnlockMethod: (params: StartAddUnlockMethodParams) => Promise<{
|
|
97
101
|
total: number;
|
package/lib/unlock-method.js
CHANGED
|
@@ -228,9 +228,11 @@ const addUnlockMethodData = {
|
|
|
228
228
|
timeoutId: 0,
|
|
229
229
|
userId: "",
|
|
230
230
|
// 云端用户 id
|
|
231
|
-
unlockDpId: 0
|
|
231
|
+
unlockDpId: 0,
|
|
232
|
+
timeout: 15000
|
|
232
233
|
};
|
|
233
|
-
const handleAddTimeout = ()
|
|
234
|
+
const handleAddTimeout = function () {
|
|
235
|
+
let timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 15000;
|
|
234
236
|
clearTimeout(addUnlockMethodData.timeoutId);
|
|
235
237
|
// @ts-expect-error
|
|
236
238
|
addUnlockMethodData.timeoutId = setTimeout(() => {
|
|
@@ -242,7 +244,7 @@ const handleAddTimeout = () => {
|
|
|
242
244
|
lockUserId: addUnlockMethodData.lockUserId,
|
|
243
245
|
error: getError(1002)
|
|
244
246
|
});
|
|
245
|
-
},
|
|
247
|
+
}, timeout);
|
|
246
248
|
};
|
|
247
249
|
const handleAddReport = async dps => {
|
|
248
250
|
if (dps[addUnlockMethodData.dpCode]) {
|
|
@@ -273,7 +275,7 @@ const handleAddReport = async dps => {
|
|
|
273
275
|
case 0xfc:
|
|
274
276
|
{
|
|
275
277
|
// 重新计时
|
|
276
|
-
handleAddTimeout();
|
|
278
|
+
handleAddTimeout(addUnlockMethodData.timeout);
|
|
277
279
|
// 录入中
|
|
278
280
|
eventData = {
|
|
279
281
|
type,
|
|
@@ -370,7 +372,7 @@ const monitoringAddReport = option => {
|
|
|
370
372
|
emitter.off(DPCHANGE, handleAddReport);
|
|
371
373
|
emitter.on(DPCHANGE, handleAddReport);
|
|
372
374
|
// 超时处理
|
|
373
|
-
handleAddTimeout();
|
|
375
|
+
handleAddTimeout(option.timeout);
|
|
374
376
|
};
|
|
375
377
|
export const startAddUnlockMethod = async params => {
|
|
376
378
|
const {
|
|
@@ -434,26 +436,6 @@ export const startAddUnlockMethod = async params => {
|
|
|
434
436
|
throw getError(1027);
|
|
435
437
|
};
|
|
436
438
|
|
|
437
|
-
// /**
|
|
438
|
-
// * 添加开锁方式
|
|
439
|
-
// * @param {AddUnlockMethodParams} params 入参
|
|
440
|
-
// * @returns
|
|
441
|
-
// */
|
|
442
|
-
// export const addUnlockMethod = async (params: AddUnlockMethodParams) => {
|
|
443
|
-
// const specialInfo = checkSpecial(!!params.isSpecial, params.specialInfo);
|
|
444
|
-
// const recordDpCode = getUnlockMethodTypeByType(params.type).code;
|
|
445
|
-
|
|
446
|
-
// const dpId = config.idsByCode[recordDpCode];
|
|
447
|
-
|
|
448
|
-
// return await createUnlockMethod({
|
|
449
|
-
// devId: config.devInfo.devId,
|
|
450
|
-
// userId: params.userId,
|
|
451
|
-
// unlockId: `${dpId}-${params.unlockId}`,
|
|
452
|
-
// unlockName: params.name,
|
|
453
|
-
// ...specialInfo,
|
|
454
|
-
// });
|
|
455
|
-
// };
|
|
456
|
-
|
|
457
439
|
/**
|
|
458
440
|
* 更新开锁方式
|
|
459
441
|
* 仅支持更新开锁方式名称和特殊开锁方式的通知信息
|
package/lib/user.js
CHANGED
|
@@ -336,6 +336,9 @@ export const openFamilyUserDetail = async userId => {
|
|
|
336
336
|
* @returns
|
|
337
337
|
*/
|
|
338
338
|
export const addUser = async params => {
|
|
339
|
+
if (!config.supportBigData) {
|
|
340
|
+
throw getError(1060);
|
|
341
|
+
}
|
|
339
342
|
if (!params.name) {
|
|
340
343
|
throw getError(1009, "name");
|
|
341
344
|
}
|
|
@@ -352,6 +355,9 @@ export const addUser = async params => {
|
|
|
352
355
|
* @returns
|
|
353
356
|
*/
|
|
354
357
|
export const removeUser = async userId => {
|
|
358
|
+
if (!config.supportBigData) {
|
|
359
|
+
throw getError(1060);
|
|
360
|
+
}
|
|
355
361
|
return removeNormalUser({
|
|
356
362
|
devId: config.devInfo.devId,
|
|
357
363
|
userId,
|
package/lib/utils/errors.js
CHANGED
|
@@ -103,7 +103,9 @@ const errors = {
|
|
|
103
103
|
// 特殊开锁方式 app 消息或手机短信必须开启一个
|
|
104
104
|
1058: "Special unlock method app message notification or phone SMS must be enabled",
|
|
105
105
|
// 门铃通知服务未开通
|
|
106
|
-
1059: "Doorbell notification service not enabled"
|
|
106
|
+
1059: "Doorbell notification service not enabled",
|
|
107
|
+
// 不支持添加普通成员
|
|
108
|
+
1060: "Does not support adding normal members"
|
|
107
109
|
};
|
|
108
110
|
export const getError = function (code) {
|
|
109
111
|
if (errors[code]) {
|