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.
To install the package, run the following command in your project directory:
npm install @ministryofjustice/hmpps-audit-client
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: 'userWhoCarriedOutDelete@example.com',
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();
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.
Have a look at hmpps-audit-poc-ui for a minimal setup for this project.
Contributions to @ministryofjustice/hmpps-audit-client
are welcome. Please ensure that your code adheres to the
existing style and that all tests pass.