import {z} from 'zod' export type GetApiApiV1SkyboxBatchArgs = {status?: string | undefined, batch_id?: number | undefined, limit?: number | undefined, offset?: number | undefined, 'x-api-key'?: string | undefined}; export type GetApiApiV1SkyboxBatchOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1SkyboxBatchResponse = z.object({data: z.array(z.object({id: z.number().int().optional(), status: z.string().optional(), quantity: z.number().int().optional(), successfully_submitted: z.number().int().optional(), completed: z.number().int().optional(), errored: z.number().int().optional()})).optional(), totalCount: z.number().int().optional(), has_more: z.boolean().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 }; /** * List the authenticated user's batch generations. * * GET /api/v1/skybox/batch */ export const getApiApiV1SkyboxBatch = async (args: GetApiApiV1SkyboxBatchArgs, options?: GetApiApiV1SkyboxBatchOptions) => { const {baseUrl = "https://backend.blockadelabs.com", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.batch_id != null) query.append("batch_id", String(args.batch_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args['x-api-key'] != null) headers.set("x-api-key", String(args['x-api-key'])) if (defaultValue !== undefined) headers.set("x-api-key", defaultValue) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/skybox/batch${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(getApiApiV1SkyboxBatchResponse, await res.json()) };