import {z} from 'zod' export type CreateApiApiProjectsProjectIdRunsRunIdCancelArgs = {projectId: string, runId: string, body: {comment: string}}; export type CreateApiApiProjectsProjectIdRunsRunIdCancelOptions = {baseUrl: string, personalAccessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiProjectsProjectIdRunsRunIdCancelResponse = z.object({id: z.string(), name: z.string().nullable(), status: z.enum(["in_progress", "completed", "cancelled", "waiting", "failure"]), runVersion: z.enum(["v2", "null"]).nullable().optional(), releaseId: z.string(), release: z.object({id: z.string(), name: z.string().nullable(), version: z.string().nullable()}).nullable().optional(), projectId: z.string(), createdById: z.string(), createdBy: z.object({id: z.string(), email: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable()}).nullable().optional(), createdAt: z.string(), completedAt: z.string().nullable().optional(), cancelledById: z.string().nullable().optional(), cancelledBy: z.object({id: z.string(), email: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable()}).nullable().optional(), cancelledComment: z.string().nullable().optional(), jobs: z.array(z.object({id: z.string(), status: z.enum(["not_started", "in_progress", "waiting", "failure", "rejected", "completed"]), order: z.number(), environmentId: z.string().nullable(), environment: z.object({id: z.string(), name: z.string(), key: z.string().nullable()}).nullable().optional(), projectId: z.string(), deploymentWorkflowRunId: z.string(), reviewedAt: z.string().nullable().optional(), reviewedBy: z.object({id: z.string(), email: z.string(), firstName: z.string().nullable(), lastName: z.string().nullable()}).nullable().optional(), reviewedComment: z.string().nullable().optional(), reviewedConclusion: z.enum(["approved", "rejected", "null"]).nullable().optional(), previousRelease: z.object({id: z.string(), name: z.string().nullable(), version: z.string().nullable()}).nullable().optional(), previousReleaseId: z.string().nullable().optional(), event: z.string().nullable().optional(), data: z.unknown(), createdAt: 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 }; /** * Cancel deployment workflow run * * POST /api/projects/{projectId}/runs/{runId}/cancel * * Also accepts auth: internalAuth */ export const createApiApiProjectsProjectIdRunsRunIdCancel = async (args: CreateApiApiProjectsProjectIdRunsRunIdCancelArgs, options: CreateApiApiProjectsProjectIdRunsRunIdCancelOptions) => { const {baseUrl, fetch: fetchFn = fetch, personalAccessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (personalAccessToken !== undefined) headers.set('authorization', `Bearer ${personalAccessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/projects/${encodeURIComponent(String(args.projectId))}/runs/${encodeURIComponent(String(args.runId))}/cancel${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiApiProjectsProjectIdRunsRunIdCancelResponse, await res.json()) };