* feat: event log, pending operations, and MCP staging - Event log system: persist bus events to event_log table for external automation platforms. Batch insert for transaction.synced. Daily cleanup cron at 02:00 UTC. - Pending operations: MCP write tools (categorize, create customer, create invoice) now stage to pending_operations instead of executing directly. Users review and commit/reject from /pending in the web UI. - Granskning page: card-based review UI with expandable previews, commit/reject dialogs. Only shown in nav when pending ops exist. - Commit route re-executes using core lib functions (no extension imports). Guards against stale state (double-commit, deleted entities). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: stage new MCP write tools after main merge Add staging for 4 new write tools from #133: - mark_invoice_paid, send_invoice, mark_invoice_sent, match_transaction_invoice - Expand pending_operations CHECK constraint - Add commit executors with full execution logic - Add UI labels and generic preview component - Remove confirm parameter from categorize (single-call staging) - Fix UUID in pending op title (fetch transaction description) - Hide Granskning nav when no pending ops Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address PR review feedback - Fix TS build error: use `select('*, customer:customers(*)')` for match_transaction_invoice to avoid array type inference - Add status guard to commitSendInvoice (prevents duplicate sends) - Replace auth.admin.getUserById with user email from session auth - Restore optimistic lock check in commitMatchTransactionInvoice - Fix tool description typo: expense_software → expense_office Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { createServiceClient } from '@/lib/supabase/server'
|
|
import { NextResponse } from 'next/server'
|
|
|
|
/**
|
|
* GET /api/events/cleanup/cron
|
|
* Daily cron job to delete event_log rows older than 30 days.
|
|
* Runs at 02:00 UTC every day.
|
|
*/
|
|
export async function GET(request: Request) {
|
|
const authHeader = request.headers.get('authorization')
|
|
const cronSecret = process.env.CRON_SECRET
|
|
|
|
if (!cronSecret || authHeader !== `Bearer ${cronSecret}`) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
try {
|
|
const supabase = await createServiceClient()
|
|
|
|
const cutoff = new Date()
|
|
cutoff.setDate(cutoff.getDate() - 30)
|
|
|
|
const { error, count } = await supabase
|
|
.from('event_log')
|
|
.delete({ count: 'exact' })
|
|
.lt('created_at', cutoff.toISOString())
|
|
|
|
if (error) throw error
|
|
|
|
const deleted = count ?? 0
|
|
console.log(`Event log cleanup completed: ${deleted} events removed`)
|
|
|
|
return NextResponse.json({ success: true, deleted })
|
|
} catch (error) {
|
|
console.error('Error in event log cleanup cron:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to clean up event log' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|