idea-aws 4.3.0 → 4.3.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.
@@ -3,8 +3,8 @@
3
3
  * Note: the log level is controlled by each Lambda function's configuration.
4
4
  */
5
5
  export declare class Logger {
6
- debug: (_: string, params?: any) => void;
7
- info: (_: string, params?: any) => void;
8
- warn: (_: string, err: Error | any, params?: any) => void;
9
- error: (_: string, err: Error | any, params?: any) => void;
6
+ debug: (summary: string, content?: object) => void;
7
+ info: (summary: string, content?: object) => void;
8
+ warn: (summary: string, error: Error | any, content?: object) => void;
9
+ error: (summary: string, error: Error | any, content?: object) => void;
10
10
  }
@@ -7,10 +7,10 @@ exports.Logger = void 0;
7
7
  */
8
8
  class Logger {
9
9
  constructor() {
10
- this.debug = (_, params = {}) => console.debug({ _, ...params });
11
- this.info = (_, params = {}) => console.info({ _, ...params });
12
- this.warn = (_, err, params = {}) => console.warn({ _, ...params, errorType: err.name, errorMessage: err.message, stackTrace: err.stack });
13
- this.error = (_, err, params = {}) => console.error({ _, ...params, errorType: err.name, errorMessage: err.message, stackTrace: err.stack });
10
+ this.debug = (summary, content = {}) => console.debug({ summary, ...content });
11
+ this.info = (summary, content = {}) => console.info({ summary, ...content });
12
+ this.warn = (summary, error, content = {}) => console.warn({ summary, ...content, error });
13
+ this.error = (summary, error, content = {}) => console.error({ summary, ...content, error });
14
14
  }
15
15
  }
16
16
  exports.Logger = Logger;
@@ -37,14 +37,14 @@ export declare abstract class ResourceController extends GenericController {
37
37
  constructor(event: APIGatewayProxyEventV2 | APIGatewayProxyEvent, callback: Callback, options?: ResourceControllerOptions);
38
38
  private initFromEventV2;
39
39
  private initFromEventV1;
40
- protected getEventInfo(): Record<string, any>;
40
+ protected getEventSummary(): Record<string, any>;
41
41
  /**
42
42
  * Force the parsing of a query parameter as an array of strings.
43
43
  */
44
44
  protected getQueryParamAsArray(paramName: string): string[];
45
45
  handleRequest: () => Promise<void>;
46
46
  private remapHandlerError;
47
- protected done(error?: Error | any, result?: any, statusCode?: number): void;
47
+ protected done(error?: Error | any, rawResult?: any, statusCode?: number): void;
48
48
  /**
49
49
  * To @override
50
50
  */
@@ -138,7 +138,7 @@ class ResourceController extends genericController_1.GenericController {
138
138
  }
139
139
  if (options.useMetrics)
140
140
  this.prepareMetrics();
141
- this.logger.info(`START: ${this.httpMethod} ${this.path}`, this.getEventInfo());
141
+ this.logger.info('START', { event: this.getEventSummary() });
142
142
  }
143
143
  catch (err) {
144
144
  this.initError = true;
@@ -190,8 +190,10 @@ class ResourceController extends genericController_1.GenericController {
190
190
  throw new RCError('Malformed body');
191
191
  }
192
192
  }
193
- getEventInfo() {
193
+ getEventSummary() {
194
194
  return {
195
+ httpMethod: this.httpMethod,
196
+ path: this.path,
195
197
  principalId: this.principalId,
196
198
  queryParams: this.queryParams,
197
199
  body: this.body,
@@ -211,30 +213,29 @@ class ResourceController extends genericController_1.GenericController {
211
213
  else
212
214
  return String(this.queryParams[paramName]).split(',');
213
215
  }
214
- remapHandlerError(err, context, replaceWithMessage) {
216
+ remapHandlerError(err, interceptedInContext, replaceWithMessage) {
215
217
  if (err instanceof RCError)
216
218
  return err;
217
219
  const error = err;
218
- error.context = context;
220
+ error.intercepted = interceptedInContext;
219
221
  error.internalMessage = error.message;
220
222
  error.message = replaceWithMessage;
221
223
  return error;
222
224
  }
223
- done(error, result, statusCode = this.returnStatusCode ?? (error ? 400 : 200)) {
224
- const logContent = { statusCode, event: this.getEventInfo() };
225
- if (result)
226
- logContent.result = Array.isArray(result) ? `Array (${result.length})` : result;
225
+ done(error, rawResult, statusCode = this.returnStatusCode ?? (error ? 400 : 200)) {
226
+ const result = error ? { message: error.message } : rawResult ?? {};
227
227
  if (error)
228
- this.logger.error(`END-FAILED: ${this.httpMethod} ${this.path}`, error, logContent);
228
+ this.logger.error('END-FAILED', error, { statusCode, event: this.getEventSummary() });
229
229
  else
230
- this.logger.info(`END-SUCCESS: ${this.httpMethod} ${this.path}`, logContent);
230
+ this.logger.info('END-SUCCESS', { statusCode, event: this.getEventSummary() });
231
+ this.logger.debug('END-DETAIL', Array.isArray(result) ? { array: result.length } : result);
231
232
  if (this.logRequestsWithKey)
232
233
  this.storeLog(!error);
233
234
  if (this.metrics)
234
235
  this.publishMetrics(statusCode, error);
235
236
  this.callback(null, {
236
237
  statusCode: String(statusCode),
237
- body: error ? JSON.stringify({ message: error.message }) : JSON.stringify(result ?? {}),
238
+ body: JSON.stringify(result),
238
239
  headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }
239
240
  });
240
241
  }
@@ -9,7 +9,7 @@ class StreamController extends genericController_1.GenericController {
9
9
  constructor(event, callback) {
10
10
  super(event, callback);
11
11
  this.records = event.Records ?? [];
12
- this.logger.info(`START STREAM: ${this.records.length ?? 0} records`);
12
+ this.logger.info('START STREAM', { records: this.records.length ?? 0 });
13
13
  }
14
14
  }
15
15
  exports.StreamController = StreamController;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idea-aws",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "description": "AWS wrappers to use in IDEA's back-ends",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",