import {z} from 'zod' export type HelmForceEvent = 'DIFF'; export type CreateApiHelmHelmIdRedeployArgs = {helmId: string, forceEvent?: HelmForceEvent | undefined}; export type CreateApiHelmHelmIdRedeployOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const stateEnum = z.enum(["BUILDING", "BUILD_ERROR", "CANCELED", "CANCELING", "DELETED", "DELETE_ERROR", "DELETE_QUEUED", "DELETING", "DEPLOYED", "DEPLOYING", "DEPLOYMENT_ERROR", "DEPLOYMENT_QUEUED", "EXECUTING", "QUEUED", "READY", "RECAP", "RESTARTED", "RESTARTING", "RESTART_ERROR", "RESTART_QUEUED", "STOPPED", "STOPPING", "STOP_ERROR", "STOP_QUEUED", "WAITING_DELETING", "WAITING_RESTARTING", "WAITING_RUNNING", "WAITING_STOPPING"]); export const serviceDeploymentStatusEnum = z.enum(["NEVER_DEPLOYED", "OUT_OF_DATE", "UP_TO_DATE"]); export const serviceStepMetricNameEnum = z.enum(["REGISTRY_CREATE_REPOSITORY", "GIT_CLONE", "BUILD_QUEUEING", "BUILD", "DEPLOYMENT_QUEUEING", "DEPLOYMENT", "ROUTER_DEPLOYMENT", "MIRROR_IMAGE", "EXECUTING"]); export const stepMetricStatusEnum = z.enum(["SUCCESS", "ERROR", "CANCEL", "SKIP"]); export const serviceStepMetric = z.object({step_name: serviceStepMetricNameEnum.optional(), status: stepMetricStatusEnum.optional(), duration_sec: z.number().int().optional()}); export const serviceStepMetrics = z.object({total_duration_sec: z.number().int().nullable().optional(), total_computing_duration_sec: z.number().int().optional(), details: z.array(serviceStepMetric).optional()}); export const serviceActionEnum = z.enum(["DEPLOY", "DELETE", "RESTART", "STOP", "UNKNOWN"]); export const serviceActionStatusEnum = z.enum(["QUEUED", "ONGOING", "SUCCESS", "ERROR", "EXECUTING", "CANCELED", "CANCELING", "NEVER"]); export const statusDetails = z.object({action: serviceActionEnum, status: serviceActionStatusEnum}); export const status = z.object({id: z.string(), state: stateEnum, service_deployment_status: serviceDeploymentStatusEnum, last_deployment_date: z.string().optional(), is_part_last_deployment: z.boolean().optional(), steps: serviceStepMetrics.optional(), execution_id: z.string().optional(), status_details: statusDetails, deployment_request_id: z.string().nullable().optional(), deployment_requests_count: z.number().int().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 }; /** * Redeploy helm * * POST /helm/{helmId}/redeploy * * Also accepts auth: bearerAuth */ export const createApiHelmHelmIdRedeploy = async (args: CreateApiHelmHelmIdRedeployArgs, options?: CreateApiHelmHelmIdRedeployOptions) => { 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 (args.forceEvent != null) query.append("forceEvent", String(args.forceEvent)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/helm/${encodeURIComponent(String(args.helmId))}/redeploy${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(status, await res.json()) };