@cloudbase/cli 2.10.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
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
35
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
27
  };
@@ -75,133 +66,127 @@ function inferConfigFormat(filePath) {
75
66
  return filePath.toLowerCase().endsWith('.toml') ? 'toml' : 'json';
76
67
  }
77
68
  class MCPConfigModifier {
78
- modifyMCPConfigs(extractDir, log) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- try {
81
- log.info((0, i18n_1.t)('🔧 正在修改 MCP 配置文件...'));
82
- for (const [ide, files] of Object.entries(IDE_FILE_MAPPINGS)) {
83
- for (const descriptor of files) {
84
- if (!descriptor.isMcpConfig)
85
- continue;
86
- const filePath = path_1.default.join(extractDir, descriptor.path);
87
- log.debug((0, i18n_1.t)('检查文件: {{filePath}}', { filePath }));
88
- if (yield fs_extra_1.default.pathExists(filePath)) {
89
- log.debug((0, i18n_1.t)('找到 MCP 配置文件: {{filePath}}', { filePath }));
90
- const format = inferConfigFormat(descriptor.path);
91
- if (format === 'json') {
92
- yield this.modifyMCPJsonFile(filePath, log);
93
- }
94
- else if (format === 'toml') {
95
- yield this.modifyMCPTomlFile(filePath, log);
96
- }
69
+ async modifyMCPConfigs(extractDir, log) {
70
+ try {
71
+ log.info((0, i18n_1.t)('🔧 正在修改 MCP 配置文件...'));
72
+ for (const [ide, files] of Object.entries(IDE_FILE_MAPPINGS)) {
73
+ for (const descriptor of files) {
74
+ if (!descriptor.isMcpConfig)
75
+ continue;
76
+ const filePath = path_1.default.join(extractDir, descriptor.path);
77
+ log.debug((0, i18n_1.t)('检查文件: {{filePath}}', { filePath }));
78
+ if (await fs_extra_1.default.pathExists(filePath)) {
79
+ log.debug((0, i18n_1.t)('找到 MCP 配置文件: {{filePath}}', { filePath }));
80
+ const format = inferConfigFormat(descriptor.path);
81
+ if (format === 'json') {
82
+ await this.modifyMCPJsonFile(filePath, log);
97
83
  }
98
- else {
99
- log.debug((0, i18n_1.t)('文件不存在: {{filePath}}', { filePath }));
84
+ else if (format === 'toml') {
85
+ await this.modifyMCPTomlFile(filePath, log);
100
86
  }
101
87
  }
88
+ else {
89
+ log.debug((0, i18n_1.t)('文件不存在: {{filePath}}', { filePath }));
90
+ }
102
91
  }
103
- log.info((0, i18n_1.t)('✅ MCP 配置文件修改完成'));
104
- }
105
- catch (error) {
106
- log.warn((0, i18n_1.t)('⚠️ MCP 配置文件修改失败: {{error}}', { error: error.message }));
107
92
  }
108
- });
93
+ log.info((0, i18n_1.t)('✅ MCP 配置文件修改完成'));
94
+ }
95
+ catch (error) {
96
+ log.warn((0, i18n_1.t)('⚠️ MCP 配置文件修改失败: {{error}}', { error: error.message }));
97
+ }
109
98
  }
110
- modifyMCPJsonFile(filePath, log) {
111
- return __awaiter(this, void 0, void 0, function* () {
112
- try {
113
- const content = yield fs_extra_1.default.readFile(filePath, 'utf-8');
114
- const config = JSON.parse(content);
115
- log.debug((0, i18n_1.t)('读取配置文件 {{filePath}}: {{config}}', { filePath, config: JSON.stringify(config) }));
116
- let modified = false;
117
- const modifyCommands = (obj) => {
118
- if (typeof obj !== 'object' || obj === null) {
119
- return obj;
120
- }
121
- if (Array.isArray(obj)) {
122
- return obj.map((item) => modifyCommands(item));
123
- }
124
- const result = Object.assign({}, obj);
125
- if (result.command === 'npx' && Array.isArray(result.args)) {
126
- const argsStr = result.args.join(' ');
127
- log.debug(`${(0, i18n_1.t)('检查命令')}: command=${result.command}, args=${JSON.stringify(result.args)}`);
128
- if (argsStr.includes('npm-global-exec@latest') &&
129
- argsStr.includes('@cloudbase/cloudbase-mcp@latest')) {
130
- log.debug((0, i18n_1.t)('匹配到需要修改的命令: {{argsStr}}', { argsStr }));
131
- result.command = 'cloudbase-mcp';
132
- result.args = [];
133
- result.env = {
134
- INTEGRATION_IDE: process.env.INTEGRATION_IDE || 'CloudBaseCLI'
135
- };
136
- modified = true;
137
- log.debug(`${(0, i18n_1.t)('修改配置文件')} ${filePath}: npx -> cloudbase-mcp`);
138
- }
139
- else {
140
- log.debug((0, i18n_1.t)('命令不匹配修改条件: {{argsStr}}', { argsStr }));
141
- }
99
+ async modifyMCPJsonFile(filePath, log) {
100
+ try {
101
+ const content = await fs_extra_1.default.readFile(filePath, 'utf-8');
102
+ const config = JSON.parse(content);
103
+ log.debug((0, i18n_1.t)('读取配置文件 {{filePath}}: {{config}}', { filePath, config: JSON.stringify(config) }));
104
+ let modified = false;
105
+ const modifyCommands = (obj) => {
106
+ if (typeof obj !== 'object' || obj === null) {
107
+ return obj;
108
+ }
109
+ if (Array.isArray(obj)) {
110
+ return obj.map((item) => modifyCommands(item));
111
+ }
112
+ const result = { ...obj };
113
+ if (result.command === 'npx' && Array.isArray(result.args)) {
114
+ const argsStr = result.args.join(' ');
115
+ log.debug(`${(0, i18n_1.t)('检查命令')}: command=${result.command}, args=${JSON.stringify(result.args)}`);
116
+ if (argsStr.includes('npm-global-exec@latest') &&
117
+ argsStr.includes('@cloudbase/cloudbase-mcp@latest')) {
118
+ log.debug((0, i18n_1.t)('匹配到需要修改的命令: {{argsStr}}', { argsStr }));
119
+ result.command = 'cloudbase-mcp';
120
+ result.args = [];
121
+ result.env = {
122
+ INTEGRATION_IDE: process.env.INTEGRATION_IDE || 'CloudBaseCLI'
123
+ };
124
+ modified = true;
125
+ log.debug(`${(0, i18n_1.t)('修改配置文件')} ${filePath}: npx -> cloudbase-mcp`);
142
126
  }
143
- for (const [key, value] of Object.entries(result)) {
144
- result[key] = modifyCommands(value);
127
+ else {
128
+ log.debug((0, i18n_1.t)('命令不匹配修改条件: {{argsStr}}', { argsStr }));
145
129
  }
146
- return result;
147
- };
148
- const modifiedConfig = modifyCommands(config);
149
- if (modified) {
150
- yield fs_extra_1.default.writeJson(filePath, modifiedConfig, { spaces: 2 });
151
- log.debug((0, i18n_1.t)('✅ 已修改 {{filePath}}', { filePath }));
152
130
  }
153
- else {
154
- log.debug((0, i18n_1.t)('⚠️ 配置文件 {{filePath}} 未发生修改', { filePath }));
131
+ for (const [key, value] of Object.entries(result)) {
132
+ result[key] = modifyCommands(value);
155
133
  }
134
+ return result;
135
+ };
136
+ const modifiedConfig = modifyCommands(config);
137
+ if (modified) {
138
+ await fs_extra_1.default.writeJson(filePath, modifiedConfig, { spaces: 2 });
139
+ log.debug((0, i18n_1.t)('✅ 已修改 {{filePath}}', { filePath }));
156
140
  }
157
- catch (error) {
158
- log.warn((0, i18n_1.t)('⚠️ 修改配置文件 {{filePath}} 失败: {{error}}', { filePath, error: error.message }));
141
+ else {
142
+ log.debug((0, i18n_1.t)('⚠️ 配置文件 {{filePath}} 未发生修改', { filePath }));
159
143
  }
160
- });
144
+ }
145
+ catch (error) {
146
+ log.warn((0, i18n_1.t)('⚠️ 修改配置文件 {{filePath}} 失败: {{error}}', { filePath, error: error.message }));
147
+ }
161
148
  }
162
- modifyMCPTomlFile(filePath, log) {
163
- return __awaiter(this, void 0, void 0, function* () {
164
- try {
165
- const content = yield fs_extra_1.default.readFile(filePath, 'utf-8');
166
- const toml = yield Promise.resolve().then(() => __importStar(require('toml')));
167
- const config = toml.parse(content);
168
- let modified = false;
169
- const modifyCommands = (obj) => {
170
- if (typeof obj !== 'object' || obj === null) {
171
- return obj;
172
- }
173
- if (Array.isArray(obj)) {
174
- return obj.map((item) => modifyCommands(item));
175
- }
176
- const result = Object.assign({}, obj);
177
- if (result.command === 'npx' && Array.isArray(result.args)) {
178
- const argsStr = result.args.join(' ');
179
- if (argsStr.includes('@cloudbase/cloudbase-mcp@latest')) {
180
- result.command = 'cloudbase-mcp';
181
- result.args = [];
182
- result.env = {
183
- INTEGRATION_IDE: process.env.INTEGRATION_IDE || 'CloudBaseCLI'
184
- };
185
- modified = true;
186
- log.debug(`${(0, i18n_1.t)('修改配置文件')} ${filePath}: npx -> cloudbase-mcp`);
187
- }
188
- }
189
- for (const [key, value] of Object.entries(result)) {
190
- result[key] = modifyCommands(value);
149
+ async modifyMCPTomlFile(filePath, log) {
150
+ try {
151
+ const content = await fs_extra_1.default.readFile(filePath, 'utf-8');
152
+ const toml = await Promise.resolve().then(() => __importStar(require('toml')));
153
+ const config = toml.parse(content);
154
+ let modified = false;
155
+ const modifyCommands = (obj) => {
156
+ if (typeof obj !== 'object' || obj === null) {
157
+ return obj;
158
+ }
159
+ if (Array.isArray(obj)) {
160
+ return obj.map((item) => modifyCommands(item));
161
+ }
162
+ const result = { ...obj };
163
+ if (result.command === 'npx' && Array.isArray(result.args)) {
164
+ const argsStr = result.args.join(' ');
165
+ if (argsStr.includes('@cloudbase/cloudbase-mcp@latest')) {
166
+ result.command = 'cloudbase-mcp';
167
+ result.args = [];
168
+ result.env = {
169
+ INTEGRATION_IDE: process.env.INTEGRATION_IDE || 'CloudBaseCLI'
170
+ };
171
+ modified = true;
172
+ log.debug(`${(0, i18n_1.t)('修改配置文件')} ${filePath}: npx -> cloudbase-mcp`);
191
173
  }
192
- return result;
193
- };
194
- const modifiedConfig = modifyCommands(config);
195
- if (modified) {
196
- const tomlString = this.objectToToml(modifiedConfig);
197
- yield fs_extra_1.default.writeFile(filePath, tomlString, 'utf-8');
198
- log.debug(`✅ ${(0, i18n_1.t)('已修改')} ${filePath}`);
199
174
  }
175
+ for (const [key, value] of Object.entries(result)) {
176
+ result[key] = modifyCommands(value);
177
+ }
178
+ return result;
179
+ };
180
+ const modifiedConfig = modifyCommands(config);
181
+ if (modified) {
182
+ const tomlString = this.objectToToml(modifiedConfig);
183
+ await fs_extra_1.default.writeFile(filePath, tomlString, 'utf-8');
184
+ log.debug(`✅ ${(0, i18n_1.t)('已修改')} ${filePath}`);
200
185
  }
201
- catch (error) {
202
- log.warn((0, i18n_1.t)('⚠️ 修改配置文件 {{filePath}} 失败: {{errorMessage}}', { filePath, errorMessage: error.message }));
203
- }
204
- });
186
+ }
187
+ catch (error) {
188
+ log.warn((0, i18n_1.t)('⚠️ 修改配置文件 {{filePath}} 失败: {{errorMessage}}', { filePath, errorMessage: error.message }));
189
+ }
205
190
  }
206
191
  objectToToml(obj, prefix = '') {
207
192
  const lines = [];
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.CloudApiService = void 0;
13
4
  const toolbox_1 = require("@cloudbase/toolbox");
@@ -35,29 +26,30 @@ class CloudApiService {
35
26
  baseParams,
36
27
  proxy: (0, toolbox_1.getProxy)(),
37
28
  timeout: constant_1.REQUEST_TIMEOUT,
38
- getCredential: () => __awaiter(this, void 0, void 0, function* () {
29
+ getCredential: async () => {
39
30
  if ((commonCredential === null || commonCredential === void 0 ? void 0 : commonCredential.secretId) && !isTokenExpired(commonCredential)) {
40
31
  return commonCredential;
41
32
  }
42
- const credential = yield (0, toolbox_1.getCredentialWithoutCheck)();
33
+ const credential = await (0, toolbox_1.getCredentialWithoutCheck)();
43
34
  if (!credential) {
44
35
  throw new error_1.CloudBaseError((0, i18n_1.t)('无有效身份信息,请使用 cloudbase login 登录'));
45
36
  }
46
37
  commonCredential = credential;
47
- return Object.assign(Object.assign({}, credential), { tokenExpired: Number(credential.accessTokenExpired) });
48
- })
38
+ return {
39
+ ...credential,
40
+ tokenExpired: Number(credential.accessTokenExpired)
41
+ };
42
+ }
49
43
  });
50
44
  }
51
- request(action, data = {}, method = 'POST') {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- const region = this.region || (yield (0, toolbox_1.getRegion)());
54
- const reqOptions = { action, data, method, region };
55
- const startTime = new Date();
56
- const res = yield this.apiService.request(reqOptions);
57
- const endTime = new Date();
58
- (0, debug_logger_1.debugLogger)(reqOptions, res, startTime, endTime);
59
- return res;
60
- });
45
+ async request(action, data = {}, method = 'POST') {
46
+ const region = this.region || (await (0, toolbox_1.getRegion)());
47
+ const reqOptions = { action, data, method, region };
48
+ const startTime = new Date();
49
+ const res = await this.apiService.request(reqOptions);
50
+ const endTime = new Date();
51
+ (0, debug_logger_1.debugLogger)(reqOptions, res, startTime, endTime);
52
+ return res;
61
53
  }
62
54
  }
63
55
  exports.CloudApiService = CloudApiService;
@@ -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
  };
@@ -23,39 +14,35 @@ const proxy_1 = require("./proxy");
23
14
  const http_request_1 = require("./http-request");
24
15
  const i18n_1 = require("../../i18n");
25
16
  const refreshTokenUrl = 'https://iaas.cloud.tencent.com/tcb_refresh';
26
- function refreshTmpToken(metaData) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const mac = yield (0, platform_1.getMacAddress)();
29
- const hash = (0, tools_1.md5)(mac);
30
- metaData.hash = hash;
31
- const res = yield (0, http_request_1.fetch)(refreshTokenUrl, {
32
- method: 'POST',
33
- body: JSON.stringify(metaData),
34
- headers: { 'Content-Type': 'application/json' }
35
- });
36
- if (res.code !== 0) {
37
- throw new error_1.CloudBaseError(res.message, {
38
- code: res.code
39
- });
40
- }
41
- const { data: credential } = res;
42
- return credential;
17
+ async function refreshTmpToken(metaData) {
18
+ const mac = await (0, platform_1.getMacAddress)();
19
+ const hash = (0, tools_1.md5)(mac);
20
+ metaData.hash = hash;
21
+ const res = await (0, http_request_1.fetch)(refreshTokenUrl, {
22
+ method: 'POST',
23
+ body: JSON.stringify(metaData),
24
+ headers: { 'Content-Type': 'application/json' }
43
25
  });
26
+ if (res.code !== 0) {
27
+ throw new error_1.CloudBaseError(res.message, {
28
+ code: res.code
29
+ });
30
+ }
31
+ const { data: credential } = res;
32
+ return credential;
44
33
  }
45
34
  exports.refreshTmpToken = refreshTmpToken;
46
- function checkAndGetCredential(throwError = false) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const credential = yield (0, toolbox_1.checkAndGetCredential)({
49
- proxy: (0, proxy_1.getProxy)(),
50
- timeout: constant_1.REQUEST_TIMEOUT
51
- });
52
- if (!credential || lodash_1.default.isEmpty(credential)) {
53
- if (throwError) {
54
- throw new error_1.CloudBaseError((0, i18n_1.t)('无有效身份信息,请使用 cloudbase login 登录'));
55
- }
56
- return null;
57
- }
58
- return credential;
35
+ async function checkAndGetCredential(throwError = false) {
36
+ const credential = await (0, toolbox_1.checkAndGetCredential)({
37
+ proxy: (0, proxy_1.getProxy)(),
38
+ timeout: constant_1.REQUEST_TIMEOUT
59
39
  });
40
+ if (!credential || lodash_1.default.isEmpty(credential)) {
41
+ if (throwError) {
42
+ throw new error_1.CloudBaseError((0, i18n_1.t)('无有效身份信息,请使用 cloudbase login 登录'));
43
+ }
44
+ return null;
45
+ }
46
+ return credential;
60
47
  }
61
48
  exports.checkAndGetCredential = checkAndGetCredential;
@@ -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
  };
@@ -28,81 +19,73 @@ function handleTimeout(e) {
28
19
  throw e;
29
20
  }
30
21
  }
31
- function fetchWithDebugLogger(useTextTransform, ...args) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const startTime = new Date();
34
- const rawRes = yield (0, node_fetch_1.default)(...args);
35
- const res = useTextTransform ? yield rawRes.text() : rawRes;
36
- const endTime = new Date();
37
- (0, debug_logger_1.debugLogger)(args, res, startTime, endTime);
38
- return res;
39
- });
22
+ async function fetchWithDebugLogger(useTextTransform, ...args) {
23
+ const startTime = new Date();
24
+ const rawRes = await (0, node_fetch_1.default)(...args);
25
+ const res = useTextTransform ? await rawRes.text() : rawRes;
26
+ const endTime = new Date();
27
+ (0, debug_logger_1.debugLogger)(args, res, startTime, endTime);
28
+ return res;
40
29
  }
41
- function fetch(url, config = {}) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const proxy = (0, proxy_1.getProxy)();
44
- if (proxy) {
45
- config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
46
- }
47
- config.timeout = constant_1.REQUEST_TIMEOUT;
48
- let json;
49
- let text;
50
- try {
51
- const res = yield fetchWithDebugLogger(true, url, config);
52
- text = res;
53
- json = JSON.parse(text);
54
- }
55
- catch (e) {
56
- handleTimeout(e);
57
- json = text;
58
- }
59
- return json;
60
- });
30
+ async function fetch(url, config = {}) {
31
+ const proxy = (0, proxy_1.getProxy)();
32
+ if (proxy) {
33
+ config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
34
+ }
35
+ config.timeout = constant_1.REQUEST_TIMEOUT;
36
+ let json;
37
+ let text;
38
+ try {
39
+ const res = await fetchWithDebugLogger(true, url, config);
40
+ text = res;
41
+ json = JSON.parse(text);
42
+ }
43
+ catch (e) {
44
+ handleTimeout(e);
45
+ json = text;
46
+ }
47
+ return json;
61
48
  }
62
49
  exports.fetch = fetch;
63
- function postFetch(url, data) {
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const proxy = (0, proxy_1.getProxy)();
66
- const config = {
67
- method: 'POST',
68
- headers: {
69
- 'Content-Type': 'application/json'
70
- },
71
- body: JSON.stringify(data)
72
- };
73
- if (proxy) {
74
- config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
75
- }
76
- config.timeout = constant_1.REQUEST_TIMEOUT;
77
- let json;
78
- let text;
79
- try {
80
- const res = yield fetchWithDebugLogger(true, url, config);
81
- text = res;
82
- json = JSON.parse(text);
83
- }
84
- catch (e) {
85
- handleTimeout(e);
86
- json = text;
87
- }
88
- return json;
89
- });
50
+ async function postFetch(url, data) {
51
+ const proxy = (0, proxy_1.getProxy)();
52
+ const config = {
53
+ method: 'POST',
54
+ headers: {
55
+ 'Content-Type': 'application/json'
56
+ },
57
+ body: JSON.stringify(data)
58
+ };
59
+ if (proxy) {
60
+ config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
61
+ }
62
+ config.timeout = constant_1.REQUEST_TIMEOUT;
63
+ let json;
64
+ let text;
65
+ try {
66
+ const res = await fetchWithDebugLogger(true, url, config);
67
+ text = res;
68
+ json = JSON.parse(text);
69
+ }
70
+ catch (e) {
71
+ handleTimeout(e);
72
+ json = text;
73
+ }
74
+ return json;
90
75
  }
91
76
  exports.postFetch = postFetch;
92
- function fetchStream(url, config = {}) {
93
- return __awaiter(this, void 0, void 0, function* () {
94
- const proxy = (0, proxy_1.getProxy)();
95
- if (proxy) {
96
- config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
97
- }
98
- config.timeout = constant_1.REQUEST_TIMEOUT;
99
- try {
100
- const res = yield fetchWithDebugLogger(false, url, config);
101
- return res;
102
- }
103
- catch (e) {
104
- handleTimeout(e);
105
- }
106
- });
77
+ async function fetchStream(url, config = {}) {
78
+ const proxy = (0, proxy_1.getProxy)();
79
+ if (proxy) {
80
+ config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy);
81
+ }
82
+ config.timeout = constant_1.REQUEST_TIMEOUT;
83
+ try {
84
+ const res = await fetchWithDebugLogger(false, url, config);
85
+ return res;
86
+ }
87
+ catch (e) {
88
+ handleTimeout(e);
89
+ }
107
90
  }
108
91
  exports.fetchStream = fetchStream;
@@ -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
  };
@@ -17,35 +8,31 @@ const manager_node_1 = __importDefault(require("@cloudbase/manager-node"));
17
8
  const toolbox_1 = require("@cloudbase/toolbox");
18
9
  const credential_1 = require("./credential");
19
10
  const proxy_1 = require("./proxy");
20
- function getMangerService(envId = '') {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const { secretId, secretKey, token } = yield (0, credential_1.checkAndGetCredential)(true);
23
- const region = yield (0, toolbox_1.getRegion)();
24
- const app = new manager_node_1.default({
25
- token,
26
- envId,
27
- region,
28
- secretId,
29
- secretKey,
30
- proxy: (0, proxy_1.getProxy)()
31
- });
32
- return app;
11
+ async function getMangerService(envId = '') {
12
+ const { secretId, secretKey, token } = await (0, credential_1.checkAndGetCredential)(true);
13
+ const region = await (0, toolbox_1.getRegion)();
14
+ const app = new manager_node_1.default({
15
+ token,
16
+ envId,
17
+ region,
18
+ secretId,
19
+ secretKey,
20
+ proxy: (0, proxy_1.getProxy)()
33
21
  });
22
+ return app;
34
23
  }
35
24
  exports.getMangerService = getMangerService;
36
- function getStorageService(envId) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- const { secretId, secretKey, token } = yield (0, credential_1.checkAndGetCredential)(true);
39
- const region = yield (0, toolbox_1.getRegion)();
40
- const app = new manager_node_1.default({
41
- token,
42
- envId,
43
- secretId,
44
- region,
45
- secretKey,
46
- proxy: (0, proxy_1.getProxy)()
47
- });
48
- return app.storage;
25
+ async function getStorageService(envId) {
26
+ const { secretId, secretKey, token } = await (0, credential_1.checkAndGetCredential)(true);
27
+ const region = await (0, toolbox_1.getRegion)();
28
+ const app = new manager_node_1.default({
29
+ token,
30
+ envId,
31
+ secretId,
32
+ region,
33
+ secretKey,
34
+ proxy: (0, proxy_1.getProxy)()
49
35
  });
36
+ return app.storage;
50
37
  }
51
38
  exports.getStorageService = getStorageService;