import {z} from 'zod' export type GetApiAtomicassetsV1CollectionsArgs = {author?: string | undefined, match?: string | undefined, authorized_account?: string | undefined, notify_account?: string | undefined, collection_blacklist?: string | undefined, collection_whitelist?: string | undefined, collection_name?: string | undefined, ids?: string | undefined, lower_bound?: string | undefined, upper_bound?: string | undefined, before?: number | undefined, after?: number | undefined, page?: number | undefined, limit?: number | undefined, order?: ('asc' | 'desc') | undefined, sort?: ('created' | 'collection_name') | undefined}; export type GetApiAtomicassetsV1CollectionsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const collection = z.object({contract: z.string().optional(), collection_name: z.string().optional(), name: z.string().optional(), author: z.string().optional(), allow_notify: z.boolean().optional(), authorized_accounts: z.array(z.string()).optional(), notify_accounts: z.array(z.string()).optional(), market_fee: z.number().optional(), data: z.object({}).optional(), created_at_block: z.string().optional(), created_at_time: z.string().optional()}); export const getApiAtomicassetsV1CollectionsResponse = z.object({success: z.boolean().optional(), data: z.array(collection).optional(), query_time: 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 }; /** * Fetch collections * * GET /atomicassets/v1/collections */ export const getApiAtomicassetsV1Collections = async (args: GetApiAtomicassetsV1CollectionsArgs, options?: GetApiAtomicassetsV1CollectionsOptions) => { const {baseUrl = "https://atomic.3dkrender.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.author != null) query.append("author", String(args.author)) if (args.match != null) query.append("match", String(args.match)) if (args.authorized_account != null) query.append("authorized_account", String(args.authorized_account)) if (args.notify_account != null) query.append("notify_account", String(args.notify_account)) if (args.collection_blacklist != null) query.append("collection_blacklist", String(args.collection_blacklist)) if (args.collection_whitelist != null) query.append("collection_whitelist", String(args.collection_whitelist)) if (args.collection_name != null) query.append("collection_name", String(args.collection_name)) if (args.ids != null) query.append("ids", String(args.ids)) if (args.lower_bound != null) query.append("lower_bound", String(args.lower_bound)) if (args.upper_bound != null) query.append("upper_bound", String(args.upper_bound)) if (args.before != null) query.append("before", String(args.before)) if (args.after != null) query.append("after", String(args.after)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.order != null) query.append("order", String(args.order)) if (args.sort != null) query.append("sort", String(args.sort)) const url = `${baseUrl.replace(/\/+$/, '')}/atomicassets/v1/collections${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(getApiAtomicassetsV1CollectionsResponse, await res.json()) };