Skip to content

feat: Audit logs#500

Draft
sidwebworks wants to merge 11 commits intomainfrom
sid/audit-logs
Draft

feat: Audit logs#500
sidwebworks wants to merge 11 commits intomainfrom
sid/audit-logs

Conversation

@sidwebworks
Copy link
Member

@sidwebworks sidwebworks commented Feb 12, 2026

What does this PR do?

Adds a complete per-company audit log system that tracks INSERT, UPDATE, and DELETE operations on key business entities. Users can view change history globally from Settings or per-entity via an "Audit History" button in each entity's header dropdown. Also includes a few unrelated bug fixes.
Audit log core

  • Per-company audit tables (auditLog_{companyId}) with RLS, created via RPC functions
  • Captures actor ID, operation type, entity info, and a structured diff of old vs new values
  • Distinct tableName (database table) and entityType (semantic UI label) so multiple tables can map to the same entity type (e.g. itemCostitem)
  • Automatic archiving: logs older than the retention period are archived to storage and downloadable from Settings
    Audit event processing
  • New Trigger.dev task processes audit events from the event system
  • Scheduled archive task for compressing and storing old logs
    ERP UI
  • AuditLogDrawer — entity-level audit history in a slide-over drawer
  • AuditLogTable — global audit log with expandable rows showing colored diffs, clickable entity links, and actor avatars
  • AuditLogSettings — enable/disable audit logging, view/download archives
  • Audit history integrated into all entity headers: Customer, Supplier, Part, Tool, Material, Consumable, Job, Quote, Sales Order, Purchase Order, Sales Invoice, Purchase Invoice, Person
  • Table component now supports renderExpandedRow for row expansion
    Bug fixes
  • Fix collapsible sidebar not re-opening when returning to desktop from mobile
  • Transparent background for address autocomplete input
  • Fix date formatting locale to en-US

Visual Demo (For contributors especially)

Video Demo (if applicable):

  • N/A — internal PR

Image Demo (if applicable):

image

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. Enable audit logging: Go to Settings → Audit Logs, toggle the feature on. This creates the per-company audit table and attaches event triggers.
  2. Generate audit entries: Make changes to any auditable entity (create/update/delete a Customer, Supplier, Part, Order, etc.)
  3. Global audit log: Navigate to Settings → Audit Logs and verify entries appear in the table. Expand a row to see the colored diff. Click entity IDs to navigate to the entity. Filter by entity type, actor, or operation.
  4. Entity-level audit: Open any entity (e.g. a Customer), click the dropdown menu in the header, and select "Audit History". Verify the drawer opens with that entity's change history.
  5. Sidebar fix: Resize the browser below 768px (mobile), then resize back above 768px. Verify the secondary sidebar re-opens on pages that have one (e.g. any list page in the ERP).
  6. Archive download: If logs older than the retention period exist, verify they appear in the Archives section of Settings → Audit Logs and can be downloaded.
    Environment: No new environment variables required. Requires running the new migrations.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have checked that my changes generate no new warnings

@vercel
Copy link

vercel bot commented Feb 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
academy Ready Ready Preview, Comment Feb 16, 2026 8:09pm
carbon Ready Ready Preview, Comment Feb 16, 2026 8:09pm
mes Ready Ready Preview, Comment Feb 16, 2026 8:09pm

Request Review

sidwebworks and others added 5 commits February 13, 2026 21:35
- Add per-company audit log tables (auditLog_{companyId}) with RPC functions
- Capture INSERT, UPDATE, DELETE operations on key entities (item, itemCost,
  purchaseInvoice, salesInvoice, purchaseOrder, salesOrder, customer, supplier,
  job, quote, employee)
- Store actor ID (from auth.uid()), operation type, entity info, and diff of changes
- Add audit.config.ts for configuration and audit.types.ts for type definitions
- Add audit task handler in Trigger.dev for processing audit events
- Update event system to capture actorId and support dynamic primary keys
- Add global audit log view in Settings with expandable rows showing colored diffs
- Add Table component renderExpandedRow prop for row expansion support
- Add AuditLogDrawer component for entity-level audit history
- Integrate audit log drawer into entity headers (Customer, Supplier, Item, etc.)
Add audit history button to dropdown menus for all item types,
allowing users to view change history for tools, materials, and consumables.
- Entity IDs are now clickable links based on ID prefix (e.g. item_, po_, cust_)
- Actor avatars link to the employee account page
- Entity labels use domain-prefixed names (e.g. Inventory Item, Sales Order)
Introduce distinct tableName and entityType concepts so multiple tables
can map to the same semantic entity type. Use service role for archive
queries to bypass RLS and fix locale to en-US for date formatting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants