import {z} from 'zod' export type GetApiOrgsOrgIdProjectsProjectIdScoutTodosArgs = {'x-redocly-scout-version'?: string | undefined, orgId: string, projectId: string, after?: string | undefined, before?: string | undefined, sort?: string | undefined, filter?: string | undefined, limit?: number | undefined}; export type GetApiOrgsOrgIdProjectsProjectIdScoutTodosOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const page = z.object({nextPage: z.string().nullable(), previousPage: z.string().nullable(), limit: z.number().int().gte(1).lte(100)}); 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 jobList = z.object({object: z.literal("list"), page: page, items: z.array(job)}); 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 all todos * * GET /orgs/{orgId}/projects/{projectId}/scout/todos */ export const getApiOrgsOrgIdProjectsProjectIdScoutTodos = async (args: GetApiOrgsOrgIdProjectsProjectIdScoutTodosArgs, options?: GetApiOrgsOrgIdProjectsProjectIdScoutTodosOptions) => { const {baseUrl = "https://app.cloud.redocly.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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 (args.after != null) query.append("after", String(args.after)) if (args.before != null) query.append("before", String(args.before)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.limit != null) query.append("limit", String(args.limit)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(jobList, await res.json()) };