import {z} from 'zod' export type GetApiJobJobIdDeploymentHistoryV2Args = {pageSize?: (number | null) | undefined}; export type GetApiJobJobIdDeploymentHistoryV2Options = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const serviceTypeEnum = z.enum(["APPLICATION", "DATABASE", "CONTAINER", "JOB", "HELM", "TERRAFORM"]); 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 organizationEventOrigin = z.enum(["API", "CLI", "CONSOLE", "GIT", "QOVERY_INTERNAL", "TERRAFORM_PROVIDER"]); export const deploymentHistoryAuditingData = z.object({created_at: z.string(), updated_at: z.string(), triggered_by: z.string(), origin: organizationEventOrigin.optional()}); export const commit = z.object({created_at: z.string(), git_commit_id: z.string(), tag: z.string(), message: z.string(), author_name: z.string(), author_avatar_url: z.string().optional(), commit_page_url: z.string().optional()}).nullable(); export const jobLifecyleSchedule = z.object({arguments: z.array(z.string()), entrypoint: z.string().optional()}); export const jobCronSchedule = z.object({arguments: z.array(z.string()), entrypoint: z.string().optional(), scheduled_at: z.string(), timezone: z.string()}); export const jobLifecycleTypeEnum = z.enum(["GENERIC", "TERRAFORM", "CLOUDFORMATION"]); export const deploymentHistoryServiceDetails = z.union([z.object({commit: commit}), z.object({image_name: z.string(), tag: z.string(), arguments: z.array(z.string()), entrypoint: z.string().optional()}), z.object({image_name: z.string(), tag: z.string(), commit: commit.optional(), schedule: z.object({on_start: jobLifecyleSchedule.optional(), on_stop: jobLifecyleSchedule.optional(), on_delete: jobLifecyleSchedule.optional(), cron_job: jobCronSchedule.optional(), lifecycle_type: jobLifecycleTypeEnum.optional()}).optional(), job_type: z.enum(["CRON", "LIFECYCLE"])}), z.object({commit: commit.optional(), repository: z.object({chart_name: z.string().optional(), chart_version: z.string().optional()}).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 deploymentHistoryService = z.object({identifier: z.object({name: z.string(), service_id: z.string(), service_type: serviceTypeEnum, execution_id: z.string().optional()}), status: stateEnum, auditing_data: deploymentHistoryAuditingData, details: deploymentHistoryServiceDetails, status_details: statusDetails.optional(), icon_uri: z.string(), total_duration: z.string().optional()}); export const deploymentHistoryServicePaginatedResponseListV2 = z.object({page: z.number(), page_size: z.number(), results: z.array(deploymentHistoryService).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 }; /** * List job deployments * * GET /job/{jobId}/deploymentHistoryV2 * * Also accepts auth: bearerAuth */ export const getApiJobJobIdDeploymentHistoryV2 = async (args: GetApiJobJobIdDeploymentHistoryV2Args, options?: GetApiJobJobIdDeploymentHistoryV2Options) => { 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.pageSize != null) query.append("pageSize", String(args.pageSize)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/job/${encodeURIComponent(String(args.jobId))}/deploymentHistoryV2${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(deploymentHistoryServicePaginatedResponseListV2, await res.json()) };