@abtnode/core 1.16.43-beta-20250505-062139-b156e7da → 1.16.43-beta-20250507-124320-c405ab23

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 CHANGED
@@ -87,7 +87,7 @@ class NodeAPI {
87
87
  }
88
88
 
89
89
  async getEnv() {
90
- const info = await IP.get();
90
+ const info = await IP.get({ timeout: 5000 });
91
91
  info.internalV4 = info.internal;
92
92
  info.externalV4 = info.external;
93
93
 
@@ -108,6 +108,7 @@ class BundleDownloader extends EventEmitter {
108
108
  await resolveDownload(tarballPath, this.installDir, {
109
109
  removeTarFile: false,
110
110
  nodeInfo,
111
+ dist,
111
112
  onProgress: ({ name: _name }) => {
112
113
  onProgress({ status: 'extracting', name: _name });
113
114
  },
@@ -21,7 +21,11 @@ const asyncFs = fs.promises;
21
21
  * nodeInfo: { enableDocker: boolean };
22
22
  * }} option
23
23
  */
24
- const resolveDownload = async (tarFile, dist, { removeTarFile = true, logger = defaultLogger, onProgress } = {}) => {
24
+ const resolveDownload = async (
25
+ tarFile,
26
+ distDir,
27
+ { removeTarFile = true, logger = defaultLogger, onProgress, dist } = {}
28
+ ) => {
25
29
  const downloadDir = path.join(path.dirname(tarFile), path.basename(tarFile, path.extname(tarFile)));
26
30
  const tmp = `${downloadDir}-tmp`;
27
31
  try {
@@ -56,11 +60,14 @@ const resolveDownload = async (tarFile, dist, { removeTarFile = true, logger = d
56
60
  dir = path.join(dir, BLOCKLET_BUNDLE_FOLDER);
57
61
  }
58
62
 
59
- logger.info('Move downloadDir to installDir', { downloadDir });
63
+ logger.info('Move expandDir to downloadDir', { expandDir: dir, downloadDir });
60
64
  await fs.move(dir, downloadDir, { overwrite: true });
61
65
  fs.removeSync(tmp);
62
66
 
63
67
  meta = getBlockletMeta(downloadDir);
68
+ if (dist?.integrity) {
69
+ meta.dist = dist;
70
+ }
64
71
  const { name, version } = meta;
65
72
 
66
73
  if (typeof onProgress === 'function') {
@@ -68,7 +75,7 @@ const resolveDownload = async (tarFile, dist, { removeTarFile = true, logger = d
68
75
  }
69
76
  await ensureBlockletExpanded(meta, downloadDir);
70
77
 
71
- installDir = getBundleDir(dist, meta);
78
+ installDir = getBundleDir(distDir, meta);
72
79
  if (fs.existsSync(installDir)) {
73
80
  fs.removeSync(installDir);
74
81
  logger.info('cleanup blocklet upgrade dir', { name, version, installDir });
@@ -76,6 +83,7 @@ const resolveDownload = async (tarFile, dist, { removeTarFile = true, logger = d
76
83
 
77
84
  fs.mkdirSync(installDir, { recursive: true });
78
85
 
86
+ logger.info('Move downloadDir to installDir with full', { downloadDir, installDir, dist: meta.dist });
79
87
  await fs.move(downloadDir, installDir, { overwrite: true });
80
88
  } catch (error) {
81
89
  fs.removeSync(downloadDir);
@@ -88,13 +96,13 @@ const resolveDownload = async (tarFile, dist, { removeTarFile = true, logger = d
88
96
 
89
97
  const resolveDiffDownload = async (
90
98
  tarFile,
91
- dist,
92
- { meta: oldMeta, deleteSet, cwd = '/', logger = defaultLogger } = {}
99
+ distDir,
100
+ { meta: oldMeta, deleteSet, cwd = '/', logger = defaultLogger, dist } = {}
93
101
  ) => {
94
102
  // eslint-disable-next-line no-param-reassign
95
103
  tarFile = path.join(cwd, tarFile);
96
104
  // eslint-disable-next-line no-param-reassign
97
- dist = path.join(cwd, dist);
105
+ distDir = path.join(cwd, distDir);
98
106
 
99
107
  logger.info('Resolve diff download', { tarFile, cwd });
100
108
  const downloadDir = path.join(path.dirname(tarFile), path.basename(tarFile, path.extname(tarFile)));
@@ -107,8 +115,8 @@ const resolveDiffDownload = async (
107
115
  logger.error('expand blocklet tar file error', { error });
108
116
  throw error;
109
117
  }
110
- logger.info('Copy installDir to downloadDir', { installDir: dist, downloadDir });
111
- await fs.copy(getBundleDir(dist, oldMeta), downloadDir);
118
+ logger.info('Copy installDir to downloadDir', { installDir: distDir, downloadDir });
119
+ await fs.copy(getBundleDir(distDir, oldMeta), downloadDir);
112
120
  try {
113
121
  // delete
114
122
  logger.info('Delete files from downloadDir', { fileNum: deleteSet.length });
@@ -135,15 +143,18 @@ const resolveDiffDownload = async (
135
143
  await walkDiff(diffDir);
136
144
  fs.removeSync(diffDir);
137
145
  const meta = getBlockletMeta(downloadDir);
146
+ if (dist?.integrity) {
147
+ meta.dist = dist;
148
+ }
138
149
 
139
150
  await ensureBlockletExpanded(meta, downloadDir);
140
151
 
141
152
  // move to installDir
142
- const bundleDir = getBundleDir(dist, meta);
143
- logger.info('Move downloadDir to installDir', { downloadDir, bundleDir });
144
- await fs.move(downloadDir, bundleDir, { overwrite: true });
153
+ const installDir = getBundleDir(distDir, meta);
154
+ logger.info('Move downloadDir to installDir with diff', { downloadDir, installDir });
155
+ await fs.move(downloadDir, installDir, { overwrite: true });
145
156
 
146
- return { meta, installDir: bundleDir };
157
+ return { meta, installDir };
147
158
  } catch (error) {
148
159
  fs.removeSync(downloadDir);
149
160
  fs.removeSync(diffDir);
@@ -631,6 +631,7 @@ class DiskBlockletManager extends BaseBlockletManager {
631
631
  sync,
632
632
  downloadTokenList,
633
633
  onlyRequired,
634
+ dist,
634
635
  },
635
636
  context = {}
636
637
  ) {
@@ -652,6 +653,7 @@ class DiskBlockletManager extends BaseBlockletManager {
652
653
  context,
653
654
  states,
654
655
  manager: this,
656
+ dist,
655
657
  });
656
658
  }
657
659
 
@@ -31,6 +31,7 @@ const installComponentFromUpload = async ({
31
31
  context = {},
32
32
  manager,
33
33
  states,
34
+ dist,
34
35
  }) => {
35
36
  logger.info('install component', { from: 'upload file' });
36
37
 
@@ -67,10 +68,10 @@ const installComponentFromUpload = async ({
67
68
  throw new Error('Blocklet version changed when diff deploying');
68
69
  }
69
70
 
70
- meta = (await resolveDiffDownload(tarFile, manager.installDir, { deleteSet, meta: oldChild.meta })).meta;
71
+ meta = (await resolveDiffDownload(tarFile, manager.installDir, { deleteSet, meta: oldChild.meta, dist })).meta;
71
72
  } else {
72
73
  // full deploy
73
- meta = (await resolveDownload(tarFile, manager.installDir)).meta;
74
+ meta = (await resolveDownload(tarFile, manager.installDir, { dist })).meta;
74
75
  }
75
76
 
76
77
  if (meta.did === rootDid) {
@@ -945,7 +945,7 @@ const initLogger =
945
945
  ),
946
946
  });
947
947
 
948
- if (process.env.NODE_ENV === 'production') {
948
+ if (process.env.NODE_ENV === 'production' || process.env.ABT_LOG_TO_FILE === 'true') {
949
949
  logger.level = level || 'info';
950
950
  if (!fs.existsSync(logDir)) {
951
951
  fs.mkdirSync(logDir, { recursive: true });
@@ -119,16 +119,27 @@ const publishToEndpoint = async ({ did, projectId, endpointId, releaseId, manage
119
119
  releaseDir = `${releaseDir}-${endpointId}`;
120
120
  }
121
121
 
122
- // const metaFile = path.join(releaseDir, '.blocklet', 'release', 'blocklet.json');
123
122
  const bundleDir = path.join(releaseDir, '.blocklet', 'bundle');
124
123
  let localMeta;
124
+ const metaFile = path.join(releaseDir, '.blocklet', 'release', 'blocklet.json');
125
+ let metaExists = false;
125
126
  try {
126
- localMeta = getBlockletMeta(bundleDir);
127
- } catch (error) {
128
- throw new Error(`Get blocklet meta failed: ${error.message}`);
127
+ await fs.access(metaFile);
128
+ metaExists = true;
129
+ } catch (_) {
130
+ //
129
131
  }
130
- if (hasReservedKey(localMeta.environments)) {
131
- throw new Error('Blocklet key of environments can not start with `ABT_NODE_` or `BLOCKLET_`');
132
+ if (metaExists) {
133
+ localMeta = JSON.parse(await fs.readFile(metaFile, 'utf-8'));
134
+ } else {
135
+ try {
136
+ localMeta = getBlockletMeta(bundleDir);
137
+ } catch (error) {
138
+ throw new Error(`Get blocklet meta failed: ${error.message}`);
139
+ }
140
+ if (hasReservedKey(localMeta.environments)) {
141
+ throw new Error('Blocklet key of environments can not start with `ABT_NODE_` or `BLOCKLET_`');
142
+ }
132
143
  }
133
144
 
134
145
  const mountPoint = getMountPoint(localMeta);
@@ -213,6 +224,10 @@ const publishToEndpoint = async ({ did, projectId, endpointId, releaseId, manage
213
224
  deleteSet,
214
225
  mountPoint,
215
226
  rootDid,
227
+ dist: {
228
+ tarball: localMeta.dist?.tarball || '',
229
+ integrity: localMeta.dist?.integrity || '',
230
+ },
216
231
  });
217
232
 
218
233
  try {
@@ -146,10 +146,13 @@ class Router {
146
146
  blockPolicy.blacklist = await expandBlacklist(blockPolicy.blacklist);
147
147
 
148
148
  // remove current internal ip from blacklist to avoid blocking self
149
- const result = await IP.get({ includeExternal: false, timeout: 2000 });
149
+ const result = await IP.get({ timeout: 2000 });
150
150
  if (result?.internal) {
151
151
  blockPolicy.blacklist = blockPolicy.blacklist.filter((x) => x !== result.internal);
152
152
  }
153
+ if (result?.external) {
154
+ blockPolicy.blacklist = blockPolicy.blacklist.filter((x) => x !== result.external);
155
+ }
153
156
 
154
157
  // Append blocked ips from database
155
158
  const blockedIps = await getActiveBlacklist();
@@ -7,11 +7,11 @@ const CustomError = require('@abtnode/util/lib/custom-error');
7
7
 
8
8
  const logger = require('@abtnode/logger')('@abtnode/core:states:access-key');
9
9
  const BaseState = require('./base');
10
- const { accessKeySchema } = require('../validators/access-key');
10
+ const { accessKeySchema, REMARK_MAX_LENGTH } = require('../validators/access-key');
11
11
 
12
12
  const validateRemark = (remark) => {
13
- if (remark && remark.length > 50) {
14
- throw new CustomError(400, 'Remark length should NOT be more than 50 characters');
13
+ if (remark && remark.length > REMARK_MAX_LENGTH) {
14
+ throw new CustomError(400, `Remark length should NOT be more than ${REMARK_MAX_LENGTH} characters`);
15
15
  }
16
16
  };
17
17
 
@@ -193,7 +193,7 @@ class BackupState extends BaseState {
193
193
  const dateColumn = this.model.sequelize.fn(
194
194
  'strftime',
195
195
  '%Y-%m-%d', // 提取年月日
196
- this.model.sequelize.fn('datetime', this.model.sequelize.col('createdAt'), `+${offset} minutes`)
196
+ this.model.sequelize.fn('datetime', this.model.sequelize.col('createdAt'), `${offset} minutes`)
197
197
  );
198
198
  /**
199
199
  * @type {import('sequelize').WhereOptions<import('@abtnode/models').BackupState>}
@@ -141,6 +141,18 @@ const blockletCache = new SingleFlightLRUCache({
141
141
  ttl: BLOCKLET_CACHE_TTL,
142
142
  });
143
143
 
144
+ const getVersionScope = (meta) => {
145
+ if (meta.dist?.integrity) {
146
+ const safeHash = meta.dist.integrity
147
+ .replace('sha512-', '')
148
+ .slice(0, 8)
149
+ .replace(/[^a-zA-Z0-9]/g, '');
150
+ return `${meta.version}-${safeHash}`;
151
+ }
152
+
153
+ return meta.version;
154
+ };
155
+
144
156
  const deleteBlockletCache = (did) => {
145
157
  const flags = [false, true];
146
158
  flags.forEach((ensureIntegrity) => {
@@ -1182,6 +1194,7 @@ const pruneBlockletBundle = async ({ blocklets, installDir, blockletSettings })
1182
1194
  for (const blocklet of blocklets) {
1183
1195
  forEachBlockletSync(blocklet, (component) => {
1184
1196
  blockletMap[`${component.meta.bundleName}/${component.meta.version}`] = true;
1197
+ blockletMap[`${component.meta.bundleName}/${getVersionScope(component.meta)}`] = true;
1185
1198
  });
1186
1199
  }
1187
1200
  for (const setting of blockletSettings) {
@@ -1189,6 +1202,7 @@ const pruneBlockletBundle = async ({ blocklets, installDir, blockletSettings })
1189
1202
  if (child.status !== BlockletStatus.deleted) {
1190
1203
  forEachBlockletSync(child, (component) => {
1191
1204
  blockletMap[`${component.meta.bundleName}/${component.meta.version}`] = true;
1205
+ blockletMap[`${component.meta.bundleName}/${getVersionScope(component.meta)}`] = true;
1192
1206
  });
1193
1207
  }
1194
1208
  }
@@ -1466,7 +1480,27 @@ const getDiffFiles = async (inputFiles, sourceDir) => {
1466
1480
  };
1467
1481
  };
1468
1482
 
1469
- const getBundleDir = (installDir, meta) => path.join(installDir, meta.bundleName || meta.name, meta.version);
1483
+ const checkCompatibleOnce = {};
1484
+
1485
+ // TODO: 梁柱, 这里为了兼容旧版的 blocklet,需要暂时保留,未来所有 blocklet 都使用新路径了可以删除
1486
+ const compatibleWithOldBlocklets = (dir) => {
1487
+ if (checkCompatibleOnce[dir] !== undefined) {
1488
+ return checkCompatibleOnce[dir];
1489
+ }
1490
+
1491
+ checkCompatibleOnce[dir] = !!fs.existsSync(path.join(dir, 'blocklet.yml'));
1492
+
1493
+ return checkCompatibleOnce[dir];
1494
+ };
1495
+
1496
+ const getBundleDir = (installDir, meta) => {
1497
+ const oldDir = path.join(installDir, meta.bundleName || meta.name, meta.version);
1498
+ if (compatibleWithOldBlocklets(oldDir)) {
1499
+ return oldDir;
1500
+ }
1501
+
1502
+ return path.join(installDir, meta.bundleName || meta.name, getVersionScope(meta));
1503
+ };
1470
1504
 
1471
1505
  const needBlockletDownload = (blocklet, oldBlocklet) => {
1472
1506
  if ([BlockletSource.upload, BlockletSource.local, BlockletSource.custom].includes(blocklet.source)) {
@@ -356,7 +356,7 @@ const setupAppOwner = async ({ node, sessionId, justCreate = false, context, pro
356
356
  userDid: ownerDid,
357
357
  appPid: appDid,
358
358
  status: 'online',
359
- visitorId: context?.visitorId,
359
+ // visitorId: context?.visitorId, // NOTICE: @2025-05-06 初始化新应用时,使用新的 visitorId
360
360
  ua: context?.ua, // NOTICE: @2024-12-01 webapp 暂不做 userSession 纠正 ua 的处理,因为 webapp 中不涉及 userSession 管理
361
361
  lastLoginIp: context?.lastLoginIp,
362
362
  extra: {
@@ -3,6 +3,8 @@ const { didExtension } = require('@blocklet/meta/lib/extension');
3
3
 
4
4
  const Joi = JOI.extend(didExtension);
5
5
 
6
+ const REMARK_MAX_LENGTH = 200;
7
+
6
8
  const accessKeySchema = Joi.object({
7
9
  accessKeyId: Joi.string().required().min(1).max(40).messages({
8
10
  'string.empty': 'Access Key ID cannot be empty',
@@ -20,9 +22,12 @@ const accessKeySchema = Joi.object({
20
22
  'string.max': 'Passport length must be less than or equal to 40 characters long',
21
23
  }),
22
24
 
23
- remark: Joi.string().allow('').max(128).messages({
24
- 'string.max': 'Remark length must be less than or equal to 128 characters long',
25
- }),
25
+ remark: Joi.string()
26
+ .allow('')
27
+ .max(REMARK_MAX_LENGTH)
28
+ .messages({
29
+ 'string.max': `Remark length must be less than or equal to ${REMARK_MAX_LENGTH} characters long`,
30
+ }),
26
31
 
27
32
  createdBy: Joi.string().trim().required(),
28
33
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.43-beta-20250505-062139-b156e7da",
6
+ "version": "1.16.43-beta-20250507-124320-c405ab23",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,21 +19,21 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@abtnode/analytics": "1.16.43-beta-20250505-062139-b156e7da",
23
- "@abtnode/auth": "1.16.43-beta-20250505-062139-b156e7da",
24
- "@abtnode/certificate-manager": "1.16.43-beta-20250505-062139-b156e7da",
25
- "@abtnode/client": "1.16.43-beta-20250505-062139-b156e7da",
26
- "@abtnode/constant": "1.16.43-beta-20250505-062139-b156e7da",
27
- "@abtnode/cron": "1.16.43-beta-20250505-062139-b156e7da",
28
- "@abtnode/docker-utils": "1.16.43-beta-20250505-062139-b156e7da",
29
- "@abtnode/logger": "1.16.43-beta-20250505-062139-b156e7da",
30
- "@abtnode/models": "1.16.43-beta-20250505-062139-b156e7da",
31
- "@abtnode/queue": "1.16.43-beta-20250505-062139-b156e7da",
32
- "@abtnode/rbac": "1.16.43-beta-20250505-062139-b156e7da",
33
- "@abtnode/router-provider": "1.16.43-beta-20250505-062139-b156e7da",
34
- "@abtnode/static-server": "1.16.43-beta-20250505-062139-b156e7da",
35
- "@abtnode/timemachine": "1.16.43-beta-20250505-062139-b156e7da",
36
- "@abtnode/util": "1.16.43-beta-20250505-062139-b156e7da",
22
+ "@abtnode/analytics": "1.16.43-beta-20250507-124320-c405ab23",
23
+ "@abtnode/auth": "1.16.43-beta-20250507-124320-c405ab23",
24
+ "@abtnode/certificate-manager": "1.16.43-beta-20250507-124320-c405ab23",
25
+ "@abtnode/client": "1.16.43-beta-20250507-124320-c405ab23",
26
+ "@abtnode/constant": "1.16.43-beta-20250507-124320-c405ab23",
27
+ "@abtnode/cron": "1.16.43-beta-20250507-124320-c405ab23",
28
+ "@abtnode/docker-utils": "1.16.43-beta-20250507-124320-c405ab23",
29
+ "@abtnode/logger": "1.16.43-beta-20250507-124320-c405ab23",
30
+ "@abtnode/models": "1.16.43-beta-20250507-124320-c405ab23",
31
+ "@abtnode/queue": "1.16.43-beta-20250507-124320-c405ab23",
32
+ "@abtnode/rbac": "1.16.43-beta-20250507-124320-c405ab23",
33
+ "@abtnode/router-provider": "1.16.43-beta-20250507-124320-c405ab23",
34
+ "@abtnode/static-server": "1.16.43-beta-20250507-124320-c405ab23",
35
+ "@abtnode/timemachine": "1.16.43-beta-20250507-124320-c405ab23",
36
+ "@abtnode/util": "1.16.43-beta-20250507-124320-c405ab23",
37
37
  "@arcblock/did": "1.20.4",
38
38
  "@arcblock/did-auth": "1.20.4",
39
39
  "@arcblock/did-ext": "1.20.4",
@@ -44,14 +44,14 @@
44
44
  "@arcblock/pm2-events": "^0.0.5",
45
45
  "@arcblock/validator": "1.20.4",
46
46
  "@arcblock/vc": "1.20.4",
47
- "@blocklet/constant": "1.16.43-beta-20250505-062139-b156e7da",
47
+ "@blocklet/constant": "1.16.43-beta-20250507-124320-c405ab23",
48
48
  "@blocklet/did-space-js": "^1.0.49",
49
- "@blocklet/env": "1.16.43-beta-20250505-062139-b156e7da",
49
+ "@blocklet/env": "1.16.43-beta-20250507-124320-c405ab23",
50
50
  "@blocklet/error": "^0.2.4",
51
- "@blocklet/meta": "1.16.43-beta-20250505-062139-b156e7da",
52
- "@blocklet/resolver": "1.16.43-beta-20250505-062139-b156e7da",
53
- "@blocklet/sdk": "1.16.43-beta-20250505-062139-b156e7da",
54
- "@blocklet/store": "1.16.43-beta-20250505-062139-b156e7da",
51
+ "@blocklet/meta": "1.16.43-beta-20250507-124320-c405ab23",
52
+ "@blocklet/resolver": "1.16.43-beta-20250507-124320-c405ab23",
53
+ "@blocklet/sdk": "1.16.43-beta-20250507-124320-c405ab23",
54
+ "@blocklet/store": "1.16.43-beta-20250507-124320-c405ab23",
55
55
  "@blocklet/theme": "^2.13.21",
56
56
  "@fidm/x509": "^1.2.1",
57
57
  "@ocap/mcrypto": "1.20.4",
@@ -116,5 +116,5 @@
116
116
  "jest": "^29.7.0",
117
117
  "unzipper": "^0.10.11"
118
118
  },
119
- "gitHead": "b1056718bbb5c25aef0cacc08d29762ebc420f66"
119
+ "gitHead": "4e5087dfaa52788676f313d23bfdd3ac68d63503"
120
120
  }