import {z} from 'zod' export type ArtifactFamily = 'anaconda_project' | 'anaconda_env' | 'cve' | 'conda' | 'python' | 'cran' | 'notebook' | 'docker' | 'sbom'; export type CVEStatus = 'reported' | 'active' | 'mitigated' | 'cleared' | 'disputed' | 'unknown'; export type GetApiChannelsChannelNameArtifactsArtifactFamilyArtifactNameFilesArgs = {channel_name: string, artifact_family: ArtifactFamily, artifact_name: string, offset?: number | undefined, limit?: number | undefined, sort?: (Array<'ckey' | '-ckey' | 'updated_at' | '-updated_at' | 'blob_size' | '-blob_size' | 'metadata_version' | '-metadata_version' | 'metadata_platforms' | '-metadata_platforms'>) | undefined, omit_cve?: boolean | undefined, include_nonsearchable?: boolean | undefined, status?: Array | undefined, max_score?: number | undefined, min_score?: number | undefined, architectures?: Array | undefined, state?: ('active' | 'passive') | undefined, created_min?: string | undefined, created_max?: string | undefined, ckey?: string | undefined, version?: string | undefined, cve_extra_info?: boolean | undefined}; export type GetApiChannelsChannelNameArtifactsArtifactFamilyArtifactNameFilesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const artifactFamily = z.enum(["anaconda_project", "anaconda_env", "cve", "conda", "python", "cran", "notebook", "docker", "sbom"]); export const cVEStatus = z.enum(["reported", "active", "mitigated", "cleared", "disputed", "unknown"]); export const artifactFile = z.object({channel: z.string().optional(), subchannel: z.string().optional(), ckey: z.string().optional(), family: artifactFamily.optional(), name: z.string().optional(), metadata: z.object({}).optional(), signatures: z.object({}).optional(), size: z.number().optional(), url: z.string().optional(), cve_count: z.number().optional(), cve_score: z.number().optional(), cve_scores: z.object({cvssv2: z.number().optional(), cvssv3: z.number().optional()}).optional(), cve_status: cVEStatus.optional(), created_at: z.string().optional(), updated_at: z.string().optional()}); export const getApiChannelsChannelNameArtifactsArtifactFamilyArtifactNameFilesResponse = z.object({total_count: z.number().optional(), items: z.array(artifactFile).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 }; /** * Get all files of the artifact * * GET /channels/{channel_name}/artifacts/{artifact_family}/{artifact_name}/files */ export const getApiChannelsChannelNameArtifactsArtifactFamilyArtifactNameFiles = async (args: GetApiChannelsChannelNameArtifactsArtifactFamilyArtifactNameFilesArgs, options?: GetApiChannelsChannelNameArtifactsArtifactFamilyArtifactNameFilesOptions) => { const {baseUrl = "https://api.anaconda.cloud/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) for (const item of args.sort ?? []) query.append("sort", String(item)) if (args.omit_cve != null) query.append("omit_cve", String(args.omit_cve)) if (args.include_nonsearchable != null) query.append("include_nonsearchable", String(args.include_nonsearchable)) for (const item of args.status ?? []) query.append("status", String(item)) if (args.max_score != null) query.append("max_score", String(args.max_score)) if (args.min_score != null) query.append("min_score", String(args.min_score)) for (const item of args.architectures ?? []) query.append("architectures", String(item)) if (args.state != null) query.append("state", String(args.state)) if (args.created_min != null) query.append("created_min", String(args.created_min)) if (args.created_max != null) query.append("created_max", String(args.created_max)) if (args.ckey != null) query.append("ckey", String(args.ckey)) if (args.version != null) query.append("version", String(args.version)) if (args.cve_extra_info != null) query.append("cve_extra_info", String(args.cve_extra_info)) const url = `${baseUrl.replace(/\/+$/, '')}/channels/${encodeURIComponent(String(args.channel_name))}/artifacts/${encodeURIComponent(String(args.artifact_family))}/${encodeURIComponent(String(args.artifact_name))}/files${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(getApiChannelsChannelNameArtifactsArtifactFamilyArtifactNameFilesResponse, await res.json()) };