import {z} from 'zod' export type DuplicateRequest = {name: string}; export type CreateApiApiV1EnginesEngineIDDuplicateArgs = {engineID: number, body: DuplicateRequest}; export type CreateApiApiV1EnginesEngineIDDuplicateOptions = {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 }; /** * Duplicate engine * * POST /api/v1/engines/{engineID}/duplicate */ export const createApiApiV1EnginesEngineIDDuplicate = async (args: CreateApiApiV1EnginesEngineIDDuplicateArgs, options?: CreateApiApiV1EnginesEngineIDDuplicateOptions) => { 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))}/duplicate${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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()) };