Audit API
⚡ 5 min readThe trackUserAction() method records actions for audit logs (method name is fixed; tag identifies the event). Use it for sensitive operations, compliance, and activity trails
trackUserAction()
Records a user action for audit logging. Supports severity levels, success/failure status, and optional metadata
transcodes.trackUserAction(
event: {
tag: string;
severity?: 'low' | 'medium' | 'high';
status?: boolean;
error?: string;
metadata?: Record<string, unknown>;
},
options?: {
requireAuth?: boolean;
webhookNotification?: boolean;
}
): Promise<void>Event Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tag | string | Yes | Tag identifying the action (e.g., ‘user:login’, ‘document:create’) |
severity | 'low' | 'medium' | 'high' | No | Severity level. Default: 'low' |
status | boolean | No | Success/failure. Default: true |
error | string | No | Error message when status: false |
metadata | Record<string, unknown> | No | Additional metadata (e.g., { method: 'passkey' }) |
Options
| Parameter | Type | Required | Description |
|---|---|---|---|
requireAuth | boolean | No | If true, opens login modal when user not authenticated. Default: false |
webhookNotification | boolean | No | Send Slack webhook regardless of severity. Default: false |
Examples
Basic usage
await transcodes.trackUserAction({
tag: 'user:login',
metadata: { method: 'passkey' },
});With severity and status
await transcodes.trackUserAction({
tag: 'document:delete',
severity: 'high',
status: true,
metadata: { documentId: 'doc_123' },
});Failed action with error
await transcodes.trackUserAction(
{
tag: 'payment:process',
severity: 'high',
status: false,
error: 'Payment gateway timeout',
metadata: { amount: 99.99 },
},
{ webhookNotification: true }
);Require authentication
// Opens login modal if user not authenticated
await transcodes.trackUserAction(
{ tag: 'sensitive:action', severity: 'medium' },
{ requireAuth: true }
);Common Tags
| Tag Pattern | Example Use Case |
|---|---|
user:login | Member login event (example tag) |
user:register | New member registration (example) |
user:logout | Member sign-out (example tag) |
document:create | Document created |
document:delete | Document deleted |
payment:* | Payment-related actions |
Related
Last updated on