import {z} from 'zod' export type CreateApiClusterClusterIdUpgradeArgs = {clusterId: string}; export type CreateApiClusterClusterIdUpgradeOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const clusterStateEnum = z.enum(["BUILDING", "BUILD_ERROR", "CANCELED", "CANCELING", "DELETED", "DELETE_ERROR", "DELETE_QUEUED", "DELETING", "DEPLOYED", "DEPLOYING", "DEPLOYMENT_ERROR", "DEPLOYMENT_QUEUED", "DRY_RUN", "QUEUED", "READY", "STOPPED", "STOPPING", "STOP_ERROR", "STOP_QUEUED", "RESTART_QUEUED", "RESTARTING", "RESTARTED", "RESTART_ERROR", "INVALID_CREDENTIALS"]); export const clusterLock = z.object({reason: z.string(), ttl_in_days: z.number().int().optional(), cluster_id: z.string(), locked_at: z.string(), owner_name: z.string()}); export const clusterStatus = z.object({cluster_id: z.string().optional(), status: clusterStateEnum.optional(), is_deployed: z.boolean().optional(), next_k8s_available_version: z.string().nullable().optional(), last_execution_id: z.string().optional(), cluster_lock: clusterLock.optional(), last_deployment_date: z.string().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 }; /** * Upgrade a cluster * * POST /cluster/{clusterId}/upgrade * * Also accepts auth: bearerAuth */ export const createApiClusterClusterIdUpgrade = async (args: CreateApiClusterClusterIdUpgradeArgs, options?: CreateApiClusterClusterIdUpgradeOptions) => { const {baseUrl = "https://api.qovery.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/cluster/${encodeURIComponent(String(args.clusterId))}/upgrade${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(clusterStatus, await res.json()) };