@cloudbase/manager-node 4.7.3 → 4.7.4-beta.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/lib/constant.js +6 -1
- package/lib/function/index.js +47 -45
- package/package.json +1 -1
- package/types/constant.d.ts +4 -0
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.COS_SDK_KEEPALIVE = exports.COS_SDK_PROTOCOL = exports.INTERNAL_ENDPOINT_REGION = 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;
|
|
7
|
+
exports.SCF_TEMP_COS = exports.COS_SDK_KEEPALIVE = exports.COS_SDK_PROTOCOL = exports.INTERNAL_ENDPOINT_REGION = 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',
|
|
@@ -59,3 +59,8 @@ exports.USE_INTERNAL_ENDPOINT = "USE_INTERNAL_ENDPOINT" in process.env;
|
|
|
59
59
|
exports.INTERNAL_ENDPOINT_REGION = process.env.INTERNAL_ENDPOINT_REGION;
|
|
60
60
|
exports.COS_SDK_PROTOCOL = process.env.COS_SDK_PROTOCOL;
|
|
61
61
|
exports.COS_SDK_KEEPALIVE = process.env.COS_SDK_KEEPALIVE;
|
|
62
|
+
// SCF 临时 COS 配置(用于函数代码上传)
|
|
63
|
+
exports.SCF_TEMP_COS = {
|
|
64
|
+
APPID: '1253665819',
|
|
65
|
+
REGION: 'ap-shanghai'
|
|
66
|
+
};
|
package/lib/function/index.js
CHANGED
|
@@ -103,12 +103,13 @@ class FunctionService {
|
|
|
103
103
|
* @memberof FunctionService
|
|
104
104
|
*/
|
|
105
105
|
async updateFunctionIncrementalCode(funcParam) {
|
|
106
|
-
const { env } = this.getFunctionConfig();
|
|
106
|
+
const { env, namespace } = this.getFunctionConfig();
|
|
107
107
|
const { functionRootPath, func, deleteFiles, addFiles } = funcParam;
|
|
108
108
|
const { name, runtime } = func;
|
|
109
109
|
const params = {
|
|
110
110
|
FunctionName: name,
|
|
111
|
-
EnvId: env
|
|
111
|
+
EnvId: env,
|
|
112
|
+
Namespace: namespace
|
|
112
113
|
};
|
|
113
114
|
let packer;
|
|
114
115
|
let base64;
|
|
@@ -249,9 +250,9 @@ class FunctionService {
|
|
|
249
250
|
*/
|
|
250
251
|
async listFunctions(limit = 20, offset = 0) {
|
|
251
252
|
// 获取Function 环境配置
|
|
252
|
-
const {
|
|
253
|
-
const res = await this.
|
|
254
|
-
|
|
253
|
+
const { env } = this.getFunctionConfig();
|
|
254
|
+
const res = await this.tcbService.request('ListFunctions', {
|
|
255
|
+
EnvId: env,
|
|
255
256
|
Limit: limit,
|
|
256
257
|
Offset: offset
|
|
257
258
|
});
|
|
@@ -282,8 +283,8 @@ class FunctionService {
|
|
|
282
283
|
const { envId } = options;
|
|
283
284
|
while (true) {
|
|
284
285
|
try {
|
|
285
|
-
const res = await this.
|
|
286
|
-
|
|
286
|
+
const res = await this.tcbService.request('ListFunctions', {
|
|
287
|
+
EnvId: envId,
|
|
287
288
|
Limit: pageSize,
|
|
288
289
|
Offset: currentOffset
|
|
289
290
|
});
|
|
@@ -614,7 +615,8 @@ class FunctionService {
|
|
|
614
615
|
}
|
|
615
616
|
catch (e) {
|
|
616
617
|
throw new error_1.CloudBaseError(`[${func.name}] 更新函数配置失败:${e.message}`, {
|
|
617
|
-
code: e.code
|
|
618
|
+
code: e.code,
|
|
619
|
+
requestId: e.requestId
|
|
618
620
|
});
|
|
619
621
|
}
|
|
620
622
|
}
|
|
@@ -663,8 +665,9 @@ class FunctionService {
|
|
|
663
665
|
return res;
|
|
664
666
|
}
|
|
665
667
|
catch (e) {
|
|
666
|
-
throw new error_1.CloudBaseError(`[${funcName}]
|
|
667
|
-
code: e.code
|
|
668
|
+
throw new error_1.CloudBaseError(`[${funcName}] 函数代码更新失败:${e.message}`, {
|
|
669
|
+
code: e.code,
|
|
670
|
+
requestId: e.requestId
|
|
668
671
|
});
|
|
669
672
|
}
|
|
670
673
|
}
|
|
@@ -689,7 +692,9 @@ class FunctionService {
|
|
|
689
692
|
return Object.assign({ RequestId }, Result);
|
|
690
693
|
}
|
|
691
694
|
catch (e) {
|
|
692
|
-
throw new error_1.CloudBaseError(`[${name}]
|
|
695
|
+
throw new error_1.CloudBaseError(`[${name}] 调用失败:${e.message}`, {
|
|
696
|
+
requestId: e.requestId
|
|
697
|
+
});
|
|
693
698
|
}
|
|
694
699
|
}
|
|
695
700
|
/**
|
|
@@ -767,7 +772,8 @@ class FunctionService {
|
|
|
767
772
|
catch (e) {
|
|
768
773
|
throw new error_1.CloudBaseError(`[${name}] 创建触发器失败:${e.message}`, {
|
|
769
774
|
action: e.action,
|
|
770
|
-
code: e.code
|
|
775
|
+
code: e.code,
|
|
776
|
+
requestId: e.requestId
|
|
771
777
|
});
|
|
772
778
|
}
|
|
773
779
|
}
|
|
@@ -859,7 +865,9 @@ class FunctionService {
|
|
|
859
865
|
return { Url, RequestId, CodeSha256 };
|
|
860
866
|
}
|
|
861
867
|
catch (e) {
|
|
862
|
-
throw new error_1.CloudBaseError(`[${functionName}]
|
|
868
|
+
throw new error_1.CloudBaseError(`[${functionName}] 获取函数代码下载链接失败:${e.message}`, {
|
|
869
|
+
requestId: e.requestId
|
|
870
|
+
});
|
|
863
871
|
}
|
|
864
872
|
}
|
|
865
873
|
// 函数绑定文件层
|
|
@@ -1032,9 +1040,9 @@ class FunctionService {
|
|
|
1032
1040
|
return;
|
|
1033
1041
|
// 创建失败
|
|
1034
1042
|
if (Status === constant_1.SCF_STATUS.CREATE_FAILED) {
|
|
1035
|
-
|
|
1036
|
-
const
|
|
1037
|
-
throw new error_1.CloudBaseError(
|
|
1043
|
+
const errorDetails = (StatusReasons === null || StatusReasons === void 0 ? void 0 : StatusReasons.map(item => `[${item.ErrorCode}] ${item.ErrorMessage}`).join('\n')) || '';
|
|
1044
|
+
const errorMsg = `云函数创建失败${StatusDesc ? `\n状态描述: ${StatusDesc}` : ''}${errorDetails ? `\n失败信息: ${errorDetails}` : ''}`;
|
|
1045
|
+
throw new error_1.CloudBaseError(errorMsg, { requestId: RequestId });
|
|
1038
1046
|
}
|
|
1039
1047
|
// 函数状态正常
|
|
1040
1048
|
clearInterval(ticker);
|
|
@@ -1194,11 +1202,10 @@ class FunctionService {
|
|
|
1194
1202
|
const zipFilePath = await packer.compressFiles();
|
|
1195
1203
|
// 3. 初始化 cos 并上传
|
|
1196
1204
|
const tempCosObjectName = `/${cosDate}/${objectPath}`;
|
|
1197
|
-
const TEMP_COS_APPID = '1253665819';
|
|
1198
1205
|
const uploadParams = {
|
|
1199
|
-
Bucket: `shtempcos-${
|
|
1206
|
+
Bucket: `shtempcos-${constant_1.SCF_TEMP_COS.APPID}`,
|
|
1200
1207
|
Key: tempCosObjectName,
|
|
1201
|
-
Region:
|
|
1208
|
+
Region: constant_1.SCF_TEMP_COS.REGION,
|
|
1202
1209
|
FilePath: zipFilePath,
|
|
1203
1210
|
};
|
|
1204
1211
|
const cos = new cos_nodejs_sdk_v5_1.default({
|
|
@@ -1212,7 +1219,7 @@ class FunctionService {
|
|
|
1212
1219
|
// 清理临时文件
|
|
1213
1220
|
await packer.clean();
|
|
1214
1221
|
if (err) {
|
|
1215
|
-
reject(err);
|
|
1222
|
+
reject(new error_1.CloudBaseError(`COS 上传失败: ${err.message || err}`));
|
|
1216
1223
|
}
|
|
1217
1224
|
else {
|
|
1218
1225
|
resolve(data);
|
|
@@ -1323,32 +1330,26 @@ class FunctionService {
|
|
|
1323
1330
|
root: functionRootPath
|
|
1324
1331
|
});
|
|
1325
1332
|
await packer.build();
|
|
1326
|
-
//
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
// 再调用tcb COS 上传方式
|
|
1338
|
-
const cosResult = await this.uploadFunctionZipToCos(options, installDependency);
|
|
1333
|
+
// 指定 zip 上传方式:走 ZipFile base64 上传
|
|
1334
|
+
if (deployMode === 'zip') {
|
|
1335
|
+
// 判断是否超过 ZipFile 上传大小限制(1.5MB)
|
|
1336
|
+
const reachMax = await packer.isReachMaxSize();
|
|
1337
|
+
if (reachMax) {
|
|
1338
|
+
throw new error_1.CloudBaseError('ZipFile 上传不能大于 1.5MB,请使用 COS 上传方式(deployMode: "cos")');
|
|
1339
|
+
}
|
|
1340
|
+
const base64 = await packer.getBase64Code();
|
|
1341
|
+
if (!(base64 === null || base64 === void 0 ? void 0 : base64.length)) {
|
|
1342
|
+
throw new error_1.CloudBaseError('文件不能为空');
|
|
1343
|
+
}
|
|
1339
1344
|
return {
|
|
1340
|
-
|
|
1341
|
-
CosBucketRegion: 'ap-shanghai',
|
|
1342
|
-
TempCosObjectName: `/${legacyResult.Key}`
|
|
1345
|
+
ZipFile: base64
|
|
1343
1346
|
};
|
|
1344
1347
|
}
|
|
1345
|
-
//
|
|
1346
|
-
const
|
|
1347
|
-
if (!(base64 === null || base64 === void 0 ? void 0 : base64.length)) {
|
|
1348
|
-
throw new error_1.CloudBaseError('文件不能为空');
|
|
1349
|
-
}
|
|
1348
|
+
// 默认走 COS 上传
|
|
1349
|
+
const legacyResult = await this.uploadFunctionZipToCosLegacy(options, installDependency);
|
|
1350
1350
|
return {
|
|
1351
|
-
|
|
1351
|
+
CosBucketRegion: constant_1.SCF_TEMP_COS.REGION,
|
|
1352
|
+
TempCosObjectName: `/${legacyResult.Key}`
|
|
1352
1353
|
};
|
|
1353
1354
|
}
|
|
1354
1355
|
// 获取 COS 临时信息
|
|
@@ -1387,10 +1388,11 @@ class FunctionService {
|
|
|
1387
1388
|
* @memberof FunctionService
|
|
1388
1389
|
*/
|
|
1389
1390
|
getFunctionConfig() {
|
|
1390
|
-
var _a;
|
|
1391
|
+
var _a, _b, _c, _d;
|
|
1391
1392
|
const envConfig = this.environment.lazyEnvironmentConfig;
|
|
1392
|
-
|
|
1393
|
-
const
|
|
1393
|
+
// Functions 可能为空
|
|
1394
|
+
const namespace = ((_b = (_a = envConfig.Functions) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.Namespace) || '';
|
|
1395
|
+
const appId = (_d = (_c = envConfig.Storages) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.AppId;
|
|
1394
1396
|
const { proxy } = this.environment.cloudBaseContext;
|
|
1395
1397
|
return {
|
|
1396
1398
|
proxy,
|
package/package.json
CHANGED
package/types/constant.d.ts
CHANGED