@ray-js/lock-sdk 1.1.1-beta.2 → 1.1.1-beta.21
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/index.d.ts +8 -0
- package/lib/api/index.js +10 -0
- package/lib/api/lock.d.ts +5 -0
- package/lib/api/lock.js +7 -0
- package/lib/api/user.d.ts +3 -17
- package/lib/api/user.js +5 -5
- package/lib/capability.js +45 -19
- package/lib/config/dp-map/common.js +1 -1
- package/lib/config/dp-map/unlock-method-big.js +1 -1
- package/lib/config/dp-map/unlock-method.d.ts +4 -4
- package/lib/config/dp-map/unlock-method.js +1 -1
- package/lib/config/index.d.ts +2 -1
- package/lib/config/index.js +1 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +7 -2
- package/lib/interface.d.ts +13 -1
- package/lib/log.js +16 -4
- package/lib/offline-dps.js +4 -12
- package/lib/open/ble-dedicated-dp.d.ts +4 -0
- package/lib/open/ble-dedicated-dp.js +148 -0
- package/lib/open/ble-remote-no-dp-key.d.ts +4 -0
- package/lib/open/ble-remote-no-dp-key.js +69 -0
- package/lib/open/report-status.d.ts +1 -0
- package/lib/open/report-status.js +23 -0
- package/lib/open.js +10 -10
- package/lib/other.d.ts +1 -0
- package/lib/other.js +10 -2
- package/lib/state.js +25 -15
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/temp.js +1 -1
- package/lib/sync/unlock-method.js +16 -16
- package/lib/sync/user.js +46 -21
- package/lib/temporary.js +15 -33
- package/lib/unlock-method.d.ts +3 -1
- package/lib/unlock-method.js +103 -18
- package/lib/user.d.ts +2 -2
- package/lib/user.js +81 -71
- package/lib/utils/device.d.ts +1 -0
- package/lib/utils/device.js +6 -0
- package/lib/utils/errors.d.ts +1 -0
- package/lib/utils/errors.js +37 -0
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +15 -12
- package/package.json +1 -1
package/lib/api/index.d.ts
CHANGED
|
@@ -27,4 +27,12 @@ export declare const fetchOfflineDpData: (deviceId: string) => Promise<{
|
|
|
27
27
|
}[]>;
|
|
28
28
|
export declare const publishOfflineDpData: (deviceId: string, dpData: Record<string, DpValue>) => Promise<unknown>;
|
|
29
29
|
export declare const clearOfflineDpData: (deviceId: string) => Promise<unknown>;
|
|
30
|
+
export declare const getFileRemoteUrl: ({ biz, resources, }: {
|
|
31
|
+
biz: string;
|
|
32
|
+
resources: {
|
|
33
|
+
objectKey: string;
|
|
34
|
+
}[];
|
|
35
|
+
}) => Promise<{
|
|
36
|
+
signedUrls: Record<string, string>;
|
|
37
|
+
}>;
|
|
30
38
|
export {};
|
package/lib/api/index.js
CHANGED
|
@@ -70,3 +70,13 @@ export const clearOfflineDpData = async (deviceId) => {
|
|
|
70
70
|
version: "1.0",
|
|
71
71
|
});
|
|
72
72
|
};
|
|
73
|
+
export const getFileRemoteUrl = ({ biz, resources, }) => {
|
|
74
|
+
return requestApi({
|
|
75
|
+
api: `${THING}.web.fastroute.download.sign`,
|
|
76
|
+
version: "2.0",
|
|
77
|
+
data: {
|
|
78
|
+
biz,
|
|
79
|
+
signedRequest: { resources },
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
};
|
package/lib/api/lock.d.ts
CHANGED
|
@@ -124,4 +124,9 @@ interface BindUnlockMethodToUserByRecordParams {
|
|
|
124
124
|
unlockIds: string[];
|
|
125
125
|
}
|
|
126
126
|
export declare const bindUnlockMethodToUserByRecord: (params: BindUnlockMethodToUserByRecordParams) => Promise<boolean>;
|
|
127
|
+
interface ValidatePasswordComplexityParams {
|
|
128
|
+
devId: string;
|
|
129
|
+
password: string;
|
|
130
|
+
}
|
|
131
|
+
export declare const validatePasswordComplexity: (params: ValidatePasswordComplexityParams) => Promise<boolean>;
|
|
127
132
|
export {};
|
package/lib/api/lock.js
CHANGED
|
@@ -116,3 +116,10 @@ export const bindUnlockMethodToUserByRecord = (params) => {
|
|
|
116
116
|
data: params,
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
|
+
export const validatePasswordComplexity = (params) => {
|
|
120
|
+
return requestApi({
|
|
121
|
+
api: "m.lock.password.simplicity.check",
|
|
122
|
+
version: "1.0",
|
|
123
|
+
data: params,
|
|
124
|
+
});
|
|
125
|
+
};
|
package/lib/api/user.d.ts
CHANGED
|
@@ -82,26 +82,12 @@ export declare const getUserList: (params: getUserListParams) => Promise<{
|
|
|
82
82
|
user: UserListItem[];
|
|
83
83
|
hasNext: boolean;
|
|
84
84
|
}>;
|
|
85
|
-
interface
|
|
85
|
+
interface GetUserDetailQueryParams {
|
|
86
86
|
devId: string;
|
|
87
87
|
userId: string;
|
|
88
|
+
dpIds: string;
|
|
88
89
|
}
|
|
89
|
-
|
|
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>;
|
|
90
|
+
export declare const getUserDetailQuery: (params: GetUserDetailQueryParams) => Promise<UserListItem>;
|
|
105
91
|
export interface RemovedUserData {
|
|
106
92
|
userId: string;
|
|
107
93
|
lockUserId: number;
|
package/lib/api/user.js
CHANGED
|
@@ -38,17 +38,17 @@ export const getUserList = (params) => {
|
|
|
38
38
|
data: params,
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
export const
|
|
41
|
+
export const getUserDetailQuery = (params) => {
|
|
42
42
|
return requestApi({
|
|
43
|
-
api:
|
|
44
|
-
version: "
|
|
43
|
+
api: "m.lock.user.detail.query",
|
|
44
|
+
version: "1.0",
|
|
45
45
|
data: params,
|
|
46
46
|
});
|
|
47
47
|
};
|
|
48
48
|
export const getUsersSyncLockData = (deviceId) => {
|
|
49
49
|
return requestApi({
|
|
50
50
|
api: `${THING}.m.device.lock.sync.batch`,
|
|
51
|
-
version: "
|
|
51
|
+
version: "1.0",
|
|
52
52
|
data: {
|
|
53
53
|
devId: deviceId,
|
|
54
54
|
},
|
|
@@ -57,7 +57,7 @@ export const getUsersSyncLockData = (deviceId) => {
|
|
|
57
57
|
export const removeUser = (devId, userId) => {
|
|
58
58
|
return requestApi({
|
|
59
59
|
api: `${THING}.m.device.member.remove`,
|
|
60
|
-
version: "
|
|
60
|
+
version: "1.0",
|
|
61
61
|
data: {
|
|
62
62
|
devId,
|
|
63
63
|
userId,
|
package/lib/capability.js
CHANGED
|
@@ -8,7 +8,7 @@ export const isActiveThread = async () => {
|
|
|
8
8
|
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
9
9
|
if (hasThread) {
|
|
10
10
|
const deviceStatus = getDeviceStatus();
|
|
11
|
-
if (deviceStatus.
|
|
11
|
+
if (deviceStatus.onlineTypes.includes("cloud") ||
|
|
12
12
|
config.communication.length === 1) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
@@ -45,6 +45,7 @@ export const getDeviceAdvancedAbilities = async () => {
|
|
|
45
45
|
"tyabi4ucx5",
|
|
46
46
|
"tyabis9tpe",
|
|
47
47
|
"tyabiwxrn9",
|
|
48
|
+
"tyabipd4hh",
|
|
48
49
|
]),
|
|
49
50
|
getDeviceAdvancedAbility(config.devInfo.devId),
|
|
50
51
|
]);
|
|
@@ -68,27 +69,52 @@ export const getDeviceAdvancedAbilities = async () => {
|
|
|
68
69
|
support: false,
|
|
69
70
|
config: {},
|
|
70
71
|
},
|
|
72
|
+
unlockGuide: {
|
|
73
|
+
support: false,
|
|
74
|
+
config: {},
|
|
75
|
+
},
|
|
71
76
|
};
|
|
72
77
|
productAbilities.forEach((item) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
78
|
+
try {
|
|
79
|
+
if (item.isOpen) {
|
|
80
|
+
const data = JSON.parse(item.extConfig);
|
|
81
|
+
switch (item.abilityCode) {
|
|
82
|
+
case "tyabi4ucx5": {
|
|
83
|
+
deviceAdvanceAbilityCache.ai.config = data;
|
|
84
|
+
const dataReport = data?.ai_data_report ?? false;
|
|
85
|
+
const itemRecognition = data?.ai_recognition?.[0]?.item_recognition ?? false;
|
|
86
|
+
const petRecognition = data?.ai_recognition?.[0]?.pet_recognition ?? false;
|
|
87
|
+
const voice = data?.ai_voice ?? false;
|
|
88
|
+
const message = data?.ai_message ?? false;
|
|
89
|
+
deviceAdvanceAbilityCache.ai.support =
|
|
90
|
+
dataReport ||
|
|
91
|
+
itemRecognition ||
|
|
92
|
+
petRecognition ||
|
|
93
|
+
voice ||
|
|
94
|
+
message;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
case "tyabis9tpe": {
|
|
98
|
+
deviceAdvanceAbilityCache.wechat.support = true;
|
|
99
|
+
deviceAdvanceAbilityCache.wechat.config = data;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case "tyabiwxrn9": {
|
|
103
|
+
deviceAdvanceAbilityCache.wechatVoip.support =
|
|
104
|
+
!!data?.voipType?.includes("0");
|
|
105
|
+
deviceAdvanceAbilityCache.wechatVoip.config = data;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case "tyabipd4hh": {
|
|
109
|
+
deviceAdvanceAbilityCache.unlockGuide.support = true;
|
|
110
|
+
deviceAdvanceAbilityCache.unlockGuide.config = data;
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
87
115
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
!!data?.voipType?.includes("0");
|
|
91
|
-
deviceAdvanceAbilityCache.wechatVoip.config = data;
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.warn(`setting [${item.abilityCode}] config error`, error);
|
|
92
118
|
}
|
|
93
119
|
});
|
|
94
120
|
return deviceAdvanceAbilityCache;
|
|
@@ -52,7 +52,7 @@ export const validConfigDpMap = {
|
|
|
52
52
|
.slice(0, 7);
|
|
53
53
|
},
|
|
54
54
|
format: (value) => {
|
|
55
|
-
const weekHex = parseInt(value.reverse().join(""), 2)
|
|
55
|
+
const weekHex = parseInt([...value].reverse().join(""), 2)
|
|
56
56
|
.toString(16)
|
|
57
57
|
.padStart(2, "0");
|
|
58
58
|
return `000000${weekHex}`;
|
|
@@ -161,7 +161,7 @@ declare const remove: readonly [{
|
|
|
161
161
|
}, {
|
|
162
162
|
readonly name: "unlockId";
|
|
163
163
|
}, {
|
|
164
|
-
readonly name: "
|
|
164
|
+
readonly name: "operation";
|
|
165
165
|
}];
|
|
166
166
|
declare const reportRemove: ({
|
|
167
167
|
readonly name: "type";
|
|
@@ -176,7 +176,7 @@ declare const reportRemove: ({
|
|
|
176
176
|
} | {
|
|
177
177
|
readonly name: "unlockId";
|
|
178
178
|
} | {
|
|
179
|
-
readonly name: "
|
|
179
|
+
readonly name: "operation";
|
|
180
180
|
} | {
|
|
181
181
|
name: string;
|
|
182
182
|
})[];
|
|
@@ -649,7 +649,7 @@ declare const _default: {
|
|
|
649
649
|
}, {
|
|
650
650
|
readonly name: "unlockId";
|
|
651
651
|
}, {
|
|
652
|
-
readonly name: "
|
|
652
|
+
readonly name: "operation";
|
|
653
653
|
}];
|
|
654
654
|
reportRemove: ({
|
|
655
655
|
readonly name: "type";
|
|
@@ -664,7 +664,7 @@ declare const _default: {
|
|
|
664
664
|
} | {
|
|
665
665
|
readonly name: "unlockId";
|
|
666
666
|
} | {
|
|
667
|
-
readonly name: "
|
|
667
|
+
readonly name: "operation";
|
|
668
668
|
} | {
|
|
669
669
|
name: string;
|
|
670
670
|
})[];
|
package/lib/config/index.d.ts
CHANGED
|
@@ -18,9 +18,10 @@ declare const config: {
|
|
|
18
18
|
videoAngle: number;
|
|
19
19
|
supportMultipleFace: boolean;
|
|
20
20
|
supportOfflineDps: boolean;
|
|
21
|
+
preFetch: boolean;
|
|
21
22
|
deviceStatus: DeviceStatus;
|
|
22
23
|
};
|
|
23
|
-
type UpdateConfigParams = Omit<LockSDKOption, "devInfo" | "deviceId">;
|
|
24
|
+
type UpdateConfigParams = Omit<LockSDKOption, "devInfo" | "deviceId" | "preFetch">;
|
|
24
25
|
export declare const updateConfig: (options: UpdateConfigParams) => void;
|
|
25
26
|
export declare const hasCapability: (capability: ProductCommunicationType) => boolean;
|
|
26
27
|
export declare const hasDp: (dpCode: string) => boolean;
|
package/lib/config/index.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { hasCapability, hasDp, updateConfig } from "./config";
|
|
|
2
2
|
import { LockSDKOption } from "./interface";
|
|
3
3
|
import { getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate } from "./state";
|
|
4
4
|
import { syncUnlockMethod } from "./sync/unlock-method";
|
|
5
|
+
import syncDeleteUsers from "./sync/user";
|
|
5
6
|
import { publishDps } from "./utils/publishDps";
|
|
6
7
|
import { publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache } from "./offline-dps";
|
|
7
8
|
export * from "./user";
|
|
@@ -19,4 +20,4 @@ export * from "./linkage";
|
|
|
19
20
|
export * from "./capability";
|
|
20
21
|
export declare const init: (options?: LockSDKOption) => Promise<void>;
|
|
21
22
|
export declare const destroy: () => void;
|
|
22
|
-
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
|
23
|
+
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, syncDeleteUsers, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
package/lib/index.js
CHANGED
|
@@ -2,8 +2,9 @@ import config, { hasCapability, hasDp, updateConfig } from "./config";
|
|
|
2
2
|
import dpCodes from "./config/dp-code";
|
|
3
3
|
import { addEvents, clearState, initState, removeEvents, getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate, } from "./state";
|
|
4
4
|
import { getCapabilities } from "./utils";
|
|
5
|
-
import { getDeviceInfo, getLaunchOptionsSync } from "./utils/device";
|
|
5
|
+
import { getDeviceInfo, getLaunchOptionsSync, trackEvent, } from "./utils/device";
|
|
6
6
|
import { syncUnlockMethod } from "./sync/unlock-method";
|
|
7
|
+
import syncDeleteUsers from "./sync/user";
|
|
7
8
|
import { publishDps } from "./utils/publishDps";
|
|
8
9
|
import { publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, } from "./offline-dps";
|
|
9
10
|
export * from "./user";
|
|
@@ -60,12 +61,16 @@ export const init = async (options) => {
|
|
|
60
61
|
config.codesById = codesById;
|
|
61
62
|
config.idsByCode = idsByCode;
|
|
62
63
|
config.supportBigData = !!dpSchema[dpCodes.synchMethodW];
|
|
64
|
+
config.preFetch = options?.preFetch ?? false;
|
|
63
65
|
config.communication = getCapabilities(devInfo.capability).map((item) => item.id);
|
|
64
66
|
addEvents();
|
|
67
|
+
trackEvent("t$y_UztB3Lj9Qns375R0r7dA0L5Kr2VytH3J".replace("$", ""), {
|
|
68
|
+
pid: devInfo.productId,
|
|
69
|
+
});
|
|
65
70
|
await initState();
|
|
66
71
|
};
|
|
67
72
|
export const destroy = () => {
|
|
68
73
|
clearState();
|
|
69
74
|
removeEvents();
|
|
70
75
|
};
|
|
71
|
-
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
|
76
|
+
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, syncDeleteUsers, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
package/lib/interface.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export interface LockSDKOption {
|
|
|
10
10
|
passwordSupportZero?: boolean;
|
|
11
11
|
supportMultipleFace?: boolean;
|
|
12
12
|
supportOfflineDps?: boolean;
|
|
13
|
+
preFetch?: boolean;
|
|
13
14
|
}
|
|
14
15
|
export interface ErrorData {
|
|
15
16
|
errorCode: number;
|
|
@@ -81,7 +82,7 @@ export interface CurrentUser {
|
|
|
81
82
|
permanent: boolean;
|
|
82
83
|
}
|
|
83
84
|
export interface UnlockMethodBaseInfo {
|
|
84
|
-
unlockId:
|
|
85
|
+
unlockId: number;
|
|
85
86
|
unlockName: string;
|
|
86
87
|
isBound: boolean;
|
|
87
88
|
id: number;
|
|
@@ -143,11 +144,13 @@ export type DpMapDataType<T extends DpMapType> = {
|
|
|
143
144
|
};
|
|
144
145
|
export interface NotifyInfo {
|
|
145
146
|
appSend?: boolean;
|
|
147
|
+
msgSend?: boolean;
|
|
146
148
|
msgPhone?: string;
|
|
147
149
|
countryCode?: string;
|
|
148
150
|
}
|
|
149
151
|
export interface UnlockMethodDetail {
|
|
150
152
|
isBound: boolean;
|
|
153
|
+
type: UnlockMethodType;
|
|
151
154
|
phase: number;
|
|
152
155
|
dpId: number;
|
|
153
156
|
isSpecial: boolean;
|
|
@@ -312,6 +315,10 @@ export interface DeviceAdvancedAbility {
|
|
|
312
315
|
support: boolean;
|
|
313
316
|
config: Record<string, any>;
|
|
314
317
|
};
|
|
318
|
+
unlockGuide: {
|
|
319
|
+
support: boolean;
|
|
320
|
+
config: Record<string, any>;
|
|
321
|
+
};
|
|
315
322
|
}
|
|
316
323
|
export interface OfflineDpInfo {
|
|
317
324
|
value: DpValue;
|
|
@@ -320,4 +327,9 @@ export interface OfflineDpInfo {
|
|
|
320
327
|
export interface OfflineDps {
|
|
321
328
|
[code: string]: OfflineDpInfo;
|
|
322
329
|
}
|
|
330
|
+
export interface UnlockGuide {
|
|
331
|
+
videoUrl: string;
|
|
332
|
+
picUrl: string;
|
|
333
|
+
expireTime: number;
|
|
334
|
+
}
|
|
323
335
|
export {};
|
package/lib/log.js
CHANGED
|
@@ -36,6 +36,12 @@ export const getLatestLogs = async () => {
|
|
|
36
36
|
catch {
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
let userName = item.userName;
|
|
40
|
+
let unlockName = item.unlockName;
|
|
41
|
+
if (item.dpId === 89 || item.dpId === 69) {
|
|
42
|
+
unlockName = item.userName;
|
|
43
|
+
userName = "";
|
|
44
|
+
}
|
|
39
45
|
return {
|
|
40
46
|
type,
|
|
41
47
|
logId: item.logId,
|
|
@@ -43,8 +49,8 @@ export const getLatestLogs = async () => {
|
|
|
43
49
|
dpCode,
|
|
44
50
|
data: itemData,
|
|
45
51
|
userId: item.userId,
|
|
46
|
-
userName
|
|
47
|
-
unlockName
|
|
52
|
+
userName,
|
|
53
|
+
unlockName,
|
|
48
54
|
mediaInfo: item.mediaInfoList,
|
|
49
55
|
unionUnlockInfo: item.unionUnlockInfo?.map((item1) => {
|
|
50
56
|
return {
|
|
@@ -142,6 +148,12 @@ export const getLogs = async (params) => {
|
|
|
142
148
|
if (dpCode === dpCodes.lockLocalRecord) {
|
|
143
149
|
type = "local_operation";
|
|
144
150
|
}
|
|
151
|
+
let userName = record.userName;
|
|
152
|
+
let unlockName = record.unlockName;
|
|
153
|
+
if (record.dpId === 89 || record.dpId === 69) {
|
|
154
|
+
unlockName = record.userName;
|
|
155
|
+
userName = "";
|
|
156
|
+
}
|
|
145
157
|
return {
|
|
146
158
|
type,
|
|
147
159
|
logId: record.historyId.toString(),
|
|
@@ -149,8 +161,8 @@ export const getLogs = async (params) => {
|
|
|
149
161
|
dpId: record.dpId,
|
|
150
162
|
data: dpValue,
|
|
151
163
|
dpCode,
|
|
152
|
-
userName
|
|
153
|
-
unlockName
|
|
164
|
+
userName,
|
|
165
|
+
unlockName,
|
|
154
166
|
mediaInfo: record.mediaInfoList,
|
|
155
167
|
unionUnlockInfo: record.unionUnlockInfo?.map((item) => ({
|
|
156
168
|
userId: item.userId,
|
package/lib/offline-dps.js
CHANGED
|
@@ -29,14 +29,14 @@ export const checkOfflineDpUpdate = async (dps, isForce) => {
|
|
|
29
29
|
if (!config.supportOfflineDps) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const hasOne = Object.keys(dps).some((code) => cache[code]?.pushStatus === false);
|
|
32
|
+
const hasOne = Object.keys(dps).some((code) => cache?.[code]?.pushStatus === false);
|
|
33
33
|
if (hasOne || isForce) {
|
|
34
34
|
const res = await getOfflineDps(true);
|
|
35
35
|
emitter.emit(OFFLINE_DPS_UPDATE, res);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
export const getOfflineDpCache = (code) => {
|
|
39
|
-
return cache[code];
|
|
39
|
+
return cache?.[code];
|
|
40
40
|
};
|
|
41
41
|
export const publishOfflineDps = async (dps) => {
|
|
42
42
|
const { devInfo, dpSchema } = config;
|
|
@@ -52,20 +52,12 @@ export const publishOfflineDps = async (dps) => {
|
|
|
52
52
|
return acc;
|
|
53
53
|
}, {});
|
|
54
54
|
await publishOfflineDpData(devInfo.devId, dpData);
|
|
55
|
-
|
|
56
|
-
await checkOfflineDpUpdate({}, true);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
}
|
|
55
|
+
checkOfflineDpUpdate({}, true);
|
|
60
56
|
};
|
|
61
57
|
export const clearOfflineDps = async () => {
|
|
62
58
|
const { devInfo } = config;
|
|
63
59
|
await clearOfflineDpData(devInfo.devId);
|
|
64
|
-
|
|
65
|
-
await checkOfflineDpUpdate({}, true);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
}
|
|
60
|
+
checkOfflineDpUpdate({}, true);
|
|
69
61
|
};
|
|
70
62
|
const OFFLINE_DPS_UPDATE = "offline_dps_update";
|
|
71
63
|
export const onOfflineDpsUpdate = (callback) => {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const isDedicatedBleHexSuccess: (raw: string) => boolean;
|
|
2
|
+
export declare const resolveDedicatedBleCommandDp: () => string | null;
|
|
3
|
+
export declare const executeDedicatedBleManualLock: (timeout: number) => Promise<void>;
|
|
4
|
+
export declare const executeDedicatedBleRawAction: (isOpen: boolean, timeout: number) => Promise<void>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
|
+
import { getDoorKey } from "../api/lock";
|
|
3
|
+
import config, { hasDp } from "../config";
|
|
4
|
+
import dpCodes from "../config/dp-code";
|
|
5
|
+
import { open as openMap, reportOpen as reportOpenMap, } from "../config/dp-map/open";
|
|
6
|
+
import syncRemoteSerectKey from "../sync/remote-serect-key";
|
|
7
|
+
import { stringToBytes } from "../utils/byte";
|
|
8
|
+
import { decrypt } from "../utils/device";
|
|
9
|
+
import { getError } from "../utils/errors";
|
|
10
|
+
import { publishDps } from "../utils/publishDps";
|
|
11
|
+
import { getOpenDoorMemberId } from "./ble-remote-no-dp-key";
|
|
12
|
+
import { mapRemoteOpenReportStatus } from "./report-status";
|
|
13
|
+
const normalizeHex = (raw) => raw.replace(/\s/g, "").toLowerCase();
|
|
14
|
+
export const isDedicatedBleHexSuccess = (raw) => {
|
|
15
|
+
const n = normalizeHex(raw);
|
|
16
|
+
if (n.length < 2) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return n.startsWith("00") || n.endsWith("00");
|
|
20
|
+
};
|
|
21
|
+
const parseDedicatedBleHexStatus = (raw) => {
|
|
22
|
+
const n = normalizeHex(raw);
|
|
23
|
+
if (n.length < 2) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (isDedicatedBleHexSuccess(raw)) {
|
|
27
|
+
return { status: 0 };
|
|
28
|
+
}
|
|
29
|
+
if (n.includes("06")) {
|
|
30
|
+
return { status: 0x06 };
|
|
31
|
+
}
|
|
32
|
+
return { status: 0x01 };
|
|
33
|
+
};
|
|
34
|
+
const tryParseStandardUnlockReport = (raw, memberId) => {
|
|
35
|
+
try {
|
|
36
|
+
const result = dpUtils.parse(raw, reportOpenMap);
|
|
37
|
+
if (result.memberId !== memberId) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const resolveDedicatedBleCommandDp = () => {
|
|
50
|
+
if (hasDp(dpCodes.bleUnlockCheck)) {
|
|
51
|
+
return dpCodes.bleUnlockCheck;
|
|
52
|
+
}
|
|
53
|
+
if (hasDp(dpCodes.bluetoothUnlock)) {
|
|
54
|
+
return dpCodes.bluetoothUnlock;
|
|
55
|
+
}
|
|
56
|
+
if (hasDp(dpCodes.unlockBle)) {
|
|
57
|
+
return dpCodes.unlockBle;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
const createDedicatedBleCheckReport = (commandDp, memberId) => {
|
|
62
|
+
return (dpData) => {
|
|
63
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
64
|
+
if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
|
|
65
|
+
return { status: 0 };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (typeof dpData[commandDp] !== "undefined") {
|
|
69
|
+
const raw = dpData[commandDp];
|
|
70
|
+
const standard = tryParseStandardUnlockReport(raw, memberId);
|
|
71
|
+
if (standard) {
|
|
72
|
+
return standard;
|
|
73
|
+
}
|
|
74
|
+
const hexStatus = parseDedicatedBleHexStatus(raw);
|
|
75
|
+
if (hexStatus !== false) {
|
|
76
|
+
return hexStatus;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
|
|
80
|
+
const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
|
|
81
|
+
if (result.memberId === memberId) {
|
|
82
|
+
if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export const executeDedicatedBleManualLock = async (timeout) => {
|
|
92
|
+
if (!hasDp(dpCodes.manualLock)) {
|
|
93
|
+
throw getError(1014);
|
|
94
|
+
}
|
|
95
|
+
await publishDps({
|
|
96
|
+
[dpCodes.manualLock]: true,
|
|
97
|
+
}, {
|
|
98
|
+
timeout,
|
|
99
|
+
checkReport: (dpData) => {
|
|
100
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
101
|
+
if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
|
|
102
|
+
return { status: 0 };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (typeof dpData[dpCodes.manualLock] !== "undefined") {
|
|
106
|
+
return { status: 0 };
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
export const executeDedicatedBleRawAction = async (isOpen, timeout) => {
|
|
113
|
+
if (!isOpen && hasDp(dpCodes.manualLock)) {
|
|
114
|
+
await executeDedicatedBleManualLock(timeout);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const commandDp = resolveDedicatedBleCommandDp();
|
|
118
|
+
if (!commandDp) {
|
|
119
|
+
throw getError(1014);
|
|
120
|
+
}
|
|
121
|
+
await syncRemoteSerectKey();
|
|
122
|
+
let pw = "";
|
|
123
|
+
try {
|
|
124
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
125
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
await syncRemoteSerectKey(true);
|
|
129
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
130
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
131
|
+
}
|
|
132
|
+
const memberId = await getOpenDoorMemberId();
|
|
133
|
+
const payload = dpUtils.format({
|
|
134
|
+
status: Number(isOpen),
|
|
135
|
+
memberId,
|
|
136
|
+
key: stringToBytes(pw),
|
|
137
|
+
type: 3,
|
|
138
|
+
}, openMap);
|
|
139
|
+
const response = (await publishDps({
|
|
140
|
+
[commandDp]: payload,
|
|
141
|
+
}, {
|
|
142
|
+
timeout,
|
|
143
|
+
checkReport: createDedicatedBleCheckReport(commandDp, memberId),
|
|
144
|
+
}));
|
|
145
|
+
if (response.status !== 0) {
|
|
146
|
+
throw mapRemoteOpenReportStatus(response.status);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DpValue } from "../interface";
|
|
2
|
+
export declare const createRemoteNoDpKeyBleCheckReport: (memberId: number) => (dpData: Record<string, DpValue>) => any;
|
|
3
|
+
export declare const executeBleRemoteNoDpKeyAction: (isOpen: boolean, timeout: number, memberId: number) => Promise<void>;
|
|
4
|
+
export declare const getOpenDoorMemberId: () => Promise<number>;
|