@abtnode/core 1.6.2 → 1.6.6

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/node.js CHANGED
@@ -114,7 +114,7 @@ class NodeAPI {
114
114
  const info = await this.state.read();
115
115
  const env = await this.state.getEnvironments();
116
116
  info.environments = Object.keys(env).map((x) => ({ key: x, value: env[x] }));
117
- info.uptime = +new Date() - process.uptime() * 1000;
117
+ info.uptime = process.uptime() * 1000;
118
118
 
119
119
  return info;
120
120
  }
@@ -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
  };