import {z} from 'zod' export type GetApiApiV1EngineFieldsArgs = {page_size?: number | undefined, cursor?: string | undefined, id?: Array | undefined, engine?: string | undefined, name?: string | undefined, used?: boolean | undefined, ordering?: ('id' | '-id' | 'engine' | '-engine' | 'name' | '-name') | undefined}; export type GetApiApiV1EngineFieldsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({next: z.string().nullable().optional(), previous: z.string().nullable().optional()}); export const modifiedBy = z.string().nullable(); export const modifiedAt = z.string().nullable(); export const engineField = z.object({id: z.number().int(), url: z.string(), engine: z.string(), name: z.string(), label: z.string(), type: z.enum(["string", "number", "date", "enum"]), subtype: z.string().nullable(), pre_trained_field_id: z.string().nullable(), tabular: z.boolean(), multiline: z.enum(["true", "false"]), created_by: z.string().nullable(), created_at: z.string().nullable(), modified_by: modifiedBy, modified_at: modifiedAt}); export const getApiApiV1EngineFieldsResponse = z.object({pagination: pagination, results: z.array(engineField)}); 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 engine fields * * GET /api/v1/engine_fields */ export const getApiApiV1EngineFields = async (args: GetApiApiV1EngineFieldsArgs, options?: GetApiApiV1EngineFieldsOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.id != null) query.append("id", args.id.join(',')) if (args.engine != null) query.append("engine", String(args.engine)) if (args.name != null) query.append("name", String(args.name)) if (args.used != null) query.append("used", String(args.used)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/engine_fields${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(getApiApiV1EngineFieldsResponse, await res.json()) };