@ministryofjustice/hmpps-audit-client
v1.1.1
Published
Read [this Confluence page](https://dsdmoj.atlassian.net/wiki/spaces/HAA/pages/4598071684/How+to+integrate+with+the+HMPPS+Audit+service) for the full breakdown of this project.
Downloads
694
Maintainers
Keywords
Readme
@ministryofjustice/hmpps-audit-client
Read this Confluence page for the full breakdown of this project.
hmpps-audit-client
is a Typescript client library designed to simplify the process of publishing audit events in your
HMPPS projects. It provides an AuditService
class that interfaces with AWS SQS (Simple Queue Service) to send audit
messages asynchronously.
Installation
To install the package, run the following command in your project directory:
npm install @ministryofjustice/hmpps-audit-client
Usage
Here's a quick example of how to use hmpps-audit-client:
import { auditService } from 'hmpps-audit-client';
async function sendAuditEvent() {
try {
await auditService.sendAuditMessage({
action: 'DELETE_USER',
who: '[email protected]',
subjectId: '123',
subjectType: 'USER_ID',
service: 'hmpps-audit-poc-ui',
details: "{ 'deletionSuccessful': true }",
// Additional parameters are optional
});
console.log('Audit event sent successfully');
} catch (error) {
console.error('Error sending audit event:', error);
}
}
sendAuditEvent();
API
The sendAuditMessage method accepts an object with the following properties:
- action (string): The action being audited. This should be capitalised with underscore separators e.g. VIEW_DPS_USER
- who (string): Identifier of the user or entity performing the action.
- subjectId (optional string): Identifier of the subject of the action e.g. which user is being viewed.
- subjectType (optional string): Type of the subject (e.g., 'USER_ID').
- correlationId (optional string): Correlation ID for the event. This is useful for linking multiple audit events to each other.
- service (string): the service that produced this event e.g. 'hmpps-manage-users'.
- details (optional string): Additional details about the event. This must be a JSON string, as per the example.
- logErrors (optional boolean, defaults to true): Whether to log errors to the console.
Configuration
Have a look at hmpps-audit-poc-ui for a minimal setup for this project.
Contributing
Contributions to @ministryofjustice/hmpps-audit-client
are welcome. Please ensure that your code adheres to the
existing style and that all tests pass.