Audit Log
Application activity records
git clone https://github.com/bijectionhq/audit-log.git
cd audit-log
git checkout b067f6d062cfa6831c0b7ae7ae1dbdf11e6746d7Bijection repository access is required. Request access.
Description
Application activity records
Explore the package README for API concepts, configuration, and examples. Check the Bijection source for adaptation-specific setup.
Review the source and its dependencies before adopting this package. Source availability does not establish npm publication or runtime qualification.
Getting started
- Get the source at the revision above and read its package documentation.
- Check the required Bijection SDK version, dependencies, and external service credentials.
- Follow the package setup instructions and the guide to using components.
- Exercise the component in your deployment according to your project’s verification rules.
Open source
Maintained source: bijectionhq/audit-log. Based on robertalv/audit-log. License: Apache-2.0. Consult the repository for license terms, notices, and contributor attribution.
From the upstream publisher
A comprehensive audit logging component for Convex - track user actions, API calls, and system events with built-in compliance features.
Explore the demo ↗Upstream overview
From the upstream package documentation.
The Convex Audit Log component provides comprehensive event tracking and change logging for Convex applications with built-in compliance features. It automatically captures who, what, when, and where for any action, tracks before/after states with diff generation, and includes PII redaction capabilities. The component offers flexible querying, real-time monitoring, anomaly detection, and pre-built React hooks for common audit log UI patterns.
Use cases
From the upstream package documentation.
- Track user actions and system changes for regulatory compliance (SOC 2, GDPR, HIPAA) by logging authentication events, profile updates, and data modifications with automatic before/after state capture
- Monitor security incidents by detecting failed login attempts, unauthorized access patterns, and suspicious activity with configurable thresholds and real-time alerts
- Debug production issues by maintaining a searchable history of API calls, database changes, and system events with severity levels and metadata filtering
- Generate compliance reports for auditors by exporting filtered audit logs as CSV or JSON with customizable retention policies and automatic cleanup
- Build admin dashboards with real-time event monitoring using pre-built React hooks for displaying document history, user activity, and system statistics
How it works
From the upstream package documentation.
The component integrates into your Convex app through convex.config.ts and provides an AuditLog class that wraps the component API. You create an audit log client in your backend functions and call methods like log() for single events, logChange() for before/after tracking with automatic diff generation, and logBulk() for batch operations.
Query methods include queryByResource() for document history, queryByActor() for user activity, and search() with advanced filtering by severity, timestamp, and tags. The component provides real-time monitoring through watchCritical() and analytics via getStats() and detectAnomalies() for identifying unusual event patterns.
Built-in privacy controls automatically redact PII fields specified in the configuration, while the retention system uses cleanup() to remove old logs based on configurable policies. React integration comes through hooks like useAuditLogByResource() and utility functions for formatting timestamps and styling severity levels.
Upstream package FAQ
Does Convex Audit Log impact application performance?
Convex Audit Log is designed for minimal performance impact with asynchronous logging and batched writes. It leverages Convex's built-in reactivity system and only processes events that match your configured rules, avoiding unnecessary overhead.
Can I customize what data gets logged and redacted?
Yes, Convex Audit Log provides flexible configuration for event filtering and PII redaction rules. You can specify which fields to log, what to redact based on patterns or field names, and set different policies for different event types.
How do I query historical audit logs efficiently?
Convex Audit Log includes optimized database indexes and query helpers for common patterns like filtering by actor, resource, time range, or event type. The component provides React hooks that handle pagination and real-time updates automatically.
What happens to audit logs when data retention policies expire?
Convex Audit Log automatically handles cleanup based on your retention policies while maintaining referential integrity. You can configure different retention periods for different event types and export logs before deletion for long-term archival.
Can I integrate audit logs with external monitoring systems?
Convex Audit Log supports exporting logs in JSON and CSV formats, and provides webhooks for real-time event streaming. You can easily integrate with external SIEM systems, monitoring tools, or compliance platforms using the structured export APIs.
Use with agents and CLI
Give your coding agent the component’s source identity and setup guidance.
Help me integrate Audit Log with Bijection.
Read: https://bijection.com/components/audit-log/SKILL.md
Check SDK compatibility and dependency availability.
Follow this project's execution and verification rules.Upstream README.md
View repository ↗Documentation from robertalv/audit-log, recorded October 23, 2026. APIs and setup may differ in the Bijection adaptation.
Convex Audit Log Component
A comprehensive audit logging component for Convex that helps you track user actions, API calls, and system events with built-in compliance features.
Features
- Automatic Event Capture - Log who, what, when, and where for any action
- Change Tracking - Record before/after states with automatic diff generation
- PII Redaction - Built-in privacy controls for sensitive data
- Flexible Querying - Query by actor, resource, severity, time range, and more
- Real-time Monitoring - Subscribe to critical events as they happen
- Anomaly Detection - Detect unusual patterns in event frequency
- Report Generation - Export audit logs as JSON or CSV
- Configurable Retention - Automatic cleanup with customizable policies
- React Hooks - Pre-built hooks for common UI patterns
Installation
npm install convex-audit-log
Create a convex.config.ts file in your app's convex/ folder and install the component:
// convex/convex.config.ts
import { defineApp } from "convex/server";
import auditLog from "convex-audit-log/convex.config.js";
const app = defineApp();
app.use(auditLog);
export default app;
Quick Start
1. Create an AuditLog Client
// convex/auditLog.ts
import { AuditLog } from "convex-audit-log";
import { components } from "./_generated/api";
export const auditLog = new AuditLog(components.auditLog, {
// Optional: Configure PII fields to automatically redact
piiFields: ["email", "phone", "ssn", "password"],
});
2. Log Events in Your Mutations
import { mutation } from "./_generated/server";
import { auditLog } from "./auditLog";
export const updateUserProfile = mutation({
args: { userId: v.id("users"), name: v.string(), email: v.string() },
handler: async (ctx, args) => {
// Get current state
const before = await ctx.db.get(args.userId);
// Perform the update
await ctx.db.patch(args.userId, { name: args.name, email: args.email });
// Get new state
const after = await ctx.db.get(args.userId);
// Log the change with automatic diff
await auditLog.logChange(ctx, {
action: "user.profile.updated",
actorId: ctx.auth.getUserIdentity()?.subject,
resourceType: "users",
resourceId: args.userId,
before,
after,
generateDiff: true,
severity: "info",
});
return after;
},
});
3. Query Audit Logs
import { query } from "./_generated/server";
import { auditLog } from "./auditLog";
// Get all changes to a specific document
export const getDocumentHistory = query({
args: { documentId: v.string() },
handler: async (ctx, args) => {
return await auditLog.queryByResource(ctx, {
resourceType: "documents",
resourceId: args.documentId,
limit: 50,
});
},
});
// Get all actions by a specific user
export const getUserActivity = query({
args: { userId: v.string() },
handler: async (ctx, args) => {
return await auditLog.queryByActor(ctx, {
actorId: args.userId,
limit: 50,
});
},
});
// Watch for critical security events
export const watchSecurityEvents = query({
handler: async (ctx) => {
return await auditLog.watchCritical(ctx, {
severity: ["warning", "error", "critical"],
limit: 20,
});
},
});
API Reference
Severity Levels
| Level | Description |
|---|---|
info | Regular operations (login, profile update) |
warning | Potentially concerning actions (password change, permission change) |
error | Failed operations or errors |
critical | Security-sensitive events (unauthorized access, data breaches) |
Core Methods
log(ctx, event)
Log a single audit event.
await auditLog.log(ctx, {
action: "user.login",
actorId: userId,
severity: "info",
metadata: { method: "password" },
tags: ["authentication"],
});
logChange(ctx, event)
Log a change event with before/after states.
await auditLog.logChange(ctx, {
action: "document.updated",
actorId: userId,
resourceType: "documents",
resourceId: docId,
before: { title: "Old Title" },
after: { title: "New Title" },
generateDiff: true, // Automatically generate diff
severity: "info",
});
logBulk(ctx, events)
Log multiple events in a single transaction.
await auditLog.logBulk(ctx, [
{ action: "document.created", severity: "info", ... },
{ action: "notification.sent", severity: "info", ... },
]);
Query Methods
queryByResource(ctx, args)
Query logs for a specific resource.
const history = await auditLog.queryByResource(ctx, {
resourceType: "documents",
resourceId: docId,
limit: 50,
fromTimestamp: Date.now() - 7 * 24 * 60 * 60 * 1000, // Last 7 days
});
queryByActor(ctx, args)
Query logs for a specific actor.
const activity = await auditLog.queryByActor(ctx, {
actorId: userId,
limit: 50,
actions: ["user.login", "user.logout"], // Optional filter
});
search(ctx, args)
Advanced search with multiple filters.
const results = await auditLog.search(ctx, {
filters: {
severity: ["warning", "error", "critical"],
actions: ["user.login.failed"],
fromTimestamp: Date.now() - 24 * 60 * 60 * 1000,
tags: ["security"],
},
pagination: { limit: 100 },
});
watchCritical(ctx, args)
Subscribe to critical events in real-time.
const criticalEvents = await auditLog.watchCritical(ctx, {
severity: ["error", "critical"],
limit: 20,
});
Analytics Methods
getStats(ctx, args)
Get statistics for audit logs.
const stats = await auditLog.getStats(ctx, {
fromTimestamp: Date.now() - 24 * 60 * 60 * 1000,
});
// Returns: { totalCount, bySeverity, topActions, topActors }
detectAnomalies(ctx, patterns)
Detect anomalies based on event frequency.
const anomalies = await auditLog.detectAnomalies(ctx, [
{ action: "user.login.failed", threshold: 5, windowMinutes: 5 },
{ action: "record.deleted", threshold: 50, windowMinutes: 60 },
]);
generateReport(ctx, args)
Generate a compliance report.
const report = await auditLog.generateReport(ctx, {
startDate: startOfMonth,
endDate: endOfMonth,
format: "csv", // or "json"
includeFields: ["timestamp", "action", "actorId", "resourceType"],
groupBy: "action",
});
Maintenance Methods
cleanup(ctx, options)
Clean up old audit logs based on retention policies.
const deletedCount = await auditLog.cleanup(ctx, {
olderThanDays: 90,
preserveSeverity: ["critical"], // Keep critical events forever
batchSize: 100,
});
React Hooks
import {
useAuditLogByResource,
useWatchCriticalEvents,
useAuditLogStats,
formatTimestamp,
getSeverityColor,
} from "convex-audit-log/react";
import { api } from "../convex/_generated/api";
function DocumentHistory({ documentId }: { documentId: string }) {
const logs = useAuditLogByResource(api.auditLog.queryByResource, {
resourceType: "documents",
resourceId: documentId,
limit: 20,
});
if (!logs) return <div>Loading...</div>;
return (
<ul>
{logs.map((log) => (
<li key={log._id} style={{ borderLeftColor: getSeverityColor(log.severity) }}>
<strong>{log.action}</strong>
<span>{formatTimestamp(log.timestamp)}</span>
</li>
))}
</ul>
);
}
Pre-defined Action Constants
Use the provided action constants for consistency:
import { AuditActions } from "convex-audit-log";
await auditLog.log(ctx, {
action: AuditActions.USER_LOGIN,
// ...
});
Available actions:
USER_LOGIN,USER_LOGIN_FAILED,USER_LOGOUT,USER_SIGNUPPASSWORD_CHANGED,PASSWORD_RESET_REQUESTED,PASSWORD_RESET_COMPLETEDMFA_ENABLED,MFA_DISABLEDUSER_CREATED,USER_UPDATED,USER_DELETEDUSER_ROLE_CHANGED,USER_PERMISSIONS_CHANGEDRECORD_CREATED,RECORD_UPDATED,RECORD_DELETED,RECORD_VIEWED,RECORD_EXPORTEDSETTINGS_CHANGED,API_KEY_CREATED,API_KEY_REVOKEDUNAUTHORIZED_ACCESS,SUSPICIOUS_ACTIVITY,RATE_LIMIT_EXCEEDED
Exposing API to React Clients
// convex/auditLog.ts
import { exposeAuditLogApi } from "convex-audit-log";
import { components } from "./_generated/api";
export const {
queryByResource,
queryByActor,
getStats,
watchCritical,
} = exposeAuditLogApi(components.auditLog, {
auth: async (ctx, operation) => {
const userId = await getAuthUserId(ctx);
if (!userId && operation.type !== "read") {
throw new Error("Unauthorized");
}
return userId;
},
});
Testing
import { test } from "vitest";
import { convexTest } from "convex-test";
import auditLogComponent from "convex-audit-log/test";
import schema from "./schema";
test("audit logging", async () => {
const t = convexTest(schema);
auditLogComponent.register(t);
await t.run(async (ctx) => {
// Test your audit log functionality
});
});
Example App
Run the example app to see the component in action:
npm install
npm run dev
The example app includes:
- Event generation demo
- Real-time log viewer
- Analytics dashboard with statistics
- Anomaly detection monitoring
Contributing
See CONTRIBUTING.md for development instructions.
License
Apache-2.0