import {z} from 'zod' export type GetApiApiV1JobsJobIdDownloadArgs = {job_id: string, file_id: string, node_id?: (string | null) | undefined, 'unstructured-api-key'?: (string | null) | undefined}; export type GetApiApiV1JobsJobIdDownloadOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiApiV1JobsJobIdDownloadResponse = z.unknown(); 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 }; /** * Download Job output * * GET /api/v1/jobs/{job_id}/download */ export const getApiApiV1JobsJobIdDownload = async (args: GetApiApiV1JobsJobIdDownloadArgs, options: GetApiApiV1JobsJobIdDownloadOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.file_id != null) query.append("file_id", String(args.file_id)) if (args.node_id != null) query.append("node_id", String(args.node_id)) if (args['unstructured-api-key'] != null) headers.set("unstructured-api-key", String(args['unstructured-api-key'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/jobs/${encodeURIComponent(String(args.job_id))}/download${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(getApiApiV1JobsJobIdDownloadResponse, await res.json()) };