@ray-js/lock-sdk 1.2.0-beta.4 → 1.2.0-beta.6

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.
@@ -0,0 +1,26 @@
1
+ export interface CloudServiceStatus {
2
+ isExit: boolean;
3
+ duration: number;
4
+ imgDuration: number;
5
+ hasPurchasedOrder: boolean;
6
+ isFree: boolean;
7
+ }
8
+ export interface ServiceBenefitPopupItem {
9
+ name: string;
10
+ serviceCode: string;
11
+ catalogCode: string;
12
+ batchId: string;
13
+ expireTime: number;
14
+ usedTimes?: number;
15
+ numPerDevice?: number;
16
+ popupType: number;
17
+ }
18
+ export interface ClaimResultItem {
19
+ success: boolean;
20
+ errorCode?: string;
21
+ name?: string;
22
+ purchasedName?: string;
23
+ }
24
+ export declare const getCloudServiceStatusApi: (devId: string) => Promise<CloudServiceStatus>;
25
+ export declare const getServicePopupListApi: (devId: string) => Promise<ServiceBenefitPopupItem[]>;
26
+ export declare const claimServiceApi: (devId: string, batchId: string) => Promise<ClaimResultItem[]>;
@@ -0,0 +1,25 @@
1
+ import { requestApi } from "./request";
2
+ export const getCloudServiceStatusApi = (devId) => {
3
+ return requestApi({
4
+ logName: "getCloudServiceStatus",
5
+ api: "m.lock.media.effect.credential",
6
+ version: "1.0",
7
+ data: { devId },
8
+ });
9
+ };
10
+ export const getServicePopupListApi = (devId) => {
11
+ return requestApi({
12
+ logName: "getServicePopupList",
13
+ api: "m.lock.vas.popup.content",
14
+ version: "1.0",
15
+ data: { devId, catalogCodes: "" },
16
+ });
17
+ };
18
+ export const claimServiceApi = (devId, batchId) => {
19
+ return requestApi({
20
+ logName: "claimService",
21
+ api: "m.lock.vas.collect.trigger",
22
+ version: "1.0",
23
+ data: { devId, catalogCodes: "", batchId },
24
+ });
25
+ };
@@ -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";
@@ -67,6 +67,7 @@ const dpCodes = {
67
67
  doorOpened: "door_opened",
68
68
  unlockApp: "unlock_app",
69
69
  initiativeMessage: "initiative_message",
70
+ locationSelect: "location_select",
70
71
  manualLock: "manual_lock",
71
72
  checkCodeSet: "check_code_set",
72
73
  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
+ }];
@@ -0,0 +1,19 @@
1
+ export const locationSelectReportMap = [
2
+ {
3
+ name: "status",
4
+ },
5
+ {
6
+ name: "list",
7
+ bytes: 2,
8
+ loop: true,
9
+ type: "child",
10
+ childMap: [
11
+ {
12
+ name: "index",
13
+ },
14
+ {
15
+ name: "type",
16
+ },
17
+ ],
18
+ },
19
+ ];
@@ -11,6 +11,7 @@ export * from "./log";
11
11
  export * from "./signal";
12
12
  export * from "./sleep";
13
13
  export * from "./misc";
14
+ export * from "./service";
14
15
  export * from "./media";
15
16
  export * from "./voice-file";
16
17
  export * from "./linkage";
@@ -11,6 +11,7 @@ export * from "./log";
11
11
  export * from "./signal";
12
12
  export * from "./sleep";
13
13
  export * from "./misc";
14
+ export * from "./service";
14
15
  export * from "./media";
15
16
  export * from "./voice-file";
16
17
  export * from "./linkage";
@@ -1,6 +1,11 @@
1
- import { GetMediaUrlParams, OpenLocalAlbumParams } from "../../../feature/media/media";
1
+ import { GetMediaUrlParams, OpenLocalAlbumParams, GotoPlaybackParams } from "../../../feature/media/media";
2
2
  export declare function getMediaUrl(params: GetMediaUrlParams): Promise<import("../../../feature/media/media").MediaUrlResult>;
3
3
  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 gotoPlayback(params?: GotoPlaybackParams): Promise<void>;
8
+ export declare function isSupportMultiCamera(): boolean;
9
+ export declare function getCameraInfo(): import("../../../feature/media/camera").CameraInfo | undefined;
10
+ export declare function queryCameraInfo(): Promise<import("../../../feature/media/camera").CameraInfo | undefined>;
11
+ export declare function switchCamera(index: number): Promise<true>;
@@ -1,6 +1,7 @@
1
1
  import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
2
- import { getMediaUrlForRuntime, isSupportMediaForRuntime, openLocalAlbumForRuntime, getMediaInfoForRuntime, } from "../../../feature/media/media";
2
+ import { getMediaUrlForRuntime, isSupportMediaForRuntime, openLocalAlbumForRuntime, gotoPlaybackForRuntime, 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,18 @@ export function getMediaInfo() {
16
17
  export function openLocalAlbum(params) {
17
18
  return openLocalAlbumForRuntime(resolveRuntimeFromExportThis(this), params);
18
19
  }
20
+ export function gotoPlayback(params) {
21
+ return gotoPlaybackForRuntime(resolveRuntimeFromExportThis(this), params);
22
+ }
23
+ export function isSupportMultiCamera() {
24
+ return isSupportMultiCameraForRuntime(resolveRuntimeFromExportThis(this));
25
+ }
26
+ export function getCameraInfo() {
27
+ return getCameraInfoForRuntime(resolveRuntimeFromExportThis(this));
28
+ }
29
+ export async function queryCameraInfo() {
30
+ return queryCameraInfoForRuntime(resolveRuntimeFromExportThis(this));
31
+ }
32
+ export async function switchCamera(index) {
33
+ return switchCameraForRuntime(resolveRuntimeFromExportThis(this), index);
34
+ }
@@ -0,0 +1,4 @@
1
+ export type { CloudServiceStatus, ServiceBenefitPopupItem, ClaimResultItem, } from "../../../api/service";
2
+ export declare function getCloudServiceStatus(): Promise<import("../../../api/service").CloudServiceStatus>;
3
+ export declare function getServicePopupList(): Promise<import("../../../api/service").ServiceBenefitPopupItem[]>;
4
+ export declare function claimService(batchId: string): Promise<import("../../../api/service").ClaimResultItem[]>;
@@ -0,0 +1,11 @@
1
+ import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
2
+ import { getCloudServiceStatusForRuntime, getServicePopupListForRuntime, claimServiceForRuntime, } from "../../../feature/service/value-added";
3
+ export async function getCloudServiceStatus() {
4
+ return getCloudServiceStatusForRuntime(resolveRuntimeFromExportThis(this));
5
+ }
6
+ export async function getServicePopupList() {
7
+ return getServicePopupListForRuntime(resolveRuntimeFromExportThis(this));
8
+ }
9
+ export async function claimService(batchId) {
10
+ return claimServiceForRuntime(resolveRuntimeFromExportThis(this), batchId);
11
+ }
@@ -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 "../../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
+ };
@@ -19,6 +19,12 @@ export interface OpenLocalAlbumParams {
19
19
  serviceCode?: string;
20
20
  }
21
21
  export declare const openLocalAlbumForRuntime: (runtime: LockDeviceRuntime, params?: OpenLocalAlbumParams) => Promise<void>;
22
+ export interface GotoPlaybackParams {
23
+ tabs?: ("local" | "cloud")[];
24
+ isLowPower?: boolean;
25
+ rotate?: number;
26
+ }
27
+ export declare const gotoPlaybackForRuntime: (runtime: LockDeviceRuntime, params?: GotoPlaybackParams) => Promise<void>;
22
28
  export interface MediaInfo {
23
29
  imageAngle: number;
24
30
  videoAngle: number;
@@ -52,6 +52,27 @@ export const openLocalAlbumForRuntime = async (runtime, params) => {
52
52
  }
53
53
  return Promise.reject(getError(1013));
54
54
  };
55
+ export const gotoPlaybackForRuntime = async (runtime, params) => {
56
+ const link = await isSupportShortLink("camera_playbacks_panel");
57
+ if (!link) {
58
+ return Promise.reject(getError(1013));
59
+ }
60
+ const tabs = params?.tabs && params.tabs.length ? params.tabs : ["local"];
61
+ let url = `tuyaSmart://${link}?extra_camera_uuid=${runtime.devId}&devId=${runtime.devId}&bizType=doorLock&defaultShowTabs=true&theme=1&tabs=${JSON.stringify(tabs)}`;
62
+ if (params?.isLowPower) {
63
+ url += `&isLowPowerDevice=true`;
64
+ }
65
+ if (params?.rotate !== undefined) {
66
+ url += `&rotate=${params.rotate}`;
67
+ }
68
+ return new Promise((resolve, reject) => {
69
+ ty.router({
70
+ url,
71
+ success: () => resolve(),
72
+ fail: (e) => reject(e),
73
+ });
74
+ });
75
+ };
55
76
  export const getMediaInfoForRuntime = (runtime) => {
56
77
  const isSEI = runtime.config.capabilities?.rotateType === RotateType.SEI;
57
78
  return {
@@ -52,6 +52,11 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
52
52
  cloudStorage: {
53
53
  support: deviceAdvancedAbility.types.includes(0),
54
54
  },
55
+ vr: {
56
+ support: false,
57
+ defaultMode: "",
58
+ modes: [],
59
+ },
55
60
  ai: {
56
61
  support: false,
57
62
  config: {},
@@ -52,67 +52,72 @@ export const createTempCustomForRuntime = parallelOnlyForRuntime(async function
52
52
  throw handleCloudError(error);
53
53
  }
54
54
  }
55
- await isValidPassword(baseData);
56
- const { tyNum, name: createdName } = await createTemporaryPassword({
57
- ...baseData,
58
- sn: 0,
59
- availTime: 0,
60
- symbolic: false,
61
- dpTunnel: 2,
62
- });
63
- if (!tyNum) {
64
- const error = getError(1043);
65
- sdkLog("warn", "tempPassword", "createCustomMissingCloudNo", {
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
- const targetDpCode = cfg.supportBigData
73
- ? dpCodes.tempPwdCreateW
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;
@@ -1,5 +1,6 @@
1
1
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
2
  export interface GotoServiceParams {
3
3
  tab?: "cloudStorage" | "AI";
4
+ showGift?: boolean;
4
5
  }
5
6
  export declare function gotoServiceForRuntime(rt: LockDeviceRuntime, params?: GotoServiceParams): Promise<unknown>;
@@ -5,7 +5,10 @@ export function gotoServiceForRuntime(rt, params) {
5
5
  type = 3;
6
6
  }
7
7
  return new Promise((resolve, reject) => {
8
- const url = `godzilla://tyawqoyej4wi3pqebb?deviceId=${rt.config.devInfo.devId}&commodityType=${type}`;
8
+ let url = `godzilla://tyawqoyej4wi3pqebb?deviceId=${rt.config.devInfo.devId}&commodityType=${type}`;
9
+ if (params?.showGift) {
10
+ url += `&showGift=true`;
11
+ }
9
12
  navigateToMiniProgram({
10
13
  position: "bottom",
11
14
  shortLink: url,
@@ -0,0 +1,4 @@
1
+ import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
+ export declare const getCloudServiceStatusForRuntime: (rt: LockDeviceRuntime) => Promise<import("../../api/service").CloudServiceStatus>;
3
+ export declare const getServicePopupListForRuntime: (rt: LockDeviceRuntime) => Promise<import("../../api/service").ServiceBenefitPopupItem[]>;
4
+ export declare const claimServiceForRuntime: (rt: LockDeviceRuntime, batchId: string) => Promise<import("../../api/service").ClaimResultItem[]>;
@@ -0,0 +1,4 @@
1
+ import { getCloudServiceStatusApi, getServicePopupListApi, claimServiceApi, } from "../../api/service";
2
+ export const getCloudServiceStatusForRuntime = (rt) => getCloudServiceStatusApi(rt.config.devInfo.devId);
3
+ export const getServicePopupListForRuntime = (rt) => getServicePopupListApi(rt.config.devInfo.devId);
4
+ export const claimServiceForRuntime = (rt, batchId) => claimServiceApi(rt.config.devInfo.devId, batchId);
@@ -19,6 +19,9 @@ export const syncUnlockMethodWithRuntime = async (runtime) => {
19
19
  });
20
20
  rt.sync.unlockMethodAutoSyncEnabled = false;
21
21
  const { allOpenDps = "" } = await getCurrentUserForRuntime(rt);
22
+ if (!allOpenDps) {
23
+ return;
24
+ }
22
25
  const { ins = "", distributed = false } = await fetchSyncUnlockMethodInfo({
23
26
  devId: rt.config.devInfo.devId,
24
27
  dpIds: allOpenDps.split(","),
@@ -338,6 +338,11 @@ export interface DeviceAdvancedAbility {
338
338
  cloudStorage: {
339
339
  support: boolean;
340
340
  };
341
+ vr: {
342
+ support: boolean;
343
+ defaultMode: string;
344
+ modes: string[];
345
+ };
341
346
  ai: {
342
347
  support: boolean;
343
348
  config: Record<string, any>;
@@ -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]) {
@@ -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.tyep === ModuleType.M7258) {
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lock-sdk",
3
- "version": "1.2.0-beta.4",
3
+ "version": "1.2.0-beta.6",
4
4
  "files": [
5
5
  "lib",
6
6
  "LICENSE.md"