@cloudbase/cli 2.10.0-beta.0 → 2.11.0-beta.0

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 (205) hide show
  1. package/lib/auth/login.js +51 -65
  2. package/lib/auth/logout.js +3 -14
  3. package/lib/commands/account/login.js +136 -149
  4. package/lib/commands/account/logout.js +3 -14
  5. package/lib/commands/ag/base.js +203 -0
  6. package/lib/commands/ag/create.js +301 -0
  7. package/lib/commands/ag/debug/index.html +699 -0
  8. package/lib/commands/ag/delete.js +200 -0
  9. package/lib/commands/ag/deploy.js +185 -0
  10. package/lib/commands/ag/detail.js +113 -0
  11. package/lib/commands/ag/index.js +22 -0
  12. package/lib/commands/ag/list.js +155 -0
  13. package/lib/commands/ag/run.js +644 -0
  14. package/lib/commands/ai/index.js +76 -95
  15. package/lib/commands/cloudfunction/base.js +182 -203
  16. package/lib/commands/cloudrun/base.js +578 -603
  17. package/lib/commands/common.js +48 -63
  18. package/lib/commands/config/delete.js +16 -27
  19. package/lib/commands/config/get.js +13 -24
  20. package/lib/commands/config/list.js +16 -27
  21. package/lib/commands/config/set.js +33 -44
  22. package/lib/commands/db/base.js +221 -240
  23. package/lib/commands/env/base.js +36 -49
  24. package/lib/commands/env/domain.js +79 -94
  25. package/lib/commands/env/login.js +120 -135
  26. package/lib/commands/framework/index.js +32 -49
  27. package/lib/commands/fun/base.js +223 -244
  28. package/lib/commands/functions/alias/getRoute.js +33 -44
  29. package/lib/commands/functions/alias/setRoute.js +36 -47
  30. package/lib/commands/functions/code-download.js +43 -54
  31. package/lib/commands/functions/code-update.js +23 -34
  32. package/lib/commands/functions/concurrency/delete.js +11 -22
  33. package/lib/commands/functions/concurrency/list.js +20 -31
  34. package/lib/commands/functions/concurrency/set.js +13 -24
  35. package/lib/commands/functions/config-update.js +30 -41
  36. package/lib/commands/functions/copy.js +12 -23
  37. package/lib/commands/functions/delete.js +30 -41
  38. package/lib/commands/functions/deploy.js +184 -202
  39. package/lib/commands/functions/detail.js +23 -34
  40. package/lib/commands/functions/invoke.js +69 -75
  41. package/lib/commands/functions/layer/bind.js +102 -105
  42. package/lib/commands/functions/layer/create.js +29 -35
  43. package/lib/commands/functions/layer/delete.js +42 -48
  44. package/lib/commands/functions/layer/download.js +52 -58
  45. package/lib/commands/functions/layer/list.js +44 -50
  46. package/lib/commands/functions/layer/sort.js +39 -45
  47. package/lib/commands/functions/list.js +25 -36
  48. package/lib/commands/functions/log.js +65 -73
  49. package/lib/commands/functions/run.js +118 -116
  50. package/lib/commands/functions/trigger-create.js +32 -43
  51. package/lib/commands/functions/trigger-delete.js +50 -61
  52. package/lib/commands/functions/version/list.js +29 -40
  53. package/lib/commands/functions/version/publish.js +11 -22
  54. package/lib/commands/gateway/create.js +50 -61
  55. package/lib/commands/gateway/delete.js +38 -49
  56. package/lib/commands/gateway/domain.js +65 -80
  57. package/lib/commands/gateway/list.js +31 -42
  58. package/lib/commands/gateway/switch.js +48 -61
  59. package/lib/commands/helpers/init.js +226 -249
  60. package/lib/commands/helpers/new.js +35 -46
  61. package/lib/commands/helpers/open.js +22 -33
  62. package/lib/commands/hosting/hosting.js +157 -178
  63. package/lib/commands/index.js +1 -0
  64. package/lib/commands/lowcode/app.js +114 -144
  65. package/lib/commands/lowcode/comps.js +136 -127
  66. package/lib/commands/lowcode/utils.js +11 -22
  67. package/lib/commands/pull/pull.js +33 -46
  68. package/lib/commands/run/delete.js +35 -46
  69. package/lib/commands/run/image/delete.js +32 -39
  70. package/lib/commands/run/image/download.js +26 -33
  71. package/lib/commands/run/image/list.js +41 -48
  72. package/lib/commands/run/image/upload.js +26 -33
  73. package/lib/commands/run/list.js +32 -43
  74. package/lib/commands/run/service/config.js +17 -28
  75. package/lib/commands/run/service/deploy.js +15 -26
  76. package/lib/commands/run/service/list.js +48 -59
  77. package/lib/commands/run/service/update.js +7 -18
  78. package/lib/commands/run/standalonegateway/create.js +35 -42
  79. package/lib/commands/run/standalonegateway/destroy.js +23 -30
  80. package/lib/commands/run/standalonegateway/list.js +19 -26
  81. package/lib/commands/run/standalonegateway/package.js +31 -38
  82. package/lib/commands/run/standalonegateway/turn.js +27 -34
  83. package/lib/commands/run/version/create.js +198 -205
  84. package/lib/commands/run/version/delete.js +31 -38
  85. package/lib/commands/run/version/list.js +42 -49
  86. package/lib/commands/run/version/modify.js +27 -34
  87. package/lib/commands/run/version/update.js +201 -208
  88. package/lib/commands/runf/base.js +216 -237
  89. package/lib/commands/self-update.js +59 -72
  90. package/lib/commands/smart.js +66 -79
  91. package/lib/commands/storage/storage.js +192 -219
  92. package/lib/commands/third/thirdAttach.js +16 -27
  93. package/lib/commands/utils.js +119 -149
  94. package/lib/db/index.js +48 -67
  95. package/lib/decorators/captureError.js +10 -21
  96. package/lib/decorators/guard.js +11 -22
  97. package/lib/decorators/injectParams.js +29 -40
  98. package/lib/decorators/params/common.js +5 -2
  99. package/lib/decorators/params/index.js +3 -12
  100. package/lib/env/domain.js +13 -28
  101. package/lib/env/index.js +25 -44
  102. package/lib/env/login.js +30 -45
  103. package/lib/function/alias.js +31 -44
  104. package/lib/function/base.js +187 -215
  105. package/lib/function/code.js +8 -19
  106. package/lib/function/concurrency.js +43 -58
  107. package/lib/function/create.js +43 -53
  108. package/lib/function/delete.js +22 -35
  109. package/lib/function/layer/attach.js +33 -46
  110. package/lib/function/layer/create.js +34 -45
  111. package/lib/function/layer/delete.js +5 -16
  112. package/lib/function/layer/download.js +11 -22
  113. package/lib/function/layer/list.js +12 -25
  114. package/lib/function/layer/sort.js +6 -17
  115. package/lib/function/trigger.js +65 -82
  116. package/lib/function/update.js +24 -32
  117. package/lib/function/version.js +29 -42
  118. package/lib/function/vpc.js +12 -25
  119. package/lib/gateway/index.js +77 -104
  120. package/lib/hosting.js +157 -188
  121. package/lib/run/delete.js +3 -12
  122. package/lib/run/image/build.js +6 -15
  123. package/lib/run/image/delete.js +3 -12
  124. package/lib/run/image/info.js +3 -12
  125. package/lib/run/image/list.js +6 -15
  126. package/lib/run/list.js +19 -30
  127. package/lib/run/repo.js +6 -15
  128. package/lib/run/service/common.js +160 -173
  129. package/lib/run/service/config.js +44 -57
  130. package/lib/run/service/deployPackage.js +33 -44
  131. package/lib/run/service/list.js +8 -14
  132. package/lib/run/service/showLogs.js +69 -90
  133. package/lib/run/service/update.js +50 -63
  134. package/lib/run/standalonegateway/create.js +3 -12
  135. package/lib/run/standalonegateway/destroy.js +3 -12
  136. package/lib/run/standalonegateway/list.js +3 -12
  137. package/lib/run/standalonegateway/package/list.js +3 -12
  138. package/lib/run/standalonegateway/turn/off.js +3 -12
  139. package/lib/run/standalonegateway/turn/on.js +3 -12
  140. package/lib/run/version/create.js +41 -31
  141. package/lib/run/version/delete.js +3 -12
  142. package/lib/run/version/list.js +3 -12
  143. package/lib/run/version/modify.js +3 -12
  144. package/lib/run/version/repo.js +6 -15
  145. package/lib/run/version/update.js +37 -26
  146. package/lib/storage.js +62 -93
  147. package/lib/third/index.js +6 -17
  148. package/lib/utils/ai/banner.js +49 -60
  149. package/lib/utils/ai/claudeWindows.js +2 -2
  150. package/lib/utils/ai/config.js +169 -206
  151. package/lib/utils/ai/ensureFiles.js +6 -17
  152. package/lib/utils/ai/env.js +16 -27
  153. package/lib/utils/ai/envLocalManager.js +35 -52
  154. package/lib/utils/ai/router.js +927 -1005
  155. package/lib/utils/ai/setup.js +527 -563
  156. package/lib/utils/auth.js +3 -14
  157. package/lib/utils/checkTcbrEnv.js +20 -31
  158. package/lib/utils/cli-table.js +6 -1
  159. package/lib/utils/config.js +4 -13
  160. package/lib/utils/dts.js +98 -113
  161. package/lib/utils/env.js +154 -175
  162. package/lib/utils/function-packer.js +29 -42
  163. package/lib/utils/log.js +10 -21
  164. package/lib/utils/mcp-config-modifier.js +105 -120
  165. package/lib/utils/net/cloud-api-request.js +15 -23
  166. package/lib/utils/net/credential.js +26 -39
  167. package/lib/utils/net/http-request.js +63 -80
  168. package/lib/utils/net/manager-service.js +22 -35
  169. package/lib/utils/notice.js +16 -27
  170. package/lib/utils/output/loading.js +3 -12
  171. package/lib/utils/parallel.js +32 -43
  172. package/lib/utils/platform/mac.js +4 -15
  173. package/lib/utils/platform/port.js +4 -15
  174. package/lib/utils/prompt/select.js +6 -15
  175. package/lib/utils/report.js +28 -33
  176. package/lib/utils/reporter/agree.js +11 -22
  177. package/lib/utils/reporter/download.js +17 -28
  178. package/lib/utils/reporter/usage.js +12 -23
  179. package/lib/utils/store/auth.js +17 -30
  180. package/lib/utils/store/config.js +11 -25
  181. package/lib/utils/store/db.js +17 -36
  182. package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
  183. package/lib/utils/template-manager.js +215 -242
  184. package/lib/utils/template.js +81 -96
  185. package/lib/utils/tools/common.js +45 -56
  186. package/lib/utils/tools/time.js +5 -16
  187. package/lib/utils/url.js +10 -4
  188. package/package.json +2 -2
  189. package/specs/ag-command/design.md +421 -0
  190. package/specs/ag-command/doc.md +204 -0
  191. package/specs/ag-command/requirements.md +173 -0
  192. package/specs/ag-command/summary.md +174 -0
  193. package/specs/ag-command/tasks.md +197 -0
  194. package/specs/ag-command/usage-guide.md +420 -0
  195. package/tsconfig.json +1 -1
  196. package/types/commands/ag/base.d.ts +44 -0
  197. package/types/commands/ag/create.d.ts +25 -0
  198. package/types/commands/ag/delete.d.ts +32 -0
  199. package/types/commands/ag/deploy.d.ts +31 -0
  200. package/types/commands/ag/detail.d.ts +28 -0
  201. package/types/commands/ag/index.d.ts +6 -0
  202. package/types/commands/ag/list.d.ts +35 -0
  203. package/types/commands/ag/run.d.ts +52 -0
  204. package/types/commands/cloudrun/base.d.ts +10 -0
  205. package/types/commands/index.d.ts +1 -0
package/lib/auth/login.js CHANGED
@@ -1,13 +1,4 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -39,73 +30,68 @@ const LoginRes = {
39
30
  };
40
31
  }
41
32
  };
42
- function loginByWebAuth() {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- try {
45
- const credential = yield utils_1.authSupevisor.loginByWebAuth({
46
- getAuthUrl: (rawUrl) => {
47
- if ((0, i18n_1.isIntl)()) {
48
- return rawUrl.replace('https://tcb.cloud.tencent.com/dev', utils_1.EUrl.DevPlatform);
49
- }
50
- return rawUrl;
33
+ async function loginByWebAuth() {
34
+ try {
35
+ const credential = await utils_1.authSupevisor.loginByWebAuth({
36
+ getAuthUrl: (rawUrl) => {
37
+ if ((0, i18n_1.isIntl)()) {
38
+ return rawUrl.replace('https://tcb.cloud.tencent.com/dev', utils_1.EUrl.DevPlatform);
51
39
  }
52
- });
53
- if (lodash_1.default.isEmpty(credential)) {
54
- return LoginRes.INVALID_TOKEN;
40
+ return rawUrl;
55
41
  }
56
- return Object.assign({ credential }, LoginRes.SUCCESS);
57
- }
58
- catch (error) {
59
- console.error((0, i18n_1.t)('Web 授权登录失败,可能是环境兼容性问题'));
60
- console.error((0, i18n_1.t)('建议使用密钥登录:tcb login --key'));
61
- console.error((0, i18n_1.t)('详细说明请参考:{{url}}', { url: 'https://docs.cloudbase.net/cli-v1/login#%E8%85%BE%E8%AE%AF%E4%BA%91-%E4%BA%91%E5%BC%80%E5%8F%91%E6%8E%A7%E5%88%B6%E5%8F%B0%E6%8E%88%E6%9D%83' }));
62
- return {
63
- code: 'WEB_AUTH_FAILED',
64
- msg: (0, i18n_1.t)('Web 授权登录失败,请使用密钥登录:tcb login --key'),
65
- error: error.message
66
- };
67
- }
68
- });
69
- }
70
- exports.loginByWebAuth = loginByWebAuth;
71
- function loginWithKey(secretId, secretKey, token) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- if (!secretId || !secretKey) {
74
- return LoginRes.INVALID_PARAM((0, i18n_1.t)('SecretID 或 SecretKey 不能为空'));
75
- }
76
- const credential = yield utils_1.authSupevisor.loginByApiSecret(secretId, secretKey, token);
42
+ });
77
43
  if (lodash_1.default.isEmpty(credential)) {
78
44
  return LoginRes.INVALID_TOKEN;
79
45
  }
80
- return LoginRes.SUCCESS;
81
- });
46
+ return {
47
+ credential,
48
+ ...LoginRes.SUCCESS
49
+ };
50
+ }
51
+ catch (error) {
52
+ console.error((0, i18n_1.t)('Web 授权登录失败,可能是环境兼容性问题'));
53
+ console.error((0, i18n_1.t)('建议使用密钥登录:tcb login --key'));
54
+ console.error((0, i18n_1.t)('详细说明请参考:{{url}}', { url: 'https://docs.cloudbase.net/cli-v1/login#%E8%85%BE%E8%AE%AF%E4%BA%91-%E4%BA%91%E5%BC%80%E5%8F%91%E6%8E%A7%E5%88%B6%E5%8F%B0%E6%8E%88%E6%9D%83' }));
55
+ return {
56
+ code: 'WEB_AUTH_FAILED',
57
+ msg: (0, i18n_1.t)('Web 授权登录失败,请使用密钥登录:tcb login --key'),
58
+ error: error.message
59
+ };
60
+ }
61
+ }
62
+ exports.loginByWebAuth = loginByWebAuth;
63
+ async function loginWithKey(secretId, secretKey, token) {
64
+ if (!secretId || !secretKey) {
65
+ return LoginRes.INVALID_PARAM((0, i18n_1.t)('SecretID 或 SecretKey 不能为空'));
66
+ }
67
+ const credential = await utils_1.authSupevisor.loginByApiSecret(secretId, secretKey, token);
68
+ if (lodash_1.default.isEmpty(credential)) {
69
+ return LoginRes.INVALID_TOKEN;
70
+ }
71
+ return LoginRes.SUCCESS;
82
72
  }
83
73
  exports.loginWithKey = loginWithKey;
84
- function login(options = {}) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- const { secretId, secretKey, key, token } = options;
87
- return key ? loginWithKey(secretId, secretKey, token) : loginByWebAuth();
88
- });
74
+ async function login(options = {}) {
75
+ const { secretId, secretKey, key, token } = options;
76
+ return key ? loginWithKey(secretId, secretKey, token) : loginByWebAuth();
89
77
  }
90
78
  exports.login = login;
91
- function checkLogin() {
79
+ async function checkLogin() {
92
80
  var _a;
93
- return __awaiter(this, void 0, void 0, function* () {
94
- const credential = yield (0, utils_1.checkAndGetCredential)();
95
- if (lodash_1.default.isEmpty(credential)) {
96
- log.info((0, i18n_1.t)('你还没有登录,请在控制台中授权登录'));
97
- const res = yield (0, utils_1.execWithLoading)(() => login(), {
98
- startTip: (0, i18n_1.t)('请在浏览器中打开的授权页面进行授权...'),
99
- successTip: (0, i18n_1.t)('授权登录成功!')
100
- });
101
- const envId = (_a = res === null || res === void 0 ? void 0 : res.credential) === null || _a === void 0 ? void 0 : _a.envId;
102
- if (envId) {
103
- const env = yield (0, env_1.getEnvInfo)(envId);
104
- if (env.Status === "UNAVAILABLE") {
105
- yield (0, utils_1.checkEnvAvaliable)(envId);
106
- }
81
+ const credential = await (0, utils_1.checkAndGetCredential)();
82
+ if (lodash_1.default.isEmpty(credential)) {
83
+ log.info((0, i18n_1.t)('你还没有登录,请在控制台中授权登录'));
84
+ const res = await (0, utils_1.execWithLoading)(() => login(), {
85
+ startTip: (0, i18n_1.t)('请在浏览器中打开的授权页面进行授权...'),
86
+ successTip: (0, i18n_1.t)('授权登录成功!')
87
+ });
88
+ const envId = (_a = res === null || res === void 0 ? void 0 : res.credential) === null || _a === void 0 ? void 0 : _a.envId;
89
+ if (envId) {
90
+ const env = await (0, env_1.getEnvInfo)(envId);
91
+ if (env.Status === "UNAVAILABLE") {
92
+ await (0, utils_1.checkEnvAvaliable)(envId);
107
93
  }
108
94
  }
109
- });
95
+ }
110
96
  }
111
97
  exports.checkLogin = checkLogin;
@@ -1,20 +1,9 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.logout = void 0;
13
4
  const utils_1 = require("../utils");
14
- function logout() {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- process.emit('logout');
17
- yield utils_1.authSupevisor.logout();
18
- });
5
+ async function logout() {
6
+ process.emit('logout');
7
+ await utils_1.authSupevisor.logout();
19
8
  }
20
9
  exports.logout = logout;
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
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
14
  var __importDefault = (this && this.__importDefault) || function (mod) {
24
15
  return (mod && mod.__esModule) ? mod : { "default": mod };
25
16
  };
@@ -49,22 +40,20 @@ ${chalk_1.default.gray('–')} ${(0, i18n_1.t)('查看命令使用介绍')}
49
40
  ${(0, i18n_1.t)('Tips:可以使用简写命令 tcb 代替 cloudbase')}`;
50
41
  console.log(tips);
51
42
  }
52
- function askForCollectDataConfirm() {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const agree = yield utils_1.usageStore.get('agreeCollect');
55
- if (agree)
56
- return;
57
- const { confirm } = yield inquirer_1.default.prompt({
58
- type: 'confirm',
59
- name: 'confirm',
60
- message: (0, i18n_1.t)('是否同意 Cloudbase CLI 收集您的使用数据以改进产品?'),
61
- default: true
62
- });
63
- if (confirm) {
64
- yield utils_1.usageStore.set('agreeCollect', true);
65
- }
66
- yield (0, utils_1.collectAgree)(confirm);
43
+ async function askForCollectDataConfirm() {
44
+ const agree = await utils_1.usageStore.get('agreeCollect');
45
+ if (agree)
46
+ return;
47
+ const { confirm } = await inquirer_1.default.prompt({
48
+ type: 'confirm',
49
+ name: 'confirm',
50
+ message: (0, i18n_1.t)('是否同意 Cloudbase CLI 收集您的使用数据以改进产品?'),
51
+ default: true
67
52
  });
53
+ if (confirm) {
54
+ await utils_1.usageStore.set('agreeCollect', true);
55
+ }
56
+ await (0, utils_1.collectAgree)(confirm);
68
57
  }
69
58
  let LoginCommand = class LoginCommand extends common_1.Command {
70
59
  get options() {
@@ -93,149 +82,147 @@ let LoginCommand = class LoginCommand extends common_1.Command {
93
82
  withoutAuth: true
94
83
  };
95
84
  }
96
- execute(options, log) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- log.verbose(options);
99
- const { apiKeyId, apiKey, token } = options;
100
- const loading = (0, utils_1.loadingFactory)();
101
- loading.start((0, i18n_1.t)('检验登录状态'));
102
- const credential = yield (0, utils_1.checkAndGetCredential)();
103
- if (!lodash_1.default.isEmpty(credential)) {
104
- loading.succeed((0, i18n_1.t)('您已登录,无需再次登录!'));
105
- return;
85
+ async execute(options, log) {
86
+ log.verbose(options);
87
+ const { apiKeyId, apiKey, token } = options;
88
+ const loading = (0, utils_1.loadingFactory)();
89
+ loading.start((0, i18n_1.t)('检验登录状态'));
90
+ const credential = await (0, utils_1.checkAndGetCredential)();
91
+ if (!lodash_1.default.isEmpty(credential)) {
92
+ loading.succeed((0, i18n_1.t)('您已登录,无需再次登录!'));
93
+ return;
94
+ }
95
+ else {
96
+ loading.stop();
97
+ }
98
+ if (apiKey && apiKeyId) {
99
+ loading.start((0, i18n_1.t)('正在验证腾讯云密钥...'));
100
+ const res = await (0, auth_1.login)({
101
+ token,
102
+ key: true,
103
+ secretKey: apiKey,
104
+ secretId: apiKeyId
105
+ });
106
+ if (res.code === 'SUCCESS') {
107
+ loading.succeed((0, i18n_1.t)('登录成功!'));
108
+ printSuggestion();
106
109
  }
107
110
  else {
108
- loading.stop();
111
+ loading.fail((0, i18n_1.t)('腾讯云密钥验证失败,请检查密钥是否正确或终端网络是否可用!'));
112
+ return process.exit(1);
109
113
  }
110
- if (apiKey && apiKeyId) {
111
- loading.start((0, i18n_1.t)('正在验证腾讯云密钥...'));
112
- const res = yield (0, auth_1.login)({
113
- token,
114
- key: true,
115
- secretKey: apiKey,
116
- secretId: apiKeyId
117
- });
118
- if (res.code === 'SUCCESS') {
119
- loading.succeed((0, i18n_1.t)('登录成功!'));
120
- printSuggestion();
121
- }
122
- else {
123
- loading.fail((0, i18n_1.t)('腾讯云密钥验证失败,请检查密钥是否正确或终端网络是否可用!'));
124
- return process.exit(1);
125
- }
114
+ }
115
+ else if (options.key) {
116
+ const clickableLink = (0, utils_1.genClickableLink)(`${utils_1.EUrl.Console}/cam/capi`);
117
+ console.log((0, i18n_1.t)('您可以访问 {{link}} 获取 API 秘钥', { link: clickableLink }));
118
+ const { secretId } = await inquirer_1.default.prompt({
119
+ type: 'input',
120
+ name: 'secretId',
121
+ message: (0, i18n_1.t)('请输入腾讯云 SecretID:')
122
+ });
123
+ const { secretKey } = await inquirer_1.default.prompt({
124
+ type: 'input',
125
+ name: 'secretKey',
126
+ message: (0, i18n_1.t)('请输入腾讯云 SecretKey:')
127
+ });
128
+ if (!secretId || !secretKey) {
129
+ throw new error_1.CloudBaseError((0, i18n_1.t)('SecretID 或 SecretKey 不能为空'));
126
130
  }
127
- else if (options.key) {
128
- const clickableLink = (0, utils_1.genClickableLink)(`${utils_1.EUrl.Console}/cam/capi`);
129
- console.log((0, i18n_1.t)('您可以访问 {{link}} 获取 API 秘钥', { link: clickableLink }));
130
- const { secretId } = yield inquirer_1.default.prompt({
131
- type: 'input',
132
- name: 'secretId',
133
- message: (0, i18n_1.t)('请输入腾讯云 SecretID:')
134
- });
135
- const { secretKey } = yield inquirer_1.default.prompt({
136
- type: 'input',
137
- name: 'secretKey',
138
- message: (0, i18n_1.t)('请输入腾讯云 SecretKey:')
139
- });
140
- if (!secretId || !secretKey) {
141
- throw new error_1.CloudBaseError((0, i18n_1.t)('SecretID 或 SecretKey 不能为空'));
142
- }
143
- loading.start((0, i18n_1.t)('正在验证腾讯云密钥...'));
144
- const res = yield (0, auth_1.login)({
145
- key: true,
146
- secretId,
147
- secretKey
148
- });
149
- if (res.code === 'SUCCESS') {
150
- loading.succeed((0, i18n_1.t)('登录成功!'));
151
- yield askForCollectDataConfirm();
152
- printSuggestion();
153
- }
154
- else {
155
- loading.fail((0, i18n_1.t)('腾讯云密钥验证失败,请检查密钥是否正确或终端网络是否可用!'));
156
- return process.exit(1);
157
- }
131
+ loading.start((0, i18n_1.t)('正在验证腾讯云密钥...'));
132
+ const res = await (0, auth_1.login)({
133
+ key: true,
134
+ secretId,
135
+ secretKey
136
+ });
137
+ if (res.code === 'SUCCESS') {
138
+ loading.succeed((0, i18n_1.t)('登录成功!'));
139
+ await askForCollectDataConfirm();
140
+ printSuggestion();
158
141
  }
159
142
  else {
160
- loading.start((0, i18n_1.t)('请在浏览器中打开的授权页面进行授权...'));
161
- const res = yield (0, auth_1.login)();
162
- if (res.code === 'SUCCESS') {
163
- loading.succeed((0, i18n_1.t)('登录成功!'));
164
- yield askForCollectDataConfirm();
165
- printSuggestion();
166
- }
167
- else if (res.code === 'WEB_AUTH_FAILED') {
168
- loading.fail((0, i18n_1.t)('Web 授权登录失败'));
169
- console.log(chalk_1.default.yellow((0, i18n_1.t)('⚠️ 检测到环境兼容性问题')));
170
- console.log(chalk_1.default.cyan((0, i18n_1.t)('建议使用密钥登录:')));
171
- console.log(chalk_1.default.cyan((0, i18n_1.t)('tcb login --key')));
172
- console.log(chalk_1.default.gray((0, i18n_1.t)('详细说明请参考:{{url}}', { url: 'https://docs.cloudbase.net/cli-v1/login#%E8%85%BE%E8%AE%AF%E4%BA%91-%E4%BA%91%E5%BC%80%E5%8F%91%E6%8E%A7%E5%88%B6%E5%8F%B0%E6%8E%88%E6%9D%83' })));
173
- console.log('');
174
- const { useKey } = yield inquirer_1.default.prompt({
175
- type: 'confirm',
176
- name: 'useKey',
177
- message: (0, i18n_1.t)('是否切换到密钥登录模式?'),
178
- default: true
143
+ loading.fail((0, i18n_1.t)('腾讯云密钥验证失败,请检查密钥是否正确或终端网络是否可用!'));
144
+ return process.exit(1);
145
+ }
146
+ }
147
+ else {
148
+ loading.start((0, i18n_1.t)('请在浏览器中打开的授权页面进行授权...'));
149
+ const res = await (0, auth_1.login)();
150
+ if (res.code === 'SUCCESS') {
151
+ loading.succeed((0, i18n_1.t)('登录成功!'));
152
+ await askForCollectDataConfirm();
153
+ printSuggestion();
154
+ }
155
+ else if (res.code === 'WEB_AUTH_FAILED') {
156
+ loading.fail((0, i18n_1.t)('Web 授权登录失败'));
157
+ console.log(chalk_1.default.yellow((0, i18n_1.t)('⚠️ 检测到环境兼容性问题')));
158
+ console.log(chalk_1.default.cyan((0, i18n_1.t)('建议使用密钥登录:')));
159
+ console.log(chalk_1.default.cyan((0, i18n_1.t)('tcb login --key')));
160
+ console.log(chalk_1.default.gray((0, i18n_1.t)('详细说明请参考:{{url}}', { url: 'https://docs.cloudbase.net/cli-v1/login#%E8%85%BE%E8%AE%AF%E4%BA%91-%E4%BA%91%E5%BC%80%E5%8F%91%E6%8E%A7%E5%88%B6%E5%8F%B0%E6%8E%88%E6%9D%83' })));
161
+ console.log('');
162
+ const { useKey } = await inquirer_1.default.prompt({
163
+ type: 'confirm',
164
+ name: 'useKey',
165
+ message: (0, i18n_1.t)('是否切换到密钥登录模式?'),
166
+ default: true
167
+ });
168
+ if (useKey) {
169
+ const clickableLink = (0, utils_1.genClickableLink)('https://console.cloud.tencent.com/cam/capi');
170
+ console.log((0, i18n_1.t)('您可以访问 {{link}} 获取 API 秘钥', { link: clickableLink }));
171
+ const { secretId } = await inquirer_1.default.prompt({
172
+ type: 'input',
173
+ name: 'secretId',
174
+ message: (0, i18n_1.t)('请输入腾讯云 SecretID:')
175
+ });
176
+ const { secretKey } = await inquirer_1.default.prompt({
177
+ type: 'input',
178
+ name: 'secretKey',
179
+ message: (0, i18n_1.t)('请输入腾讯云 SecretKey:')
179
180
  });
180
- if (useKey) {
181
- const clickableLink = (0, utils_1.genClickableLink)('https://console.cloud.tencent.com/cam/capi');
182
- console.log((0, i18n_1.t)('您可以访问 {{link}} 获取 API 秘钥', { link: clickableLink }));
183
- const { secretId } = yield inquirer_1.default.prompt({
184
- type: 'input',
185
- name: 'secretId',
186
- message: (0, i18n_1.t)('请输入腾讯云 SecretID:')
187
- });
188
- const { secretKey } = yield inquirer_1.default.prompt({
189
- type: 'input',
190
- name: 'secretKey',
191
- message: (0, i18n_1.t)('请输入腾讯云 SecretKey:')
192
- });
193
- if (!secretId || !secretKey) {
194
- throw new error_1.CloudBaseError((0, i18n_1.t)('SecretID 或 SecretKey 不能为空'));
195
- }
196
- loading.start((0, i18n_1.t)('正在验证腾讯云密钥...'));
197
- const keyRes = yield (0, auth_1.login)({
198
- key: true,
199
- secretId,
200
- secretKey
201
- });
202
- if (keyRes.code === 'SUCCESS') {
203
- loading.succeed((0, i18n_1.t)('登录成功!'));
204
- yield askForCollectDataConfirm();
205
- printSuggestion();
206
- }
207
- else {
208
- loading.fail((0, i18n_1.t)('腾讯云密钥验证失败,请检查密钥是否正确或终端网络是否可用!'));
209
- return process.exit(1);
210
- }
181
+ if (!secretId || !secretKey) {
182
+ throw new error_1.CloudBaseError((0, i18n_1.t)('SecretID 或 SecretKey 不能为空'));
183
+ }
184
+ loading.start((0, i18n_1.t)('正在验证腾讯云密钥...'));
185
+ const keyRes = await (0, auth_1.login)({
186
+ key: true,
187
+ secretId,
188
+ secretKey
189
+ });
190
+ if (keyRes.code === 'SUCCESS') {
191
+ loading.succeed((0, i18n_1.t)('登录成功!'));
192
+ await askForCollectDataConfirm();
193
+ printSuggestion();
211
194
  }
212
195
  else {
196
+ loading.fail((0, i18n_1.t)('腾讯云密钥验证失败,请检查密钥是否正确或终端网络是否可用!'));
213
197
  return process.exit(1);
214
198
  }
215
199
  }
216
200
  else {
217
- loading.fail(res.msg);
218
- console.log((0, i18n_1.t)('Web 授权登录失败,秘钥校验失败!'));
219
201
  return process.exit(1);
220
202
  }
221
203
  }
222
- const consoleUrl = `${utils_1.EUrl.TcbConsole}/env/index?action=CreateEnv&from=cli`;
223
- try {
224
- const envs = yield (0, env_1.listEnvs)();
225
- if (!envs.length) {
226
- log.warn((0, i18n_1.t)('您还没有可用的环境,请前往控制台 {{link}} 创建环境', { link: (0, utils_1.genClickableLink)(consoleUrl) }));
227
- }
204
+ else {
205
+ loading.fail(res.msg);
206
+ console.log((0, i18n_1.t)('Web 授权登录失败,秘钥校验失败!'));
207
+ return process.exit(1);
228
208
  }
229
- catch (e) {
230
- if (e.code === 'ResourceNotFound.UserNotExists') {
231
- log.error((0, i18n_1.t)('您还没有可用的环境,请前往控制台 {{link}} 创建环境', { link: (0, utils_1.genClickableLink)(consoleUrl) }));
232
- }
233
- else {
234
- console.error(e);
235
- throw e;
236
- }
209
+ }
210
+ const consoleUrl = `${utils_1.EUrl.TcbConsole}/env/index?action=CreateEnv&from=cli`;
211
+ try {
212
+ const envs = await (0, env_1.listEnvs)();
213
+ if (!envs.length) {
214
+ log.warn((0, i18n_1.t)('您还没有可用的环境,请前往控制台 {{link}} 创建环境', { link: (0, utils_1.genClickableLink)(consoleUrl) }));
237
215
  }
238
- });
216
+ }
217
+ catch (e) {
218
+ if (e.code === 'ResourceNotFound.UserNotExists') {
219
+ log.error((0, i18n_1.t)('您还没有可用的环境,请前往控制台 {{link}} 创建环境', { link: (0, utils_1.genClickableLink)(consoleUrl) }));
220
+ }
221
+ else {
222
+ console.error(e);
223
+ throw e;
224
+ }
225
+ }
239
226
  }
240
227
  };
241
228
  __decorate([
@@ -11,15 +11,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
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
14
  Object.defineProperty(exports, "__esModule", { value: true });
24
15
  exports.LogoutCommand = void 0;
25
16
  const common_1 = require("../common");
@@ -36,11 +27,9 @@ let LogoutCommand = class LogoutCommand extends common_1.Command {
36
27
  withoutAuth: true
37
28
  };
38
29
  }
39
- execute(log) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- yield (0, auth_1.logout)();
42
- log.success((0, i18n_1.t)('注销登录成功!'));
43
- });
30
+ async execute(log) {
31
+ await (0, auth_1.logout)();
32
+ log.success((0, i18n_1.t)('注销登录成功!'));
44
33
  }
45
34
  };
46
35
  __decorate([