@ray-js/lock-sdk 1.1.1-beta.2 → 1.1.1-beta.3
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/capability.js +44 -18
- package/lib/config/index.d.ts +2 -1
- package/lib/config/index.js +1 -0
- package/lib/index.js +1 -0
- package/lib/interface.d.ts +10 -0
- package/lib/open.js +9 -9
- package/lib/state.js +17 -12
- package/lib/unlock-method.d.ts +2 -1
- package/lib/unlock-method.js +48 -1
- package/lib/utils/index.js +13 -11
- 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/capability.js
CHANGED
|
@@ -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;
|
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.js
CHANGED
|
@@ -60,6 +60,7 @@ export const init = async (options) => {
|
|
|
60
60
|
config.codesById = codesById;
|
|
61
61
|
config.idsByCode = idsByCode;
|
|
62
62
|
config.supportBigData = !!dpSchema[dpCodes.synchMethodW];
|
|
63
|
+
config.preFetch = options?.preFetch ?? false;
|
|
63
64
|
config.communication = getCapabilities(devInfo.capability).map((item) => item.id);
|
|
64
65
|
addEvents();
|
|
65
66
|
await initState();
|
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;
|
|
@@ -312,6 +313,10 @@ export interface DeviceAdvancedAbility {
|
|
|
312
313
|
support: boolean;
|
|
313
314
|
config: Record<string, any>;
|
|
314
315
|
};
|
|
316
|
+
unlockGuide: {
|
|
317
|
+
support: boolean;
|
|
318
|
+
config: Record<string, any>;
|
|
319
|
+
};
|
|
315
320
|
}
|
|
316
321
|
export interface OfflineDpInfo {
|
|
317
322
|
value: DpValue;
|
|
@@ -320,4 +325,9 @@ export interface OfflineDpInfo {
|
|
|
320
325
|
export interface OfflineDps {
|
|
321
326
|
[code: string]: OfflineDpInfo;
|
|
322
327
|
}
|
|
328
|
+
export interface UnlockGuide {
|
|
329
|
+
videoUrl: string;
|
|
330
|
+
picUrl: string;
|
|
331
|
+
expireTime: number;
|
|
332
|
+
}
|
|
323
333
|
export {};
|
package/lib/open.js
CHANGED
|
@@ -42,18 +42,18 @@ export const checkRemoteEnabled = parallelMerge(async () => {
|
|
|
42
42
|
if (deviceStatus.type !== "online") {
|
|
43
43
|
throw getError(1001);
|
|
44
44
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const isLocalOnline = deviceStatus.onlineTypes.length === 1 &&
|
|
46
|
+
deviceStatus.onlineTypes.includes("local");
|
|
47
|
+
const isThreadLocalOnline = hasThread && isLocalOnline;
|
|
48
|
+
if (isThreadLocalOnline || deviceStatus.onlineTypes.includes("ble")) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (isLocalOnline) {
|
|
52
|
+
throw getError(1064);
|
|
49
53
|
}
|
|
50
54
|
if (dpSchema[dpCodes.remoteNoDpKey] === undefined) {
|
|
51
55
|
throw getError(1045);
|
|
52
56
|
}
|
|
53
|
-
if ((hasThread && deviceStatus.onlineType === "local") ||
|
|
54
|
-
deviceStatus.onlineType === "ble") {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
57
|
if (!remoteOpenEnabled) {
|
|
58
58
|
throw getError(1046);
|
|
59
59
|
}
|
|
@@ -65,7 +65,7 @@ export const checkRemoteEnabled = parallelMerge(async () => {
|
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
const _doAction = async (isOpen, timeout) => {
|
|
68
|
-
const { devInfo,
|
|
68
|
+
const { devInfo, communication } = config;
|
|
69
69
|
await checkRemoteEnabled();
|
|
70
70
|
const deviceStatus = getDeviceStatus();
|
|
71
71
|
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
package/lib/state.js
CHANGED
|
@@ -38,7 +38,7 @@ const updateOnlineType = async () => {
|
|
|
38
38
|
updateDeviceStatus();
|
|
39
39
|
};
|
|
40
40
|
export const getDeviceStatus = () => {
|
|
41
|
-
const { onlineType,
|
|
41
|
+
const { onlineType, devInfo: { isCloudOnline, isOnline, wifiEnableState }, } = config;
|
|
42
42
|
const status = {
|
|
43
43
|
type: isOnline ? "online" : "offline",
|
|
44
44
|
connectEnable: false,
|
|
@@ -46,7 +46,7 @@ export const getDeviceStatus = () => {
|
|
|
46
46
|
onlineTypes: [],
|
|
47
47
|
isWifiActive: wifiEnableState !== 1,
|
|
48
48
|
};
|
|
49
|
-
const isBleOnline =
|
|
49
|
+
const isBleOnline = isOnlineByType(onlineType, 2);
|
|
50
50
|
const isLocalOnline = !isCloudOnline && isOnlineByType(onlineType, 1);
|
|
51
51
|
const supportWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
52
52
|
const supportBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
@@ -199,24 +199,29 @@ export const permissions = [
|
|
|
199
199
|
"everyOne",
|
|
200
200
|
"noOne",
|
|
201
201
|
];
|
|
202
|
+
var DeviceProperties;
|
|
203
|
+
(function (DeviceProperties) {
|
|
204
|
+
DeviceProperties["REMOTE_UNLOCK_AUTH"] = "REMOTE_UNLOCK_AUTH";
|
|
205
|
+
DeviceProperties["UNLOCK_PHONE_REMOTE"] = "UNLOCK_PHONE_REMOTE";
|
|
206
|
+
})(DeviceProperties || (DeviceProperties = {}));
|
|
207
|
+
const propsList = [
|
|
208
|
+
DeviceProperties.REMOTE_UNLOCK_AUTH,
|
|
209
|
+
DeviceProperties.UNLOCK_PHONE_REMOTE,
|
|
210
|
+
];
|
|
202
211
|
const fetchDeviceProperties = async (isForce) => {
|
|
203
212
|
let result = null;
|
|
204
213
|
if (isForce) {
|
|
205
|
-
result = await getDeviceProperties(config.devInfo.devId,
|
|
206
|
-
"REMOTE_UNLOCK_AUTH",
|
|
207
|
-
"UNLOCK_PHONE_REMOTE",
|
|
208
|
-
]);
|
|
214
|
+
result = await getDeviceProperties(config.devInfo.devId, propsList);
|
|
209
215
|
}
|
|
210
216
|
else {
|
|
211
217
|
result = await getDataWithPreFetch("getDeviceProperties", () => {
|
|
212
|
-
return getDeviceProperties(config.devInfo.devId,
|
|
213
|
-
"REMOTE_UNLOCK_AUTH",
|
|
214
|
-
"UNLOCK_PHONE_REMOTE",
|
|
215
|
-
]);
|
|
218
|
+
return getDeviceProperties(config.devInfo.devId, propsList);
|
|
216
219
|
});
|
|
217
220
|
}
|
|
218
|
-
config.remoteOpenEnabled =
|
|
219
|
-
|
|
221
|
+
config.remoteOpenEnabled =
|
|
222
|
+
result[DeviceProperties.UNLOCK_PHONE_REMOTE] === "true";
|
|
223
|
+
config.remoteOpenPermission =
|
|
224
|
+
permissions[+result[DeviceProperties.REMOTE_UNLOCK_AUTH] || 0];
|
|
220
225
|
};
|
|
221
226
|
export const initState = async () => {
|
|
222
227
|
const { devInfo: { dps, devId }, dpSchema, } = config;
|
package/lib/unlock-method.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ErrorData, UnBindUnlockMethodGroup, UnlockMethodDetail, UnlockMethodType } from "./interface";
|
|
1
|
+
import { ErrorData, UnBindUnlockMethodGroup, UnlockGuide, UnlockMethodDetail, UnlockMethodType } from "./interface";
|
|
2
2
|
export interface SpecialUnlockMethodInfo {
|
|
3
3
|
appSend?: boolean;
|
|
4
4
|
msgPhone?: string;
|
|
@@ -85,4 +85,5 @@ export type AddUnlockMethodEvent = StepEvent | SuccessEvent | ErrorEvent;
|
|
|
85
85
|
export type AddUnlockMethodListener = (event: AddUnlockMethodEvent) => void;
|
|
86
86
|
export declare const onAddUnlockMethod: (listener: AddUnlockMethodListener) => void;
|
|
87
87
|
export declare const offAddUnlockMethod: (listener: AddUnlockMethodListener) => void;
|
|
88
|
+
export declare const getUnlockGuide: (type: UnlockMethodType) => Promise<UnlockGuide | null>;
|
|
88
89
|
export {};
|
package/lib/unlock-method.js
CHANGED
|
@@ -12,8 +12,9 @@ import { publishDps } from "./utils/publishDps";
|
|
|
12
12
|
import { encrypt } from "./utils/device";
|
|
13
13
|
import emitter from "./utils/event";
|
|
14
14
|
import { DPCHANGE, UNLOCK_METHOD_EVENT } from "./utils/constant";
|
|
15
|
-
import { sendPhoneVerifyCode } from "./api";
|
|
15
|
+
import { getFileRemoteUrl, sendPhoneVerifyCode } from "./api";
|
|
16
16
|
import { getUserInfo } from "./user";
|
|
17
|
+
import { getDeviceAdvancedAbilities } from "./capability";
|
|
17
18
|
const getAddUnlockError = (status) => {
|
|
18
19
|
if (status >= 0 && status <= 10) {
|
|
19
20
|
return getError(1015 + status);
|
|
@@ -560,3 +561,49 @@ export const onAddUnlockMethod = (listener) => {
|
|
|
560
561
|
export const offAddUnlockMethod = (listener) => {
|
|
561
562
|
emitter.off(UNLOCK_METHOD_EVENT, listener);
|
|
562
563
|
};
|
|
564
|
+
const guileTypeMap = {
|
|
565
|
+
card: ["addCard", "addCardPic"],
|
|
566
|
+
finger: ["addFingerprint", "addFingerprintPic"],
|
|
567
|
+
face: ["addFace", "addFacePic"],
|
|
568
|
+
fingerVein: ["addFingervein", "addFingerveinPic"],
|
|
569
|
+
hand: ["addPalmvein", "addPalmveinPic"],
|
|
570
|
+
eye: ["addIris", "addIrisPic"],
|
|
571
|
+
};
|
|
572
|
+
export const getUnlockGuide = async (type) => {
|
|
573
|
+
if (type === "password") {
|
|
574
|
+
return null;
|
|
575
|
+
}
|
|
576
|
+
const { unlockGuide } = await getDeviceAdvancedAbilities();
|
|
577
|
+
if (unlockGuide.support) {
|
|
578
|
+
const [videoKey, picKey] = guileTypeMap[type] || ["", ""];
|
|
579
|
+
const resources = [];
|
|
580
|
+
let videoUrlPath = "";
|
|
581
|
+
let picUrlPath = "";
|
|
582
|
+
if (unlockGuide.config[picKey]) {
|
|
583
|
+
picUrlPath = unlockGuide.config[picKey].url;
|
|
584
|
+
resources.push({
|
|
585
|
+
objectKey: picUrlPath,
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
if (unlockGuide.config[videoKey]) {
|
|
589
|
+
videoUrlPath = unlockGuide.config[videoKey].url;
|
|
590
|
+
resources.push({
|
|
591
|
+
objectKey: videoUrlPath,
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
if (resources.length === 0) {
|
|
595
|
+
return null;
|
|
596
|
+
}
|
|
597
|
+
const { signedUrls } = await getFileRemoteUrl({
|
|
598
|
+
biz: "hulk_video_tutorial_video",
|
|
599
|
+
resources,
|
|
600
|
+
});
|
|
601
|
+
const expireTime = Date.now() + 30 * 60 * 1000;
|
|
602
|
+
return {
|
|
603
|
+
videoUrl: signedUrls[videoUrlPath],
|
|
604
|
+
picUrl: signedUrls[picUrlPath],
|
|
605
|
+
expireTime,
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
return null;
|
|
609
|
+
};
|
package/lib/utils/index.js
CHANGED
|
@@ -258,18 +258,20 @@ onBackgroundFetchData(preFetchKeys, (res) => {
|
|
|
258
258
|
});
|
|
259
259
|
});
|
|
260
260
|
export const getDataWithPreFetch = async (key, apiCb) => {
|
|
261
|
-
if (
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
result
|
|
268
|
-
|
|
269
|
-
|
|
261
|
+
if (config.preFetch) {
|
|
262
|
+
if (preFetchData[key]) {
|
|
263
|
+
return preFetchData[key];
|
|
264
|
+
}
|
|
265
|
+
try {
|
|
266
|
+
const result = await getBackgroundFetchData([key]);
|
|
267
|
+
if (result &&
|
|
268
|
+
result.fetchedData[key] &&
|
|
269
|
+
result.fetchedData[key].fetchedData) {
|
|
270
|
+
return result.fetchedData[key].fetchedData;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
270
274
|
}
|
|
271
|
-
}
|
|
272
|
-
catch {
|
|
273
275
|
}
|
|
274
276
|
return apiCb();
|
|
275
277
|
};
|