import {z} from 'zod' export type StorageTypeEnum = 'FAST_SSD'; 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 BuildModeEnum = 'DOCKER'; 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 PortProtocolEnum = 'HTTP' | 'GRPC' | 'TCP' | 'UDP'; export type ServicePort = {id: string, name?: string | undefined, internal_port: number, external_port?: number | undefined, publicly_accessible: boolean, is_default?: boolean | undefined, protocol: PortProtocolEnum, public_path?: string | undefined, public_path_rewrite?: string | undefined}; export type ServicePortResponseList = Array; export type ServiceAnnotationRequest = {id: string}; export type ServiceAnnotationsRequestList = Array; export type ServiceLabelRequest = {id: string}; export type ServiceLabelsRequestList = Array; export type ApplicationEditRequest = {storage?: (Array<{id?: string | undefined, type: StorageTypeEnum, size: number, mount_point: string}>) | undefined, name?: string | undefined, description?: string | undefined, git_repository?: ApplicationGitRepositoryRequest | undefined, build_mode?: BuildModeEnum | undefined, dockerfile_path?: (string | null) | undefined, cpu?: number | undefined, memory?: number | undefined, min_running_instances?: number | undefined, max_running_instances?: number | undefined, healthchecks: Healthcheck, auto_preview?: boolean | undefined, ports?: ServicePortResponseList | undefined, arguments?: Array | undefined, entrypoint?: string | undefined, auto_deploy?: (boolean | null) | undefined, annotations_groups?: ServiceAnnotationsRequestList | undefined, labels_groups?: ServiceLabelsRequestList | undefined, icon_uri?: string | undefined, docker_target_build_stage?: (string | null) | undefined}; export type UpdateApiApplicationApplicationIdArgs = {applicationId: string, body: ApplicationEditRequest}; export type UpdateApiApplicationApplicationIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const storageTypeEnum = z.literal("FAST_SSD"); export const referenceObject = z.object({id: z.string()}); 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 buildModeEnum = z.literal("DOCKER"); 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 portProtocolEnum = z.enum(["HTTP", "GRPC", "TCP", "UDP"]); export const servicePort = z.object({id: z.string(), name: z.string().optional(), internal_port: z.number().int(), external_port: z.number().int().optional(), publicly_accessible: z.boolean(), is_default: z.boolean().optional(), protocol: portProtocolEnum, public_path: z.string().optional(), public_path_rewrite: z.string().optional()}); export const servicePortResponseList = z.array(servicePort); 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 serviceTypeEnum = z.enum(["APPLICATION", "DATABASE", "CONTAINER", "JOB", "HELM", "TERRAFORM"]); export const application = z.object({id: z.string(), created_at: z.string(), updated_at: z.string().optional(), storage: z.array(z.object({id: z.string(), type: storageTypeEnum, size: z.number().int(), mount_point: z.string()})).optional(), environment: referenceObject, git_repository: applicationGitRepository.optional(), maximum_cpu: z.number().int().optional(), maximum_memory: z.number().int().optional(), maximun_gpu: z.number().int().gte(0).optional(), name: z.string(), description: z.string().optional(), build_mode: buildModeEnum.optional(), dockerfile_path: z.string().nullable().optional(), cpu: z.number().int().optional(), memory: z.number().int().optional(), gpu: z.number().int().gte(0).optional(), min_running_instances: z.number().int().gte(0).optional(), max_running_instances: z.number().int().optional(), healthchecks: healthcheck, auto_preview: z.boolean().optional(), ports: servicePortResponseList.optional(), arguments: z.array(z.string()).optional(), entrypoint: z.string().optional(), auto_deploy: z.boolean().optional(), annotations_groups: organizationAnnotationsGroupResponseList.optional(), labels_groups: organizationLabelsGroupResponseList.optional(), icon_uri: z.string(), service_type: serviceTypeEnum, docker_target_build_stage: z.string().nullable().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 }; /** * Edit application * * PUT /application/{applicationId} * * Also accepts auth: bearerAuth */ export const updateApiApplicationApplicationId = async (args: UpdateApiApplicationApplicationIdArgs, options?: UpdateApiApplicationApplicationIdOptions) => { 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(/\/+$/, '')}/application/${encodeURIComponent(String(args.applicationId))}${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(application, await res.json()) };