1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! # modo::audit
//!
//! Explicit audit logging for business-significant actions.
//!
//! Records structured events with actor, action, resource, and optional
//! metadata/client context. No automatic middleware capture — callers
//! build an [`AuditEntry`] and pass it to [`AuditLog`]. A built-in
//! SQLite backend writes to the `audit_log` table; custom backends
//! implement [`AuditLogBackend`].
//!
//! | Type | Purpose |
//! |------|---------|
//! | [`AuditEntry`] | Builder for audit events — four required fields plus optional metadata, client info, tenant |
//! | [`AuditRecord`] | Stored row returned by queries — all fields flat, includes `id` and `created_at` |
//! | [`AuditLogBackend`] | Object-safe trait for custom storage backends |
//! | [`AuditLog`] | Service wrapper — [`record()`](AuditLog::record) propagates errors, [`record_silent()`](AuditLog::record_silent) traces and swallows |
//! | [`AuditRepo`] | Query interface — [`list()`](AuditRepo::list) for all entries, [`query()`](AuditRepo::query) with [`ValidatedFilter`](crate::db::ValidatedFilter) |
//! | [`MemoryAuditBackend`] | In-memory backend for tests (requires `test-helpers` feature or `#[cfg(test)]`) |
//!
//! ## Quick start
//!
//! ```rust,no_run
//! use modo::audit::{AuditEntry, AuditLog, AuditRepo};
//! use modo::db::Database;
//!
//! # async fn example(db: Database) -> modo::Result<()> {
//! // Write
//! let audit = AuditLog::new(db.clone());
//! let entry = AuditEntry::new("user_123", "doc.deleted", "document", "doc_42")
//! .metadata(serde_json::json!({"reason": "expired"}))
//! .tenant_id("tenant_1");
//! audit.record(&entry).await?;
//!
//! // Query
//! use modo::db::CursorRequest;
//! let repo = AuditRepo::new(db);
//! let page = repo.list(CursorRequest { after: None, per_page: 20 }).await?;
//! # Ok(())
//! # }
//! ```
pub use AuditLog;
pub use MemoryAuditBackend;
pub use AuditLogBackend;
pub use AuditEntry;
pub use AuditRecord;
pub use AuditRepo;