@abtnode/core 1.6.3 → 1.6.7
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/blocklet/extras.js +26 -1
- package/lib/blocklet/manager/disk.js +126 -131
- package/lib/cert.js +116 -0
- package/lib/index.js +26 -9
- package/lib/migrations/1.6.4-security.js +59 -0
- package/lib/migrations/1.6.5-security.js +60 -0
- package/lib/migrations/1.6.7-certificate.js +30 -0
- package/lib/router/helper.js +99 -107
- package/lib/router/index.js +1 -1
- package/lib/router/manager.js +10 -6
- package/lib/states/base.js +3 -212
- package/lib/states/blocklet-extras.js +20 -15
- package/lib/states/blocklet.js +58 -17
- package/lib/states/index.js +4 -21
- package/lib/states/node.js +9 -3
- package/lib/util/blocklet.js +1 -1
- package/lib/util/index.js +2 -0
- package/package.json +22 -20
package/lib/blocklet/extras.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const uniqBy = require('lodash/uniqBy');
|
|
2
|
+
const cloneDeep = require('lodash/cloneDeep');
|
|
3
|
+
const security = require('@abtnode/util/lib/security');
|
|
2
4
|
const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/meta/lib/constants');
|
|
3
5
|
|
|
4
|
-
const mergeConfigs = (oldConfigs, newConfigs = []) => {
|
|
6
|
+
const mergeConfigs = ({ old: oldConfigs, cur: newConfigs = [], did = '', dek = '' }) => {
|
|
5
7
|
const metaConfigs = (oldConfigs || []).filter((x) => !x.custom);
|
|
6
8
|
const customConfigs = (oldConfigs || []).filter((x) => x.custom);
|
|
7
9
|
|
|
@@ -23,6 +25,14 @@ const mergeConfigs = (oldConfigs, newConfigs = []) => {
|
|
|
23
25
|
return acc;
|
|
24
26
|
}, {});
|
|
25
27
|
|
|
28
|
+
if (dek && did) {
|
|
29
|
+
newConfigs.forEach((x) => {
|
|
30
|
+
if (x.secure) {
|
|
31
|
+
x.value = security.encrypt(x.value, did, dek);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
// newConfig 为用户传的,也可以是从环境变量中去读的
|
|
27
37
|
const uniqConfigs = uniqBy(newConfigs, (x) => x.key || x.name);
|
|
28
38
|
|
|
@@ -105,6 +115,21 @@ const mergeConfigs = (oldConfigs, newConfigs = []) => {
|
|
|
105
115
|
return mergedConfig;
|
|
106
116
|
};
|
|
107
117
|
|
|
118
|
+
const parseConfigs = ({ data, did, dek }) => {
|
|
119
|
+
if (dek && did && Array.isArray(data)) {
|
|
120
|
+
return cloneDeep(data).map((x) => {
|
|
121
|
+
if (x.secure) {
|
|
122
|
+
x.value = security.decrypt(x.value, did, dek);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return x;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return data;
|
|
130
|
+
};
|
|
131
|
+
|
|
108
132
|
module.exports = {
|
|
109
133
|
mergeConfigs,
|
|
134
|
+
parseConfigs,
|
|
110
135
|
};
|