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

@stackone/audit

v1.11.0

Published

Audit logging client for StackOne projects. Records events to Kafka and queries them via Tinybird OLAP database.

Readme

@stackone/audit

Audit logging client for StackOne projects. Records events to Kafka and queries them via Tinybird OLAP database.

This package uses the tech stack provided by the Connect Monorepo global setup. Please check the root README for more information.

Features

  • Event Recording: Send audit events to Kafka with automatic enrichment (eventId, eventTime)
  • Event Querying: Query audit events from Tinybird with flexible filtering
  • Array Parameter Support: Filter by multiple values for organizationId, userId, action, and more
  • Type Safety: Full TypeScript support with a single AuditEvent type
  • Error Handling: Graceful error handling with detailed logging

Requirements

Please check the root README for requirements.

Installation

npm install @stackone/audit

Usage

Basic Setup

import { AuditClient } from '@stackone/audit';

const client = new AuditClient({
  kafkaClientConfig: { brokers: ['localhost:9092'] },
  olapConfig: {
    baseUrl: 'https://api.tinybird.co',
    token: process.env.TINYBIRD_TOKEN
  },
  logger: myLogger
});

await client.initialize();

Recording Events

Basic Event

await client.recordEvent({
  service: 'idp',
  organizationId: 'org-123',
  userId: 'user-456',
  action: 'user.login',
  success: true
});

Event with Details

await client.recordEvent({
  service: 'api',
  organizationId: 'org-123',
  action: 'document.created',
  details: {
    documentId: 'doc-789',
    documentType: 'invoice',
    fileSize: 1024
  }
});

Disabled Event (for testing)

await client.recordEvent(event, { enabled: false });

Querying Events

Query by Single Organization

const result = await client.queryEvents({
  organizationId: 'org-123',
  pageSize: 50
});

console.log(`Found ${result.total} events, showing page ${result.pageNumber}`);
console.log(result.events); // Array of events

Query Multiple Actions with Date Range

const result = await client.queryEvents({
  organizationId: 'org-123',
  action: ['user.login', 'user.logout'],
  startTime: new Date('2024-01-01'),
  endTime: new Date('2024-01-31'),
  pageNumber: 1,
  pageSize: 100
});

console.log(`Total matching events: ${result.total}`);
console.log(`Showing ${result.events.length} events`);

Query Multiple Organizations and Users

const result = await client.queryEvents({
  organizationId: ['org-123', 'org-456'],
  userId: ['user-1', 'user-2', 'user-3'],
  success: true
});

console.log(result.events); // Matching events
console.log(result.total);  // Total count

Query Failed Actions

const result = await client.queryEvents({
  service: 'idp',
  success: false,
  startTime: new Date(Date.now() - 24 * 60 * 60 * 1000) // Last 24 hours
});

console.log(`Found ${result.total} failures`);

API Reference

AuditClient

Main client for recording and querying audit events.

Constructor Options

  • kafkaClientConfig - Kafka broker configuration
  • olapConfig - OLAP database (Tinybird) configuration
    • baseUrl - Tinybird API base URL
    • token - Tinybird authentication token
  • logger - Logger instance for audit operations
  • getKafkaClient - Custom Kafka client builder (optional, for testing)
  • getHttpClient - Custom HTTP client builder (optional, for testing)

Methods

initialize(): Promise<void>

Initializes the audit client by connecting to Kafka. Must be called before recording events.

recordEvent(event: AuditEvent, options?: AuditOptions): Promise<void>

Records an audit event to Kafka. The event is automatically enriched with eventId and eventTime.

Event Fields:

  • service (required) - Name of the service generating the event
  • organizationId (optional) - Organization identifier
  • userId (optional) - User identifier
  • action (optional) - Action identifier (e.g., 'user.login', 'document.created')
  • subAction (optional) - Sub-action identifier
  • success (optional) - Whether the action was successful
  • details (optional) - Additional event metadata
  • eventTime (optional) - Timestamp of the event (defaults to now)

Options:

  • enabled (default: true) - Whether to actually send the event
queryEvents(query: AuditQuery): Promise<AuditQueryResult>

Queries audit events from the OLAP database. Returns events that match ALL specified filters (AND logic).

Query Filters:

  • service - Filter by service name(s) (string or string[])
  • organizationId - Filter by organization ID(s) (string or string[])
  • userId - Filter by user ID(s) (string or string[])
  • action - Filter by action(s) (string or string[])
  • subAction - Filter by sub-action(s) (string or string[])
  • success - Filter by success status (boolean)
  • startTime - Filter events after this timestamp (inclusive)
  • endTime - Filter events before this timestamp (inclusive)
  • pageNumber - Page number for pagination (1-indexed)
  • pageSize - Number of events per page

Returns: AuditQueryResult containing:

  • events - Array of matching audit events
  • total - Total count of matching events (before pagination)
  • pageNumber - Current page number
  • pageSize - Number of events per page

Throws:

  • Error if HTTP client is not configured or OLAP token is missing
  • ZodError if the response fails schema validation

AuditEvent

Type representing an audit event.

type AuditEvent = {
  eventId?: string;
  service: string;
  organizationId?: string;
  userId?: string;
  action?: string;
  subAction?: string;
  success?: boolean;
  details?: Record<string, unknown>;
  eventTime?: Date;
};

AuditQueryResult

Type representing the result of a query operation.

type AuditQueryResult = {
  events: AuditEvent[];
  total: number;
  pageNumber: number;
  pageSize: number;
};

Available commands

# clean build output
$ npm run clean
# build package
$ npm run build
# run tests
$ npm run test
# run tests on watch mode
$ npm run test:watch
# run linter
$ npm run lint
# run linter and try to fix any error
$ npm run lint:fix