@abtnode/core 1.15.17 → 1.16.0-beta-b16cb035
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 +1679 -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 +572 -497
- 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 +194 -138
- package/lib/states/blocklet.js +361 -104
- 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/index.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
const
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
2
3
|
const md5 = require('@abtnode/util/lib/md5');
|
|
4
|
+
const formatContext = require('@abtnode/util/lib/format-context');
|
|
3
5
|
const Cron = require('@abtnode/cron');
|
|
4
6
|
|
|
5
7
|
const logger = require('@abtnode/logger')('@abtnode/core');
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
fromBlockletSource,
|
|
10
|
-
toBlockletSource,
|
|
11
|
-
} = require('@blocklet/meta/lib/constants');
|
|
8
|
+
const { fromBlockletStatus, toBlockletStatus, fromBlockletSource, toBlockletSource } = require('@blocklet/constant');
|
|
9
|
+
const { listProviders } = require('@abtnode/router-provider');
|
|
10
|
+
const { DEFAULT_CERTIFICATE_EMAIL, EVENTS } = require('@abtnode/constant');
|
|
12
11
|
|
|
13
12
|
const RoutingSnapshot = require('./states/routing-snapshot');
|
|
14
|
-
const BlockletRegistry = require('./blocklet/registry');
|
|
15
13
|
const BlockletManager = require('./blocklet/manager/disk');
|
|
16
14
|
const RouterManager = require('./router/manager');
|
|
17
15
|
const getRouterHelpers = require('./router/helper');
|
|
@@ -20,18 +18,21 @@ const NodeAPI = require('./api/node');
|
|
|
20
18
|
const TeamAPI = require('./api/team');
|
|
21
19
|
const WebHook = require('./webhook');
|
|
22
20
|
const states = require('./states');
|
|
21
|
+
const Cert = require('./cert');
|
|
23
22
|
|
|
24
23
|
const IP = require('./util/ip');
|
|
25
24
|
const DomainStatus = require('./util/domain-status');
|
|
26
|
-
const
|
|
25
|
+
const Maintain = require('./util/maintain');
|
|
27
26
|
const resetNode = require('./util/reset-node');
|
|
28
|
-
const { getServices } = require('./util/service');
|
|
29
27
|
const DiskMonitor = require('./util/disk-monitor');
|
|
30
|
-
const
|
|
28
|
+
const StoreUtil = require('./util/store');
|
|
29
|
+
const createQueue = require('./util/queue');
|
|
31
30
|
const createEvents = require('./event');
|
|
32
31
|
const pm2Events = require('./blocklet/manager/pm2-events');
|
|
33
32
|
const { createStateReadyQueue, createStateReadyHandler } = require('./util/ready');
|
|
34
|
-
const {
|
|
33
|
+
const { createDataArchive } = require('./util/blocklet');
|
|
34
|
+
const { toStatus, fromStatus, ensureDataDirs, getQueueConcurrencyByMem, getStateCrons } = require('./util');
|
|
35
|
+
const getMetaFromUrl = require('./util/get-meta-from-url');
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
38
|
* @param {object} options
|
|
@@ -46,6 +47,7 @@ const { toStatus, fromStatus, ensureDataDirs, getQueueConcurrencyByMem } = requi
|
|
|
46
47
|
* version
|
|
47
48
|
* runtimeConfig: {}
|
|
48
49
|
* autoUpgrade
|
|
50
|
+
* registerUrl
|
|
49
51
|
* webWalletUrl
|
|
50
52
|
*/
|
|
51
53
|
function ABTNode(options) {
|
|
@@ -53,6 +55,11 @@ function ABTNode(options) {
|
|
|
53
55
|
throw new Error('Can not initialize ABTNode without dataDir');
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
const ekFile = path.join(options.dataDir, '.sock');
|
|
59
|
+
if (fs.existsSync(ekFile)) {
|
|
60
|
+
options.dek = fs.readFileSync(ekFile);
|
|
61
|
+
}
|
|
62
|
+
|
|
56
63
|
if (typeof options.daemon === 'undefined') {
|
|
57
64
|
options.daemon = false;
|
|
58
65
|
}
|
|
@@ -93,7 +100,25 @@ function ABTNode(options) {
|
|
|
93
100
|
concurrency,
|
|
94
101
|
maxRetries: 3,
|
|
95
102
|
retryDelay: 5000, // retry after 5 seconds
|
|
96
|
-
maxTimeout: 60 * 1000 * 15, // throw timeout error after
|
|
103
|
+
maxTimeout: 60 * 1000 * 15, // throw timeout error after 15 minutes
|
|
104
|
+
id: (job) => (job ? md5(`${job.entity}-${job.action}-${job.id}`) : ''),
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const backupQueue = createQueue({
|
|
109
|
+
daemon: options.daemon,
|
|
110
|
+
name: 'backup_queue',
|
|
111
|
+
dataDir: dataDirs.core,
|
|
112
|
+
onJob: async (job) => {
|
|
113
|
+
if (typeof blockletManager.onJob === 'function') {
|
|
114
|
+
await blockletManager.onJob(job);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
options: {
|
|
118
|
+
concurrency,
|
|
119
|
+
maxRetries: 3,
|
|
120
|
+
retryDelay: 10000, // retry after 10 seconds
|
|
121
|
+
maxTimeout: 60 * 1000 * 30, // throw timeout error after 30 minutes
|
|
97
122
|
id: (job) => (job ? md5(`${job.entity}-${job.action}-${job.id}`) : ''),
|
|
98
123
|
},
|
|
99
124
|
});
|
|
@@ -101,7 +126,13 @@ function ABTNode(options) {
|
|
|
101
126
|
// Initialize storage
|
|
102
127
|
states.init(dataDirs, options);
|
|
103
128
|
|
|
104
|
-
const
|
|
129
|
+
const certManager = new Cert({
|
|
130
|
+
maintainerEmail: DEFAULT_CERTIFICATE_EMAIL,
|
|
131
|
+
dataDir: dataDirs.certManagerModule,
|
|
132
|
+
states,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const routerManager = new RouterManager({ certManager });
|
|
105
136
|
const routingSnapshot = new RoutingSnapshot({
|
|
106
137
|
baseDir: dataDirs.core,
|
|
107
138
|
getRoutingData: async () => {
|
|
@@ -111,18 +142,21 @@ function ABTNode(options) {
|
|
|
111
142
|
},
|
|
112
143
|
});
|
|
113
144
|
|
|
114
|
-
const
|
|
145
|
+
const teamManager = new TeamManager({ nodeDid: options.nodeDid, dataDirs, states });
|
|
146
|
+
|
|
115
147
|
const blockletManager = new BlockletManager({
|
|
116
148
|
dataDirs,
|
|
117
149
|
startQueue,
|
|
118
150
|
installQueue,
|
|
119
|
-
|
|
151
|
+
backupQueue,
|
|
120
152
|
daemon: options.daemon,
|
|
153
|
+
teamManager,
|
|
121
154
|
});
|
|
155
|
+
blockletManager.setMaxListeners(0);
|
|
122
156
|
|
|
123
157
|
const {
|
|
124
158
|
handleRouting,
|
|
125
|
-
|
|
159
|
+
resetSiteByDid,
|
|
126
160
|
updateNodeRouting,
|
|
127
161
|
takeRoutingSnapshot,
|
|
128
162
|
getRoutingSites,
|
|
@@ -134,32 +168,27 @@ function ABTNode(options) {
|
|
|
134
168
|
getCertificates,
|
|
135
169
|
getSitesFromSnapshot,
|
|
136
170
|
getRoutingCrons,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
171
|
+
ensureWildcardCerts,
|
|
172
|
+
getRouterProvider,
|
|
173
|
+
addRoutingSite,
|
|
174
|
+
deleteRoutingSite,
|
|
175
|
+
updateRoutingSite,
|
|
176
|
+
addRoutingRule,
|
|
177
|
+
updateRoutingRule,
|
|
178
|
+
deleteRoutingRule,
|
|
179
|
+
addDomainAlias,
|
|
180
|
+
deleteDomainAlias,
|
|
181
|
+
} = getRouterHelpers({ dataDirs, routingSnapshot, routerManager, blockletManager, certManager });
|
|
182
|
+
|
|
183
|
+
const nodeAPI = new NodeAPI(states.node);
|
|
184
|
+
const teamAPI = new TeamAPI({ states, teamManager, dataDirs });
|
|
185
|
+
|
|
186
|
+
blockletManager.resetSiteByDid = resetSiteByDid;
|
|
145
187
|
|
|
146
188
|
// Generate an on node ready callback
|
|
147
189
|
const onStatesReady = createStateReadyQueue({ states, options, dataDirs });
|
|
148
190
|
onStatesReady(createStateReadyHandler(routingSnapshot));
|
|
149
|
-
const domainStatus = new DomainStatus(routerManager);
|
|
150
|
-
|
|
151
|
-
const events = createEvents({
|
|
152
|
-
blockletManager,
|
|
153
|
-
blockletRegistry,
|
|
154
|
-
ensureBlockletRouting,
|
|
155
|
-
ensureBlockletRoutingForUpgrade,
|
|
156
|
-
removeBlockletRouting,
|
|
157
|
-
takeRoutingSnapshot,
|
|
158
|
-
routerManager,
|
|
159
|
-
handleRouting,
|
|
160
|
-
domainStatus,
|
|
161
|
-
teamAPI,
|
|
162
|
-
});
|
|
191
|
+
const domainStatus = new DomainStatus({ routerManager, states });
|
|
163
192
|
|
|
164
193
|
const isInitialized = async () => {
|
|
165
194
|
const state = await states.node.read();
|
|
@@ -183,23 +212,30 @@ function ABTNode(options) {
|
|
|
183
212
|
|
|
184
213
|
// Blocklet manager
|
|
185
214
|
installBlocklet: blockletManager.install.bind(blockletManager),
|
|
186
|
-
|
|
215
|
+
installComponent: blockletManager.installComponent.bind(blockletManager),
|
|
187
216
|
startBlocklet: blockletManager.start.bind(blockletManager),
|
|
188
217
|
stopBlocklet: blockletManager.stop.bind(blockletManager),
|
|
189
218
|
reloadBlocklet: blockletManager.reload.bind(blockletManager),
|
|
190
219
|
restartBlocklet: blockletManager.restart.bind(blockletManager),
|
|
191
220
|
deleteBlocklet: blockletManager.delete.bind(blockletManager),
|
|
221
|
+
deleteComponent: blockletManager.deleteComponent.bind(blockletManager),
|
|
192
222
|
cancelDownloadBlocklet: blockletManager.cancelDownload.bind(blockletManager),
|
|
193
|
-
upgradeBlocklet: blockletManager.upgrade.bind(blockletManager),
|
|
194
223
|
configBlocklet: blockletManager.config.bind(blockletManager),
|
|
195
224
|
devBlocklet: blockletManager.dev.bind(blockletManager),
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
225
|
+
checkComponentsForUpdates: blockletManager.checkComponentsForUpdates.bind(blockletManager),
|
|
226
|
+
upgradeComponents: blockletManager.upgradeComponents.bind(blockletManager),
|
|
227
|
+
getBlockletMetaFromUrl: getMetaFromUrl.bind(blockletManager),
|
|
228
|
+
getBlockletForLauncher: blockletManager.getBlockletForLauncher.bind(blockletManager),
|
|
229
|
+
resetBlocklet: blockletManager.reset.bind(blockletManager),
|
|
202
230
|
deleteBlockletProcess: blockletManager.deleteProcess.bind(blockletManager),
|
|
231
|
+
configPublicToStore: blockletManager.configPublicToStore.bind(blockletManager),
|
|
232
|
+
configNavigations: blockletManager.configNavigations.bind(blockletManager),
|
|
233
|
+
updateWhoCanAccess: blockletManager.updateWhoCanAccess.bind(blockletManager),
|
|
234
|
+
updateComponentTitle: blockletManager.updateComponentTitle.bind(blockletManager),
|
|
235
|
+
updateComponentMountPoint: blockletManager.updateComponentMountPoint.bind(blockletManager),
|
|
236
|
+
backupToSpaces: blockletManager.backupToSpaces.bind(blockletManager),
|
|
237
|
+
restoreFromSpaces: blockletManager.restoreFromSpaces.bind(blockletManager),
|
|
238
|
+
migrateApplicationToStructV2: blockletManager.migrateApplicationToStructV2.bind(blockletManager),
|
|
203
239
|
|
|
204
240
|
// For diagnose purpose
|
|
205
241
|
syncBlockletStatus: blockletManager.status.bind(blockletManager),
|
|
@@ -209,39 +245,50 @@ function ABTNode(options) {
|
|
|
209
245
|
getBlocklets: blockletManager.list.bind(blockletManager),
|
|
210
246
|
getBlocklet: blockletManager.detail.bind(blockletManager),
|
|
211
247
|
getBlockletDiff: blockletManager.diff.bind(blockletManager),
|
|
248
|
+
hasBlocklet: blockletManager.hasBlocklet.bind(blockletManager),
|
|
212
249
|
updateAllBlockletEnvironment: blockletManager.updateAllBlockletEnvironment.bind(blockletManager),
|
|
250
|
+
setBlockletInitialized: blockletManager.setInitialized.bind(blockletManager),
|
|
251
|
+
getBlockletRuntimeHistory: blockletManager.getRuntimeHistory.bind(blockletManager),
|
|
213
252
|
|
|
214
|
-
//
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
getRegistryMeta: BlockletRegistry.getRegistryMeta,
|
|
253
|
+
// Store
|
|
254
|
+
getBlockletMeta: StoreUtil.getBlockletMeta,
|
|
255
|
+
getStoreMeta: StoreUtil.getStoreMeta,
|
|
218
256
|
|
|
219
257
|
// Node State
|
|
220
258
|
getNodeInfo: nodeAPI.getInfo.bind(nodeAPI),
|
|
221
259
|
getNodeEnv: nodeAPI.getEnv.bind(nodeAPI),
|
|
222
260
|
updateNodeInfo: nodeAPI.updateNodeInfo.bind(nodeAPI),
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
addNodeOwner: states.node.addNodeOwner.bind(states.node),
|
|
261
|
+
getDelegationState: nodeAPI.getDelegationState.bind(nodeAPI),
|
|
262
|
+
cleanupDirtyMaintainState: states.node.cleanupDirtyMaintainState.bind(states.node),
|
|
263
|
+
updateNodeOwner: states.node.updateNodeOwner.bind(states.node),
|
|
264
|
+
updateNftHolder: states.node.updateNftHolder.bind(states.node),
|
|
228
265
|
updateNodeRouting,
|
|
229
266
|
isInitialized,
|
|
230
267
|
resetNode: (params, context) =>
|
|
231
|
-
resetNode({ params, context, blockletManager, routerManager, takeRoutingSnapshot, teamManager }),
|
|
268
|
+
resetNode({ params, context, blockletManager, routerManager, takeRoutingSnapshot, teamManager, certManager }),
|
|
269
|
+
updateNodeStatus: states.node.updateStatus.bind(states.node),
|
|
270
|
+
resetNodeStatus: states.node.resetStatus.bind(states.node),
|
|
271
|
+
|
|
272
|
+
// Gateway
|
|
273
|
+
updateGateway: nodeAPI.updateGateway.bind(nodeAPI),
|
|
232
274
|
|
|
233
275
|
// Team && Access control
|
|
234
276
|
|
|
235
277
|
// Invitation
|
|
236
|
-
|
|
278
|
+
createMemberInvitation: teamAPI.createMemberInvitation.bind(teamAPI),
|
|
279
|
+
createTransferInvitation: teamAPI.createTransferInvitation.bind(teamAPI),
|
|
280
|
+
getInvitation: teamAPI.getInvitation.bind(teamAPI),
|
|
237
281
|
getInvitations: teamAPI.getInvitations.bind(teamAPI),
|
|
238
|
-
|
|
282
|
+
checkInvitation: teamAPI.checkInvitation.bind(teamAPI),
|
|
239
283
|
deleteInvitation: teamAPI.deleteInvitation.bind(teamAPI),
|
|
284
|
+
closeInvitation: teamAPI.closeInvitation.bind(teamAPI),
|
|
240
285
|
|
|
241
286
|
// Account
|
|
242
287
|
getUsers: teamAPI.getUsers.bind(teamAPI),
|
|
243
288
|
getUsersCount: teamAPI.getUsersCount.bind(teamAPI),
|
|
289
|
+
getUsersCountPerRole: teamAPI.getUsersCountPerRole.bind(teamAPI),
|
|
244
290
|
getUser: teamAPI.getUser.bind(teamAPI),
|
|
291
|
+
getOwner: teamAPI.getOwner.bind(teamAPI),
|
|
245
292
|
getNodeUsers: () => teamAPI.getUsers({ teamDid: options.nodeDid }),
|
|
246
293
|
getNodeUser: (user) => teamAPI.getUser({ teamDid: options.nodeDid, user }),
|
|
247
294
|
addUser: teamAPI.addUser.bind(teamAPI),
|
|
@@ -272,6 +319,8 @@ function ABTNode(options) {
|
|
|
272
319
|
// Passport
|
|
273
320
|
revokeUserPassport: teamAPI.revokeUserPassport.bind(teamAPI),
|
|
274
321
|
enableUserPassport: teamAPI.enableUserPassport.bind(teamAPI),
|
|
322
|
+
issuePassportToUser: teamAPI.issuePassportToUser.bind(teamAPI),
|
|
323
|
+
|
|
275
324
|
createPassportIssuance: teamAPI.createPassportIssuance.bind(teamAPI),
|
|
276
325
|
getPassportIssuances: teamAPI.getPassportIssuances.bind(teamAPI),
|
|
277
326
|
getPassportIssuance: teamAPI.getPassportIssuance.bind(teamAPI),
|
|
@@ -280,23 +329,31 @@ function ABTNode(options) {
|
|
|
280
329
|
configTrustedPassports: teamAPI.configTrustedPassports.bind(teamAPI),
|
|
281
330
|
configPassportIssuance: teamAPI.configPassportIssuance.bind(teamAPI),
|
|
282
331
|
|
|
332
|
+
// Team Settings
|
|
333
|
+
addBlockletStore: teamAPI.addStore.bind(teamAPI),
|
|
334
|
+
deleteBlockletStore: teamAPI.deleteStore.bind(teamAPI),
|
|
335
|
+
|
|
283
336
|
// Challenge
|
|
284
337
|
generateChallenge: states.challenge.generate.bind(states.challenge),
|
|
285
338
|
verifyChallenge: states.challenge.verify.bind(states.challenge),
|
|
286
339
|
|
|
287
340
|
// Notifications
|
|
288
|
-
getNotifications: states.notification.
|
|
341
|
+
getNotifications: states.notification.findPaginated.bind(states.notification),
|
|
289
342
|
readNotifications: states.notification.read.bind(states.notification),
|
|
290
343
|
unreadNotifications: states.notification.unread.bind(states.notification),
|
|
291
344
|
|
|
345
|
+
// AuditLog
|
|
346
|
+
createAuditLog: (params) => states.auditLog.create(params, instance),
|
|
347
|
+
getAuditLogs: states.auditLog.findPaginated.bind(states.auditLog),
|
|
348
|
+
|
|
292
349
|
// Routing
|
|
293
350
|
routerManager,
|
|
294
|
-
addRoutingSite
|
|
295
|
-
deleteRoutingSite
|
|
296
|
-
updateRoutingSite
|
|
297
|
-
addRoutingRule
|
|
298
|
-
updateRoutingRule
|
|
299
|
-
deleteRoutingRule
|
|
351
|
+
addRoutingSite,
|
|
352
|
+
deleteRoutingSite,
|
|
353
|
+
updateRoutingSite,
|
|
354
|
+
addRoutingRule,
|
|
355
|
+
updateRoutingRule,
|
|
356
|
+
deleteRoutingRule,
|
|
300
357
|
getRoutingRuleById: states.site.getRuleById.bind(states.site),
|
|
301
358
|
getRoutingSites: (params, context) => getRoutingSites(params, context, { withDefaultCors: false }),
|
|
302
359
|
getRoutingSnapshots: routingSnapshot.listSnapshots.bind(routingSnapshot),
|
|
@@ -304,23 +361,27 @@ function ABTNode(options) {
|
|
|
304
361
|
takeRoutingSnapshot,
|
|
305
362
|
getSitesFromSnapshot,
|
|
306
363
|
ensureDashboardRouting,
|
|
364
|
+
ensureWildcardCerts,
|
|
307
365
|
|
|
308
|
-
addDomainAlias
|
|
309
|
-
deleteDomainAlias
|
|
366
|
+
addDomainAlias,
|
|
367
|
+
deleteDomainAlias,
|
|
310
368
|
|
|
311
369
|
getRoutingProviders: () => listProviders(dataDirs.router),
|
|
312
370
|
checkDomains: domainStatus.checkDomainsStatus.bind(domainStatus),
|
|
313
371
|
handleRouting,
|
|
314
372
|
|
|
315
|
-
|
|
373
|
+
certManager,
|
|
374
|
+
updateCertificate: certManager.update.bind(certManager),
|
|
316
375
|
getCertificates,
|
|
317
|
-
addCertificate:
|
|
318
|
-
deleteCertificate:
|
|
319
|
-
findCertificateByDomain:
|
|
376
|
+
addCertificate: certManager.add.bind(certManager),
|
|
377
|
+
deleteCertificate: certManager.remove.bind(certManager),
|
|
378
|
+
findCertificateByDomain: certManager.getByDomain.bind(certManager),
|
|
379
|
+
issueLetsEncryptCert: certManager.issue.bind(certManager),
|
|
320
380
|
|
|
321
381
|
// Access Key
|
|
322
382
|
getAccessKeys: states.accessKey.list.bind(states.accessKey),
|
|
323
383
|
getAccessKey: states.accessKey.detail.bind(states.accessKey),
|
|
384
|
+
getAccessKeyByTag: states.accessKey.getAccessKeyByTag.bind(states.accessKey),
|
|
324
385
|
createAccessKey: states.accessKey.create.bind(states.accessKey),
|
|
325
386
|
updateAccessKey: states.accessKey.update.bind(states.accessKey),
|
|
326
387
|
deleteAccessKey: states.accessKey.remove.bind(states.accessKey),
|
|
@@ -331,10 +392,11 @@ function ABTNode(options) {
|
|
|
331
392
|
markMigrationExecuted: states.migration.markExecuted.bind(states.migration),
|
|
332
393
|
|
|
333
394
|
// Upgrading
|
|
334
|
-
upgradeNodeVersion:
|
|
335
|
-
checkNodeVersion:
|
|
336
|
-
|
|
337
|
-
|
|
395
|
+
upgradeNodeVersion: () => Maintain.triggerMaintain({ action: 'upgrade', next: Maintain.resumeMaintain }),
|
|
396
|
+
checkNodeVersion: Maintain.checkNewVersion,
|
|
397
|
+
restartServer: () => Maintain.triggerMaintain({ action: 'restart', next: Maintain.resumeMaintain }),
|
|
398
|
+
isBeingMaintained: Maintain.isBeingMaintained,
|
|
399
|
+
resumeMaintain: Maintain.resumeMaintain,
|
|
338
400
|
|
|
339
401
|
// Session
|
|
340
402
|
getSession: (params, context) => states.session.read(params.id, context),
|
|
@@ -348,10 +410,31 @@ function ABTNode(options) {
|
|
|
348
410
|
),
|
|
349
411
|
endSession: (params, context) => states.session.end(params.id, context),
|
|
350
412
|
|
|
351
|
-
|
|
352
|
-
|
|
413
|
+
getNodeRuntimeHistory: nodeAPI.getHistory.bind(nodeAPI),
|
|
414
|
+
getNodeRuntimeInfo: nodeAPI.getRealtimeData.bind(nodeAPI),
|
|
415
|
+
|
|
416
|
+
getRouterProvider,
|
|
417
|
+
|
|
418
|
+
// for exporting blocklet data dir
|
|
419
|
+
createBlockletDataArchive: createDataArchive,
|
|
353
420
|
};
|
|
354
421
|
|
|
422
|
+
const events = createEvents({
|
|
423
|
+
blockletManager,
|
|
424
|
+
ensureBlockletRouting,
|
|
425
|
+
ensureBlockletRoutingForUpgrade,
|
|
426
|
+
removeBlockletRouting,
|
|
427
|
+
takeRoutingSnapshot,
|
|
428
|
+
handleRouting,
|
|
429
|
+
domainStatus,
|
|
430
|
+
teamAPI,
|
|
431
|
+
teamManager,
|
|
432
|
+
certManager,
|
|
433
|
+
routerManager,
|
|
434
|
+
node: instance,
|
|
435
|
+
nodeRuntimeMonitor: nodeAPI.runtimeMonitor,
|
|
436
|
+
});
|
|
437
|
+
|
|
355
438
|
const webhook = WebHook({ events, dataDirs, instance });
|
|
356
439
|
|
|
357
440
|
const initCron = () => {
|
|
@@ -359,11 +442,12 @@ function ABTNode(options) {
|
|
|
359
442
|
context: { states, events, webhook },
|
|
360
443
|
jobs: [
|
|
361
444
|
IP.cron,
|
|
362
|
-
|
|
363
|
-
Upgrade.getCron(),
|
|
445
|
+
Maintain.getCron(),
|
|
364
446
|
...getRoutingCrons(),
|
|
365
447
|
...blockletManager.getCrons(),
|
|
366
448
|
DiskMonitor.getCron(),
|
|
449
|
+
...getStateCrons(states),
|
|
450
|
+
...nodeAPI.getCrons(),
|
|
367
451
|
],
|
|
368
452
|
onError: (error, name) => {
|
|
369
453
|
states.notification.create({
|
|
@@ -377,20 +461,44 @@ function ABTNode(options) {
|
|
|
377
461
|
});
|
|
378
462
|
};
|
|
379
463
|
|
|
464
|
+
const createCLILog = (action) => {
|
|
465
|
+
instance
|
|
466
|
+
.createAuditLog({
|
|
467
|
+
action,
|
|
468
|
+
args: {},
|
|
469
|
+
context: formatContext({
|
|
470
|
+
user: { fullName: 'CLI', role: 'admin', did: options.nodeDid },
|
|
471
|
+
headers: { 'user-agent': 'CLI' },
|
|
472
|
+
}),
|
|
473
|
+
result: null,
|
|
474
|
+
})
|
|
475
|
+
.catch(console.error);
|
|
476
|
+
};
|
|
477
|
+
|
|
380
478
|
if (options.daemon) {
|
|
479
|
+
// 启动证书服务
|
|
480
|
+
certManager
|
|
481
|
+
.start()
|
|
482
|
+
.then(() => logger.info('start certificate manager service successfully'))
|
|
483
|
+
.catch((error) => logger.error('start certificate manager service failed', { error }));
|
|
484
|
+
|
|
381
485
|
if (process.env.NODE_ENV === 'development') {
|
|
382
|
-
|
|
486
|
+
setTimeout(() => {
|
|
487
|
+
initCron();
|
|
488
|
+
}, 1000);
|
|
383
489
|
} else {
|
|
384
490
|
// We should only respond to pm2 events when node is alive
|
|
385
|
-
events.on(
|
|
491
|
+
events.on(EVENTS.NODE_STARTED, () => {
|
|
386
492
|
pm2Events.resume();
|
|
387
493
|
initCron();
|
|
494
|
+
createCLILog('startServer');
|
|
388
495
|
});
|
|
389
496
|
}
|
|
390
497
|
}
|
|
391
498
|
|
|
392
|
-
events.on(
|
|
499
|
+
events.on(EVENTS.NODE_STOPPED, () => {
|
|
393
500
|
pm2Events.pause();
|
|
501
|
+
createCLILog('stopServer');
|
|
394
502
|
});
|
|
395
503
|
|
|
396
504
|
return Object.assign(events, {
|
|
@@ -7,7 +7,7 @@ module.exports = async ({ states, config, configFile, printInfo }) => {
|
|
|
7
7
|
printInfo('Try to update node config to 1.0.21...');
|
|
8
8
|
let changed = false;
|
|
9
9
|
|
|
10
|
-
const rawConfig = yaml.
|
|
10
|
+
const rawConfig = yaml.load(fs.readFileSync(configFile).toString());
|
|
11
11
|
const info = await states.node.read();
|
|
12
12
|
|
|
13
13
|
const updates = [
|
|
@@ -13,7 +13,7 @@ module.exports = async ({ states, config, configFile, printInfo }) => {
|
|
|
13
13
|
printInfo('Try to update node config to 1.0.22...');
|
|
14
14
|
let changed = false;
|
|
15
15
|
|
|
16
|
-
const rawConfig = yaml.
|
|
16
|
+
const rawConfig = yaml.load(fs.readFileSync(configFile).toString());
|
|
17
17
|
const info = await states.node.read();
|
|
18
18
|
|
|
19
19
|
const updates = [
|
package/lib/migrations/1.0.25.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = async ({ states, config, configFile, printInfo }) => {
|
|
|
10
10
|
printInfo('Try to update node config to 1.0.25...');
|
|
11
11
|
let changed = false;
|
|
12
12
|
|
|
13
|
-
const rawConfig = yaml.
|
|
13
|
+
const rawConfig = yaml.load(fs.readFileSync(configFile).toString());
|
|
14
14
|
const info = await states.node.read();
|
|
15
15
|
|
|
16
16
|
const updates = [
|
|
@@ -7,7 +7,7 @@ module.exports = async ({ states, config, configFile, printInfo }) => {
|
|
|
7
7
|
printInfo('Try to update node config to 1.0.32...');
|
|
8
8
|
let changed = false;
|
|
9
9
|
|
|
10
|
-
const rawConfig = yaml.
|
|
10
|
+
const rawConfig = yaml.load(fs.readFileSync(configFile).toString());
|
|
11
11
|
const info = await states.node.read();
|
|
12
12
|
|
|
13
13
|
const updates = [{ key: 'routing.https', value: true }];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable no-await-in-loop */
|
|
2
2
|
/* eslint-disable no-underscore-dangle */
|
|
3
|
-
const { BLOCKLET_DEFAULT_PORT_NAME } = require('@blocklet/
|
|
3
|
+
const { BLOCKLET_DEFAULT_PORT_NAME } = require('@blocklet/constant');
|
|
4
4
|
|
|
5
5
|
module.exports = async ({ states, printInfo }) => {
|
|
6
6
|
printInfo('Try to update node config to 1.0.33...');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module.exports = async ({ states, printInfo }) => {
|
|
2
|
+
printInfo('Try to rename Blocklet Registry to Blocklet Store in db...');
|
|
3
|
+
|
|
4
|
+
const info = await states.node.read();
|
|
5
|
+
(info.blockletRegistryList || []).forEach((item) => {
|
|
6
|
+
if (!item) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
item.name = (item.name || '').replace('Registry', 'Store');
|
|
10
|
+
item.description = (item.description || '').replace('registry', 'store');
|
|
11
|
+
item.url = (item.url || '').replace('registry.arcblock.io', 'store.blocklet.dev');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
await states.node.updateNodeInfo(info);
|
|
15
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable no-continue */
|
|
2
|
+
/* eslint-disable no-await-in-loop */
|
|
3
|
+
/* eslint-disable no-underscore-dangle */
|
|
4
|
+
|
|
5
|
+
module.exports = async ({ states, printInfo }) => {
|
|
6
|
+
printInfo('Try to update blocklet to 1.6.17...');
|
|
7
|
+
const blockletState = states.blocklet;
|
|
8
|
+
|
|
9
|
+
const blocklets = await blockletState.getBlocklets();
|
|
10
|
+
for (const blocklet of blocklets) {
|
|
11
|
+
if (!blocklet) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (!blocklet.children || !blocklet.children.length) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const meta = blocklet.meta || {};
|
|
20
|
+
const { did } = meta;
|
|
21
|
+
if (!did) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const children = (blocklet.children || []).map((child) => {
|
|
26
|
+
if (child.mountPoint) {
|
|
27
|
+
return child;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const config = (meta.children || []).find((x) => x.name === child.meta.name);
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
config &&
|
|
34
|
+
config.mountPoints &&
|
|
35
|
+
config.mountPoints[0] &&
|
|
36
|
+
config.mountPoints[0].root &&
|
|
37
|
+
config.mountPoints[0].root.prefix
|
|
38
|
+
) {
|
|
39
|
+
child.mountPoint = config.mountPoints[0].root.prefix;
|
|
40
|
+
}
|
|
41
|
+
printInfo(`Set mountPoint: ${child.mountPoint} to child ${child.meta.name} in ${blocklet.meta.name}`);
|
|
42
|
+
|
|
43
|
+
return child;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await blockletState.update(blocklet._id, { $set: { children } });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const yaml = require('js-yaml');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const set = require('lodash/set');
|
|
4
|
+
const omit = require('lodash/omit');
|
|
5
|
+
const {
|
|
6
|
+
DEFAULT_WILDCARD_CERT_HOST,
|
|
7
|
+
DEFAULT_DID_DOMAIN,
|
|
8
|
+
DEFAULT_DID_REGISTRY,
|
|
9
|
+
DEFAULT_IP_DOMAIN,
|
|
10
|
+
} = require('@abtnode/constant');
|
|
11
|
+
|
|
12
|
+
module.exports = async ({ states, printInfo, configFile }) => {
|
|
13
|
+
printInfo('Try to rename dashboardDomain to ipWildcardDomain in db...');
|
|
14
|
+
|
|
15
|
+
let info = await states.node.read();
|
|
16
|
+
set(info, 'routing.ipWildcardDomain', info.routing.dashboardDomain || DEFAULT_IP_DOMAIN);
|
|
17
|
+
set(info, 'routing.wildcardCertHost', DEFAULT_WILDCARD_CERT_HOST);
|
|
18
|
+
set(info, 'didDomain', DEFAULT_DID_DOMAIN);
|
|
19
|
+
set(info, 'didRegistry', DEFAULT_DID_REGISTRY);
|
|
20
|
+
info = omit(info, 'routing.dashboardDomain');
|
|
21
|
+
|
|
22
|
+
await states.node.updateNodeInfo(info);
|
|
23
|
+
|
|
24
|
+
if (process.env.NODE_ENV !== 'development') {
|
|
25
|
+
let rawConfig = yaml.load(fs.readFileSync(configFile).toString());
|
|
26
|
+
set(rawConfig, 'node.routing.ipWildcardDomain', info.routing.ipWildcardDomain);
|
|
27
|
+
set(rawConfig, 'node.routing.wildcardCertHost', DEFAULT_WILDCARD_CERT_HOST);
|
|
28
|
+
set(rawConfig, 'node.didDomain', DEFAULT_DID_DOMAIN);
|
|
29
|
+
set(rawConfig, 'node.didRegistry', DEFAULT_DID_REGISTRY);
|
|
30
|
+
rawConfig = omit(rawConfig, 'node.routing.dashboardDomain');
|
|
31
|
+
fs.writeFileSync(configFile, yaml.dump(rawConfig));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
printInfo(`> Persist new config to file: ${configFile}`);
|
|
35
|
+
};
|