import {z} from 'zod' export type OrganizationUrl = string; export type CreatedBy = string | null; export type CreatedAt = string; export type ModifiedBy = string | null; export type ModifiedAt = string | null; export type EngineBase = {id?: number | undefined, url?: string | undefined, name?: string | undefined, type?: ('extractor' | 'splitter') | undefined, learning_enabled?: boolean | undefined, description?: string | undefined, agenda_id?: string | undefined, organization?: OrganizationUrl | undefined, training_queues?: (Array | null) | undefined, settings?: ({use_case?: ('generic_ap' | 'coupa_line_level' | 'coupa_header_level') | undefined}) | undefined, created_by?: CreatedBy | undefined, created_at?: CreatedAt | undefined, modified_by?: ModifiedBy | undefined, modified_at?: ModifiedAt | undefined}; export type PatchApiApiV1EnginesEngineIDArgs = {engineID: number, body: EngineBase}; export type PatchApiApiV1EnginesEngineIDOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const organizationUrl = z.string(); export const createdBy = z.string().nullable(); export const createdAt = z.string(); export const modifiedBy = z.string().nullable(); export const modifiedAt = z.string().nullable(); export const engine = z.object({id: z.number().int(), url: z.string(), name: z.string(), type: z.enum(["extractor", "splitter"]), learning_enabled: z.boolean(), description: z.string(), agenda_id: z.string(), organization: organizationUrl, training_queues: z.array(z.string()).nullable(), settings: z.object({use_case: z.enum(["generic_ap", "coupa_line_level", "coupa_header_level"]).optional()}), created_by: createdBy, created_at: createdAt, 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 }; /** * Partial update engine * * PATCH /api/v1/engines/{engineID} */ export const patchApiApiV1EnginesEngineID = async (args: PatchApiApiV1EnginesEngineIDArgs, options?: PatchApiApiV1EnginesEngineIDOptions) => { 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/engines/${encodeURIComponent(String(args.engineID))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(engine, await res.json()) };