Skip to content

Reports

Melvin PETIT edited this page Jun 22, 2026 · 2 revisions

Reports

The Reports page assembles a filterable, exportable security report from the current data. Aggregation logic lives in src/lib/reports/, orchestrated by getReportData(companyId, filters).

Report sections

getReportData runs all aggregations in parallel and returns a ReportData object with these sections:

Section Module Content
Key findings findings.ts Headline takeaways derived from the other sections
Exposure exposure.ts Overall exposure summary (employees affected, breach counts)
Data types data-types.ts Breakdown of compromised data categories
Departments departments.ts Exposure grouped by department
Employees by-employee.ts Per-employee breach breakdown
Trends trends.ts Time-series of detections
Compliance compliance.ts Compliance-oriented summary
Deltas deltas.ts Change vs. a comparison window

Each section has a matching UI component in src/components/reports/ (ExposureSection, DataTypeSection, DepartmentSection, EmployeeSection, TrendsSection, ComplianceSection, KeyFindingsSection), composed by ReportCanvas with a ReportToolbar and ReportFilterBar.

Filters

Filters are defined in reports/filters.ts (ReportFilters, with an EMPTY_FILTERS default). They scope every section consistently, since all aggregations receive the same filter object.

Comparison windows

The Deltas section compares the current period against a previous one. The window logic is in reports/windows.ts and is covered by unit tests in reports/windows.test.ts (run with npm test).

CSV export

Reports export to CSV via reports/csv.ts, exposed at:

GET /api/reports/export

The endpoint streams a CSV built from the same ReportData, honoring the active filters.

PDF rendering

Reports also render to PDF via reports/pdf.ts (reportPdf(sections, data)), built with @react-pdf/renderer. The PDF includes the selected sections and is used both for on-demand download and as an attachment on scheduled deliveries.

Scheduled delivery

A report can be emailed on a recurring schedule. The model is ReportSchedule (frequency WEEKLY or MONTHLY, a recipients list, a sections list, and an enabled flag); logic lives in src/lib/reportSchedules.ts.

runDueReportSchedules (invoked from the cron endpoint) sends every enabled schedule whose interval has elapsed, attaching both the PDF and a full-report CSV, and stamps lastSentAt only on a successful dispatch so a failure is retried next tick.

Endpoint Method Auth Description
/api/reports/schedules GET/POST ADMIN List / create schedules
/api/reports/schedules/[id] PATCH/DELETE ADMIN Update / delete a schedule

Email delivery requires the mail provider to be configured (see Configuration) and the scheduler to be driven by CRON_SECRET.

Clone this wiki locally