@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.
- package/lib/auth/login.js +51 -65
- package/lib/auth/logout.js +3 -14
- package/lib/commands/account/login.js +136 -149
- package/lib/commands/account/logout.js +3 -14
- package/lib/commands/ag/base.js +203 -0
- package/lib/commands/ag/create.js +301 -0
- package/lib/commands/ag/debug/index.html +699 -0
- package/lib/commands/ag/delete.js +200 -0
- package/lib/commands/ag/deploy.js +185 -0
- package/lib/commands/ag/detail.js +113 -0
- package/lib/commands/ag/index.js +22 -0
- package/lib/commands/ag/list.js +155 -0
- package/lib/commands/ag/run.js +644 -0
- package/lib/commands/ai/index.js +76 -95
- package/lib/commands/cloudfunction/base.js +182 -203
- package/lib/commands/cloudrun/base.js +578 -603
- package/lib/commands/common.js +48 -63
- package/lib/commands/config/delete.js +16 -27
- package/lib/commands/config/get.js +13 -24
- package/lib/commands/config/list.js +16 -27
- package/lib/commands/config/set.js +33 -44
- package/lib/commands/db/base.js +221 -240
- package/lib/commands/env/base.js +36 -49
- package/lib/commands/env/domain.js +79 -94
- package/lib/commands/env/login.js +120 -135
- package/lib/commands/framework/index.js +32 -49
- package/lib/commands/fun/base.js +223 -244
- package/lib/commands/functions/alias/getRoute.js +33 -44
- package/lib/commands/functions/alias/setRoute.js +36 -47
- package/lib/commands/functions/code-download.js +43 -54
- package/lib/commands/functions/code-update.js +23 -34
- package/lib/commands/functions/concurrency/delete.js +11 -22
- package/lib/commands/functions/concurrency/list.js +20 -31
- package/lib/commands/functions/concurrency/set.js +13 -24
- package/lib/commands/functions/config-update.js +30 -41
- package/lib/commands/functions/copy.js +12 -23
- package/lib/commands/functions/delete.js +30 -41
- package/lib/commands/functions/deploy.js +184 -202
- package/lib/commands/functions/detail.js +23 -34
- package/lib/commands/functions/invoke.js +69 -75
- package/lib/commands/functions/layer/bind.js +102 -105
- package/lib/commands/functions/layer/create.js +29 -35
- package/lib/commands/functions/layer/delete.js +42 -48
- package/lib/commands/functions/layer/download.js +52 -58
- package/lib/commands/functions/layer/list.js +44 -50
- package/lib/commands/functions/layer/sort.js +39 -45
- package/lib/commands/functions/list.js +25 -36
- package/lib/commands/functions/log.js +65 -73
- package/lib/commands/functions/run.js +118 -116
- package/lib/commands/functions/trigger-create.js +32 -43
- package/lib/commands/functions/trigger-delete.js +50 -61
- package/lib/commands/functions/version/list.js +29 -40
- package/lib/commands/functions/version/publish.js +11 -22
- package/lib/commands/gateway/create.js +50 -61
- package/lib/commands/gateway/delete.js +38 -49
- package/lib/commands/gateway/domain.js +65 -80
- package/lib/commands/gateway/list.js +31 -42
- package/lib/commands/gateway/switch.js +48 -61
- package/lib/commands/helpers/init.js +226 -249
- package/lib/commands/helpers/new.js +35 -46
- package/lib/commands/helpers/open.js +22 -33
- package/lib/commands/hosting/hosting.js +157 -178
- package/lib/commands/index.js +1 -0
- package/lib/commands/lowcode/app.js +114 -144
- package/lib/commands/lowcode/comps.js +136 -127
- package/lib/commands/lowcode/utils.js +11 -22
- package/lib/commands/pull/pull.js +33 -46
- package/lib/commands/run/delete.js +35 -46
- package/lib/commands/run/image/delete.js +32 -39
- package/lib/commands/run/image/download.js +26 -33
- package/lib/commands/run/image/list.js +41 -48
- package/lib/commands/run/image/upload.js +26 -33
- package/lib/commands/run/list.js +32 -43
- package/lib/commands/run/service/config.js +17 -28
- package/lib/commands/run/service/deploy.js +15 -26
- package/lib/commands/run/service/list.js +48 -59
- package/lib/commands/run/service/update.js +7 -18
- package/lib/commands/run/standalonegateway/create.js +35 -42
- package/lib/commands/run/standalonegateway/destroy.js +23 -30
- package/lib/commands/run/standalonegateway/list.js +19 -26
- package/lib/commands/run/standalonegateway/package.js +31 -38
- package/lib/commands/run/standalonegateway/turn.js +27 -34
- package/lib/commands/run/version/create.js +198 -205
- package/lib/commands/run/version/delete.js +31 -38
- package/lib/commands/run/version/list.js +42 -49
- package/lib/commands/run/version/modify.js +27 -34
- package/lib/commands/run/version/update.js +201 -208
- package/lib/commands/runf/base.js +216 -237
- package/lib/commands/self-update.js +59 -72
- package/lib/commands/smart.js +66 -79
- package/lib/commands/storage/storage.js +192 -219
- package/lib/commands/third/thirdAttach.js +16 -27
- package/lib/commands/utils.js +119 -149
- package/lib/db/index.js +48 -67
- package/lib/decorators/captureError.js +10 -21
- package/lib/decorators/guard.js +11 -22
- package/lib/decorators/injectParams.js +29 -40
- package/lib/decorators/params/common.js +5 -2
- package/lib/decorators/params/index.js +3 -12
- package/lib/env/domain.js +13 -28
- package/lib/env/index.js +25 -44
- package/lib/env/login.js +30 -45
- package/lib/function/alias.js +31 -44
- package/lib/function/base.js +187 -215
- package/lib/function/code.js +8 -19
- package/lib/function/concurrency.js +43 -58
- package/lib/function/create.js +43 -53
- package/lib/function/delete.js +22 -35
- package/lib/function/layer/attach.js +33 -46
- package/lib/function/layer/create.js +34 -45
- package/lib/function/layer/delete.js +5 -16
- package/lib/function/layer/download.js +11 -22
- package/lib/function/layer/list.js +12 -25
- package/lib/function/layer/sort.js +6 -17
- package/lib/function/trigger.js +65 -82
- package/lib/function/update.js +24 -32
- package/lib/function/version.js +29 -42
- package/lib/function/vpc.js +12 -25
- package/lib/gateway/index.js +77 -104
- package/lib/hosting.js +157 -188
- package/lib/run/delete.js +3 -12
- package/lib/run/image/build.js +6 -15
- package/lib/run/image/delete.js +3 -12
- package/lib/run/image/info.js +3 -12
- package/lib/run/image/list.js +6 -15
- package/lib/run/list.js +19 -30
- package/lib/run/repo.js +6 -15
- package/lib/run/service/common.js +160 -173
- package/lib/run/service/config.js +44 -57
- package/lib/run/service/deployPackage.js +33 -44
- package/lib/run/service/list.js +8 -14
- package/lib/run/service/showLogs.js +69 -90
- package/lib/run/service/update.js +50 -63
- package/lib/run/standalonegateway/create.js +3 -12
- package/lib/run/standalonegateway/destroy.js +3 -12
- package/lib/run/standalonegateway/list.js +3 -12
- package/lib/run/standalonegateway/package/list.js +3 -12
- package/lib/run/standalonegateway/turn/off.js +3 -12
- package/lib/run/standalonegateway/turn/on.js +3 -12
- package/lib/run/version/create.js +41 -31
- package/lib/run/version/delete.js +3 -12
- package/lib/run/version/list.js +3 -12
- package/lib/run/version/modify.js +3 -12
- package/lib/run/version/repo.js +6 -15
- package/lib/run/version/update.js +37 -26
- package/lib/storage.js +62 -93
- package/lib/third/index.js +6 -17
- package/lib/utils/ai/banner.js +49 -60
- package/lib/utils/ai/claudeWindows.js +2 -2
- package/lib/utils/ai/config.js +169 -206
- package/lib/utils/ai/ensureFiles.js +6 -17
- package/lib/utils/ai/env.js +16 -27
- package/lib/utils/ai/envLocalManager.js +35 -52
- package/lib/utils/ai/router.js +927 -1005
- package/lib/utils/ai/setup.js +527 -563
- package/lib/utils/auth.js +3 -14
- package/lib/utils/checkTcbrEnv.js +20 -31
- package/lib/utils/cli-table.js +6 -1
- package/lib/utils/config.js +4 -13
- package/lib/utils/dts.js +98 -113
- package/lib/utils/env.js +154 -175
- package/lib/utils/function-packer.js +29 -42
- package/lib/utils/log.js +10 -21
- package/lib/utils/mcp-config-modifier.js +105 -120
- package/lib/utils/net/cloud-api-request.js +15 -23
- package/lib/utils/net/credential.js +26 -39
- package/lib/utils/net/http-request.js +63 -80
- package/lib/utils/net/manager-service.js +22 -35
- package/lib/utils/notice.js +16 -27
- package/lib/utils/output/loading.js +3 -12
- package/lib/utils/parallel.js +32 -43
- package/lib/utils/platform/mac.js +4 -15
- package/lib/utils/platform/port.js +4 -15
- package/lib/utils/prompt/select.js +6 -15
- package/lib/utils/report.js +28 -33
- package/lib/utils/reporter/agree.js +11 -22
- package/lib/utils/reporter/download.js +17 -28
- package/lib/utils/reporter/usage.js +12 -23
- package/lib/utils/store/auth.js +17 -30
- package/lib/utils/store/config.js +11 -25
- package/lib/utils/store/db.js +17 -36
- package/lib/utils/tcbrApi/callTcbrApi.js +19 -28
- package/lib/utils/template-manager.js +215 -242
- package/lib/utils/template.js +81 -96
- package/lib/utils/tools/common.js +45 -56
- package/lib/utils/tools/time.js +5 -16
- package/lib/utils/url.js +10 -4
- package/package.json +2 -2
- package/specs/ag-command/design.md +421 -0
- package/specs/ag-command/doc.md +204 -0
- package/specs/ag-command/requirements.md +173 -0
- package/specs/ag-command/summary.md +174 -0
- package/specs/ag-command/tasks.md +197 -0
- package/specs/ag-command/usage-guide.md +420 -0
- package/tsconfig.json +1 -1
- package/types/commands/ag/base.d.ts +44 -0
- package/types/commands/ag/create.d.ts +25 -0
- package/types/commands/ag/delete.d.ts +32 -0
- package/types/commands/ag/deploy.d.ts +31 -0
- package/types/commands/ag/detail.d.ts +28 -0
- package/types/commands/ag/index.d.ts +6 -0
- package/types/commands/ag/list.d.ts +35 -0
- package/types/commands/ag/run.d.ts +52 -0
- package/types/commands/cloudrun/base.d.ts +10 -0
- 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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
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
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
144
|
-
|
|
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
|
-
|
|
154
|
-
|
|
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
|
-
|
|
158
|
-
log.
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
202
|
-
|
|
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: () =>
|
|
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 =
|
|
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
|
|
48
|
-
|
|
38
|
+
return {
|
|
39
|
+
...credential,
|
|
40
|
+
tokenExpired: Number(credential.accessTokenExpired)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
49
43
|
});
|
|
50
44
|
}
|
|
51
|
-
request(action, data = {}, method = 'POST') {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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;
|