Typed events
Declare your action catalog once with any Standard Schema validator (valibot, zod, arktype):
record() autocompletes actions, and wrong metadata is a compile error and a runtime error.
npm install @xtandard/auditA WorkOS Audit Logs alternative as a library. record() is one call in your request handler.
Every tenant gets its own hash chain with signed checkpoints, so your customers, and their
auditors, can verify that nobody, including you, altered or deleted their history.
Typed events
Declare your action catalog once with any Standard Schema validator (valibot, zod, arktype):
record() autocompletes actions, and wrong metadata is a compile error and a runtime error.
Tamper evidence
A hash chain per tenant, sectioned digests so personal data can be erased without breaking it, and Ed25519-signed checkpoints that a zero-dependency verifier checks offline.
A customer portal
Your customers browse, filter, export and verify their own events inside your product, scoped by a signed token: no sessions, no proxy routes.
Exports & SIEM streaming
CSV, JSON and a verifiable bundle; at-least-once, per-tenant ordered streams to HTTP, Standard Webhooks, Datadog, Splunk, S3 or files. Nothing sits on the record path.
Your storage
Postgres, SQLite, libSQL, Drizzle, MongoDB, Redis, unstorage, Cloudflare KV, files or memory: a four-method KV contract plus an optional native event log for indexed queries.
Framework adapters
Mount the admin UI and API in Hono, Elysia (1 and 2), Express or Bun, and fill tenant, actor,
IP and request id for every event with one auditContext() middleware.
import { createAuditCore } from "@xtandard/audit";import { createPostgresStorage } from "@xtandard/audit/storage/postgres";
const audit = createAuditCore({ storage: createPostgresStorage({ url: process.env.DATABASE_URL! }),});
// In the handler where the thing actually happens:await audit.record({ tenant: org.id, // the customer organization action: "member.role_changed", actor: { id: user.id, name: user.name, email: user.email }, targets: [{ type: "user", id: member.id, name: member.name }], metadata: { from: "member", to: "admin" },});Synchronous-commit: record() validates, chains and appends, and throws rather than silently
dropping. A buffered createRecorder() covers fire-and-forget hot paths.
Quickstart →
import * as v from "valibot";import { createAuditCore, defineActions } from "@xtandard/audit";
const actions = defineActions({ "invoice.paid": { metadata: v.object({ invoiceId: v.string(), amount: v.number() }), targets: ["invoice"], group: "Billing", }, "member.removed": { targets: ["user"] },});
const audit = createAuditCore({ storage, actions });await audit.record({ tenant, action: "invoice.paid", // autocompletes; typos are compile errors actor, metadata: { invoiceId: "inv_1", amount: 4200 },});The catalog also feeds the admin UI’s action filter and the portal. Quickstart →
const page = await audit.query({ tenant: "acme", actions: ["invoice.*"], // families actorId: "user_1", from: "2026-01-01", search: "refund", limit: 50,});// { items, pageInfo: { hasNextPage, endCursor } }const next = await audit.query({ tenant: "acme", cursor: page.pageInfo.endCursor! });Keyset pagination, stable while new events arrive, executed natively by the SQL and MongoDB drivers. Querying →
import { verifyBundle } from "@xtandard/audit/verify";
// The customer's (or their auditor's) side: nothing but the exported bundle and Web Crypto.const report = await verifyBundle(await Bun.file("acme.audit.jsonl").text());console.log(report.ok ? `verified ${report.checked} events` : report.issues);Or xtandard-audit verify --bundle acme.jsonl from the CLI. Your side runs the same check with
await audit.verify("acme"). Tamper evidence →
// Your server, after your own auth (optionally narrowed by a view filter):const token = await createPortalToken(process.env.PORTAL_SECRET!, org.id, { filter: { excludeActions: ["support.*"] },});
// Your React frontend:import { AuditPortal } from "@xtandard/audit/react";import "@xtandard/audit/react/styles.css";
<AuditPortal apiBaseUrl="/audit" token={token} />;The WorkOS-style audit-log viewer, self-hosted and tenant-scoped. Customer portal →
import { auditPanel } from "@xtandard/audit/hono";import { datadogSink } from "@xtandard/audit/sinks/datadog";
const panel = auditPanel({ core: audit, basePath: "/audit", streams: [{ name: "datadog", sink: datadogSink({ apiKey: process.env.DD_API_KEY! }) }],});app.route("/audit", panel);Streams read the log by per-tenant sequence cursors with backoff, so a SIEM outage loses nothing. Exports & streaming →
flowchart LR
subgraph host["your app process"]
direction TB
APP["app code"] -- "record()" --> CORE["<b>core</b><br/>validate · transform<br/>hash-chain · append"]
PANEL["<b>panel</b><br/>admin UI + API + portal<br/>Hono · Elysia · Express · Bun"] --> CORE
STREAMS["<b>stream runner</b><br/>per-tenant cursors<br/>batches · backoff"] --> CORE
end
CORE <--> DB[("your database<br/>Postgres · SQLite · Mongo<br/>Redis · Drizzle · KV …")]
STREAMS -- "batches + signed checkpoints" --> SIEM["Datadog · Splunk · S3<br/>webhooks · HTTP"]
PORTAL["<AuditPortal><br/>in your product"] -- "portal token" --> PANEL
AUDITOR["customer / auditor"] -- "verify bundle" --> VERIFY["/verify<br/>zero dependencies"]
The record plane (record()) is the hot path; the control plane (query, export, verify,
checkpoints, retention, erasure) is hook-guarded, authorized and self-audited: exports and
erasures land in the tenant’s own log. Architecture →
@xtandard/audit is one of a family of open-source, MIT-licensed projects that share the xtandard
name. They are independent of each other: use any of them on its own. The products share their
building blocks through @xtandard/kit, a regular dependency you never install or configure
yourself.
| Project | What it is | Links |
|---|---|---|
@xtandard/audit (this package) |
A self-hosted, embeddable, tamper-evident audit-log control plane for B2B SaaS: a WorkOS Audit Logs alternative as a library | Docs · GitHub · npm |
@xtandard/kit |
The shared building blocks of the xtandard products: storage drivers and conformance suite, auth, HTTP plumbing, adapters, admin shell and tooling | Docs · GitHub · npm |
@xtandard/lib |
Lightweight, type-safe TypeScript utilities with a zero-dependency core | Docs · GitHub · npm |
@xtandard/flags |
A self-hosted, embeddable, OpenFeature-compatible feature-flag control plane with pluggable storage | Docs · GitHub · npm |
@xtandard/webhooks |
A self-hosted, embeddable, Standard Webhooks-compliant outbound-webhooks control plane: a Svix alternative as a library | Docs · GitHub · npm |
@xtandard/links |
Self-hosted, embeddable branded short links with click analytics, conversion attribution and deep links: a Dub / Bitly alternative as a library | Docs · GitHub · npm |
@xtandard/entitlements |
An embeddable entitlements, plans and usage-metering engine: typed catalog, atomic metering, any billing provider, admin UI and customer portal | Docs · GitHub · npm |
@xtandard/xyte |
A Zyte API-compatible /v1/extract client and server that runs on any proxy provider, or none |
Docs · GitHub · npm |
| xtandard-image | A self-hosted image and video processing server in Go and libvips: imgproxy-compatible URLs plus the imgix, Cloudinary, ImageKit, Cloudflare and Thumbor dialects, with a TypeScript client (@xtandard/image) |
Docs · GitHub · npm |
Related: drizzle-audit captures row-level changes in
Drizzle ORM and forwards them here with @xtandard/audit/drizzle-audit
(the bridge), and
drizzle-cursor is cursor-based pagination for
Drizzle. More: the xtandard ecosystem.