import {z} from 'zod' export type GetApiPhonesSessionsSessionIdFilesArgs = {session_id: string, limit?: number | undefined, offset?: number | undefined, search?: string | undefined, mime_type?: string | undefined, min_size_bytes?: number | undefined, max_size_bytes?: number | undefined, created_after?: string | undefined, created_before?: string | undefined}; export type GetApiPhonesSessionsSessionIdFilesOptions = {baseUrl: string, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const fileSummary = z.object({$schema: z.string().optional(), 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 fileUsage = z.object({byte_limit: z.number().int(), file_count: z.number().int(), file_limit: z.number().int(), total_bytes: z.number().int()}); export const fileListResponse = z.object({$schema: z.string().optional(), files: z.array(fileSummary).nullable(), total: z.number().int(), usage: fileUsage}); 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 }; /** * List a session's captured files * * GET /phones/sessions/{session_id}/files */ export const getApiPhonesSessionsSessionIdFiles = async (args: GetApiPhonesSessionsSessionIdFilesArgs, options: GetApiPhonesSessionsSessionIdFilesOptions) => { const {baseUrl, fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.search != null) query.append("search", String(args.search)) if (args.mime_type != null) query.append("mime_type", String(args.mime_type)) if (args.min_size_bytes != null) query.append("min_size_bytes", String(args.min_size_bytes)) if (args.max_size_bytes != null) query.append("max_size_bytes", String(args.max_size_bytes)) if (args.created_after != null) query.append("created_after", String(args.created_after)) if (args.created_before != null) query.append("created_before", String(args.created_before)) if (apiKeyAuth !== undefined) headers.set("X-Axilio-Api-Key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/phones/sessions/${encodeURIComponent(String(args.session_id))}/files${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(fileListResponse, await res.json()) };