@abtnode/core 1.16.6-beta-1fde60e3 → 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.
@@ -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) ? uniq(did) : [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.controller && process.env.NODE_ENV !== 'test') {
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')), ['_id', 'createdAt', 'updatedAt']);
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(
@@ -1,5 +1,4 @@
1
1
  const { BlockletStatus, BLOCKLET_MODES, fromBlockletStatus, BlockletSource } = require('@blocklet/constant');
2
- const toDid = require('@blocklet/meta/lib/did');
3
2
 
4
3
  const logger = require('@abtnode/logger')('@abtnode/core:install-app-dev');
5
4
  const { ensureMeta, updateBlockletFallbackLogo, ensureAppLogo } = require('../../../util/blocklet');
@@ -13,10 +12,7 @@ const { ensureMeta, updateBlockletFallbackLogo, ensureAppLogo } = require('../..
13
12
  * @returns
14
13
  */
15
14
  const installApplicationFromDev = async ({ folder, meta, states, manager } = {}) => {
16
- const { version } = meta;
17
-
18
- const name = `${meta.name}-dev`;
19
- const did = toDid(name);
15
+ const { version, name, did } = meta;
20
16
 
21
17
  const exist = await states.blocklet.getBlocklet(did);
22
18
  if (exist) {
@@ -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 = uniq([].concat(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 = uniq([].concat(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 = uniq([].concat(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 });
@@ -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
- new Promise((resolve, reject) => {
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) => {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.6-beta-1fde60e3",
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-1fde60e3",
23
- "@abtnode/certificate-manager": "1.16.6-beta-1fde60e3",
24
- "@abtnode/constant": "1.16.6-beta-1fde60e3",
25
- "@abtnode/cron": "1.16.6-beta-1fde60e3",
26
- "@abtnode/db": "1.16.6-beta-1fde60e3",
27
- "@abtnode/logger": "1.16.6-beta-1fde60e3",
28
- "@abtnode/queue": "1.16.6-beta-1fde60e3",
29
- "@abtnode/rbac": "1.16.6-beta-1fde60e3",
30
- "@abtnode/router-provider": "1.16.6-beta-1fde60e3",
31
- "@abtnode/static-server": "1.16.6-beta-1fde60e3",
32
- "@abtnode/timemachine": "1.16.6-beta-1fde60e3",
33
- "@abtnode/util": "1.16.6-beta-1fde60e3",
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,9 +40,9 @@
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-1fde60e3",
44
- "@blocklet/meta": "1.16.6-beta-1fde60e3",
45
- "@blocklet/sdk": "1.16.6-beta-1fde60e3",
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
46
  "@did-space/client": "^0.2.83",
47
47
  "@fidm/x509": "^1.2.1",
48
48
  "@ocap/mcrypto": "1.18.75",
@@ -94,5 +94,5 @@
94
94
  "express": "^4.18.2",
95
95
  "jest": "^27.5.1"
96
96
  },
97
- "gitHead": "be8d8eab7d210910e24dae3b389f2c70aa414a13"
97
+ "gitHead": "36b58c0651762472ac34ad880965c47510eb9768"
98
98
  }