@cloudbase/manager-node 4.2.0 → 4.2.2
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/CHANGELOG.md +0 -4
- package/lib/constant.js +1 -5
- package/lib/env/index.js +209 -10
- package/lib/function/index.js +21 -3
- package/lib/storage/index.js +3 -19
- package/lib/utils/cloud-api-request.js +0 -7
- package/lib/utils/http-request.js +3 -3
- package/package.json +3 -4
- package/src/access/index.ts +168 -0
- package/src/access/types.ts +55 -0
- package/src/billing/index.ts +43 -0
- package/src/cam/index.ts +106 -0
- package/src/cloudBaseRun/index.ts +40 -0
- package/src/cloudBaseRun/types.ts +24 -0
- package/src/common/index.ts +54 -0
- package/src/constant.ts +56 -0
- package/src/context.ts +18 -0
- package/src/database/index.ts +369 -0
- package/src/debug.ts +34 -0
- package/src/env/index.ts +614 -0
- package/src/environment.ts +156 -0
- package/src/environmentManager.ts +50 -0
- package/src/error.ts +27 -0
- package/src/function/index.ts +1378 -0
- package/src/function/packer.ts +164 -0
- package/src/function/types.ts +165 -0
- package/src/hosting/index.ts +698 -0
- package/src/index.ts +127 -0
- package/src/interfaces/base.interface.ts +8 -0
- package/src/interfaces/billing.interface.ts +21 -0
- package/src/interfaces/cam.interface.ts +28 -0
- package/src/interfaces/flexdb.interface.ts +104 -0
- package/src/interfaces/function.interface.ts +75 -0
- package/src/interfaces/index.ts +7 -0
- package/src/interfaces/storage.interface.ts +29 -0
- package/src/interfaces/tcb.interface.ts +642 -0
- package/src/storage/index.ts +1281 -0
- package/src/third/index.ts +24 -0
- package/src/user/index.ts +174 -0
- package/src/user/types.ts +21 -0
- package/src/utils/auth.ts +112 -0
- package/src/utils/cloud-api-request.ts +252 -0
- package/src/utils/cloudbase-request.ts +109 -0
- package/src/utils/envLazy.ts +15 -0
- package/src/utils/fs.ts +57 -0
- package/src/utils/http-request.ts +37 -0
- package/src/utils/index.ts +103 -0
- package/src/utils/parallel.ts +82 -0
- package/src/utils/uuid.ts +14 -0
- package/types/constant.d.ts +0 -7
- package/types/env/index.d.ts +17 -0
- package/types/function/index.d.ts +6 -1
- package/types/function/types.d.ts +2 -0
- package/types/interfaces/tcb.interface.d.ts +6 -0
- package/lib/utils/runenv.js +0 -8
- package/types/utils/runenv.d.ts +0 -1
package/src/index.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { EnvService } from './env'
|
|
2
|
+
import { FunctionService } from './function'
|
|
3
|
+
import { StorageService } from './storage'
|
|
4
|
+
import { DatabaseService } from './database'
|
|
5
|
+
import { CloudBaseContext } from './context'
|
|
6
|
+
import { CommonService } from './common'
|
|
7
|
+
import { HostingService } from './hosting'
|
|
8
|
+
import { Environment } from './environment'
|
|
9
|
+
import { EnvironmentManager } from './environmentManager'
|
|
10
|
+
import { ThirdService } from './third'
|
|
11
|
+
import { AccessService } from './access'
|
|
12
|
+
import { UserService } from './user'
|
|
13
|
+
import { CloudBaseRunService } from './cloudBaseRun'
|
|
14
|
+
|
|
15
|
+
interface CloudBaseConfig {
|
|
16
|
+
secretId?: string
|
|
17
|
+
secretKey?: string
|
|
18
|
+
token?: string
|
|
19
|
+
envId?: string
|
|
20
|
+
proxy?: string
|
|
21
|
+
region?: string
|
|
22
|
+
envType?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class CloudBase {
|
|
26
|
+
private static cloudBase: CloudBase
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* init 初始化 为单例
|
|
30
|
+
*
|
|
31
|
+
* @static
|
|
32
|
+
* @param {ManagerConfig} config
|
|
33
|
+
* @returns {CloudBase}
|
|
34
|
+
* @memberof CloudBase
|
|
35
|
+
*/
|
|
36
|
+
public static init(config: CloudBaseConfig): CloudBase {
|
|
37
|
+
if (!CloudBase.cloudBase) {
|
|
38
|
+
CloudBase.cloudBase = new CloudBase(config)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return CloudBase.cloudBase
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private context: CloudBaseContext
|
|
45
|
+
private cloudBaseConfig: CloudBaseConfig = {}
|
|
46
|
+
private environmentManager: EnvironmentManager
|
|
47
|
+
|
|
48
|
+
public constructor(config: CloudBaseConfig = {}) {
|
|
49
|
+
let { secretId, secretKey, token, envId, proxy, region, envType } = config
|
|
50
|
+
// config 中传入的 secretId secretkey 必须同时存在
|
|
51
|
+
if ((secretId && !secretKey) || (!secretId && secretKey)) {
|
|
52
|
+
throw new Error('secretId and secretKey must be a pair')
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.cloudBaseConfig = {
|
|
56
|
+
secretId,
|
|
57
|
+
secretKey,
|
|
58
|
+
token,
|
|
59
|
+
envId,
|
|
60
|
+
envType,
|
|
61
|
+
proxy,
|
|
62
|
+
region
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 初始化 context
|
|
66
|
+
this.context = new CloudBaseContext(this.cloudBaseConfig)
|
|
67
|
+
|
|
68
|
+
this.environmentManager = new EnvironmentManager(this.context)
|
|
69
|
+
this.environmentManager.add(envId || '')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public addEnvironment(envId: string): void {
|
|
73
|
+
this.environmentManager.add(envId)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public currentEnvironment(): Environment {
|
|
77
|
+
return this.environmentManager.getCurrentEnv()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public get functions(): FunctionService {
|
|
81
|
+
return this.currentEnvironment().getFunctionService()
|
|
82
|
+
}
|
|
83
|
+
public get storage(): StorageService {
|
|
84
|
+
return this.currentEnvironment().getStorageService()
|
|
85
|
+
}
|
|
86
|
+
public get database(): DatabaseService {
|
|
87
|
+
return this.currentEnvironment().getDatabaseService()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
public get hosting(): HostingService {
|
|
91
|
+
return this.currentEnvironment().getHostingService()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public get access(): AccessService {
|
|
95
|
+
return this.currentEnvironment().getAccessService()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public get cloudApp(): CloudBaseRunService {
|
|
99
|
+
return this.currentEnvironment().getCloudBaseRunService()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public commonService(service?: string, version?: string): CommonService {
|
|
103
|
+
return this.currentEnvironment().getCommonService(service, version)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public get env(): EnvService {
|
|
107
|
+
return this.currentEnvironment().getEnvService()
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public get third(): ThirdService {
|
|
111
|
+
return this.currentEnvironment().getThirdService()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public get user(): UserService {
|
|
115
|
+
return this.currentEnvironment().getUserService()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public getEnvironmentManager(): EnvironmentManager {
|
|
119
|
+
return this.environmentManager
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
public getManagerConfig(): CloudBaseConfig {
|
|
123
|
+
return this.cloudBaseConfig
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export = CloudBase
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { IResponseInfo } from './base.interface'
|
|
2
|
+
|
|
3
|
+
export interface IGoodItem {
|
|
4
|
+
GoodsCategoryId: number
|
|
5
|
+
RegionId: number
|
|
6
|
+
ZoneId: number
|
|
7
|
+
GoodsNum: number
|
|
8
|
+
ProjectId: number
|
|
9
|
+
PayMode: number
|
|
10
|
+
Platform: number
|
|
11
|
+
GoodsDetail: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface IGenerateDealsRes extends IResponseInfo {
|
|
15
|
+
OrderIds: Array<string>
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IPayDealsRes extends IResponseInfo {
|
|
19
|
+
OrderIds: Array<string>
|
|
20
|
+
ResourceIds: Array<string>
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { IResponseInfo } from './base.interface'
|
|
2
|
+
|
|
3
|
+
interface IRoleInfo {
|
|
4
|
+
RoleId: string // 角色ID
|
|
5
|
+
RoleName: string // 角色名称
|
|
6
|
+
PolicyDocument: string // 角色策略文档
|
|
7
|
+
Description: string // 角色描述
|
|
8
|
+
AddTime: string // 角色创建时间
|
|
9
|
+
UpdateTime: string // 角色的最近一次时间
|
|
10
|
+
ConsoleLogin: number // 角色是否允许登录
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IRoleListRes extends IResponseInfo {
|
|
14
|
+
List: Array<IRoleInfo>
|
|
15
|
+
TotalNum: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ICreateRoleRes extends IResponseInfo {
|
|
19
|
+
RoleId: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ICheckTcbServiceRes extends IResponseInfo {
|
|
23
|
+
Initialized: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface IGetRoleRes extends IResponseInfo {
|
|
27
|
+
RoleInfo: IRoleInfo
|
|
28
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export interface IExistsRes {
|
|
2
|
+
RequestId: string
|
|
3
|
+
Msg?: string
|
|
4
|
+
Exists: boolean
|
|
5
|
+
}
|
|
6
|
+
export interface IDatabaseTableReq {
|
|
7
|
+
Tag: string
|
|
8
|
+
TableName: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface IndexInfo {
|
|
12
|
+
// 索引名称
|
|
13
|
+
Name: string
|
|
14
|
+
// 索引大小,单位: 字节
|
|
15
|
+
Size: number
|
|
16
|
+
// 索引键值
|
|
17
|
+
Keys: Indexkey[]
|
|
18
|
+
// 索引使用信息
|
|
19
|
+
Accesses: IndexAccesses
|
|
20
|
+
// 是否为唯一索引
|
|
21
|
+
Unique: boolean
|
|
22
|
+
}
|
|
23
|
+
export interface IndexAccesses {
|
|
24
|
+
// 索引命中次数
|
|
25
|
+
Ops: number
|
|
26
|
+
// 命中次数从何时开始计数
|
|
27
|
+
Since: string
|
|
28
|
+
}
|
|
29
|
+
export interface Indexkey {
|
|
30
|
+
// 键名
|
|
31
|
+
Name?: string
|
|
32
|
+
// 方向:specify 1 for ascending or -1 for descending
|
|
33
|
+
Direction?: string
|
|
34
|
+
}
|
|
35
|
+
export interface DropIndex {
|
|
36
|
+
// 索引名称
|
|
37
|
+
IndexName: string
|
|
38
|
+
}
|
|
39
|
+
export interface CreateIndex {
|
|
40
|
+
// 索引名称
|
|
41
|
+
IndexName: string
|
|
42
|
+
// 索引结构
|
|
43
|
+
MgoKeySchema: MgoKeySchema
|
|
44
|
+
}
|
|
45
|
+
export interface MgoKeySchema {
|
|
46
|
+
// 索引字段
|
|
47
|
+
MgoIndexKeys: MgoIndexKeys[]
|
|
48
|
+
// 是否为唯一索引
|
|
49
|
+
MgoIsUnique: boolean
|
|
50
|
+
}
|
|
51
|
+
export interface Pager {
|
|
52
|
+
// 分页偏移量
|
|
53
|
+
Offset: number
|
|
54
|
+
// 每页返回记录数
|
|
55
|
+
Limit: number
|
|
56
|
+
// 文档集合总数
|
|
57
|
+
Total: number
|
|
58
|
+
}
|
|
59
|
+
export interface MgoIndexKeys {
|
|
60
|
+
// 索引字段名
|
|
61
|
+
Name: string
|
|
62
|
+
// 索引类型,当前支持1,-1,2d
|
|
63
|
+
Direction: string
|
|
64
|
+
}
|
|
65
|
+
export interface TableInfo {
|
|
66
|
+
// 表名
|
|
67
|
+
TableName: string
|
|
68
|
+
CollectionName: string
|
|
69
|
+
// 表中文档数量
|
|
70
|
+
Count: number
|
|
71
|
+
// 表的大小(即表中文档总大小),单位:字节
|
|
72
|
+
Size: number
|
|
73
|
+
// 索引数量
|
|
74
|
+
IndexCount: number
|
|
75
|
+
// 索引占用空间,单位:字节
|
|
76
|
+
IndexSize: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface GoodsDetail {
|
|
80
|
+
// 配额id
|
|
81
|
+
QuataId: string
|
|
82
|
+
// 存储GB
|
|
83
|
+
DiskSize?: number
|
|
84
|
+
// 同时连接数
|
|
85
|
+
ConnNum?: number
|
|
86
|
+
// 读操作数
|
|
87
|
+
ReadOperands?: number
|
|
88
|
+
// 写操作数
|
|
89
|
+
WriteOperands?: number
|
|
90
|
+
// 集合限制
|
|
91
|
+
CollectionLimits?: number
|
|
92
|
+
// 单集合索引限制
|
|
93
|
+
SingleCollectionIndexLimits?: number
|
|
94
|
+
}
|
|
95
|
+
export interface ResourceAmount {
|
|
96
|
+
// 已用磁盘容量,单位为MB
|
|
97
|
+
UsedDiskSize?: number
|
|
98
|
+
// 当天已消耗读请求个数
|
|
99
|
+
ReadOperands?: number
|
|
100
|
+
// 当天已消耗写请求个数
|
|
101
|
+
WriteOperands?: number
|
|
102
|
+
// 已创建表个数
|
|
103
|
+
TableNum?: number
|
|
104
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export interface IFunctionVPC {
|
|
2
|
+
subnetId: string
|
|
3
|
+
vpcId: string
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface ICloudFunctionTrigger {
|
|
7
|
+
name: string
|
|
8
|
+
type: string
|
|
9
|
+
config: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 支持的函数配置
|
|
13
|
+
export interface ICloudFunctionConfig {
|
|
14
|
+
timeout?: number
|
|
15
|
+
envVariables?: Record<string, string | number | boolean>
|
|
16
|
+
runtime?: string
|
|
17
|
+
vpc?: IFunctionVPC
|
|
18
|
+
installDependency?: boolean
|
|
19
|
+
l5?: boolean
|
|
20
|
+
memorySize?: number
|
|
21
|
+
// 函数绑定的角色
|
|
22
|
+
role?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LayerVersionSimple {
|
|
26
|
+
LayerName: string // layer名称
|
|
27
|
+
LayerVersion: number // 版本号
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ICloudFunction extends ICloudFunctionConfig {
|
|
31
|
+
name: string
|
|
32
|
+
handler?: string
|
|
33
|
+
codeSecret?: string
|
|
34
|
+
isWaitInstall?: boolean
|
|
35
|
+
ignore?: string | string[]
|
|
36
|
+
layers?: {
|
|
37
|
+
name: string
|
|
38
|
+
version: number
|
|
39
|
+
}[]
|
|
40
|
+
triggers?: ICloudFunctionTrigger[]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface IFunctionLogOptions {
|
|
44
|
+
name: string
|
|
45
|
+
offset?: number
|
|
46
|
+
limit?: number
|
|
47
|
+
order?: string
|
|
48
|
+
orderBy?: string
|
|
49
|
+
startTime?: string
|
|
50
|
+
endTime?: string
|
|
51
|
+
requestId?: string
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IFunctionInvokeRes {
|
|
55
|
+
RequestId: string // 请求 Id
|
|
56
|
+
Log: string // 表示执行过程中的日志输出
|
|
57
|
+
RetMsg: string // 表示执行函数的返回
|
|
58
|
+
ErrMsg: string // 表示执行函数的错误返回信息
|
|
59
|
+
MemUsage: number // 执行函数时的内存大小,单位为Byte
|
|
60
|
+
Duration: number // 表示执行函数的耗时,单位是毫秒
|
|
61
|
+
BillDuration: number // 表示函数的计费耗时,单位是毫秒
|
|
62
|
+
FunctionRequestId: string // 此次函数执行的Id
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface IFunctionLogRes {
|
|
66
|
+
RequestId: string // 请求 Id
|
|
67
|
+
Data: []
|
|
68
|
+
TotalCount: number
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface IFunctionDownloadUrlRes {
|
|
72
|
+
Url: string
|
|
73
|
+
RequestId: string
|
|
74
|
+
CodeSha256: string
|
|
75
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface IUploadMetadata {
|
|
2
|
+
token: string
|
|
3
|
+
url: string
|
|
4
|
+
authorization: string
|
|
5
|
+
fileId: string
|
|
6
|
+
cosFileId: string
|
|
7
|
+
download_url: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IListFileInfo {
|
|
11
|
+
Key: string // 对象键
|
|
12
|
+
LastModified: string // 对象最后修改时间,为 ISO8601 格式,如2019-05-24T10:56:40Z date
|
|
13
|
+
ETag: string // 对象的实体标签(Entity Tag),是对象被创建时标识对象内容的信息标签,可用于检查对象的内容是否发生变化
|
|
14
|
+
Size: string // 对象大小,单位为 Byte
|
|
15
|
+
Owner: string // 对象持有者信息
|
|
16
|
+
StorageClass: string // 对象存储类型,标准存储 STANDARD
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface IFileInfo {
|
|
20
|
+
Size: string // 文件大小 KB
|
|
21
|
+
Type: string // 文件类型
|
|
22
|
+
Date: string // 修改时间
|
|
23
|
+
ETag: string // 对象的实体标签(Entity Tag)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ITempUrlInfo {
|
|
27
|
+
cloudPath: string
|
|
28
|
+
maxAge?: number // 单位:秒
|
|
29
|
+
}
|