import {z} from 'zod' export type ModifiedBy = string | null; export type ModifiedAt = string | null; export type EngineFieldBase = {id?: number | undefined, url?: string | undefined, engine?: string | undefined, name?: string | undefined, label?: string | undefined, type?: ('string' | 'number' | 'date' | 'enum') | undefined, subtype?: (string | null) | undefined, pre_trained_field_id?: (string | null) | undefined, tabular?: boolean | undefined, multiline?: ('true' | 'false') | undefined, created_by?: (string | null) | undefined, created_at?: (string | null) | undefined, modified_by?: ModifiedBy | undefined, modified_at?: ModifiedAt | undefined}; export type UpdateApiApiV1EngineFieldsEngineFieldIDArgs = {engineFieldID: number, body: EngineFieldBase}; export type UpdateApiApiV1EngineFieldsEngineFieldIDOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; 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 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 }; /** * Update engine field * * PUT /api/v1/engine_fields/{engineFieldID} */ export const updateApiApiV1EngineFieldsEngineFieldID = async (args: UpdateApiApiV1EngineFieldsEngineFieldIDArgs, options?: UpdateApiApiV1EngineFieldsEngineFieldIDOptions) => { const {baseUrl = "https://example.rossum.app", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/engine_fields/${encodeURIComponent(String(args.engineFieldID))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(engineField, await res.json()) };