@nocobase/cli 1.8.0-alpha.11 → 1.8.0-alpha.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "1.8.0-alpha.11",
3
+ "version": "1.8.0-alpha.13",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./src/index.js",
@@ -8,7 +8,7 @@
8
8
  "nocobase": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@nocobase/app": "1.8.0-alpha.11",
11
+ "@nocobase/app": "1.8.0-alpha.13",
12
12
  "@nocobase/license-kit": "^0.2.3",
13
13
  "@types/fs-extra": "^11.0.1",
14
14
  "@umijs/utils": "3.5.20",
@@ -27,12 +27,12 @@
27
27
  "tsx": "^4.19.0"
28
28
  },
29
29
  "devDependencies": {
30
- "@nocobase/devtools": "1.8.0-alpha.11"
30
+ "@nocobase/devtools": "1.8.0-alpha.13"
31
31
  },
32
32
  "repository": {
33
33
  "type": "git",
34
34
  "url": "git+https://github.com/nocobase/nocobase.git",
35
35
  "directory": "packages/core/cli"
36
36
  },
37
- "gitHead": "ca21882066ded53ac54e7340d3f5fdd2d4275a76"
37
+ "gitHead": "3f8aefecc5cb18cfc18e8bc1600df72fa10ca858"
38
38
  }
@@ -143,6 +143,17 @@ class Package {
143
143
  });
144
144
  console.log(chalk.greenBright(`Downloaded: ${this.packageName}@${version}`));
145
145
  } catch (error) {
146
+ if (error?.response?.data && typeof error?.response?.data?.pipe === 'function') {
147
+ let errorMessageBuffer = '';
148
+ error.response.data.on?.('data', (chunk) => {
149
+ errorMessageBuffer += chunk.toString('utf8'); // 收集错误信息
150
+ });
151
+ error.response.data.on?.('end', () => {
152
+ if (error.response.status === 403) {
153
+ console.error(chalk.redBright('You do not have permission to download this package version.'));
154
+ }
155
+ });
156
+ }
146
157
  console.log(chalk.redBright(`Download failed: ${this.packageName}`));
147
158
  }
148
159
  }
@@ -252,7 +263,13 @@ module.exports = (cli) => {
252
263
  NOCOBASE_PKG_USERNAME,
253
264
  NOCOBASE_PKG_PASSWORD,
254
265
  } = process.env;
255
- const { accessKeyId, accessKeySecret } = await getAccessKeyPair();
266
+ let accessKeyId;
267
+ let accessKeySecret;
268
+ try {
269
+ ({ accessKeyId, accessKeySecret } = await getAccessKeyPair());
270
+ } catch (e) {
271
+ return;
272
+ }
256
273
  if (!(NOCOBASE_PKG_USERNAME && NOCOBASE_PKG_PASSWORD) && !(accessKeyId && accessKeySecret)) {
257
274
  return;
258
275
  }
package/src/util.js CHANGED
@@ -19,7 +19,7 @@ const fs = require('fs-extra');
19
19
  const os = require('os');
20
20
  const moment = require('moment-timezone');
21
21
  const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit');
22
- const _ = require('lodash');
22
+ const omit = require('lodash/omit');
23
23
 
24
24
  exports.isPackageValid = (pkg) => {
25
25
  try {
@@ -491,10 +491,20 @@ exports.generatePlugins = function () {
491
491
  }
492
492
  };
493
493
 
494
+ async function isEnvMatch(keyData) {
495
+ const env = await getEnvAsync();
496
+ if (env?.container?.id && keyData?.instanceData?.container?.id) {
497
+ return (
498
+ JSON.stringify(omit(env, ['timestamp', 'container', 'hostname'])) ===
499
+ JSON.stringify(omit(keyData?.instanceData, ['timestamp', 'container', 'hostname']))
500
+ );
501
+ }
502
+ return JSON.stringify(omit(env, ['timestamp'])) === JSON.stringify(omit(keyData?.instanceData, ['timestamp']));
503
+ }
504
+
494
505
  exports.getAccessKeyPair = async function () {
495
506
  const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
496
507
  if (!fs.existsSync(keyFile)) {
497
- // showLicenseInfo(LicenseKeyError.notExist);
498
508
  return {};
499
509
  }
500
510
 
@@ -505,13 +515,13 @@ exports.getAccessKeyPair = async function () {
505
515
  keyData = JSON.parse(keyDataStr);
506
516
  } catch (error) {
507
517
  showLicenseInfo(LicenseKeyError.parseFailed);
508
- return {};
518
+ throw new Error(LicenseKeyError.parseFailed.title);
509
519
  }
510
520
 
511
- const currentEnv = await getEnvAsync();
512
- if (!_.isEqual(_.omit(keyData?.instanceData, ['timestamp']), _.omit(currentEnv, ['timestamp']))) {
521
+ const isEnvMatched = await isEnvMatch(keyData);
522
+ if (!isEnvMatched) {
513
523
  showLicenseInfo(LicenseKeyError.notMatch);
514
- return {};
524
+ throw new Error(LicenseKeyError.notMatch.title);
515
525
  }
516
526
 
517
527
  const { accessKeyId, accessKeySecret } = keyData;
@@ -520,21 +530,21 @@ exports.getAccessKeyPair = async function () {
520
530
 
521
531
  const LicenseKeyError = {
522
532
  notExist: {
523
- title: 'License key not exist',
533
+ title: 'License key not found',
524
534
  content:
525
535
  'Please go to the license settings page to obtain the Instance ID for the current environment, and then generate the license key on the service platform.',
526
536
  },
527
537
  parseFailed: {
528
- title: 'License key parse failed',
538
+ title: 'Invalid license key format',
529
539
  content: 'Please check your license key, or regenerate the license key on the service platform.',
530
540
  },
531
541
  notMatch: {
532
- title: 'License key not matched',
542
+ title: 'License key mismatch',
533
543
  content:
534
544
  'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
535
545
  },
536
546
  notValid: {
537
- title: 'License key not valid',
547
+ title: 'Invalid license key',
538
548
  content:
539
549
  'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
540
550
  },