Export Download Service
Component Detail
Service Layer
medium complexity
backend
2
Dependencies
1
Dependents
1
Entities
0
Integrations
Description
Next.js API route that retrieves the finalized bufdir_exports record and streams it as a downloadable file in the format accepted by Bufdir (CSV or XLSX). Enforces the export_status flag to prevent re-export without explicit unlock, and writes every export event to audit_logs with full provenance metadata.
export-download-service
Sources & reasoning
The blueprint mandates this component. It is the core of the feature - handling secure file streaming, enforcing the re-export lock, and writing the audit trail that gives Org Admins documented proof of what version was submitted to Bufdir.
No source references — this artifact was included based on reasoning alone (see above).
Responsibilities
- Retrieve finalized report record from bufdir_exports by report ID
- Stream file response as downloadable CSV or XLSX
- Enforce export_status flag and reject re-export of already-submitted reports
- Write export event to audit_logs with user ID, timestamp, organization ID, and report reference
- Update export_status on bufdir_exports after successful download
Interfaces
GET /api/v1/bufdir-exports/:id/download
POST /api/v1/bufdir-exports/:id/unlock
streamFile(reportId: string, format: 'csv' | 'xlsx'): ReadableStream
recordExportAuditEvent(userId: string, orgId: string, reportId: string): Promise<void>
checkExportStatus(reportId: string): ExportStatus
Relationships
Dependencies (2)
Components this component depends on