export type CollectionCriteria = {slug: string}; export type ContractCriteria = {address: string}; export type NumericTraitCriteria = {max?: (number | null) | undefined, min?: (number | null) | undefined, type: string}; export type TraitCriteria = {type: string, value: string}; export type CriteriaRequest = {collection: CollectionCriteria, contract?: (ContractCriteria | null) | undefined, numericTraits?: (Array | null) | undefined, trait?: (TraitCriteria | null) | undefined, traits?: (Array | null) | undefined}; export type ConsiderationItem = {endAmount: string, identifierOrCriteria: string, itemType: number, recipient: string, startAmount: string, token: string}; export type OfferItem = {endAmount: string, identifierOrCriteria: string, itemType: number, startAmount: string, token: string}; export type SeaportParameters = {conduitKey: string, consideration: Array, counter: string, endTime: string, offer: Array, offerer: string, orderType: number, salt: string, startTime: string, totalOriginalConsiderationItems: number, zone?: string | undefined, zoneHash: string}; export type SeaportProtocolDataModel = {parameters: SeaportParameters, signature: string}; export type OfferWithCriteriaRequest = {criteria: CriteriaRequest, protocol_address: string, protocol_data: SeaportProtocolDataModel}; export type CreateApiApiV2OffersArgs = {body: OfferWithCriteriaRequest}; export type CreateApiApiV2OffersOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a criteria offer * * POST /api/v2/offers */ export const createApiApiV2Offers = async (args: CreateApiApiV2OffersArgs, options?: CreateApiApiV2OffersOptions) => { 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${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() };