@ray-js/lock-sdk 1.0.0-beta-1
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 +5 -0
- package/lib/api/index.js +18 -0
- package/lib/api/linkage.d.ts +161 -0
- package/lib/api/linkage.js +74 -0
- package/lib/api/lock.d.ts +195 -0
- package/lib/api/lock.js +129 -0
- package/lib/api/log.d.ts +166 -0
- package/lib/api/log.js +44 -0
- package/lib/api/setting.d.ts +14 -0
- package/lib/api/setting.js +36 -0
- package/lib/api/temp.d.ts +211 -0
- package/lib/api/temp.js +130 -0
- package/lib/api/user.d.ts +154 -0
- package/lib/api/user.js +59 -0
- package/lib/api/video.d.ts +9 -0
- package/lib/api/video.js +17 -0
- package/lib/config/dp-code/index.d.ts +175 -0
- package/lib/config/dp-code/index.js +224 -0
- package/lib/config/dp-map/common.d.ts +102 -0
- package/lib/config/dp-map/common.js +120 -0
- package/lib/config/dp-map/normal.d.ts +6 -0
- package/lib/config/dp-map/normal.js +51 -0
- package/lib/config/dp-map/open.d.ts +21 -0
- package/lib/config/dp-map/open.js +62 -0
- package/lib/config/dp-map/unlock-method-big.d.ts +559 -0
- package/lib/config/dp-map/unlock-method-big.js +237 -0
- package/lib/config/dp-map/unlock-method.d.ts +551 -0
- package/lib/config/dp-map/unlock-method.js +231 -0
- package/lib/config/index.d.ts +46 -0
- package/lib/config/index.js +56 -0
- package/lib/constant.d.ts +101 -0
- package/lib/constant.js +136 -0
- package/lib/dp-interface.d.ts +7 -0
- package/lib/dp-interface.js +1 -0
- package/lib/event.d.ts +8 -0
- package/lib/event.js +9 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +92 -0
- package/lib/interface.d.ts +807 -0
- package/lib/interface.js +1 -0
- package/lib/linkage.d.ts +26 -0
- package/lib/linkage.js +175 -0
- package/lib/log.d.ts +91 -0
- package/lib/log.js +314 -0
- package/lib/media.d.ts +43 -0
- package/lib/media.js +80 -0
- package/lib/open.d.ts +48 -0
- package/lib/open.js +247 -0
- package/lib/other.d.ts +36 -0
- package/lib/other.js +178 -0
- package/lib/parse/index.d.ts +6 -0
- package/lib/parse/index.js +22 -0
- package/lib/signal.d.ts +26 -0
- package/lib/signal.js +38 -0
- package/lib/sleep.d.ts +61 -0
- package/lib/sleep.js +121 -0
- package/lib/state.d.ts +54 -0
- package/lib/state.js +429 -0
- package/lib/sync/remote-serect-key.d.ts +5 -0
- package/lib/sync/remote-serect-key.js +60 -0
- package/lib/sync/t0.d.ts +5 -0
- package/lib/sync/t0.js +33 -0
- package/lib/sync/temp.d.ts +7 -0
- package/lib/sync/temp.js +88 -0
- package/lib/sync/unlock-mothod.d.ts +5 -0
- package/lib/sync/unlock-mothod.js +54 -0
- package/lib/temporary.d.ts +226 -0
- package/lib/temporary.js +637 -0
- package/lib/unlock-method.d.ts +269 -0
- package/lib/unlock-method.js +723 -0
- package/lib/user.d.ts +108 -0
- package/lib/user.js +361 -0
- package/lib/utils/base64-to-hex.d.ts +1 -0
- package/lib/utils/base64-to-hex.js +12 -0
- package/lib/utils/byte.d.ts +19 -0
- package/lib/utils/byte.js +74 -0
- package/lib/utils/constant.d.ts +11 -0
- package/lib/utils/constant.js +17 -0
- package/lib/utils/device.d.ts +207 -0
- package/lib/utils/device.js +353 -0
- package/lib/utils/errors.d.ts +2 -0
- package/lib/utils/errors.js +125 -0
- package/lib/utils/event.d.ts +23 -0
- package/lib/utils/event.js +144 -0
- package/lib/utils/hex-to-base64.d.ts +1 -0
- package/lib/utils/hex-to-base64.js +8 -0
- package/lib/utils/hex-to-bytes.d.ts +6 -0
- package/lib/utils/hex-to-bytes.js +16 -0
- package/lib/utils/index.d.ts +169 -0
- package/lib/utils/index.js +419 -0
- package/lib/utils/log.d.ts +5 -0
- package/lib/utils/log.js +78 -0
- package/lib/utils/publishDps.d.ts +11 -0
- package/lib/utils/publishDps.js +91 -0
- package/package.json +37 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.some.js";
|
|
4
|
+
function createEmitter() {
|
|
5
|
+
let listeners = {};
|
|
6
|
+
let cachedEvents = {};
|
|
7
|
+
function addEvent(type, cb, emitType) {
|
|
8
|
+
if (!listeners[type]) {
|
|
9
|
+
listeners[type] = [];
|
|
10
|
+
}
|
|
11
|
+
// 确认一个事件只注册一次
|
|
12
|
+
const index = listeners[type].findIndex(item => item.cb === cb);
|
|
13
|
+
if (index === -1) {
|
|
14
|
+
listeners[type].push({
|
|
15
|
+
type: emitType,
|
|
16
|
+
cb
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
// 执行类型是否变更
|
|
20
|
+
if (listeners[type][index].type !== emitType) {
|
|
21
|
+
listeners[type][index].type = emitType;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 注册事件监听
|
|
28
|
+
* @param type
|
|
29
|
+
* @param cb
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 注册事件监听
|
|
34
|
+
* 事件只会执行一次
|
|
35
|
+
* @param type
|
|
36
|
+
* @param cb
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 是否有事件监听
|
|
41
|
+
* @param type
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
function hasListener(type) {
|
|
45
|
+
return !!listeners[type] && listeners[type].length > 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 缓存事件,当有监听器时直接执行
|
|
50
|
+
* 事件会被缓存,直到有监听器时才会执行
|
|
51
|
+
* @param type
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 清除缓存事件
|
|
56
|
+
* @param type
|
|
57
|
+
*/
|
|
58
|
+
function clearCache(type) {
|
|
59
|
+
cachedEvents[type] = [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 移除事件监听
|
|
64
|
+
* @param type
|
|
65
|
+
* @param cb
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
function off(type, cb) {
|
|
69
|
+
if (!listeners[type]) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
listeners[type].some((item, i) => {
|
|
73
|
+
if (item.cb === cb) {
|
|
74
|
+
listeners[type].splice(i, 1);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 执行事件
|
|
83
|
+
* @param type
|
|
84
|
+
* @param data
|
|
85
|
+
*/
|
|
86
|
+
function emit(type, data) {
|
|
87
|
+
if (listeners[type]) {
|
|
88
|
+
// 取得事件列表的副本进行操作,以保证所有事件被执行
|
|
89
|
+
const list = [...listeners[type]];
|
|
90
|
+
const count = list.length;
|
|
91
|
+
for (let i = 0; i < count; i++) {
|
|
92
|
+
const {
|
|
93
|
+
cb,
|
|
94
|
+
type: cbType
|
|
95
|
+
} = list[i];
|
|
96
|
+
if (cbType === "once") {
|
|
97
|
+
listeners[type].splice(i, 1);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
cb(data);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
// 监听事件执行不影响同步任务
|
|
103
|
+
console.warn(e);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 清除事件监听
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
on: function on(type, cb) {
|
|
115
|
+
addEvent(type, cb, "on");
|
|
116
|
+
|
|
117
|
+
// 是否有缓存事件数据
|
|
118
|
+
if (cachedEvents[type] && cachedEvents[type].length > 0) {
|
|
119
|
+
// 执行缓存事件
|
|
120
|
+
cachedEvents[type].forEach(data => {
|
|
121
|
+
emit(type, data);
|
|
122
|
+
});
|
|
123
|
+
// 清除缓存事件
|
|
124
|
+
clearCache(type);
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
off,
|
|
128
|
+
once: function once(type, cb) {
|
|
129
|
+
addEvent(type, cb, "once");
|
|
130
|
+
},
|
|
131
|
+
emit,
|
|
132
|
+
clear: () => {
|
|
133
|
+
listeners = {};
|
|
134
|
+
},
|
|
135
|
+
hasListener,
|
|
136
|
+
cache: function cache(type, data) {
|
|
137
|
+
cachedEvents[type] = cachedEvents[type] || [];
|
|
138
|
+
cachedEvents[type].push(data);
|
|
139
|
+
},
|
|
140
|
+
clearCache
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export { createEmitter };
|
|
144
|
+
export default createEmitter();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function hexToBase64(value: string): string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 将 hex 字符串转为字节数据
|
|
3
|
+
* @param value
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export default function hexToBytes(value) {
|
|
7
|
+
if (value.length % 2 !== 0) {
|
|
8
|
+
throw new Error('hex length error');
|
|
9
|
+
}
|
|
10
|
+
const len = value.length / 2;
|
|
11
|
+
const data = new Uint8Array(len);
|
|
12
|
+
for (let i = 0; i < len; i++) {
|
|
13
|
+
data[i] = parseInt(value.slice(i * 2, i * 2 + 2), 16);
|
|
14
|
+
}
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { UserType } from "../constant";
|
|
2
|
+
import { EffectiveConfig, UnlockMethodConfig, Week } from "../interface";
|
|
3
|
+
import { LoopTypes } from "./constant";
|
|
4
|
+
/**
|
|
5
|
+
* 格式化为24时间格式
|
|
6
|
+
* @param time
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const get24Time: (time: number) => number[];
|
|
10
|
+
export declare const getNowTime: () => number;
|
|
11
|
+
/**
|
|
12
|
+
* 判断设备在线类型
|
|
13
|
+
* @param onlineType 设备的通道在线数据
|
|
14
|
+
* @param type 待检测的通道类型,0为wifi,1为局域网,2为蓝牙,3为Mesh, 4为 beacon
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare const isOnlineByType: (onlineType: number, type: number) => boolean;
|
|
18
|
+
export declare function isCapability(capability: number, id: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* 获取产品支持的通讯能力
|
|
21
|
+
* @param capability 产品能力值
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare function getCapabilities(capability: number): ({
|
|
25
|
+
readonly id: 0;
|
|
26
|
+
readonly name: "wifi";
|
|
27
|
+
readonly short: "wf";
|
|
28
|
+
} | {
|
|
29
|
+
readonly id: 1;
|
|
30
|
+
readonly name: "cable";
|
|
31
|
+
readonly short: "ca";
|
|
32
|
+
} | {
|
|
33
|
+
readonly id: 2;
|
|
34
|
+
readonly name: "gprs";
|
|
35
|
+
readonly short: "gp";
|
|
36
|
+
} | {
|
|
37
|
+
readonly id: 3;
|
|
38
|
+
readonly name: "nb-iot";
|
|
39
|
+
readonly short: "nb";
|
|
40
|
+
} | {
|
|
41
|
+
readonly id: 10;
|
|
42
|
+
readonly name: "bluetooth";
|
|
43
|
+
readonly short: "ble";
|
|
44
|
+
} | {
|
|
45
|
+
readonly id: 11;
|
|
46
|
+
readonly name: "blemesh";
|
|
47
|
+
readonly short: "bm";
|
|
48
|
+
} | {
|
|
49
|
+
readonly id: 12;
|
|
50
|
+
readonly name: "zigbee";
|
|
51
|
+
readonly short: "zig";
|
|
52
|
+
} | {
|
|
53
|
+
readonly id: 13;
|
|
54
|
+
readonly name: "infrared";
|
|
55
|
+
readonly short: "inf";
|
|
56
|
+
} | {
|
|
57
|
+
readonly id: 14;
|
|
58
|
+
readonly name: "subpieces";
|
|
59
|
+
readonly short: "sub";
|
|
60
|
+
} | {
|
|
61
|
+
readonly id: 15;
|
|
62
|
+
readonly name: "sigmesh";
|
|
63
|
+
readonly short: "sig";
|
|
64
|
+
} | {
|
|
65
|
+
readonly id: 16;
|
|
66
|
+
readonly name: "mcu";
|
|
67
|
+
readonly short: "mcu";
|
|
68
|
+
} | {
|
|
69
|
+
readonly id: 17;
|
|
70
|
+
readonly name: "ty_smesh";
|
|
71
|
+
readonly short: "TY_SMESH";
|
|
72
|
+
} | {
|
|
73
|
+
readonly id: 18;
|
|
74
|
+
readonly name: "Zwave";
|
|
75
|
+
readonly short: "Zwave";
|
|
76
|
+
} | {
|
|
77
|
+
readonly id: 19;
|
|
78
|
+
readonly name: "pl-mesh";
|
|
79
|
+
readonly short: "pl-mesh";
|
|
80
|
+
} | {
|
|
81
|
+
readonly id: 20;
|
|
82
|
+
readonly name: "cat1";
|
|
83
|
+
readonly short: "cat1";
|
|
84
|
+
} | {
|
|
85
|
+
readonly id: 21;
|
|
86
|
+
readonly name: "beacon";
|
|
87
|
+
readonly short: "beacon";
|
|
88
|
+
} | {
|
|
89
|
+
readonly id: 22;
|
|
90
|
+
readonly name: "cat4";
|
|
91
|
+
readonly short: "cat4";
|
|
92
|
+
} | {
|
|
93
|
+
readonly id: 23;
|
|
94
|
+
readonly name: "cat10";
|
|
95
|
+
readonly short: "cat10";
|
|
96
|
+
} | {
|
|
97
|
+
readonly id: 24;
|
|
98
|
+
readonly name: "lte-catm";
|
|
99
|
+
readonly short: "catm";
|
|
100
|
+
} | {
|
|
101
|
+
readonly id: 25;
|
|
102
|
+
readonly name: "thread";
|
|
103
|
+
readonly short: "thread";
|
|
104
|
+
})[];
|
|
105
|
+
export declare const formatWeek: (value: number[]) => number;
|
|
106
|
+
export declare const parseWeek: (value: number) => Week;
|
|
107
|
+
/**
|
|
108
|
+
* 获取一个永久生效的设置
|
|
109
|
+
* @returns
|
|
110
|
+
*/
|
|
111
|
+
export declare const getPermanentSetting: () => {
|
|
112
|
+
startTime: number;
|
|
113
|
+
endTime: number;
|
|
114
|
+
loop: LoopTypes;
|
|
115
|
+
loopConfig: number;
|
|
116
|
+
weeks: number[];
|
|
117
|
+
days: never[];
|
|
118
|
+
startHour: number;
|
|
119
|
+
startMinute: number;
|
|
120
|
+
endHour: number;
|
|
121
|
+
endMinute: number;
|
|
122
|
+
};
|
|
123
|
+
export declare const isAdmin: (userType: UserType) => boolean;
|
|
124
|
+
export declare const validateEffectiveConfig: (effective?: EffectiveConfig) => void;
|
|
125
|
+
/**
|
|
126
|
+
* 是否使用近场通道,一般为蓝牙
|
|
127
|
+
* @returns
|
|
128
|
+
*/
|
|
129
|
+
export declare const isUseNearChannel: () => boolean;
|
|
130
|
+
export declare const parseOfflinePassword: (value: string) => string;
|
|
131
|
+
/**
|
|
132
|
+
* 格式化时间戳为毫秒
|
|
133
|
+
* 注意此方法只支持 2010 年之后的时间戳
|
|
134
|
+
* @param timestamp 时间戳
|
|
135
|
+
*/
|
|
136
|
+
export declare const formatTimestampToMilliseconds: (timestamp: number) => number;
|
|
137
|
+
/**
|
|
138
|
+
* 开锁方式配置数据
|
|
139
|
+
*/
|
|
140
|
+
export declare const unlockMethodConfigs: UnlockMethodConfig[];
|
|
141
|
+
export declare const getUnlockMethodTypeByDpCode: (dpCode: string) => UnlockMethodConfig;
|
|
142
|
+
export declare const getUnlockMethodTypeById: (id: number) => UnlockMethodConfig;
|
|
143
|
+
export declare const getUnlockMethodTypeByType: (type: string) => UnlockMethodConfig;
|
|
144
|
+
/**
|
|
145
|
+
* 针对异常函数,当函数在短时间内被多次调用时,只保留最先一次调用,并统一返回结果
|
|
146
|
+
* @param cb 回调函数
|
|
147
|
+
* @returns
|
|
148
|
+
*/
|
|
149
|
+
export declare const parallelMerge: <T extends (...args: any[]) => Promise<any>>(cb: T) => (...args: Parameters<T>) => ReturnType<T>;
|
|
150
|
+
/**
|
|
151
|
+
* 针对异常函数,当函数在短时间内被多次调用时,只允许函数在短时间内执行一次
|
|
152
|
+
* @param cb 回调函数
|
|
153
|
+
* @returns
|
|
154
|
+
*/
|
|
155
|
+
export declare const parallelOnly: <T extends (...args: any[]) => Promise<any>>(cb: T) => (...args: Parameters<T>) => ReturnType<T>;
|
|
156
|
+
declare const preFetchKeys: readonly ["getRotate", "getCurrentUser", "getDeviceProperties"];
|
|
157
|
+
type PreFetchKey = (typeof preFetchKeys)[number];
|
|
158
|
+
export declare const getDataWithPreFetch: <T>(key: PreFetchKey, apiCb: () => Promise<T>) => Promise<T>;
|
|
159
|
+
export declare const equels: (source: any, target: any) => boolean;
|
|
160
|
+
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
161
|
+
export declare const getHomeInfo: () => Promise<{
|
|
162
|
+
homeName: string;
|
|
163
|
+
homeId: string;
|
|
164
|
+
longitude: string;
|
|
165
|
+
latitude: string;
|
|
166
|
+
address: string;
|
|
167
|
+
admin: boolean;
|
|
168
|
+
}>;
|
|
169
|
+
export {};
|