import {z} from 'zod' export type CreateApiApiV30ProjectsProjectUuidContainerImportSbomArgs = {projectUuid: string, imageName?: string | undefined, body: BodyInit}; export type CreateApiApiV30ProjectsProjectUuidContainerImportSbomOptions = {baseUrl?: string | undefined, bearerKey?: string | undefined, fetch?: typeof fetch | undefined}; export const projectDTOV3 = z.object({uuid: z.string().optional(), name: z.string().optional(), path: z.string().optional(), applicationName: z.string().optional(), applicationUuid: z.string().optional()}); export const sbomScanInfoDTO = z.object({scanUuid: z.string().optional(), createdAt: z.string().optional()}); export const sbomScanLinksDTO = z.object({logs: z.string().optional()}); export const sbomScanResponseDTO = z.object({supportToken: z.string().optional(), project: projectDTOV3.optional(), scan: sbomScanInfoDTO.optional(), link: sbomScanLinksDTO.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 }; /** * Import a container SBOM into a project (Containers) * * POST /api/v3.0/projects/{projectUuid}/container/importSbom */ export const createApiApiV30ProjectsProjectUuidContainerImportSbom = async (args: CreateApiApiV30ProjectsProjectUuidContainerImportSbomArgs, options?: CreateApiApiV30ProjectsProjectUuidContainerImportSbomOptions) => { const {baseUrl = "https://baseUrl", fetch: fetchFn = fetch, bearerKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.imageName != null) query.append("imageName", String(args.imageName)) if (bearerKey !== undefined) headers.set('authorization', `Bearer ${bearerKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3.0/projects/${encodeURIComponent(String(args.projectUuid))}/container/importSbom${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(sbomScanResponseDTO, await res.json()) };