@abtnode/core 1.15.17 → 1.16.0-beta-8ee536d7
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 +67 -69
- package/lib/api/team.js +386 -55
- package/lib/blocklet/downloader/blocklet-downloader.js +226 -0
- package/lib/blocklet/downloader/bundle-downloader.js +272 -0
- package/lib/blocklet/downloader/constants.js +3 -0
- package/lib/blocklet/downloader/resolve-download.js +199 -0
- package/lib/blocklet/extras.js +83 -26
- package/lib/blocklet/hooks.js +18 -65
- package/lib/blocklet/manager/base.js +10 -16
- package/lib/blocklet/manager/disk.js +1680 -1566
- package/lib/blocklet/manager/helper/install-application-from-backup.js +177 -0
- package/lib/blocklet/manager/helper/install-application-from-dev.js +94 -0
- package/lib/blocklet/manager/helper/install-application-from-general.js +188 -0
- package/lib/blocklet/manager/helper/install-component-from-dev.js +84 -0
- package/lib/blocklet/manager/helper/install-component-from-upload.js +181 -0
- package/lib/blocklet/manager/helper/install-component-from-url.js +173 -0
- package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +450 -0
- package/lib/blocklet/manager/helper/rollback-cache.js +41 -0
- package/lib/blocklet/manager/helper/upgrade-components.js +152 -0
- package/lib/blocklet/migration.js +30 -52
- package/lib/blocklet/storage/backup/audit-log.js +27 -0
- package/lib/blocklet/storage/backup/base.js +62 -0
- package/lib/blocklet/storage/backup/blocklet-extras.js +92 -0
- package/lib/blocklet/storage/backup/blocklet.js +70 -0
- package/lib/blocklet/storage/backup/blocklets.js +74 -0
- package/lib/blocklet/storage/backup/data.js +19 -0
- package/lib/blocklet/storage/backup/logs.js +24 -0
- package/lib/blocklet/storage/backup/routing-rule.js +19 -0
- package/lib/blocklet/storage/backup/spaces.js +240 -0
- package/lib/blocklet/storage/restore/base.js +67 -0
- package/lib/blocklet/storage/restore/blocklet-extras.js +86 -0
- package/lib/blocklet/storage/restore/blocklet.js +56 -0
- package/lib/blocklet/storage/restore/blocklets.js +43 -0
- package/lib/blocklet/storage/restore/logs.js +21 -0
- package/lib/blocklet/storage/restore/spaces.js +156 -0
- package/lib/blocklet/storage/utils/hash.js +51 -0
- package/lib/blocklet/storage/utils/zip.js +43 -0
- package/lib/cert.js +206 -0
- package/lib/event.js +237 -64
- package/lib/index.js +191 -83
- package/lib/migrations/1.0.21-update-config.js +1 -1
- package/lib/migrations/1.0.22-max-memory.js +1 -1
- package/lib/migrations/1.0.25.js +1 -1
- package/lib/migrations/1.0.32-update-config.js +1 -1
- package/lib/migrations/1.0.33-blocklets.js +1 -1
- package/lib/migrations/1.5.20-registry.js +15 -0
- package/lib/migrations/1.6.17-blocklet-children.js +48 -0
- package/lib/migrations/1.6.21-rename-ip-echo-domain.js +35 -0
- 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.9-update-node-info-and-certificate.js +38 -0
- package/lib/migrations/1.7.1-blocklet-setup.js +18 -0
- package/lib/migrations/1.7.12-blocklet-meta.js +51 -0
- package/lib/migrations/1.7.15-blocklet-bundle-source.js +42 -0
- package/lib/migrations/1.7.20-blocklet-component.js +41 -0
- package/lib/migrations/1.8.33-blocklet-mem-limit.js +20 -0
- package/lib/migrations/README.md +1 -1
- package/lib/migrations/index.js +6 -2
- package/lib/monitor/blocklet-runtime-monitor.js +200 -0
- package/lib/monitor/get-history-list.js +37 -0
- package/lib/monitor/node-runtime-monitor.js +228 -0
- package/lib/router/helper.js +576 -500
- package/lib/router/index.js +85 -21
- package/lib/router/manager.js +146 -187
- package/lib/states/README.md +36 -1
- package/lib/states/access-key.js +39 -17
- package/lib/states/audit-log.js +462 -0
- package/lib/states/base.js +4 -213
- package/lib/states/blocklet-extras.js +195 -138
- package/lib/states/blocklet.js +371 -110
- package/lib/states/cache.js +8 -6
- package/lib/states/challenge.js +5 -5
- package/lib/states/index.js +19 -36
- package/lib/states/migration.js +4 -4
- package/lib/states/node.js +135 -46
- package/lib/states/notification.js +22 -35
- package/lib/states/session.js +17 -9
- package/lib/states/site.js +50 -25
- package/lib/states/user.js +74 -20
- package/lib/states/webhook.js +10 -6
- package/lib/team/manager.js +124 -7
- package/lib/util/blocklet.js +1223 -246
- package/lib/util/chain.js +1 -1
- package/lib/util/default-node-config.js +5 -23
- package/lib/util/disk-monitor.js +13 -10
- package/lib/util/domain-status.js +84 -15
- package/lib/util/get-accessible-external-node-ip.js +2 -2
- package/lib/util/get-domain-for-blocklet.js +13 -0
- package/lib/util/get-meta-from-url.js +33 -0
- package/lib/util/index.js +207 -272
- package/lib/util/ip.js +6 -0
- package/lib/util/maintain.js +233 -0
- package/lib/util/public-to-store.js +85 -0
- package/lib/util/ready.js +1 -1
- package/lib/util/requirement.js +28 -9
- package/lib/util/reset-node.js +22 -7
- package/lib/util/router.js +13 -0
- package/lib/util/rpc.js +16 -0
- package/lib/util/store.js +179 -0
- package/lib/util/sysinfo.js +44 -0
- package/lib/util/ua.js +54 -0
- package/lib/validators/blocklet-extra.js +24 -0
- package/lib/validators/node.js +25 -12
- package/lib/validators/permission.js +16 -1
- package/lib/validators/role.js +17 -3
- package/lib/validators/router.js +40 -20
- package/lib/validators/trusted-passport.js +1 -0
- package/lib/validators/util.js +22 -5
- package/lib/webhook/index.js +45 -35
- package/lib/webhook/sender/index.js +5 -0
- package/lib/webhook/sender/slack/index.js +1 -1
- package/lib/webhook/sender/wallet/index.js +48 -0
- package/package.json +54 -36
- package/lib/blocklet/registry.js +0 -205
- package/lib/states/https-cert.js +0 -67
- package/lib/util/get-ip-dns-domain-for-blocklet.js +0 -19
- package/lib/util/service.js +0 -66
- package/lib/util/upgrade.js +0 -178
- /package/lib/{queue.js → util/queue.js} +0 -0
package/lib/api/node.js
CHANGED
|
@@ -6,97 +6,45 @@ const isDocker = require('@abtnode/util/lib/is-docker');
|
|
|
6
6
|
const isGitpod = require('@abtnode/util/lib/is-gitpod');
|
|
7
7
|
const getFolderSize = require('@abtnode/util/lib/get-folder-size');
|
|
8
8
|
const canPackageReadWrite = require('@abtnode/util/lib/can-pkg-rw');
|
|
9
|
-
const {
|
|
9
|
+
const { toDelegateAddress } = require('@arcblock/did-util');
|
|
10
10
|
|
|
11
11
|
const logger = require('@abtnode/logger')('@abtnode/core:api:node');
|
|
12
12
|
|
|
13
13
|
const IP = require('../util/ip');
|
|
14
|
-
const { validateNodeInfo } = require('../validators/node');
|
|
15
|
-
const BlockletRegistry = require('../blocklet/registry');
|
|
14
|
+
const { validateNodeInfo, validateUpdateGateway } = require('../validators/node');
|
|
16
15
|
const { getAll } = require('../blocklet/manager/engine');
|
|
16
|
+
const { getDelegateState } = require('../util');
|
|
17
|
+
const { NodeRuntimeMonitor } = require('../monitor/node-runtime-monitor');
|
|
18
|
+
const getHistoryList = require('../monitor/get-history-list');
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
throw new Error('Registry URL should not be empty');
|
|
21
|
-
}
|
|
20
|
+
// 10s 上报统计一次
|
|
21
|
+
const MONITOR_RECORD_INTERVAL_SEC = 10;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// 保存当天数据, 每天上报 8640 次
|
|
24
|
+
const MONITOR_HISTORY_LENGTH = 86400 / MONITOR_RECORD_INTERVAL_SEC;
|
|
25
25
|
|
|
26
26
|
class NodeAPI {
|
|
27
27
|
/**
|
|
28
28
|
*
|
|
29
29
|
* @param {object} state Node StateDB
|
|
30
30
|
*/
|
|
31
|
-
constructor(state
|
|
31
|
+
constructor(state) {
|
|
32
32
|
assert.notStrictEqual(state, undefined, 'argument state can not be undefined');
|
|
33
33
|
assert.notStrictEqual(state, null, 'argument state can not be null');
|
|
34
34
|
|
|
35
|
-
this.
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line no-unused-vars
|
|
40
|
-
async addRegistry({ url }, context) {
|
|
41
|
-
logger.info('add registry', { url });
|
|
42
|
-
const sanitized = sanitizeUrl(url);
|
|
43
|
-
const info = await this.state.read();
|
|
44
|
-
const exist = info.blockletRegistryList.find((x) => x.url === sanitized);
|
|
45
|
-
if (exist) {
|
|
46
|
-
throw new Error(`Blocklet registry already exist: ${sanitized}`);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
await BlockletRegistry.validateRegistryURL(sanitized);
|
|
50
|
-
|
|
51
|
-
const newBlockletRegistry = await BlockletRegistry.getRegistryMeta(sanitized);
|
|
52
|
-
const newBlockletRegistryList = info.blockletRegistryList.map((x) => ({ ...x, selected: false }));
|
|
53
|
-
newBlockletRegistryList.push({ ...newBlockletRegistry, url: sanitized, selected: true, protected: false });
|
|
54
|
-
|
|
55
|
-
this.blockletRegistry.clearCache();
|
|
56
|
-
return this.state.updateNodeInfo({ blockletRegistryList: newBlockletRegistryList });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// eslint-disable-next-line no-unused-vars
|
|
60
|
-
async deleteRegistry({ url }, context) {
|
|
61
|
-
logger.info('delete registry', { url });
|
|
62
|
-
const sanitized = sanitizeUrl(url);
|
|
63
|
-
const info = await this.state.read();
|
|
64
|
-
const exist = info.blockletRegistryList.find((x) => x.url === sanitized);
|
|
65
|
-
if (!exist) {
|
|
66
|
-
throw new Error(`Blocklet registry does not exist: ${sanitized}`);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
this.blockletRegistry.clearCache();
|
|
70
|
-
|
|
71
|
-
const blockletRegistryList = info.blockletRegistryList.filter((x) => x.url !== sanitized);
|
|
72
|
-
if (!blockletRegistryList.find((x) => x.selected)) {
|
|
73
|
-
blockletRegistryList[0].selected = true;
|
|
74
|
-
}
|
|
75
|
-
return this.state.updateNodeInfo({ blockletRegistryList });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// eslint-disable-next-line no-unused-vars
|
|
79
|
-
async selectRegistry({ url }, context) {
|
|
80
|
-
logger.info('select registry', { url });
|
|
81
|
-
const sanitized = sanitizeUrl(url);
|
|
82
|
-
const info = await this.state.read();
|
|
83
|
-
const exist = info.blockletRegistryList.find((x) => x.url === sanitized);
|
|
84
|
-
if (!exist) {
|
|
85
|
-
throw new Error(`Blocklet registry does not exist: ${sanitized}`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.blockletRegistry.clearCache();
|
|
89
|
-
return this.state.updateNodeInfo({
|
|
90
|
-
blockletRegistryList: info.blockletRegistryList.map((x) => ({ ...x, selected: x.url === sanitized })),
|
|
35
|
+
this.runtimeMonitor = new NodeRuntimeMonitor({
|
|
36
|
+
historyLength: MONITOR_HISTORY_LENGTH,
|
|
91
37
|
});
|
|
38
|
+
|
|
39
|
+
this.state = state;
|
|
92
40
|
}
|
|
93
41
|
|
|
94
42
|
async updateNodeInfo(entity = {}, context) {
|
|
95
43
|
await validateNodeInfo(entity, context);
|
|
96
44
|
|
|
97
|
-
if (entity.autoUpgrade) {
|
|
45
|
+
if (entity.autoUpgrade && process.env.NODE_ENV !== 'development') {
|
|
98
46
|
try {
|
|
99
|
-
canPackageReadWrite(
|
|
47
|
+
canPackageReadWrite(process.env.ABT_NODE_BINARY_NAME, process.env.ABT_NODE_PACKAGE_NAME);
|
|
100
48
|
} catch (err) {
|
|
101
49
|
throw new Error(`Auto upgrade is not supported for this node due to: ${err.message}`);
|
|
102
50
|
}
|
|
@@ -115,7 +63,7 @@ class NodeAPI {
|
|
|
115
63
|
const info = await this.state.read();
|
|
116
64
|
const env = await this.state.getEnvironments();
|
|
117
65
|
info.environments = Object.keys(env).map((x) => ({ key: x, value: env[x] }));
|
|
118
|
-
info.uptime =
|
|
66
|
+
info.uptime = process.uptime() * 1000;
|
|
119
67
|
|
|
120
68
|
return info;
|
|
121
69
|
}
|
|
@@ -155,6 +103,56 @@ class NodeAPI {
|
|
|
155
103
|
|
|
156
104
|
return res;
|
|
157
105
|
}
|
|
106
|
+
|
|
107
|
+
async updateGateway(entity, context) {
|
|
108
|
+
const data = await validateUpdateGateway(entity, context);
|
|
109
|
+
|
|
110
|
+
return this.state.updateGateway(data);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async getDelegationState() {
|
|
114
|
+
const info = await this.state.read();
|
|
115
|
+
|
|
116
|
+
const ownerNft = info.ownerNft || {};
|
|
117
|
+
if (!ownerNft.did) {
|
|
118
|
+
throw new Error('Invalid owner NFT');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const address = toDelegateAddress(ownerNft.holder, info.did);
|
|
122
|
+
const state = await getDelegateState(info.launcher.chainHost, address);
|
|
123
|
+
if (!state) {
|
|
124
|
+
return { delegated: false };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const transferV2Delegation = (state.ops || []).find(({ key }) => key === 'fg:t:transfer_v2');
|
|
128
|
+
return { delegated: !!transferV2Delegation };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// eslint-disable-next-line no-unused-vars
|
|
132
|
+
getHistory({ hours = 1 } = {}, context) {
|
|
133
|
+
const history = this.runtimeMonitor.getHistory();
|
|
134
|
+
|
|
135
|
+
return getHistoryList({
|
|
136
|
+
history,
|
|
137
|
+
hours,
|
|
138
|
+
recordIntervalSec: MONITOR_RECORD_INTERVAL_SEC,
|
|
139
|
+
props: ['date', 'cpu', 'mem', 'daemonMem', 'serviceMem', 'dbMem'],
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getRealtimeData() {
|
|
144
|
+
return this.runtimeMonitor.getRealtimeData();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getCrons() {
|
|
148
|
+
return [
|
|
149
|
+
{
|
|
150
|
+
name: 'record-node-runtime-info',
|
|
151
|
+
time: `*/${MONITOR_RECORD_INTERVAL_SEC} * * * * *`,
|
|
152
|
+
fn: () => this.runtimeMonitor.monit(),
|
|
153
|
+
},
|
|
154
|
+
];
|
|
155
|
+
}
|
|
158
156
|
}
|
|
159
157
|
|
|
160
158
|
module.exports = NodeAPI;
|