@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.
Files changed (56) hide show
  1. package/CHANGELOG.md +0 -4
  2. package/lib/constant.js +1 -5
  3. package/lib/env/index.js +209 -10
  4. package/lib/function/index.js +21 -3
  5. package/lib/storage/index.js +3 -19
  6. package/lib/utils/cloud-api-request.js +0 -7
  7. package/lib/utils/http-request.js +3 -3
  8. package/package.json +3 -4
  9. package/src/access/index.ts +168 -0
  10. package/src/access/types.ts +55 -0
  11. package/src/billing/index.ts +43 -0
  12. package/src/cam/index.ts +106 -0
  13. package/src/cloudBaseRun/index.ts +40 -0
  14. package/src/cloudBaseRun/types.ts +24 -0
  15. package/src/common/index.ts +54 -0
  16. package/src/constant.ts +56 -0
  17. package/src/context.ts +18 -0
  18. package/src/database/index.ts +369 -0
  19. package/src/debug.ts +34 -0
  20. package/src/env/index.ts +614 -0
  21. package/src/environment.ts +156 -0
  22. package/src/environmentManager.ts +50 -0
  23. package/src/error.ts +27 -0
  24. package/src/function/index.ts +1378 -0
  25. package/src/function/packer.ts +164 -0
  26. package/src/function/types.ts +165 -0
  27. package/src/hosting/index.ts +698 -0
  28. package/src/index.ts +127 -0
  29. package/src/interfaces/base.interface.ts +8 -0
  30. package/src/interfaces/billing.interface.ts +21 -0
  31. package/src/interfaces/cam.interface.ts +28 -0
  32. package/src/interfaces/flexdb.interface.ts +104 -0
  33. package/src/interfaces/function.interface.ts +75 -0
  34. package/src/interfaces/index.ts +7 -0
  35. package/src/interfaces/storage.interface.ts +29 -0
  36. package/src/interfaces/tcb.interface.ts +642 -0
  37. package/src/storage/index.ts +1281 -0
  38. package/src/third/index.ts +24 -0
  39. package/src/user/index.ts +174 -0
  40. package/src/user/types.ts +21 -0
  41. package/src/utils/auth.ts +112 -0
  42. package/src/utils/cloud-api-request.ts +252 -0
  43. package/src/utils/cloudbase-request.ts +109 -0
  44. package/src/utils/envLazy.ts +15 -0
  45. package/src/utils/fs.ts +57 -0
  46. package/src/utils/http-request.ts +37 -0
  47. package/src/utils/index.ts +103 -0
  48. package/src/utils/parallel.ts +82 -0
  49. package/src/utils/uuid.ts +14 -0
  50. package/types/constant.d.ts +0 -7
  51. package/types/env/index.d.ts +17 -0
  52. package/types/function/index.d.ts +6 -1
  53. package/types/function/types.d.ts +2 -0
  54. package/types/interfaces/tcb.interface.d.ts +6 -0
  55. package/lib/utils/runenv.js +0 -8
  56. package/types/utils/runenv.d.ts +0 -1
@@ -0,0 +1,43 @@
1
+ import { CloudService } from '../utils'
2
+ import { CloudBaseContext } from '../context'
3
+ import { IServiceVersion, IGoodItem, IGenerateDealsRes, IPayDealsRes } from '../interfaces'
4
+
5
+ export class BillingService {
6
+ static billServiceVersion: IServiceVersion = {
7
+ service: 'billing',
8
+ version: '2018-07-09'
9
+ }
10
+ private billService: CloudService
11
+
12
+ constructor(context: CloudBaseContext) {
13
+ this.billService = new CloudService(
14
+ context,
15
+ BillingService.billServiceVersion.service,
16
+ BillingService.billServiceVersion.version
17
+ )
18
+ }
19
+
20
+ /**
21
+ * 创建订单
22
+ * @param {Array<IGoodItem>} goods
23
+ * @returns {Promise<IGenerateDealsRes>}
24
+ * @memberof BillingService
25
+ */
26
+ public async GenerateDeals(goods: Array<IGoodItem>): Promise<IGenerateDealsRes> {
27
+ return this.billService.request<IGenerateDealsRes>('GenerateDeals', {
28
+ Goods: goods
29
+ })
30
+ }
31
+
32
+ /**
33
+ * 支付订单
34
+ * @param {Array<string>} orderIds
35
+ * @returns {Promise<IPayDealsRes>}
36
+ * @memberof BillingService
37
+ */
38
+ public async PayDeals(orderIds: Array<string>): Promise<IPayDealsRes> {
39
+ return this.billService.request<IPayDealsRes>('PayDeals', {
40
+ OrderIds: orderIds
41
+ })
42
+ }
43
+ }
@@ -0,0 +1,106 @@
1
+ import { CloudService } from '../utils'
2
+ import { CloudBaseContext } from '../context'
3
+ import {
4
+ IServiceVersion,
5
+ IRoleListRes,
6
+ ICreateRoleRes,
7
+ IResponseInfo,
8
+ IGetRoleRes
9
+ } from '../interfaces'
10
+
11
+ export class CamService {
12
+ static camServiceVersion: IServiceVersion = {
13
+ service: 'cam',
14
+ version: '2019-01-16'
15
+ }
16
+ private camService: CloudService
17
+
18
+ constructor(context: CloudBaseContext) {
19
+ this.camService = new CloudService(
20
+ context,
21
+ CamService.camServiceVersion.service,
22
+ CamService.camServiceVersion.version
23
+ )
24
+ }
25
+
26
+ /**
27
+ * 查询账户角色列表
28
+ * @param {number} page
29
+ * @param {number} rp
30
+ * @returns {Promise<IRoleListRes>}
31
+ * @memberof CamService
32
+ */
33
+ public async describeRoleList(page: number, rp: number): Promise<IRoleListRes> {
34
+ return this.camService.request<IRoleListRes>('DescribeRoleList', {
35
+ Page: page,
36
+ Rp: rp
37
+ })
38
+ }
39
+
40
+ /**
41
+ * 获取角色详情
42
+ * @param {string} roleName
43
+ * @returns {Promise<IGetRoleRes>}
44
+ * @memberof CamService
45
+ */
46
+ public async getRole(roleName: string): Promise<IGetRoleRes> {
47
+ return this.camService.request<IGetRoleRes>('GetRole', {
48
+ RoleName: roleName
49
+ })
50
+ }
51
+
52
+ /**
53
+ * 创建角色
54
+ * @param {{
55
+ * RoleName: string
56
+ * PolicyDocument: string
57
+ * Description: string
58
+ * }} param
59
+ * @returns {Promise<ICreateRoleRes>}
60
+ * @memberof CamService
61
+ */
62
+ public async createRole(param: {
63
+ RoleName: string
64
+ PolicyDocument: string
65
+ Description: string
66
+ }): Promise<ICreateRoleRes> {
67
+ return this.camService.request<ICreateRoleRes>('CreateRole', param)
68
+ }
69
+
70
+ /**
71
+ * 绑定角色策略
72
+ * @param {{
73
+ * PolicyId: number
74
+ * AttachRoleName: string
75
+ * }} param
76
+ * @returns {Promise<IResponseInfo>}
77
+ * @memberof CamService
78
+ */
79
+ public async attachRolePolicy(param: {
80
+ PolicyId: number
81
+ AttachRoleName: string
82
+ }): Promise<IResponseInfo> {
83
+ return this.camService.request<IResponseInfo>('AttachRolePolicy', param)
84
+ }
85
+
86
+ public async attachRolePolicies(param: {
87
+ RoleId?: number
88
+ RoleName?: string
89
+ PolicyId?: number[]
90
+ PolicyName?: string[]
91
+ }): Promise<IResponseInfo> {
92
+ return this.camService.request<IResponseInfo>('AttachRolePolicies', param)
93
+ }
94
+
95
+ /**
96
+ * 删除角色
97
+ * @param {string} roleName
98
+ * @returns {Promise<IResponseInfo>}
99
+ * @memberof CamService
100
+ */
101
+ public async deleteRole(roleName: string): Promise<IResponseInfo> {
102
+ return this.camService.request<IResponseInfo>('DeleteRole', {
103
+ RoleName: roleName
104
+ })
105
+ }
106
+ }
@@ -0,0 +1,40 @@
1
+ import { Environment } from '../environment'
2
+ import { CloudService, preLazy, upperCaseObjKey } from '../utils'
3
+ import { IModifyServerFlowOption } from './types'
4
+ import { IResponseInfo } from '../interfaces'
5
+
6
+ export class CloudBaseRunService {
7
+ private tcbService: CloudService
8
+ private environment: Environment
9
+
10
+ constructor(environment: Environment) {
11
+ this.environment = environment
12
+ this.tcbService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
13
+ }
14
+
15
+ // 修改容器内版本流量配置
16
+ @preLazy()
17
+ public async modifyServerFlow(
18
+ options: IModifyServerFlowOption
19
+ ): Promise<{
20
+ Result: string // succ代表成功
21
+ RequestId: string // 请求ID
22
+ }> {
23
+ const { envId } = this.getEnvInfo()
24
+
25
+ return this.tcbService.request('ModifyCloudBaseRunServerFlowConf', {
26
+ EnvId: envId,
27
+ ServerName: options.serverName,
28
+ VersionFlowItems: upperCaseObjKey(options.versionFlowItems)
29
+ // TrafficType: options.trafficType
30
+ })
31
+ }
32
+
33
+ private getEnvInfo() {
34
+ const envConfig = this.environment.lazyEnvironmentConfig
35
+
36
+ return {
37
+ envId: envConfig.EnvId
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,24 @@
1
+ export interface IModifyServerFlowOption {
2
+ serverName: string
3
+ versionFlowItems?: ICloudBaseRunVersionFlowItem[]
4
+ trafficType?: string
5
+ }
6
+
7
+ export interface ICloudBaseRunVersionFlowItem {
8
+ versionName: string // 版本名称
9
+ flowRatio: number // 流量占比
10
+ urlParam?: IObjectKV // 流量参数
11
+ priority?: number // 优先级(数值越小,优先级越高)
12
+ isDefaultPriority?: boolean // 是否是默认兜底版本
13
+ }
14
+
15
+ export interface IObjectKV {
16
+ key: string
17
+ value: string
18
+ }
19
+
20
+ export interface IClouBaseRunKVPriority {
21
+ key: string
22
+ value: string
23
+ priority: number
24
+ }
@@ -0,0 +1,54 @@
1
+ import { CloudService, preLazy } from '../utils'
2
+ import { CloudBaseContext } from '../context'
3
+ import { CloudBaseError } from '../error'
4
+ import { Environment } from '../environment'
5
+
6
+ interface ICommonApiServiceOption {
7
+ Action: string // 接口名称
8
+ Param: Record<string, any> // 接口传参
9
+ }
10
+ /**
11
+ * 公共的云api调用方法 透传用户参数 无业务逻辑处理
12
+ * @export
13
+ * @class CommonService
14
+ */
15
+
16
+ const ActionVersionMap = {
17
+ tcb: '2018-06-08',
18
+ flexdb: '2018-11-27',
19
+ scf: '2018-04-16',
20
+ sts: '2018-04-16',
21
+ cam: '2018-04-16',
22
+ lowcode: '2021-01-08'
23
+ }
24
+
25
+ export class CommonService {
26
+ private commonService: CloudService
27
+ private environment: Environment
28
+
29
+ constructor(environment: Environment, serviceType: string, serviceVersion: string) {
30
+ this.environment = environment
31
+ this.commonService = new CloudService(
32
+ environment.cloudBaseContext,
33
+ serviceType,
34
+ serviceVersion || ActionVersionMap[serviceType]
35
+ )
36
+ }
37
+
38
+ /**
39
+ * 公共方法调用
40
+ * @param {ICommonApiServiceParam} param
41
+ * @returns {Promise<any>}
42
+ * @memberof CommonService
43
+ */
44
+ public async call(options: ICommonApiServiceOption): Promise<any> {
45
+ const { Action, Param = {} } = options
46
+ if (!Action) {
47
+ throw new CloudBaseError('缺少必填参数 Action')
48
+ }
49
+
50
+ const res = await this.commonService.request(Action, { ...Param })
51
+
52
+ return res
53
+ }
54
+ }
@@ -0,0 +1,56 @@
1
+ // // cloudbase cli 配置的字段名
2
+ // export class ConfigItems {
3
+ // static credentail = 'credential'
4
+ // }
5
+
6
+ export const ENV_NAME = {
7
+ ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
8
+ ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
9
+ ENV_SESSIONTOKEN: 'TENCENTCLOUD_SESSIONTOKEN',
10
+ ENV_TCB_ENV_ID: 'TENCENTCLOUD_TCB_ENVID',
11
+ ENV_RUNENV: 'TENCENTCLOUD_RUNENV',
12
+ ENV_RUNENV_SCF: 'TENCENTCLOUD_RUNENV=SCF'
13
+ }
14
+
15
+ export const SDK_VERSION = 'TCB-NODE-MANAGER/1.0.O'
16
+
17
+ export const RUN_ENV = {
18
+ SCF: 'SCF'
19
+ }
20
+
21
+ export const ENDPOINT = {
22
+ TCB: 'tcb.tencentcloudapi.com',
23
+ SCF: 'scf.tencentcloudapi.com',
24
+ COS: 'cos.tencentcloudapi.com',
25
+ FLEXDB: 'flexdb.tencentcloudapi.com'
26
+ }
27
+
28
+ export const SERVICE_TYPE = {
29
+ TCB: 'tcb'
30
+ }
31
+
32
+ export const ERROR = {
33
+ MISS_SECRET_INFO_IN_ENV: 'MISS_SECRET_INFO_IN_ENV',
34
+ MISS_SECRET_INFO_IN_ARGS: 'MISS_SECRET_INFO_IN_ARGS',
35
+ CURRENT_ENVIRONMENT_IS_NULL: 'CURRENT_ENVIRONMENT_IS_NULL',
36
+ ENV_ID_NOT_EXISTS: 'ENV_ID_NOT_EXISTS'
37
+ }
38
+
39
+ export const PUBLIC_RSA_KEY = `
40
+ -----BEGIN PUBLIC KEY-----
41
+ MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0ZLB0ZpWWFsHPnDDw++Nc2wI3
42
+ nl2uyOrIJ5FUfxt4GAmt1Faf5pgMxAnL9exEUrrUDUX8Ri1R0KyfnHQQwCvKt8T8
43
+ bgILIJe9UB8e9dvFqgqH2oA8Vqwi0YqDcvFLFJk2BJbm/0QYtZ563FumW8LEXAgu
44
+ UeHi/0OZN9vQ33jWMQIDAQAB
45
+ -----END PUBLIC KEY-----
46
+ `
47
+ export const ROLE_NAME = {
48
+ TCB: 'TCB_QcsRole'
49
+ }
50
+
51
+ export const SCF_STATUS = {
52
+ ACTIVE: 'Active',
53
+ CREATING: 'Creating',
54
+ UPDATING: 'Updating',
55
+ CREATE_FAILED: 'CreateFailed'
56
+ }
package/src/context.ts ADDED
@@ -0,0 +1,18 @@
1
+ export class CloudBaseContext {
2
+ public readonly secretId: string
3
+ public readonly secretKey: string
4
+ public readonly token: string
5
+ public readonly proxy: string
6
+ public readonly envId: string
7
+ public readonly region: string
8
+ public readonly envType: string // baas/run/weda/hosting
9
+
10
+ constructor({ secretId = '', secretKey = '', token = '', proxy = '', region = '', envType = '' }) {
11
+ this.secretId = secretId
12
+ this.secretKey = secretKey
13
+ this.token = token
14
+ this.proxy = proxy
15
+ this.region = region
16
+ this.envType = envType
17
+ }
18
+ }