import {z} from 'zod' export type FileRenameRequest = {filename: string}; export type PatchApiFilesFileIdArgs = {file_id: string, body: FileRenameRequest}; export type PatchApiFilesFileIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const fileSummary = z.object({attachment_url: z.string().optional(), bytes_transferred: z.number().int().optional(), capture_error: z.string().optional(), capture_state: z.enum(["detected", "uploading", "ready", "skipped_size", "skipped_quota", "skipped_type", "dropped_teardown", "failed"]).optional(), checksum: z.string().optional(), created_at: z.string(), display_url: z.string().optional(), download_url: z.string().optional(), duration_seconds: z.number().int().optional(), filename: z.string(), height: z.number().int().optional(), id: z.string(), message_id: z.string().optional(), mime_type: z.string(), on_phone_count: z.number().int(), phone_id: z.string().optional(), preview_state: z.enum(["processing", "ready", "unavailable"]), reel_url: z.string().optional(), session_id: z.string().optional(), size_bytes: z.number().int(), source: z.enum(["upload", "capture", "message"]), status: z.enum(["uploading", "ready"]), surface: z.literal("phone").optional(), thumbnail_url: z.string().optional(), width: z.number().int().optional()}); export const renameFileOutputBody = z.object({file: fileSummary}); 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 }; /** * Update a file * * PATCH /files/{file_id} */ export const patchApiFilesFileId = async (args: PatchApiFilesFileIdArgs, options?: PatchApiFilesFileIdOptions) => { const {baseUrl = "https://api.axilio.ai/api/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/files/${encodeURIComponent(String(args.file_id))}${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(renameFileOutputBody, await res.json()) };