@cloudbase/manager-node 4.2.12 → 4.3.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.
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.CloudRunService = void 0;
13
+ const path_1 = __importDefault(require("path"));
14
+ const utils_1 = require("../utils");
15
+ /**
16
+ * 云托管服务管理类
17
+ * 提供云托管服务的初始化、下载、列表查询和删除等功能
18
+ */
19
+ class CloudRunService {
20
+ constructor(environment) {
21
+ this.environment = environment;
22
+ this.tcbrService = new utils_1.CloudService(environment.cloudBaseContext, 'tcbr', '2022-02-17');
23
+ this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
24
+ }
25
+ /**
26
+ * 初始化云托管代码项目
27
+ * @param {Object} params 初始化参数
28
+ * @param {string} params.serverName 服务名称,将作为项目目录名
29
+ * @param {string} [params.template='helloworld'] 模板标识符,默认为'helloworld'
30
+ * @param {string} [params.targetPath='.'] 目标路径,默认为当前目录
31
+ * @returns {Promise<void>}
32
+ * @throws 当模板不存在、下载失败或解压失败时抛出错误
33
+ */
34
+ async init(params) {
35
+ const { serverName, template = 'helloworld', targetPath = '.' } = params || {};
36
+ // 1. 获取模板列表
37
+ const templates = await this.getTemplates();
38
+ const templateData = templates.find(item => item.identifier === template);
39
+ if (!templateData || !templateData.zipFileStore) {
40
+ throw new Error(`未找到匹配的模板: ${template}`);
41
+ }
42
+ // 2. 下载并解压模板到目标目录
43
+ const downloadUrl = templateData.zipFileStore;
44
+ const projectDir = path_1.default.resolve(targetPath, serverName);
45
+ await (0, utils_1.downloadAndExtractRemoteZip)(downloadUrl, projectDir);
46
+ return { projectDir };
47
+ }
48
+ /**
49
+ * 下载云托管服务代码到本地目录
50
+ * @param {Object} params 下载参数
51
+ * @param {string} params.serverName 要下载的服务名称
52
+ * @param {string} params.targetPath 下载的目标路径(绝对路径或相对路径)
53
+ * @returns {Promise<void>}
54
+ * @throws 当以下情况发生时抛出错误:
55
+ * - 未找到服务版本
56
+ * - 获取下载地址失败
57
+ * - 下载或解压过程中出错
58
+ */
59
+ async download(params) {
60
+ var _a, _b;
61
+ const envConfig = this.environment.lazyEnvironmentConfig;
62
+ const { serverName, targetPath } = params;
63
+ /**
64
+ * 获取最新版本
65
+ */
66
+ const cloudRunServerDetailRes = await this.tcbrService.request('DescribeCloudRunServerDetail', {
67
+ EnvId: envConfig.EnvId,
68
+ ServerName: serverName
69
+ });
70
+ const version = (_b = (_a = cloudRunServerDetailRes.OnlineVersionInfos) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.VersionName;
71
+ if (!version) {
72
+ throw new Error('未找到云托管服务版本');
73
+ }
74
+ /**
75
+ * 获取下载地址
76
+ */
77
+ const cloudBaseBuildServiceRes = await this.tcbService.request('DescribeCloudBaseBuildService', {
78
+ EnvId: envConfig.EnvId,
79
+ ServiceName: serverName,
80
+ ServiceVersion: version
81
+ });
82
+ if (cloudBaseBuildServiceRes === null || cloudBaseBuildServiceRes === void 0 ? void 0 : cloudBaseBuildServiceRes.DownloadUrl) {
83
+ await (0, utils_1.downloadAndExtractRemoteZip)(cloudBaseBuildServiceRes === null || cloudBaseBuildServiceRes === void 0 ? void 0 : cloudBaseBuildServiceRes.DownloadUrl, path_1.default.resolve(targetPath));
84
+ }
85
+ else {
86
+ throw new Error(`云托管代码下载地址为空(请求ID: ${cloudBaseBuildServiceRes.RequestId})`);
87
+ }
88
+ }
89
+ /**
90
+ * 获取云托管服务列表
91
+ * @param {Object} [params] 查询参数
92
+ * @param {number} [params.pageSize] 每页数量
93
+ * @param {number} [params.pageNum] 页码
94
+ * @param {string} [params.serverName] 服务名称筛选
95
+ * @param {string} [params.serverType] 服务类型筛选
96
+ * @returns {Promise<ICloudrunListResponse>} 包含服务列表和总数等信息的响应对象
97
+ */
98
+ async list(params) {
99
+ const envConfig = this.environment.lazyEnvironmentConfig;
100
+ return this.tcbrService.request('DescribeCloudRunServers', Object.assign({ EnvId: envConfig.EnvId }, {
101
+ PageSize: (params === null || params === void 0 ? void 0 : params.pageSize) || 10,
102
+ PageNum: (params === null || params === void 0 ? void 0 : params.pageNum) || 1,
103
+ ServerName: params === null || params === void 0 ? void 0 : params.serverName,
104
+ ServerType: params === null || params === void 0 ? void 0 : params.serverType
105
+ }));
106
+ }
107
+ /**
108
+ *查询云托管服务详情
109
+ * @param {Object} params 查询参数
110
+ * @param {string} params.serverName 要查询的服务名称
111
+ * @returns {Promise<ICloudrunDetailResponse>} 返回服务详情响应对象
112
+ */
113
+ async detail(params) {
114
+ const envConfig = this.environment.lazyEnvironmentConfig;
115
+ return this.tcbrService.request('DescribeCloudRunServerDetail', {
116
+ EnvId: envConfig.EnvId,
117
+ ServerName: params.serverName
118
+ });
119
+ }
120
+ /**
121
+ * 删除指定的云托管服务
122
+ * @param {string} serverName - 要删除的服务名称,必须是在当前环境中已存在的服务
123
+ * @returns {Promise<IResponseInfo>} 返回删除操作的响应信息
124
+ */
125
+ async delete(params) {
126
+ // 获取当前环境配置(包含EnvId)
127
+ const envConfig = this.environment.lazyEnvironmentConfig;
128
+ // 调用TCBR服务的DeleteCloudRunServer接口执行删除
129
+ return this.tcbrService.request('DeleteCloudRunServer', {
130
+ EnvId: envConfig.EnvId, // 环境ID
131
+ ServerName: params.serverName // 要删除的服务名称
132
+ });
133
+ }
134
+ /**
135
+ * 获取云托管服务模板列表
136
+ * @returns {Promise<ITemplate[]>} 返回模板数组
137
+ */
138
+ async getTemplates() {
139
+ return (0, utils_1.fetchTemplates)(['tcbrFunc', 'tcbrContainer']);
140
+ }
141
+ }
142
+ exports.CloudRunService = CloudRunService;
143
+ __decorate([
144
+ (0, utils_1.preLazy)()
145
+ ], CloudRunService.prototype, "init", null);
146
+ __decorate([
147
+ (0, utils_1.preLazy)()
148
+ ], CloudRunService.prototype, "download", null);
149
+ __decorate([
150
+ (0, utils_1.preLazy)()
151
+ ], CloudRunService.prototype, "list", null);
152
+ __decorate([
153
+ (0, utils_1.preLazy)()
154
+ ], CloudRunService.prototype, "detail", null);
155
+ __decorate([
156
+ (0, utils_1.preLazy)()
157
+ ], CloudRunService.prototype, "delete", null);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudrunServerType = void 0;
4
+ var CloudrunServerType;
5
+ (function (CloudrunServerType) {
6
+ /**
7
+ * 函数型服务
8
+ */
9
+ CloudrunServerType["Function"] = "function";
10
+ /**
11
+ * 容器型服务
12
+ */
13
+ CloudrunServerType["Container"] = "container";
14
+ })(CloudrunServerType || (exports.CloudrunServerType = CloudrunServerType = {}));
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Environment = void 0;
4
4
  const database_1 = require("./database");
5
5
  const function_1 = require("./function");
6
+ const cloudrun_1 = require("./cloudrun");
6
7
  const storage_1 = require("./storage");
7
8
  const env_1 = require("./env");
8
9
  const common_1 = require("./common");
@@ -22,6 +23,7 @@ class Environment {
22
23
  this.envType = context.envType;
23
24
  // 拉取当前环境 的环境信息 todo
24
25
  this.functionService = new function_1.FunctionService(this);
26
+ this.cloudRunService = new cloudrun_1.CloudRunService(this);
25
27
  this.databaseService = new database_1.DatabaseService(this);
26
28
  this.storageService = new storage_1.StorageService(this);
27
29
  this.envService = new env_1.EnvService(this);
@@ -62,6 +64,9 @@ class Environment {
62
64
  getFunctionService() {
63
65
  return this.functionService;
64
66
  }
67
+ getCloudRunService() {
68
+ return this.cloudRunService;
69
+ }
65
70
  getEnvService() {
66
71
  return this.envService;
67
72
  }
package/lib/index.js CHANGED
@@ -46,6 +46,9 @@ class CloudBase {
46
46
  get functions() {
47
47
  return this.currentEnvironment().getFunctionService();
48
48
  }
49
+ get cloudrun() {
50
+ return this.currentEnvironment().getCloudRunService();
51
+ }
49
52
  get storage() {
50
53
  return this.currentEnvironment().getStorageService();
51
54
  }
@@ -10,7 +10,7 @@ const node_fetch_1 = __importDefault(require("node-fetch"));
10
10
  const https_proxy_agent_1 = require("https-proxy-agent");
11
11
  const error_1 = require("../error");
12
12
  // 使用 fetch + 代理
13
- async function fetch(url, config = {}, proxy) {
13
+ async function fetch(url, config = {}, proxy = null) {
14
14
  if (proxy || process.env.http_proxy) {
15
15
  config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
16
16
  }
@@ -33,7 +33,7 @@ async function fetch(url, config = {}, proxy) {
33
33
  }
34
34
  return json;
35
35
  }
36
- async function fetchStream(url, config = {}, proxy) {
36
+ async function fetchStream(url, config = {}, proxy = null) {
37
37
  if (proxy || process.env.http_proxy) {
38
38
  config.agent = new https_proxy_agent_1.HttpsProxyAgent(proxy || process.env.http_proxy);
39
39
  }
@@ -19,28 +19,35 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.guid6 = void 0;
21
21
  exports.compressToZip = compressToZip;
22
+ exports.downloadAndExtractRemoteZip = downloadAndExtractRemoteZip;
22
23
  exports.getRuntime = getRuntime;
23
24
  exports.getEnvVar = getEnvVar;
24
25
  exports.rsaEncrypt = rsaEncrypt;
25
26
  exports.sleep = sleep;
26
27
  exports.upperCaseStringFisrt = upperCaseStringFisrt;
27
28
  exports.upperCaseObjKey = upperCaseObjKey;
28
- const fs_1 = __importDefault(require("fs"));
29
+ exports.fetchTemplates = fetchTemplates;
29
30
  const archiver_1 = __importDefault(require("archiver"));
30
31
  const crypto_1 = __importDefault(require("crypto"));
32
+ const fs_extra_1 = __importDefault(require("fs-extra"));
33
+ const lodash_1 = __importDefault(require("lodash"));
34
+ const path_1 = __importDefault(require("path"));
35
+ const stream_1 = require("stream");
36
+ const unzipper_1 = __importDefault(require("unzipper"));
31
37
  const constant_1 = require("../constant");
32
- var uuid_1 = require("./uuid");
33
- Object.defineProperty(exports, "guid6", { enumerable: true, get: function () { return uuid_1.guid6; } });
34
- __exportStar(require("./cloud-api-request"), exports);
38
+ const http_request_1 = require("./http-request");
35
39
  __exportStar(require("./auth"), exports);
40
+ __exportStar(require("./cloud-api-request"), exports);
36
41
  __exportStar(require("./cloudbase-request"), exports);
37
- __exportStar(require("./http-request"), exports);
38
42
  __exportStar(require("./envLazy"), exports);
39
43
  __exportStar(require("./fs"), exports);
44
+ __exportStar(require("./http-request"), exports);
45
+ var uuid_1 = require("./uuid");
46
+ Object.defineProperty(exports, "guid6", { enumerable: true, get: function () { return uuid_1.guid6; } });
40
47
  async function compressToZip(option) {
41
48
  const { dirPath, outputPath, ignore, pattern = '**/*' } = option;
42
49
  return new Promise((resolve, reject) => {
43
- const output = fs_1.default.createWriteStream(outputPath);
50
+ const output = fs_extra_1.default.createWriteStream(outputPath);
44
51
  const archive = (0, archiver_1.default)('zip');
45
52
  output.on('close', function () {
46
53
  resolve({
@@ -62,6 +69,36 @@ async function compressToZip(option) {
62
69
  archive.finalize();
63
70
  });
64
71
  }
72
+ /**
73
+ * 下载并解压云托管模板到指定目录
74
+ * @param {string} downloadUrl 模板下载地址
75
+ * @param {string} targetPath 目标路径
76
+ * @returns {Promise<void>}
77
+ * @throws 当下载失败或解压失败时抛出错误
78
+ */
79
+ async function downloadAndExtractRemoteZip(downloadUrl, targetPath) {
80
+ const downloadResponse = await (0, http_request_1.fetchStream)(downloadUrl);
81
+ if (!downloadResponse.ok) {
82
+ throw new Error(`下载失败,状态码: ${downloadResponse.status}`);
83
+ }
84
+ if (!downloadResponse.body) {
85
+ throw new Error('下载响应中没有数据流');
86
+ }
87
+ // 将响应数据转为Buffer
88
+ const zipBuffer = Buffer.from(await downloadResponse.arrayBuffer());
89
+ // 创建目标目录
90
+ const dirPath = path_1.default.resolve(targetPath);
91
+ await fs_extra_1.default.ensureDir(dirPath);
92
+ // 使用unzipper解压
93
+ await new Promise((resolve, reject) => {
94
+ const bufferStream = new stream_1.PassThrough();
95
+ bufferStream.end(zipBuffer);
96
+ bufferStream
97
+ .pipe(unzipper_1.default.Extract({ path: dirPath }))
98
+ .on('close', resolve)
99
+ .on('error', reject);
100
+ });
101
+ }
65
102
  function getRuntime() {
66
103
  return process.env[constant_1.ENV_NAME.ENV_RUNENV];
67
104
  }
@@ -105,3 +142,15 @@ function upperCaseObjKey(object) {
105
142
  }
106
143
  return object;
107
144
  }
145
+ /**
146
+ * 获取函数模板列表
147
+ * @param type 函数模板类型,支持 'scfFunc' 和 'tcbrFunc'
148
+ * @returns
149
+ */
150
+ async function fetchTemplates(types) {
151
+ const apiUrl = 'https://qcloud-tcb-console-1258344699.ap-shanghai.service.tcloudbase.com/func_tpl/v1.0/function_list/find?skip=0&limit=500';
152
+ const responseData = await (0, http_request_1.fetch)(apiUrl, {
153
+ method: 'POST'
154
+ });
155
+ return responseData.data.filter((item) => lodash_1.default.intersection(types, item.funcTypes).length > 0);
156
+ }
package/package.json CHANGED
@@ -1,15 +1,18 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "4.2.12",
3
+ "version": "4.3.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "build": "rimraf lib types && npx tsc",
8
- "test": "jest --runInBand --detectOpenHandles --coverage --testTimeout=50000",
8
+ "test:coverage": "jest --runInBand --detectOpenHandles --coverage --testTimeout=50000",
9
+ "test": "jest --runInBand --detectOpenHandles --testTimeout=50000",
9
10
  "lint": "eslint \"./**/*.ts\"",
10
11
  "lint:fix": "eslint --fix \"./**/*.ts\"",
11
12
  "prepublishOnly": "npm run build",
12
- "watch": "rimraf lib types && tsc -w"
13
+ "watch": "rimraf lib types && tsc -w",
14
+ "link": "node scripts/link.js",
15
+ "unlink": "node scripts/link.js -d"
13
16
  },
14
17
  "repository": {
15
18
  "type": "git",
@@ -19,9 +22,12 @@
19
22
  "license": "ISC",
20
23
  "typings": "types/index.d.ts",
21
24
  "devDependencies": {
25
+ "@lerna/create-symlink": "^6.4.1",
26
+ "@types/fs-extra": "^11.0.4",
22
27
  "@types/jest": "^24.0.18",
23
28
  "@types/node": "^12.7.4",
24
29
  "@types/node-fetch": "^2.5.0",
30
+ "@types/unzipper": "^0.10.11",
25
31
  "@typescript-eslint/eslint-plugin": "^3.7.1",
26
32
  "@typescript-eslint/parser": "^3.7.1",
27
33
  "eslint": "^7.6.0",
@@ -38,11 +44,14 @@
38
44
  "archiver": "^3.1.1",
39
45
  "cos-nodejs-sdk-v5": "^2.14.0",
40
46
  "del": "^5.1.0",
47
+ "fs-extra": "^11.3.0",
41
48
  "https-proxy-agent": "^5.0.1",
49
+ "lodash": "^4.17.21",
42
50
  "make-dir": "^3.0.0",
43
51
  "micromatch": "^4.0.2",
44
52
  "node-fetch": "^2.6.0",
45
53
  "query-string": "^6.8.3",
54
+ "unzipper": "^0.12.3",
46
55
  "walkdir": "^0.4.1"
47
56
  },
48
57
  "husky": {
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Tencent is pleased to support the open source community by making CloudBaseFramework - 云原生一体化部署工具 available.
3
+ *
4
+ * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
5
+ *
6
+ * Please refer to license text included with this package for license details.
7
+ */
8
+
9
+ const os = require('os')
10
+ const fs = require('fs')
11
+ const fse = require('fs-extra')
12
+ const del = require('del')
13
+ const path = require('path')
14
+ const mkdirp = require('mkdirp')
15
+ const { execSync } = require('child_process')
16
+ const { createSymlink } = require('@lerna/create-symlink')
17
+
18
+ const globalNpmPath = execSync('npm root -g', {
19
+ encoding: 'utf-8'
20
+ }).trim()
21
+ // 如果不支持workspace 可以用下面写死
22
+ // const globalNpmPath = '/usr/local/lib/node_modules';
23
+
24
+ async function main() {
25
+ const unlink = process.argv?.[2] === '-d'
26
+ await linkCore(unlink)
27
+ }
28
+
29
+ async function linkCore(unlink = false) {
30
+ const jsonString = await fs.readFileSync(path.join(__dirname, '../package.json'))
31
+ const { name } = JSON.parse(jsonString)
32
+ await link(path.join(process.cwd()), path.join(globalNpmPath, '@cloudbase/cli'), name, unlink)
33
+ }
34
+
35
+ function isSymlink(path) {
36
+ const stats = fs.lstatSync(path)
37
+ return stats.isSymbolicLink()
38
+ }
39
+
40
+ // 将 global tcb cli 工具中的 framework-core link 到 packages/framework-core
41
+ async function link(src, dest, packageName, unlink = false) {
42
+ const prevCwd = process.cwd()
43
+ const destPlugin = path.join(dest, 'node_modules', '@cloudbase')
44
+ // 确保目录存在
45
+ mkdirp.sync(destPlugin)
46
+ // 切换 cwd
47
+ process.chdir(destPlugin)
48
+
49
+ const pathName = packageName.replace('@cloudbase/', '')
50
+ const backupPathName = `${pathName}_backup`
51
+
52
+ if (unlink) {
53
+ if (fs.existsSync(pathName) && !isSymlink(pathName)) {
54
+ console.log(`【失败】${pathName} 不是软链接`, process.cwd())
55
+ return
56
+ }
57
+
58
+ if (fs.existsSync(pathName) && fs.existsSync(backupPathName)) {
59
+ // 删除软链接
60
+ del.sync([pathName])
61
+
62
+ // 恢复备份
63
+ fse.moveSync(backupPathName, pathName)
64
+
65
+ // 删除软链接
66
+ console.log('【成功】删除软链接:', process.cwd())
67
+ } else {
68
+ console.info(
69
+ `不存在 ${pathName} 或 ${backupPathName},请重装安装 npm i @cloudbase/cli -g`,
70
+ process.cwd()
71
+ )
72
+ }
73
+ } else {
74
+ // 创建软链接
75
+
76
+ if (fs.existsSync(pathName)) {
77
+ if (!fs.existsSync(backupPathName)) {
78
+ // 不存在备份则进行备份
79
+
80
+ if (!isSymlink(pathName)) {
81
+ // 不是软链接才备份
82
+ fse.moveSync(pathName, backupPathName)
83
+ }
84
+ } else {
85
+ // 存在备份则直接删除
86
+ del.sync([pathName])
87
+ }
88
+ }
89
+
90
+ await createSymlink(src, pathName, 'junction')
91
+ console.log('【成功】创建软链接:', process.cwd())
92
+ }
93
+
94
+ // 切回源目录
95
+ process.chdir(prevCwd)
96
+ }
97
+
98
+ main()
package/tsconfig.json CHANGED
@@ -11,7 +11,8 @@
11
11
  "declaration": true,
12
12
  "declarationDir": "./types",
13
13
  "experimentalDecorators": true,
14
- "newLine": "LF"
14
+ "newLine": "LF",
15
+ "skipLibCheck": true
15
16
  },
16
17
  "include": ["src/**/*"],
17
18
  "exclude": ["node_modules", "test"]
@@ -0,0 +1,81 @@
1
+ import { Environment } from '../environment';
2
+ import { IResponseInfo } from '../interfaces';
3
+ import { CloudrunServerType, ICloudrunDetailResponse, ICloudrunListResponse, ITemplate } from './type';
4
+ /**
5
+ * 云托管服务管理类
6
+ * 提供云托管服务的初始化、下载、列表查询和删除等功能
7
+ */
8
+ export declare class CloudRunService {
9
+ private environment;
10
+ private tcbrService;
11
+ private tcbService;
12
+ constructor(environment: Environment);
13
+ /**
14
+ * 初始化云托管代码项目
15
+ * @param {Object} params 初始化参数
16
+ * @param {string} params.serverName 服务名称,将作为项目目录名
17
+ * @param {string} [params.template='helloworld'] 模板标识符,默认为'helloworld'
18
+ * @param {string} [params.targetPath='.'] 目标路径,默认为当前目录
19
+ * @returns {Promise<void>}
20
+ * @throws 当模板不存在、下载失败或解压失败时抛出错误
21
+ */
22
+ init(params: {
23
+ serverName: string;
24
+ template?: string;
25
+ targetPath?: string;
26
+ }): Promise<{
27
+ projectDir: string;
28
+ }>;
29
+ /**
30
+ * 下载云托管服务代码到本地目录
31
+ * @param {Object} params 下载参数
32
+ * @param {string} params.serverName 要下载的服务名称
33
+ * @param {string} params.targetPath 下载的目标路径(绝对路径或相对路径)
34
+ * @returns {Promise<void>}
35
+ * @throws 当以下情况发生时抛出错误:
36
+ * - 未找到服务版本
37
+ * - 获取下载地址失败
38
+ * - 下载或解压过程中出错
39
+ */
40
+ download(params: {
41
+ serverName: string;
42
+ targetPath: string;
43
+ }): Promise<void>;
44
+ /**
45
+ * 获取云托管服务列表
46
+ * @param {Object} [params] 查询参数
47
+ * @param {number} [params.pageSize] 每页数量
48
+ * @param {number} [params.pageNum] 页码
49
+ * @param {string} [params.serverName] 服务名称筛选
50
+ * @param {string} [params.serverType] 服务类型筛选
51
+ * @returns {Promise<ICloudrunListResponse>} 包含服务列表和总数等信息的响应对象
52
+ */
53
+ list(params?: {
54
+ pageSize?: number;
55
+ pageNum?: number;
56
+ serverName?: string;
57
+ serverType?: CloudrunServerType;
58
+ }): Promise<ICloudrunListResponse>;
59
+ /**
60
+ *查询云托管服务详情
61
+ * @param {Object} params 查询参数
62
+ * @param {string} params.serverName 要查询的服务名称
63
+ * @returns {Promise<ICloudrunDetailResponse>} 返回服务详情响应对象
64
+ */
65
+ detail(params: {
66
+ serverName: string;
67
+ }): Promise<ICloudrunDetailResponse>;
68
+ /**
69
+ * 删除指定的云托管服务
70
+ * @param {string} serverName - 要删除的服务名称,必须是在当前环境中已存在的服务
71
+ * @returns {Promise<IResponseInfo>} 返回删除操作的响应信息
72
+ */
73
+ delete(params: {
74
+ serverName: string;
75
+ }): Promise<IResponseInfo>;
76
+ /**
77
+ * 获取云托管服务模板列表
78
+ * @returns {Promise<ITemplate[]>} 返回模板数组
79
+ */
80
+ getTemplates(): Promise<ITemplate[]>;
81
+ }
@@ -0,0 +1,315 @@
1
+ export declare enum CloudrunServerType {
2
+ /**
3
+ * 函数型服务
4
+ */
5
+ Function = "function",
6
+ /**
7
+ * 容器型服务
8
+ */
9
+ Container = "container"
10
+ }
11
+ /**
12
+ * 服务基础信息接口
13
+ */
14
+ export interface ICloudrunServerBaseInfo {
15
+ /**
16
+ * 服务名称
17
+ * @example "serverName"
18
+ */
19
+ ServerName: string;
20
+ /**
21
+ * 默认服务域名
22
+ * @example "http://xxx.xxx.xxx"
23
+ */
24
+ DefaultDomainName: string;
25
+ /**
26
+ * 自定义域名
27
+ * @example "http://xxx.xxx.xxx"
28
+ */
29
+ CustomDomainName: string;
30
+ /**
31
+ * 服务状态
32
+ * @example "running" | "deploying" | "deploy_failed"
33
+ */
34
+ Status: 'running' | 'deploying' | 'deploy_failed';
35
+ /**
36
+ * 更新时间
37
+ * @example "2022-03-09 14:00:00"
38
+ */
39
+ UpdateTime: string;
40
+ /**
41
+ * 公网访问类型数组
42
+ * @example ["OA","MINIAPP","VPC"]
43
+ */
44
+ AccessTypes: string[];
45
+ /**
46
+ * 展示自定义域名数组
47
+ * @example ["http://xxx.xxx.xxx","http://xxx.xxx.xxx"]
48
+ */
49
+ CustomDomainNames: string[];
50
+ /**
51
+ * 服务类型
52
+ * @example "function" | "container"
53
+ */
54
+ ServerType: CloudrunServerType;
55
+ /**
56
+ * 流量类型(请根据实际业务补充具体类型定义)
57
+ */
58
+ TrafficType?: string;
59
+ }
60
+ /**
61
+ * 扩缩容策略配置
62
+ */
63
+ export interface ICloudrunHpaPolicy {
64
+ /**
65
+ * 扩缩容类型
66
+ * @example "cpu" | "mem" | "cpu/mem"
67
+ */
68
+ PolicyType: string;
69
+ /**
70
+ * 扩缩容阈值(百分比)
71
+ * @example 60
72
+ */
73
+ PolicyThreshold: number;
74
+ }
75
+ /**
76
+ * 定时扩缩容配置
77
+ */
78
+ export interface ICloudrunTimerScale {
79
+ /**
80
+ * 循环类型
81
+ * @example "none"
82
+ */
83
+ CycleType?: string;
84
+ /**
85
+ * 循环起始日期
86
+ * @example "2022-09-08"
87
+ */
88
+ StartDate?: string;
89
+ /**
90
+ * 循环结束日期
91
+ * @example "2022-09-08"
92
+ */
93
+ EndDate?: string;
94
+ /**
95
+ * 起始时间
96
+ * @example "00:00:00"
97
+ */
98
+ StartTime?: string;
99
+ /**
100
+ * 结束时间
101
+ * @example "23:59:00"
102
+ */
103
+ EndTime?: string;
104
+ /**
105
+ * 副本个数
106
+ * @example 1
107
+ */
108
+ ReplicaNum?: number;
109
+ }
110
+ /**
111
+ * 服务基础配置信息
112
+ */
113
+ export interface ICloudrunServerBaseConfig {
114
+ /**
115
+ * 环境 ID
116
+ * @example "test-1gbtbgkjf8f48e2c"
117
+ */
118
+ EnvId: string;
119
+ /**
120
+ * 服务名称
121
+ * @example "server-name"
122
+ */
123
+ ServerName: string;
124
+ /**
125
+ * 公网访问类型数组
126
+ * @example ["PUBLIC", "OA", "MINIAPP", "VPC", ""]
127
+ */
128
+ OpenAccessTypes: string[];
129
+ /**
130
+ * CPU 规格
131
+ * @example 0.25
132
+ */
133
+ Cpu: number;
134
+ /**
135
+ * 内存规格
136
+ * @example 0.25
137
+ */
138
+ Mem: number;
139
+ /**
140
+ * 最小副本数
141
+ * @example 1
142
+ */
143
+ MinNum: number;
144
+ /**
145
+ * 最大副本数
146
+ * @example 2
147
+ */
148
+ MaxNum: number;
149
+ /**
150
+ * 扩缩容配置
151
+ * @example cpu, mem, cpu/mem
152
+ */
153
+ PolicyDetails: ICloudrunHpaPolicy[];
154
+ /**
155
+ * 日志采集路径
156
+ * @example "stdout"
157
+ */
158
+ CustomLogs: string;
159
+ /**
160
+ * 环境变量
161
+ * @example {"MYSQL_USERNAME":"root"}
162
+ */
163
+ EnvParams: string;
164
+ /**
165
+ * 延迟检测时间(秒)
166
+ * @example 2
167
+ */
168
+ InitialDelaySeconds: number;
169
+ /**
170
+ * 创建时间
171
+ * @example "2022-03-10 19:44:07"
172
+ */
173
+ CreateTime: string;
174
+ /**
175
+ * 服务端口
176
+ * @example 8080
177
+ */
178
+ Port: number;
179
+ /**
180
+ * 是否有 Dockerfile
181
+ * @example true
182
+ */
183
+ HasDockerfile: boolean;
184
+ /**
185
+ * Dockerfile 文件名
186
+ * @example "Dockerfile"
187
+ */
188
+ Dockerfile: string;
189
+ /**
190
+ * 构建目录
191
+ * @example "src/"
192
+ */
193
+ BuildDir: string;
194
+ /**
195
+ * 日志类型
196
+ * @example "none" | "default" | "custom"
197
+ */
198
+ LogType?: string;
199
+ /**
200
+ * CLS 日志集 ID
201
+ * @example "dafslakfjkdal"
202
+ */
203
+ LogSetId?: string;
204
+ /**
205
+ * CLS 主题 ID
206
+ * @example "sfafkslkfj"
207
+ */
208
+ LogTopicId?: string;
209
+ /**
210
+ * 日志解析类型
211
+ * @example "json" | "line"
212
+ */
213
+ LogParseType?: string;
214
+ /**
215
+ * 服务标签
216
+ * @example "function"
217
+ */
218
+ Tag?: string;
219
+ /**
220
+ * 内网访问开关
221
+ * @example "close" | "open"
222
+ */
223
+ InternalAccess?: string;
224
+ /**
225
+ * 内网域名
226
+ * @example "https://sdfsdf"
227
+ */
228
+ InternalDomain?: string;
229
+ /**
230
+ * 运行模式
231
+ * @example "custom"
232
+ */
233
+ OperationMode?: string;
234
+ /**
235
+ * 定时扩缩容配置
236
+ */
237
+ TimerScale?: ICloudrunTimerScale[];
238
+ /**
239
+ * Dockerfile EntryPoint 参数
240
+ * @example ["echo", "test"]
241
+ */
242
+ EntryPoint?: string[];
243
+ /**
244
+ * Dockerfile Cmd 参数
245
+ * @example ["echo", "test"]
246
+ */
247
+ Cmd?: string[];
248
+ }
249
+ /**
250
+ * 在线版本信息
251
+ */
252
+ export interface ICloudrunOnlineVersionInfo {
253
+ /**
254
+ * 版本名称
255
+ * @example "test-001"
256
+ */
257
+ VersionName: string;
258
+ /**
259
+ * 镜像URL
260
+ * @example "imageurl"
261
+ */
262
+ ImageUrl: string;
263
+ /**
264
+ * 流量比例
265
+ * @example "100"
266
+ */
267
+ FlowRatio: string;
268
+ }
269
+ /**
270
+ * 服务列表响应接口
271
+ */
272
+ export interface ICloudrunListResponse {
273
+ /**
274
+ * 服务列表数组
275
+ */
276
+ ServerList: ICloudrunServerBaseInfo[];
277
+ /**
278
+ * 服务总数
279
+ * @example 10
280
+ */
281
+ Total: number;
282
+ /**
283
+ * 请求ID
284
+ */
285
+ RequestId: string;
286
+ }
287
+ /**
288
+ * 服务详情响应接口
289
+ */
290
+ export interface ICloudrunDetailResponse {
291
+ /**
292
+ * 服务基本信息
293
+ */
294
+ BaseInfo: ICloudrunServerBaseInfo;
295
+ /**
296
+ * 服务配置信息
297
+ */
298
+ ServerConfig: ICloudrunServerBaseConfig;
299
+ /**
300
+ * 在线版本信息
301
+ */
302
+ OnlineVersionInfos: ICloudrunOnlineVersionInfo[];
303
+ /**
304
+ * 请求ID
305
+ */
306
+ RequestId: string;
307
+ }
308
+ export interface ITemplate {
309
+ identifier: string;
310
+ title: string;
311
+ description: string;
312
+ runtimeVersion: string;
313
+ language: string;
314
+ zipFileStore: string;
315
+ }
@@ -1,5 +1,6 @@
1
1
  import { DatabaseService } from './database';
2
2
  import { FunctionService } from './function';
3
+ import { CloudRunService } from './cloudrun';
3
4
  import { StorageService } from './storage';
4
5
  import { EnvService } from './env';
5
6
  import { CommonService } from './common';
@@ -17,6 +18,7 @@ export declare class Environment {
17
18
  private envId;
18
19
  private envType?;
19
20
  private functionService;
21
+ private cloudRunService;
20
22
  private databaseService;
21
23
  private storageService;
22
24
  private envService;
@@ -32,6 +34,7 @@ export declare class Environment {
32
34
  getStorageService(): StorageService;
33
35
  getDatabaseService(): DatabaseService;
34
36
  getFunctionService(): FunctionService;
37
+ getCloudRunService(): CloudRunService;
35
38
  getEnvService(): EnvService;
36
39
  getHostingService(): HostingService;
37
40
  getThirdService(): ThirdService;
package/types/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { EnvService } from './env';
2
2
  import { FunctionService } from './function';
3
+ import { CloudRunService } from './cloudrun';
3
4
  import { StorageService } from './storage';
4
5
  import { DatabaseService } from './database';
5
6
  import { CommonService } from './common';
@@ -37,6 +38,7 @@ declare class CloudBase {
37
38
  addEnvironment(envId: string): void;
38
39
  currentEnvironment(): Environment;
39
40
  get functions(): FunctionService;
41
+ get cloudrun(): CloudRunService;
40
42
  get storage(): StorageService;
41
43
  get database(): DatabaseService;
42
44
  get hosting(): HostingService;
@@ -1,3 +1,3 @@
1
1
  import _fetch from 'node-fetch';
2
- export declare function fetch(url: string, config: Record<string, any>, proxy: any): Promise<any>;
3
- export declare function fetchStream(url: string, config: Record<string, any>, proxy: any): Promise<_fetch.Response>;
2
+ export declare function fetch(url: string, config?: Record<string, any>, proxy?: any): Promise<any>;
3
+ export declare function fetchStream(url: string, config?: Record<string, any>, proxy?: any): Promise<_fetch.Response>;
@@ -1,10 +1,11 @@
1
- export { guid6 } from './uuid';
2
- export * from './cloud-api-request';
1
+ import { ITemplate } from '../cloudrun/type';
3
2
  export * from './auth';
3
+ export * from './cloud-api-request';
4
4
  export * from './cloudbase-request';
5
- export * from './http-request';
6
5
  export * from './envLazy';
7
6
  export * from './fs';
7
+ export * from './http-request';
8
+ export { guid6 } from './uuid';
8
9
  interface IZipOption {
9
10
  dirPath: string;
10
11
  outputPath: string;
@@ -12,9 +13,23 @@ interface IZipOption {
12
13
  pattern?: string;
13
14
  }
14
15
  export declare function compressToZip(option: IZipOption): Promise<unknown>;
16
+ /**
17
+ * 下载并解压云托管模板到指定目录
18
+ * @param {string} downloadUrl 模板下载地址
19
+ * @param {string} targetPath 目标路径
20
+ * @returns {Promise<void>}
21
+ * @throws 当下载失败或解压失败时抛出错误
22
+ */
23
+ export declare function downloadAndExtractRemoteZip(downloadUrl: string, targetPath: string): Promise<void>;
15
24
  export declare function getRuntime(): string;
16
25
  export declare function getEnvVar(envName: string): string;
17
26
  export declare function rsaEncrypt(data: string): string;
18
27
  export declare function sleep(time: number): Promise<void>;
19
28
  export declare function upperCaseStringFisrt(str: string): string;
20
29
  export declare function upperCaseObjKey(object: any): any;
30
+ /**
31
+ * 获取函数模板列表
32
+ * @param type 函数模板类型,支持 'scfFunc' 和 'tcbrFunc'
33
+ * @returns
34
+ */
35
+ export declare function fetchTemplates(types: ('scfFunc' | 'tcbrFunc' | 'tcbrContainer')[]): Promise<ITemplate[]>;