@abtnode/core 1.6.14 → 1.6.15
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/manager/disk.js +13 -2
- package/lib/index.js +0 -10
- package/lib/router/helper.js +19 -9
- package/lib/router/manager.js +23 -5
- package/lib/util/blocklet.js +5 -0
- package/lib/util/router.js +13 -0
- package/lib/validators/permission.js +16 -1
- package/package.json +20 -20
|
@@ -2332,7 +2332,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2332
2332
|
async _rollback(action, did, oldBlocklet) {
|
|
2333
2333
|
if (action === 'install') {
|
|
2334
2334
|
// remove blocklet
|
|
2335
|
-
return this._deleteBlocklet({ did, keepData:
|
|
2335
|
+
return this._deleteBlocklet({ did, keepData: true });
|
|
2336
2336
|
}
|
|
2337
2337
|
|
|
2338
2338
|
if (['upgrade', 'downgrade'].includes(action)) {
|
|
@@ -2374,7 +2374,18 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2374
2374
|
const result = await states.blocklet.deleteBlocklet(did);
|
|
2375
2375
|
logger.info('blocklet removed successfully', { did });
|
|
2376
2376
|
|
|
2377
|
-
|
|
2377
|
+
let keepRouting = true;
|
|
2378
|
+
if (keepData === false || keepConfigs === false) {
|
|
2379
|
+
keepRouting = false;
|
|
2380
|
+
}
|
|
2381
|
+
|
|
2382
|
+
this.emit(BlockletEvents.removed, {
|
|
2383
|
+
blocklet: result,
|
|
2384
|
+
context: {
|
|
2385
|
+
...context,
|
|
2386
|
+
keepRouting,
|
|
2387
|
+
},
|
|
2388
|
+
});
|
|
2378
2389
|
return blocklet;
|
|
2379
2390
|
}
|
|
2380
2391
|
|
package/lib/index.js
CHANGED
|
@@ -400,16 +400,6 @@ function ABTNode(options) {
|
|
|
400
400
|
} else {
|
|
401
401
|
// We should only respond to pm2 events when node is alive
|
|
402
402
|
events.on('node.started', async () => {
|
|
403
|
-
const info = await states.node.read();
|
|
404
|
-
certManager
|
|
405
|
-
.issue({ domain: `${info.did.toLowerCase()}.${info.didDomain}` })
|
|
406
|
-
.then(() => {
|
|
407
|
-
logger.info('add issue daemon certificate job');
|
|
408
|
-
})
|
|
409
|
-
.catch((error) => {
|
|
410
|
-
logger.error('issue daemon certificate job failed', { error });
|
|
411
|
-
});
|
|
412
|
-
|
|
413
403
|
pm2Events.resume();
|
|
414
404
|
initCron();
|
|
415
405
|
});
|
package/lib/router/helper.js
CHANGED
|
@@ -55,6 +55,7 @@ const { getFromCache: getAccessibleExternalNodeIp } = require('../util/get-acces
|
|
|
55
55
|
|
|
56
56
|
const Router = require('./index');
|
|
57
57
|
const states = require('../states');
|
|
58
|
+
const { getBlockletDomainGroupName, getDidFromDomainGroupName } = require('../util/router');
|
|
58
59
|
|
|
59
60
|
/**
|
|
60
61
|
* replace 888-888-888-888 with accessible ip for domain
|
|
@@ -353,6 +354,18 @@ const ensureCorsForWebWallet = async (sites) => {
|
|
|
353
354
|
return sites;
|
|
354
355
|
};
|
|
355
356
|
|
|
357
|
+
const filterSitesForRemovedBlocklets = async (sites = []) => {
|
|
358
|
+
const blocklets = await states.blocklet.getBlocklets();
|
|
359
|
+
return sites.filter((site) => {
|
|
360
|
+
if (!site.domain.endsWith(BLOCKLET_SITE_GROUP_SUFFIX)) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const did = getDidFromDomainGroupName(site.domain);
|
|
365
|
+
return blocklets.some((x) => x.meta.did === did);
|
|
366
|
+
});
|
|
367
|
+
};
|
|
368
|
+
|
|
356
369
|
const ensureLatestInfo = async (sites = [], { withDefaultCors = true } = {}) => {
|
|
357
370
|
let result = await ensureLatestNodeInfo(sites, { withDefaultCors });
|
|
358
371
|
result = await ensureWellknownRule(result);
|
|
@@ -713,7 +726,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
713
726
|
return `/${str}`.replace(/^\/+/, '/');
|
|
714
727
|
};
|
|
715
728
|
|
|
716
|
-
const domainGroup =
|
|
729
|
+
const domainGroup = getBlockletDomainGroupName(blocklet.meta.did);
|
|
717
730
|
|
|
718
731
|
const pathPrefix = getPrefix(webInterface.prefix);
|
|
719
732
|
const rule = {
|
|
@@ -755,13 +768,6 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
755
768
|
context
|
|
756
769
|
);
|
|
757
770
|
logger.info('add routing site', { site: domainGroup });
|
|
758
|
-
if (
|
|
759
|
-
process.env.NODE_ENV !== 'development' &&
|
|
760
|
-
process.env.NODE_ENV !== 'test' &&
|
|
761
|
-
blocklet.mode !== 'development'
|
|
762
|
-
) {
|
|
763
|
-
await certManager.issue({ domain: didDomain });
|
|
764
|
-
}
|
|
765
771
|
|
|
766
772
|
return true;
|
|
767
773
|
}
|
|
@@ -1080,7 +1086,10 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
1080
1086
|
const nodeInfo = await nodeState.read();
|
|
1081
1087
|
|
|
1082
1088
|
const ruleChanged = await routerManager.deleteRoutingRulesItemByDid({ did: blocklet.meta.did }, context);
|
|
1083
|
-
|
|
1089
|
+
let siteChanged;
|
|
1090
|
+
if (!context.keepRouting) {
|
|
1091
|
+
siteChanged = await _removeBlockletSites(blocklet, nodeInfo, context);
|
|
1092
|
+
}
|
|
1084
1093
|
|
|
1085
1094
|
return ruleChanged || siteChanged;
|
|
1086
1095
|
};
|
|
@@ -1140,6 +1149,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
1140
1149
|
try {
|
|
1141
1150
|
const info = await nodeState.read();
|
|
1142
1151
|
let { sites } = await readRoutingSites();
|
|
1152
|
+
sites = await filterSitesForRemovedBlocklets(sites);
|
|
1143
1153
|
sites = await ensureLatestInfo(sites);
|
|
1144
1154
|
sites = await ensureAuthService(sites, blockletManager);
|
|
1145
1155
|
sites = await ensureServiceRule(sites);
|
package/lib/router/manager.js
CHANGED
|
@@ -186,19 +186,37 @@ class RouterManager extends EventEmitter {
|
|
|
186
186
|
return dbSite;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
async addDomainAlias({ id, domainAlias }, context = {}) {
|
|
189
|
+
async addDomainAlias({ id, domainAlias, force }, context = {}) {
|
|
190
190
|
await validateAddDomainAlias(domainAlias, context);
|
|
191
191
|
const dbSite = await states.site.findOne({ _id: id });
|
|
192
192
|
if (!dbSite) {
|
|
193
193
|
throw new Error(`site ${id} does not exist`);
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
// check domain exists in site domain
|
|
197
|
+
const mainDomainSiteCount = await states.site.count({
|
|
198
|
+
domain: domainAlias,
|
|
198
199
|
});
|
|
199
200
|
|
|
200
|
-
if (
|
|
201
|
-
|
|
201
|
+
if (mainDomainSiteCount > 0) {
|
|
202
|
+
if (!force) {
|
|
203
|
+
throw new Error(`${domainAlias} already exists`);
|
|
204
|
+
} else {
|
|
205
|
+
throw new Error(`${domainAlias} cannot be forced-added`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// check domain exists in site alias domain
|
|
210
|
+
const aliasDomainSite = await states.site.findOne({
|
|
211
|
+
$or: [{ domainAliases: domainAlias }, { 'domainAliases.value': domainAlias }],
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
if (aliasDomainSite) {
|
|
215
|
+
if (!force) {
|
|
216
|
+
throw new Error(`${domainAlias} already exists`);
|
|
217
|
+
} else {
|
|
218
|
+
await this.deleteDomainAlias({ id: aliasDomainSite.id, domainAlias });
|
|
219
|
+
}
|
|
202
220
|
}
|
|
203
221
|
|
|
204
222
|
const updateResult = await states.site.update(
|
package/lib/util/blocklet.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { BLOCKLET_SITE_GROUP_SUFFIX } = require('@abtnode/constant');
|
|
2
|
+
|
|
3
|
+
const getBlockletDomainGroupName = (did) => `${did}${BLOCKLET_SITE_GROUP_SUFFIX}`;
|
|
4
|
+
|
|
5
|
+
const getDidFromDomainGroupName = (name) => {
|
|
6
|
+
const did = name.replace(BLOCKLET_SITE_GROUP_SUFFIX, '');
|
|
7
|
+
return did;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
getBlockletDomainGroupName,
|
|
12
|
+
getDidFromDomainGroupName,
|
|
13
|
+
};
|
|
@@ -2,7 +2,22 @@
|
|
|
2
2
|
const JOI = require('joi');
|
|
3
3
|
const { getMultipleLangParams } = require('./util');
|
|
4
4
|
|
|
5
|
-
const nameSchema = JOI.string()
|
|
5
|
+
const nameSchema = JOI.string()
|
|
6
|
+
.trim()
|
|
7
|
+
.max(64)
|
|
8
|
+
.custom((name) => {
|
|
9
|
+
const arr = name.split('_');
|
|
10
|
+
const formatTip = 'The format of permission name should be "{action}_{resource}", e.g. query_data';
|
|
11
|
+
if (arr.length > 2) {
|
|
12
|
+
throw new Error(`Too much "_". ${formatTip}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (arr.length < 2) {
|
|
16
|
+
throw new Error(formatTip);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return name;
|
|
20
|
+
});
|
|
6
21
|
const descriptionSchema = JOI.string().trim().max(600);
|
|
7
22
|
|
|
8
23
|
const createPermissionSchema = JOI.object({
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.6.
|
|
6
|
+
"version": "1.6.15",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,28 +19,28 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/certificate-manager": "1.6.
|
|
23
|
-
"@abtnode/constant": "1.6.
|
|
24
|
-
"@abtnode/cron": "1.6.
|
|
25
|
-
"@abtnode/db": "1.6.
|
|
26
|
-
"@abtnode/logger": "1.6.
|
|
27
|
-
"@abtnode/queue": "1.6.
|
|
28
|
-
"@abtnode/rbac": "1.6.
|
|
29
|
-
"@abtnode/router-provider": "1.6.
|
|
30
|
-
"@abtnode/static-server": "1.6.
|
|
31
|
-
"@abtnode/timemachine": "1.6.
|
|
32
|
-
"@abtnode/util": "1.6.
|
|
33
|
-
"@arcblock/did": "^1.13.
|
|
34
|
-
"@arcblock/event-hub": "1.13.
|
|
22
|
+
"@abtnode/certificate-manager": "1.6.15",
|
|
23
|
+
"@abtnode/constant": "1.6.15",
|
|
24
|
+
"@abtnode/cron": "1.6.15",
|
|
25
|
+
"@abtnode/db": "1.6.15",
|
|
26
|
+
"@abtnode/logger": "1.6.15",
|
|
27
|
+
"@abtnode/queue": "1.6.15",
|
|
28
|
+
"@abtnode/rbac": "1.6.15",
|
|
29
|
+
"@abtnode/router-provider": "1.6.15",
|
|
30
|
+
"@abtnode/static-server": "1.6.15",
|
|
31
|
+
"@abtnode/timemachine": "1.6.15",
|
|
32
|
+
"@abtnode/util": "1.6.15",
|
|
33
|
+
"@arcblock/did": "^1.13.84",
|
|
34
|
+
"@arcblock/event-hub": "1.13.84",
|
|
35
35
|
"@arcblock/pm2-events": "^0.0.5",
|
|
36
|
-
"@arcblock/vc": "^1.13.
|
|
37
|
-
"@blocklet/meta": "1.6.
|
|
36
|
+
"@arcblock/vc": "^1.13.84",
|
|
37
|
+
"@blocklet/meta": "1.6.15",
|
|
38
38
|
"@fidm/x509": "^1.2.1",
|
|
39
39
|
"@nedb/core": "^1.2.2",
|
|
40
40
|
"@nedb/multi": "^1.2.2",
|
|
41
|
-
"@ocap/mcrypto": "^1.13.
|
|
42
|
-
"@ocap/util": "^1.13.
|
|
43
|
-
"@ocap/wallet": "^1.13.
|
|
41
|
+
"@ocap/mcrypto": "^1.13.84",
|
|
42
|
+
"@ocap/util": "^1.13.84",
|
|
43
|
+
"@ocap/wallet": "^1.13.84",
|
|
44
44
|
"@slack/webhook": "^5.0.3",
|
|
45
45
|
"axios": "^0.21.4",
|
|
46
46
|
"axon": "^2.0.3",
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"express": "^4.17.1",
|
|
76
76
|
"jest": "^27.4.5"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "1b7b07da04387b1daa838b251a9388355009142d"
|
|
79
79
|
}
|