import {z} from 'zod' export type GetApiBatchesBatchTokenEvaluationsArgs = {evaluation_status?: string | undefined, evaluation_result?: string | undefined, row_status?: string | undefined, outcome?: string | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiBatchesBatchTokenEvaluationsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const batchLink = z.object({href: z.string().optional()}); export const getApiBatchesBatchTokenEvaluationsResponse = z.object({status_code: z.number().optional(), error: z.object({}).nullable().optional(), _links: z.object({self: batchLink.optional(), next: batchLink.optional(), prev: batchLink.optional(), batch: batchLink.optional()}).optional(), _embedded: z.object({evaluations: z.array(z.object({})).optional()}).optional(), page: z.number().int().optional(), per_page: z.number().int().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 a Batch's Evaluations * * GET /batches/{batch_token}/evaluations * * Also accepts auth: basic */ export const getApiBatchesBatchTokenEvaluations = async (args: GetApiBatchesBatchTokenEvaluationsArgs, options?: GetApiBatchesBatchTokenEvaluationsOptions) => { const {baseUrl = "https://sandbox.alloy.co/v1", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.evaluation_status != null) query.append("evaluation_status", String(args.evaluation_status)) if (args.evaluation_result != null) query.append("evaluation_result", String(args.evaluation_result)) if (args.row_status != null) query.append("row_status", String(args.row_status)) if (args.outcome != null) query.append("outcome", String(args.outcome)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/batches/${encodeURIComponent(String(args.batch_token))}/evaluations${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(getApiBatchesBatchTokenEvaluationsResponse, await res.json()) };