import {z} from 'zod' export type GetApiV1DocumentsCollectionsCollectionIdUploadUploadedFileIdOptions = {baseUrl?: string | undefined, ClientID?: string | undefined, AccessKey?: string | undefined, fetch?: typeof fetch | undefined}; export const uploadedFileDetail = z.object({file_id: z.string(), filename: z.string().max(255), mime_type: z.enum(["application/pdf", "image/jpeg", "image/png", "image/tiff", "image/webp", "image/x-ms-bmp", "image/heic", "image/heif"]), validations: z.object({is_viable_size: z.boolean().nullable().optional(), is_supported_type: z.boolean().nullable().optional(), is_accessible: z.boolean().nullable().optional(), is_valid: z.boolean().nullable().optional(), is_readable: z.boolean().nullable().optional(), is_unique: z.boolean().nullable().optional()}).nullable().optional(), status: z.enum(["pending", "validating", "validated", "invalid", "duplicate", "processing", "successful", "failed"]), file_url: z.string(), user_id: z.string().max(32).nullable().optional(), external_user_id: z.string().max(512).nullable().optional(), created_at: z.string(), updated_at: z.string()}); 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 }; /** * Get uploaded file details * * GET /v1/documents/collections/{collection_id}/upload/{uploaded_file_id}/ */ export const getApiV1DocumentsCollectionsCollectionIdUploadUploadedFileId = async (options?: GetApiV1DocumentsCollectionsCollectionIdUploadUploadedFileIdOptions) => { const {baseUrl = "https://prod.truv.com", fetch: fetchFn = fetch, ClientID, AccessKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ClientID !== undefined) headers.set("X-Access-Client-Id", ClientID) if (AccessKey !== undefined) headers.set("X-Access-Secret", AccessKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/documents/collections/${encodeURIComponent(String(args.collection_id))}/upload/${encodeURIComponent(String(args.uploaded_file_id))}/${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(uploadedFileDetail, await res.json()) };