import {z} from 'zod' export type SksClusterLabels = {[key: string]: string}; export type SksOidc = {'client-id': string, 'issuer-url': string, 'username-claim'?: string | undefined, 'username-prefix'?: string | undefined, 'groups-claim'?: string | undefined, 'groups-prefix'?: string | undefined, 'required-claim'?: {[key: string]: string} | undefined}; export type SksAuditEndpoint = string; export type SksAuditBearerToken = string; export type SksAuditInitialBackoff = string; export type SksAuditUpdate = {endpoint?: SksAuditEndpoint | undefined, 'bearer-token'?: SksAuditBearerToken | undefined, 'initial-backoff'?: SksAuditInitialBackoff | undefined, enabled?: boolean | undefined}; export type UpdateApiSksClusterIdArgs = {id: string, body: {description?: (string | null) | undefined, labels?: SksClusterLabels | undefined, 'auto-upgrade'?: boolean | undefined, oidc?: SksOidc | undefined, name?: string | undefined, 'enable-operators-ca'?: boolean | undefined, 'feature-gates'?: (Array | null) | undefined, addons?: (Array<'exoscale-cloud-controller' | 'exoscale-container-storage-interface' | 'metrics-server' | 'karpenter'>) | undefined, audit?: SksAuditUpdate | undefined}}; export type UpdateApiSksClusterIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const operation = z.object({id: z.string().optional(), reason: z.enum(["incorrect", "unknown", "unavailable", "forbidden", "busy", "fault", "partial", "not-found", "interrupted", "unsupported", "conflict"]).optional(), reference: z.object({id: z.string().optional(), link: z.string().optional(), command: z.string().optional()}).optional(), message: z.string().optional(), state: z.enum(["failure", "pending", "success", "timeout"]).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 }; /** * Update an SKS cluster * * PUT /sks-cluster/{id} */ export const updateApiSksClusterId = async (args: UpdateApiSksClusterIdArgs, options?: UpdateApiSksClusterIdOptions) => { const {baseUrl = "https://api-ch-gva-2.exoscale.com/v2", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/sks-cluster/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(operation, await res.json()) };