@ray-js/lock-sdk 1.0.1 → 1.0.2

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 (86) hide show
  1. package/lib/api/index.js +13 -15
  2. package/lib/api/linkage.d.ts +0 -18
  3. package/lib/api/linkage.js +61 -81
  4. package/lib/api/lock.d.ts +0 -69
  5. package/lib/api/lock.js +91 -113
  6. package/lib/api/log.d.ts +0 -33
  7. package/lib/api/log.js +33 -38
  8. package/lib/api/setting.d.ts +0 -11
  9. package/lib/api/setting.js +17 -30
  10. package/lib/api/temp.d.ts +0 -48
  11. package/lib/api/temp.js +85 -115
  12. package/lib/api/user.d.ts +5 -54
  13. package/lib/api/user.js +40 -52
  14. package/lib/api/video.d.ts +0 -5
  15. package/lib/api/video.js +9 -15
  16. package/lib/config/dp-code/index.d.ts +0 -117
  17. package/lib/config/dp-code/index.js +79 -221
  18. package/lib/config/dp-map/common.d.ts +0 -3
  19. package/lib/config/dp-map/common.js +101 -116
  20. package/lib/config/dp-map/normal.js +29 -50
  21. package/lib/config/dp-map/open.d.ts +0 -16
  22. package/lib/config/dp-map/open.js +62 -63
  23. package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
  24. package/lib/config/dp-map/unlock-method-big.js +196 -233
  25. package/lib/config/dp-map/unlock-method.d.ts +0 -63
  26. package/lib/config/dp-map/unlock-method.js +189 -227
  27. package/lib/config/index.d.ts +0 -25
  28. package/lib/config/index.js +21 -54
  29. package/lib/constant.d.ts +12 -40
  30. package/lib/constant.js +83 -136
  31. package/lib/event.d.ts +0 -6
  32. package/lib/event.js +1 -8
  33. package/lib/index.d.ts +0 -7
  34. package/lib/index.js +45 -71
  35. package/lib/interface.d.ts +0 -523
  36. package/lib/interface.js +1 -1
  37. package/lib/linkage.d.ts +0 -18
  38. package/lib/linkage.js +125 -162
  39. package/lib/log.d.ts +0 -50
  40. package/lib/log.js +255 -290
  41. package/lib/media.d.ts +0 -34
  42. package/lib/media.js +6 -77
  43. package/lib/open.d.ts +0 -35
  44. package/lib/open.js +129 -224
  45. package/lib/other.d.ts +0 -24
  46. package/lib/other.js +98 -159
  47. package/lib/parse/index.d.ts +0 -4
  48. package/lib/parse/index.js +13 -19
  49. package/lib/signal.d.ts +0 -13
  50. package/lib/signal.js +17 -31
  51. package/lib/sleep.d.ts +0 -42
  52. package/lib/sleep.js +41 -98
  53. package/lib/state.d.ts +0 -38
  54. package/lib/state.js +223 -369
  55. package/lib/sync/remote-serect-key.d.ts +0 -4
  56. package/lib/sync/remote-serect-key.js +33 -49
  57. package/lib/sync/t0.d.ts +0 -3
  58. package/lib/sync/t0.js +14 -21
  59. package/lib/sync/temp.d.ts +0 -5
  60. package/lib/sync/temp.js +68 -77
  61. package/lib/sync/unlock-mothod.d.ts +0 -3
  62. package/lib/sync/unlock-mothod.js +28 -40
  63. package/lib/temporary.d.ts +0 -149
  64. package/lib/temporary.js +469 -593
  65. package/lib/unlock-method.d.ts +0 -185
  66. package/lib/unlock-method.js +479 -650
  67. package/lib/user.d.ts +2 -81
  68. package/lib/user.js +202 -336
  69. package/lib/utils/base64-to-hex.js +10 -10
  70. package/lib/utils/byte.d.ts +0 -16
  71. package/lib/utils/byte.js +57 -68
  72. package/lib/utils/constant.js +7 -11
  73. package/lib/utils/device.d.ts +46 -83
  74. package/lib/utils/device.js +294 -322
  75. package/lib/utils/errors.js +75 -122
  76. package/lib/utils/event.js +79 -135
  77. package/lib/utils/hex-to-base64.js +5 -5
  78. package/lib/utils/hex-to-bytes.d.ts +0 -5
  79. package/lib/utils/hex-to-bytes.js +10 -15
  80. package/lib/utils/index.d.ts +0 -42
  81. package/lib/utils/index.js +247 -377
  82. package/lib/utils/log.d.ts +1 -4
  83. package/lib/utils/log.js +71 -74
  84. package/lib/utils/publishDps.d.ts +0 -5
  85. package/lib/utils/publishDps.js +58 -80
  86. package/package.json +3 -4
@@ -1,355 +1,327 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import "core-js/modules/esnext.iterator.constructor.js";
3
- import "core-js/modules/esnext.iterator.reduce.js";
4
- /***
5
- * 统一重新封装 TTT 能力api
6
- * 以便于以后支持跨端能力
7
- */
8
-
9
- export const getDeviceInfo = devId => {
10
- return new Promise((resolve, reject) => {
11
- ty.device.getDeviceInfo({
12
- deviceId: devId,
13
- success: res => resolve(res),
14
- fail: reject
1
+ export const getDeviceInfo = (devId) => {
2
+ return new Promise((resolve, reject) => {
3
+ ty.device.getDeviceInfo({
4
+ deviceId: devId,
5
+ success: (res) => resolve(res),
6
+ fail: reject,
7
+ });
15
8
  });
16
- });
17
- };
18
- export const getDeviceProperties = async devId => {
19
- return new Promise((resolve, reject) => {
20
- ty.device.getDeviceProperty({
21
- deviceId: devId,
22
- success: _ref => {
23
- let {
24
- properties
25
- } = _ref;
26
- const result = Object.keys(properties).reduce((res, cur) => {
27
- const value = properties[cur];
28
- try {
29
- res[cur] = JSON.parse(value);
30
- } catch {
31
- res[cur] = value;
32
- }
33
- return res;
34
- }, {});
35
- resolve(result);
36
- },
37
- fail: reject
9
+ };
10
+ export const getDeviceProperties = async (devId) => {
11
+ return new Promise((resolve, reject) => {
12
+ ty.device.getDeviceProperty({
13
+ deviceId: devId,
14
+ success: ({ properties }) => {
15
+ const result = Object.keys(properties).reduce((res, cur) => {
16
+ const value = properties[cur];
17
+ try {
18
+ res[cur] = JSON.parse(value);
19
+ }
20
+ catch {
21
+ res[cur] = value;
22
+ }
23
+ return res;
24
+ }, {});
25
+ resolve(result);
26
+ },
27
+ fail: reject,
28
+ });
38
29
  });
39
- });
40
30
  };
41
31
  export const setDeviceProperty = async (devId, code, value) => {
42
- return new Promise((resolve, reject) => {
43
- ty.device.setDeviceProperty({
44
- deviceId: devId,
45
- code,
46
- value: JSON.stringify(value),
47
- success: () => {
48
- resolve(true);
49
- },
50
- fail: reject
32
+ return new Promise((resolve, reject) => {
33
+ ty.device.setDeviceProperty({
34
+ deviceId: devId,
35
+ code,
36
+ value: JSON.stringify(value),
37
+ success: () => {
38
+ resolve(true);
39
+ },
40
+ fail: reject,
41
+ });
51
42
  });
52
- });
53
- };
54
- export const publishDeviceDps = params => {
55
- return new Promise((resolve, reject) => {
56
- ty.device.publishDps(_objectSpread(_objectSpread({
57
- mode: 2,
58
- pipelines: [],
59
- options: {}
60
- }, params), {}, {
61
- success: resolve,
62
- fail: reject
63
- }));
64
- });
65
- };
66
- export const registerDevice = devIds => {
67
- ty.device.registerDeviceListListener({
68
- deviceIdList: devIds
69
- });
70
- };
71
- export const registerBleStatus = devId => {
72
- ty.device.subscribeBLEConnectStatus({
73
- deviceId: devId
74
- });
75
- };
76
- export const onDpDataChange = func => {
77
- ty.device.onDpDataChange(func);
78
- };
79
- export const offDpDataChange = func => {
80
- // 由于 小程序底层删除为同步删除,如果在 onDpDataChange 回调中删除监听函数,可能会导致某些回调无法被触发,所以这里使用异步删除
81
- setTimeout(() => {
82
- ty.device.offDpDataChange(func);
83
- }, 0);
84
- };
85
-
86
- // 设备信息变化
87
- export const onDeviceInfoUpdated = func => {
88
- ty.device.onDeviceInfoUpdated(func);
89
- };
90
- export const offDeviceInfoUpdated = func => {
91
- ty.device.offDeviceInfoUpdated(func);
92
- };
93
- // 设备在离线变更
94
- export const onOnlineChange = func => {
95
- ty.device.onDeviceOnlineStatusUpdate(func);
96
- };
97
- export const offOnlineChange = func => {
98
- ty.device.offDeviceOnlineStatusUpdate(func);
99
- };
100
-
101
- // 蓝牙连接状态变更
102
- export const onBleChange = func => {
103
- ty.device.onBLEConnectStatusChange(func);
104
- };
105
- export const offBleChange = func => {
106
- ty.device.offBLEConnectStatusChange(func);
43
+ };
44
+ export const publishDeviceDps = (params) => {
45
+ return new Promise((resolve, reject) => {
46
+ ty.device.publishDps({
47
+ mode: 2,
48
+ pipelines: [],
49
+ options: {},
50
+ ...params,
51
+ success: resolve,
52
+ fail: reject,
53
+ });
54
+ });
55
+ };
56
+ export const registerDevice = (devIds) => {
57
+ ty.device.registerDeviceListListener({ deviceIdList: devIds });
58
+ };
59
+ export const registerBleStatus = (devId) => {
60
+ ty.device.subscribeBLEConnectStatus({ deviceId: devId });
61
+ };
62
+ export const onDpDataChange = (func) => {
63
+ ty.device.onDpDataChange(func);
64
+ };
65
+ export const offDpDataChange = (func) => {
66
+ setTimeout(() => {
67
+ ty.device.offDpDataChange(func);
68
+ }, 0);
69
+ };
70
+ export const onDeviceInfoUpdated = (func) => {
71
+ ty.device.onDeviceInfoUpdated(func);
72
+ };
73
+ export const offDeviceInfoUpdated = (func) => {
74
+ ty.device.offDeviceInfoUpdated(func);
75
+ };
76
+ export const onOnlineChange = (func) => {
77
+ ty.device.onDeviceOnlineStatusUpdate(func);
78
+ };
79
+ export const offOnlineChange = (func) => {
80
+ ty.device.offDeviceOnlineStatusUpdate(func);
81
+ };
82
+ export const onBleChange = (func) => {
83
+ ty.device.onBLEConnectStatusChange(func);
84
+ };
85
+ export const offBleChange = (func) => {
86
+ ty.device.offBLEConnectStatusChange(func);
107
87
  };
108
88
  export const getSystemInfo = () => ty.getSystemInfoSync();
109
- export const showModal = options => {
110
- return ty.showModal(options);
111
- };
112
- export const showToast = options => {
113
- return ty.showToast(options);
114
- };
115
- export const api = options => {
116
- return new Promise((resolve, reject) => {
117
- ty.apiRequestByAtop({
118
- api: options.url,
119
- postData: options.data,
120
- version: options.version,
121
- success: d => {
122
- resolve(d);
123
- },
124
- fail: err => {
125
- reject(err);
126
- }
89
+ export const showModal = (options) => {
90
+ return ty.showModal(options);
91
+ };
92
+ export const showToast = (options) => {
93
+ return ty.showToast(options);
94
+ };
95
+ export const api = (options) => {
96
+ return new Promise((resolve, reject) => {
97
+ ty.apiRequestByAtop({
98
+ api: options.url,
99
+ postData: options.data,
100
+ version: options.version,
101
+ success: (d) => {
102
+ resolve(d);
103
+ },
104
+ fail: (err) => {
105
+ reject(err);
106
+ },
107
+ });
127
108
  });
128
- });
129
- };
130
- export const getDeviceOnlineType = deviceId => {
131
- return new Promise((resolve, reject) => {
132
- ty.device.getDeviceOnlineType({
133
- deviceId,
134
- success: d => {
135
- resolve(d.onlineType);
136
- },
137
- fail: err => {
138
- reject(err);
139
- }
109
+ };
110
+ export const getDeviceOnlineType = (deviceId) => {
111
+ return new Promise((resolve, reject) => {
112
+ ty.device.getDeviceOnlineType({
113
+ deviceId,
114
+ success: (d) => {
115
+ resolve(d.onlineType);
116
+ },
117
+ fail: (err) => {
118
+ reject(err);
119
+ },
120
+ });
140
121
  });
141
- });
142
- };
143
- export const requestCloud = options => {
144
- return new Promise((resolve, reject) => {
145
- ty.requestCloud({
146
- api: options.api,
147
- version: options.version,
148
- data: options.data,
149
- extData: options.extData,
150
- success: d => {
151
- resolve(d);
152
- },
153
- fail: err => {
154
- var _err$innerError;
155
- reject((_err$innerError = err.innerError) !== null && _err$innerError !== void 0 ? _err$innerError : err);
156
- }
122
+ };
123
+ export const requestCloud = (options) => {
124
+ return new Promise((resolve, reject) => {
125
+ ty.requestCloud({
126
+ api: options.api,
127
+ version: options.version,
128
+ data: options.data,
129
+ extData: options.extData,
130
+ success: (d) => {
131
+ resolve(d);
132
+ },
133
+ fail: (err) => {
134
+ reject(err.innerError ?? err);
135
+ },
136
+ });
157
137
  });
158
- });
159
138
  };
160
139
  export const getLaunchOptionsSync = () => {
161
- return ty.getLaunchOptionsSync();
140
+ return ty.getLaunchOptionsSync();
162
141
  };
163
-
164
- // 加密函数(ECB 模式)
165
142
  export async function encrypt(deviceId, plaintext) {
166
- return new Promise((resolve, reject) => {
167
- // @ts-expect-error
168
- ty.device.aes128EncryptedStringWithPassword({
169
- deviceId,
170
- password: plaintext,
171
- success: res => {
172
- resolve(res.toUpperCase());
173
- },
174
- fail: reject
143
+ return new Promise((resolve, reject) => {
144
+ ty.device.aes128EncryptedStringWithPassword({
145
+ deviceId,
146
+ password: plaintext,
147
+ success: (res) => {
148
+ resolve(res.toUpperCase());
149
+ },
150
+ fail: reject,
151
+ });
175
152
  });
176
- });
177
153
  }
178
-
179
- // 解密函数(ECB 模式)
180
154
  export async function decrypt(deviceId, plaintext) {
181
- return new Promise((resolve, reject) => {
182
- // @ts-expect-error
183
- ty.device.aes128DecryptedStringWithPassword({
184
- deviceId,
185
- password: plaintext,
186
- success: res => {
187
- resolve(res);
188
- },
189
- fail: reject
155
+ return new Promise((resolve, reject) => {
156
+ ty.device.aes128DecryptedStringWithPassword({
157
+ deviceId,
158
+ password: plaintext,
159
+ success: (res) => {
160
+ resolve(res);
161
+ },
162
+ fail: reject,
163
+ });
190
164
  });
191
- });
192
165
  }
193
-
194
- // 获取当前家庭信息
195
166
  export const getCurrentHomeInfo = async () => {
196
- return new Promise((resolve, reject) => {
197
- ty.home.getCurrentHomeInfo({
198
- success: res => resolve(res),
199
- fail: reject
167
+ return new Promise((resolve, reject) => {
168
+ ty.home.getCurrentHomeInfo({
169
+ success: (res) => resolve(res),
170
+ fail: reject,
171
+ });
200
172
  });
201
- });
202
- };
203
- export const isSupportShortLink = async link => {
204
- return new Promise(resolve => {
205
- ty.canIUseRouter({
206
- url: link,
207
- success: res => {
208
- if (res !== null && res !== void 0 && res.result) {
209
- resolve(link);
210
- } else {
211
- resolve("");
212
- }
213
- },
214
- fail: err => {
215
- console.warn("isSupportShortLink fail", err);
216
- resolve("");
217
- }
173
+ };
174
+ export const isSupportShortLink = async (link) => {
175
+ return new Promise((resolve) => {
176
+ ty.canIUseRouter({
177
+ url: link,
178
+ success: (res) => {
179
+ if (res?.result) {
180
+ resolve(link);
181
+ }
182
+ else {
183
+ resolve("");
184
+ }
185
+ },
186
+ fail: (err) => {
187
+ console.warn("isSupportShortLink fail", err);
188
+ resolve("");
189
+ },
190
+ });
218
191
  });
219
- });
220
192
  };
221
193
  export const onBackgroundFetchData = (fetchApiKeys, cb) => {
222
- // @ts-expect-error
223
- if (ty.onBackgroundFetchData) {
224
- // @ts-expect-error
225
- ty.onBackgroundFetchData({
226
- fetchApiKeys,
227
- success: data => {
228
- cb(data);
229
- },
230
- fail: () => {
231
- // 不处理
232
- }
194
+ if (ty.onBackgroundFetchData) {
195
+ ty.onBackgroundFetchData({
196
+ fetchApiKeys,
197
+ success: (data) => {
198
+ cb(data);
199
+ },
200
+ fail: () => {
201
+ },
202
+ });
203
+ }
204
+ };
205
+ export const getBackgroundFetchData = async (fetchApiKeys) => {
206
+ if (ty.getBackgroundFetchData) {
207
+ return new Promise((resolve) => {
208
+ ty.getBackgroundFetchData({
209
+ fetchType: "periodic",
210
+ fetchApiKeys,
211
+ success: (res) => {
212
+ resolve(res);
213
+ },
214
+ fail: () => {
215
+ resolve(null);
216
+ },
217
+ });
218
+ });
219
+ }
220
+ return null;
221
+ };
222
+ export const sendMqttMessage = async (params) => {
223
+ return new Promise((resolve, reject) => {
224
+ ty.device.sendMqttMessage({
225
+ ...params,
226
+ options: {},
227
+ success: (res) => {
228
+ resolve(res);
229
+ },
230
+ fail: (err) => {
231
+ reject(err);
232
+ },
233
+ });
233
234
  });
234
- }
235
- };
236
- export const getBackgroundFetchData = async fetchApiKeys => {
237
- // @ts-expect-error
238
- if (ty.getBackgroundFetchData) {
239
- return new Promise(resolve => {
240
- // @ts-expect-error
241
- ty.getBackgroundFetchData({
242
- fetchType: "periodic",
243
- fetchApiKeys,
244
- success: res => {
245
- resolve(res);
246
- },
247
- fail: () => {
248
- resolve(null);
249
- }
250
- });
235
+ };
236
+ export const onMqttMessage = (cb) => {
237
+ ty.device.onMqttMessageReceived(cb);
238
+ };
239
+ export const offMqttMessage = (cb) => {
240
+ ty.device.offMqttMessageReceived(cb);
241
+ };
242
+ export const registerMQTTDeviceListener = (deviceId) => {
243
+ ty.device.registerMQTTDeviceListener({
244
+ deviceId,
251
245
  });
252
- }
253
- return null;
254
- };
255
- /**
256
- * 发送 MQTT 消息
257
- * @param params
258
- * @returns
259
- */
260
- export const sendMqttMessage = async params => {
261
- return new Promise((resolve, reject) => {
262
- ty.device.sendMqttMessage(_objectSpread(_objectSpread({}, params), {}, {
263
- options: {},
264
- success: res => {
265
- resolve(res);
266
- },
267
- fail: err => {
268
- reject(err);
269
- }
270
- }));
271
- });
272
- };
273
- export const onMqttMessage = cb => {
274
- ty.device.onMqttMessageReceived(cb);
275
- };
276
- export const offMqttMessage = cb => {
277
- ty.device.offMqttMessageReceived(cb);
278
- };
279
- export const registerMQTTDeviceListener = deviceId => {
280
- ty.device.registerMQTTDeviceListener({
281
- deviceId
282
- });
283
- };
284
- export const registerMQTTProtocolListener = protocol => {
285
- ty.device.registerMQTTProtocolListener({
286
- protocol
287
- });
288
- };
289
- export const openPanel = params => {
290
- return ty.openPanel(params);
246
+ };
247
+ export const registerMQTTProtocolListener = (protocol) => {
248
+ ty.device.registerMQTTProtocolListener({
249
+ protocol,
250
+ });
251
+ };
252
+ export const openPanel = (params) => {
253
+ return ty.openPanel(params);
291
254
  };
292
255
  export const openNativeRouter = (name, params) => {
293
- const query = Object.entries(params).reduce((acc, _ref2) => {
294
- let [key, value] = _ref2;
295
- if (typeof value !== "undefined") {
296
- acc.push(`${key}=${value}`);
297
- }
298
- return acc;
299
- }, []).join("&");
300
- return new Promise((resolve, reject) => {
301
- ty.canIUseRouter({
302
- url: name,
303
- success: res => {
304
- if (res !== null && res !== void 0 && res.result) {
305
- ty.router({
306
- url: `thingSmart://${name}?${query}`,
307
- success: () => {
308
- resolve(true);
309
- },
310
- fail: e => {
311
- reject(e);
312
- }
313
- });
256
+ const query = Object.entries(params)
257
+ .reduce((acc, [key, value]) => {
258
+ if (typeof value !== "undefined") {
259
+ acc.push(`${key}=${value}`);
314
260
  }
315
- },
316
- fail: err => {
317
- reject(err);
318
- }
261
+ return acc;
262
+ }, [])
263
+ .join("&");
264
+ return new Promise((resolve, reject) => {
265
+ ty.canIUseRouter({
266
+ url: name,
267
+ success: (res) => {
268
+ if (res?.result) {
269
+ const url = `thingSmart://${name}?${query}`;
270
+ ty.router({
271
+ url: url,
272
+ success: () => {
273
+ resolve(true);
274
+ },
275
+ fail: (e) => {
276
+ reject(e);
277
+ },
278
+ });
279
+ }
280
+ },
281
+ fail: (err) => {
282
+ reject(err);
283
+ },
284
+ });
285
+ });
286
+ };
287
+ export const createAction = (params) => {
288
+ return new Promise((resolve, reject) => {
289
+ ty.device.createAction({
290
+ ...params,
291
+ actionArray: [],
292
+ success: (res) => {
293
+ resolve(res.actionArray);
294
+ },
295
+ fail: (err) => {
296
+ reject(err);
297
+ },
298
+ });
299
+ });
300
+ };
301
+ export const editAction = (params) => {
302
+ return new Promise((resolve, reject) => {
303
+ ty.device.editAction({
304
+ ...params,
305
+ success: (res) => {
306
+ resolve(res.actionArray);
307
+ },
308
+ fail: (err) => {
309
+ reject(err);
310
+ },
311
+ });
319
312
  });
320
- });
321
- };
322
- export const createAction = params => {
323
- return new Promise((resolve, reject) => {
324
- ty.device.createAction(_objectSpread(_objectSpread({}, params), {}, {
325
- actionArray: [],
326
- success: res => {
327
- resolve(res.actionArray);
328
- },
329
- fail: err => {
330
- reject(err);
331
- }
332
- }));
333
- });
334
- };
335
- export const editAction = params => {
336
- return new Promise((resolve, reject) => {
337
- // @ts-expect-error
338
- ty.device.editAction(_objectSpread(_objectSpread({}, params), {}, {
339
- success: res => {
340
- resolve(res.actionArray);
341
- },
342
- fail: err => {
343
- reject(err);
344
- }
345
- }));
346
- });
347
313
  };
348
314
  export const getHomeInfo = async () => {
349
- return new Promise((resolve, reject) => {
350
- ty.home.getCurrentHomeInfo({
351
- success: res => resolve(res),
352
- fail: reject
315
+ return new Promise((resolve, reject) => {
316
+ ty.home.getCurrentHomeInfo({
317
+ success: (res) => resolve(res),
318
+ fail: reject,
319
+ });
353
320
  });
354
- });
355
- };
321
+ };
322
+ export const navigateToMiniProgram = (params) => {
323
+ return ty.navigateToMiniProgram(params);
324
+ };
325
+ export const navigateTo = (params) => {
326
+ return ty.navigateTo(params);
327
+ };