@cloudbase/manager-node 4.6.9 → 4.7.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/lib/environment.js +1 -0
- package/lib/function/index.js +216 -67
- package/lib/function/packer.js +1 -0
- package/lib/user/index.js +3 -0
- package/package.json +1 -1
- package/types/function/index.d.ts +19 -1
- package/types/function/packer.d.ts +1 -1
- package/types/function/types.d.ts +4 -1
- package/types/interfaces/function.interface.d.ts +2 -0
- package/types/user/index.d.ts +6 -0
package/lib/environment.js
CHANGED
|
@@ -23,6 +23,7 @@ class Environment {
|
|
|
23
23
|
this.cloudBaseContext = context;
|
|
24
24
|
this.envType = context.envType;
|
|
25
25
|
// 拉取当前环境 的环境信息 todo
|
|
26
|
+
this.userService = new user_1.UserService(this);
|
|
26
27
|
this.functionService = new function_1.FunctionService(this);
|
|
27
28
|
this.cloudRunService = new cloudrun_1.CloudRunService(this);
|
|
28
29
|
this.agentService = new agent_1.AgentService(this);
|
package/lib/function/index.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.FunctionService = void 0;
|
|
|
13
13
|
const fs_1 = __importDefault(require("fs"));
|
|
14
14
|
const path_1 = __importDefault(require("path"));
|
|
15
15
|
const lodash_1 = __importDefault(require("lodash"));
|
|
16
|
+
const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
16
17
|
const packer_1 = require("./packer");
|
|
17
18
|
const error_1 = require("../error");
|
|
18
19
|
const utils_1 = require("../utils");
|
|
@@ -77,6 +78,14 @@ function configToParams(options) {
|
|
|
77
78
|
}));
|
|
78
79
|
params.Layers = transformLayers;
|
|
79
80
|
}
|
|
81
|
+
// HTTP 云函数类型
|
|
82
|
+
if ((func === null || func === void 0 ? void 0 : func.type) === 'HTTP') {
|
|
83
|
+
params.Type = 'HTTP';
|
|
84
|
+
}
|
|
85
|
+
// 云函数描述
|
|
86
|
+
if (func === null || func === void 0 ? void 0 : func.description) {
|
|
87
|
+
params.Description = func.description;
|
|
88
|
+
}
|
|
80
89
|
return params;
|
|
81
90
|
}
|
|
82
91
|
class FunctionService {
|
|
@@ -85,6 +94,7 @@ class FunctionService {
|
|
|
85
94
|
this.scfService = new utils_1.CloudService(environment.cloudBaseContext, 'scf', '2018-04-16');
|
|
86
95
|
this.vpcService = new utils_1.CloudService(environment.cloudBaseContext, 'vpc', '2017-03-12');
|
|
87
96
|
this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
|
|
97
|
+
this.userService = environment.getUserService();
|
|
88
98
|
}
|
|
89
99
|
/**
|
|
90
100
|
* 增量更新函数代码
|
|
@@ -93,12 +103,12 @@ class FunctionService {
|
|
|
93
103
|
* @memberof FunctionService
|
|
94
104
|
*/
|
|
95
105
|
async updateFunctionIncrementalCode(funcParam) {
|
|
96
|
-
const {
|
|
106
|
+
const { env } = this.getFunctionConfig();
|
|
97
107
|
const { functionRootPath, func, deleteFiles, addFiles } = funcParam;
|
|
98
108
|
const { name, runtime } = func;
|
|
99
109
|
const params = {
|
|
100
110
|
FunctionName: name,
|
|
101
|
-
|
|
111
|
+
EnvId: env
|
|
102
112
|
};
|
|
103
113
|
let packer;
|
|
104
114
|
let base64;
|
|
@@ -122,7 +132,7 @@ class FunctionService {
|
|
|
122
132
|
}
|
|
123
133
|
params.AddFiles = base64;
|
|
124
134
|
}
|
|
125
|
-
return this.
|
|
135
|
+
return this.tcbService.request('UpdateFunctionIncrementalCode', params);
|
|
126
136
|
}
|
|
127
137
|
/**
|
|
128
138
|
* 创建云函数
|
|
@@ -130,14 +140,14 @@ class FunctionService {
|
|
|
130
140
|
* @returns {(Promise<IResponseInfo | ICreateFunctionRes>)}
|
|
131
141
|
*/
|
|
132
142
|
async createFunction(funcParam) {
|
|
133
|
-
const {
|
|
134
|
-
const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath } = funcParam;
|
|
143
|
+
const { env } = this.getFunctionConfig();
|
|
144
|
+
const { func, functionRootPath, force = false, base64Code, codeSecret, functionPath, deployMode } = funcParam;
|
|
135
145
|
const funcName = func.name;
|
|
136
146
|
const params = configToParams({
|
|
137
147
|
func,
|
|
138
148
|
codeSecret,
|
|
139
149
|
baseParams: {
|
|
140
|
-
|
|
150
|
+
EnvId: env,
|
|
141
151
|
Role: 'TCB_QcsRole',
|
|
142
152
|
Stamp: 'MINI_QCBASE'
|
|
143
153
|
}
|
|
@@ -146,14 +156,15 @@ class FunctionService {
|
|
|
146
156
|
func,
|
|
147
157
|
base64Code,
|
|
148
158
|
functionPath,
|
|
149
|
-
functionRootPath
|
|
159
|
+
functionRootPath,
|
|
160
|
+
deployMode
|
|
150
161
|
}, params.InstallDependency);
|
|
151
162
|
const { TopicId, LogsetId } = this.getClsServiceConfig();
|
|
152
163
|
params.ClsTopicId = TopicId;
|
|
153
164
|
params.ClsLogsetId = LogsetId;
|
|
154
165
|
try {
|
|
155
166
|
// 创建云函数
|
|
156
|
-
const res = await this.
|
|
167
|
+
const res = await this.tcbService.request('CreateFunction', params);
|
|
157
168
|
// 等待函数状态正常
|
|
158
169
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
159
170
|
// 创建函数触发器、失败自动重试
|
|
@@ -222,9 +233,9 @@ class FunctionService {
|
|
|
222
233
|
*/
|
|
223
234
|
async getFunctionList(limit = 20, offset = 0) {
|
|
224
235
|
// 获取Function 环境配置
|
|
225
|
-
const {
|
|
226
|
-
const res = await this.
|
|
227
|
-
|
|
236
|
+
const { env } = this.getFunctionConfig();
|
|
237
|
+
const res = await this.tcbService.request('ListFunctions', {
|
|
238
|
+
EnvId: env,
|
|
228
239
|
Limit: limit,
|
|
229
240
|
Offset: offset
|
|
230
241
|
});
|
|
@@ -355,16 +366,17 @@ class FunctionService {
|
|
|
355
366
|
* @returns {Promise<Record<string, string>>}
|
|
356
367
|
*/
|
|
357
368
|
async getFunctionDetail(name, codeSecret) {
|
|
358
|
-
const {
|
|
369
|
+
const { env } = this.getFunctionConfig();
|
|
359
370
|
const params = {
|
|
360
371
|
FunctionName: name,
|
|
361
|
-
|
|
362
|
-
ShowCode: 'TRUE'
|
|
372
|
+
EnvId: env,
|
|
373
|
+
ShowCode: 'TRUE',
|
|
374
|
+
Namespace: env
|
|
363
375
|
};
|
|
364
376
|
if (codeSecret) {
|
|
365
377
|
params.CodeSecret = codeSecret;
|
|
366
378
|
}
|
|
367
|
-
const data = await this.
|
|
379
|
+
const data = await this.tcbService.request('GetFunction', params);
|
|
368
380
|
// 解析 VPC 配置
|
|
369
381
|
const { VpcId = '', SubnetId = '' } = data.VpcConfig || {};
|
|
370
382
|
if (VpcId && SubnetId) {
|
|
@@ -554,6 +566,9 @@ class FunctionService {
|
|
|
554
566
|
Namespace: namespace,
|
|
555
567
|
L5Enable: l5Enable
|
|
556
568
|
};
|
|
569
|
+
if (func === null || func === void 0 ? void 0 : func.description) {
|
|
570
|
+
params.Description = func.description;
|
|
571
|
+
}
|
|
557
572
|
// 修复参数存在 undefined 字段时,会出现鉴权失败的情况
|
|
558
573
|
// Environment 为覆盖式修改,不保留已有字段
|
|
559
574
|
envVariables.length && (params.Environment = { Variables: envVariables });
|
|
@@ -610,9 +625,9 @@ class FunctionService {
|
|
|
610
625
|
* @memberof FunctionService
|
|
611
626
|
*/
|
|
612
627
|
async updateFunctionCode(funcParam) {
|
|
613
|
-
const { func, functionRootPath, base64Code, codeSecret, functionPath } = funcParam;
|
|
628
|
+
const { func, functionRootPath, base64Code, codeSecret, functionPath, deployMode } = funcParam;
|
|
614
629
|
const funcName = func.name;
|
|
615
|
-
const {
|
|
630
|
+
const { env } = this.getFunctionConfig();
|
|
616
631
|
let installDependency;
|
|
617
632
|
// Node 函数默认安装依赖
|
|
618
633
|
installDependency = isNodeFunction(func.runtime) ? 'TRUE' : 'FALSE';
|
|
@@ -624,9 +639,16 @@ class FunctionService {
|
|
|
624
639
|
func,
|
|
625
640
|
functionPath,
|
|
626
641
|
functionRootPath,
|
|
627
|
-
base64Code
|
|
642
|
+
base64Code,
|
|
643
|
+
deployMode
|
|
628
644
|
}, installDependency);
|
|
629
|
-
const params =
|
|
645
|
+
const params = {
|
|
646
|
+
FunctionName: funcName,
|
|
647
|
+
EnvId: env,
|
|
648
|
+
Handler: func.handler || 'index.main',
|
|
649
|
+
InstallDependency: installDependency,
|
|
650
|
+
Code: codeParams
|
|
651
|
+
};
|
|
630
652
|
if (codeSecret) {
|
|
631
653
|
params.CodeSecret = codeSecret;
|
|
632
654
|
}
|
|
@@ -634,7 +656,7 @@ class FunctionService {
|
|
|
634
656
|
// 等待函数状态正常
|
|
635
657
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
636
658
|
// 更新云函数代码
|
|
637
|
-
const res = await this.
|
|
659
|
+
const res = await this.tcbService.request('UpdateFunctionCode', params);
|
|
638
660
|
if (installDependency && func.isWaitInstall === true) {
|
|
639
661
|
await this.waitFunctionActive(funcName, codeSecret);
|
|
640
662
|
}
|
|
@@ -989,6 +1011,45 @@ class FunctionService {
|
|
|
989
1011
|
LayerVersion: version
|
|
990
1012
|
});
|
|
991
1013
|
}
|
|
1014
|
+
// 检查函数状态,部分操作在函数更新中时不可进行
|
|
1015
|
+
async waitFunctionActive(funcName, codeSecret) {
|
|
1016
|
+
let ticker;
|
|
1017
|
+
let timer;
|
|
1018
|
+
let resolved;
|
|
1019
|
+
return new Promise((resolve, reject) => {
|
|
1020
|
+
// 超时时间 5 分钟
|
|
1021
|
+
timer = setTimeout(() => {
|
|
1022
|
+
clearInterval(ticker);
|
|
1023
|
+
if (!resolved) {
|
|
1024
|
+
reject(new error_1.CloudBaseError('函数状态异常,检查超时'));
|
|
1025
|
+
}
|
|
1026
|
+
}, 300000);
|
|
1027
|
+
ticker = setInterval(async () => {
|
|
1028
|
+
try {
|
|
1029
|
+
const { Status, StatusDesc, StatusReasons, RequestId } = await this.getFunctionDetail(funcName, codeSecret);
|
|
1030
|
+
// 更新中
|
|
1031
|
+
if (Status === constant_1.SCF_STATUS.CREATING || Status === constant_1.SCF_STATUS.UPDATING)
|
|
1032
|
+
return;
|
|
1033
|
+
// 创建失败
|
|
1034
|
+
if (Status === constant_1.SCF_STATUS.CREATE_FAILED) {
|
|
1035
|
+
StatusDesc && console.log(`函数状态描述: ${StatusDesc}`);
|
|
1036
|
+
const errorDetails = StatusReasons.map(item => `[${item.ErrorCode}] ${item.ErrorMessage}`).join('\n');
|
|
1037
|
+
throw new error_1.CloudBaseError(`云函数创建失败\n失败信息: ${errorDetails}\nRequestId: ${RequestId}`);
|
|
1038
|
+
}
|
|
1039
|
+
// 函数状态正常
|
|
1040
|
+
clearInterval(ticker);
|
|
1041
|
+
clearTimeout(timer);
|
|
1042
|
+
resolve();
|
|
1043
|
+
}
|
|
1044
|
+
catch (e) {
|
|
1045
|
+
clearInterval(ticker);
|
|
1046
|
+
clearTimeout(timer);
|
|
1047
|
+
reject(e);
|
|
1048
|
+
}
|
|
1049
|
+
resolved = true;
|
|
1050
|
+
}, 1000);
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
992
1053
|
/**
|
|
993
1054
|
* 设置预置并发
|
|
994
1055
|
* @private
|
|
@@ -1104,6 +1165,114 @@ class FunctionService {
|
|
|
1104
1165
|
Namespace: namespace
|
|
1105
1166
|
});
|
|
1106
1167
|
}
|
|
1168
|
+
/**
|
|
1169
|
+
* 通过scf COS 上传方式(通过 GetTempCosInfo + COS SDK 上传)
|
|
1170
|
+
* 返回 TempCosObjectName 用于创建/更新函数
|
|
1171
|
+
*/
|
|
1172
|
+
async uploadFunctionZipToCosLegacy(options, installDependency) {
|
|
1173
|
+
const { func, functionPath, functionRootPath } = options;
|
|
1174
|
+
const { env } = this.getFunctionConfig();
|
|
1175
|
+
const { CloudAppId } = await this.userService.getTcbAccountInfo();
|
|
1176
|
+
const objectPath = `${CloudAppId}/${env}/${func.name}.zip`;
|
|
1177
|
+
// 1. 生成存放函数包的临时 Cos 目录
|
|
1178
|
+
const { Date: cosDate, Sign } = await this.scfService.request('GetTempCosInfo', {
|
|
1179
|
+
ObjectPath: `${objectPath}`
|
|
1180
|
+
});
|
|
1181
|
+
// 2. 本地压缩
|
|
1182
|
+
const codeType = packer_1.CodeType.File;
|
|
1183
|
+
// 云端安装依赖,自动忽略 node_modules 目录
|
|
1184
|
+
const ignore = installDependency === 'TRUE'
|
|
1185
|
+
? ['node_modules/**/*', 'node_modules', ...(func.ignore || [])]
|
|
1186
|
+
: [...(func.ignore || [])];
|
|
1187
|
+
const packer = new packer_1.FunctionPacker({
|
|
1188
|
+
ignore,
|
|
1189
|
+
codeType,
|
|
1190
|
+
functionPath,
|
|
1191
|
+
name: func.name,
|
|
1192
|
+
root: functionRootPath
|
|
1193
|
+
});
|
|
1194
|
+
const zipFilePath = await packer.compressFiles();
|
|
1195
|
+
// 3. 初始化 cos 并上传
|
|
1196
|
+
const tempCosObjectName = `/${cosDate}/${objectPath}`;
|
|
1197
|
+
const TEMP_COS_APPID = '1253665819';
|
|
1198
|
+
const uploadParams = {
|
|
1199
|
+
Bucket: `shtempcos-${TEMP_COS_APPID}`,
|
|
1200
|
+
Key: tempCosObjectName,
|
|
1201
|
+
Region: 'ap-shanghai',
|
|
1202
|
+
FilePath: zipFilePath,
|
|
1203
|
+
};
|
|
1204
|
+
const cos = new cos_nodejs_sdk_v5_1.default({
|
|
1205
|
+
getAuthorization: function (options, callback) {
|
|
1206
|
+
// 注入上一步获取的临时密钥
|
|
1207
|
+
callback(Sign);
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
return new Promise((resolve, reject) => {
|
|
1211
|
+
cos.sliceUploadFile(uploadParams, async (err, data) => {
|
|
1212
|
+
// 清理临时文件
|
|
1213
|
+
await packer.clean();
|
|
1214
|
+
if (err) {
|
|
1215
|
+
reject(err);
|
|
1216
|
+
}
|
|
1217
|
+
else {
|
|
1218
|
+
resolve(data);
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
/**
|
|
1224
|
+
* 新的 COS 上传方式(通过 DescribeBuildServiceCosInfo + PUT 上传)
|
|
1225
|
+
* 返回 CosTimestamp 用于创建/更新函数
|
|
1226
|
+
*/
|
|
1227
|
+
async uploadFunctionZipToCos(options, installDependency) {
|
|
1228
|
+
const { func, functionPath, functionRootPath } = options;
|
|
1229
|
+
const { env } = this.getFunctionConfig();
|
|
1230
|
+
// 1. 生成存放函数包的临时 Cos 目录
|
|
1231
|
+
const { UploadUrl, UnixTimestamp, UploadHeaders } = await this.tcbService.request('DescribeBuildServiceCosInfo', {
|
|
1232
|
+
EnvId: env,
|
|
1233
|
+
ServiceName: func.name,
|
|
1234
|
+
Business: 'scf',
|
|
1235
|
+
Suffix: '.zip'
|
|
1236
|
+
});
|
|
1237
|
+
// 2. 本地压缩
|
|
1238
|
+
const codeType = packer_1.CodeType.File;
|
|
1239
|
+
// 云端安装依赖,自动忽略 node_modules 目录
|
|
1240
|
+
const ignore = installDependency === 'TRUE'
|
|
1241
|
+
? ['node_modules/**/*', 'node_modules', ...(func.ignore || [])]
|
|
1242
|
+
: [...(func.ignore || [])];
|
|
1243
|
+
const packer = new packer_1.FunctionPacker({
|
|
1244
|
+
ignore,
|
|
1245
|
+
codeType,
|
|
1246
|
+
functionPath,
|
|
1247
|
+
name: func.name,
|
|
1248
|
+
root: functionRootPath
|
|
1249
|
+
});
|
|
1250
|
+
const zipFilePath = await packer.compressFiles();
|
|
1251
|
+
// 3. 通过 UploadUrl 直接上传
|
|
1252
|
+
const fileBuffer = fs_1.default.readFileSync(zipFilePath);
|
|
1253
|
+
// 构建请求头
|
|
1254
|
+
const headers = {
|
|
1255
|
+
'Content-Type': 'application/zip'
|
|
1256
|
+
};
|
|
1257
|
+
if (UploadHeaders && UploadHeaders.length > 0) {
|
|
1258
|
+
UploadHeaders.forEach(item => {
|
|
1259
|
+
headers[item.Key] = item.Value;
|
|
1260
|
+
});
|
|
1261
|
+
}
|
|
1262
|
+
const response = await fetch(UploadUrl, {
|
|
1263
|
+
method: 'PUT',
|
|
1264
|
+
body: fileBuffer,
|
|
1265
|
+
headers
|
|
1266
|
+
});
|
|
1267
|
+
if (!response.ok) {
|
|
1268
|
+
throw new error_1.CloudBaseError(`上传失败: ${response.status} ${response.statusText}`);
|
|
1269
|
+
}
|
|
1270
|
+
// 清理临时文件
|
|
1271
|
+
await packer.clean();
|
|
1272
|
+
return {
|
|
1273
|
+
UnixTimestamp
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1107
1276
|
async createAccessPath(name, path) {
|
|
1108
1277
|
const access = this.environment.getAccessService();
|
|
1109
1278
|
try {
|
|
@@ -1128,11 +1297,13 @@ class FunctionService {
|
|
|
1128
1297
|
}
|
|
1129
1298
|
}
|
|
1130
1299
|
async getCodeParams(options, installDependency) {
|
|
1131
|
-
const { func, functionPath, functionRootPath, base64Code } = options;
|
|
1132
|
-
//
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1300
|
+
const { func, functionPath, functionRootPath, base64Code, deployMode } = options;
|
|
1301
|
+
// 更新的时候直接上传的zip包的情况
|
|
1302
|
+
// ZIP 包大小上限 20MB,base64 编码后长度约为原始大小的 4/3
|
|
1303
|
+
const MAX_ZIP_SIZE = 20 * 1024 * 1024; // 20MB
|
|
1304
|
+
const MAX_BASE64_LENGTH = Math.floor(MAX_ZIP_SIZE * 4 / 3); // ≈ 27962026
|
|
1305
|
+
if ((base64Code === null || base64Code === void 0 ? void 0 : base64Code.length) > MAX_BASE64_LENGTH) {
|
|
1306
|
+
throw new error_1.CloudBaseError('ZIP 包不能大于 20MB');
|
|
1136
1307
|
}
|
|
1137
1308
|
if (base64Code === null || base64Code === void 0 ? void 0 : base64Code.length) {
|
|
1138
1309
|
return {
|
|
@@ -1152,11 +1323,22 @@ class FunctionService {
|
|
|
1152
1323
|
root: functionRootPath
|
|
1153
1324
|
});
|
|
1154
1325
|
await packer.build();
|
|
1155
|
-
//
|
|
1326
|
+
// 如果指定了上传方式,按指定方式上传
|
|
1327
|
+
// 判断是否需要走 COS 上传
|
|
1156
1328
|
const reachMax = await packer.isReachMaxSize();
|
|
1157
|
-
|
|
1158
|
-
|
|
1329
|
+
const useCos = deployMode === 'cos' || (deployMode !== 'zip' && reachMax);
|
|
1330
|
+
if (useCos) {
|
|
1331
|
+
// 先调用scf的 COS 上传方式
|
|
1332
|
+
const legacyResult = await this.uploadFunctionZipToCosLegacy(options, installDependency);
|
|
1333
|
+
// 再调用tcb COS 上传方式
|
|
1334
|
+
const cosResult = await this.uploadFunctionZipToCos(options, installDependency);
|
|
1335
|
+
return {
|
|
1336
|
+
CosTimestamp: cosResult.UnixTimestamp,
|
|
1337
|
+
CosBucketRegion: 'ap-shanghai',
|
|
1338
|
+
TempCosObjectName: `/${legacyResult.Key}`
|
|
1339
|
+
};
|
|
1159
1340
|
}
|
|
1341
|
+
// ZIP base64 上传
|
|
1160
1342
|
const base64 = await packer.getBase64Code();
|
|
1161
1343
|
if (!(base64 === null || base64 === void 0 ? void 0 : base64.length)) {
|
|
1162
1344
|
throw new error_1.CloudBaseError('文件不能为空');
|
|
@@ -1250,45 +1432,6 @@ class FunctionService {
|
|
|
1250
1432
|
});
|
|
1251
1433
|
return SubnetSet;
|
|
1252
1434
|
}
|
|
1253
|
-
// 检查函数状态,部分操作在函数更新中时不可进行
|
|
1254
|
-
async waitFunctionActive(funcName, codeSecret) {
|
|
1255
|
-
let ticker;
|
|
1256
|
-
let timer;
|
|
1257
|
-
let resolved;
|
|
1258
|
-
return new Promise((resolve, reject) => {
|
|
1259
|
-
// 超时时间 5 分钟
|
|
1260
|
-
timer = setTimeout(() => {
|
|
1261
|
-
clearInterval(ticker);
|
|
1262
|
-
if (!resolved) {
|
|
1263
|
-
reject(new error_1.CloudBaseError('函数状态异常,检查超时'));
|
|
1264
|
-
}
|
|
1265
|
-
}, 300000);
|
|
1266
|
-
ticker = setInterval(async () => {
|
|
1267
|
-
try {
|
|
1268
|
-
const { Status, StatusDesc, StatusReasons, RequestId } = await this.getFunctionDetail(funcName, codeSecret);
|
|
1269
|
-
// 更新中
|
|
1270
|
-
if (Status === constant_1.SCF_STATUS.CREATING || Status === constant_1.SCF_STATUS.UPDATING)
|
|
1271
|
-
return;
|
|
1272
|
-
// 创建失败
|
|
1273
|
-
if (Status === constant_1.SCF_STATUS.CREATE_FAILED) {
|
|
1274
|
-
StatusDesc && console.log(`函数状态描述: ${StatusDesc}`);
|
|
1275
|
-
const errorDetails = StatusReasons.map(item => `[${item.ErrorCode}] ${item.ErrorMessage}`).join('\n');
|
|
1276
|
-
throw new error_1.CloudBaseError(`云函数创建失败\n失败信息: ${errorDetails}\nRequestId: ${RequestId}`);
|
|
1277
|
-
}
|
|
1278
|
-
// 函数状态正常
|
|
1279
|
-
clearInterval(ticker);
|
|
1280
|
-
clearTimeout(timer);
|
|
1281
|
-
resolve();
|
|
1282
|
-
}
|
|
1283
|
-
catch (e) {
|
|
1284
|
-
clearInterval(ticker);
|
|
1285
|
-
clearTimeout(timer);
|
|
1286
|
-
reject(e);
|
|
1287
|
-
}
|
|
1288
|
-
resolved = true;
|
|
1289
|
-
}, 1000);
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
1435
|
}
|
|
1293
1436
|
exports.FunctionService = FunctionService;
|
|
1294
1437
|
__decorate([
|
|
@@ -1399,6 +1542,12 @@ __decorate([
|
|
|
1399
1542
|
__decorate([
|
|
1400
1543
|
(0, utils_1.preLazy)()
|
|
1401
1544
|
], FunctionService.prototype, "getFunctionAlias", null);
|
|
1545
|
+
__decorate([
|
|
1546
|
+
(0, utils_1.preLazy)()
|
|
1547
|
+
], FunctionService.prototype, "uploadFunctionZipToCosLegacy", null);
|
|
1548
|
+
__decorate([
|
|
1549
|
+
(0, utils_1.preLazy)()
|
|
1550
|
+
], FunctionService.prototype, "uploadFunctionZipToCos", null);
|
|
1402
1551
|
__decorate([
|
|
1403
1552
|
(0, utils_1.preLazy)()
|
|
1404
1553
|
], FunctionService.prototype, "createAccessPath", null);
|
package/lib/function/packer.js
CHANGED
package/lib/user/index.js
CHANGED
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ export interface IFunctionCode {
|
|
|
6
6
|
functionRootPath?: string;
|
|
7
7
|
base64Code?: string;
|
|
8
8
|
functionPath?: string;
|
|
9
|
+
deployMode?: 'cos' | 'zip';
|
|
9
10
|
}
|
|
10
11
|
export interface ICreateFunctionParam {
|
|
11
12
|
func: ICloudFunction & {
|
|
@@ -16,6 +17,7 @@ export interface ICreateFunctionParam {
|
|
|
16
17
|
base64Code?: string;
|
|
17
18
|
functionPath?: string;
|
|
18
19
|
codeSecret?: string;
|
|
20
|
+
deployMode?: 'cos' | 'zip';
|
|
19
21
|
}
|
|
20
22
|
export interface IUpdateFunctionCodeParam {
|
|
21
23
|
func: ICloudFunction;
|
|
@@ -23,6 +25,7 @@ export interface IUpdateFunctionCodeParam {
|
|
|
23
25
|
functionRootPath?: string;
|
|
24
26
|
base64Code?: string;
|
|
25
27
|
codeSecret?: string;
|
|
28
|
+
deployMode?: 'cos' | 'zip';
|
|
26
29
|
}
|
|
27
30
|
export interface IUpdateFunctionIncrementalCodeParam {
|
|
28
31
|
func: ICloudFunction;
|
|
@@ -225,6 +228,7 @@ export declare class FunctionService {
|
|
|
225
228
|
private vpcService;
|
|
226
229
|
private scfService;
|
|
227
230
|
private tcbService;
|
|
231
|
+
private userService;
|
|
228
232
|
constructor(environment: Environment);
|
|
229
233
|
/**
|
|
230
234
|
* 增量更新函数代码
|
|
@@ -425,6 +429,7 @@ export declare class FunctionService {
|
|
|
425
429
|
listLayerVersions(options: IVersionListOptions): Promise<IListLayerVersionsRes>;
|
|
426
430
|
listLayers(options: ILayerListOptions): Promise<IListLayerRes>;
|
|
427
431
|
getLayerVersion(options: ILayerOptions): Promise<IGetLayerVersionRes>;
|
|
432
|
+
waitFunctionActive(funcName: string, codeSecret?: string): Promise<void>;
|
|
428
433
|
/**
|
|
429
434
|
* 设置预置并发
|
|
430
435
|
* @private
|
|
@@ -477,6 +482,20 @@ export declare class FunctionService {
|
|
|
477
482
|
* @memberof FunctionService
|
|
478
483
|
*/
|
|
479
484
|
getFunctionAlias(params: IGetFunctionAlias): Promise<IGetFunctionAliasRes>;
|
|
485
|
+
/**
|
|
486
|
+
* 通过scf COS 上传方式(通过 GetTempCosInfo + COS SDK 上传)
|
|
487
|
+
* 返回 TempCosObjectName 用于创建/更新函数
|
|
488
|
+
*/
|
|
489
|
+
uploadFunctionZipToCosLegacy(options: IFunctionCode, installDependency: 'TRUE' | 'FALSE'): Promise<{
|
|
490
|
+
Key: string;
|
|
491
|
+
}>;
|
|
492
|
+
/**
|
|
493
|
+
* 新的 COS 上传方式(通过 DescribeBuildServiceCosInfo + PUT 上传)
|
|
494
|
+
* 返回 CosTimestamp 用于创建/更新函数
|
|
495
|
+
*/
|
|
496
|
+
uploadFunctionZipToCos(options: IFunctionCode, installDependency: 'TRUE' | 'FALSE'): Promise<{
|
|
497
|
+
UnixTimestamp: string;
|
|
498
|
+
}>;
|
|
480
499
|
private createAccessPath;
|
|
481
500
|
private getCodeParams;
|
|
482
501
|
private getTempCosInfo;
|
|
@@ -503,5 +522,4 @@ export declare class FunctionService {
|
|
|
503
522
|
* @returns
|
|
504
523
|
*/
|
|
505
524
|
private getSubnets;
|
|
506
|
-
private waitFunctionActive;
|
|
507
525
|
}
|
|
@@ -27,7 +27,7 @@ export declare class FunctionPacker {
|
|
|
27
27
|
incrementalPath: string;
|
|
28
28
|
codeType: CodeType;
|
|
29
29
|
constructor(options: IPackerOptions);
|
|
30
|
-
compressFiles(): Promise<
|
|
30
|
+
compressFiles(): Promise<string>;
|
|
31
31
|
getJavaFile(): void;
|
|
32
32
|
build(): Promise<void>;
|
|
33
33
|
isBigFile(): Promise<boolean>;
|
|
@@ -181,7 +181,10 @@ export interface ITag1 {
|
|
|
181
181
|
export interface IFunctionCode {
|
|
182
182
|
CosBucketName?: string;
|
|
183
183
|
CosObjectName?: string;
|
|
184
|
-
|
|
184
|
+
CosBucketRegion?: string;
|
|
185
|
+
TempCosObjectName?: string;
|
|
186
|
+
ZipFile?: string;
|
|
187
|
+
CosTimestamp?: string;
|
|
185
188
|
}
|
|
186
189
|
export interface ILayerVersionItem {
|
|
187
190
|
LayerName: string;
|
package/types/user/index.d.ts
CHANGED