CSV / JSON File Generator
Component Detail
Description
Utility that converts structured export records into a downloadable CSV or JSON file. Handles encoding, column ordering, header row generation, and proper escaping of special characters. Writes the generated file to Supabase Storage for secure, temporary access via signed URL.
csv-json-file-generator
Summaries
This shared utility component directly enables the data portability that accounting teams and coordinators depend on to integrate activity data into their existing financial workflows. By producing standards-compliant CSV and JSON files, it ensures that exported records can be imported without friction into any spreadsheet tool, accounting platform, or reporting system — eliminating manual data re-entry that wastes staff time and introduces errors. As a shared component used across multiple export features, it reduces development cost by providing a single, well-tested implementation instead of duplicating file generation logic. The reliable encoding and escaping behavior ensures data integrity is preserved across character sets and special characters, protecting against corrupted imports that could undermine financial reporting accuracy.
This is a medium-complexity, shared utility component with no external dependencies, making it one of the lower-risk items on the export pipeline's critical path. It can be developed and unit tested in isolation before the broader export pipeline is integrated. Because it is shared across multiple export features, it should be prioritized early in the sprint cycle to unblock parallel feature development. Key deliverables include RFC 4180 CSV compliance verification, JSON serialization tests with edge-case characters, Supabase Storage write integration, and signed URL path return validation.
The `buildFileName()` function must align with the naming convention expected by the signed URL generation logic upstream. Regression testing should cover large record sets to validate memory efficiency of `Uint8List` output. Minimal deployment risk given no third-party API dependencies.
This utility component provides four primary interfaces: `generateCsv(records, headers): Uint8List` and `generateJson(records): Uint8List` for serialization, `writeToStorage(fileBytes, path, orgId): string` for persisting output to the Supabase Storage bucket, and `buildFileName(orgId, exportRunId, format): string` for deterministic file naming. CSV generation must comply with RFC 4180 — handle comma-containing fields with double-quote wrapping, escape embedded double quotes as `""`, and enforce CRLF line endings. JSON output should be compact (no pretty-printing) to minimize file size. Storage writes target a private bucket with TTL-based expiry; the returned storage path is consumed by the upstream edge function to generate a signed download URL.
As a shared component, keep it stateless and side-effect-free except for the explicit storage write. Avoid importing platform-specific libraries to maintain testability outside the Edge Function runtime.
Responsibilities
- Serialize export record arrays to RFC 4180 compliant CSV
- Serialize export record arrays to compact JSON
- Write output file to Supabase Storage bucket with expiry
- Return storage path for signed URL generation
Interfaces
generateCsv(records, headers): Uint8List
generateJson(records): Uint8List
writeToStorage(fileBytes, path, orgId): string
buildFileName(orgId, exportRunId, format): string
Relationships
Dependents (2)
Components that depend on this component