@bpmromandie/audittrail-service-lib
v1.0.6
Published
The `audittrail-service-lib` is a TypeScript library designed to facilitate the creation, management, and retrieval of audit logs in microservices architecture. It leverages modern technologies like Axios for HTTP requests and Pino for logging, providing
Downloads
154
Keywords
Readme
AuditTrail Service Library
The audittrail-service-lib
is a TypeScript library designed to facilitate the creation, management, and retrieval of audit logs in microservices architecture. It leverages modern technologies like Axios for HTTP requests and Pino for logging, providing a robust solution for integrating audit trail capabilities into your applications.
Publishing with Scripts
This project includes scripts to facilitate building and publishing the package to a private npm registry. Below are the instructions for using these scripts.
Requirements Setup
- npm: Ensure that
npm
is installed and available in your system's PATH. - Private npm registry: If you're using a private npm registry (https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/), make sure to have the necessary authentication set up (e.g., using
.npmrc
).
.npmrc
Configuration for Private NPM Registry
Installation
.npmrc
Configuration (Recommended)
For the correct registry settings, add the following to your project's .npmrc
file:
# Use the default npm registry for public packages
registry=https://registry.npmjs.org/
# Use the private Artifactory registry for @bpmromandie scope
@bpmromandie:registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/
//bin.swisscom.com/artifactory/api/npm/kyc-npm-local/:username=YOUR_USERNAME
//bin.swisscom.com/artifactory/api/npm/kyc-npm-local/:_password=YOUR_BASE64_ENCODED_PASSWORD
//bin.swisscom.com/artifactory/api/npm/kyc-npm-local/:email=YOUR_EMAIL
This ensures that public packages are fetched from the public registry and private packages (under @bpmromandie) are fetched from your Artifactory registry.
If your project uses private npm packages (e.g., @bpmromandie
scope), you must configure .npmrc
with the correct registry and credentials. Here's an example .npmrc
file:
- Ensure you have npm installed and configured correctly on your system before running these scripts.
- The scripts will check if the necessary configurations (like .npmrc) are set for the private registry before proceeding with the build and publish steps.
- You might need to provide authentication details for accessing the private registry. This can typically be done by modifying the .npmrc file within the script or manually before running the script.
- Replace YOUR_USERNAME, YOUR_BASE64_ENCODED_PASSWORD, and YOUR_EMAIL with your actual credentials.
- Ensure .npmrc is in your project root and will be copied during the Docker build process.
Using PowerShell Script (Windows)
The publish.ps1
script automates the process of building and publishing the package to a private registry. To use this script:
- Open PowerShell as Administrator.
- Navigate to the project directory where
publish.ps1
is located. - Run the script:
.\publish.ps1
Using Shell Script (Unix/Linux/Mac)
The publish.ps1
script serves a similar purpose but is intended for use in Unix-like environments. To use this script:
- Open Terminal
- Navigate to the project directory where publish.sh is located
- mage the script executable(if not already)
chmod +x publish.sh
- Run the script
./publish.sh
Features
- Create Log Entries: Easily log audit events in your service.
- Fetch Logs: Retrieve logs based on various criteria.
- Connection Checks: Verify service connectivity.
- Configurable: Flexible initialization to suit different deployment environments.
Installation
Install audittrail-service-lib
using npm:
npm install audittrail-service-lib
Usage
Here's how to use audittrail-service-lib in your project:
Initializing the AuditTrailService
import { AuditTrailService } from 'audittrail-service-lib';
const apiUrl = 'http://localhost:6004';
const service = new AuditTrailService({baseUrl: apiUrl});
Creating a Log Entry
const logEntry = {
message: 'User login successful',
level: 'info'
};
service.createLog(logEntry)
.then(() => console.log('Log entry created'))
.catch(error => console.error('Error creating log entry', error));
Fetching Logs
service.getLogs()
.then(logs => console.log('Logs:', logs))
.catch(error => console.error('Error fetching logs', error));
API Reference
- createLog(logData): Create a new log entry.
- getLogs(): Fetch all logs.
- filterLogs(criteria): Fetch logs that meet specified criteria.
Quick local setup
- npm config set @bpmromandie:registry https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/
- npm login --scope=@bpmromandie --registry=https://bin.swisscom.com/artifactory/api/npm/kyc-npm-local/
- npm i
- modify the package version in package.json
- npm run build
- npm publish