import {z} from 'zod' export type GitCommitCheck = {name: string, status: 'IN_PROGRESS' | 'SUCCESS' | 'FAILED', description?: string | undefined, targetUrl?: string | undefined}; export type JobMetadata = {scoutVersion?: string | undefined, errorMessage?: string | undefined, errorStack?: string | undefined}; export type Job = {id: unknown, status: 'PENDING' | 'PROCESSING' | 'COMPLETED' | 'FAILED', type: 'PROCESS_GIT_REPO' | 'UPDATE_STATUS', organizationId?: string | undefined, projectId?: string | undefined, providerId?: string | undefined, providerType: 'GITHUB_CLOUD' | 'GITHUB_SERVER' | 'GITLAB_CLOUD' | 'GITLAB_SELF_MANAGED' | 'BITBUCKET_CLOUD' | 'BITBUCKET_DATACENTER' | 'AZURE', namespaceId: string, repositoryId: string, branch: string, commitSha: string, isMainBranch?: boolean | undefined, prId?: string | undefined, attempts: number, parentJobId?: unknown | undefined, checks?: Array | undefined, metadata?: JobMetadata | undefined, startedAt?: string | undefined, createdAt: string, updatedAt: string}; export type CreateApiOrgsOrgIdProjectsProjectIdScoutTodosArgs = {'x-redocly-scout-version'?: string | undefined, orgId: string, projectId: string, body: Job}; export type CreateApiOrgsOrgIdProjectsProjectIdScoutTodosOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const gitCommitCheck = z.object({name: z.string(), status: z.enum(["IN_PROGRESS", "SUCCESS", "FAILED"]), description: z.string().optional(), targetUrl: z.string().optional()}); export const jobMetadata = z.object({scoutVersion: z.string().optional(), errorMessage: z.string().optional(), errorStack: z.string().optional()}); export const job = z.object({id: z.string(), status: z.enum(["PENDING", "PROCESSING", "COMPLETED", "FAILED"]), type: z.enum(["PROCESS_GIT_REPO", "UPDATE_STATUS"]), organizationId: z.string().optional(), projectId: z.string().optional(), providerId: z.string().optional(), providerType: z.enum(["GITHUB_CLOUD", "GITHUB_SERVER", "GITLAB_CLOUD", "GITLAB_SELF_MANAGED", "BITBUCKET_CLOUD", "BITBUCKET_DATACENTER", "AZURE"]), namespaceId: z.string(), repositoryId: z.string(), branch: z.string(), commitSha: z.string(), isMainBranch: z.boolean().optional(), prId: z.string().optional(), attempts: z.number().int(), parentJobId: z.string().optional(), checks: z.array(gitCommitCheck).optional(), metadata: jobMetadata.optional(), startedAt: z.string().optional(), createdAt: z.string(), updatedAt: z.string()}); 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 }; /** * Create a job todo * * POST /orgs/{orgId}/projects/{projectId}/scout/todos */ export const createApiOrgsOrgIdProjectsProjectIdScoutTodos = async (args: CreateApiOrgsOrgIdProjectsProjectIdScoutTodosArgs, options?: CreateApiOrgsOrgIdProjectsProjectIdScoutTodosOptions) => { const {baseUrl = "https://app.cloud.redocly.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-redocly-scout-version'] != null) headers.set("x-redocly-scout-version", String(args['x-redocly-scout-version'])) if (ApiKey !== undefined) headers.set('authorization', `Bearer ${ApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/orgs/${encodeURIComponent(String(args.orgId))}/projects/${encodeURIComponent(String(args.projectId))}/scout/todos${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(job, await res.json()) };