@abtnode/core 1.16.6-beta-9e9fec72 → 1.16.6-beta-7cbab489
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 +2 -16
- package/lib/blocklet/manager/helper/install-application-from-backup.js +9 -1
- package/lib/blocklet/manager/helper/install-application-from-dev.js +3 -3
- package/lib/router/helper.js +82 -107
- package/lib/states/blocklet-extras.js +3 -4
- package/lib/states/notification.js +1 -13
- package/lib/states/user.js +3 -3
- package/lib/util/blocklet.js +19 -16
- package/lib/validators/router.js +1 -0
- package/lib/validators/trusted-factory.js +1 -0
- package/package.json +18 -22
|
@@ -5,7 +5,6 @@ const path = require('path');
|
|
|
5
5
|
const flat = require('flat');
|
|
6
6
|
const get = require('lodash/get');
|
|
7
7
|
const omit = require('lodash/omit');
|
|
8
|
-
const uniq = require('lodash/uniq');
|
|
9
8
|
const merge = require('lodash/merge');
|
|
10
9
|
const pick = require('lodash/pick');
|
|
11
10
|
const cloneDeep = require('lodash/cloneDeep');
|
|
@@ -1010,7 +1009,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1010
1009
|
throw new Error('configs list is not an array');
|
|
1011
1010
|
}
|
|
1012
1011
|
|
|
1013
|
-
const tmpDids = Array.isArray(did) ?
|
|
1012
|
+
const tmpDids = Array.isArray(did) ? did : [did];
|
|
1014
1013
|
const [rootDid, ...childDids] = tmpDids;
|
|
1015
1014
|
const rootMetaDid = await states.blocklet.getBlockletMetaDid(rootDid);
|
|
1016
1015
|
const dids = [rootMetaDid, ...childDids];
|
|
@@ -1993,7 +1992,7 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
1993
1992
|
});
|
|
1994
1993
|
}
|
|
1995
1994
|
|
|
1996
|
-
if (blocklet
|
|
1995
|
+
if (blocklet?.controller?.nftId && process.env.NODE_ENV !== 'test') {
|
|
1997
1996
|
const nodeInfo = await states.node.read();
|
|
1998
1997
|
await consumeServerlessNFT({ nftId: blocklet.controller.nftId, nodeInfo, blocklet });
|
|
1999
1998
|
this.emit(BlockletEvents.nftConsumed, { blocklet, context });
|
|
@@ -2273,19 +2272,6 @@ class BlockletManager extends BaseBlockletManager {
|
|
|
2273
2272
|
fs.removeSync(cacheDir);
|
|
2274
2273
|
await this._cleanBlockletData({ blocklet, keepData, keepLogsDir, keepConfigs });
|
|
2275
2274
|
|
|
2276
|
-
if (blocklet.mode !== BLOCKLET_MODES.DEVELOPMENT) {
|
|
2277
|
-
const nodeInfo = await states.node.read();
|
|
2278
|
-
const { wallet } = getBlockletInfo(blocklet, nodeInfo.sk);
|
|
2279
|
-
didDocument
|
|
2280
|
-
.disableBlockletDNS({ appPid: blocklet.appPid, wallet, didRegistryUrl: nodeInfo.didRegistry })
|
|
2281
|
-
.then(() => {
|
|
2282
|
-
logger.info(`disabled blocklet ${blocklet.appPid} dns`);
|
|
2283
|
-
})
|
|
2284
|
-
.catch((err) => {
|
|
2285
|
-
logger.error(`disable blocklet ${blocklet.appPid} dns failed`, { error: err });
|
|
2286
|
-
});
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
2275
|
const result = await states.blocklet.deleteBlocklet(did);
|
|
2290
2276
|
logger.info('blocklet removed successfully', { did });
|
|
2291
2277
|
|
|
@@ -67,7 +67,15 @@ const installApplicationFromBackup = async ({
|
|
|
67
67
|
const { meta } = blockletState;
|
|
68
68
|
const { did, name: appName } = meta;
|
|
69
69
|
|
|
70
|
-
const extra = omit(fs.readJSONSync(path.join(dir, 'blocklet-extras.json')), [
|
|
70
|
+
const extra = omit(fs.readJSONSync(path.join(dir, 'blocklet-extras.json')), [
|
|
71
|
+
'_id',
|
|
72
|
+
'createdAt',
|
|
73
|
+
'updatedAt',
|
|
74
|
+
'controller.nftId',
|
|
75
|
+
'controller.nftOwner',
|
|
76
|
+
'controller.chainHost',
|
|
77
|
+
'controller.appMaxCount',
|
|
78
|
+
]);
|
|
71
79
|
|
|
72
80
|
if (blockletState.meta.did !== extra.did) {
|
|
73
81
|
throw new Error(
|
|
@@ -12,7 +12,7 @@ const { ensureMeta, updateBlockletFallbackLogo, ensureAppLogo } = require('../..
|
|
|
12
12
|
* @returns
|
|
13
13
|
*/
|
|
14
14
|
const installApplicationFromDev = async ({ folder, meta, states, manager } = {}) => {
|
|
15
|
-
const {
|
|
15
|
+
const { version, name, did } = meta;
|
|
16
16
|
|
|
17
17
|
const exist = await states.blocklet.getBlocklet(did);
|
|
18
18
|
if (exist) {
|
|
@@ -53,8 +53,8 @@ const installApplicationFromDev = async ({ folder, meta, states, manager } = {})
|
|
|
53
53
|
// create app
|
|
54
54
|
const added = await manager._addBlocklet({
|
|
55
55
|
component,
|
|
56
|
-
name
|
|
57
|
-
did
|
|
56
|
+
name,
|
|
57
|
+
did,
|
|
58
58
|
mode: BLOCKLET_MODES.DEVELOPMENT,
|
|
59
59
|
});
|
|
60
60
|
logger.info('add blocklet for dev', { did, version, meta });
|
package/lib/router/helper.js
CHANGED
|
@@ -16,7 +16,7 @@ const getTmpDir = require('@abtnode/util/lib/get-tmp-directory');
|
|
|
16
16
|
const downloadFile = require('@abtnode/util/lib/download-file');
|
|
17
17
|
const { updateBlockletDocument } = require('@abtnode/util/lib/did-document');
|
|
18
18
|
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
19
|
-
const {
|
|
19
|
+
const { forEachBlockletSync } = require('@blocklet/meta/lib/util');
|
|
20
20
|
const {
|
|
21
21
|
DOMAIN_FOR_DEFAULT_SITE,
|
|
22
22
|
DOMAIN_FOR_IP_SITE_REGEXP,
|
|
@@ -71,6 +71,8 @@ const { getBlockletKnownAs, getBlockletDidDomainList } = require('../util/blockl
|
|
|
71
71
|
|
|
72
72
|
const isServiceFeDevelopment = process.env.ABT_NODE_SERVICE_FE_PORT;
|
|
73
73
|
|
|
74
|
+
const hasRuleByPrefix = (site, value) => site.rules.find((x) => x.isProtected && get(x, 'from.pathPrefix') === value);
|
|
75
|
+
|
|
74
76
|
/**
|
|
75
77
|
* replace 888-888-888-888 with accessible ip for domain
|
|
76
78
|
*/
|
|
@@ -399,6 +401,79 @@ const filterSitesForRemovedBlocklets = async (sites = [], blocklets) => {
|
|
|
399
401
|
});
|
|
400
402
|
};
|
|
401
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Add system routing rules for blocklet in wellknown site
|
|
406
|
+
*
|
|
407
|
+
* @returns {boolean} if routing changed
|
|
408
|
+
*/
|
|
409
|
+
const ensureBlockletWellknownRules = async (sites, blocklets) => {
|
|
410
|
+
/**
|
|
411
|
+
* 1. component blocklet 不允许有相同多的 wellknown
|
|
412
|
+
* 1. wellknown 可以访问的路由:
|
|
413
|
+
* /.well-known/xxx
|
|
414
|
+
* /{wellknown owner blocklet}/.well-known/xxx
|
|
415
|
+
*/
|
|
416
|
+
const isWellknownInterface = (x) => x.type === BLOCKLET_INTERFACE_TYPE_WELLKNOWN;
|
|
417
|
+
|
|
418
|
+
const handler = ({ rules, site, blocklet, tmpInterface, mountPoint }) => {
|
|
419
|
+
let pathPrefix = normalizePathPrefix(tmpInterface.prefix);
|
|
420
|
+
if (!pathPrefix.startsWith(WELLKNOWN_PATH_PREFIX)) {
|
|
421
|
+
throw new Error(`Wellknown path prefix must start with: ${WELLKNOWN_PATH_PREFIX}`);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
const tmpMountPoint = mountPoint || blocklet.mountPoint;
|
|
425
|
+
if (tmpMountPoint) {
|
|
426
|
+
pathPrefix = joinUrl(tmpMountPoint, pathPrefix);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const port = findInterfacePortByName(blocklet, tmpInterface.name);
|
|
430
|
+
const existedRule = hasRuleByPrefix(site, pathPrefix);
|
|
431
|
+
if (existedRule) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
rules.push({
|
|
436
|
+
from: { pathPrefix },
|
|
437
|
+
to: {
|
|
438
|
+
did: blocklet.meta.did,
|
|
439
|
+
port,
|
|
440
|
+
targetPrefix: tmpMountPoint,
|
|
441
|
+
type: ROUTING_RULE_TYPES.GENERAL_PROXY,
|
|
442
|
+
interfaceName: tmpInterface.name,
|
|
443
|
+
},
|
|
444
|
+
isProtected: true,
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
return sites
|
|
449
|
+
.map((site) => {
|
|
450
|
+
if (!site.domain.endsWith(BLOCKLET_SITE_GROUP_SUFFIX)) {
|
|
451
|
+
return site;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const blocklet = blocklets.find((x) => x.meta.did === site.blockletDid);
|
|
455
|
+
|
|
456
|
+
const rules = [];
|
|
457
|
+
|
|
458
|
+
forEachBlockletSync(blocklet, (b) => {
|
|
459
|
+
(b.meta.interfaces || []).forEach((item) => {
|
|
460
|
+
if (isWellknownInterface(item)) {
|
|
461
|
+
handler({ rules, blocklet: b, tmpInterface: item, site });
|
|
462
|
+
|
|
463
|
+
// 在站点的根路由下挂载一个
|
|
464
|
+
if (b.mountPoint && b.mountPoint !== '/') {
|
|
465
|
+
handler({ rules, blocklet: b, tmpInterface: item, site, mountPoint: '/' });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
site.rules = site.rules.concat(rules);
|
|
472
|
+
return site;
|
|
473
|
+
})
|
|
474
|
+
.filter(Boolean);
|
|
475
|
+
};
|
|
476
|
+
|
|
402
477
|
const ensureBlockletCache = async (sites = [], blocklets) => {
|
|
403
478
|
return sites
|
|
404
479
|
.map((site) => {
|
|
@@ -456,6 +531,7 @@ const ensureLatestInfo = async (sites = [], { withDefaultCors = true } = {}) =>
|
|
|
456
531
|
let result = await ensureLatestNodeInfo(sites, { withDefaultCors });
|
|
457
532
|
result = await ensureBlockletDid(result);
|
|
458
533
|
result = await filterSitesForRemovedBlocklets(sites, blocklets);
|
|
534
|
+
result = await ensureBlockletWellknownRules(result, blocklets);
|
|
459
535
|
result = await ensureBlockletCache(result, blocklets);
|
|
460
536
|
result = await ensureWellknownRule(result);
|
|
461
537
|
result = await ensureCorsForWebWallet(result);
|
|
@@ -485,7 +561,6 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
485
561
|
const notification = states.notification;
|
|
486
562
|
|
|
487
563
|
// site level duplication detection
|
|
488
|
-
const hasRuleByPrefix = (site, value) => site.rules.find((x) => x.isProtected && get(x, 'from.pathPrefix') === value);
|
|
489
564
|
|
|
490
565
|
const downloadCert = async ({ domain, url }) => {
|
|
491
566
|
const destFolder = getTmpDir(path.join(`certificate-${Date.now()}`));
|
|
@@ -794,7 +869,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
794
869
|
*
|
|
795
870
|
* @returns {boolean} if routing state db changed
|
|
796
871
|
*/
|
|
797
|
-
const _ensureBlockletSites = async (blocklet,
|
|
872
|
+
const _ensureBlockletSites = async (blocklet, nodeInfo, context = {}) => {
|
|
798
873
|
const webInterface = (blocklet.meta.interfaces || []).find((x) => x.type === BLOCKLET_INTERFACE_TYPE_WEB);
|
|
799
874
|
if (!webInterface) {
|
|
800
875
|
return false;
|
|
@@ -884,97 +959,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
884
959
|
return true;
|
|
885
960
|
};
|
|
886
961
|
|
|
887
|
-
|
|
888
|
-
* Add system routing rules for blocklet in wellknown site
|
|
889
|
-
*
|
|
890
|
-
* @returns {boolean} if routing changed
|
|
891
|
-
*/
|
|
892
|
-
const _ensureBlockletRulesForWellknownSite = async (blocklet, sites, context = {}) => {
|
|
893
|
-
const wellknownSite = sites.find((x) => x.name === NAME_FOR_WELLKNOWN_SITE);
|
|
894
|
-
if (!wellknownSite) {
|
|
895
|
-
return false;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
/**
|
|
899
|
-
* 1. component blocklet 不允许有相同多的 wellknown
|
|
900
|
-
* 1. wellknown 可以访问的路由:
|
|
901
|
-
* /.well-known/xxx
|
|
902
|
-
* /{wellknown owner blocklet}/.well-known/xxx
|
|
903
|
-
*/
|
|
904
|
-
|
|
905
|
-
const isWellknownInterface = (x) => x.type === BLOCKLET_INTERFACE_TYPE_WELLKNOWN;
|
|
906
|
-
|
|
907
|
-
const handler = async (tmpBlocklet, tmpInterface, mountPoint) => {
|
|
908
|
-
let pathPrefix = normalizePathPrefix(tmpInterface.prefix);
|
|
909
|
-
if (!pathPrefix.startsWith(WELLKNOWN_PATH_PREFIX)) {
|
|
910
|
-
throw new Error(`Wellknown path prefix must start with: ${WELLKNOWN_PATH_PREFIX}`);
|
|
911
|
-
}
|
|
912
|
-
|
|
913
|
-
const tmpMountPoint = mountPoint || tmpBlocklet.mountPoint;
|
|
914
|
-
if (tmpMountPoint) {
|
|
915
|
-
pathPrefix = joinUrl(tmpMountPoint, pathPrefix);
|
|
916
|
-
}
|
|
917
|
-
|
|
918
|
-
const port = findInterfacePortByName(tmpBlocklet, tmpInterface.name);
|
|
919
|
-
const existedRule = hasRuleByPrefix(wellknownSite, pathPrefix);
|
|
920
|
-
|
|
921
|
-
const rule = {
|
|
922
|
-
from: { pathPrefix },
|
|
923
|
-
to: {
|
|
924
|
-
did: tmpBlocklet.meta.did,
|
|
925
|
-
port,
|
|
926
|
-
type: ROUTING_RULE_TYPES.GENERAL_PROXY,
|
|
927
|
-
interfaceName: tmpInterface.name,
|
|
928
|
-
},
|
|
929
|
-
isProtected: true,
|
|
930
|
-
};
|
|
931
|
-
|
|
932
|
-
if (!existedRule) {
|
|
933
|
-
await routerManager.addRoutingRule(
|
|
934
|
-
{ id: wellknownSite.id, rule, skipCheckDynamicBlacklist: true, formatPathPrefix: false },
|
|
935
|
-
context
|
|
936
|
-
);
|
|
937
|
-
return true;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
// 兼容代码,旧的 rule 没有 to.did 字段
|
|
941
|
-
if (port !== existedRule.to.port || existedRule.to.did !== tmpBlocklet.meta.did) {
|
|
942
|
-
existedRule.to = rule.to;
|
|
943
|
-
|
|
944
|
-
await routerManager.updateRoutingRule(
|
|
945
|
-
{ id: wellknownSite.id, rule: existedRule, skipProtectedRuleChecking: true, formatPathPrefix: false },
|
|
946
|
-
context
|
|
947
|
-
);
|
|
948
|
-
|
|
949
|
-
return true;
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
return false;
|
|
953
|
-
};
|
|
954
|
-
|
|
955
|
-
const tasks = [];
|
|
956
|
-
|
|
957
|
-
forEachBlocklet(
|
|
958
|
-
blocklet,
|
|
959
|
-
(b) => {
|
|
960
|
-
(b.meta.interfaces || []).forEach((item) => {
|
|
961
|
-
if (isWellknownInterface(item)) {
|
|
962
|
-
tasks.push(handler(b, item));
|
|
963
|
-
|
|
964
|
-
if (!b.mountPoint || b.mountPoint !== '/') {
|
|
965
|
-
tasks.push(handler(b, item, '/')); // 在站点的根路由下挂载一个
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
|
-
},
|
|
970
|
-
{ sync: true }
|
|
971
|
-
);
|
|
972
|
-
|
|
973
|
-
const changes = await Promise.all(tasks);
|
|
974
|
-
return changes.some(Boolean);
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
const _removeBlockletSites = async (blocklet, nodeInfo, context = {}) => {
|
|
962
|
+
const _removeBlockletSites = async (blocklet, context = {}) => {
|
|
978
963
|
let changed = false;
|
|
979
964
|
|
|
980
965
|
const site = await states.site.findOne({ domain: `${blocklet.meta.did}${BLOCKLET_SITE_GROUP_SUFFIX}` });
|
|
@@ -1002,16 +987,7 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
1002
987
|
return false;
|
|
1003
988
|
}
|
|
1004
989
|
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
const tasks = [
|
|
1008
|
-
_ensureBlockletRulesForWellknownSite(blocklet, sites, context),
|
|
1009
|
-
_ensureBlockletSites(blocklet, sites, nodeInfo, context),
|
|
1010
|
-
];
|
|
1011
|
-
|
|
1012
|
-
const changes = await Promise.all(tasks);
|
|
1013
|
-
|
|
1014
|
-
return changes.some(Boolean);
|
|
990
|
+
return _ensureBlockletSites(blocklet, nodeInfo, context);
|
|
1015
991
|
};
|
|
1016
992
|
|
|
1017
993
|
/**
|
|
@@ -1105,12 +1081,10 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
|
|
|
1105
1081
|
* @returns {boolean} if routing changed
|
|
1106
1082
|
*/
|
|
1107
1083
|
const removeBlockletRouting = async (blocklet, context = {}) => {
|
|
1108
|
-
const nodeInfo = await nodeState.read();
|
|
1109
|
-
|
|
1110
1084
|
const ruleChanged = await routerManager.deleteRoutingRulesItemByDid({ did: blocklet.meta.did }, context);
|
|
1111
1085
|
let siteChanged;
|
|
1112
1086
|
if (!context.keepRouting) {
|
|
1113
|
-
siteChanged = await _removeBlockletSites(blocklet,
|
|
1087
|
+
siteChanged = await _removeBlockletSites(blocklet, context);
|
|
1114
1088
|
}
|
|
1115
1089
|
|
|
1116
1090
|
return ruleChanged || siteChanged;
|
|
@@ -1468,3 +1442,4 @@ module.exports.ensureLatestNodeInfo = ensureLatestNodeInfo;
|
|
|
1468
1442
|
module.exports.ensureLatestInterfaceInfo = ensureLatestInterfaceInfo;
|
|
1469
1443
|
module.exports.ensureLatestInfo = ensureLatestInfo;
|
|
1470
1444
|
module.exports.ensureWellknownRule = ensureWellknownRule;
|
|
1445
|
+
module.exports.ensureBlockletWellknownRules = ensureBlockletWellknownRules;
|
|
@@ -5,7 +5,6 @@ const logger = require('@abtnode/logger')('state-blocklet-extras');
|
|
|
5
5
|
const { EXPIRED_BLOCKLET_DATA_RETENTION_DAYS } = require('@abtnode/constant');
|
|
6
6
|
const camelCase = require('lodash/camelCase');
|
|
7
7
|
const get = require('lodash/get');
|
|
8
|
-
const uniq = require('lodash/uniq');
|
|
9
8
|
const dayjs = require('dayjs');
|
|
10
9
|
|
|
11
10
|
const BaseState = require('./base');
|
|
@@ -129,7 +128,7 @@ class BlockletExtrasState extends BaseState {
|
|
|
129
128
|
generateGetFn(extra) {
|
|
130
129
|
return async (dids, path, defaultValue) => {
|
|
131
130
|
// eslint-disable-next-line no-param-reassign
|
|
132
|
-
dids =
|
|
131
|
+
dids = [].concat(dids);
|
|
133
132
|
const [rootDid, ...childDids] = dids;
|
|
134
133
|
const { dek } = this.config;
|
|
135
134
|
const { name, afterGet = noop('data') } = extra;
|
|
@@ -152,7 +151,7 @@ class BlockletExtrasState extends BaseState {
|
|
|
152
151
|
generateSetFn(extra) {
|
|
153
152
|
return async (dids, data) => {
|
|
154
153
|
// eslint-disable-next-line no-param-reassign
|
|
155
|
-
dids =
|
|
154
|
+
dids = [].concat(dids);
|
|
156
155
|
const [rootDid, ...childDids] = dids;
|
|
157
156
|
const { dek } = this.config;
|
|
158
157
|
const { name, beforeSet = noop('cur') } = extra;
|
|
@@ -192,7 +191,7 @@ class BlockletExtrasState extends BaseState {
|
|
|
192
191
|
generateDelFn(extra) {
|
|
193
192
|
return async (dids) => {
|
|
194
193
|
// eslint-disable-next-line no-param-reassign
|
|
195
|
-
dids =
|
|
194
|
+
dids = [].concat(dids);
|
|
196
195
|
const [rootDid, ...childDids] = dids;
|
|
197
196
|
const { name } = extra;
|
|
198
197
|
const item = await this.findOne({ did: rootDid });
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const get = require('lodash/get');
|
|
2
1
|
const logger = require('@abtnode/logger')('@abtnode/core:states:notification');
|
|
3
2
|
const { EVENTS } = require('@abtnode/constant');
|
|
4
3
|
|
|
@@ -54,23 +53,12 @@ class NotificationState extends BaseState {
|
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
55
|
|
|
57
|
-
async findPaginated({
|
|
56
|
+
async findPaginated({ read, paging } = {}) {
|
|
58
57
|
const conditions = {};
|
|
59
|
-
// eslint-disable-next-line no-param-reassign
|
|
60
|
-
receiver = receiver || get(context, 'user.did');
|
|
61
|
-
if (!receiver && !sender) {
|
|
62
|
-
throw new Error('Receiver or sender is required to find notifications');
|
|
63
|
-
}
|
|
64
58
|
|
|
65
59
|
if (typeof read === 'boolean') {
|
|
66
60
|
conditions.read = read;
|
|
67
61
|
}
|
|
68
|
-
if (sender) {
|
|
69
|
-
conditions.sender = sender;
|
|
70
|
-
}
|
|
71
|
-
if (receiver) {
|
|
72
|
-
conditions.receiver = receiver;
|
|
73
|
-
}
|
|
74
62
|
|
|
75
63
|
return this.paginate(conditions, { createdAt: -1 }, { ...paging, pageSize: 10 });
|
|
76
64
|
}
|
package/lib/states/user.js
CHANGED
|
@@ -438,9 +438,9 @@ class User extends BaseState {
|
|
|
438
438
|
* @param {string} did user's did
|
|
439
439
|
* @returns {BlockletUser}
|
|
440
440
|
*/
|
|
441
|
-
async getUser(did, {
|
|
441
|
+
async getUser(did, { enableConnectedAccount = false, enableNormalize = false, blockletSk } = {}) {
|
|
442
442
|
let user = await this.findOne({ did });
|
|
443
|
-
if (
|
|
443
|
+
if (enableConnectedAccount) {
|
|
444
444
|
if (!user) {
|
|
445
445
|
user = await this.findOne({
|
|
446
446
|
'extraConfigs.connectedAccounts.did': did,
|
|
@@ -513,7 +513,7 @@ class User extends BaseState {
|
|
|
513
513
|
let action = '';
|
|
514
514
|
const now = new Date().toISOString();
|
|
515
515
|
const oldUser = await this.getUser(user.did, {
|
|
516
|
-
|
|
516
|
+
enableConnectedAccount: true,
|
|
517
517
|
});
|
|
518
518
|
const cloneData = cloneDeep(user);
|
|
519
519
|
const passports = upsertToPassports(
|
package/lib/util/blocklet.js
CHANGED
|
@@ -28,6 +28,8 @@ const { isValid: isValidDid, isEthereumDid } = require('@arcblock/did');
|
|
|
28
28
|
const logger = require('@abtnode/logger')('@abtnode/core:util:blocklet');
|
|
29
29
|
const pm2 = require('@abtnode/util/lib/async-pm2');
|
|
30
30
|
const sleep = require('@abtnode/util/lib/sleep');
|
|
31
|
+
const getPm2ProcessInfo = require('@abtnode/util/lib/get-pm2-process-info');
|
|
32
|
+
const killProcessOccupiedPorts = require('@abtnode/util/lib/kill-process-occupied-ports');
|
|
31
33
|
const getNodeWallet = require('@abtnode/util/lib/get-app-wallet');
|
|
32
34
|
const { formatEnv } = require('@abtnode/util/lib/security');
|
|
33
35
|
const ensureEndpointHealthy = require('@abtnode/util/lib/ensure-endpoint-healthy');
|
|
@@ -526,6 +528,14 @@ const startBlockletProcess = async (
|
|
|
526
528
|
// run hook
|
|
527
529
|
await preStart(b, { env });
|
|
528
530
|
|
|
531
|
+
// kill process if port is occupied
|
|
532
|
+
try {
|
|
533
|
+
const { ports } = b;
|
|
534
|
+
await killProcessOccupiedPorts({ ports, pm2ProcessId: processId, printError: logger.error.bind(logger) });
|
|
535
|
+
} catch (error) {
|
|
536
|
+
logger.error('Failed to killProcessOccupiedPorts', { error });
|
|
537
|
+
}
|
|
538
|
+
|
|
529
539
|
// start process
|
|
530
540
|
const maxMemoryRestart = get(nodeInfo, 'runtimeConfig.blockletMaxMemoryLimit', BLOCKLET_MAX_MEM_LIMIT_IN_MB);
|
|
531
541
|
|
|
@@ -720,21 +730,8 @@ const getProcessState = async (processId) => {
|
|
|
720
730
|
return statusMap[info.pm2_env.status];
|
|
721
731
|
};
|
|
722
732
|
|
|
723
|
-
const getProcessInfo = (processId) =>
|
|
724
|
-
|
|
725
|
-
pm2.describe(processId, async (err, [info]) => {
|
|
726
|
-
if (err) {
|
|
727
|
-
logger.error('Failed to get blocklet status from pm2', { error: err });
|
|
728
|
-
return reject(err);
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
if (!info) {
|
|
732
|
-
return reject(new CustomError('BLOCKLET_PROCESS_404', 'Blocklet process info is not available'));
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
return resolve(info);
|
|
736
|
-
});
|
|
737
|
-
});
|
|
733
|
+
const getProcessInfo = (processId, { throwOnNotExist = true } = {}) =>
|
|
734
|
+
getPm2ProcessInfo(processId, { printError: logger.error.bind(logger), throwOnNotExist });
|
|
738
735
|
|
|
739
736
|
const deleteProcess = (processId) =>
|
|
740
737
|
new Promise((resolve, reject) => {
|
|
@@ -1407,7 +1404,13 @@ const getBlocklet = async ({
|
|
|
1407
1404
|
// app settings
|
|
1408
1405
|
const settings = await states.blockletExtras.getSettings(blocklet.meta.did);
|
|
1409
1406
|
blocklet.trustedPassports = get(settings, 'trustedPassports') || [];
|
|
1410
|
-
blocklet.trustedFactories = get(settings, 'trustedFactories') || []
|
|
1407
|
+
blocklet.trustedFactories = (get(settings, 'trustedFactories') || []).map((x) => {
|
|
1408
|
+
if (!x.passport.ttlPolicy) {
|
|
1409
|
+
x.passport.ttlPolicy = 'never';
|
|
1410
|
+
x.passport.ttl = 0;
|
|
1411
|
+
}
|
|
1412
|
+
return x;
|
|
1413
|
+
});
|
|
1411
1414
|
blocklet.enablePassportIssuance = get(settings, 'enablePassportIssuance', true);
|
|
1412
1415
|
blocklet.settings = settings || {};
|
|
1413
1416
|
|
package/lib/validators/router.js
CHANGED
|
@@ -70,6 +70,7 @@ const ruleSchema = {
|
|
|
70
70
|
.valid(...Object.keys(ROUTER_CACHE_GROUPS))
|
|
71
71
|
.allow('')
|
|
72
72
|
.default(''),
|
|
73
|
+
targetPrefix: Joi.string().trim().max(150), // path prefix of interface of target blocklet
|
|
73
74
|
},
|
|
74
75
|
|
|
75
76
|
// List of services that manipulate the request before the upstream blocklet
|
|
@@ -14,6 +14,7 @@ const trustedFactoriesSchema = Joi.array()
|
|
|
14
14
|
remark: Joi.string().trim().required(),
|
|
15
15
|
passport: Joi.object({
|
|
16
16
|
role: Joi.string().required(),
|
|
17
|
+
ttlPolicy: Joi.string().valid('never', 'mint', 'exchange').required(),
|
|
17
18
|
ttl: Joi.number().integer().min(0).default(0),
|
|
18
19
|
}).required(),
|
|
19
20
|
})
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.6-beta-
|
|
6
|
+
"version": "1.16.6-beta-7cbab489",
|
|
7
7
|
"description": "",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -19,18 +19,18 @@
|
|
|
19
19
|
"author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@abtnode/auth": "1.16.6-beta-
|
|
23
|
-
"@abtnode/certificate-manager": "1.16.6-beta-
|
|
24
|
-
"@abtnode/constant": "1.16.6-beta-
|
|
25
|
-
"@abtnode/cron": "1.16.6-beta-
|
|
26
|
-
"@abtnode/db": "1.16.6-beta-
|
|
27
|
-
"@abtnode/logger": "1.16.6-beta-
|
|
28
|
-
"@abtnode/queue": "1.16.6-beta-
|
|
29
|
-
"@abtnode/rbac": "1.16.6-beta-
|
|
30
|
-
"@abtnode/router-provider": "1.16.6-beta-
|
|
31
|
-
"@abtnode/static-server": "1.16.6-beta-
|
|
32
|
-
"@abtnode/timemachine": "1.16.6-beta-
|
|
33
|
-
"@abtnode/util": "1.16.6-beta-
|
|
22
|
+
"@abtnode/auth": "1.16.6-beta-7cbab489",
|
|
23
|
+
"@abtnode/certificate-manager": "1.16.6-beta-7cbab489",
|
|
24
|
+
"@abtnode/constant": "1.16.6-beta-7cbab489",
|
|
25
|
+
"@abtnode/cron": "1.16.6-beta-7cbab489",
|
|
26
|
+
"@abtnode/db": "1.16.6-beta-7cbab489",
|
|
27
|
+
"@abtnode/logger": "1.16.6-beta-7cbab489",
|
|
28
|
+
"@abtnode/queue": "1.16.6-beta-7cbab489",
|
|
29
|
+
"@abtnode/rbac": "1.16.6-beta-7cbab489",
|
|
30
|
+
"@abtnode/router-provider": "1.16.6-beta-7cbab489",
|
|
31
|
+
"@abtnode/static-server": "1.16.6-beta-7cbab489",
|
|
32
|
+
"@abtnode/timemachine": "1.16.6-beta-7cbab489",
|
|
33
|
+
"@abtnode/util": "1.16.6-beta-7cbab489",
|
|
34
34
|
"@arcblock/did": "1.18.75",
|
|
35
35
|
"@arcblock/did-auth": "1.18.75",
|
|
36
36
|
"@arcblock/did-ext": "^1.18.75",
|
|
@@ -40,12 +40,11 @@
|
|
|
40
40
|
"@arcblock/jwt": "^1.18.75",
|
|
41
41
|
"@arcblock/pm2-events": "^0.0.5",
|
|
42
42
|
"@arcblock/vc": "1.18.75",
|
|
43
|
-
"@blocklet/constant": "1.16.6-beta-
|
|
44
|
-
"@blocklet/meta": "1.16.6-beta-
|
|
45
|
-
"@blocklet/sdk": "1.16.6-beta-
|
|
46
|
-
"@did-space/client": "^0.2.
|
|
43
|
+
"@blocklet/constant": "1.16.6-beta-7cbab489",
|
|
44
|
+
"@blocklet/meta": "1.16.6-beta-7cbab489",
|
|
45
|
+
"@blocklet/sdk": "1.16.6-beta-7cbab489",
|
|
46
|
+
"@did-space/client": "^0.2.83",
|
|
47
47
|
"@fidm/x509": "^1.2.1",
|
|
48
|
-
"@ocap/client": "1.18.75",
|
|
49
48
|
"@ocap/mcrypto": "1.18.75",
|
|
50
49
|
"@ocap/util": "1.18.75",
|
|
51
50
|
"@ocap/wallet": "1.18.75",
|
|
@@ -66,18 +65,15 @@
|
|
|
66
65
|
"get-port": "^5.1.1",
|
|
67
66
|
"hasha": "^5.2.2",
|
|
68
67
|
"is-base64": "^1.1.0",
|
|
69
|
-
"is-ip": "^3.1.0",
|
|
70
68
|
"is-url": "^1.2.4",
|
|
71
69
|
"joi": "17.7.0",
|
|
72
70
|
"js-yaml": "^4.1.0",
|
|
73
71
|
"kill-port": "^2.0.1",
|
|
74
72
|
"lodash": "^4.17.21",
|
|
75
|
-
"lru-cache": "^6.0.0",
|
|
76
73
|
"moment-timezone": "^0.5.37",
|
|
77
74
|
"node-stream-zip": "^1.15.0",
|
|
78
75
|
"p-limit": "^3.1.0",
|
|
79
76
|
"p-retry": "4.6.1",
|
|
80
|
-
"pm2": "^5.2.0",
|
|
81
77
|
"semver": "^7.3.8",
|
|
82
78
|
"shelljs": "^0.8.5",
|
|
83
79
|
"ssri": "^8.0.1",
|
|
@@ -98,5 +94,5 @@
|
|
|
98
94
|
"express": "^4.18.2",
|
|
99
95
|
"jest": "^27.5.1"
|
|
100
96
|
},
|
|
101
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "36b58c0651762472ac34ad880965c47510eb9768"
|
|
102
98
|
}
|