@ministryofjustice/hmpps-audit-client

1.0.20 • Public • Published

@ministryofjustice/hmpps-audit-client

hmpps-audit-client is a Node.js 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: '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();

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @ministryofjustice/hmpps-audit-client

Weekly Downloads

314

Version

1.0.20

License

ISC

Unpacked Size

36.9 kB

Total Files

7

Last publish

Collaborators

  • gregtyler
  • moj-igor
  • ma226860
  • hmpps-digital-prison-reporting
  • probation-integration-bot
  • jbrightonmoj
  • solidgoldpig
  • umaar
  • todderz
  • romidane
  • emileswarts
  • elena_vi
  • stevemarshall
  • adamsilver
  • asmega
  • sequencemedialimited
  • form-builder-team
  • form-builder-developers
  • simonwhatley
  • johnnolan
  • paulmassey