@vectorx/xhs-cloud-cli 0.0.0-beta-20251112071234

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.
Files changed (50) hide show
  1. package/README.md +34 -0
  2. package/bin/rcb.js +264 -0
  3. package/lib/commands/agent/build.js +222 -0
  4. package/lib/commands/agent/dev.js +117 -0
  5. package/lib/commands/agent/index.js +19 -0
  6. package/lib/commands/agent/new.js +125 -0
  7. package/lib/commands/auth/index.js +18 -0
  8. package/lib/commands/auth/login.js +196 -0
  9. package/lib/commands/auth/logout.js +87 -0
  10. package/lib/commands/index.js +18 -0
  11. package/lib/constants/cmd.js +37 -0
  12. package/lib/core/base.js +95 -0
  13. package/lib/decorators/auth.js +49 -0
  14. package/lib/decorators/captureError.js +28 -0
  15. package/lib/decorators/constants.js +15 -0
  16. package/lib/decorators/index.js +20 -0
  17. package/lib/decorators/injectParams.js +57 -0
  18. package/lib/decorators/params/common.js +16 -0
  19. package/lib/decorators/params/index.js +29 -0
  20. package/lib/index.js +17 -0
  21. package/lib/main.js +20 -0
  22. package/lib/output.js +7 -0
  23. package/package.json +104 -0
  24. package/templates/chatbox-agent/.env.template +2 -0
  25. package/templates/chatbox-agent/agent-cloudbase-functions.json +11 -0
  26. package/templates/chatbox-agent/package.json +11 -0
  27. package/templates/chatbox-agent/project.config.json +5 -0
  28. package/templates/chatbox-agent/src/index.js +51 -0
  29. package/templates/weather-agent/index.js +92 -0
  30. package/templates/weather-agent/project.config.json +4 -0
  31. package/types/commands/agent/build.d.ts +26 -0
  32. package/types/commands/agent/dev.d.ts +15 -0
  33. package/types/commands/agent/index.d.ts +3 -0
  34. package/types/commands/agent/new.d.ts +16 -0
  35. package/types/commands/auth/index.d.ts +2 -0
  36. package/types/commands/auth/login.d.ts +13 -0
  37. package/types/commands/auth/logout.d.ts +7 -0
  38. package/types/commands/index.d.ts +2 -0
  39. package/types/constants/cmd.d.ts +11 -0
  40. package/types/core/base.d.ts +40 -0
  41. package/types/decorators/auth.d.ts +1 -0
  42. package/types/decorators/captureError.d.ts +1 -0
  43. package/types/decorators/constants.d.ts +11 -0
  44. package/types/decorators/index.d.ts +4 -0
  45. package/types/decorators/injectParams.d.ts +1 -0
  46. package/types/decorators/params/common.d.ts +4 -0
  47. package/types/decorators/params/index.d.ts +8 -0
  48. package/types/index.d.ts +1 -0
  49. package/types/main.d.ts +3 -0
  50. package/types/output.d.ts +3 -0
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.AgentNewCommand = void 0;
28
+ const fs_1 = __importDefault(require("fs"));
29
+ const path_1 = __importDefault(require("path"));
30
+ const chalk_1 = __importDefault(require("chalk"));
31
+ const base_1 = require("../../core/base");
32
+ const decorators_1 = require("../../decorators");
33
+ let AgentNewCommand = class AgentNewCommand extends base_1.Command {
34
+ execute(options, log) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ const { projectName, dir } = options;
37
+ if (!projectName) {
38
+ log.error("项目名称不能为空");
39
+ process.exit(1);
40
+ }
41
+ const targetDir = dir || process.cwd();
42
+ const projectDir = path_1.default.join(targetDir, projectName);
43
+ if (fs_1.default.existsSync(projectDir)) {
44
+ log.error(`项目目录已存在: ${projectDir}`);
45
+ process.exit(1);
46
+ }
47
+ log.breakLine();
48
+ console.log(chalk_1.default.bold.blue("📋 项目创建信息"));
49
+ console.log(chalk_1.default.gray("─".repeat(40)));
50
+ console.log(chalk_1.default.bold("创建目录: ") + chalk_1.default.green(projectDir));
51
+ console.log(chalk_1.default.bold("目录名称: ") + chalk_1.default.cyan(projectName));
52
+ console.log(chalk_1.default.gray("─".repeat(40)));
53
+ log.breakLine();
54
+ const templateDir = path_1.default.join(__dirname, "../../../", "templates", "chatbox-agent");
55
+ if (!fs_1.default.existsSync(templateDir)) {
56
+ log.error(`模板目录不存在: ${templateDir}`);
57
+ throw new Error(`模板目录不存在: ${templateDir}`);
58
+ }
59
+ const spinnerCopy = require("ora")("复制模板文件...").start();
60
+ try {
61
+ yield this.copyTemplate(templateDir, projectDir);
62
+ spinnerCopy.succeed("模板文件复制完成");
63
+ }
64
+ catch (e) {
65
+ spinnerCopy.fail("模板文件复制失败: " + e.message);
66
+ throw e;
67
+ }
68
+ log.breakLine();
69
+ log.info(`✔️ 项目创建成功: ${projectDir}`);
70
+ log.info("下一步操作:");
71
+ log.info(` - cd ${projectDir}`);
72
+ log.info(" - npm install");
73
+ log.info(" - npm run dev");
74
+ });
75
+ }
76
+ copyTemplate(sourceDir, targetDir) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ if (!fs_1.default.existsSync(targetDir)) {
79
+ fs_1.default.mkdirSync(targetDir, { recursive: true });
80
+ }
81
+ const files = fs_1.default.readdirSync(sourceDir);
82
+ for (const file of files) {
83
+ const sourcePath = path_1.default.join(sourceDir, file);
84
+ const targetPath = path_1.default.join(targetDir, file);
85
+ const stat = fs_1.default.statSync(sourcePath);
86
+ if (stat.isDirectory()) {
87
+ yield this.copyTemplate(sourcePath, targetPath);
88
+ }
89
+ else {
90
+ fs_1.default.copyFileSync(sourcePath, targetPath);
91
+ }
92
+ }
93
+ });
94
+ }
95
+ get options() {
96
+ return {
97
+ cmd: "agent",
98
+ childCmd: "new",
99
+ desc: "创建新的 agent 项目",
100
+ usage: "rcb agent new [templateName]",
101
+ options: [
102
+ {
103
+ flags: "-d, --dir <dir>",
104
+ desc: "指定项目创建的目标目录,默认为当前目录",
105
+ },
106
+ {
107
+ flags: "-p, --projectName <projectName>",
108
+ desc: "指定项目名称,默认为当前目录名称",
109
+ },
110
+ ],
111
+ };
112
+ }
113
+ };
114
+ exports.AgentNewCommand = AgentNewCommand;
115
+ __decorate([
116
+ (0, decorators_1.InjectParams)(),
117
+ __param(0, (0, decorators_1.ArgsOptions)()),
118
+ __param(1, (0, decorators_1.Log)()),
119
+ __metadata("design:type", Function),
120
+ __metadata("design:paramtypes", [Object, Function]),
121
+ __metadata("design:returntype", Promise)
122
+ ], AgentNewCommand.prototype, "execute", null);
123
+ exports.AgentNewCommand = AgentNewCommand = __decorate([
124
+ (0, base_1.ICommand)()
125
+ ], AgentNewCommand);
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./login"), exports);
18
+ __exportStar(require("./logout"), exports);
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.GetLoginInfoCommand = exports.LoginCommand = void 0;
25
+ const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
26
+ const chalk_1 = __importDefault(require("chalk"));
27
+ const base_1 = require("../../core/base");
28
+ let LoginCommand = class LoginCommand extends base_1.Command {
29
+ constructor() {
30
+ super();
31
+ this.authService = cloud_toolkit_1.container.get(cloud_toolkit_1.SERVICE_IDENTIFIERS.AuthService);
32
+ }
33
+ execute(ctx) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ try {
36
+ const existingLoginInfo = yield this.authService.getLoginInfo();
37
+ if (existingLoginInfo) {
38
+ cloud_toolkit_1.logger.warn("检测到您已经登录,如需切换登录信息,请先退出登录");
39
+ cloud_toolkit_1.logger.breakLine();
40
+ console.log(chalk_1.default.bold.blue("📋 当前登录信息"));
41
+ console.log(chalk_1.default.gray("─".repeat(40)));
42
+ console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("●".repeat(8) + existingLoginInfo.cli_token.slice(-8)));
43
+ console.log(chalk_1.default.bold("过期时间: ") +
44
+ chalk_1.default.yellow(new Date(existingLoginInfo.create_at + existingLoginInfo.expire_in_sec * 1000).toLocaleString("zh-CN")));
45
+ console.log(chalk_1.default.gray("─".repeat(40)));
46
+ cloud_toolkit_1.logger.breakLine();
47
+ console.log(chalk_1.default.yellow("💡 提示:如需重新登录,请先执行退出登录命令"));
48
+ console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb logout"));
49
+ return;
50
+ }
51
+ const { secretId, secretKey } = ctx.options;
52
+ if (!secretId || !secretKey) {
53
+ cloud_toolkit_1.logger.error("登录秘钥(secretId, secretKey)不能为空");
54
+ cloud_toolkit_1.logger.breakLine();
55
+ console.log(chalk_1.default.yellow("💡 请前往「小红书小程序开发平台」获取登录秘钥 (secretId, secretKey)"));
56
+ cloud_toolkit_1.logger.printClickableLink("请前往 https://miniapp.xiaohongshu.com/console-panel");
57
+ cloud_toolkit_1.logger.breakLine();
58
+ console.log(chalk_1.default.gray(" 获取秘钥后,您可以执行以下命令进行登录: "));
59
+ console.log(chalk_1.default.gray(" rcb login --secretId <secretId> --secretKey <secretKey>"));
60
+ cloud_toolkit_1.logger.breakLine();
61
+ process.exit(1);
62
+ }
63
+ let loginInfo = null;
64
+ if (this.authService.hasLogin()) {
65
+ loginInfo = yield this.authService.getLoginInfo();
66
+ }
67
+ if (loginInfo) {
68
+ cloud_toolkit_1.logger.error("检测到您已经登录,如需切换登录信息,请先退出登录");
69
+ cloud_toolkit_1.logger.breakLine();
70
+ console.log(chalk_1.default.bold.blue("📋 当前登录信息"));
71
+ console.log(chalk_1.default.gray("─".repeat(40)));
72
+ console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("●".repeat(8) + loginInfo.cli_token.slice(-8)));
73
+ console.log(chalk_1.default.bold("过期时间: ") + chalk_1.default.yellow(new Date(loginInfo.expire_in_sec).toLocaleString("zh-CN")));
74
+ console.log(chalk_1.default.gray("─".repeat(40)));
75
+ cloud_toolkit_1.logger.breakLine();
76
+ console.log(chalk_1.default.yellow("💡 提示:如需重新登录,请先执行退出登录命令"));
77
+ console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb logout"));
78
+ return;
79
+ }
80
+ const spinner = require("ora")("正在验证小红书云服务密钥信息...").start();
81
+ try {
82
+ const nonce = (0, cloud_toolkit_1.getNonce)();
83
+ const cliToken = this.authService.getToken(secretId, secretKey, nonce);
84
+ const { code, data, msg } = yield this.authService.check({
85
+ secret_id: secretId,
86
+ nonce,
87
+ cli_token: cliToken,
88
+ });
89
+ if (code !== 0) {
90
+ cloud_toolkit_1.logger.error(`密钥验证失败,请检查密钥是否正确或终端网络是否可用: ${msg}`);
91
+ process.exit(1);
92
+ }
93
+ try {
94
+ yield this.authService.saveLoginInfo({
95
+ secret_id: secretId,
96
+ cli_token: cliToken,
97
+ create_at: Date.now(),
98
+ expire_in_sec: data.expire_in_sec,
99
+ });
100
+ }
101
+ catch (error) {
102
+ cloud_toolkit_1.logger.error(`保存登录信息失败: ${error.message}`);
103
+ process.exit(1);
104
+ }
105
+ spinner.succeed();
106
+ cloud_toolkit_1.logger.breakLine();
107
+ const expireTime = new Date(Date.now() + data.expire_in_sec * 1000);
108
+ cloud_toolkit_1.logger.info(`获取 access_token 成功: ${chalk_1.default.green(data.cli_token)}`);
109
+ cloud_toolkit_1.logger.info(`access_token 过期时间: ${chalk_1.default.yellow(expireTime.toLocaleString("zh-CN"))}`);
110
+ cloud_toolkit_1.logger.breakLine();
111
+ cloud_toolkit_1.logger.success("🎉 登录成功!欢迎使用小红书云服务 CLI");
112
+ }
113
+ catch (error) {
114
+ spinner.fail("登录验证失败");
115
+ throw error;
116
+ }
117
+ }
118
+ catch (error) {
119
+ cloud_toolkit_1.logger.error(`❌ 登录失败: ${error.message}`);
120
+ cloud_toolkit_1.logger.breakLine();
121
+ console.log(chalk_1.default.gray("💡 常见问题:"));
122
+ console.log(chalk_1.default.gray(" • 请检查 token 是否正确"));
123
+ console.log(chalk_1.default.gray(" • 请确保网络连接正常"));
124
+ process.exit(1);
125
+ }
126
+ });
127
+ }
128
+ get options() {
129
+ return {
130
+ cmd: "login",
131
+ desc: "登录小红书云服务",
132
+ options: [
133
+ {
134
+ flags: "-s, --secretId <secretId>",
135
+ desc: "小红书云服务 API 秘钥 Id",
136
+ required: true,
137
+ },
138
+ {
139
+ flags: "-k, --secretKey <secretKey>",
140
+ desc: "小红书云服务 API 秘钥 Key",
141
+ required: true,
142
+ },
143
+ ],
144
+ };
145
+ }
146
+ };
147
+ exports.LoginCommand = LoginCommand;
148
+ exports.LoginCommand = LoginCommand = __decorate([
149
+ (0, base_1.ICommand)(),
150
+ __metadata("design:paramtypes", [])
151
+ ], LoginCommand);
152
+ let GetLoginInfoCommand = class GetLoginInfoCommand extends base_1.Command {
153
+ constructor() {
154
+ super();
155
+ this.authService = new cloud_toolkit_1.AuthService();
156
+ }
157
+ execute(ctx) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ try {
160
+ const loginInfo = yield this.authService.getLoginInfo();
161
+ if (!loginInfo) {
162
+ cloud_toolkit_1.logger.error("未登录或登录已过期");
163
+ cloud_toolkit_1.logger.breakLine();
164
+ console.log(chalk_1.default.yellow("💡 提示:请先执行登录命令"));
165
+ console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb login --secretId <secretId> --secretKey <secretKey>"));
166
+ process.exit(1);
167
+ }
168
+ cloud_toolkit_1.logger.breakLine();
169
+ console.log(chalk_1.default.bold.blue("📋 当前登录信息"));
170
+ console.log(chalk_1.default.gray("─".repeat(40)));
171
+ console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("●".repeat(8) + loginInfo.cli_token.slice(-8)));
172
+ console.log(chalk_1.default.bold("过期时间: ") +
173
+ chalk_1.default.yellow(new Date(loginInfo.create_at + loginInfo.expire_in_sec * 1000).toLocaleString("zh-CN")));
174
+ console.log(chalk_1.default.gray("─".repeat(40)));
175
+ cloud_toolkit_1.logger.breakLine();
176
+ }
177
+ catch (error) {
178
+ cloud_toolkit_1.logger.error(`获取登录信息失败: ${error.message}`);
179
+ process.exit(1);
180
+ }
181
+ });
182
+ }
183
+ get options() {
184
+ return {
185
+ cmd: "login",
186
+ childCmd: "get",
187
+ desc: "获取当前登录用户信息",
188
+ options: [],
189
+ };
190
+ }
191
+ };
192
+ exports.GetLoginInfoCommand = GetLoginInfoCommand;
193
+ exports.GetLoginInfoCommand = GetLoginInfoCommand = __decorate([
194
+ (0, base_1.ICommand)(),
195
+ __metadata("design:paramtypes", [])
196
+ ], GetLoginInfoCommand);
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
12
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13
+ return new (P || (P = Promise))(function (resolve, reject) {
14
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
15
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
16
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
17
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
18
+ });
19
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.LogoutCommand = void 0;
25
+ const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
26
+ const chalk_1 = __importDefault(require("chalk"));
27
+ const inversify_1 = require("inversify");
28
+ const base_1 = require("../../core/base");
29
+ let LogoutCommand = class LogoutCommand extends base_1.Command {
30
+ constructor() {
31
+ super();
32
+ this.authService = cloud_toolkit_1.container.get(cloud_toolkit_1.SERVICE_IDENTIFIERS.AuthService);
33
+ }
34
+ execute(ctx) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ try {
37
+ const loginInfo = yield this.authService.getLoginInfo();
38
+ if (!loginInfo) {
39
+ cloud_toolkit_1.logger.warn("当前未登录,无需退出");
40
+ cloud_toolkit_1.logger.breakLine();
41
+ console.log(chalk_1.default.gray("💡 提示:如需登录,请使用以下命令"));
42
+ console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb login -k <key>"));
43
+ return;
44
+ }
45
+ cloud_toolkit_1.logger.breakLine();
46
+ console.log(chalk_1.default.bold.yellow("📋 当前登录信息"));
47
+ console.log(chalk_1.default.gray("─".repeat(40)));
48
+ console.log(chalk_1.default.bold("Token: ") + chalk_1.default.green("*".repeat(8) + loginInfo.cli_token.slice(-8)));
49
+ console.log(chalk_1.default.gray("─".repeat(40)));
50
+ cloud_toolkit_1.logger.breakLine();
51
+ const spinner = require("ora")("正在清除登录信息...").start();
52
+ try {
53
+ yield this.authService.clearLoginInfo();
54
+ spinner.succeed("登录信息已清除");
55
+ cloud_toolkit_1.logger.breakLine();
56
+ cloud_toolkit_1.logger.success("👋 退出登录成功!");
57
+ cloud_toolkit_1.logger.info("本地登录信息已清除,如需重新登录请使用 login 命令");
58
+ }
59
+ catch (error) {
60
+ spinner.fail("清除登录信息失败");
61
+ throw error;
62
+ }
63
+ }
64
+ catch (error) {
65
+ cloud_toolkit_1.logger.error(`❌ 退出登录失败: ${error.message}`);
66
+ cloud_toolkit_1.logger.breakLine();
67
+ console.log(chalk_1.default.gray("💡 可能的解决方案:"));
68
+ console.log(chalk_1.default.gray(" • 请检查文件权限"));
69
+ console.log(chalk_1.default.gray(" • 请确保配置文件未被其他进程占用"));
70
+ process.exit(1);
71
+ }
72
+ });
73
+ }
74
+ get options() {
75
+ return {
76
+ cmd: "logout",
77
+ desc: "退出登录并清除本地登录信息",
78
+ options: [],
79
+ };
80
+ }
81
+ };
82
+ exports.LogoutCommand = LogoutCommand;
83
+ exports.LogoutCommand = LogoutCommand = __decorate([
84
+ (0, base_1.ICommand)(),
85
+ (0, inversify_1.injectable)(),
86
+ __metadata("design:paramtypes", [])
87
+ ], LogoutCommand);
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./auth"), exports);
18
+ __exportStar(require("./agent"), exports);
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ALL_COMMANDS = exports.COMMAND = exports.EVENT = void 0;
4
+ var EVENT;
5
+ (function (EVENT) {
6
+ EVENT["PROCESS_EXIT"] = "processExit";
7
+ EVENT["PROCESS_ERROR"] = "processError";
8
+ })(EVENT || (exports.EVENT = EVENT = {}));
9
+ var COMMAND;
10
+ (function (COMMAND) {
11
+ COMMAND["LOGIN"] = "login";
12
+ COMMAND["ENV"] = "env";
13
+ COMMAND["FN"] = "fn";
14
+ COMMAND["AGENT"] = "agent";
15
+ })(COMMAND || (exports.COMMAND = COMMAND = {}));
16
+ exports.ALL_COMMANDS = [
17
+ "login",
18
+ "login get",
19
+ "logout",
20
+ "agent dev",
21
+ "agent build",
22
+ "agent deploy",
23
+ "agent list",
24
+ "env list",
25
+ "env domain list",
26
+ "env domain create",
27
+ "env domain delete",
28
+ "fn list",
29
+ "fn download",
30
+ "fn deploy",
31
+ "fn delete",
32
+ "fn detail",
33
+ "fn code update",
34
+ "fn invoke",
35
+ "fn publish-version",
36
+ "fn list-function-versions",
37
+ ];
@@ -0,0 +1,95 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Command = exports.registrableCommands = void 0;
13
+ exports.ICommand = ICommand;
14
+ const commander_1 = require("commander");
15
+ exports.registrableCommands = [];
16
+ function ICommand() {
17
+ return (target) => {
18
+ exports.registrableCommands.push({ Command: target });
19
+ };
20
+ }
21
+ const cmdMap = new Map();
22
+ class Command {
23
+ init() {
24
+ const { cmd, childCmd, childSubCmd, deprecateCmd } = this.options;
25
+ let instance;
26
+ if (cmdMap.has(cmd)) {
27
+ instance = cmdMap.get(cmd);
28
+ }
29
+ else {
30
+ instance = commander_1.program.command(cmd);
31
+ instance._helpDescription = "输出帮助信息";
32
+ instance.addHelpCommand("help [command]", "查看命令帮助信息");
33
+ cmdMap.set(cmd, instance);
34
+ }
35
+ if (childCmd) {
36
+ let cmdKey;
37
+ let cmdName;
38
+ let desc;
39
+ if (typeof childCmd === "string") {
40
+ cmdKey = `${cmd}-${childCmd}`;
41
+ cmdName = childCmd;
42
+ }
43
+ else {
44
+ cmdKey = `${cmd}-${childCmd.cmd}`;
45
+ cmdName = childCmd.cmd;
46
+ desc = childCmd.desc;
47
+ }
48
+ if (cmdMap.has(cmdKey)) {
49
+ instance = cmdMap.get(cmdKey);
50
+ }
51
+ else {
52
+ instance = instance.command(cmdName);
53
+ instance._helpDescription = "查看命令帮助信息";
54
+ desc && instance.description(desc);
55
+ cmdMap.set(cmdKey, instance);
56
+ }
57
+ if (childSubCmd) {
58
+ instance = instance.command(childSubCmd);
59
+ }
60
+ }
61
+ this.createProgram(instance, false);
62
+ if (deprecateCmd) {
63
+ const newCmd = [cmd, childCmd, childSubCmd]
64
+ .filter((_) => _)
65
+ .map((item) => {
66
+ if (typeof item === "string")
67
+ return item;
68
+ return item.cmd;
69
+ })
70
+ .join(" ");
71
+ this.createProgram(commander_1.program.command(deprecateCmd), true, newCmd);
72
+ }
73
+ }
74
+ createProgram(instance, deprecate, newCmd) {
75
+ const { cmd, desc, options } = this.options;
76
+ instance.storeOptionsAsProperties(false);
77
+ options.forEach((option) => {
78
+ const { hideHelp } = option;
79
+ if (hideHelp) {
80
+ instance.addOption(new commander_1.Option(option.flags, option.desc).hideHelp());
81
+ }
82
+ else {
83
+ instance.option(option.flags, option.desc);
84
+ }
85
+ });
86
+ instance.description(desc);
87
+ instance.action((...args) => __awaiter(this, void 0, void 0, function* () {
88
+ const params = args.slice(0, -1);
89
+ const cmdOptions = instance.opts();
90
+ const ctx = { cmd, params, options: cmdOptions };
91
+ yield this.execute(ctx);
92
+ }));
93
+ }
94
+ }
95
+ exports.Command = Command;
@@ -0,0 +1,49 @@
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.AuthGuard = AuthGuard;
16
+ const cloud_toolkit_1 = require("@vectorx/cloud-toolkit");
17
+ const cloud_toolkit_2 = require("@vectorx/cloud-toolkit");
18
+ const chalk_1 = __importDefault(require("chalk"));
19
+ function AuthGuard() {
20
+ return (target) => {
21
+ const originalExecute = target.prototype.execute;
22
+ target.prototype.execute = function (ctx) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ try {
25
+ if (cloud_toolkit_2.isIDE) {
26
+ return originalExecute.call(this, ctx);
27
+ }
28
+ }
29
+ catch (error) {
30
+ console.log(error);
31
+ }
32
+ const authService = cloud_toolkit_2.container.get(cloud_toolkit_2.SERVICE_IDENTIFIERS.AuthService);
33
+ const loginInfo = yield authService.getLoginInfo();
34
+ if (!loginInfo) {
35
+ cloud_toolkit_1.logger.error(`Warning: 执行当前命令需要先登录~`);
36
+ cloud_toolkit_1.logger.breakLine();
37
+ console.log(chalk_1.default.yellow("💡提示:请先执行登录命令"));
38
+ console.log(chalk_1.default.gray(" 使用命令: ") + chalk_1.default.cyan("rcb login --secretId <secretId> --secretKey <secretKey>"));
39
+ cloud_toolkit_1.logger.breakLine();
40
+ console.log(chalk_1.default.gray("🔗 获取登录秘钥:https://miniapp.xiaohongshu.com/console-panel"));
41
+ cloud_toolkit_1.logger.breakLine();
42
+ process.exit(1);
43
+ }
44
+ return originalExecute.call(this, ctx);
45
+ });
46
+ };
47
+ return target;
48
+ };
49
+ }
@@ -0,0 +1,28 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CaptureError = void 0;
13
+ const CaptureError = () => (target, key, descriptor) => {
14
+ const rawFunc = descriptor.value;
15
+ descriptor.value = function (...args) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ const res = yield rawFunc.apply(this, args);
19
+ return res;
20
+ }
21
+ catch (e) {
22
+ const errMsg = (e === null || e === void 0 ? void 0 : e.message) || (typeof (e === null || e === void 0 ? void 0 : e.toString) === "function" ? e.toString() : "") || "Unknown Error";
23
+ }
24
+ });
25
+ };
26
+ return descriptor;
27
+ };
28
+ exports.CaptureError = CaptureError;