@cloudbase/manager-node 5.5.2-beta.0 → 5.5.3-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/jest.config.js +1 -1
- package/lib/database/index.js +25 -13
- package/lib/env/index.js +71 -0
- package/lib/environment.js +0 -5
- package/lib/index.js +0 -3
- package/lib/user/index.js +3 -1
- package/package.json +2 -1
- package/types/database/index.d.ts +2 -1
- package/types/env/index.d.ts +16 -0
- package/types/environment.d.ts +0 -3
- package/types/index.d.ts +0 -2
- package/types/user/types.d.ts +1 -0
- package/lib/talosSandbox/index.js +0 -1121
- package/lib/talosSandbox/type.js +0 -3
- package/types/talosSandbox/index.d.ts +0 -182
- package/types/talosSandbox/type.d.ts +0 -689
package/jest.config.js
CHANGED
|
@@ -12,7 +12,7 @@ module.exports = {
|
|
|
12
12
|
testEnvironment: 'node',
|
|
13
13
|
testPathIgnorePatterns: [
|
|
14
14
|
// PG 集成测试 / smoke 测试需要 PostgreSQL 环境,流水线默认跳过
|
|
15
|
-
'
|
|
15
|
+
'pg-storage-integration\\.test\\.ts$'
|
|
16
16
|
],
|
|
17
17
|
// https://github.com/facebook/jest/issues/5164
|
|
18
18
|
globalSetup: './test/global-setup-hook.ts',
|
package/lib/database/index.js
CHANGED
|
@@ -46,6 +46,14 @@ class DatabaseService {
|
|
|
46
46
|
Tag: Databases[0].InstanceId
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
+
getMongoConnector() {
|
|
50
|
+
const currEnv = this.environment;
|
|
51
|
+
const { Databases } = currEnv.lazyEnvironmentConfig;
|
|
52
|
+
return {
|
|
53
|
+
DatabaseName: Databases[0].InstanceId,
|
|
54
|
+
InstanceId: 'flexdb'
|
|
55
|
+
};
|
|
56
|
+
}
|
|
49
57
|
async checkCollectionExists(collectionName) {
|
|
50
58
|
try {
|
|
51
59
|
const result = await this.describeCollection(collectionName);
|
|
@@ -63,10 +71,10 @@ class DatabaseService {
|
|
|
63
71
|
}
|
|
64
72
|
}
|
|
65
73
|
async createCollection(collectionName) {
|
|
66
|
-
|
|
74
|
+
const MongoConnector = this.getMongoConnector();
|
|
67
75
|
const res = await this.dbOpService.request('CreateTable', {
|
|
68
76
|
EnvId: this.envId,
|
|
69
|
-
|
|
77
|
+
MongoConnector,
|
|
70
78
|
TableName: collectionName
|
|
71
79
|
});
|
|
72
80
|
return res;
|
|
@@ -75,10 +83,10 @@ class DatabaseService {
|
|
|
75
83
|
// 先检查当前集合是否存在
|
|
76
84
|
const existRes = await this.checkCollectionExists(collectionName);
|
|
77
85
|
if (existRes.Exists) {
|
|
78
|
-
|
|
86
|
+
const MongoConnector = this.getMongoConnector();
|
|
79
87
|
const res = await this.dbOpService.request('DeleteTable', {
|
|
80
88
|
EnvId: this.envId,
|
|
81
|
-
|
|
89
|
+
MongoConnector,
|
|
82
90
|
TableName: collectionName
|
|
83
91
|
});
|
|
84
92
|
return res;
|
|
@@ -88,15 +96,15 @@ class DatabaseService {
|
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
async updateCollection(collectionName, indexiesInfo) {
|
|
91
|
-
|
|
92
|
-
const res = await this.dbOpService.request('UpdateTable', Object.assign({ EnvId: this.envId,
|
|
99
|
+
const MongoConnector = this.getMongoConnector();
|
|
100
|
+
const res = await this.dbOpService.request('UpdateTable', Object.assign({ EnvId: this.envId, MongoConnector, TableName: collectionName }, indexiesInfo));
|
|
93
101
|
return res;
|
|
94
102
|
}
|
|
95
103
|
async describeCollection(collectionName) {
|
|
96
|
-
|
|
104
|
+
const MongoConnector = this.getMongoConnector();
|
|
97
105
|
return this.dbOpService.request('DescribeTable', {
|
|
98
106
|
EnvId: this.envId,
|
|
99
|
-
|
|
107
|
+
MongoConnector,
|
|
100
108
|
TableName: collectionName
|
|
101
109
|
});
|
|
102
110
|
}
|
|
@@ -105,14 +113,14 @@ class DatabaseService {
|
|
|
105
113
|
MgoLimit: this.DEFAULT_MGO_LIMIT,
|
|
106
114
|
MgoOffset: this.DEFAULT_MGO_OFFSET
|
|
107
115
|
}) {
|
|
108
|
-
|
|
116
|
+
const MongoConnector = this.getMongoConnector();
|
|
109
117
|
if (options.MgoLimit === undefined) {
|
|
110
118
|
options.MgoLimit = this.DEFAULT_MGO_LIMIT;
|
|
111
119
|
}
|
|
112
120
|
if (options.MgoOffset === undefined) {
|
|
113
121
|
options.MgoOffset = this.DEFAULT_MGO_OFFSET;
|
|
114
122
|
}
|
|
115
|
-
const res = await this.dbOpService.request('ListTables', Object.assign({ EnvId: this.envId,
|
|
123
|
+
const res = await this.dbOpService.request('ListTables', Object.assign({ EnvId: this.envId, MongoConnector }, options));
|
|
116
124
|
if (res.Tables === null) {
|
|
117
125
|
// 无集合
|
|
118
126
|
res.Collections = [];
|
|
@@ -277,12 +285,16 @@ class DatabaseService {
|
|
|
277
285
|
}
|
|
278
286
|
/**
|
|
279
287
|
* 执行文档型数据库命令
|
|
280
|
-
* @param options 命令参数(命令列表、可选的
|
|
288
|
+
* @param options 命令参数(命令列表、可选的 EnvId/MongoConnector)
|
|
281
289
|
* @returns 执行结果,Data 为 JSON 字符串数组
|
|
282
290
|
*/
|
|
283
291
|
async runCommands(options) {
|
|
284
|
-
|
|
285
|
-
return this.dbOpService.request('RunCommands',
|
|
292
|
+
const MongoConnector = options.MongoConnector || this.getMongoConnector();
|
|
293
|
+
return this.dbOpService.request('RunCommands', {
|
|
294
|
+
MgoCommands: options.MgoCommands,
|
|
295
|
+
MongoConnector,
|
|
296
|
+
EnvId: options.EnvId || this.envId,
|
|
297
|
+
});
|
|
286
298
|
}
|
|
287
299
|
/**
|
|
288
300
|
* 在 PostgreSQL 数据库上执行 SQL 语句
|
package/lib/env/index.js
CHANGED
|
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.EnvService = void 0;
|
|
13
13
|
const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
14
14
|
const util_1 = __importDefault(require("util"));
|
|
15
|
+
const http_request_1 = require("../utils/http-request");
|
|
16
|
+
const signature_nodejs_1 = require("@cloudbase/signature-nodejs");
|
|
15
17
|
const error_1 = require("../error");
|
|
16
18
|
const utils_1 = require("../utils");
|
|
17
19
|
const constant_1 = require("../constant");
|
|
@@ -26,6 +28,7 @@ class EnvService {
|
|
|
26
28
|
this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
|
|
27
29
|
this.commonService = environment.getCommonService('lowcode', '2021-01-08');
|
|
28
30
|
this.billingService = new billing_1.BillingService(environment.cloudBaseContext);
|
|
31
|
+
this.tokenCache = new Map();
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
34
|
* 列出所有环境
|
|
@@ -410,6 +413,74 @@ class EnvService {
|
|
|
410
413
|
async describeApiKeyList(options) {
|
|
411
414
|
return this.tcbService.request('DescribeApiKeyList', Object.assign({ EnvId: this.envId }, options));
|
|
412
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* 根据密钥信息获取管理员访问令牌
|
|
418
|
+
* 使用 secretId、secretKey 和 sessionToken 签发访问令牌
|
|
419
|
+
* 默认从初始化时的 cloudBaseContext 中读取密钥,也可显式传入 credentials 覆盖
|
|
420
|
+
* @param {Object} [credentials] 密钥信息,不传则使用初始化时的密钥
|
|
421
|
+
* @param {string} credentials.secretId 密钥ID
|
|
422
|
+
* @param {string} credentials.secretKey 密钥Key
|
|
423
|
+
* @param {string} [credentials.token] sessionToken
|
|
424
|
+
* @returns {Promise<string>} 访问令牌
|
|
425
|
+
*/
|
|
426
|
+
async getAdminAccessToken(credentials) {
|
|
427
|
+
const { secretId, secretKey, token } = credentials || this.environment.cloudBaseContext;
|
|
428
|
+
if (!secretId || !secretKey) {
|
|
429
|
+
throw new error_1.CloudBaseError('missing secretId or secretKey of tencent cloud');
|
|
430
|
+
}
|
|
431
|
+
const envId = this.envId;
|
|
432
|
+
const cacheKey = `access_token_secret_${envId}_${secretId}`;
|
|
433
|
+
const cached = this.tokenCache.get(cacheKey);
|
|
434
|
+
if (cached && cached.expiry > Date.now()) {
|
|
435
|
+
return cached.token;
|
|
436
|
+
}
|
|
437
|
+
const host = `${envId}${this.environment.cloudBaseContext.isInternalEndpoint()
|
|
438
|
+
? '.api.intl.tcloudbasegateway.com'
|
|
439
|
+
: '.api.tcloudbasegateway.com'}`;
|
|
440
|
+
const url = `https://${host}/auth/v1/token/clientCredential`;
|
|
441
|
+
const method = 'POST';
|
|
442
|
+
const headers = {
|
|
443
|
+
'Content-Type': 'application/json',
|
|
444
|
+
Host: host,
|
|
445
|
+
};
|
|
446
|
+
const data = { grant_type: 'client_credentials' };
|
|
447
|
+
const timestamp = Math.floor(new Date().getTime() / 1000) - 1;
|
|
448
|
+
const { authorization, timestamp: signTimestamp } = (0, signature_nodejs_1.sign)({
|
|
449
|
+
secretId,
|
|
450
|
+
secretKey,
|
|
451
|
+
method,
|
|
452
|
+
url,
|
|
453
|
+
headers,
|
|
454
|
+
params: data,
|
|
455
|
+
timestamp,
|
|
456
|
+
withSignedParams: false,
|
|
457
|
+
isCloudApi: true,
|
|
458
|
+
});
|
|
459
|
+
headers['Authorization'] = `${authorization}, Timestamp=${signTimestamp}${token ? `, Token=${token}` : ''}`;
|
|
460
|
+
headers['X-Signature-Expires'] = 600;
|
|
461
|
+
headers['X-Timestamp'] = signTimestamp;
|
|
462
|
+
try {
|
|
463
|
+
const response = await (0, http_request_1.fetch)(url, {
|
|
464
|
+
method,
|
|
465
|
+
headers,
|
|
466
|
+
body: JSON.stringify(data),
|
|
467
|
+
});
|
|
468
|
+
const res = await response.json();
|
|
469
|
+
const access_token = res === null || res === void 0 ? void 0 : res.access_token;
|
|
470
|
+
const expires_in = (res === null || res === void 0 ? void 0 : res.expires_in) || 0;
|
|
471
|
+
if (access_token && expires_in) {
|
|
472
|
+
this.tokenCache.set(cacheKey, {
|
|
473
|
+
token: access_token,
|
|
474
|
+
expiry: Date.now() + (expires_in * 1000) / 2,
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
return access_token;
|
|
478
|
+
}
|
|
479
|
+
catch (e) {
|
|
480
|
+
console.log(e);
|
|
481
|
+
throw e;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
413
484
|
// 创建自定义登录私钥
|
|
414
485
|
async createCustomLoginKeys() {
|
|
415
486
|
return this.cloudService.request('CreateCustomLoginKeys', {
|
package/lib/environment.js
CHANGED
|
@@ -22,7 +22,6 @@ const cloudApp_1 = require("./cloudApp");
|
|
|
22
22
|
const permission_1 = require("./permission");
|
|
23
23
|
const sandbox_1 = require("./sandbox");
|
|
24
24
|
const aiModel_1 = require("./aiModel");
|
|
25
|
-
const talosSandbox_1 = require("./talosSandbox");
|
|
26
25
|
class Environment {
|
|
27
26
|
constructor(context, envId) {
|
|
28
27
|
this.inited = false;
|
|
@@ -48,7 +47,6 @@ class Environment {
|
|
|
48
47
|
this.cloudAppService = new cloudApp_1.CloudAppService(this);
|
|
49
48
|
this.sandboxService = new sandbox_1.SandboxService(this);
|
|
50
49
|
this.aiModelService = new aiModel_1.AiModelService(this);
|
|
51
|
-
this.talosSandboxService = new talosSandbox_1.TalosSandboxService(this);
|
|
52
50
|
}
|
|
53
51
|
async lazyInit() {
|
|
54
52
|
if (!this.inited) {
|
|
@@ -123,9 +121,6 @@ class Environment {
|
|
|
123
121
|
getAiModelService() {
|
|
124
122
|
return this.aiModelService;
|
|
125
123
|
}
|
|
126
|
-
getTalosSandboxService() {
|
|
127
|
-
return this.talosSandboxService;
|
|
128
|
-
}
|
|
129
124
|
getCommonService(serviceType = 'tcb', serviceVersion) {
|
|
130
125
|
return new common_1.CommonService(this, serviceType, serviceVersion);
|
|
131
126
|
}
|
package/lib/index.js
CHANGED
|
@@ -122,9 +122,6 @@ class CloudBase {
|
|
|
122
122
|
get aiModel() {
|
|
123
123
|
return this.currentEnvironment().getAiModelService();
|
|
124
124
|
}
|
|
125
|
-
get talosSandbox() {
|
|
126
|
-
return this.currentEnvironment().getTalosSandboxService();
|
|
127
|
-
}
|
|
128
125
|
get docs() {
|
|
129
126
|
if (!this.docsService) {
|
|
130
127
|
this.docsService = new docs_1.DocsService();
|
package/lib/user/index.js
CHANGED
|
@@ -188,7 +188,7 @@ class UserService {
|
|
|
188
188
|
}
|
|
189
189
|
async describeUserList(options = {}) {
|
|
190
190
|
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
191
|
-
const { pageNo = 1, pageSize = 20, name, nickName, phone, email } = options;
|
|
191
|
+
const { pageNo = 1, pageSize = 20, name, nickName, phone, email, uidList } = options;
|
|
192
192
|
if (!Number.isInteger(pageNo) || pageNo < 1) {
|
|
193
193
|
throw new Error('Invalid pageNo');
|
|
194
194
|
}
|
|
@@ -208,6 +208,8 @@ class UserService {
|
|
|
208
208
|
reqData.Phone = phone;
|
|
209
209
|
if (this.isValidStr(email))
|
|
210
210
|
reqData.Email = email;
|
|
211
|
+
if (Array.isArray(uidList) && uidList.length > 0)
|
|
212
|
+
reqData.UidList = uidList;
|
|
211
213
|
return this.tcbService.request('DescribeUserList', reqData);
|
|
212
214
|
}
|
|
213
215
|
async modifyUser(options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/manager-node",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.3-beta.0",
|
|
4
4
|
"description": "The node manage service api for cloudbase.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"typescript": "^5.8.3"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@cloudbase/signature-nodejs": "^1.0.0",
|
|
44
45
|
"@cloudbase/database": "^0.6.2",
|
|
45
46
|
"archiver": "^3.1.1",
|
|
46
47
|
"cos-nodejs-sdk-v5": "^2.14.0",
|
|
@@ -155,6 +155,7 @@ export declare class DatabaseService {
|
|
|
155
155
|
constructor(environment: Environment);
|
|
156
156
|
getCurrEnvironment(): Environment;
|
|
157
157
|
getDatabaseConfig(): IDatabaseConfig;
|
|
158
|
+
getMongoConnector(): IMongoConnector;
|
|
158
159
|
checkCollectionExists(collectionName: string): Promise<IExistsRes>;
|
|
159
160
|
createCollection(collectionName: string): Promise<any>;
|
|
160
161
|
deleteCollection(collectionName: string): Promise<any>;
|
|
@@ -197,7 +198,7 @@ export declare class DatabaseService {
|
|
|
197
198
|
restoreTables(time: string, modifyTableNamesInfo: IModifyTableNamesInfo[], instanceId?: string): Promise<IRestoreTCBTablesResult>;
|
|
198
199
|
/**
|
|
199
200
|
* 执行文档型数据库命令
|
|
200
|
-
* @param options 命令参数(命令列表、可选的
|
|
201
|
+
* @param options 命令参数(命令列表、可选的 EnvId/MongoConnector)
|
|
201
202
|
* @returns 执行结果,Data 为 JSON 字符串数组
|
|
202
203
|
*/
|
|
203
204
|
runCommands(options: IRunCommandsOptions): Promise<IRunCommandsResult>;
|
package/types/env/index.d.ts
CHANGED
|
@@ -559,6 +559,7 @@ export declare class EnvService {
|
|
|
559
559
|
private envType?;
|
|
560
560
|
private commonService;
|
|
561
561
|
private billingService;
|
|
562
|
+
private tokenCache;
|
|
562
563
|
constructor(environment: Environment);
|
|
563
564
|
/**
|
|
564
565
|
* 列出所有环境
|
|
@@ -779,6 +780,21 @@ export declare class EnvService {
|
|
|
779
780
|
* @returns {Promise<IDescribeApiKeyListRes>}
|
|
780
781
|
*/
|
|
781
782
|
describeApiKeyList(options?: IDescribeApiKeyListParams): Promise<IDescribeApiKeyListRes>;
|
|
783
|
+
/**
|
|
784
|
+
* 根据密钥信息获取管理员访问令牌
|
|
785
|
+
* 使用 secretId、secretKey 和 sessionToken 签发访问令牌
|
|
786
|
+
* 默认从初始化时的 cloudBaseContext 中读取密钥,也可显式传入 credentials 覆盖
|
|
787
|
+
* @param {Object} [credentials] 密钥信息,不传则使用初始化时的密钥
|
|
788
|
+
* @param {string} credentials.secretId 密钥ID
|
|
789
|
+
* @param {string} credentials.secretKey 密钥Key
|
|
790
|
+
* @param {string} [credentials.token] sessionToken
|
|
791
|
+
* @returns {Promise<string>} 访问令牌
|
|
792
|
+
*/
|
|
793
|
+
getAdminAccessToken(credentials?: {
|
|
794
|
+
secretId: string;
|
|
795
|
+
secretKey: string;
|
|
796
|
+
token?: string;
|
|
797
|
+
}): Promise<string>;
|
|
782
798
|
createCustomLoginKeys(): Promise<{
|
|
783
799
|
PrivateKey: string;
|
|
784
800
|
KeyID: string;
|
package/types/environment.d.ts
CHANGED
|
@@ -18,7 +18,6 @@ import { EnvInfo } from './interfaces';
|
|
|
18
18
|
import { PermissionService } from './permission';
|
|
19
19
|
import { SandboxService } from './sandbox';
|
|
20
20
|
import { AiModelService } from './aiModel';
|
|
21
|
-
import { TalosSandboxService } from './talosSandbox';
|
|
22
21
|
export declare class Environment {
|
|
23
22
|
inited: boolean;
|
|
24
23
|
cloudBaseContext: CloudBaseContext;
|
|
@@ -42,7 +41,6 @@ export declare class Environment {
|
|
|
42
41
|
private cloudAppService;
|
|
43
42
|
private sandboxService;
|
|
44
43
|
private aiModelService;
|
|
45
|
-
private talosSandboxService;
|
|
46
44
|
constructor(context: CloudBaseContext, envId: string);
|
|
47
45
|
lazyInit(): Promise<any>;
|
|
48
46
|
getEnvId(): string;
|
|
@@ -64,7 +62,6 @@ export declare class Environment {
|
|
|
64
62
|
getPermissionService(): PermissionService;
|
|
65
63
|
getSandboxService(): SandboxService;
|
|
66
64
|
getAiModelService(): AiModelService;
|
|
67
|
-
getTalosSandboxService(): TalosSandboxService;
|
|
68
65
|
getCommonService(serviceType: string, serviceVersion: any): CommonService;
|
|
69
66
|
getServicesEnvInfo(): Promise<any>;
|
|
70
67
|
getAuthConfig(): {
|
package/types/index.d.ts
CHANGED
|
@@ -19,7 +19,6 @@ import { PermissionService } from './permission';
|
|
|
19
19
|
import { SandboxService } from './sandbox';
|
|
20
20
|
import { CloudAppService } from './cloudApp';
|
|
21
21
|
import { AiModelService } from './aiModel';
|
|
22
|
-
import { TalosSandboxService } from './talosSandbox';
|
|
23
22
|
interface CloudBaseConfig {
|
|
24
23
|
secretId?: string;
|
|
25
24
|
secretKey?: string;
|
|
@@ -85,7 +84,6 @@ declare class CloudBase {
|
|
|
85
84
|
get permission(): PermissionService;
|
|
86
85
|
get sandbox(): SandboxService;
|
|
87
86
|
get aiModel(): AiModelService;
|
|
88
|
-
get talosSandbox(): TalosSandboxService;
|
|
89
87
|
get docs(): DocsService;
|
|
90
88
|
getEnvironmentManager(): EnvironmentManager;
|
|
91
89
|
getManagerConfig(): CloudBaseConfig;
|