Skip to content

Commit

Permalink
Add shouldSkipAuditFunc option and some type fixes
Browse files Browse the repository at this point in the history
- Add shouldSkipAuditFunc(https://github.com/PayU/express-request-logger/releases/tag/v4.0.0)
- Fix some mismatches with README and remove using of any
  • Loading branch information
acomagu committed May 10, 2024
1 parent 1875397 commit ca2c27b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ app.use(
"5xx": "error",
},
},
shouldSkipAuditFunc(_req, _res) {
return false;
},
}),
(req, res, next) => {
req.maxBodyLength; // $ExpectType number
Expand Down
35 changes: 24 additions & 11 deletions types/express-requests-logger/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ declare namespace audit {
*/
maskBody?: string[] | undefined;

/**
* pass the fields you wish to mask in the query of the requests (sensitive data like passwords, credit cards numbers etc..).
* {@link https://github.com/PayU/express-request-logger#maskquery}
*/
maskQuery?: string[] | undefined;

/**
* pass the header names you wish to exclude from the audit (senstitive data like authorization headers etc..). * field - exclude all headers
* {@link https://github.com/PayU/express-request-logger#excludeheaders}
Expand All @@ -53,14 +47,25 @@ declare namespace audit {
/**
* {@link https://github.com/PayU/express-request-logger#options}
*/
interface Options extends CommonOptions {
interface Options {
/**
* The logger to use for logging the request/response.
* Package tested only with `bunyan` logger, but should work with any logger which has a info method which takes an object.
* {@link https://github.com/PayU/express-request-logger#logger}
*/
logger?: Logger | undefined;

/**
* Should be a function, that returns boolean value to indicate whether
* to skip the audit for the current request. Usually the logic should
* be around the request/response params. Useful to provide a custom
* logic for cases we would want to skip logging specific request.
*
* The default implementation of the function returns false.
* {@link https://github.com/PayU/express-request-logger#shouldskipauditfunc}
*/
shouldSkipAuditFunc?: ((req: Express.Request, res: Express.Response) => boolean) | undefined;

/**
* `true` - log once the request arrives (request details), and log after response is sent (both request and response).
* Useful if there is a concern that the server will crash during the request and there is a need to log the request before it's processed.
Expand All @@ -79,8 +84,16 @@ declare namespace audit {
* Specific configuration for requests
* {@link https://github.com/PayU/express-request-logger#request}
*/
request?: any;
request?: RequestOptions | undefined;

/**
* Specific configuration for responses
* {@link https://github.com/PayU/express-request-logger#response}
*/
response?: ResponseOptions | undefined;
}

interface RequestOptions extends CommonOptions {
/**
* Additional to mask options, you can add your own functionality to mask request body.
* This function will execute as a masking function before the package functions.
Expand All @@ -90,10 +103,10 @@ declare namespace audit {
customMaskBodyFunc?: ((req: Request) => string) | undefined;

/**
* Specific configuration for responses
* {@link https://github.com/PayU/express-request-logger#response}
* pass the fields you wish to mask in the query of the requests (sensitive data like passwords, credit cards numbers etc..).
* {@link https://github.com/PayU/express-request-logger#maskquery}
*/
response?: ResponseOptions | undefined;
maskQuery?: string[] | undefined;
}

interface ResponseOptions extends CommonOptions {
Expand Down
2 changes: 1 addition & 1 deletion types/express-requests-logger/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"name": "@types/express-requests-logger",
"version": "3.0.9999",
"version": "4.0.9999",
"projects": [
"https://github.com/PayU/express-request-logger"
],
Expand Down

0 comments on commit ca2c27b

Please sign in to comment.