Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4 #2

Closed
wants to merge 16 commits into from
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@babel/preset-env",
{
"targets": {
"node": true
"node": "current"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
node-version: 14
- run: npm install
- run: npm test
- uses: JS-DevTools/npm-publish@v1
Expand Down
61 changes: 61 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Changelog

## Breaking changes v4

### Node.js
**Dropped** support for Node.js **12**. Minimum Node.js version is now **14**

### API changes
#### Registration Options
- auditAuthOnly -> removed (can be filtered with isAuditable, check example below)
- auditGetRequests -> removed (can be filtered with isAuditable, check example below)
- showErrorsOnStdErr -> renamed to **debug** (false by default)
- isAuditable -> invoked with **request** as parameter (arity 1) to handle all cases (audits all by default, check example below for filtering)
- getEntity -> renamed to **setEntity**. Returns by default the endpoint path
- cacheEnabled -> renamed to isCacheEnabled

Example using **isAuditable** (auditAuthOnly, auditGetRequests cases and path filtering)

```js
await server.register({
plugin: require("hapi-audit-rest"),
options: {
isAuditable: ({ auth: { isAuthenticated }, method, url: { pathname } }) => {
// do not audit unauthenticated requests
if (!isAuthenticated) {
return false
}

// do not audit GET requests
if (method === "get") {
return false
}

// do not audit requests when path does not start from /api
if (!pathname.startsWith("/api")) {
return false
}

// return true to audit all other cases
return true
}
},
});
```

Example using **setEntity** option:
```js
await server.register({
plugin: require("hapi-audit-rest"),
options: {
// use the standard pattern of an api i.e. /api/v1.0/users, to refine the entity name
// will have 'entity: users' in audit log
setEntity: (path) => path.split("/")[3],
}
},
});
```


#### Route Options
- getPath -> renamed to **setInjectedPath**
128 changes: 91 additions & 37 deletions README.md

Large diffs are not rendered by default.