import {z} from 'zod' export type CreateApiApiV1AnnotationsAnnotationIDPageDataTranslateArgs = {annotationID: number, body: {page_numbers: Array, target_language: 'af' | 'sq' | 'am' | 'ar' | 'hy' | 'az' | 'bn' | 'bs' | 'bg' | 'ca' | 'zh' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'fa-AF' | 'nl' | 'en' | 'et' | 'fa' | 'tl' | 'fi' | 'fr' | 'fr-CA' | 'ka' | 'de' | 'el' | 'gu' | 'ht' | 'ha' | 'he' | 'hi' | 'hu' | 'is' | 'id' | 'ga' | 'it' | 'ja' | 'kn' | 'kk' | 'ko' | 'lv' | 'lt' | 'mk' | 'ms' | 'ml' | 'mt' | 'mr' | 'mn' | 'no' | 'ps' | 'pl' | 'pt' | 'pt-PT' | 'pa' | 'ro' | 'ru' | 'sr' | 'si' | 'sk' | 'sl' | 'so' | 'es' | 'es-MX' | 'sw' | 'sv' | 'ta' | 'te' | 'th' | 'tr' | 'uk' | 'ur' | 'uz' | 'vi' | 'cy', source_language?: ('auto' | 'af' | 'sq' | 'am' | 'ar' | 'hy' | 'az' | 'bn' | 'bs' | 'bg' | 'ca' | 'zh' | 'zh-TW' | 'hr' | 'cs' | 'da' | 'fa-AF' | 'nl' | 'en' | 'et' | 'fa' | 'tl' | 'fi' | 'fr' | 'fr-CA' | 'ka' | 'de' | 'el' | 'gu' | 'ht' | 'ha' | 'he' | 'hi' | 'hu' | 'is' | 'id' | 'ga' | 'it' | 'ja' | 'kn' | 'kk' | 'ko' | 'lv' | 'lt' | 'mk' | 'ms' | 'ml' | 'mt' | 'mr' | 'mn' | 'no' | 'ps' | 'pl' | 'pt' | 'pt-PT' | 'pa' | 'ro' | 'ru' | 'sr' | 'si' | 'sk' | 'sl' | 'so' | 'es' | 'es-MX' | 'sw' | 'sv' | 'ta' | 'te' | 'th' | 'tr' | 'uk' | 'ur' | 'uz' | 'vi' | 'cy') | undefined, granularity: 'lines'}}; export type CreateApiApiV1AnnotationsAnnotationIDPageDataTranslateOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiApiV1AnnotationsAnnotationIDPageDataTranslateResponse = z.object({results: z.array(z.object({page_number: z.number().int().optional(), granularity: z.string().optional(), source_language: z.string().optional(), items: z.array(z.object({text: z.string().optional(), position: z.array(z.number().int()).optional()})).optional()})).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 }; /** * Translate page spatial data * * POST /api/v1/annotations/{annotationID}/page_data/translate */ export const createApiApiV1AnnotationsAnnotationIDPageDataTranslate = async (args: CreateApiApiV1AnnotationsAnnotationIDPageDataTranslateArgs, options?: CreateApiApiV1AnnotationsAnnotationIDPageDataTranslateOptions) => { 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/annotations/${encodeURIComponent(String(args.annotationID))}/page_data/translate${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(createApiApiV1AnnotationsAnnotationIDPageDataTranslateResponse, await res.json()) };