import {z} from 'zod' export type EntityTreeDTO = {uuid?: string | undefined, name?: string | undefined, scopeUuid?: string | undefined, scopeName?: string | undefined}; export type ReportExportProcessDTO = {uuid?: string | undefined, name?: string | undefined, scopeUuid?: string | undefined, scopeName?: string | undefined, subScopes?: Array | undefined, title?: string | undefined, reportType?: ('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') | undefined, format?: ('json' | 'html' | 'unknown' | 'xml' | 'excel' | 'yaml' | 'pdf' | 'tv' | 'rdf' | 'csv' | 'sarif' | 'text') | undefined, scopeType?: ('organization' | 'product' | 'project' | 'unsupported' | 'account') | undefined, scopeUuidList?: Array | undefined, projectUuids?: Array | undefined, status?: ('PENDING' | 'IN_PROGRESS' | 'FAILED' | 'FAILURE' | 'SUCCESS') | undefined, createdBy?: string | undefined, createdAt?: string | undefined, sendEmailNotification?: boolean | undefined, labelsUuidList?: Array | undefined, includeVulnerabilities?: boolean | undefined, excludeInactiveProjects?: boolean | undefined}; export type CreateApiApiV30ProjectsProjectUuidImagesReportsSBOMArgs = {projectUuid: string, body: ReportExportProcessDTO}; export type CreateApiApiV30ProjectsProjectUuidImagesReportsSBOMOptions = {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 Image Project SBOM report asynchronously * * POST /api/v3.0/projects/{projectUuid}/images/reports/SBOM */ export const createApiApiV30ProjectsProjectUuidImagesReportsSBOM = async (args: CreateApiApiV30ProjectsProjectUuidImagesReportsSBOMArgs, options?: CreateApiApiV30ProjectsProjectUuidImagesReportsSBOMOptions) => { 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))}/images/reports/SBOM${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()) };