import {z} from 'zod' export type GetApiSelfHostedAccountIdTasksTaskIdArgs = {accountId: string, taskId: string}; export type GetApiSelfHostedAccountIdTasksTaskIdOptions = {baseUrl?: string | undefined, RunnerPoolAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const taskTypeEnum = z.enum(["post-plan", "post-apply"]); export const vcsTypeEnum = z.enum(["github", "gitlab", "bitbucket", "codecommit", "azuredevops"]); export const runnerTypeEnum = z.enum(["github-actions", "gitlab-pipelines", "bitbucket-pipelines", "azure-pipelines", "jenkins", "semaphore", "atlantis", "env0", "firefly", "unrecognized"]); export const task = z.object({id: z.string().optional(), accountId: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), contentKeys: z.record(z.string(), z.string()).optional(), status: z.string().optional(), resultStatus: z.string().optional(), type: taskTypeEnum.optional(), guardrailsSummary: z.object({total: z.number().int().optional(), passed: z.number().int().optional(), failed: z.number().int().optional(), violations: z.array(z.object({id: z.string().optional(), severity: z.enum(["high", "medium", "low"]).optional(), message: z.string().optional()})).optional(), description: z.string().optional()}).optional(), backendSummary: z.object({type: z.enum(["s3", "azurerm", "gcs", "consul"]).optional(), config: z.record(z.string(), z.unknown()).optional(), resources: z.number().int().optional(), description: z.string().optional()}).optional(), changedFilesCodeSummary: z.object({total: z.number().int().optional(), added: z.number().int().optional(), modified: z.number().int().optional(), deleted: z.number().int().optional(), files: z.array(z.object({path: z.string().optional(), type: z.enum(["added", "modified", "deleted"]).optional()})).optional(), description: z.string().optional()}).optional(), vcsType: vcsTypeEnum.optional(), runnerType: runnerTypeEnum.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 }; /** * Get task (self-hosted) * * GET /self-hosted/{accountId}/tasks/{taskId} */ export const getApiSelfHostedAccountIdTasksTaskId = async (args: GetApiSelfHostedAccountIdTasksTaskIdArgs, options?: GetApiSelfHostedAccountIdTasksTaskIdOptions) => { const {baseUrl = "https://api.firefly.ai/v2", fetch: fetchFn = fetch, RunnerPoolAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (RunnerPoolAuth !== undefined) headers.set('authorization', `Bearer ${RunnerPoolAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/self-hosted/${encodeURIComponent(String(args.accountId))}/tasks/${encodeURIComponent(String(args.taskId))}${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(task, await res.json()) };