export type CollectionObject = {slug: string}; export type NumericTraitCriteria = {max?: (number | null) | undefined, min?: (number | null) | undefined, type: string}; export type TraitObject = {type: string, value: string}; export type CriteriaObject = {collection: CollectionObject, numericTraits?: Array | undefined, trait?: TraitObject | undefined, traits?: Array | undefined}; export type BuildOfferRequest = {criteria: CriteriaObject, offer_protection_enabled: boolean, offerer: string, protocol_address: string, quantity: number}; export type CreateApiApiV2OffersBuildArgs = {body: BuildOfferRequest}; export type CreateApiApiV2OffersBuildOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Build a criteria offer * * POST /api/v2/offers/build */ export const createApiApiV2OffersBuild = async (args: CreateApiApiV2OffersBuildArgs, options?: CreateApiApiV2OffersBuildOptions) => { const {baseUrl = "https://api.opensea.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/offers/build${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };