import {z} from 'zod' export type DueDiligenceReportExportProjectDTOV3 = {name?: string | undefined, format?: ('excel' | 'json' | 'xml') | undefined, sendEmailNotification?: boolean | undefined}; export type CreateApiApiV30ProjectsProjectUuidDependenciesReportsDueDiligenceArgs = {projectUuid: string, body: DueDiligenceReportExportProjectDTOV3}; export type CreateApiApiV30ProjectsProjectUuidDependenciesReportsDueDiligenceOptions = {baseUrl?: string | undefined, bearerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const entityTreeDTO = z.object({uuid: z.string().optional(), name: z.string().optional(), scopeUuid: z.string().optional(), scopeName: z.string().optional()}); export const reportExportProcessDTO = z.object({uuid: z.string().optional(), name: z.string().optional(), scopeUuid: z.string().optional(), scopeName: z.string().optional(), subScopes: z.array(entityTreeDTO).optional(), title: z.string().optional(), reportType: z.enum(["attribution", "inventory", "vulnerabilities", "securityAlerts", "sbom", "Cbom", "securityAlertsLibrary", "Compliance", "Findings", "Suppressions", "Resolved", "spdx", "spdx_2_3", "cycloneDX", "cycloneDX_1_5", "cycloneDX_1_6", "dueDiligence", "unknown", "imgAttribution", "imgDueDiligence", "imgSpdx", "imgSpdx_2_3", "imgCycloneDX", "imgCycloneDX_1_5", "aiInventory", "aiFindings", "aiBom", "aiEntities", "conversationalSystemPrompts", "imgCycloneDX_1_6", "risk", "users", "zeroDayCatalog", "activityLog", "unifiedFindings"]).optional(), format: z.enum(["json", "html", "unknown", "xml", "excel", "yaml", "pdf", "tv", "rdf", "csv", "sarif", "text"]).optional(), scopeType: z.enum(["organization", "product", "project", "unsupported", "account"]).optional(), scopeUuidList: z.array(z.string()).optional(), projectUuids: z.array(z.string()).optional(), status: z.enum(["PENDING", "IN_PROGRESS", "FAILED", "FAILURE", "SUCCESS"]).optional(), createdBy: z.string().optional(), createdAt: z.string().optional(), sendEmailNotification: z.boolean().optional(), labelsUuidList: z.array(z.string()).optional(), includeVulnerabilities: z.boolean().optional(), excludeInactiveProjects: z.boolean().optional()}); export const dWRResponseV3ReportExportProcessDTO = z.object({supportToken: z.string().optional(), response: reportExportProcessDTO.optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Export project due diligence report asynchronously (Dependencies - SCA) * * POST /api/v3.0/projects/{projectUuid}/dependencies/reports/dueDiligence */ export const createApiApiV30ProjectsProjectUuidDependenciesReportsDueDiligence = async (args: CreateApiApiV30ProjectsProjectUuidDependenciesReportsDueDiligenceArgs, options?: CreateApiApiV30ProjectsProjectUuidDependenciesReportsDueDiligenceOptions) => { const {baseUrl = "https://baseUrl", fetch: fetchFn = fetch, bearerKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerKey !== undefined) headers.set('authorization', `Bearer ${bearerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3.0/projects/${encodeURIComponent(String(args.projectUuid))}/dependencies/reports/dueDiligence${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(dWRResponseV3ReportExportProcessDTO, await res.json()) };