@ray-js/lock-sdk 1.2.0-beta.3 → 1.2.0-beta.5
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/config/dp-code/index.d.ts +1 -0
- package/lib/config/dp-code/index.js +1 -0
- package/lib/config/dp-map/media.d.ts +13 -0
- package/lib/config/dp-map/media.js +19 -0
- package/lib/entries/main/exports/media.d.ts +4 -0
- package/lib/entries/main/exports/media.js +13 -0
- package/lib/feature/media/camera.d.ts +8 -0
- package/lib/feature/media/camera.js +33 -0
- package/lib/feature/password/temporary/custom-dp.js +59 -54
- package/lib/utils/errors.js +3 -1
- package/lib/utils/parse.js +1 -1
- package/package.json +1 -1
|
@@ -67,6 +67,7 @@ declare const dpCodes: {
|
|
|
67
67
|
readonly doorOpened: "door_opened";
|
|
68
68
|
readonly unlockApp: "unlock_app";
|
|
69
69
|
readonly initiativeMessage: "initiative_message";
|
|
70
|
+
readonly locationSelect: "location_select";
|
|
70
71
|
readonly manualLock: "manual_lock";
|
|
71
72
|
readonly checkCodeSet: "check_code_set";
|
|
72
73
|
readonly bleKeyCreate: "ble_key_create";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const locationSelectReportMap: readonly [{
|
|
2
|
+
readonly name: "status";
|
|
3
|
+
}, {
|
|
4
|
+
readonly name: "list";
|
|
5
|
+
readonly bytes: 2;
|
|
6
|
+
readonly loop: true;
|
|
7
|
+
readonly type: "child";
|
|
8
|
+
readonly childMap: readonly [{
|
|
9
|
+
readonly name: "index";
|
|
10
|
+
}, {
|
|
11
|
+
readonly name: "type";
|
|
12
|
+
}];
|
|
13
|
+
}];
|
|
@@ -4,3 +4,7 @@ export declare function isSupportMedia(): boolean;
|
|
|
4
4
|
export declare function getMediaRotate(): import("../../../feature/media/rotate").MediaRotate;
|
|
5
5
|
export declare function getMediaInfo(): import("../../../feature/media/media").MediaInfo;
|
|
6
6
|
export declare function openLocalAlbum(params?: OpenLocalAlbumParams): Promise<void>;
|
|
7
|
+
export declare function isSupportMultiCamera(): boolean;
|
|
8
|
+
export declare function getCameraInfo(): import("../../../feature/media/camera").CameraInfo | undefined;
|
|
9
|
+
export declare function queryCameraInfo(): Promise<import("../../../feature/media/camera").CameraInfo | undefined>;
|
|
10
|
+
export declare function switchCamera(index: number): Promise<true>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
|
|
2
2
|
import { getMediaUrlForRuntime, isSupportMediaForRuntime, openLocalAlbumForRuntime, getMediaInfoForRuntime, } from "../../../feature/media/media";
|
|
3
3
|
import { getMediaRotateForRuntime } from "../../../feature/media/rotate";
|
|
4
|
+
import { isSupportMultiCameraForRuntime, getCameraInfoForRuntime, queryCameraInfoForRuntime, switchCameraForRuntime, } from "../../../feature/media/camera";
|
|
4
5
|
export async function getMediaUrl(params) {
|
|
5
6
|
return getMediaUrlForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
6
7
|
}
|
|
@@ -16,3 +17,15 @@ export function getMediaInfo() {
|
|
|
16
17
|
export function openLocalAlbum(params) {
|
|
17
18
|
return openLocalAlbumForRuntime(resolveRuntimeFromExportThis(this), params);
|
|
18
19
|
}
|
|
20
|
+
export function isSupportMultiCamera() {
|
|
21
|
+
return isSupportMultiCameraForRuntime(resolveRuntimeFromExportThis(this));
|
|
22
|
+
}
|
|
23
|
+
export function getCameraInfo() {
|
|
24
|
+
return getCameraInfoForRuntime(resolveRuntimeFromExportThis(this));
|
|
25
|
+
}
|
|
26
|
+
export async function queryCameraInfo() {
|
|
27
|
+
return queryCameraInfoForRuntime(resolveRuntimeFromExportThis(this));
|
|
28
|
+
}
|
|
29
|
+
export async function switchCamera(index) {
|
|
30
|
+
return switchCameraForRuntime(resolveRuntimeFromExportThis(this), index);
|
|
31
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
|
|
2
|
+
import type { DpMapDataType } from "../../interface";
|
|
3
|
+
import { locationSelectReportMap } from "../../config/dp-map/media";
|
|
4
|
+
export type CameraInfo = DpMapDataType<typeof locationSelectReportMap>;
|
|
5
|
+
export declare const isSupportMultiCameraForRuntime: (runtime: LockDeviceRuntime) => boolean;
|
|
6
|
+
export declare const getCameraInfoForRuntime: (runtime: LockDeviceRuntime) => CameraInfo | undefined;
|
|
7
|
+
export declare const queryCameraInfoForRuntime: (runtime: LockDeviceRuntime) => Promise<CameraInfo | undefined>;
|
|
8
|
+
export declare const switchCameraForRuntime: (runtime: LockDeviceRuntime, index: number) => Promise<true>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
|
+
import dpCodes from "../../config/dp-code";
|
|
3
|
+
import { locationSelectReportMap } from "../../config/dp-map/media";
|
|
4
|
+
import { getDpValueForRuntime } from "../dp/get-dp-value";
|
|
5
|
+
import { hasDpForRuntime } from "../dp/has-dp";
|
|
6
|
+
import { publishDpsForRuntime } from "../dp/publish-dps";
|
|
7
|
+
import { getError } from "src/utils/errors";
|
|
8
|
+
export const isSupportMultiCameraForRuntime = (runtime) => hasDpForRuntime(runtime, dpCodes.locationSelect);
|
|
9
|
+
export const getCameraInfoForRuntime = (runtime) => {
|
|
10
|
+
const raw = getDpValueForRuntime(runtime, dpCodes.locationSelect);
|
|
11
|
+
if (!raw) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
return dpUtils.parse(raw, locationSelectReportMap);
|
|
15
|
+
};
|
|
16
|
+
export const queryCameraInfoForRuntime = async (runtime) => {
|
|
17
|
+
await publishDpsForRuntime(runtime, { [dpCodes.locationSelect]: "ff" });
|
|
18
|
+
return getCameraInfoForRuntime(runtime);
|
|
19
|
+
};
|
|
20
|
+
export const switchCameraForRuntime = async (runtime, index) => {
|
|
21
|
+
const value = index.toString(16).padStart(2, "0");
|
|
22
|
+
await publishDpsForRuntime(runtime, { [dpCodes.locationSelect]: value });
|
|
23
|
+
const info = getCameraInfoForRuntime(runtime);
|
|
24
|
+
switch (info?.status) {
|
|
25
|
+
case 0:
|
|
26
|
+
return true;
|
|
27
|
+
case 2:
|
|
28
|
+
throw getError(1105);
|
|
29
|
+
case 1:
|
|
30
|
+
default:
|
|
31
|
+
throw getError(1104);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -52,67 +52,72 @@ export const createTempCustomForRuntime = parallelOnlyForRuntime(async function
|
|
|
52
52
|
throw handleCloudError(error);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
try {
|
|
56
|
+
await isValidPassword(baseData);
|
|
57
|
+
const { tyNum, name: createdName } = await createTemporaryPassword({
|
|
58
|
+
...baseData,
|
|
59
|
+
sn: 0,
|
|
60
|
+
availTime: 0,
|
|
61
|
+
symbolic: false,
|
|
62
|
+
dpTunnel: 2,
|
|
63
|
+
});
|
|
64
|
+
if (!tyNum) {
|
|
65
|
+
const error = getError(1043);
|
|
66
|
+
sdkLog("warn", "tempPassword", "createCustomMissingCloudNo", {
|
|
67
|
+
devId: rt.devId,
|
|
68
|
+
duration: Date.now() - startedAt,
|
|
69
|
+
error,
|
|
70
|
+
});
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
const targetDpCode = cfg.supportBigData
|
|
74
|
+
? dpCodes.tempPwdCreateW
|
|
75
|
+
: dpCodes.tempPwdCreate;
|
|
76
|
+
const dpPayload = dpUtils.format({
|
|
77
|
+
cloudNo: tyNum,
|
|
78
|
+
valid: true,
|
|
79
|
+
validConfig,
|
|
80
|
+
validNum: 0,
|
|
81
|
+
pwdLength: params.password.length,
|
|
82
|
+
pwd: params.password.split("").map(Number),
|
|
83
|
+
}, (cfg.supportBigData ? addTempPwdBigDpMap : addTempPwdDpMap));
|
|
84
|
+
const result = await publishDpsForRuntime(rt, {
|
|
85
|
+
[targetDpCode]: dpPayload,
|
|
86
|
+
}, {
|
|
87
|
+
checkReport: (dpsIn) => {
|
|
88
|
+
const dpDataRow = dpsIn;
|
|
89
|
+
const reportData = dpDataRow[targetDpCode];
|
|
90
|
+
if (reportData) {
|
|
91
|
+
const data = dpUtils.parse(dpDataRow[targetDpCode], (cfg.supportBigData
|
|
92
|
+
? reportAddTempPwdDBigpMap
|
|
93
|
+
: reportAddTempPwdDpMap));
|
|
94
|
+
if (data.cloudNo === tyNum) {
|
|
95
|
+
return data;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
if (result.status === 0) {
|
|
102
|
+
sdkLog("info", "tempPassword", "createCustomSuccess", {
|
|
103
|
+
devId: rt.devId,
|
|
104
|
+
duration: Date.now() - startedAt,
|
|
105
|
+
data: { route: "nearDp" },
|
|
106
|
+
});
|
|
107
|
+
return buildTempCustomCreateResult(createdName, params.password, result.unlockBindingId, effective);
|
|
108
|
+
}
|
|
109
|
+
const error = getError(result.status === 2 ? 1041 : 1042);
|
|
110
|
+
sdkLog("warn", "tempPassword", "createCustomDpFail", {
|
|
66
111
|
devId: rt.devId,
|
|
67
112
|
duration: Date.now() - startedAt,
|
|
113
|
+
data: { status: result.status },
|
|
68
114
|
error,
|
|
69
115
|
});
|
|
70
116
|
throw error;
|
|
71
117
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
: dpCodes.tempPwdCreate;
|
|
75
|
-
const dpPayload = dpUtils.format({
|
|
76
|
-
cloudNo: tyNum,
|
|
77
|
-
valid: true,
|
|
78
|
-
validConfig,
|
|
79
|
-
validNum: 0,
|
|
80
|
-
pwdLength: params.password.length,
|
|
81
|
-
pwd: params.password.split("").map(Number),
|
|
82
|
-
}, (cfg.supportBigData ? addTempPwdBigDpMap : addTempPwdDpMap));
|
|
83
|
-
const result = await publishDpsForRuntime(rt, {
|
|
84
|
-
[targetDpCode]: dpPayload,
|
|
85
|
-
}, {
|
|
86
|
-
checkReport: (dpsIn) => {
|
|
87
|
-
const dpDataRow = dpsIn;
|
|
88
|
-
const reportData = dpDataRow[targetDpCode];
|
|
89
|
-
if (reportData) {
|
|
90
|
-
const data = dpUtils.parse(dpDataRow[targetDpCode], (cfg.supportBigData
|
|
91
|
-
? reportAddTempPwdDBigpMap
|
|
92
|
-
: reportAddTempPwdDpMap));
|
|
93
|
-
if (data.cloudNo === tyNum) {
|
|
94
|
-
return data;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return false;
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
if (result.status === 0) {
|
|
101
|
-
sdkLog("info", "tempPassword", "createCustomSuccess", {
|
|
102
|
-
devId: rt.devId,
|
|
103
|
-
duration: Date.now() - startedAt,
|
|
104
|
-
data: { route: "nearDp" },
|
|
105
|
-
});
|
|
106
|
-
return buildTempCustomCreateResult(createdName, params.password, result.unlockBindingId, effective);
|
|
118
|
+
catch (er) {
|
|
119
|
+
throw handleCloudError(er);
|
|
107
120
|
}
|
|
108
|
-
const error = getError(result.status === 2 ? 1041 : 1042);
|
|
109
|
-
sdkLog("warn", "tempPassword", "createCustomDpFail", {
|
|
110
|
-
devId: rt.devId,
|
|
111
|
-
duration: Date.now() - startedAt,
|
|
112
|
-
data: { status: result.status },
|
|
113
|
-
error,
|
|
114
|
-
});
|
|
115
|
-
throw error;
|
|
116
121
|
});
|
|
117
122
|
export async function removeTempCustomForRuntime(rt, params) {
|
|
118
123
|
const cfg = rt.config;
|
package/lib/utils/errors.js
CHANGED
|
@@ -102,7 +102,9 @@ const errors = {
|
|
|
102
102
|
1100: "Binding limit reached",
|
|
103
103
|
1101: "The lock has already been bound, please do not bind it again",
|
|
104
104
|
1102: "Lock is binding",
|
|
105
|
-
1103: "Binding failed"
|
|
105
|
+
1103: "Binding failed",
|
|
106
|
+
1104: "Failed to switch cameras",
|
|
107
|
+
1105: "Camera switching is not supported",
|
|
106
108
|
};
|
|
107
109
|
export const getError = (code, ...places) => {
|
|
108
110
|
if (errors[code]) {
|
package/lib/utils/parse.js
CHANGED
|
@@ -6,7 +6,7 @@ export const parseCapabilities = (dpValue) => {
|
|
|
6
6
|
return null;
|
|
7
7
|
}
|
|
8
8
|
const data = dpUtils.parse(dpValue, capabilitiesMap);
|
|
9
|
-
if (data.
|
|
9
|
+
if (data.type === ModuleType.M7258) {
|
|
10
10
|
return {
|
|
11
11
|
...data,
|
|
12
12
|
rotateType: data.rotateType === 1 ? 0 : data.rotateType === 0 ? 1 : data.rotateType,
|