npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mohmk10/audit-trail-sdk

v1.0.1

Published

Official JavaScript/TypeScript SDK for Audit Trail Universal

Readme

Audit Trail SDK for JavaScript/TypeScript

Official JavaScript/TypeScript SDK for Audit Trail Universal.

Installation

npm install @mohmk10/audit-trail-sdk

Quick Start

import {
  AuditTrailClient,
  ActorBuilder,
  ActionBuilder,
  ResourceBuilder,
  MetadataBuilder,
  EventBuilder
} from '@mohmk10/audit-trail-sdk';

// Create client
const client = AuditTrailClient.builder()
  .serverUrl('https://audit.example.com')
  .apiKey('your-api-key')
  .build();

// Log an event
const response = await client.log(
  new EventBuilder()
    .actor(ActorBuilder.user('user-123', 'John Doe'))
    .action(ActionBuilder.create('Created document'))
    .resource(ResourceBuilder.document('doc-456', 'Q4 Report'))
    .metadata(new MetadataBuilder()
      .source('web-app')
      .tenantId('tenant-001')
      .build())
    .build()
);

console.log('Event logged:', response.id);

Features

  • TypeScript support with full type definitions
  • Browser and Node.js compatible
  • Fluent builder API
  • Automatic retry with exponential backoff
  • Batch event logging
  • Search capabilities

API Reference

Client Configuration

const client = AuditTrailClient.builder()
  .serverUrl('http://localhost:8080')  // Required
  .apiKey('your-api-key')              // Optional
  .timeout(30000)                      // Default: 30000ms
  .retryAttempts(3)                    // Default: 3
  .retryDelay(1000)                    // Default: 1000ms
  .headers({ 'X-Custom': 'value' })    // Optional custom headers
  .build();

Logging Events

Single Event

const response = await client.log(event);
// Response: { id, timestamp, hash, status }

Batch Events

const response = await client.logBatch([event1, event2, event3]);
// Response: { total, succeeded, failed, events, errors? }

Building Events

Actor Types

// Factory methods
const user = ActorBuilder.user('user-123', 'John Doe');
const system = ActorBuilder.system('cron-job');
const service = ActorBuilder.service('payment-svc', 'Payment Service');

// Builder pattern
const actor = new ActorBuilder()
  .id('user-123')
  .type('USER')
  .name('John Doe')
  .ip('192.168.1.1')
  .userAgent('Mozilla/5.0...')
  .attributes({ department: 'IT' })
  .build();

Action Types

// Factory methods
const create = ActionBuilder.create('Created resource');
const read = ActionBuilder.read('Viewed resource');
const update = ActionBuilder.update('Modified resource');
const del = ActionBuilder.delete('Removed resource');
const login = ActionBuilder.login();
const logout = ActionBuilder.logout();

// Builder pattern
const action = new ActionBuilder()
  .type('CUSTOM_ACTION')
  .description('Custom action description')
  .category('SECURITY')
  .build();

Resource Types

// Factory methods
const doc = ResourceBuilder.document('doc-123', 'Report');
const user = ResourceBuilder.user('user-456', 'John');
const txn = ResourceBuilder.transaction('txn-789', 'Payment');
const custom = ResourceBuilder.of('id', 'CUSTOM_TYPE', 'Name');

// With before/after state
const resource = new ResourceBuilder()
  .id('user-123')
  .type('USER')
  .name('User Profile')
  .before({ status: 'active' })
  .after({ status: 'inactive' })
  .build();

Metadata

const metadata = new MetadataBuilder()
  .source('web-app')           // Required
  .tenantId('tenant-001')      // Required
  .correlationId('corr-123')   // Optional
  .sessionId('sess-456')       // Optional
  .tags({ env: 'production' }) // Optional
  .extra({ custom: 'data' })   // Optional
  .build();

Searching Events

Advanced Search

const result = await client.search({
  tenantId: 'tenant-001',      // Required
  actorId: 'user-123',         // Optional
  actorType: 'USER',           // Optional
  actionType: 'CREATE',        // Optional
  resourceId: 'doc-456',       // Optional
  resourceType: 'DOCUMENT',    // Optional
  fromDate: '2024-01-01',      // Optional
  toDate: '2024-12-31',        // Optional
  query: 'search term',        // Optional
  page: 0,                     // Optional, default: 0
  size: 20                     // Optional, default: 20
});

// Result: { items, totalCount, page, size, totalPages }

Quick Search

const result = await client.quickSearch('search term', 'tenant-001', 0, 20);

Retrieving Events

const event = await client.getById('event-id');
// Returns null if not found

Error Handling

import {
  AuditTrailError,
  AuditTrailConnectionError,
  AuditTrailApiError,
  AuditTrailValidationError
} from '@mohmk10/audit-trail-sdk';

try {
  await client.log(event);
} catch (error) {
  if (error instanceof AuditTrailConnectionError) {
    console.error('Connection failed:', error.message);
  } else if (error instanceof AuditTrailApiError) {
    console.error('API error:', error.statusCode, error.body);
  } else if (error instanceof AuditTrailValidationError) {
    console.error('Validation errors:', error.violations);
  }
}

Browser Usage

The SDK works in modern browsers that support the Fetch API:

<script type="module">
  import { AuditTrailClient, ActorBuilder, ActionBuilder, ResourceBuilder, MetadataBuilder, EventBuilder }
    from 'https://unpkg.com/@mohmk10/audit-trail-sdk/dist/index.mjs';

  const client = AuditTrailClient.builder()
    .serverUrl('https://audit.example.com')
    .build();
</script>

License

MIT