import {z} from 'zod' export type GetApiV0TokenBulkExportJobsJobIdArgs = {job_id: string}; export type GetApiV0TokenBulkExportJobsJobIdOptions = {baseUrl?: string | undefined, APIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const jobStatus = z.enum(["queued", "running", "succeeded", "failed"]); export const tokenScanSupportedChains = z.enum(["arbitrum", "avalanche", "base", "bsc", "ethereum", "optimism", "polygon", "zora", "solana", "starknet", "starknet-sepolia", "stellar", "linea", "degen", "zksync", "scroll", "blast", "soneium-minato", "base-sepolia", "bitcoin", "abstract", "soneium", "ink", "berachain", "unichain", "ronin", "sui", "hedera", "hyperevm", "xlayer", "monad", "megaeth", "tempo", "sei", "kaia", "tron", "robinhood", "flare", "arc"]); export const bulkExportJobStatusResponse = z.object({status: jobStatus, files: z.array(z.string()).nullable().optional(), expires_in: z.number().int().nullable().optional(), chain: tokenScanSupportedChains.nullable().optional(), tokens_count: z.number().int().nullable().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 }; /** * Get Job Status * * GET /v0/token/bulk-export/jobs/{job_id} * * Also accepts auth: ClientID */ export const getApiV0TokenBulkExportJobsJobId = async (args: GetApiV0TokenBulkExportJobsJobIdArgs, options?: GetApiV0TokenBulkExportJobsJobIdOptions) => { const {baseUrl = "https://api.blockaid.io", fetch: fetchFn = fetch, APIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKey !== undefined) headers.set("X-API-Key", APIKey) const url = `${baseUrl.replace(/\/+$/, '')}/v0/token/bulk-export/jobs/${encodeURIComponent(String(args.job_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(bulkExportJobStatusResponse, await res.json()) };