import {z} from 'zod' export type GetApiProjectsProjectNameOrIdArgs = {'X-Request-Id'?: string | undefined, 'X-Is-Resource-Name'?: boolean | undefined, project_name_or_id: string}; export type GetApiProjectsProjectNameOrIdOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const projectMetadata = z.object({public: z.string().optional(), enable_content_trust: z.string().nullable().optional(), enable_content_trust_cosign: z.string().nullable().optional(), prevent_vul: z.string().nullable().optional(), severity: z.string().nullable().optional(), auto_scan: z.string().nullable().optional(), auto_sbom_generation: z.string().nullable().optional(), reuse_sys_cve_allowlist: z.string().nullable().optional(), retention_id: z.string().nullable().optional(), proxy_speed_kb: z.string().nullable().optional(), max_upstream_conn: z.string().nullable().optional(), proxy_cache_local_on_not_found: z.string().nullable().optional()}); export const cVEAllowlistItem = z.object({cve_id: z.string().optional()}); export const cVEAllowlist = z.object({id: z.number().int().optional(), project_id: z.number().int().optional(), expires_at: z.number().int().nullable().optional(), items: z.array(cVEAllowlistItem).optional(), creation_time: z.string().optional(), update_time: z.string().optional()}); export const project = z.object({project_id: z.number().int().optional(), owner_id: z.number().int().optional(), name: z.string().optional(), registry_id: z.number().int().optional(), creation_time: z.string().optional(), update_time: z.string().optional(), deleted: z.boolean().optional(), owner_name: z.string().optional(), togglable: z.boolean().optional(), current_user_role_id: z.number().int().optional(), current_user_role_ids: z.array(z.number().int()).optional(), repo_count: z.number().int().optional(), metadata: projectMetadata.optional(), cve_allowlist: cVEAllowlist.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 }; /** * Return specific project detail information * * GET /projects/{project_name_or_id} */ export const getApiProjectsProjectNameOrId = async (args: GetApiProjectsProjectNameOrIdArgs, options?: GetApiProjectsProjectNameOrIdOptions) => { const {baseUrl = "http://localhost/api/v2.0", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (args['X-Is-Resource-Name'] != null) headers.set("X-Is-Resource-Name", String(args['X-Is-Resource-Name'])) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_name_or_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(project, await res.json()) };