@ray-js/lock-sdk 1.2.0-beta.24 → 1.2.0-beta.25

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 (72) hide show
  1. package/lib/api/fit.d.ts +55 -2
  2. package/lib/api/fit.js +43 -1
  3. package/lib/api/log.d.ts +31 -0
  4. package/lib/api/log.js +22 -0
  5. package/lib/api/product.d.ts +8 -0
  6. package/lib/api/product.js +10 -0
  7. package/lib/api/temp.d.ts +21 -0
  8. package/lib/api/temp.js +24 -0
  9. package/lib/entries/fit/bootstrap/bootstrap-lock-instance.js +2 -0
  10. package/lib/entries/fit/bootstrap/bootstrap.js +1 -0
  11. package/lib/entries/fit/build-instance.js +2 -0
  12. package/lib/entries/fit/exports/binding.d.ts +4 -3
  13. package/lib/entries/fit/exports/device.d.ts +8 -7
  14. package/lib/entries/fit/exports/device.js +12 -12
  15. package/lib/entries/fit/exports/index.d.ts +3 -0
  16. package/lib/entries/fit/exports/index.js +3 -0
  17. package/lib/entries/fit/exports/log.d.ts +7 -0
  18. package/lib/entries/fit/exports/log.js +15 -0
  19. package/lib/entries/fit/exports/misc.d.ts +5 -0
  20. package/lib/entries/fit/exports/misc.js +9 -0
  21. package/lib/entries/fit/exports/setting.d.ts +4 -0
  22. package/lib/entries/fit/exports/setting.js +8 -0
  23. package/lib/entries/fit/exports/state.d.ts +4 -0
  24. package/lib/entries/fit/exports/state.js +12 -0
  25. package/lib/entries/fit/exports/temp.d.ts +24 -3
  26. package/lib/entries/fit/exports/temp.js +43 -2
  27. package/lib/entries/fit/index.js +2 -0
  28. package/lib/entries/main/exports/log.d.ts +2 -0
  29. package/lib/entries/main/exports/log.js +7 -1
  30. package/lib/entries/main/exports/misc.d.ts +3 -1
  31. package/lib/entries/main/exports/misc.js +2 -2
  32. package/lib/feature/fit/bind-lock-to-fit.js +41 -1
  33. package/lib/feature/fit/ble-key.d.ts +10 -4
  34. package/lib/feature/fit/ble-key.js +145 -4
  35. package/lib/feature/fit/device-bv.d.ts +2 -0
  36. package/lib/feature/fit/device-bv.js +15 -0
  37. package/lib/feature/fit/invalid-password.d.ts +10 -0
  38. package/lib/feature/fit/invalid-password.js +43 -0
  39. package/lib/feature/fit/list.d.ts +11 -2
  40. package/lib/feature/fit/list.js +44 -5
  41. package/lib/feature/fit/log.d.ts +7 -0
  42. package/lib/feature/fit/log.js +123 -0
  43. package/lib/feature/fit/method/update-remove.js +40 -14
  44. package/lib/feature/fit/password-list.d.ts +37 -0
  45. package/lib/feature/fit/password-list.js +44 -1
  46. package/lib/feature/fit/product.d.ts +5 -0
  47. package/lib/feature/fit/product.js +11 -0
  48. package/lib/feature/fit/security-channel.d.ts +2 -0
  49. package/lib/feature/fit/security-channel.js +15 -0
  50. package/lib/feature/fit/sync.d.ts +4 -2
  51. package/lib/feature/fit/sync.js +56 -22
  52. package/lib/feature/fit/temp-password.d.ts +23 -0
  53. package/lib/feature/fit/temp-password.js +95 -3
  54. package/lib/feature/fit/users.d.ts +1 -0
  55. package/lib/feature/fit/users.js +1 -0
  56. package/lib/feature/log/log.d.ts +5 -1
  57. package/lib/feature/log/log.js +6 -4
  58. package/lib/feature/misc/connect-device.d.ts +1 -1
  59. package/lib/feature/misc/connect-device.js +5 -5
  60. package/lib/feature/password/temporary/offline-create.d.ts +14 -0
  61. package/lib/feature/password/temporary/offline-create.js +77 -1
  62. package/lib/feature/state/clear.js +1 -0
  63. package/lib/feature/state/platform-routing.js +4 -0
  64. package/lib/feature/state/sync/remote-serect-key.js +7 -0
  65. package/lib/feature/utils/index.d.ts +1 -0
  66. package/lib/feature/utils/index.js +1 -0
  67. package/lib/interface.d.ts +12 -0
  68. package/lib/runtime/LockDeviceRuntime.js +3 -0
  69. package/lib/runtime/lock-config.d.ts +1 -0
  70. package/lib/runtime/lock-config.js +2 -1
  71. package/lib/runtime/runtime-state-types.d.ts +6 -0
  72. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { getAlarmList, getAlbumMessages, getLatest2Log, getLockLogList, getRecordList, } from "../../api/log";
1
+ import { getAlarmList, getAlbumMessages, getLatest2Log, getLockLogList, getRecordList, getAlarmUnreadCountApi, getActivePeriodApi, } from "../../api/log";
2
2
  import dpCodes from "../../config/dp-code";
3
3
  import { getCurrentUserForRuntime } from "../user/current-user";
4
4
  import base64ToHex from "../../utils/base64-to-hex";
@@ -153,7 +153,7 @@ function handleLockLogs(list, cfg) {
153
153
  userId: item.userId,
154
154
  userName: userName || "",
155
155
  unlockName: unlockName || "",
156
- mediaInfo: item.mediaInfoList?.map?.(item => {
156
+ mediaInfo: item.mediaInfoList?.map?.((item) => {
157
157
  return {
158
158
  mediaPath: item.mediaPath,
159
159
  fileKey: item.fileKey,
@@ -241,7 +241,7 @@ export const openDps = [
241
241
  dpCodes.unlockApp,
242
242
  dpCodes.unlockMatterKw,
243
243
  ];
244
- const closeTypes = [
244
+ export const closeTypes = [
245
245
  "UNDEFINED",
246
246
  "APP_REMOTE",
247
247
  "VOICE_REMOTE",
@@ -251,7 +251,7 @@ const closeTypes = [
251
251
  "AUTO",
252
252
  "LOCAL_MANUAL",
253
253
  ];
254
- const dpIdsForUsernameToUnlockName = [89, 69, 55, 67, 3, 32];
254
+ export const dpIdsForUsernameToUnlockName = [89, 69, 55, 67, 3, 32];
255
255
  export async function getLogsForRuntime(rt, params) {
256
256
  const cfg = rt.config;
257
257
  const { page = 1, pageSize = 50 } = params || {};
@@ -468,3 +468,5 @@ export const getLockLogListForRuntime = async (rt, params) => {
468
468
  lastRowKey: data?.lastRowKey ?? "",
469
469
  };
470
470
  };
471
+ export const getAlarmUnreadCountForRuntime = (rt) => getAlarmUnreadCountApi(rt.config.devInfo.devId);
472
+ export const getActivePeriodForRuntime = (rt) => getActivePeriodApi(rt.config.devInfo.devId);
@@ -1,2 +1,2 @@
1
1
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
- export declare function connectDeviceForRuntime(rt: LockDeviceRuntime): Promise<true>;
2
+ export declare function connectDeviceForRuntime(rt: LockDeviceRuntime, timeout?: number): Promise<true>;
@@ -72,7 +72,7 @@ const awakeDevice = async (devId, timeout) => {
72
72
  run();
73
73
  });
74
74
  };
75
- const connectBle = async (devId) => {
75
+ const connectBle = async (devId, timeout) => {
76
76
  const startedAt = Date.now();
77
77
  sdkLog("info", "connectDevice", "bleConnectStart", { devId });
78
78
  return new Promise((resolve, reject) => {
@@ -109,7 +109,7 @@ const connectBle = async (devId) => {
109
109
  error,
110
110
  });
111
111
  reject(error);
112
- }, 15000);
112
+ }, timeout ?? 15000);
113
113
  const clearTimer = () => {
114
114
  clearTimeout(timer);
115
115
  offBleChange(handleStatusChange);
@@ -143,7 +143,7 @@ const connectBle = async (devId) => {
143
143
  });
144
144
  });
145
145
  };
146
- export async function connectDeviceForRuntime(rt) {
146
+ export async function connectDeviceForRuntime(rt, timeout) {
147
147
  const cfg = rt.config;
148
148
  const devId = cfg.devInfo.devId;
149
149
  const deviceStatus = getDeviceStatusForRuntime(rt);
@@ -160,7 +160,7 @@ export async function connectDeviceForRuntime(rt) {
160
160
  });
161
161
  if (deviceStatus.connectEnable && hasWirelessAwakeDp) {
162
162
  if (cfg.devInfo.isCloudOnline && !getDpValueForRuntime(rt, wirelessAwake)) {
163
- const result = await awakeDevice(devId);
163
+ const result = await awakeDevice(devId, timeout);
164
164
  sdkLog("info", "connectDevice", "success", {
165
165
  devId,
166
166
  duration: Date.now() - startedAt,
@@ -179,7 +179,7 @@ export async function connectDeviceForRuntime(rt) {
179
179
  });
180
180
  return true;
181
181
  }
182
- await connectBle(devId);
182
+ await connectBle(devId, timeout);
183
183
  if (rt.cache.deviceAdvanceAbilityCache?.yuChannel.support) {
184
184
  if (rt.cache.deviceAdvanceAbilityCache?.yuChannel.value === 1) {
185
185
  yuChannelSyncSingleSync(devId);
@@ -1,7 +1,21 @@
1
+ import { type LimitOfflinePwdItem, type OfflinePwdAvailableResult } from "../../../api/temp";
1
2
  import type { TempPasswordResult } from "../../../interface";
2
3
  import type { LockDeviceRuntime } from "../../../runtime/LockDeviceRuntime";
3
4
  import type { CreateClearParams, CreateLimitParams, CreateOnceParams } from "./types";
4
5
  export declare function createTempLimitForRuntime(rt: LockDeviceRuntime, params: CreateLimitParams): Promise<TempPasswordResult>;
5
6
  export declare function createTempOnceForRuntime(rt: LockDeviceRuntime, params: CreateOnceParams): Promise<TempPasswordResult>;
7
+ export interface FitOfflineOnceResult {
8
+ password: string;
9
+ pwdId: string;
10
+ gmtExpired: number;
11
+ }
12
+ export declare function createFitOfflineOnceForRuntime(rt: LockDeviceRuntime): Promise<FitOfflineOnceResult>;
13
+ export declare function createFitOfflineLimitForRuntime(rt: LockDeviceRuntime, params: {
14
+ effectiveTime: number;
15
+ invalidTime: number;
16
+ }): Promise<FitOfflineOnceResult>;
17
+ export declare function createFitOfflineClearAllForRuntime(rt: LockDeviceRuntime): Promise<FitOfflineOnceResult>;
18
+ export declare function getFitOfflineRevocableListForRuntime(rt: LockDeviceRuntime): Promise<LimitOfflinePwdItem[]>;
19
+ export declare function getFitOfflinePwdAvailableForRuntime(rt: LockDeviceRuntime, pwdType: string): Promise<OfflinePwdAvailableResult>;
6
20
  export declare function createTempDynamicForRuntime(rt: LockDeviceRuntime): Promise<TempPasswordResult>;
7
21
  export declare function createTempClearForRuntime(rt: LockDeviceRuntime, params: CreateClearParams): Promise<TempPasswordResult>;
@@ -1,4 +1,4 @@
1
- import { getDynamicPassword, revokeOfflinePassword, } from "../../../api/temp";
1
+ import { createOfflineOnceAPI, getDynamicPassword, getLimitOfflinePwdListForClear, getOfflinePwdAvailable, revokeOfflinePassword, } from "../../../api/temp";
2
2
  import { parseOfflinePasswordForRuntime } from "../../utils";
3
3
  import { getError, handleCloudError } from "../../../utils/errors";
4
4
  import { getOfflinePassword } from "./internal/password-helpers";
@@ -87,6 +87,82 @@ export async function createTempOnceForRuntime(rt, params) {
87
87
  },
88
88
  };
89
89
  }
90
+ async function createFitOfflinePwdForRuntime(rt, params) {
91
+ const startedAt = Date.now();
92
+ sdkLog("info", "tempPassword", "createFitOfflinePwdStart", {
93
+ devId: rt.devId,
94
+ data: { pwdType: params.pwdType },
95
+ });
96
+ try {
97
+ const res = await createOfflineOnceAPI({
98
+ devId: rt.devId,
99
+ ...params,
100
+ });
101
+ sdkLog("info", "tempPassword", "createFitOfflinePwdSuccess", {
102
+ devId: rt.devId,
103
+ duration: Date.now() - startedAt,
104
+ data: { pwdType: params.pwdType },
105
+ });
106
+ return {
107
+ password: parseOfflinePasswordForRuntime(rt, res.pwd),
108
+ pwdId: res.pwdId,
109
+ gmtExpired: res.gmtExpired,
110
+ };
111
+ }
112
+ catch (error) {
113
+ sdkLog("error", "tempPassword", "createFitOfflinePwdFail", {
114
+ devId: rt.devId,
115
+ duration: Date.now() - startedAt,
116
+ data: { pwdType: params.pwdType },
117
+ error,
118
+ });
119
+ throw handleCloudError(error);
120
+ }
121
+ }
122
+ export function createFitOfflineOnceForRuntime(rt) {
123
+ return createFitOfflinePwdForRuntime(rt, {
124
+ pwdType: "1",
125
+ gmtStart: "0",
126
+ gmtExpired: "0",
127
+ });
128
+ }
129
+ export function createFitOfflineLimitForRuntime(rt, params) {
130
+ const { effectiveTime, invalidTime } = params;
131
+ if (effectiveTime >= invalidTime) {
132
+ throw getError(1010);
133
+ }
134
+ return createFitOfflinePwdForRuntime(rt, {
135
+ pwdType: "0",
136
+ gmtStart: String(effectiveTime),
137
+ gmtExpired: String(invalidTime),
138
+ });
139
+ }
140
+ export function createFitOfflineClearAllForRuntime(rt) {
141
+ return createFitOfflinePwdForRuntime(rt, {
142
+ pwdType: "9",
143
+ gmtStart: "0",
144
+ gmtExpired: "0",
145
+ });
146
+ }
147
+ export async function getFitOfflineRevocableListForRuntime(rt) {
148
+ try {
149
+ return (await getLimitOfflinePwdListForClear({ devId: rt.devId })) || [];
150
+ }
151
+ catch (error) {
152
+ throw handleCloudError(error);
153
+ }
154
+ }
155
+ export async function getFitOfflinePwdAvailableForRuntime(rt, pwdType) {
156
+ try {
157
+ return await getOfflinePwdAvailable({
158
+ devId: rt.config.devInfo.devId,
159
+ pwdType,
160
+ });
161
+ }
162
+ catch (error) {
163
+ throw handleCloudError(error);
164
+ }
165
+ }
90
166
  export async function createTempDynamicForRuntime(rt) {
91
167
  const startedAt = Date.now();
92
168
  sdkLog("info", "tempPassword", "createDynamicStart", {
@@ -8,6 +8,7 @@ export function clearStateForRuntime(runtime) {
8
8
  runtime.cache.currentUser = null;
9
9
  runtime.cache.offlineDpCache = undefined;
10
10
  runtime.cache.deviceAdvanceAbilityCache = undefined;
11
+ runtime.cache.fitDeviceBvCache = undefined;
11
12
  runtime.cache.isActiveThreadCache = false;
12
13
  runtime.sync.hasSyncedT0 = false;
13
14
  runtime.sync.syncDeleteUsersBusy = false;
@@ -3,6 +3,7 @@ import { getRuntimeByDevId, listRegisteredRuntimes, } from "../../runtime/regist
3
3
  import emitter from "../../utils/event";
4
4
  import { getWiFiSignalChangeEvent } from "../misc/signal";
5
5
  import { autoSyncTemp } from "../password/sync-temp";
6
+ import { syncFitBindingsForRuntime } from "../fit/sync";
6
7
  import syncT0 from "./sync/t0";
7
8
  import syncRemoteSerectKey from "./sync/remote-serect-key";
8
9
  import { syncOfflineDps } from "./sync/offline-dps";
@@ -93,6 +94,9 @@ const globalHandleBleChange = ({ deviceId, status }) => {
93
94
  if (rt) {
94
95
  updateOnlineType(rt);
95
96
  if (status === "CONNECTED") {
97
+ if (rt.config.isFitting) {
98
+ syncFitBindingsForRuntime(rt).catch(() => { });
99
+ }
96
100
  void syncRemoteSerectKey(rt);
97
101
  autoSyncTemp(rt);
98
102
  void syncT0(rt);
@@ -11,6 +11,13 @@ import { reportSetKey as reportSetKeyMap, setKey as setKeyMap, } from "../../../
11
11
  import { sdkLog } from "../../../utils/sdk-log";
12
12
  const syncRemoteSerectKey = async (runtime, force) => {
13
13
  const rt = runtime;
14
+ if (rt.config.isFitting || !rt.config.idsByCode[dpCodes.remoteNoPdSetkey]) {
15
+ sdkLog("debug", "syncKey", "skipped", {
16
+ devId: rt.devId,
17
+ data: { reason: "unsupported", force: !!force },
18
+ });
19
+ return;
20
+ }
14
21
  const useNear = isUseNearChannelForRuntime(rt);
15
22
  if (!useNear) {
16
23
  sdkLog("debug", "syncKey", "skipped", {
@@ -1,5 +1,6 @@
1
1
  import type { UnlockMethodConfig } from "../../interface";
2
2
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
3
+ export declare const unlockMethodDpCodes: string[];
3
4
  export declare const getUnlockMethodTypeByDpCodeForRuntime: (rt: LockDeviceRuntime, dpCode: string) => UnlockMethodConfig;
4
5
  export declare const getUnlockMethodTypeByIdForRuntime: (rt: LockDeviceRuntime, id: number | string) => UnlockMethodConfig;
5
6
  export declare const getUnlockMethodTypeByTypeForRuntime: (rt: LockDeviceRuntime, type: string) => UnlockMethodConfig;
@@ -33,6 +33,7 @@ const unlockMethodConfigs = [
33
33
  id: 6,
34
34
  },
35
35
  ];
36
+ export const unlockMethodDpCodes = unlockMethodConfigs.reduce((res, item) => res.concat(item.codes), []);
36
37
  const getUnlockMethodTypeForRuntime = (rt, cb) => {
37
38
  const result = unlockMethodConfigs.find(cb);
38
39
  if (result) {
@@ -182,6 +182,16 @@ export interface EffectiveConfig {
182
182
  effectiveTime?: number;
183
183
  expiredTime?: number;
184
184
  }
185
+ export interface FitBleKeyItem {
186
+ id: string;
187
+ unlockBindingId: string;
188
+ name: string;
189
+ opModeSubType?: number;
190
+ effectiveConfig: EffectiveConfig;
191
+ sn?: number;
192
+ userName?: string;
193
+ devNameList?: string[];
194
+ }
185
195
  export interface UnBindUnlockMethod {
186
196
  dpId: number;
187
197
  dpCode: string;
@@ -276,6 +286,8 @@ export interface LogData {
276
286
  dpCode: string;
277
287
  data: any;
278
288
  userName: string;
289
+ avatarUrl?: string;
290
+ relateDevName?: string;
279
291
  bindable: boolean;
280
292
  unlockName: string;
281
293
  mediaInfo?: MediaInfo[];
@@ -14,6 +14,7 @@ export class LockDeviceRuntime {
14
14
  offlineDpCache: undefined,
15
15
  isActiveThreadCache: false,
16
16
  deviceAdvanceAbilityCache: undefined,
17
+ fitDeviceBvCache: undefined,
17
18
  };
18
19
  this.sync = {
19
20
  hasSyncedT0: false,
@@ -21,6 +22,8 @@ export class LockDeviceRuntime {
21
22
  unlockMethodAutoSyncEnabled: true,
22
23
  tempAutoSyncEnabled: true,
23
24
  tempPayloadSyncing: false,
25
+ fitSyncReportHandler: null,
26
+ fitBindingsSyncStarted: false,
24
27
  };
25
28
  this.infra = {
26
29
  eventsRegistered: false,
@@ -26,6 +26,7 @@ export type LockConfigState = {
26
26
  isTwoWayTalk: boolean;
27
27
  cameraConfig: CameraConfig[];
28
28
  notSupportWake: boolean;
29
+ isFitting: boolean;
29
30
  };
30
31
  export declare function createDefaultDeviceStatus(): DeviceStatus;
31
32
  export declare function createLockConfigState(): LockConfigState;
@@ -35,6 +35,7 @@ export function createLockConfigState() {
35
35
  supportTalk: false,
36
36
  isTwoWayTalk: false,
37
37
  cameraConfig: [],
38
- notSupportWake: false
38
+ notSupportWake: false,
39
+ isFitting: false
39
40
  };
40
41
  }
@@ -5,6 +5,7 @@ export interface LockRuntimeCacheFields {
5
5
  offlineDpCache: OfflineDps | undefined;
6
6
  isActiveThreadCache: boolean;
7
7
  deviceAdvanceAbilityCache: DeviceAdvancedAbility | undefined;
8
+ fitDeviceBvCache: Promise<number> | undefined;
8
9
  }
9
10
  export interface LockRuntimeSyncFlags {
10
11
  hasSyncedT0: boolean;
@@ -12,6 +13,11 @@ export interface LockRuntimeSyncFlags {
12
13
  unlockMethodAutoSyncEnabled: boolean;
13
14
  tempAutoSyncEnabled: boolean;
14
15
  tempPayloadSyncing: boolean;
16
+ fitSyncReportHandler: ((data: {
17
+ deviceId?: string;
18
+ data?: string;
19
+ }) => void) | null;
20
+ fitBindingsSyncStarted: boolean;
15
21
  }
16
22
  export interface LockRuntimeInfraFields {
17
23
  eventsRegistered: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lock-sdk",
3
- "version": "1.2.0-beta.24",
3
+ "version": "1.2.0-beta.25",
4
4
  "files": [
5
5
  "lib",
6
6
  "LICENSE.md"