feat(ens): support PDF reporting (#9158)

Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
This commit is contained in:
Pedro Martín
2025-11-19 18:57:58 +01:00
committed by GitHub
parent 219bc12365
commit 94fe87b4a2
20 changed files with 3221 additions and 745 deletions

View File

@@ -0,0 +1,71 @@
/**
* Compliance Report Type Constants
*
* This file defines the available compliance report types and their metadata.
* When adding new compliance PDF reports, add entries here to maintain consistency.
*/
/**
* Available compliance report types
* Add new report types here as they become available
*/
export const COMPLIANCE_REPORT_TYPES = {
THREATSCORE: "threatscore",
ENS: "ens",
// Future report types can be added here:
// CIS: "cis",
// NIST: "nist",
} as const;
/**
* Type-safe report type extracted from COMPLIANCE_REPORT_TYPES
*/
export type ComplianceReportType =
(typeof COMPLIANCE_REPORT_TYPES)[keyof typeof COMPLIANCE_REPORT_TYPES];
/**
* Display names for each report type (user-facing)
*/
export const COMPLIANCE_REPORT_DISPLAY_NAMES: Record<
ComplianceReportType,
string
> = {
[COMPLIANCE_REPORT_TYPES.THREATSCORE]: "ThreatScore",
[COMPLIANCE_REPORT_TYPES.ENS]: "ENS RD2022",
// Add display names for future report types here
};
/**
* Default button labels for download buttons
*/
export const COMPLIANCE_REPORT_BUTTON_LABELS: Record<
ComplianceReportType,
string
> = {
[COMPLIANCE_REPORT_TYPES.THREATSCORE]: "PDF ThreatScore Report",
[COMPLIANCE_REPORT_TYPES.ENS]: "PDF ENS Report",
// Add button labels for future report types here
};
/**
* Maps compliance framework names (from API) to their report types
* This mapping determines which frameworks support PDF reporting
*/
const FRAMEWORK_TO_REPORT_TYPE: Record<string, ComplianceReportType> = {
ProwlerThreatScore: COMPLIANCE_REPORT_TYPES.THREATSCORE,
ENS: COMPLIANCE_REPORT_TYPES.ENS,
// Add new framework mappings here as PDF support is added:
// "CIS-1.5": COMPLIANCE_REPORT_TYPES.CIS,
// "NIST-800-53": COMPLIANCE_REPORT_TYPES.NIST,
};
/**
* Helper function to get report type from framework name
* Returns undefined if framework doesn't support PDF reporting
*/
export const getReportTypeForFramework = (
framework: string | undefined,
): ComplianceReportType | undefined => {
if (!framework) return undefined;
return FRAMEWORK_TO_REPORT_TYPE[framework];
};

View File

@@ -1,11 +1,15 @@
import {
getComplianceCsv,
getCompliancePdfReport,
getExportsZip,
getThreatScorePdf,
} from "@/actions/scans";
import { getTask } from "@/actions/task";
import { auth } from "@/auth.config";
import { useToast } from "@/components/ui";
import {
COMPLIANCE_REPORT_DISPLAY_NAMES,
type ComplianceReportType,
} from "@/lib/compliance/compliance-report-types";
import { AuthSocialProvider, MetaDataProps, PermissionInfo } from "@/types";
export const baseUrl = process.env.AUTH_URL || "http://localhost:3000";
@@ -221,15 +225,23 @@ export const downloadComplianceCsv = async (
);
};
export const downloadThreatScorePdf = async (
/**
* Generic function to download a compliance PDF report (ThreatScore, ENS, etc.)
* @param scanId - The scan ID
* @param reportType - Type of report (from COMPLIANCE_REPORT_TYPES)
* @param toast - Toast notification function
*/
export const downloadComplianceReportPdf = async (
scanId: string,
reportType: ComplianceReportType,
toast: ReturnType<typeof useToast>["toast"],
): Promise<void> => {
const result = await getThreatScorePdf(scanId);
const result = await getCompliancePdfReport(scanId, reportType);
const reportName = COMPLIANCE_REPORT_DISPLAY_NAMES[reportType];
await downloadFile(
result,
"application/pdf",
"The ThreatScore PDF report has been downloaded successfully.",
`The ${reportName} PDF report has been downloaded successfully.`,
toast,
);
};