@cloudbase/manager-node 4.3.4 → 4.4.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.
@@ -83,6 +83,7 @@ class FunctionService {
83
83
  this.environment = environment;
84
84
  this.scfService = new utils_1.CloudService(environment.cloudBaseContext, 'scf', '2018-04-16');
85
85
  this.vpcService = new utils_1.CloudService(environment.cloudBaseContext, 'vpc', '2017-03-12');
86
+ this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
86
87
  }
87
88
  /**
88
89
  * 增量更新函数代码
@@ -314,18 +315,19 @@ class FunctionService {
314
315
  }
315
316
  /**
316
317
  * 获取函数日志
318
+ * @deprecated 请使用 getFunctionLogsV2 代替
317
319
  * @param {{
318
- * name: string
319
- * offset: number
320
- * limit: number
321
- * order: string
322
- * orderBy: string
323
- * startTime: string
324
- * endTime: string
325
- * requestId: string
326
- * }} options
327
- * @returns {Promise<IFunctionLogRes>}
328
- */
320
+ * name: string
321
+ * offset: number
322
+ * limit: number
323
+ * order: string
324
+ * orderBy: string
325
+ * startTime: string
326
+ * endTime: string
327
+ * requestId: string
328
+ * }} options
329
+ * @returns {Promise<IFunctionLogRes>}
330
+ */
329
331
  async getFunctionLogs(options) {
330
332
  let { name, offset = 0, limit = 10, order, orderBy, startTime, endTime, requestId } = options;
331
333
  const { namespace } = this.getFunctionConfig();
@@ -352,6 +354,63 @@ class FunctionService {
352
354
  return res;
353
355
  }
354
356
  /**
357
+ * 获取函数日志 ID 列表
358
+ * @param {{
359
+ * name: string
360
+ * offset: number
361
+ * limit: number
362
+ * startTime: string
363
+ * endTime: string
364
+ * requestId: string
365
+ * qualifier: string
366
+ * }} options
367
+ * @returns {Promise<IFunctionLogResV2>}
368
+ */
369
+ async getFunctionLogsV2(options) {
370
+ let { name, offset = 0, limit = 10, startTime, endTime, requestId, qualifier } = options;
371
+ const { env } = this.getFunctionConfig();
372
+ ({ startTime, endTime } = (0, utils_1.getCompleteTimeRange)({
373
+ startTime,
374
+ endTime
375
+ }));
376
+ const params = {
377
+ EnvId: env,
378
+ FunctionName: name,
379
+ Offset: offset,
380
+ Limit: limit,
381
+ StartTime: startTime,
382
+ EndTime: endTime,
383
+ LogRequestId: requestId,
384
+ Qualifier: qualifier || "$LATEST" // 云函数版本,不传则用 $LATEST
385
+ };
386
+ const res = await this.tcbService.request('GetFunctionLogs', params);
387
+ return res;
388
+ }
389
+ /**
390
+ * 根据函数日志 ID 查询日志详情
391
+ * @param {{
392
+ * startTime: string
393
+ * endTime: string
394
+ * logRequestId: string
395
+ * }} options
396
+ * @returns {Promise<IFunctionLogRes>}
397
+ */
398
+ async getFunctionLogDetail(options) {
399
+ let { logRequestId, startTime, endTime } = options;
400
+ ({ startTime, endTime } = (0, utils_1.getCompleteTimeRange)({
401
+ startTime,
402
+ endTime
403
+ }));
404
+ const params = {
405
+ StartTime: startTime,
406
+ LogRequestId: logRequestId,
407
+ EndTime: endTime
408
+ };
409
+ console.log("params", params);
410
+ const res = await this.tcbService.request('GetFunctionLogDetail', params);
411
+ return res;
412
+ }
413
+ /**
355
414
  * 更新云函数配置
356
415
  * @param {ICloudFunction} func 云函数配置
357
416
  * @returns {Promise<IResponseInfo>}
@@ -965,6 +1024,12 @@ __decorate([
965
1024
  __decorate([
966
1025
  (0, utils_1.preLazy)()
967
1026
  ], FunctionService.prototype, "getFunctionLogs", null);
1027
+ __decorate([
1028
+ (0, utils_1.preLazy)()
1029
+ ], FunctionService.prototype, "getFunctionLogsV2", null);
1030
+ __decorate([
1031
+ (0, utils_1.preLazy)()
1032
+ ], FunctionService.prototype, "getFunctionLogDetail", null);
968
1033
  __decorate([
969
1034
  (0, utils_1.preLazy)()
970
1035
  ], FunctionService.prototype, "updateFunctionConfig", null);
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.formatTimeByMs = exports.formatTimeValue = exports.guid6 = void 0;
20
+ exports.getCompleteTimeRange = exports.formatTimeByMs = exports.formatTimeValue = exports.guid6 = void 0;
21
21
  exports.compressToZip = compressToZip;
22
22
  exports.downloadAndExtractRemoteZip = downloadAndExtractRemoteZip;
23
23
  exports.upload = upload;
@@ -238,3 +238,25 @@ const formatTimeByMs = (ms) => {
238
238
  return `${year}-${(0, exports.formatTimeValue)(month)}-${(0, exports.formatTimeValue)(date)} ${(0, exports.formatTimeValue)(hour)}:${(0, exports.formatTimeValue)(minute)}:${(0, exports.formatTimeValue)(second)}`;
239
239
  };
240
240
  exports.formatTimeByMs = formatTimeByMs;
241
+ const getCompleteTimeRange = (timeRange) => {
242
+ let { startTime, endTime } = timeRange;
243
+ if (!startTime && !endTime) {
244
+ // 都不传则 startTime 为当前时间,endTime 为 startTime + 1d
245
+ const curTime = new Date().getTime();
246
+ startTime = (0, exports.formatTimeByMs)(curTime);
247
+ endTime = (0, exports.formatTimeByMs)(curTime + 24 * 3600 * 1000);
248
+ }
249
+ if (startTime && !endTime) {
250
+ // 自动补 endTime 为 startTime + 1d
251
+ endTime = (0, exports.formatTimeByMs)(new Date(startTime).getTime() + 24 * 3600 * 1000);
252
+ }
253
+ if (endTime && !startTime) {
254
+ // 自动补 startTime 为 endTime - 1d
255
+ startTime = (0, exports.formatTimeByMs)(new Date(endTime).getTime() - 24 * 3600 * 1000);
256
+ }
257
+ return {
258
+ startTime,
259
+ endTime
260
+ };
261
+ };
262
+ exports.getCompleteTimeRange = getCompleteTimeRange;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/manager-node",
3
- "version": "4.3.4",
3
+ "version": "4.4.0",
4
4
  "description": "The node manage service api for cloudbase.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  import { Environment } from '../environment';
2
- import { IResponseInfo, ICloudFunction, IFunctionLogOptions, ICloudFunctionTrigger, IFunctionInvokeRes, IFunctionLogRes, IFunctionDownloadUrlRes } from '../interfaces';
2
+ import { IResponseInfo, ICloudFunction, 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;
@@ -177,6 +177,7 @@ export declare class FunctionService {
177
177
  private environment;
178
178
  private vpcService;
179
179
  private scfService;
180
+ private tcbService;
180
181
  constructor(environment: Environment);
181
182
  /**
182
183
  * 增量更新函数代码
@@ -228,20 +229,45 @@ export declare class FunctionService {
228
229
  getFunctionDetail(name: string, codeSecret?: string): Promise<IFunctionInfo>;
229
230
  /**
230
231
  * 获取函数日志
232
+ * @deprecated 请使用 getFunctionLogsV2 代替
231
233
  * @param {{
232
- * name: string
233
- * offset: number
234
- * limit: number
235
- * order: string
236
- * orderBy: string
237
- * startTime: string
238
- * endTime: string
239
- * requestId: string
240
- * }} options
241
- * @returns {Promise<IFunctionLogRes>}
242
- */
234
+ * name: string
235
+ * offset: number
236
+ * limit: number
237
+ * order: string
238
+ * orderBy: string
239
+ * startTime: string
240
+ * endTime: string
241
+ * requestId: string
242
+ * }} options
243
+ * @returns {Promise<IFunctionLogRes>}
244
+ */
243
245
  getFunctionLogs(options: IFunctionLogOptions): Promise<IFunctionLogRes>;
244
246
  /**
247
+ * 获取函数日志 ID 列表
248
+ * @param {{
249
+ * name: string
250
+ * offset: number
251
+ * limit: number
252
+ * startTime: string
253
+ * endTime: string
254
+ * requestId: string
255
+ * qualifier: string
256
+ * }} options
257
+ * @returns {Promise<IFunctionLogResV2>}
258
+ */
259
+ getFunctionLogsV2(options: IFunctionLogOptionsV2): Promise<IFunctionLogResV2>;
260
+ /**
261
+ * 根据函数日志 ID 查询日志详情
262
+ * @param {{
263
+ * startTime: string
264
+ * endTime: string
265
+ * logRequestId: string
266
+ * }} options
267
+ * @returns {Promise<IFunctionLogRes>}
268
+ */
269
+ getFunctionLogDetail(options: IFunctionLogDetailOptions): Promise<IFunctionLogDetailRes>;
270
+ /**
245
271
  * 更新云函数配置
246
272
  * @param {ICloudFunction} func 云函数配置
247
273
  * @returns {Promise<IResponseInfo>}
@@ -43,6 +43,20 @@ export interface IFunctionLogOptions {
43
43
  endTime?: string;
44
44
  requestId?: string;
45
45
  }
46
+ export interface IFunctionLogOptionsV2 {
47
+ name: string;
48
+ offset?: number;
49
+ limit?: number;
50
+ startTime?: string;
51
+ endTime?: string;
52
+ requestId?: string;
53
+ qualifier?: string;
54
+ }
55
+ export interface IFunctionLogDetailOptions {
56
+ endTime?: string;
57
+ logRequestId: string;
58
+ startTime?: string;
59
+ }
46
60
  export interface IFunctionInvokeRes {
47
61
  RequestId: string;
48
62
  Log: string;
@@ -58,6 +72,25 @@ export interface IFunctionLogRes {
58
72
  Data: [];
59
73
  TotalCount: number;
60
74
  }
75
+ export interface IFunctionLogResV2 {
76
+ RequestId: string;
77
+ LogList: {
78
+ RequestId: string;
79
+ RetCode: number;
80
+ RetryNum: number;
81
+ StartTime: string;
82
+ }[];
83
+ }
84
+ export interface IFunctionLogDetailRes {
85
+ Context: string;
86
+ Duration: number;
87
+ ListOver: boolean;
88
+ LogJson: string;
89
+ MemUsage: number;
90
+ RequestId: string;
91
+ RetMsg: string;
92
+ StartTime: string;
93
+ }
61
94
  export interface IFunctionDownloadUrlRes {
62
95
  Url: string;
63
96
  RequestId: string;
@@ -57,3 +57,10 @@ export declare function upperCaseObjKey(object: any): any;
57
57
  export declare function fetchTemplates(types: ('scfFunc' | 'tcbrFunc' | 'tcbrContainer')[]): Promise<ITemplate[]>;
58
58
  export declare const formatTimeValue: (num: any) => string;
59
59
  export declare const formatTimeByMs: (ms: number) => string;
60
+ export declare const getCompleteTimeRange: (timeRange: {
61
+ startTime?: string;
62
+ endTime?: string;
63
+ }) => {
64
+ startTime: string;
65
+ endTime: string;
66
+ };