@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.
Files changed (95) hide show
  1. package/lib/api/index.d.ts +5 -0
  2. package/lib/api/index.js +18 -0
  3. package/lib/api/linkage.d.ts +161 -0
  4. package/lib/api/linkage.js +74 -0
  5. package/lib/api/lock.d.ts +195 -0
  6. package/lib/api/lock.js +129 -0
  7. package/lib/api/log.d.ts +166 -0
  8. package/lib/api/log.js +44 -0
  9. package/lib/api/setting.d.ts +14 -0
  10. package/lib/api/setting.js +36 -0
  11. package/lib/api/temp.d.ts +211 -0
  12. package/lib/api/temp.js +130 -0
  13. package/lib/api/user.d.ts +154 -0
  14. package/lib/api/user.js +59 -0
  15. package/lib/api/video.d.ts +9 -0
  16. package/lib/api/video.js +17 -0
  17. package/lib/config/dp-code/index.d.ts +175 -0
  18. package/lib/config/dp-code/index.js +224 -0
  19. package/lib/config/dp-map/common.d.ts +102 -0
  20. package/lib/config/dp-map/common.js +120 -0
  21. package/lib/config/dp-map/normal.d.ts +6 -0
  22. package/lib/config/dp-map/normal.js +51 -0
  23. package/lib/config/dp-map/open.d.ts +21 -0
  24. package/lib/config/dp-map/open.js +62 -0
  25. package/lib/config/dp-map/unlock-method-big.d.ts +559 -0
  26. package/lib/config/dp-map/unlock-method-big.js +237 -0
  27. package/lib/config/dp-map/unlock-method.d.ts +551 -0
  28. package/lib/config/dp-map/unlock-method.js +231 -0
  29. package/lib/config/index.d.ts +46 -0
  30. package/lib/config/index.js +56 -0
  31. package/lib/constant.d.ts +101 -0
  32. package/lib/constant.js +136 -0
  33. package/lib/dp-interface.d.ts +7 -0
  34. package/lib/dp-interface.js +1 -0
  35. package/lib/event.d.ts +8 -0
  36. package/lib/event.js +9 -0
  37. package/lib/index.d.ts +25 -0
  38. package/lib/index.js +92 -0
  39. package/lib/interface.d.ts +807 -0
  40. package/lib/interface.js +1 -0
  41. package/lib/linkage.d.ts +26 -0
  42. package/lib/linkage.js +175 -0
  43. package/lib/log.d.ts +91 -0
  44. package/lib/log.js +314 -0
  45. package/lib/media.d.ts +43 -0
  46. package/lib/media.js +80 -0
  47. package/lib/open.d.ts +48 -0
  48. package/lib/open.js +247 -0
  49. package/lib/other.d.ts +36 -0
  50. package/lib/other.js +178 -0
  51. package/lib/parse/index.d.ts +6 -0
  52. package/lib/parse/index.js +22 -0
  53. package/lib/signal.d.ts +26 -0
  54. package/lib/signal.js +38 -0
  55. package/lib/sleep.d.ts +61 -0
  56. package/lib/sleep.js +121 -0
  57. package/lib/state.d.ts +54 -0
  58. package/lib/state.js +429 -0
  59. package/lib/sync/remote-serect-key.d.ts +5 -0
  60. package/lib/sync/remote-serect-key.js +60 -0
  61. package/lib/sync/t0.d.ts +5 -0
  62. package/lib/sync/t0.js +33 -0
  63. package/lib/sync/temp.d.ts +7 -0
  64. package/lib/sync/temp.js +88 -0
  65. package/lib/sync/unlock-mothod.d.ts +5 -0
  66. package/lib/sync/unlock-mothod.js +54 -0
  67. package/lib/temporary.d.ts +226 -0
  68. package/lib/temporary.js +637 -0
  69. package/lib/unlock-method.d.ts +269 -0
  70. package/lib/unlock-method.js +723 -0
  71. package/lib/user.d.ts +108 -0
  72. package/lib/user.js +361 -0
  73. package/lib/utils/base64-to-hex.d.ts +1 -0
  74. package/lib/utils/base64-to-hex.js +12 -0
  75. package/lib/utils/byte.d.ts +19 -0
  76. package/lib/utils/byte.js +74 -0
  77. package/lib/utils/constant.d.ts +11 -0
  78. package/lib/utils/constant.js +17 -0
  79. package/lib/utils/device.d.ts +207 -0
  80. package/lib/utils/device.js +353 -0
  81. package/lib/utils/errors.d.ts +2 -0
  82. package/lib/utils/errors.js +125 -0
  83. package/lib/utils/event.d.ts +23 -0
  84. package/lib/utils/event.js +144 -0
  85. package/lib/utils/hex-to-base64.d.ts +1 -0
  86. package/lib/utils/hex-to-base64.js +8 -0
  87. package/lib/utils/hex-to-bytes.d.ts +6 -0
  88. package/lib/utils/hex-to-bytes.js +16 -0
  89. package/lib/utils/index.d.ts +169 -0
  90. package/lib/utils/index.js +419 -0
  91. package/lib/utils/log.d.ts +5 -0
  92. package/lib/utils/log.js +78 -0
  93. package/lib/utils/publishDps.d.ts +11 -0
  94. package/lib/utils/publishDps.js +91 -0
  95. package/package.json +37 -0
package/lib/index.js ADDED
@@ -0,0 +1,92 @@
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.map.js";
4
+ import "core-js/modules/esnext.iterator.reduce.js";
5
+ import config from "./config";
6
+ import dpCodes from "./config/dp-code";
7
+ import { addEvents, clearState, initState, removeEvents, getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate } from "./state";
8
+ import { getCapabilities } from "./utils";
9
+ import { getDeviceInfo, getLaunchOptionsSync } from "./utils/device";
10
+ import { syncUnlockMethod } from "./sync/unlock-mothod";
11
+ export * from "./user";
12
+ export * from "./unlock-method";
13
+ export * from "./temporary";
14
+ export * from "./open";
15
+ export * from "./log";
16
+ export * from "./signal";
17
+ export * from "./sleep";
18
+ export * from "./interface";
19
+ export * from "./constant";
20
+ export * from "./other";
21
+ export * from "./media";
22
+ export * from "./linkage";
23
+
24
+ /**
25
+ * 初始化sdk
26
+ * @param options 初始化参数
27
+ */
28
+ export const init = async options => {
29
+ var _options$strictMode, _options$passwordDigi, _options$passwordSupp;
30
+ let {
31
+ devInfo,
32
+ deviceId
33
+ } = options || {};
34
+ if (!devInfo && !deviceId) {
35
+ // 从启动参数中获取设备id
36
+ const {
37
+ query
38
+ } = getLaunchOptionsSync();
39
+ deviceId = query.deviceId;
40
+ if (!deviceId) {
41
+ throw new Error("deviceId is required in lock sdk");
42
+ }
43
+ }
44
+ if (deviceId && (!devInfo || devInfo.devId !== deviceId)) {
45
+ devInfo = await getDeviceInfo(deviceId);
46
+ }
47
+
48
+ // 处理dp
49
+ let dpSchema = {};
50
+ const codesById = {};
51
+ const idsByCode = {};
52
+ if (devInfo.schema) {
53
+ dpSchema = devInfo.schema.reduce((acc, cur) => {
54
+ acc[cur.code] = cur;
55
+ codesById[cur.id] = cur.code;
56
+ idsByCode[cur.code] = cur.id;
57
+ return acc;
58
+ }, {});
59
+ } else if (devInfo.dpSchema) {
60
+ dpSchema = devInfo.dpSchema;
61
+ Object.keys(dpSchema).forEach(key => {
62
+ const item = dpSchema[key];
63
+ codesById[item.id] = item.code;
64
+ idsByCode[item.code] = item.id;
65
+ });
66
+ }
67
+ config.strictMode = (_options$strictMode = options === null || options === void 0 ? void 0 : options.strictMode) !== null && _options$strictMode !== void 0 ? _options$strictMode : true;
68
+ config.passwordDigitalBase = (_options$passwordDigi = options === null || options === void 0 ? void 0 : options.passwordDigitalBase) !== null && _options$passwordDigi !== void 0 ? _options$passwordDigi : 10; // 默认十进制
69
+ config.passwordSupportZero = (_options$passwordSupp = options === null || options === void 0 ? void 0 : options.passwordSupportZero) !== null && _options$passwordSupp !== void 0 ? _options$passwordSupp : true; // 默认支持0
70
+ config.devInfo = devInfo;
71
+ config.dpSchema = dpSchema;
72
+ config.codesById = codesById;
73
+ config.idsByCode = idsByCode;
74
+ config.supportBigData = !!dpSchema[dpCodes.synchMethodW];
75
+
76
+ // 产品通讯能力
77
+ config.communication = getCapabilities(devInfo.capability).map(item => item.id);
78
+
79
+ // 初始化数据
80
+ await initState();
81
+ // 加入事件
82
+ addEvents();
83
+ };
84
+
85
+ /**
86
+ * 销毁 sdk
87
+ */
88
+ export const destroy = () => {
89
+ clearState();
90
+ removeEvents();
91
+ };
92
+ export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange };