import {z} from 'zod' export type GitProviderEnum = 'BITBUCKET' | 'GITHUB' | 'GITLAB'; export type ApplicationGitRepositoryRequest = {url: string, branch?: string | undefined, root_path?: string | undefined, git_token_id?: (string | null) | undefined, provider: GitProviderEnum}; export type Probe = {type?: ({tcp?: ({port?: number | undefined, host?: (string | null) | undefined} | null) | undefined, http?: ({path?: string | undefined, scheme?: string | undefined, port?: number | undefined} | null) | undefined, exec?: ({command?: Array | undefined} | null) | undefined, grpc?: ({service?: (string | null) | undefined, port?: number | undefined} | null) | undefined}) | undefined, initial_delay_seconds?: number | undefined, period_seconds?: number | undefined, timeout_seconds?: number | undefined, success_threshold?: number | undefined, failure_threshold?: number | undefined} | null; export type Healthcheck = {readiness_probe?: Probe | undefined, liveness_probe?: Probe | undefined}; export type JobLifecycleTypeEnum = 'GENERIC' | 'TERRAFORM' | 'CLOUDFORMATION'; export type ServiceAnnotationRequest = {id: string}; export type ServiceAnnotationsRequestList = Array; export type ServiceLabelRequest = {id: string}; export type ServiceLabelsRequestList = Array; export type JobRequest = {name: string, description?: string | undefined, cpu?: number | undefined, memory?: number | undefined, gpu?: number | undefined, max_nb_restart?: number | undefined, max_duration_seconds?: number | undefined, auto_preview?: boolean | undefined, port?: (number | null) | undefined, source?: ({image?: ({image_name?: string | undefined, tag?: string | undefined, registry_id?: string | undefined} | null) | undefined, docker?: ({git_repository?: ApplicationGitRepositoryRequest | undefined, dockerfile_path?: (string | null) | undefined, dockerfile_raw?: (string | null) | undefined, docker_target_build_stage?: (string | null) | undefined} | null) | undefined}) | undefined, healthchecks: Healthcheck, schedule?: ({on_start?: ({arguments?: Array | undefined, entrypoint?: string | undefined}) | undefined, on_stop?: ({arguments?: Array | undefined, entrypoint?: string | undefined}) | undefined, on_delete?: ({arguments?: Array | undefined, entrypoint?: string | undefined}) | undefined, cronjob?: ({arguments?: Array | undefined, entrypoint?: string | undefined, timezone?: string | undefined, scheduled_at: unknown}) | undefined, lifecycle_type?: JobLifecycleTypeEnum | undefined}) | undefined, auto_deploy?: (boolean | null) | undefined, annotations_groups?: ServiceAnnotationsRequestList | undefined, labels_groups?: ServiceLabelsRequestList | undefined, icon_uri?: string | undefined}; export type UpdateApiJobJobIdArgs = {jobId: string, body: JobRequest}; export type UpdateApiJobJobIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const referenceObject = z.object({id: z.string()}); export const containerRegistryKindEnum = z.enum(["ECR", "SCALEWAY_CR", "DOCKER_HUB", "GITHUB_CR", "GITHUB_ENTERPRISE_CR", "GITLAB_CR", "PUBLIC_ECR", "DOCR", "GENERIC_CR", "GCP_ARTIFACT_REGISTRY", "AZURE_CR"]); export const containerRegistryProviderDetailsResponse = z.object({id: z.string(), name: z.string(), url: z.string(), kind: containerRegistryKindEnum}); export const containerSource = z.object({image_name: z.string(), tag: z.string(), registry_id: z.string().optional(), registry: containerRegistryProviderDetailsResponse}); export const gitProviderEnum = z.enum(["BITBUCKET", "GITHUB", "GITLAB"]); export const applicationGitRepository = z.object({has_access: z.boolean().optional(), provider: gitProviderEnum, owner: z.string(), url: z.string(), name: z.string(), branch: z.string().optional(), root_path: z.string().optional(), deployed_commit_id: z.string().optional(), deployed_commit_date: z.string().optional(), deployed_commit_contributor: z.string().optional(), deployed_commit_tag: z.string().optional(), git_token_id: z.string().nullable().optional(), git_token_name: z.string().nullable().optional()}); export const jobSourceDockerResponse = z.object({git_repository: applicationGitRepository.optional(), dockerfile_path: z.string().nullable().optional(), dockerfile_raw: z.string().nullable().optional(), docker_target_build_stage: z.string().nullable().optional()}); export const probe = z.object({type: z.object({tcp: z.object({port: z.number().int().optional(), host: z.string().nullable().optional()}).nullable().optional(), http: z.object({path: z.string().optional(), scheme: z.string().optional(), port: z.number().int().optional()}).nullable().optional(), exec: z.object({command: z.array(z.string()).optional()}).nullable().optional(), grpc: z.object({service: z.string().nullable().optional(), port: z.number().int().optional()}).nullable().optional()}).optional(), initial_delay_seconds: z.number().int().optional(), period_seconds: z.number().int().optional(), timeout_seconds: z.number().int().optional(), success_threshold: z.number().int().optional(), failure_threshold: z.number().int().optional()}).nullable(); export const healthcheck = z.object({readiness_probe: probe.optional(), liveness_probe: probe.optional()}); export const serviceTypeEnum = z.enum(["APPLICATION", "DATABASE", "CONTAINER", "JOB", "HELM", "TERRAFORM"]); export const jobTypeEnum = z.enum(["LIFECYCLE", "CRON"]); export const jobLifecycleTypeEnum = z.enum(["GENERIC", "TERRAFORM", "CLOUDFORMATION"]); export const annotation = z.object({key: z.string(), value: z.string()}); export const organizationAnnotationsGroupScopeEnum = z.enum(["DEPLOYMENTS", "STATEFUL_SETS", "SERVICES", "INGRESS", "HPA", "PODS", "SECRETS", "JOBS", "CRON_JOBS"]); export const organizationAnnotationsGroupResponse = z.object({id: z.string(), created_at: z.string(), updated_at: z.string().optional(), name: z.string(), annotations: z.array(annotation), scopes: z.array(organizationAnnotationsGroupScopeEnum)}); export const organizationAnnotationsGroupResponseList = z.array(organizationAnnotationsGroupResponse); export const label = z.object({key: z.string(), value: z.string(), propagate_to_cloud_provider: z.boolean()}); export const organizationLabelsGroupResponse = z.object({id: z.string(), created_at: z.string(), updated_at: z.string().optional(), name: z.string(), labels: z.array(label)}); export const organizationLabelsGroupResponseList = z.array(organizationLabelsGroupResponse); export const lifecycleJobResponse = z.object({id: z.string(), created_at: z.string(), updated_at: z.string().optional(), environment: referenceObject, maximum_cpu: z.number().int(), maximum_memory: z.number().int(), maximum_gpu: z.number().int().gte(0), name: z.string(), description: z.string().optional(), cpu: z.number().int(), memory: z.number().int(), gpu: z.number().int().gte(0), max_nb_restart: z.number().int().gte(0).optional(), max_duration_seconds: z.number().int().gte(0).optional(), auto_preview: z.boolean(), port: z.number().int().gte(1).nullable().optional(), source: z.union([z.object({image: containerSource}), z.object({docker: jobSourceDockerResponse})]), healthchecks: healthcheck, auto_deploy: z.boolean().optional(), icon_uri: z.string(), service_type: serviceTypeEnum, job_type: jobTypeEnum, schedule: z.object({on_start: z.object({arguments: z.array(z.string()).optional(), entrypoint: z.string().optional()}).optional(), on_stop: z.object({arguments: z.array(z.string()).optional(), entrypoint: z.string().optional()}).optional(), on_delete: z.object({arguments: z.array(z.string()).optional(), entrypoint: z.string().optional()}).optional(), lifecycle_type: jobLifecycleTypeEnum.optional()}), annotations_groups: organizationAnnotationsGroupResponseList.optional(), labels_groups: organizationLabelsGroupResponseList.optional()}); export const cronJobResponse = z.object({id: z.string(), created_at: z.string(), updated_at: z.string().optional(), environment: referenceObject, maximum_cpu: z.number().int(), maximum_memory: z.number().int(), maximum_gpu: z.number().int().gte(0), name: z.string(), description: z.string().optional(), cpu: z.number().int(), memory: z.number().int(), gpu: z.number().int().gte(0), max_nb_restart: z.number().int().gte(0).optional(), max_duration_seconds: z.number().int().gte(0).optional(), auto_preview: z.boolean(), port: z.number().int().gte(1).nullable().optional(), source: z.union([z.object({image: containerSource}), z.object({docker: jobSourceDockerResponse})]), healthchecks: healthcheck, auto_deploy: z.boolean().optional(), icon_uri: z.string(), service_type: serviceTypeEnum, job_type: jobTypeEnum, schedule: z.object({cronjob: z.object({arguments: z.array(z.string()).optional(), entrypoint: z.string().optional(), timezone: z.string(), scheduled_at: z.string()})}), annotations_groups: organizationAnnotationsGroupResponseList.optional(), labels_groups: organizationLabelsGroupResponseList.optional()}); export const jobResponse = z.discriminatedUnion("job_type", [lifecycleJobResponse, cronJobResponse]); 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 }; /** * Edit job * * PUT /job/{jobId} * * Also accepts auth: bearerAuth */ export const updateApiJobJobId = async (args: UpdateApiJobJobIdArgs, options?: UpdateApiJobJobIdOptions) => { const {baseUrl = "https://api.qovery.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/job/${encodeURIComponent(String(args.jobId))}${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(jobResponse, await res.json()) };