@cloudbase/manager-node 4.0.1 → 4.1.1

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 (49) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/lib/constant.js +3 -1
  3. package/lib/env/index.js +2 -207
  4. package/lib/storage/index.js +3 -1
  5. package/lib/utils/cloud-api-request.js +2 -3
  6. package/package.json +3 -2
  7. package/types/constant.d.ts +5 -0
  8. package/types/env/index.d.ts +0 -17
  9. package/src/access/index.ts +0 -168
  10. package/src/access/types.ts +0 -55
  11. package/src/billing/index.ts +0 -43
  12. package/src/cam/index.ts +0 -106
  13. package/src/cloudBaseRun/index.ts +0 -40
  14. package/src/cloudBaseRun/types.ts +0 -24
  15. package/src/common/index.ts +0 -54
  16. package/src/constant.ts +0 -56
  17. package/src/context.ts +0 -18
  18. package/src/database/index.ts +0 -369
  19. package/src/debug.ts +0 -34
  20. package/src/env/index.ts +0 -614
  21. package/src/environment.ts +0 -156
  22. package/src/environmentManager.ts +0 -50
  23. package/src/error.ts +0 -27
  24. package/src/function/index.ts +0 -1338
  25. package/src/function/packer.ts +0 -164
  26. package/src/function/types.ts +0 -164
  27. package/src/hosting/index.ts +0 -698
  28. package/src/index.ts +0 -127
  29. package/src/interfaces/base.interface.ts +0 -8
  30. package/src/interfaces/billing.interface.ts +0 -21
  31. package/src/interfaces/cam.interface.ts +0 -28
  32. package/src/interfaces/flexdb.interface.ts +0 -104
  33. package/src/interfaces/function.interface.ts +0 -75
  34. package/src/interfaces/index.ts +0 -7
  35. package/src/interfaces/storage.interface.ts +0 -29
  36. package/src/interfaces/tcb.interface.ts +0 -636
  37. package/src/storage/index.ts +0 -1281
  38. package/src/third/index.ts +0 -24
  39. package/src/user/index.ts +0 -174
  40. package/src/user/types.ts +0 -21
  41. package/src/utils/auth.ts +0 -112
  42. package/src/utils/cloud-api-request.ts +0 -264
  43. package/src/utils/cloudbase-request.ts +0 -109
  44. package/src/utils/envLazy.ts +0 -15
  45. package/src/utils/fs.ts +0 -57
  46. package/src/utils/http-request.ts +0 -37
  47. package/src/utils/index.ts +0 -103
  48. package/src/utils/parallel.ts +0 -82
  49. package/src/utils/uuid.ts +0 -14
@@ -0,0 +1,3 @@
1
+ {
2
+ "typescript.tsdk": "node_modules\\typescript\\lib"
3
+ }
package/lib/constant.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // static credentail = 'credential'
5
5
  // }
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
7
+ exports.USE_INTERNAL_ENDPOINT = exports.SCF_STATUS = exports.ROLE_NAME = exports.PUBLIC_RSA_KEY = exports.ERROR = exports.SERVICE_TYPE = exports.ENDPOINT = exports.RUN_ENV = exports.SDK_VERSION = exports.ENV_NAME = void 0;
8
8
  exports.ENV_NAME = {
9
9
  ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
10
10
  ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
@@ -49,3 +49,5 @@ exports.SCF_STATUS = {
49
49
  UPDATING: 'Updating',
50
50
  CREATE_FAILED: 'CreateFailed'
51
51
  };
52
+ // 是否使用内网域名
53
+ exports.USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT" in process.env;
package/lib/env/index.js CHANGED
@@ -14,17 +14,13 @@ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
14
14
  const util_1 = __importDefault(require("util"));
15
15
  const error_1 = require("../error");
16
16
  const utils_1 = require("../utils");
17
- const cam_1 = require("../cam");
18
17
  const constant_1 = require("../constant");
19
- const billing_1 = require("../billing");
20
18
  class EnvService {
21
19
  constructor(environment) {
22
20
  this.environment = environment;
23
21
  this.envId = environment.getEnvId();
24
22
  this.envType = environment.getEnvType();
25
23
  this.cloudService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
26
- this.camService = new cam_1.CamService(environment.cloudBaseContext);
27
- this.billService = new billing_1.BillingService(environment.cloudBaseContext);
28
24
  }
29
25
  /**
30
26
  * 列出所有环境
@@ -33,208 +29,6 @@ class EnvService {
33
29
  async listEnvs() {
34
30
  return this.cloudService.request('DescribeEnvs');
35
31
  }
36
- /**
37
- * 创建新环境
38
- * @param {string} name 环境名称
39
- * @returns {Promise<ICreateEnvRes>}
40
- */
41
- async createEnv(param) {
42
- // 1. 检查是否开通过TCB服务,若未开通,跳2检查角色 开通则跳5 创建环境
43
- // 2. 查询tcb 角色是否绑定该账户
44
- // 3. 若未绑定,则创建角色并绑定角色
45
- // 4. 开通TCB服务
46
- // 5. 创建环境
47
- // 6. 购买环境,选择预付费 或 后付费 套餐
48
- // 7. 若购买失败,将当前环境销毁,若购买成功,返回envId
49
- const { name, paymentMode, channel = 'qc_console' } = param;
50
- // 1. 检查TCB服务是否开通
51
- const { Initialized } = await this.checkTcbService();
52
- if (!Initialized) {
53
- // 跳2 查询TCB角色是否绑定
54
- let hasTcbRole = false;
55
- try {
56
- const res = await this.camService.getRole(constant_1.ROLE_NAME.TCB);
57
- hasTcbRole = true;
58
- }
59
- catch (e) {
60
- // 判断是否为角色不存在错误
61
- if (e.code !== 'InvalidParameter.RoleNotExist') {
62
- throw e;
63
- }
64
- }
65
- if (!hasTcbRole) {
66
- // 3. 当前账户没有tcbRole,创建角色并绑定
67
- // 创建角色
68
- const createRoleResult = await this.camService.createRole({
69
- RoleName: constant_1.ROLE_NAME.TCB,
70
- Description: '云开发(TCB)操作权限含在访问管理(CAM)创建角色,新增角色载体,给角色绑定策略;含读写对象存储(COS)数据;含读写无服务器云函数(SCF)数据;含读取云监控(Monitor)数据。',
71
- PolicyDocument: '{"version":"2.0","statement":[{"action":"sts:AssumeRole","effect":"allow","principal":{"service":["scf.qcloud.com","tcb.cloud.tencent.com", "cvm.qcloud.com"]}}]}'
72
- });
73
- const { RoleId } = createRoleResult;
74
- // 绑定角色策略
75
- // await this.camService.attachRolePolicy({
76
- // PolicyId: 8825032,
77
- // AttachRoleName: ROLE_NAME.TCB
78
- // })
79
- await this.camService.attachRolePolicies({
80
- RoleName: constant_1.ROLE_NAME.TCB,
81
- PolicyName: [
82
- 'QcloudAccessForTCBRole',
83
- 'QcloudAccessForTCBRoleInAccessCloudBaseRun'
84
- ]
85
- });
86
- }
87
- // 4. 未开通则初始化TCB
88
- await this.initTcb({ Channel: channel, Source: 'qcloud' });
89
- }
90
- // 5. 创建环境
91
- const params = {
92
- Alias: name,
93
- EnvId: `${name}-${utils_1.guid6()}`,
94
- Source: 'qcloud'
95
- };
96
- if (channel) {
97
- params.Channel = channel;
98
- }
99
- const { EnvId } = await this.cloudService.request('CreateEnv', params);
100
- const realPaymentMode = paymentMode ? paymentMode : 'postpay';
101
- // 6. 购买环境
102
- let prepayCreateDeal = false;
103
- let prepayPayDeal = false;
104
- let postpayDeal = false;
105
- let payError = null;
106
- if (realPaymentMode === 'prepay') {
107
- // 预付费
108
- // 1. 创建订单
109
- // 2. 支付订单
110
- const goods = [
111
- {
112
- GoodsCategoryId: 101183,
113
- // action: 'purchase',
114
- // currency: 'CNY',
115
- RegionId: 1,
116
- ZoneId: 0,
117
- GoodsNum: 1,
118
- ProjectId: 0,
119
- PayMode: 1,
120
- Platform: 1,
121
- GoodsDetail: JSON.stringify({
122
- productCode: 'p_tcb',
123
- subProductCode: 'sp_tcb_basic',
124
- resourceId: EnvId,
125
- pid: 16677,
126
- timeUnit: 'm',
127
- timeSpan: 1,
128
- tcb_cos: 1,
129
- tcb_cdn: 1,
130
- tcb_scf: 1,
131
- tcb_mongodb: 1,
132
- region: 'ap-shanghai',
133
- zone: 'ap-shanghai-1',
134
- source: 'qcloud',
135
- envId: EnvId,
136
- packageId: 'basic',
137
- isAutoRenew: 'true',
138
- tranType: 1,
139
- productInfo: [
140
- {
141
- name: '套餐版本',
142
- value: '基础版 1'
143
- },
144
- {
145
- name: '存储空间',
146
- value: '5GB'
147
- },
148
- {
149
- name: 'CDN流量',
150
- value: '5GB'
151
- },
152
- {
153
- name: '云函数资源使用量',
154
- value: '4万GBs'
155
- },
156
- {
157
- name: '数据库容量',
158
- value: '2GB'
159
- },
160
- {
161
- name: '数据库同时连接数',
162
- value: '20个'
163
- }
164
- ]
165
- })
166
- }
167
- ];
168
- let OrderIdsList = [];
169
- try {
170
- const { OrderIds } = await this.billService.GenerateDeals(goods);
171
- OrderIdsList = OrderIds;
172
- prepayCreateDeal = true;
173
- }
174
- catch (e) {
175
- // 预付费下单失败
176
- payError = e;
177
- }
178
- if (prepayCreateDeal) {
179
- // 下单成功
180
- try {
181
- // 购买环境套餐
182
- const { OrderIds: succOrderIds } = await this.billService.PayDeals(OrderIdsList);
183
- // 判断订单是否支付成功
184
- if (succOrderIds[0] === OrderIdsList[0]) {
185
- prepayPayDeal = true;
186
- }
187
- else {
188
- throw new error_1.CloudBaseError('支付成功的订单号不一致');
189
- }
190
- }
191
- catch (e) {
192
- // 预付费订单支付失败
193
- payError = new error_1.CloudBaseError('预付费订单支付失败,请进入订单管理页面(https://console.cloud.tencent.com/deal)重新支付', {
194
- original: e
195
- });
196
- }
197
- }
198
- }
199
- if (realPaymentMode === 'postpay') {
200
- // 后付费
201
- try {
202
- const { TranId } = await this.CreatePostpayPackage(EnvId);
203
- postpayDeal = true;
204
- }
205
- catch (e) {
206
- payError = e;
207
- }
208
- }
209
- // 检查支付状态
210
- // 1. 预付费下单失败 删除环境
211
- // 2. 预付费下单成功过,支付订单失败,提示用户
212
- // 3. 后付费开通失败 删除环境
213
- if (realPaymentMode === 'prepay') {
214
- if (!prepayCreateDeal) {
215
- // 情形1
216
- await this.destroyEnv(EnvId);
217
- throw payError;
218
- }
219
- else {
220
- if (!prepayPayDeal) {
221
- // 情形2
222
- throw payError;
223
- }
224
- }
225
- }
226
- if (realPaymentMode === 'postpay') {
227
- if (!postpayDeal) {
228
- // 情形3
229
- await this.destroyEnv(EnvId);
230
- throw payError;
231
- }
232
- }
233
- // 成功返回envId
234
- return {
235
- envId: EnvId
236
- };
237
- }
238
32
  /**
239
33
  * 拉取安全域名列表
240
34
  * @returns {Promise<IAuthDomainsRes>}
@@ -464,7 +258,8 @@ class EnvService {
464
258
  return new cos_nodejs_sdk_v5_1.default({
465
259
  SecretId: secretId,
466
260
  SecretKey: secretKey,
467
- SecurityToken: token
261
+ SecurityToken: token,
262
+ Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* PUBLIC */
468
263
  });
469
264
  }
470
265
  getStorageConfig() {
@@ -20,6 +20,7 @@ const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
20
20
  const utils_1 = require("../utils");
21
21
  const error_1 = require("../error");
22
22
  const parallel_1 = require("../utils/parallel");
23
+ const constant_1 = require("../constant");
23
24
  const BIG_FILE_SIZE = 5242880; // 5MB 1024*1024*5
24
25
  class StorageService {
25
26
  constructor(environment) {
@@ -844,7 +845,8 @@ class StorageService {
844
845
  SecretId: secretId,
845
846
  SecretKey: secretKey,
846
847
  Proxy: cosProxy || proxy,
847
- SecurityToken: token
848
+ SecurityToken: token,
849
+ Domain: constant_1.USE_INTERNAL_ENDPOINT ? "{Bucket}.cos-internal.{Region}.tencentcos.cn" /* INTERNAL */ : "{Bucket}.cos.{Region}.tencentcos.cn" /* PUBLIC */
848
850
  });
849
851
  }
850
852
  /**
@@ -70,12 +70,11 @@ class CloudService {
70
70
  cam: 'https://cam.tencentcloudapi.com',
71
71
  cdn: 'https://cdn.tencentcloudapi.com'
72
72
  };
73
- // 检测环境变量,云梯账号走内网域名
74
- const USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT";
73
+ // 云梯账号走内网域名
75
74
  const intranetUrlMap = Object.keys(urlMap).map((service) => ({
76
75
  [service]: `https://${service}.internal.tencentcloudapi.com`,
77
76
  })).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
78
- if (USE_INTERNAL_ENDPOINT in process.env) {
77
+ if (constant_1.USE_INTERNAL_ENDPOINT) {
79
78
  return intranetUrlMap[this.service];
80
79
  }
81
80
  if (urlMap[this.service]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "4.0.1",
3
+ "version": "4.1.1",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -8,7 +8,8 @@
8
8
  "test": "jest --runInBand --detectOpenHandles --coverage --testTimeout=50000",
9
9
  "lint": "eslint \"./**/*.ts\"",
10
10
  "lint:fix": "eslint --fix \"./**/*.ts\"",
11
- "prepublishOnly": "npm run build"
11
+ "prepublishOnly": "npm run build",
12
+ "watch": "rimraf lib types && tsc -w"
12
13
  },
13
14
  "repository": {
14
15
  "type": "git",
@@ -35,3 +35,8 @@ export declare const SCF_STATUS: {
35
35
  UPDATING: string;
36
36
  CREATE_FAILED: string;
37
37
  };
38
+ export declare const USE_INTERNAL_ENDPOINT: boolean;
39
+ export declare const enum COS_ENDPOINT {
40
+ INTERNAL = "{Bucket}.cos-internal.{Region}.tencentcos.cn",
41
+ PUBLIC = "{Bucket}.cos.{Region}.tencentcos.cn"
42
+ }
@@ -1,13 +1,6 @@
1
1
  import { Environment } from '../environment';
2
2
  import { IResponseInfo, AuthDomain, EnvInfo, LoginConfigItem, ICheckTcbServiceRes, ICreatePostpayRes } from '../interfaces';
3
- interface ICreateEnvParam {
4
- name: string;
5
- paymentMode?: PAYMENT_MODE;
6
- channel?: QCLOUD_CHANNEL;
7
- }
8
- declare type PAYMENT_MODE = 'prepay' | 'postpay';
9
3
  declare type SOURCE = 'miniapp' | 'qcloud';
10
- declare type QCLOUD_CHANNEL = 'cocos' | 'qq' | 'cloudgame' | 'qc_console' | 'dcloud';
11
4
  interface IDeleteDomainRes {
12
5
  RequestId: string;
13
6
  Deleted: number;
@@ -32,8 +25,6 @@ export declare class EnvService {
32
25
  private environment;
33
26
  private envId;
34
27
  private cloudService;
35
- private camService;
36
- private billService;
37
28
  private envType?;
38
29
  constructor(environment: Environment);
39
30
  /**
@@ -41,14 +32,6 @@ export declare class EnvService {
41
32
  * @returns {Promise<IListEnvRes>}
42
33
  */
43
34
  listEnvs(): Promise<IListEnvRes>;
44
- /**
45
- * 创建新环境
46
- * @param {string} name 环境名称
47
- * @returns {Promise<ICreateEnvRes>}
48
- */
49
- createEnv(param: ICreateEnvParam): Promise<{
50
- envId: string;
51
- }>;
52
35
  /**
53
36
  * 拉取安全域名列表
54
37
  * @returns {Promise<IAuthDomainsRes>}
@@ -1,168 +0,0 @@
1
- import { Environment } from '../environment'
2
- import { CloudService, preLazy } from '../utils'
3
- import {
4
- ICreateAccessOptions,
5
- IApi,
6
- IUpdateOptions,
7
- IService,
8
- IDeleteOptions,
9
- IGetOptions,
10
- IDomainOptions
11
- } from './types'
12
- import { IResponseInfo } from '../interfaces'
13
-
14
- export class AccessService {
15
- private tcbService: CloudService
16
- private environment: Environment
17
-
18
- constructor(environment: Environment) {
19
- this.environment = environment
20
- this.tcbService = new CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08')
21
- }
22
-
23
- // 创建云接入路径
24
- @preLazy()
25
- public async createAccess(options: ICreateAccessOptions) {
26
- const { path, name, type = 1, auth } = options
27
- const { envId } = this.getEnvInfo()
28
-
29
- return this.tcbService.request<{
30
- APIId: string
31
- RequestId: string
32
- }>('CreateCloudBaseGWAPI', {
33
- ServiceId: envId,
34
- Path: path,
35
- Type: type,
36
- Name: name,
37
- AuthSwitch: auth ? 1 : 2
38
- })
39
- }
40
-
41
- // 获取云接入自定义域名列表
42
- @preLazy()
43
- public async getDomainList() {
44
- const { envId } = this.getEnvInfo()
45
- return this.tcbService.request<{
46
- RequestId: string
47
- // 云接入默认域名
48
- DefaultDomain: string
49
- // 是否开启了云接入服务
50
- EnableService: boolean
51
- // 云接入服务列表
52
- ServiceSet: IService[]
53
- }>('DescribeCloudBaseGWService', {
54
- ServiceId: envId
55
- })
56
- }
57
-
58
- // 获取云接入服务列表
59
- @preLazy()
60
- public async getAccessList(options: IGetOptions = {}) {
61
- const { path, name, offset, limit } = options
62
- const { envId } = this.getEnvInfo()
63
-
64
- return this.tcbService.request<{
65
- RequestId: string
66
- APISet: IApi[]
67
- Total: number
68
- Limit: number
69
- Offset: number
70
- EnableService: boolean
71
- }>('DescribeCloudBaseGWAPI', {
72
- ServiceId: envId,
73
- Path: path,
74
- Name: name,
75
- Offset: offset,
76
- limit: limit
77
- })
78
- }
79
-
80
- // 切换云接入服务开关:开启/关闭
81
- @preLazy()
82
- public async switchAuth(auth: boolean) {
83
- const { envId } = this.getEnvInfo()
84
- return this.tcbService.request<{
85
- Count: number
86
- RequestId: string
87
- }>('ModifyCloudBaseGWPrivilege', {
88
- ServiceId: envId,
89
- EnableService: auth,
90
- Options: [
91
- {
92
- Key: 'serviceswitch',
93
- Value: auth ? 'true' : 'false'
94
- }
95
- ]
96
- })
97
- }
98
-
99
- // 更新云接入路径鉴权
100
- @preLazy()
101
- public async switchPathAuth(options: IUpdateOptions) {
102
- const { apiIds, auth } = options
103
- const { envId } = this.getEnvInfo()
104
- return this.tcbService.request<{
105
- Count: number
106
- RequestId: string
107
- }>('ModifyCloudBaseGWAPIPrivilegeBatch', {
108
- ServiceId: envId,
109
- APIIdSet: apiIds,
110
- Options: [
111
- {
112
- Key: 'authswitch',
113
- Value: auth ? 'true' : 'false'
114
- }
115
- ]
116
- })
117
- }
118
-
119
- // 删除云接入服务
120
- @preLazy()
121
- public async deleteAccess(options: IDeleteOptions) {
122
- const { name, type = 1, apiId } = options
123
- const { envId } = this.getEnvInfo()
124
-
125
- return this.tcbService.request<IResponseInfo>('DeleteCloudBaseGWAPI', {
126
- ServiceId: envId,
127
- Name: name,
128
- Type: type,
129
- APIId: apiId
130
- })
131
- }
132
-
133
- // 添加自定义域名
134
- @preLazy()
135
- public async addCustomDomain(options: IDomainOptions) {
136
- const { domain, certId } = options
137
- const { envId } = this.getEnvInfo()
138
-
139
- return this.tcbService.request<IResponseInfo>('BindCloudBaseGWDomain', {
140
- Domain: domain,
141
- ServiceId: envId,
142
- CertId: certId
143
- })
144
- }
145
-
146
- // 删除自定义域名
147
- @preLazy()
148
- public async deleteCustomDomain(domain: string) {
149
- const { envId } = this.getEnvInfo()
150
-
151
- return this.tcbService.request<IResponseInfo>('DeleteCloudBaseGWDomain', {
152
- Domain: domain,
153
- ServiceId: envId
154
- })
155
- }
156
-
157
- private getEnvInfo() {
158
- const envConfig = this.environment.lazyEnvironmentConfig
159
- const appId = envConfig.Storages[0]?.AppId
160
- const { proxy } = this.environment.cloudBaseContext
161
-
162
- return {
163
- appId,
164
- proxy,
165
- envId: envConfig.EnvId
166
- }
167
- }
168
- }
@@ -1,55 +0,0 @@
1
- export interface ICreateAccessOptions {
2
- path: string
3
- // 云函数名或云应用名称
4
- name: string
5
- // 1 表示云函数,2 表示云应用
6
- type?: 1 | 2
7
- // 鉴权开关
8
- auth?: boolean
9
- }
10
-
11
- export interface IApi {
12
- ServiceId: string
13
- APIId: string
14
- Path: string
15
- Type: number
16
- Name: string
17
- CreateTime: number
18
- EnvId: string
19
- EnableAuth: boolean
20
- }
21
-
22
- export interface IUpdateOptions {
23
- // APIId
24
- apiIds: string[]
25
- // true 为开启,false 为关闭
26
- auth: boolean
27
- }
28
-
29
- export interface IService {
30
- ServiceId: string
31
- Domain: string
32
- OpenTime: number
33
- Status?: number
34
- }
35
-
36
- export interface IDeleteOptions {
37
- name?: string
38
- type?: number
39
- apiId?: string
40
- path?: string
41
- }
42
-
43
- export interface IGetOptions {
44
- path?: string
45
- name?: string
46
- limit?: number
47
- offset?: number
48
- }
49
-
50
- export interface IDomainOptions {
51
- // 域名
52
- domain: string
53
- // 腾讯云 SSL 证书 Id
54
- certId?: string
55
- }
@@ -1,43 +0,0 @@
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
- }