@cloudbase/manager-node 4.2.0 → 4.2.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.
- package/CHANGELOG.md +0 -4
- package/lib/constant.js +1 -5
- package/lib/env/index.js +209 -10
- package/lib/function/index.js +5 -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 +1362 -0
- package/src/function/packer.ts +164 -0
- package/src/function/types.ts +164 -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 +636 -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 +2 -1
- package/lib/utils/runenv.js +0 -8
- package/types/utils/runenv.d.ts +0 -1
package/CHANGELOG.md
CHANGED
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.
|
|
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;
|
|
8
8
|
exports.ENV_NAME = {
|
|
9
9
|
ENV_SECRETID: 'TENCENTCLOUD_SECRETID',
|
|
10
10
|
ENV_SECRETKEY: 'TENCENTCLOUD_SECRETKEY',
|
|
@@ -49,7 +49,3 @@ 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;
|
|
54
|
-
exports.COS_SDK_PROTOCOL = process.env.COS_SDK_PROTOCOL;
|
|
55
|
-
exports.COS_SDK_KEEPALIVE = process.env.COS_SDK_KEEPALIVE;
|
package/lib/env/index.js
CHANGED
|
@@ -14,13 +14,17 @@ 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");
|
|
17
18
|
const constant_1 = require("../constant");
|
|
19
|
+
const billing_1 = require("../billing");
|
|
18
20
|
class EnvService {
|
|
19
21
|
constructor(environment) {
|
|
20
22
|
this.environment = environment;
|
|
21
23
|
this.envId = environment.getEnvId();
|
|
22
24
|
this.envType = environment.getEnvType();
|
|
23
25
|
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);
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
26
30
|
* 列出所有环境
|
|
@@ -29,6 +33,208 @@ class EnvService {
|
|
|
29
33
|
async listEnvs() {
|
|
30
34
|
return this.cloudService.request('DescribeEnvs');
|
|
31
35
|
}
|
|
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
|
+
}
|
|
32
238
|
/**
|
|
33
239
|
* 拉取安全域名列表
|
|
34
240
|
* @returns {Promise<IAuthDomainsRes>}
|
|
@@ -255,18 +461,11 @@ class EnvService {
|
|
|
255
461
|
}
|
|
256
462
|
getCos() {
|
|
257
463
|
const { secretId, secretKey, token } = this.environment.getAuthConfig();
|
|
258
|
-
|
|
464
|
+
return new cos_nodejs_sdk_v5_1.default({
|
|
259
465
|
SecretId: secretId,
|
|
260
466
|
SecretKey: secretKey,
|
|
261
|
-
SecurityToken: token
|
|
262
|
-
|
|
263
|
-
};
|
|
264
|
-
if (constant_1.COS_SDK_PROTOCOL) {
|
|
265
|
-
cosConfig.Protocol = constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
266
|
-
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
267
|
-
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':';
|
|
268
|
-
}
|
|
269
|
-
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
467
|
+
SecurityToken: token
|
|
468
|
+
});
|
|
270
469
|
}
|
|
271
470
|
getStorageConfig() {
|
|
272
471
|
var _a;
|
package/lib/function/index.js
CHANGED
|
@@ -129,7 +129,7 @@ class FunctionService {
|
|
|
129
129
|
*/
|
|
130
130
|
async createFunction(funcParam) {
|
|
131
131
|
const { namespace } = this.getFunctionConfig();
|
|
132
|
-
const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath
|
|
132
|
+
const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath } = funcParam;
|
|
133
133
|
const funcName = func.name;
|
|
134
134
|
const params = configToParams({
|
|
135
135
|
func,
|
|
@@ -257,13 +257,15 @@ class FunctionService {
|
|
|
257
257
|
/**
|
|
258
258
|
* 删除云函数
|
|
259
259
|
* @param {string} name 云函数名称
|
|
260
|
+
* @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。
|
|
260
261
|
* @returns {Promise<IResponseInfo>}
|
|
261
262
|
*/
|
|
262
|
-
async deleteFunction(name) {
|
|
263
|
+
async deleteFunction(name, qualifier) {
|
|
263
264
|
const { namespace } = this.getFunctionConfig();
|
|
264
265
|
return this.scfService.request('DeleteFunction', {
|
|
265
266
|
FunctionName: name,
|
|
266
|
-
Namespace: namespace
|
|
267
|
+
Namespace: namespace,
|
|
268
|
+
Qualifier: qualifier
|
|
267
269
|
});
|
|
268
270
|
}
|
|
269
271
|
/**
|
package/lib/storage/index.js
CHANGED
|
@@ -20,8 +20,6 @@ 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 runenv_1 = require("../utils/runenv");
|
|
24
|
-
const constant_1 = require("../constant");
|
|
25
23
|
const BIG_FILE_SIZE = 5242880; // 5MB 1024*1024*5
|
|
26
24
|
class StorageService {
|
|
27
25
|
constructor(environment) {
|
|
@@ -841,27 +839,13 @@ class StorageService {
|
|
|
841
839
|
getCos(parallel = 20) {
|
|
842
840
|
const { secretId, secretKey, token, proxy } = this.environment.getAuthConfig();
|
|
843
841
|
const cosProxy = process.env.TCB_COS_PROXY;
|
|
844
|
-
|
|
842
|
+
return new cos_nodejs_sdk_v5_1.default({
|
|
845
843
|
FileParallelLimit: parallel,
|
|
846
844
|
SecretId: secretId,
|
|
847
845
|
SecretKey: secretKey,
|
|
848
846
|
Proxy: cosProxy || proxy,
|
|
849
|
-
SecurityToken: token
|
|
850
|
-
|
|
851
|
-
};
|
|
852
|
-
if (constant_1.COS_SDK_PROTOCOL) {
|
|
853
|
-
cosConfig.Protocol = constant_1.COS_SDK_PROTOCOL.endsWith(':')
|
|
854
|
-
? constant_1.COS_SDK_PROTOCOL.toLowerCase()
|
|
855
|
-
: constant_1.COS_SDK_PROTOCOL.toLowerCase() + ':';
|
|
856
|
-
}
|
|
857
|
-
// COSSDK 默认开启 KeepAlive,这里提供关闭的方式
|
|
858
|
-
if (constant_1.COS_SDK_KEEPALIVE) {
|
|
859
|
-
cosConfig.KeepAlive = { true: true, false: false }[constant_1.COS_SDK_KEEPALIVE];
|
|
860
|
-
}
|
|
861
|
-
else if (runenv_1.checkIsInScf()) {
|
|
862
|
-
cosConfig.KeepAlive = false;
|
|
863
|
-
}
|
|
864
|
-
return new cos_nodejs_sdk_v5_1.default(cosConfig);
|
|
847
|
+
SecurityToken: token
|
|
848
|
+
});
|
|
865
849
|
}
|
|
866
850
|
/**
|
|
867
851
|
* 将 cloudPath 转换成 cloudPath/ 形式
|
|
@@ -70,13 +70,6 @@ class CloudService {
|
|
|
70
70
|
cam: 'https://cam.tencentcloudapi.com',
|
|
71
71
|
cdn: 'https://cdn.tencentcloudapi.com'
|
|
72
72
|
};
|
|
73
|
-
// 云梯账号走内网域名
|
|
74
|
-
const intranetUrlMap = Object.keys(urlMap).map((service) => ({
|
|
75
|
-
[service]: `https://${service}.internal.tencentcloudapi.com`,
|
|
76
|
-
})).reduce((acc, cur) => (Object.assign(Object.assign({}, acc), cur)), {});
|
|
77
|
-
if (constant_1.USE_INTERNAL_ENDPOINT) {
|
|
78
|
-
return intranetUrlMap[this.service];
|
|
79
|
-
}
|
|
80
73
|
if (urlMap[this.service]) {
|
|
81
74
|
return urlMap[this.service];
|
|
82
75
|
}
|
|
@@ -6,12 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.fetchStream = exports.fetch = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
9
|
-
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
9
|
+
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
|
|
10
10
|
const error_1 = require("../error");
|
|
11
11
|
// 使用 fetch + 代理
|
|
12
12
|
async function fetch(url, config = {}, proxy) {
|
|
13
13
|
if (proxy || process.env.http_proxy) {
|
|
14
|
-
config.agent = new https_proxy_agent_1.
|
|
14
|
+
config.agent = new https_proxy_agent_1.default(proxy || process.env.http_proxy);
|
|
15
15
|
}
|
|
16
16
|
// 解决中文编码问题
|
|
17
17
|
const escapeUrl = new url_1.URL(url).toString();
|
|
@@ -35,7 +35,7 @@ async function fetch(url, config = {}, proxy) {
|
|
|
35
35
|
exports.fetch = fetch;
|
|
36
36
|
async function fetchStream(url, config = {}, proxy) {
|
|
37
37
|
if (proxy || process.env.http_proxy) {
|
|
38
|
-
config.agent = new https_proxy_agent_1.
|
|
38
|
+
config.agent = new https_proxy_agent_1.default(proxy || process.env.http_proxy);
|
|
39
39
|
}
|
|
40
40
|
// 解决中文编码问题
|
|
41
41
|
const escapeUrl = new url_1.URL(url).toString();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/manager-node",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "The node manage service api for cloudbase.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,8 +8,7 @@
|
|
|
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"
|
|
12
|
-
"watch": "rimraf lib types && tsc -w"
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
13
12
|
},
|
|
14
13
|
"repository": {
|
|
15
14
|
"type": "git",
|
|
@@ -38,7 +37,7 @@
|
|
|
38
37
|
"archiver": "^3.1.1",
|
|
39
38
|
"cos-nodejs-sdk-v5": "2.9.0",
|
|
40
39
|
"del": "^5.1.0",
|
|
41
|
-
"https-proxy-agent": "^
|
|
40
|
+
"https-proxy-agent": "^2.2.4",
|
|
42
41
|
"make-dir": "^3.0.0",
|
|
43
42
|
"micromatch": "^4.0.2",
|
|
44
43
|
"node-fetch": "^2.6.0",
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
}
|
|
@@ -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
|
+
}
|