export type GetApiApiV2EventsCollectionSlugArgs = {slug: string, after?: number | undefined, before?: number | undefined, event_type?: (Array<'sale' | 'transfer' | 'mint' | 'listing' | 'offer' | 'trait_offer' | 'collection_offer'>) | undefined, traits?: string | undefined, limit?: number | undefined, next?: string | undefined}; export type GetApiApiV2EventsCollectionSlugOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get events (by collection) * * GET /api/v2/events/collection/{slug} */ export const getApiApiV2EventsCollectionSlug = async (args: GetApiApiV2EventsCollectionSlugArgs, options?: GetApiApiV2EventsCollectionSlugOptions) => { const {baseUrl = "https://api.opensea.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "*/*") if (args.after != null) query.append("after", String(args.after)) if (args.before != null) query.append("before", String(args.before)) for (const item of args.event_type ?? []) query.append("event_type", String(item)) if (args.traits != null) query.append("traits", String(args.traits)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.next != null) query.append("next", String(args.next)) if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/events/collection/${encodeURIComponent(String(args.slug))}${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 res.blob() };