@abtnode/core 1.8.68-beta-500af7e5 → 1.8.68

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.
@@ -28,7 +28,6 @@ const lock = new Lock('blocklet-port-assign-lock');
28
28
 
29
29
  const isHex = (str) => /^0x[0-9a-f]+$/i.test(str);
30
30
  const getMaxPort = (ports = {}) => Math.max(Object.values(ports).map(Number));
31
- const getConditions = (did) => [{ 'meta.did': did }, { appDid: did }, { appPid: did }];
32
31
 
33
32
  const getExternalPortsFromMeta = (meta) =>
34
33
  (meta.interfaces || []).map((x) => x.port && x.port.external).filter(Boolean);
@@ -49,16 +48,7 @@ const formatBlocklet = (blocklet, phase, dek) => {
49
48
  return;
50
49
  }
51
50
 
52
- (b.migratedFrom || []).forEach((x) => {
53
- if (phase === 'onUpdate' && isHex(x.appSk) === true) {
54
- x.appSk = security.encrypt(x.appSk, b.meta.did, dek);
55
- }
56
- if (phase === 'onRead' && isHex(x.appSk) === false) {
57
- x.appSk = security.decrypt(x.appSk, b.meta.did, dek);
58
- }
59
- });
60
-
61
- ['BLOCKLET_APP_SK', 'BLOCKLET_APP_PSK'].forEach((key) => {
51
+ ['BLOCKLET_APP_SK'].forEach((key) => {
62
52
  const env = b.environments.find((x) => x.key === key);
63
53
  if (!env) {
64
54
  return;
@@ -108,7 +98,7 @@ class BlockletState extends BaseState {
108
98
  resolve(null);
109
99
  }
110
100
 
111
- this.findOne({ $or: getConditions(did) }, (err, doc) => {
101
+ this.findOne({ $or: [{ 'meta.did': did }, { appDid: did }] }, (err, doc) => {
112
102
  if (err) {
113
103
  return reject(err);
114
104
  }
@@ -124,7 +114,7 @@ class BlockletState extends BaseState {
124
114
  resolve(null);
125
115
  }
126
116
 
127
- this.findOne({ $or: getConditions(did) }, (err, doc) => {
117
+ this.findOne({ $or: [{ 'meta.did': did }, { appDid: did }] }, (err, doc) => {
128
118
  if (err) {
129
119
  return reject(err);
130
120
  }
@@ -140,7 +130,7 @@ class BlockletState extends BaseState {
140
130
  resolve(null);
141
131
  }
142
132
 
143
- this.findOne({ $or: getConditions(did) }, { status: 1 }, (err, doc) => {
133
+ this.findOne({ $or: [{ 'meta.did': did }, { appDid: did }] }, { status: 1 }, (err, doc) => {
144
134
  if (err) {
145
135
  return reject(err);
146
136
  }
@@ -156,7 +146,7 @@ class BlockletState extends BaseState {
156
146
  resolve(false);
157
147
  }
158
148
 
159
- this.count({ $or: getConditions(did) }, (err, count) => {
149
+ this.count({ $or: [{ 'meta.did': did }, { appDid: did }] }, (err, count) => {
160
150
  if (err) {
161
151
  return reject(err);
162
152
  }
@@ -209,9 +199,6 @@ class BlockletState extends BaseState {
209
199
  deployedFrom = '',
210
200
  mode = BLOCKLET_MODES.PRODUCTION,
211
201
  children: rawChildren = [],
212
- appPid = null, // the permanent appDid, which will not change after initial set
213
- migratedFrom = [], // the complete migrate history
214
- externalSk = false, // whether sk is managed by some party beside server, such as did-wallet
215
202
  } = {}) {
216
203
  return this.getBlocklet(meta.did).then(
217
204
  (exist) =>
@@ -242,7 +229,6 @@ class BlockletState extends BaseState {
242
229
 
243
230
  const data = {
244
231
  appDid: null, // will updated later when updating blocklet environments
245
- appPid,
246
232
  mode,
247
233
  meta: sanitized,
248
234
  status,
@@ -251,8 +237,6 @@ class BlockletState extends BaseState {
251
237
  ports,
252
238
  environments: [],
253
239
  children,
254
- migratedFrom,
255
- externalSk,
256
240
  };
257
241
 
258
242
  // add to db
@@ -124,7 +124,7 @@ class NodeState extends BaseState {
124
124
  routing,
125
125
  docker,
126
126
  mode,
127
- enableWelcomePage: mode !== NODE_MODES.SERVERLESS,
127
+ enableWelcomePage: true,
128
128
  runtimeConfig,
129
129
  ownerNft,
130
130
  diskAlertThreshold: DISK_ALERT_THRESHOLD_PERCENT,
@@ -310,10 +310,7 @@ class NodeState extends BaseState {
310
310
  }
311
311
 
312
312
  async updateGateway(gateway) {
313
- const [, nodeInfo] = await this.update(
314
- {},
315
- { $set: { 'routing.requestLimit': gateway.requestLimit, 'routing.cacheEnabled': gateway.cacheEnabled } }
316
- );
313
+ const [, nodeInfo] = await this.update({}, { $set: { 'routing.requestLimit': gateway.requestLimit } });
317
314
 
318
315
  this.emit(EVENTS.RELOAD_GATEWAY, nodeInfo);
319
316
 
@@ -31,12 +31,7 @@ const getFolderSize = require('@abtnode/util/lib/get-folder-size');
31
31
  const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
32
32
  const hashFiles = require('@abtnode/util/lib/hash-files');
33
33
  const isPathPrefixEqual = require('@abtnode/util/lib/is-path-prefix-equal');
34
- const {
35
- BLOCKLET_MAX_MEM_LIMIT_IN_MB,
36
- BLOCKLET_STORE,
37
- BLOCKLET_INSTALL_TYPE,
38
- BLOCKLET_STORE_DEV,
39
- } = require('@abtnode/constant');
34
+ const { BLOCKLET_MAX_MEM_LIMIT_IN_MB, BLOCKLET_STORE, BLOCKLET_INSTALL_TYPE } = require('@abtnode/constant');
40
35
  const formatBackSlash = require('@abtnode/util/lib/format-back-slash');
41
36
 
42
37
  const SCRIPT_ENGINES_WHITE_LIST = ['npm', 'npx', 'pnpm', 'yarn'];
@@ -94,7 +89,6 @@ const {
94
89
  validateBlockletMeta,
95
90
  prettyURL,
96
91
  getNFTState,
97
- templateReplace,
98
92
  } = require('./index');
99
93
 
100
94
  const getComponentConfig = (meta) => meta.components || meta.children;
@@ -241,12 +235,12 @@ const getComponentDirs = (
241
235
  const fillBlockletConfigs = (blocklet, configs) => {
242
236
  blocklet.configs = configs || [];
243
237
  blocklet.configObj = blocklet.configs.reduce((acc, x) => {
244
- acc[x.key] = templateReplace(x.value, blocklet);
238
+ acc[x.key] = x.value;
245
239
  return acc;
246
240
  }, {});
247
241
  blocklet.environments = blocklet.environments || [];
248
242
  blocklet.environmentObj = blocklet.environments.reduce((acc, x) => {
249
- acc[x.key] = templateReplace(x.value, blocklet);
243
+ acc[x.key] = x.value;
250
244
  return acc;
251
245
  }, {});
252
246
  };
@@ -305,16 +299,10 @@ const getAppSystemEnvironments = (blocklet, nodeInfo) => {
305
299
  })}`;
306
300
  }
307
301
 
308
- const isMigrated = Array.isArray(blocklet.migratedFrom) && blocklet.migratedFrom.length > 0;
309
- const appPid = blocklet.appPid || appId;
310
- const appPsk = isMigrated ? blocklet.migratedFrom[0].appSk : appSk;
311
-
312
302
  return {
313
303
  BLOCKLET_DID: did,
314
304
  BLOCKLET_APP_SK: appSk,
315
305
  BLOCKLET_APP_ID: appId,
316
- BLOCKLET_APP_PSK: appPsk, // permanent sk even the blocklet has been migrated
317
- BLOCKLET_APP_PID: appPid, // permanent did even the blocklet has been migrated
318
306
  BLOCKLET_APP_NAME: appName,
319
307
  BLOCKLET_APP_DESCRIPTION: appDescription,
320
308
  BLOCKLET_APP_URL: appUrl,
@@ -847,7 +835,7 @@ const parseChildrenFromMeta = async (src, context = {}) => {
847
835
  };
848
836
 
849
837
  const validateBlocklet = (blocklet) =>
850
- forEachBlocklet(blocklet, async (b) => {
838
+ forEachBlocklet(blocklet, (b) => {
851
839
  isRequirementsSatisfied(b.meta.requirements);
852
840
  validateEngine(getBlockletEngineNameByPlatform(b.meta));
853
841
  });
@@ -1412,14 +1400,12 @@ const getBlocklet = async ({
1412
1400
 
1413
1401
  blocklet.settings.storeList = blocklet.settings.storeList || [];
1414
1402
 
1415
- [BLOCKLET_STORE_DEV, BLOCKLET_STORE].forEach((store) => {
1416
- if (!blocklet.settings.storeList.find((x) => x.url === store.url)) {
1417
- blocklet.settings.storeList.unshift({
1418
- ...store,
1419
- protected: true,
1420
- });
1421
- }
1422
- });
1403
+ if (!blocklet.settings.storeList.find((x) => x.url === BLOCKLET_STORE.url)) {
1404
+ blocklet.settings.storeList.unshift({
1405
+ ...BLOCKLET_STORE,
1406
+ protected: true,
1407
+ });
1408
+ }
1423
1409
 
1424
1410
  // app site
1425
1411
  blocklet.site = await states.site.findOneByBlocklet(blocklet.meta.did);
@@ -1561,63 +1547,11 @@ const createDataArchive = (dataDir, fileName) => {
1561
1547
  });
1562
1548
  };
1563
1549
 
1564
- const isBlockletAppSkUsed = ({ environments, migratedFrom = [] }, appSk) => {
1565
- const isUsedInEnv = environments.find((e) => e.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SK)?.value === appSk;
1566
- const isUsedInHistory = migratedFrom.some((x) => x.appSk === appSk);
1567
- return isUsedInEnv || isUsedInHistory;
1568
- };
1569
-
1570
- const isRotatingAppSk = (newConfigs, oldConfigs, externalSk) => {
1571
- const newSk = newConfigs.find((x) => BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SK === x.key);
1572
- if (!newSk) {
1573
- // If no newSk found, we are not rotating the appSk
1574
- return false;
1575
- }
1576
-
1577
- const oldSk = oldConfigs.find((x) => BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SK === x.key);
1578
- if (!oldSk) {
1579
- // If we have no oldSk, we are setting the initial appSk for external managed apps
1580
- // If we have no oldSk, but we are not external managed apps, we are rotating the appSk
1581
- return !externalSk;
1582
- }
1583
-
1584
- // Otherwise, we must be rotating the appSk
1585
- // eslint-disable-next-line sonarjs/prefer-single-boolean-return
1586
- if (oldSk.value !== newSk.value) {
1587
- return true;
1588
- }
1589
-
1590
- return false;
1591
- };
1592
-
1593
- const isRotatingAppDid = (newConfigs, oldConfigs, externalSk) => {
1594
- if (isRotatingAppSk(newConfigs, oldConfigs, externalSk)) {
1595
- return true;
1596
- }
1597
-
1598
- const newType = newConfigs.find((x) => BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_WALLET_TYPE === x.key);
1599
- const oldType = oldConfigs.find((x) => BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_WALLET_TYPE === x.key);
1600
- if (!newType) {
1601
- return false;
1602
- }
1603
-
1604
- if (!oldType) {
1605
- return true;
1606
- }
1607
-
1608
- // eslint-disable-next-line sonarjs/prefer-single-boolean-return
1609
- if (oldType !== newType) {
1610
- return true;
1611
- }
1612
-
1613
- return false;
1614
- };
1615
-
1616
1550
  /**
1617
1551
  * this function has side effect on config.value
1618
1552
  * @param {{ key: string, value?: string }} config
1619
1553
  */
1620
- const validateAppConfig = async (config, states) => {
1554
+ const validateAppConfig = async (config, blockletDid, states) => {
1621
1555
  const x = config;
1622
1556
 
1623
1557
  // sk should be force secured while other app prop should not be secured
@@ -1635,10 +1569,15 @@ const validateAppConfig = async (config, states) => {
1635
1569
  }
1636
1570
  }
1637
1571
 
1638
- // Ensure sk is not used by existing blocklets, otherwise we may encounter appDid collision
1572
+ // Ensure sk is not used by other blocklets, otherwise we may encounter appDid collision
1639
1573
  const blocklets = await states.blocklet.getBlocklets({});
1640
- if (blocklets.some((b) => isBlockletAppSkUsed(b, x.value))) {
1641
- throw new Error('Invalid custom blocklet secret key: already used by existing blocklet');
1574
+ const others = blocklets.filter((b) => b.meta.did !== blockletDid);
1575
+ if (
1576
+ others.some(
1577
+ (b) => b.environments.find((e) => e.key === BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SK).value === x.value
1578
+ )
1579
+ ) {
1580
+ throw new Error('Invalid custom blocklet secret key: already used by another blocklet');
1642
1581
  }
1643
1582
  } else {
1644
1583
  delete x.value;
@@ -1751,32 +1690,6 @@ const checkDuplicateMountPoint = (blocklet, mountPoint) => {
1751
1690
  }
1752
1691
  };
1753
1692
 
1754
- const validateStore = (nodeInfo, storeUrl) => {
1755
- if (nodeInfo.mode !== 'serverless') {
1756
- return;
1757
- }
1758
-
1759
- const inStoreList = nodeInfo.blockletRegistryList.find((item) => {
1760
- const itemURLObj = new URL(item.url);
1761
- const storeUrlObj = new URL(storeUrl);
1762
-
1763
- return itemURLObj.host === storeUrlObj.host;
1764
- });
1765
-
1766
- if (!inStoreList) {
1767
- throw new Error('Must be installed from the compliant blocklet store list');
1768
- }
1769
- };
1770
-
1771
- const validateInServerless = ({ blockletMeta }) => {
1772
- const { interfaces } = blockletMeta;
1773
- const externalPortInterfaces = (interfaces || []).filter((item) => !!item.port?.external);
1774
-
1775
- if (externalPortInterfaces.length > 0) {
1776
- throw new Error('Blocklets with exposed ports cannot be installed');
1777
- }
1778
- };
1779
-
1780
1693
  module.exports = {
1781
1694
  consumeServerlessNFT,
1782
1695
  forEachBlocklet,
@@ -1822,11 +1735,6 @@ module.exports = {
1822
1735
  getConfigFromPreferences,
1823
1736
  createDataArchive,
1824
1737
  validateAppConfig,
1825
- isBlockletAppSkUsed,
1826
- isRotatingAppSk,
1827
- isRotatingAppDid,
1828
1738
  checkDuplicateAppSk,
1829
1739
  checkDuplicateMountPoint,
1830
- validateStore,
1831
- validateInServerless,
1832
1740
  };
package/lib/util/index.js CHANGED
@@ -27,7 +27,6 @@ const {
27
27
  DEFAULT_HTTP_PORT,
28
28
  DEFAULT_HTTPS_PORT,
29
29
  SLOT_FOR_IP_DNS_SITE,
30
- NODE_MODES,
31
30
  } = require('@abtnode/constant');
32
31
 
33
32
  const DEFAULT_WELLKNOWN_PORT = 8088;
@@ -453,27 +452,6 @@ const prettyURL = (url, isHttps = true) => {
453
452
  return isHttps ? `https://${url}` : `http://${url}`;
454
453
  };
455
454
 
456
- const templateReplace = (str, vars = {}) => {
457
- if (typeof str === 'string') {
458
- return str.replace(/{([.\w]+)}/g, (m, key) => get(vars, key));
459
- }
460
-
461
- return str;
462
- };
463
-
464
- const isGatewayCacheEnabled = (info) => {
465
- if (info.mode === NODE_MODES.DEBUG) {
466
- return false;
467
- }
468
-
469
- const cacheEnabled = get(info, 'routing.cacheEnabled');
470
- if (typeof cacheEnabled === 'boolean') {
471
- return cacheEnabled;
472
- }
473
-
474
- return true;
475
- };
476
-
477
455
  const lib = {
478
456
  validateOwner,
479
457
  getProviderFromNodeInfo,
@@ -511,8 +489,6 @@ const lib = {
511
489
  getNFTState,
512
490
  getServerDidDomain,
513
491
  prettyURL,
514
- templateReplace,
515
- isGatewayCacheEnabled,
516
492
  };
517
493
 
518
494
  module.exports = lib;
@@ -52,7 +52,6 @@ const updateGatewaySchema = Joi.object({
52
52
  .when('requestLimit.enabled', { is: true, then: Joi.required() }),
53
53
  ipHeader: Joi.string().allow('').trim(),
54
54
  }),
55
- cacheEnabled: Joi.bool().optional().default(true),
56
55
  });
57
56
 
58
57
  module.exports = {
@@ -5,7 +5,7 @@ const checkURLAccessible = require('@abtnode/util/lib/url-evaluation/check-acces
5
5
  const { EVENTS } = require('@abtnode/constant');
6
6
  const WebHookSender = require('./sender');
7
7
  const WalletSender = require('./sender/wallet');
8
- const createQueue = require('../util/queue');
8
+ const createQueue = require('../queue');
9
9
  const IP = require('../util/ip');
10
10
  const states = require('../states');
11
11
  const { getBaseUrls } = require('../util');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.68-beta-500af7e5",
6
+ "version": "1.8.68",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,33 +19,33 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.8.68-beta-500af7e5",
23
- "@abtnode/certificate-manager": "1.8.68-beta-500af7e5",
24
- "@abtnode/constant": "1.8.68-beta-500af7e5",
25
- "@abtnode/cron": "1.8.68-beta-500af7e5",
26
- "@abtnode/db": "1.8.68-beta-500af7e5",
27
- "@abtnode/logger": "1.8.68-beta-500af7e5",
28
- "@abtnode/queue": "1.8.68-beta-500af7e5",
29
- "@abtnode/rbac": "1.8.68-beta-500af7e5",
30
- "@abtnode/router-provider": "1.8.68-beta-500af7e5",
31
- "@abtnode/static-server": "1.8.68-beta-500af7e5",
32
- "@abtnode/timemachine": "1.8.68-beta-500af7e5",
33
- "@abtnode/util": "1.8.68-beta-500af7e5",
34
- "@arcblock/did": "1.18.57",
22
+ "@abtnode/auth": "1.8.68",
23
+ "@abtnode/certificate-manager": "1.8.68",
24
+ "@abtnode/constant": "1.8.68",
25
+ "@abtnode/cron": "1.8.68",
26
+ "@abtnode/db": "1.8.68",
27
+ "@abtnode/logger": "1.8.68",
28
+ "@abtnode/queue": "1.8.68",
29
+ "@abtnode/rbac": "1.8.68",
30
+ "@abtnode/router-provider": "1.8.68",
31
+ "@abtnode/static-server": "1.8.68",
32
+ "@abtnode/timemachine": "1.8.68",
33
+ "@abtnode/util": "1.8.68",
34
+ "@arcblock/did": "1.18.42",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
- "@arcblock/did-util": "1.18.57",
37
- "@arcblock/event-hub": "1.18.57",
38
- "@arcblock/jwt": "^1.18.57",
36
+ "@arcblock/did-util": "1.18.42",
37
+ "@arcblock/event-hub": "1.18.42",
38
+ "@arcblock/jwt": "^1.18.42",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
- "@arcblock/vc": "1.18.57",
41
- "@blocklet/constant": "1.8.68-beta-500af7e5",
42
- "@blocklet/meta": "1.8.68-beta-500af7e5",
43
- "@blocklet/sdk": "1.8.68-beta-500af7e5",
44
- "@did-space/client": "0.1.87-beta-1",
40
+ "@arcblock/vc": "1.18.42",
41
+ "@blocklet/constant": "1.8.68",
42
+ "@blocklet/meta": "1.8.68",
43
+ "@blocklet/sdk": "1.8.68",
44
+ "@did-space/client": "^0.1.66",
45
45
  "@fidm/x509": "^1.2.1",
46
- "@ocap/mcrypto": "1.18.57",
47
- "@ocap/util": "1.18.57",
48
- "@ocap/wallet": "1.18.57",
46
+ "@ocap/mcrypto": "1.18.42",
47
+ "@ocap/util": "1.18.42",
48
+ "@ocap/wallet": "1.18.42",
49
49
  "@slack/webhook": "^5.0.4",
50
50
  "archiver": "^5.3.1",
51
51
  "axios": "^0.27.2",
@@ -72,6 +72,7 @@
72
72
  "pm2": "^5.2.0",
73
73
  "semver": "^7.3.8",
74
74
  "shelljs": "^0.8.5",
75
+ "slugify": "^1.6.5",
75
76
  "ssri": "^8.0.1",
76
77
  "stream-throttle": "^0.1.3",
77
78
  "stream-to-promise": "^3.0.0",
@@ -89,5 +90,5 @@
89
90
  "express": "^4.18.2",
90
91
  "jest": "^27.5.1"
91
92
  },
92
- "gitHead": "9070621373f317a10ff0d289323bf725e30d3521"
93
+ "gitHead": "1392044ac5677bde567797adeb9a6d3f0b9264b8"
93
94
  }
File without changes