import {z} from 'zod' export type GetApiProjectsProjectIdKubernetesVersionsArgs = {project_id: string, show_deprecated?: boolean | undefined, product_name?: string | undefined}; export type GetApiProjectsProjectIdKubernetesVersionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const versionDetails = z.object({BuildVersion: z.string().optional(), MajorMinorVersion: z.string().optional(), PatchVersion: z.string().optional()}); export const kubernetesClustersVersionInfo = z.object({cluster_version_name: z.string(), supported_features: z.array(z.string()), tags: z.array(z.string()), version_details: versionDetails}); export const kubernetesNodePoolsVersionInfo = z.object({node_pool_version_name: z.string(), supported_features: z.array(z.string()), tags: z.array(z.string()), version_details: versionDetails}); export const listKubernetesVersionsResponse = z.object({kubernetes_cluster_versions: z.array(kubernetesClustersVersionInfo), kubernetes_node_pool_versions: z.array(kubernetesNodePoolsVersionInfo)}); 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 }; /** * Lists all available Kubernetes versions in the project and returns their details. * * GET /projects/{project_id}/kubernetes/versions */ export const getApiProjectsProjectIdKubernetesVersions = async (args: GetApiProjectsProjectIdKubernetesVersionsArgs, options?: GetApiProjectsProjectIdKubernetesVersionsOptions) => { const {baseUrl = "https://api.cloud.crusoe.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.show_deprecated != null) query.append("show_deprecated", String(args.show_deprecated)) if (args.product_name != null) query.append("product_name", String(args.product_name)) const url = `${baseUrl.replace(/\/+$/, '')}/projects/${encodeURIComponent(String(args.project_id))}/kubernetes/versions${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(listKubernetesVersionsResponse, await res.json()) };