@cloudbase/cli 2.6.13 → 2.6.14

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/bin/tcb.js CHANGED
@@ -1,10 +1,7 @@
1
1
  #!/usr/bin/env node
2
- const os = require('os')
3
2
  const yargsParser = require('yargs-parser')
4
3
  const chalk = require('chalk')
5
- const address = require('address')
6
4
  const { program } = require('commander')
7
- const Sentry = require('@sentry/node')
8
5
  const logSymbols = require('log-symbols')
9
6
  const didYouMean = require('didyoumean')
10
7
  const updateNotifier = require('update-notifier')
@@ -17,11 +14,11 @@ const execa = require('execa')
17
14
  const semver = require('semver')
18
15
 
19
16
  const pkg = require('../package.json')
20
- const store = require('../lib/utils/store')
21
17
  const { ALL_COMMANDS } = require('../lib/constant')
22
18
  const { getProxy } = require('../lib/utils/net')
23
19
  const { getCloudBaseConfig, getPrivateSettings } = require('../lib/utils/config')
24
20
  const { registerCommands } = require('../lib')
21
+ const { beaconAction } = require('../lib/utils/report')
25
22
 
26
23
  const regionSupported = ['ap-shanghai', 'ap-beijing', 'ap-guangzhou']
27
24
  const regionSupportedMap = {
@@ -53,18 +50,6 @@ async function main() {
53
50
  process.exit(1)
54
51
  }
55
52
 
56
- // Sentry 错误上报
57
- Sentry.init({
58
- release: pkg.version,
59
- dsn: 'https://fff0077d06624655ad70d1ee25df419e@report.url.cn/sentry/1782',
60
- httpsProxy: getProxy() || '',
61
- serverName: os.hostname(),
62
- integrations: [
63
- new Sentry.Integrations.OnUnhandledRejection({
64
- mode: 'none'
65
- })
66
- ]
67
- })
68
53
 
69
54
  // 输出版本信息
70
55
  console.log(chalk.gray(`CloudBase CLI ${pkg.version}`))
@@ -84,19 +69,6 @@ async function main() {
84
69
  // 注册命令
85
70
  await registerCommands()
86
71
 
87
- // 设置 Sentry 上报的用户 uin
88
- Sentry.configureScope((scope) => {
89
- try {
90
- const credential = store.authStore.get('credential') || {}
91
- scope.setUser({
92
- uin: credential.uin || '',
93
- ip: address.ip() || ''
94
- })
95
- } catch (e) {
96
- Sentry.captureException(e)
97
- }
98
- })
99
-
100
72
  // 设置 options 选项
101
73
  program.storeOptionsAsProperties(false)
102
74
  program.option('--verbose', '打印出内部运行信息')
@@ -173,6 +145,13 @@ async function main() {
173
145
  * 处理异常
174
146
  */
175
147
  async function errorHandler(err) {
148
+ beaconAction.report('tcb_cli_error', {
149
+ name: err.name,
150
+ message: err.message,
151
+ stack: err.stack,
152
+ requestId: err.requestId,
153
+ canIgnore: 'false'
154
+ })
176
155
  process.emit('tcbError')
177
156
  const stackIngoreErrors = ['TencentCloudSDKHttpException', 'CloudBaseError']
178
157
  // 忽略自定义错误的错误栈
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
15
  exports.Command = exports.registerCommands = exports.ICommand = void 0;
39
16
  const chalk_1 = __importDefault(require("chalk"));
40
- const Sentry = __importStar(require("@sentry/node"));
41
17
  const events_1 = require("events");
42
18
  const commander_1 = require("commander");
43
19
  const yargs_parser_1 = __importDefault(require("yargs-parser"));
@@ -45,6 +21,7 @@ const error_1 = require("../error");
45
21
  const toolbox_1 = require("@cloudbase/toolbox");
46
22
  const utils_1 = require("../utils");
47
23
  const auth_1 = require("../auth");
24
+ const report_1 = require("../utils/report");
48
25
  const registrableCommands = [];
49
26
  const cmdMap = new Map();
50
27
  const defaultCmdDecoratorOpts = {
@@ -136,7 +113,7 @@ class Command extends events_1.EventEmitter {
136
113
  }
137
114
  }
138
115
  createProgram(instance, deprecate, newCmd) {
139
- const { cmd, desc, options, requiredEnvId = true, withoutAuth = false, autoRunLogin = false } = this.options;
116
+ const { cmd, childCmd, desc, options, requiredEnvId = true, withoutAuth = false, autoRunLogin = false } = this.options;
140
117
  instance.storeOptionsAsProperties(false);
141
118
  options.forEach((option) => {
142
119
  const { hideHelp } = option;
@@ -165,10 +142,11 @@ class Command extends events_1.EventEmitter {
165
142
  if (!withoutAuth && !loginState) {
166
143
  if (autoRunLogin) {
167
144
  console.log(chalk_1.default.bold.yellowBright('无有效身份信息,将自动为您打开授权页面。'));
168
- yield (0, toolbox_1.execWithLoading)(() => (0, auth_1.login)(), {
145
+ const execResult = yield (0, toolbox_1.execWithLoading)(() => (0, auth_1.login)(), {
169
146
  startTip: '请在浏览器中打开的授权页面进行授权...',
170
147
  successTip: '授权登录成功!'
171
148
  });
149
+ loginState = execResult.credential;
172
150
  }
173
151
  else {
174
152
  throw new error_1.CloudBaseError('无有效身份信息,请使用 cloudbase login 登录');
@@ -177,6 +155,15 @@ class Command extends events_1.EventEmitter {
177
155
  if (!envId && requiredEnvId) {
178
156
  throw new error_1.CloudBaseError('未识别到有效的环境 Id,请使用 cloudbaserc 配置文件进行操作或通过 -e 参数指定环境 Id');
179
157
  }
158
+ report_1.beaconAction.addAdditionalParams({
159
+ login_uin: loginState === null || loginState === void 0 ? void 0 : loginState['uin'],
160
+ envId: envId || (loginState === null || loginState === void 0 ? void 0 : loginState['envId'])
161
+ });
162
+ report_1.beaconAction.report('tcb_cli_exec_command', {
163
+ cmd,
164
+ childCmd,
165
+ desc
166
+ });
180
167
  const ctx = {
181
168
  cmd,
182
169
  envId,
@@ -210,7 +197,6 @@ class Command extends events_1.EventEmitter {
210
197
  }
211
198
  catch (e) {
212
199
  loading.stop();
213
- Sentry.captureException(e);
214
200
  }
215
201
  });
216
202
  }
@@ -224,7 +210,6 @@ class Command extends events_1.EventEmitter {
224
210
  yield (0, utils_1.collectUsage)(cmd);
225
211
  }
226
212
  catch (e) {
227
- Sentry.captureException(e);
228
213
  }
229
214
  });
230
215
  }
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.beaconAction = void 0;
16
+ const os_1 = __importDefault(require("os"));
17
+ const crypto_1 = __importDefault(require("crypto"));
18
+ const net_1 = require("./net");
19
+ class BeaconAction {
20
+ constructor() {
21
+ this.additionalParams = {};
22
+ this.deviceId = this.getDeviceId();
23
+ this.userAgent = this.getUserAgent();
24
+ }
25
+ getUserAgent() {
26
+ const osType = os_1.default.type();
27
+ const osRelease = os_1.default.release();
28
+ const nodeVersion = process.version;
29
+ const arch = os_1.default.arch();
30
+ const cliVersion = require('../../package.json').version || 'unknown';
31
+ return `Node/${nodeVersion} (${osType} ${osRelease}; ${arch}) CLI/${cliVersion}`;
32
+ }
33
+ getDeviceId() {
34
+ const deviceInfo = [
35
+ os_1.default.hostname(),
36
+ os_1.default
37
+ .cpus()
38
+ .map((cpu) => cpu.model)
39
+ .join(','),
40
+ Object.values(os_1.default.networkInterfaces())
41
+ .reduce((acc, val) => acc.concat(val), [])
42
+ .filter((nic) => nic && !nic.internal && nic.mac)
43
+ .map((nic) => nic.mac)
44
+ .join(',')
45
+ ].join('|');
46
+ return crypto_1.default.createHash('sha256').update(deviceInfo).digest('hex').substring(0, 32);
47
+ }
48
+ report(eventCode, eventData = {}) {
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ const now = Date.now();
51
+ return (0, net_1.postFetch)('https://otheve.beacon.qq.com/analytics/v2_upload', {
52
+ appVersion: '',
53
+ sdkId: 'js',
54
+ sdkVersion: '4.5.14-web',
55
+ mainAppKey: '0WEB0AD0GM4PUUU1',
56
+ platformId: 3,
57
+ common: Object.assign({ A2: this.deviceId, A101: this.userAgent, from: 'tcb-cli', xDeployEnv: process.env.NODE_ENV }, this.additionalParams),
58
+ events: [
59
+ {
60
+ eventCode,
61
+ eventTime: String(now),
62
+ mapValue: Object.assign({}, eventData)
63
+ }
64
+ ]
65
+ });
66
+ });
67
+ }
68
+ addAdditionalParams(params) {
69
+ this.additionalParams = Object.assign(Object.assign({}, this.additionalParams), params);
70
+ }
71
+ }
72
+ exports.beaconAction = new BeaconAction();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/cli",
3
- "version": "2.6.13",
3
+ "version": "2.6.14",
4
4
  "description": "cli tool for cloudbase",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -34,11 +34,10 @@
34
34
  "@cloudbase/cloud-api": "^0.5.5",
35
35
  "@cloudbase/framework-core": "^1.9.7",
36
36
  "@cloudbase/functions-framework": "^1.5.0",
37
- "@cloudbase/iac-core": "^0.0.3-alpha.8",
37
+ "@cloudbase/iac-core": "^0.0.3-alpha.9",
38
38
  "@cloudbase/lowcode-cli": "^0.22.2",
39
39
  "@cloudbase/manager-node": "4.2.8",
40
40
  "@cloudbase/toolbox": "^0.7.5",
41
- "@sentry/node": "^5.10.2",
42
41
  "address": "^1.1.2",
43
42
  "camelcase-keys": "^7.0.2",
44
43
  "chalk": "^2.4.2",
@@ -0,0 +1,16 @@
1
+ declare class BeaconAction {
2
+ private deviceId;
3
+ private userAgent;
4
+ private additionalParams;
5
+ constructor();
6
+ private getUserAgent;
7
+ private getDeviceId;
8
+ report(eventCode: string, eventData?: {
9
+ [key: string]: any;
10
+ }): Promise<any>;
11
+ addAdditionalParams(params: {
12
+ [key: string]: any;
13
+ }): void;
14
+ }
15
+ export declare const beaconAction: BeaconAction;
16
+ export {};