@cloudbase/manager-node 4.4.9 → 4.6.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/function/index.js +312 -18
- package/lib/utils/index.js +6 -0
- package/package.json +1 -1
- package/types/function/index.d.ts +105 -3
- package/types/function/types.d.ts +55 -0
- package/types/interfaces/function.interface.d.ts +16 -0
- package/types/utils/index.d.ts +1 -0
package/lib/function/index.js
CHANGED
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.FunctionService = void 0;
|
|
13
13
|
const fs_1 = __importDefault(require("fs"));
|
|
14
14
|
const path_1 = __importDefault(require("path"));
|
|
15
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
15
16
|
const packer_1 = require("./packer");
|
|
16
17
|
const error_1 = require("../error");
|
|
17
18
|
const utils_1 = require("../utils");
|
|
@@ -258,20 +259,96 @@ class FunctionService {
|
|
|
258
259
|
});
|
|
259
260
|
return data;
|
|
260
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* 列出所有函数
|
|
264
|
+
* @param {IListFunctionOptions} options
|
|
265
|
+
* @returns {Promise<Record<string, string>[]>}
|
|
266
|
+
*/
|
|
267
|
+
async listAllFunctions(options) {
|
|
268
|
+
const allFunctions = [];
|
|
269
|
+
let currentOffset = 0;
|
|
270
|
+
const pageSize = 20;
|
|
271
|
+
const { envId } = options;
|
|
272
|
+
while (true) {
|
|
273
|
+
try {
|
|
274
|
+
const res = await this.scfService.request('ListFunctions', {
|
|
275
|
+
Namespace: envId,
|
|
276
|
+
Limit: pageSize,
|
|
277
|
+
Offset: currentOffset
|
|
278
|
+
});
|
|
279
|
+
const { Functions = [], TotalCount } = res;
|
|
280
|
+
if (Functions.length === 0) {
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
allFunctions.push(...Functions);
|
|
284
|
+
// 检查是否已获取所有函数
|
|
285
|
+
if (allFunctions.length >= TotalCount || Functions.length < pageSize) {
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
currentOffset += pageSize;
|
|
289
|
+
}
|
|
290
|
+
catch (error) {
|
|
291
|
+
throw new error_1.CloudBaseError(`获取函数列表失败: ${error.message}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
// 格式化数据
|
|
295
|
+
const data = [];
|
|
296
|
+
allFunctions.forEach(func => {
|
|
297
|
+
const { FunctionId, FunctionName, Runtime, AddTime, ModTime, Status } = func;
|
|
298
|
+
data.push({
|
|
299
|
+
FunctionId,
|
|
300
|
+
FunctionName,
|
|
301
|
+
Runtime,
|
|
302
|
+
AddTime,
|
|
303
|
+
ModTime,
|
|
304
|
+
Status
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
return data;
|
|
308
|
+
}
|
|
261
309
|
/**
|
|
262
310
|
* 删除云函数
|
|
263
311
|
* @param {string} name 云函数名称
|
|
264
312
|
* @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。
|
|
265
313
|
* @returns {Promise<IResponseInfo>}
|
|
266
314
|
*/
|
|
267
|
-
async deleteFunction(name
|
|
315
|
+
async deleteFunction({ name }) {
|
|
316
|
+
var _a;
|
|
268
317
|
const { namespace } = this.getFunctionConfig();
|
|
269
|
-
|
|
318
|
+
// 检测是否绑定了 API 网关
|
|
319
|
+
const accessService = this.environment.getAccessService();
|
|
320
|
+
const res = await accessService.getAccessList({
|
|
321
|
+
name
|
|
322
|
+
});
|
|
323
|
+
// 删除绑定的 API 网关
|
|
324
|
+
if (((_a = res === null || res === void 0 ? void 0 : res.APISet) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
325
|
+
await accessService.deleteAccess({
|
|
326
|
+
name
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
await this.scfService.request('DeleteFunction', {
|
|
270
330
|
FunctionName: name,
|
|
271
|
-
Namespace: namespace
|
|
272
|
-
Qualifier: qualifier
|
|
331
|
+
Namespace: namespace
|
|
273
332
|
});
|
|
274
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* 批量删除云函数
|
|
336
|
+
* @param {Object} options
|
|
337
|
+
* @param {string[]} options.names 云函数名称列表
|
|
338
|
+
* @returns {Promise<void>}
|
|
339
|
+
*/
|
|
340
|
+
async batchDeleteFunctions({ names }) {
|
|
341
|
+
const promises = names.map(name => (async () => {
|
|
342
|
+
try {
|
|
343
|
+
await this.deleteFunction({ name });
|
|
344
|
+
(0, utils_1.successLog)(`[${name}] 函数删除成功!`);
|
|
345
|
+
}
|
|
346
|
+
catch (e) {
|
|
347
|
+
throw new error_1.CloudBaseError(e.message);
|
|
348
|
+
}
|
|
349
|
+
})());
|
|
350
|
+
await Promise.all(promises);
|
|
351
|
+
}
|
|
275
352
|
/**
|
|
276
353
|
* 获取云函数详细信息
|
|
277
354
|
* @param {string} name 云函数名称
|
|
@@ -306,13 +383,35 @@ class FunctionService {
|
|
|
306
383
|
}
|
|
307
384
|
catch (e) {
|
|
308
385
|
data.VpcConfig = {
|
|
309
|
-
vpc: '',
|
|
310
|
-
subnet: ''
|
|
386
|
+
vpc: 'VpcId',
|
|
387
|
+
subnet: 'SubnetId'
|
|
311
388
|
};
|
|
312
389
|
}
|
|
313
390
|
}
|
|
314
391
|
return data;
|
|
315
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* 批量获取云函数详细信息
|
|
395
|
+
* @param {Object} options
|
|
396
|
+
* @param {string[]} options.names 云函数名称列表
|
|
397
|
+
* @param {string} options.envId 环境 ID
|
|
398
|
+
* @param {string} options.codeSecret
|
|
399
|
+
* @returns {Promise<IFunctionInfo[]>}
|
|
400
|
+
*/
|
|
401
|
+
async batchGetFunctionsDetail({ names, envId, codeSecret }) {
|
|
402
|
+
const data = [];
|
|
403
|
+
const promises = names.map(name => (async () => {
|
|
404
|
+
try {
|
|
405
|
+
const info = await this.getFunctionDetail(name, codeSecret);
|
|
406
|
+
data.push(info);
|
|
407
|
+
}
|
|
408
|
+
catch (e) {
|
|
409
|
+
throw new error_1.CloudBaseError(`${name} 获取信息失败:${e.message}`);
|
|
410
|
+
}
|
|
411
|
+
})());
|
|
412
|
+
await Promise.all(promises);
|
|
413
|
+
return data;
|
|
414
|
+
}
|
|
316
415
|
/**
|
|
317
416
|
* 获取函数日志
|
|
318
417
|
* @deprecated 请使用 getFunctionLogsV2 代替
|
|
@@ -409,6 +508,33 @@ class FunctionService {
|
|
|
409
508
|
const res = await this.tcbService.request('GetFunctionLogDetail', params);
|
|
410
509
|
return res;
|
|
411
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* 获取函数的完整调用日志
|
|
513
|
+
* 该方法会自动完成两步操作:1. 获取日志请求ID列表。 2. 根据ID列表获取每条日志的详细内容。
|
|
514
|
+
* @param {IFunctionLogOptionsV2} options - 查询选项
|
|
515
|
+
* @returns {Promise<IFunctionLogDetailRes[]>} 返回包含完整日志详情的数组
|
|
516
|
+
*/
|
|
517
|
+
async getCompleteFunctionLogs(options) {
|
|
518
|
+
// 调用 getFunctionLogsV2 获取日志请求ID列表
|
|
519
|
+
const { name } = options;
|
|
520
|
+
const logs = await this.getFunctionLogsV2(options);
|
|
521
|
+
// 如果没有日志,直接返回空数组
|
|
522
|
+
if (logs.LogList.length === 0) {
|
|
523
|
+
return [];
|
|
524
|
+
}
|
|
525
|
+
const detailPromises = logs.LogList.map(async (log) => {
|
|
526
|
+
// 对每一个日志ID,调用 getFunctionLogDetail
|
|
527
|
+
const res = await this.getFunctionLogDetail({
|
|
528
|
+
logRequestId: log.RequestId,
|
|
529
|
+
startTime: options.startTime,
|
|
530
|
+
endTime: options.endTime
|
|
531
|
+
});
|
|
532
|
+
return Object.assign(Object.assign({}, res), { RetCode: log.RetCode, FunctionName: name });
|
|
533
|
+
});
|
|
534
|
+
// 并发执行所有详情查询,等待它们全部完成
|
|
535
|
+
const detailedLogs = await Promise.all(detailPromises);
|
|
536
|
+
return detailedLogs;
|
|
537
|
+
}
|
|
412
538
|
/**
|
|
413
539
|
* 更新云函数配置
|
|
414
540
|
* @param {ICloudFunction} func 云函数配置
|
|
@@ -544,6 +670,28 @@ class FunctionService {
|
|
|
544
670
|
throw new error_1.CloudBaseError(`[${name}] 调用失败:\n${e.message}`);
|
|
545
671
|
}
|
|
546
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* 批量调用云函数
|
|
675
|
+
* @param {IFunctionBatchOptions} options
|
|
676
|
+
* @returns {Promise<IFunctionInvokeRes[]>}
|
|
677
|
+
*/
|
|
678
|
+
async batchInvokeFunctions(options) {
|
|
679
|
+
const { functions, envId, log = false } = options;
|
|
680
|
+
const promises = functions.map(func => (async () => {
|
|
681
|
+
try {
|
|
682
|
+
const result = await this.invokeFunction(func.name, func.params);
|
|
683
|
+
if (log) {
|
|
684
|
+
(0, utils_1.successLog)(`[${func.name}] 调用成功\n响应结果:\n`);
|
|
685
|
+
console.log(result);
|
|
686
|
+
}
|
|
687
|
+
return result;
|
|
688
|
+
}
|
|
689
|
+
catch (e) {
|
|
690
|
+
throw new error_1.CloudBaseError(`${func.name} 函数调用失败:${e.message}`);
|
|
691
|
+
}
|
|
692
|
+
})());
|
|
693
|
+
return Promise.all(promises);
|
|
694
|
+
}
|
|
547
695
|
/**
|
|
548
696
|
* 复制云函数
|
|
549
697
|
* @param {string} name 云函数名称
|
|
@@ -586,12 +734,34 @@ class FunctionService {
|
|
|
586
734
|
TriggerDesc: item.config
|
|
587
735
|
};
|
|
588
736
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
737
|
+
try {
|
|
738
|
+
return await this.scfService.request('BatchCreateTrigger', {
|
|
739
|
+
FunctionName: name,
|
|
740
|
+
Namespace: namespace,
|
|
741
|
+
Triggers: JSON.stringify(parsedTriggers),
|
|
742
|
+
Count: parsedTriggers.length
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
catch (e) {
|
|
746
|
+
throw new error_1.CloudBaseError(`[${name}] 创建触发器失败:${e.message}`, {
|
|
747
|
+
action: e.action,
|
|
748
|
+
code: e.code
|
|
749
|
+
});
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
// 批量部署函数触发器
|
|
753
|
+
async batchCreateTriggers(options) {
|
|
754
|
+
const { functions, envId } = options;
|
|
755
|
+
const promises = functions.map(func => (async () => {
|
|
756
|
+
try {
|
|
757
|
+
await this.createFunctionTriggers(func.name, func.triggers);
|
|
758
|
+
(0, utils_1.successLog)(`[${func.name}] 创建云函数触发器成功!`);
|
|
759
|
+
}
|
|
760
|
+
catch (e) {
|
|
761
|
+
throw new error_1.CloudBaseError(e.message);
|
|
762
|
+
}
|
|
763
|
+
})());
|
|
764
|
+
await Promise.all(promises);
|
|
595
765
|
}
|
|
596
766
|
/**
|
|
597
767
|
* 删除云函数触发器
|
|
@@ -601,12 +771,50 @@ class FunctionService {
|
|
|
601
771
|
*/
|
|
602
772
|
async deleteFunctionTrigger(name, triggerName) {
|
|
603
773
|
const { namespace } = this.getFunctionConfig();
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
774
|
+
try {
|
|
775
|
+
await this.scfService.request('DeleteTrigger', {
|
|
776
|
+
FunctionName: name,
|
|
777
|
+
Namespace: namespace,
|
|
778
|
+
TriggerName: triggerName,
|
|
779
|
+
Type: 'timer'
|
|
780
|
+
});
|
|
781
|
+
(0, utils_1.successLog)(`[${name}] 删除云函数触发器 ${triggerName} 成功!`);
|
|
782
|
+
}
|
|
783
|
+
catch (e) {
|
|
784
|
+
throw new error_1.CloudBaseError(`[${name}] 删除触发器失败:${e.message}`);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
async batchDeleteTriggers(options) {
|
|
788
|
+
const { functions, envId } = options;
|
|
789
|
+
const promises = functions.map(func => (async () => {
|
|
790
|
+
try {
|
|
791
|
+
func.triggers.forEach(async (trigger) => {
|
|
792
|
+
await this.deleteFunctionTrigger(func.name, trigger.name);
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
catch (e) {
|
|
796
|
+
throw new error_1.CloudBaseError(e.message);
|
|
797
|
+
}
|
|
798
|
+
})());
|
|
799
|
+
await Promise.all(promises);
|
|
800
|
+
}
|
|
801
|
+
/**
|
|
802
|
+
* 下载云函数代码
|
|
803
|
+
* @param {IFunctionCodeOptions} options
|
|
804
|
+
* @returns {Promise<void>}
|
|
805
|
+
*/
|
|
806
|
+
async downloadFunctionCode(options) {
|
|
807
|
+
const { destPath, envId, functionName, codeSecret } = options;
|
|
808
|
+
// 检验路径是否存在
|
|
809
|
+
(0, utils_1.checkFullAccess)(destPath, true);
|
|
810
|
+
// 获取下载链接
|
|
811
|
+
const { Url } = await this.scfService.request('GetFunctionAddress', {
|
|
812
|
+
FunctionName: functionName,
|
|
813
|
+
Namespace: envId,
|
|
814
|
+
CodeSecret: codeSecret
|
|
609
815
|
});
|
|
816
|
+
// 下载文件
|
|
817
|
+
return (0, utils_1.downloadAndExtractRemoteZip)(Url, destPath);
|
|
610
818
|
}
|
|
611
819
|
/**
|
|
612
820
|
* 获取云函数代码下载 链接
|
|
@@ -632,6 +840,68 @@ class FunctionService {
|
|
|
632
840
|
throw new error_1.CloudBaseError(`[${functionName}] 获取函数代码下载链接失败:\n${e.message}`);
|
|
633
841
|
}
|
|
634
842
|
}
|
|
843
|
+
// 函数绑定文件层
|
|
844
|
+
async attachLayer(options) {
|
|
845
|
+
const { envId, functionName, layerName, layerVersion, codeSecret } = options;
|
|
846
|
+
let { Layers = [] } = await this.getFunctionDetail(functionName, codeSecret);
|
|
847
|
+
Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
|
|
848
|
+
// 新加的文件层添加到最后
|
|
849
|
+
Layers.push({
|
|
850
|
+
LayerName: layerName,
|
|
851
|
+
LayerVersion: layerVersion
|
|
852
|
+
});
|
|
853
|
+
const res = await this.scfService.request('UpdateFunctionConfiguration', {
|
|
854
|
+
Layers,
|
|
855
|
+
Namespace: envId,
|
|
856
|
+
FunctionName: functionName
|
|
857
|
+
});
|
|
858
|
+
return res;
|
|
859
|
+
}
|
|
860
|
+
// 函数解绑文件层
|
|
861
|
+
async unAttachLayer(options) {
|
|
862
|
+
const { envId, functionName, layerName, layerVersion, codeSecret } = options;
|
|
863
|
+
let { Layers } = await this.getFunctionDetail(functionName, codeSecret);
|
|
864
|
+
Layers = Layers.map(item => lodash_1.default.pick(item, ['LayerName', 'LayerVersion']));
|
|
865
|
+
const index = Layers.findIndex(item => item.LayerName === layerName && item.LayerVersion === layerVersion);
|
|
866
|
+
if (index === -1) {
|
|
867
|
+
throw new error_1.CloudBaseError('层不存在');
|
|
868
|
+
}
|
|
869
|
+
// 删除指定的层
|
|
870
|
+
Layers.splice(index, 1);
|
|
871
|
+
const apiParams = {
|
|
872
|
+
Namespace: envId,
|
|
873
|
+
FunctionName: functionName,
|
|
874
|
+
Layers: Layers.length > 0 ? Layers : [{
|
|
875
|
+
LayerName: '',
|
|
876
|
+
LayerVersion: 0
|
|
877
|
+
}]
|
|
878
|
+
};
|
|
879
|
+
return this.scfService.request('UpdateFunctionConfiguration', apiParams);
|
|
880
|
+
}
|
|
881
|
+
// 更新云函数层
|
|
882
|
+
async updateFunctionLayer(options) {
|
|
883
|
+
const { envId, functionName, layers } = options;
|
|
884
|
+
return this.scfService.request('UpdateFunctionConfiguration', {
|
|
885
|
+
Layers: layers,
|
|
886
|
+
Namespace: envId,
|
|
887
|
+
FunctionName: functionName
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
// 下载文件层 ZIP 文件
|
|
891
|
+
async downloadLayer(options) {
|
|
892
|
+
const { name, version, destPath } = options;
|
|
893
|
+
const res = await this.scfService.request('GetLayerVersion', {
|
|
894
|
+
LayerName: name,
|
|
895
|
+
LayerVersion: version
|
|
896
|
+
});
|
|
897
|
+
const url = res === null || res === void 0 ? void 0 : res.Location;
|
|
898
|
+
const zipPath = path_1.default.join(destPath, `${name}-${version}.zip`);
|
|
899
|
+
if ((0, utils_1.checkFullAccess)(zipPath)) {
|
|
900
|
+
throw new error_1.CloudBaseError(`文件已存在:${zipPath}`);
|
|
901
|
+
}
|
|
902
|
+
// 下载文件
|
|
903
|
+
return (0, utils_1.downloadAndExtractRemoteZip)(url, destPath);
|
|
904
|
+
}
|
|
635
905
|
// 创建文件层版本
|
|
636
906
|
async createLayer(options) {
|
|
637
907
|
const { env } = this.getFunctionConfig();
|
|
@@ -704,7 +974,7 @@ class FunctionService {
|
|
|
704
974
|
Limit: limit,
|
|
705
975
|
Offset: offset,
|
|
706
976
|
SearchKey: searchKey,
|
|
707
|
-
SearchSrc: `TCB_${env}`
|
|
977
|
+
// SearchSrc: `TCB_${env}`
|
|
708
978
|
};
|
|
709
979
|
if (runtime) {
|
|
710
980
|
param.CompatibleRuntime = runtime;
|
|
@@ -1033,12 +1303,18 @@ __decorate([
|
|
|
1033
1303
|
__decorate([
|
|
1034
1304
|
(0, utils_1.preLazy)()
|
|
1035
1305
|
], FunctionService.prototype, "listFunctions", null);
|
|
1306
|
+
__decorate([
|
|
1307
|
+
(0, utils_1.preLazy)()
|
|
1308
|
+
], FunctionService.prototype, "listAllFunctions", null);
|
|
1036
1309
|
__decorate([
|
|
1037
1310
|
(0, utils_1.preLazy)()
|
|
1038
1311
|
], FunctionService.prototype, "deleteFunction", null);
|
|
1039
1312
|
__decorate([
|
|
1040
1313
|
(0, utils_1.preLazy)()
|
|
1041
1314
|
], FunctionService.prototype, "getFunctionDetail", null);
|
|
1315
|
+
__decorate([
|
|
1316
|
+
(0, utils_1.preLazy)()
|
|
1317
|
+
], FunctionService.prototype, "batchGetFunctionsDetail", null);
|
|
1042
1318
|
__decorate([
|
|
1043
1319
|
(0, utils_1.preLazy)()
|
|
1044
1320
|
], FunctionService.prototype, "getFunctionLogs", null);
|
|
@@ -1048,6 +1324,9 @@ __decorate([
|
|
|
1048
1324
|
__decorate([
|
|
1049
1325
|
(0, utils_1.preLazy)()
|
|
1050
1326
|
], FunctionService.prototype, "getFunctionLogDetail", null);
|
|
1327
|
+
__decorate([
|
|
1328
|
+
(0, utils_1.preLazy)()
|
|
1329
|
+
], FunctionService.prototype, "getCompleteFunctionLogs", null);
|
|
1051
1330
|
__decorate([
|
|
1052
1331
|
(0, utils_1.preLazy)()
|
|
1053
1332
|
], FunctionService.prototype, "updateFunctionConfig", null);
|
|
@@ -1057,6 +1336,9 @@ __decorate([
|
|
|
1057
1336
|
__decorate([
|
|
1058
1337
|
(0, utils_1.preLazy)()
|
|
1059
1338
|
], FunctionService.prototype, "invokeFunction", null);
|
|
1339
|
+
__decorate([
|
|
1340
|
+
(0, utils_1.preLazy)()
|
|
1341
|
+
], FunctionService.prototype, "batchInvokeFunctions", null);
|
|
1060
1342
|
__decorate([
|
|
1061
1343
|
(0, utils_1.preLazy)()
|
|
1062
1344
|
], FunctionService.prototype, "copyFunction", null);
|
|
@@ -1069,6 +1351,18 @@ __decorate([
|
|
|
1069
1351
|
__decorate([
|
|
1070
1352
|
(0, utils_1.preLazy)()
|
|
1071
1353
|
], FunctionService.prototype, "getFunctionDownloadUrl", null);
|
|
1354
|
+
__decorate([
|
|
1355
|
+
(0, utils_1.preLazy)()
|
|
1356
|
+
], FunctionService.prototype, "attachLayer", null);
|
|
1357
|
+
__decorate([
|
|
1358
|
+
(0, utils_1.preLazy)()
|
|
1359
|
+
], FunctionService.prototype, "unAttachLayer", null);
|
|
1360
|
+
__decorate([
|
|
1361
|
+
(0, utils_1.preLazy)()
|
|
1362
|
+
], FunctionService.prototype, "updateFunctionLayer", null);
|
|
1363
|
+
__decorate([
|
|
1364
|
+
(0, utils_1.preLazy)()
|
|
1365
|
+
], FunctionService.prototype, "downloadLayer", null);
|
|
1072
1366
|
__decorate([
|
|
1073
1367
|
(0, utils_1.preLazy)()
|
|
1074
1368
|
], FunctionService.prototype, "createLayer", null);
|
package/lib/utils/index.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.sleep = sleep;
|
|
|
29
29
|
exports.upperCaseStringFisrt = upperCaseStringFisrt;
|
|
30
30
|
exports.upperCaseObjKey = upperCaseObjKey;
|
|
31
31
|
exports.fetchTemplates = fetchTemplates;
|
|
32
|
+
exports.successLog = successLog;
|
|
32
33
|
const archiver_1 = __importDefault(require("archiver"));
|
|
33
34
|
const crypto_1 = __importDefault(require("crypto"));
|
|
34
35
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -37,6 +38,7 @@ const path_1 = __importDefault(require("path"));
|
|
|
37
38
|
const unzipper_1 = __importDefault(require("unzipper"));
|
|
38
39
|
const constant_1 = require("../constant");
|
|
39
40
|
const http_request_1 = require("./http-request");
|
|
41
|
+
const log_symbols_1 = __importDefault(require("log-symbols"));
|
|
40
42
|
__exportStar(require("./auth"), exports);
|
|
41
43
|
__exportStar(require("./cloud-api-request"), exports);
|
|
42
44
|
__exportStar(require("./cloudbase-request"), exports);
|
|
@@ -307,3 +309,7 @@ const getCompleteTimeRange = (timeRange) => {
|
|
|
307
309
|
};
|
|
308
310
|
};
|
|
309
311
|
exports.getCompleteTimeRange = getCompleteTimeRange;
|
|
312
|
+
function successLog(msg) {
|
|
313
|
+
// 空格,兼容中文字符编码长度问题
|
|
314
|
+
console.log(`${log_symbols_1.default.success} ${msg}`);
|
|
315
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Environment } from '../environment';
|
|
2
|
-
import { IResponseInfo, ICloudFunction, IFunctionLogOptions, ICloudFunctionTrigger, IFunctionInvokeRes, IFunctionLogRes, IFunctionDownloadUrlRes, IFunctionLogDetailOptions, IFunctionLogDetailRes, IFunctionLogOptionsV2, IFunctionLogResV2 } from '../interfaces';
|
|
2
|
+
import { IResponseInfo, ICloudFunction, ICloudFunctionV2, IFunctionLogOptions, ICloudFunctionTrigger, IFunctionInvokeRes, IFunctionLogRes, IFunctionDownloadUrlRes, IFunctionLogDetailOptions, IFunctionLogDetailRes, IFunctionLogOptionsV2, IFunctionLogResV2 } from '../interfaces';
|
|
3
3
|
import { IFunctionInfo } from './types';
|
|
4
4
|
export interface IFunctionCode {
|
|
5
5
|
func: ICloudFunction;
|
|
@@ -173,6 +173,53 @@ export interface IGetFunctionAliasRes extends IResponseInfo {
|
|
|
173
173
|
AddTime: string;
|
|
174
174
|
ModTime: string;
|
|
175
175
|
}
|
|
176
|
+
export interface IListFunctionOptions {
|
|
177
|
+
limit?: number;
|
|
178
|
+
offset?: number;
|
|
179
|
+
envId: string;
|
|
180
|
+
}
|
|
181
|
+
export interface IFunctionBatchOptions {
|
|
182
|
+
functions: ICloudFunctionV2[];
|
|
183
|
+
envId: string;
|
|
184
|
+
log?: boolean;
|
|
185
|
+
}
|
|
186
|
+
export interface IGetAsyncEventStatusRes extends IResponseInfo {
|
|
187
|
+
Result: IAsyncEventStatus;
|
|
188
|
+
RequestId: string;
|
|
189
|
+
}
|
|
190
|
+
export interface IAsyncEventStatus {
|
|
191
|
+
InvokeRequestId: string;
|
|
192
|
+
Status: string;
|
|
193
|
+
StatusCode: number;
|
|
194
|
+
}
|
|
195
|
+
export interface IFunctionCodeOptions {
|
|
196
|
+
envId: string;
|
|
197
|
+
destPath: string;
|
|
198
|
+
functionName: string;
|
|
199
|
+
codeSecret?: string;
|
|
200
|
+
}
|
|
201
|
+
export interface ILayerDownloadOptions {
|
|
202
|
+
name: string;
|
|
203
|
+
version: number;
|
|
204
|
+
destPath: string;
|
|
205
|
+
force?: boolean;
|
|
206
|
+
}
|
|
207
|
+
export interface IAttachOptions {
|
|
208
|
+
envId: string;
|
|
209
|
+
layerName: string;
|
|
210
|
+
layerVersion: number;
|
|
211
|
+
functionName: string;
|
|
212
|
+
codeSecret?: string;
|
|
213
|
+
}
|
|
214
|
+
export interface ISortOptions {
|
|
215
|
+
envId: string;
|
|
216
|
+
functionName: string;
|
|
217
|
+
layers: ILayer[];
|
|
218
|
+
}
|
|
219
|
+
export interface ILayer {
|
|
220
|
+
LayerName: string;
|
|
221
|
+
LayerVersion: number;
|
|
222
|
+
}
|
|
176
223
|
export declare class FunctionService {
|
|
177
224
|
private environment;
|
|
178
225
|
private vpcService;
|
|
@@ -214,19 +261,49 @@ export declare class FunctionService {
|
|
|
214
261
|
* @returns {Promise<Record<string, string>[]>}
|
|
215
262
|
*/
|
|
216
263
|
listFunctions(limit?: number, offset?: number): Promise<Record<string, string>[]>;
|
|
264
|
+
/**
|
|
265
|
+
* 列出所有函数
|
|
266
|
+
* @param {IListFunctionOptions} options
|
|
267
|
+
* @returns {Promise<Record<string, string>[]>}
|
|
268
|
+
*/
|
|
269
|
+
listAllFunctions(options: IListFunctionOptions): Promise<Record<string, string>[]>;
|
|
217
270
|
/**
|
|
218
271
|
* 删除云函数
|
|
219
272
|
* @param {string} name 云函数名称
|
|
220
273
|
* @param {string} qualifier 需要删除的版本号,不填默认删除函数下全部版本。
|
|
221
274
|
* @returns {Promise<IResponseInfo>}
|
|
222
275
|
*/
|
|
223
|
-
deleteFunction(name
|
|
276
|
+
deleteFunction({ name }: {
|
|
277
|
+
name: any;
|
|
278
|
+
}): Promise<void>;
|
|
279
|
+
/**
|
|
280
|
+
* 批量删除云函数
|
|
281
|
+
* @param {Object} options
|
|
282
|
+
* @param {string[]} options.names 云函数名称列表
|
|
283
|
+
* @returns {Promise<void>}
|
|
284
|
+
*/
|
|
285
|
+
batchDeleteFunctions({ names }: {
|
|
286
|
+
names: any;
|
|
287
|
+
}): Promise<void>;
|
|
224
288
|
/**
|
|
225
289
|
* 获取云函数详细信息
|
|
226
290
|
* @param {string} name 云函数名称
|
|
227
291
|
* @returns {Promise<Record<string, string>>}
|
|
228
292
|
*/
|
|
229
293
|
getFunctionDetail(name: string, codeSecret?: string): Promise<IFunctionInfo>;
|
|
294
|
+
/**
|
|
295
|
+
* 批量获取云函数详细信息
|
|
296
|
+
* @param {Object} options
|
|
297
|
+
* @param {string[]} options.names 云函数名称列表
|
|
298
|
+
* @param {string} options.envId 环境 ID
|
|
299
|
+
* @param {string} options.codeSecret
|
|
300
|
+
* @returns {Promise<IFunctionInfo[]>}
|
|
301
|
+
*/
|
|
302
|
+
batchGetFunctionsDetail({ names, envId, codeSecret }: {
|
|
303
|
+
names: any;
|
|
304
|
+
envId: any;
|
|
305
|
+
codeSecret: any;
|
|
306
|
+
}): Promise<IFunctionInfo[]>;
|
|
230
307
|
/**
|
|
231
308
|
* 获取函数日志
|
|
232
309
|
* @deprecated 请使用 getFunctionLogsV2 代替
|
|
@@ -267,6 +344,13 @@ export declare class FunctionService {
|
|
|
267
344
|
* @returns {Promise<IFunctionLogDetailRes>}
|
|
268
345
|
*/
|
|
269
346
|
getFunctionLogDetail(options: IFunctionLogDetailOptions): Promise<IFunctionLogDetailRes>;
|
|
347
|
+
/**
|
|
348
|
+
* 获取函数的完整调用日志
|
|
349
|
+
* 该方法会自动完成两步操作:1. 获取日志请求ID列表。 2. 根据ID列表获取每条日志的详细内容。
|
|
350
|
+
* @param {IFunctionLogOptionsV2} options - 查询选项
|
|
351
|
+
* @returns {Promise<IFunctionLogDetailRes[]>} 返回包含完整日志详情的数组
|
|
352
|
+
*/
|
|
353
|
+
getCompleteFunctionLogs(options: IFunctionLogOptionsV2): Promise<IFunctionLogDetailRes[]>;
|
|
270
354
|
/**
|
|
271
355
|
* 更新云函数配置
|
|
272
356
|
* @param {ICloudFunction} func 云函数配置
|
|
@@ -287,6 +371,12 @@ export declare class FunctionService {
|
|
|
287
371
|
* @returns {Promise<IFunctionInvokeRes>}
|
|
288
372
|
*/
|
|
289
373
|
invokeFunction(name: string, params?: Record<string, any>): Promise<IFunctionInvokeRes>;
|
|
374
|
+
/**
|
|
375
|
+
* 批量调用云函数
|
|
376
|
+
* @param {IFunctionBatchOptions} options
|
|
377
|
+
* @returns {Promise<IFunctionInvokeRes[]>}
|
|
378
|
+
*/
|
|
379
|
+
batchInvokeFunctions(options: IFunctionBatchOptions): Promise<IFunctionInvokeRes[]>;
|
|
290
380
|
/**
|
|
291
381
|
* 复制云函数
|
|
292
382
|
* @param {string} name 云函数名称
|
|
@@ -303,13 +393,21 @@ export declare class FunctionService {
|
|
|
303
393
|
* @returns {Promise<IResponseInfo>}
|
|
304
394
|
*/
|
|
305
395
|
createFunctionTriggers(name: string, triggers?: ICloudFunctionTrigger[]): Promise<IResponseInfo>;
|
|
396
|
+
batchCreateTriggers(options: IFunctionBatchOptions): Promise<void>;
|
|
306
397
|
/**
|
|
307
398
|
* 删除云函数触发器
|
|
308
399
|
* @param {string} name 云函数名称
|
|
309
400
|
* @param {string} triggerName 云函数触发器名称
|
|
310
401
|
* @returns {Promise<IResponseInfo>}
|
|
311
402
|
*/
|
|
312
|
-
deleteFunctionTrigger(name: string, triggerName: string): Promise<
|
|
403
|
+
deleteFunctionTrigger(name: string, triggerName: string): Promise<void>;
|
|
404
|
+
batchDeleteTriggers(options: IFunctionBatchOptions): Promise<void>;
|
|
405
|
+
/**
|
|
406
|
+
* 下载云函数代码
|
|
407
|
+
* @param {IFunctionCodeOptions} options
|
|
408
|
+
* @returns {Promise<void>}
|
|
409
|
+
*/
|
|
410
|
+
downloadFunctionCode(options: IFunctionCodeOptions): Promise<void>;
|
|
313
411
|
/**
|
|
314
412
|
* 获取云函数代码下载 链接
|
|
315
413
|
* @param {string} functionName
|
|
@@ -318,6 +416,10 @@ export declare class FunctionService {
|
|
|
318
416
|
* @memberof FunctionService
|
|
319
417
|
*/
|
|
320
418
|
getFunctionDownloadUrl(functionName: string, codeSecret?: string): Promise<IFunctionDownloadUrlRes>;
|
|
419
|
+
attachLayer(options: IAttachOptions): Promise<IResponseInfo>;
|
|
420
|
+
unAttachLayer(options: IAttachOptions): Promise<IResponseInfo>;
|
|
421
|
+
updateFunctionLayer(options: ISortOptions): Promise<IResponseInfo>;
|
|
422
|
+
downloadLayer(options: ILayerDownloadOptions): Promise<void>;
|
|
321
423
|
createLayer(options: IFunctionLayerOptions): Promise<ICreateLayerResponse>;
|
|
322
424
|
deleteLayerVersion(options: ILayerOptions): Promise<IResponseInfo>;
|
|
323
425
|
listLayerVersions(options: IVersionListOptions): Promise<IListLayerVersionsRes>;
|
|
@@ -122,6 +122,61 @@ export interface IFunctionInfo {
|
|
|
122
122
|
ErrorMessage: string;
|
|
123
123
|
}[];
|
|
124
124
|
RequestId: string;
|
|
125
|
+
Layers: ILayerVersionInfo[];
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 层版本信息
|
|
129
|
+
* 被 GetFunction, ListLayerVersions, ListLayers 接口引用
|
|
130
|
+
*/
|
|
131
|
+
export interface ILayerVersionInfo {
|
|
132
|
+
/**
|
|
133
|
+
* 版本适用的运行时
|
|
134
|
+
* @example ["Python3.10","Python3.9"]
|
|
135
|
+
*/
|
|
136
|
+
CompatibleRuntimes?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* 创建时间
|
|
139
|
+
* @example 2024-11-22 16:52:21
|
|
140
|
+
*/
|
|
141
|
+
AddTime?: string;
|
|
142
|
+
/**
|
|
143
|
+
* 版本描述
|
|
144
|
+
* @example "a layer"
|
|
145
|
+
*/
|
|
146
|
+
Description?: string;
|
|
147
|
+
/**
|
|
148
|
+
* 许可证信息
|
|
149
|
+
* @example " "
|
|
150
|
+
*/
|
|
151
|
+
LicenseInfo?: string | null;
|
|
152
|
+
/**
|
|
153
|
+
* 版本号
|
|
154
|
+
* @example 1
|
|
155
|
+
*/
|
|
156
|
+
LayerVersion?: number;
|
|
157
|
+
/**
|
|
158
|
+
* 层名称
|
|
159
|
+
* @example "layer-name1"
|
|
160
|
+
*/
|
|
161
|
+
LayerName?: string;
|
|
162
|
+
/**
|
|
163
|
+
* 层的具体版本当前状态
|
|
164
|
+
* Active:正常状态
|
|
165
|
+
*/
|
|
166
|
+
Status?: string;
|
|
167
|
+
/**
|
|
168
|
+
* Stamp
|
|
169
|
+
* @example "Default"
|
|
170
|
+
*/
|
|
171
|
+
Stamp?: string;
|
|
172
|
+
/**
|
|
173
|
+
* 返回层绑定的标签信息
|
|
174
|
+
*/
|
|
175
|
+
Tags?: ITag1[];
|
|
176
|
+
}
|
|
177
|
+
export interface ITag1 {
|
|
178
|
+
Key: string;
|
|
179
|
+
Value: string[];
|
|
125
180
|
}
|
|
126
181
|
export interface IFunctionCode {
|
|
127
182
|
CosBucketName?: string;
|
|
@@ -33,6 +33,21 @@ export interface ICloudFunction extends ICloudFunctionConfig {
|
|
|
33
33
|
}[];
|
|
34
34
|
triggers?: ICloudFunctionTrigger[];
|
|
35
35
|
}
|
|
36
|
+
export interface ICloudFunctionV2 {
|
|
37
|
+
name: string;
|
|
38
|
+
config?: ICloudFunctionConfig;
|
|
39
|
+
triggers?: ICloudFunctionTrigger[];
|
|
40
|
+
params?: Record<string, string>;
|
|
41
|
+
handler?: string;
|
|
42
|
+
ignore?: string | string[];
|
|
43
|
+
timeout?: number;
|
|
44
|
+
envVariables?: Record<string, string | number | boolean>;
|
|
45
|
+
runtime?: string;
|
|
46
|
+
vpc?: IFunctionVPC;
|
|
47
|
+
l5?: boolean;
|
|
48
|
+
installDependency?: boolean;
|
|
49
|
+
isWaitInstall?: boolean;
|
|
50
|
+
}
|
|
36
51
|
export interface IFunctionLogOptions {
|
|
37
52
|
name: string;
|
|
38
53
|
offset?: number;
|
|
@@ -66,6 +81,7 @@ export interface IFunctionInvokeRes {
|
|
|
66
81
|
Duration: number;
|
|
67
82
|
BillDuration: number;
|
|
68
83
|
FunctionRequestId: string;
|
|
84
|
+
InvokeResult: number;
|
|
69
85
|
}
|
|
70
86
|
export interface IFunctionLogRes {
|
|
71
87
|
RequestId: string;
|
package/types/utils/index.d.ts
CHANGED