import {z} from 'zod' export type GetApiV1RootCauseAnalysesIdArgs = {'x-checkly-account'?: string | undefined, id: string}; export type GetApiV1RootCauseAnalysesIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const model69 = z.object({name: z.string(), type: z.string()}); export const artifacts = z.array(model69); export const model70 = z.object({artifacts: artifacts, description: z.string()}); export const evidence = z.array(model70).nullable(); export const model71 = z.object({url: z.string(), title: z.string()}); export const referenceLinks = z.array(model71).nullable(); export const analysis = z.object({classification: z.string(), userImpact: z.string(), rootCause: z.string(), codeFix: z.string().nullable().optional(), evidence: evidence.optional(), referenceLinks: referenceLinks.optional()}); export const model72 = z.literal("COMPLETED"); export const getRca = z.object({id: z.string(), checkType: z.string(), provider: z.string(), model: z.string(), checkId: z.string().nullable().optional(), errorGroupId: z.string().nullable().optional(), durationMs: z.number(), analysis: analysis.optional(), status: model72, created_at: 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 }; /** * Retrieve a Root Cause Analysis * * GET /v1/root-cause-analyses/{id} */ export const getApiV1RootCauseAnalysesId = async (args: GetApiV1RootCauseAnalysesIdArgs, options?: GetApiV1RootCauseAnalysesIdOptions) => { const {baseUrl = "https://api.checklyhq.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-checkly-account'] != null) headers.set("x-checkly-account", String(args['x-checkly-account'])) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/root-cause-analyses/${encodeURIComponent(String(args.id))}${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(getRca, await res.json()) };