Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fagbokforlaget/nestjs-audit-logging
DEPRECATED
https://github.com/fagbokforlaget/nestjs-audit-logging
deprecated
Last synced: about 1 month ago
JSON representation
DEPRECATED
- Host: GitHub
- URL: https://github.com/fagbokforlaget/nestjs-audit-logging
- Owner: fagbokforlaget
- License: mit
- Created: 2022-04-27T06:16:03.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-02T13:10:12.000Z (10 months ago)
- Last Synced: 2024-11-24T23:12:16.322Z (2 months ago)
- Topics: deprecated
- Language: TypeScript
- Homepage:
- Size: 497 KB
- Stars: 7
- Watchers: 7
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[DEPRECATED]
## Nestjs Audit Logging Interceptor
Library to facilitate adding custom audit log messages to nestjs controllers.
# Usecase
`transport`
```
class TestLoggerTransport implements Transport {
log(): any | Promise {
return;
}
}
````module`
```
@Module({
imports: [],
controllers: [SomeController],
providers: [
AuditLogInterceptor,
{
provide: AuditLog,
useValue: new AuditLog({
actionType: ActionType.Object,
actorType: ActorType.Eportal,
service: { type: ServiceType.App, id: 'test.service' },
objectType: ObjectType.ErudioNamespace,
}),
},
{
provide: BaseAuditLogger,
useFactory: (auditLog: AuditLog) => {
baseAuditLogger = new BaseAuditLogger(
'test.one.two',
auditLog,
new TestLoggerTransport(),
);
return baseAuditLogger;
},
inject: [AuditLog],
},
]
})
````controller`
```
@Controller('/test')
export class TestController {
@AuditLogger({
action: ActionVerb.ACCESSED,
actorIdGetter: (req) => req.headers['x-gateway-user-id'],
objectIdGetter: (req) => req.params.id,
eventSubject: 'test',
errorTypes: [NotFoundException],
})
@Get('/error/:id')
action(@Param('id') id: string) {
// do some action
// success calls will be intercepted and audit log message will be emitted
// as for errors, only NotFoudException will be intercepted and an audit log message will be emitted. All errors needed for audit log should be specified upfront
}
}
```