import {z} from 'zod' export type CreateApiAgentCommerceV1PayArgs = {body: {quote_id: string} | {artworkSlug: string, buyerEmail: string, payer: string, network?: ('eip155:8453' | 'eip155:137' | 'eip155:42161' | 'eip155:480' | 'eip155:143' | 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') | undefined, shipping: {firstName: string, lastName: string, address1: string, address2?: string | undefined, city: string, state?: string | undefined, postalCode?: string | undefined, phone?: string | undefined, country: string}} | Record}; export type CreateApiAgentCommerceV1PayOptions = {baseUrl?: string | undefined, agentBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiAgentCommerceV1PayResponse = z.object({}); 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 }; /** * Pay an owned quote using a stable Bazaar resource URL. When public quote discovery is enabled, an unsigned anonymous artwork quote request returns 402 and checkout credentials. Empty probes return an example quote, not authorization to spend. Submit actual buyer details before signing; payment retries require the returned bearer credential and quote_id. Echo extensions unchanged; never put private quote details in discovery metadata. * * POST /agent-commerce/v1/pay */ export const createApiAgentCommerceV1Pay = async (args: CreateApiAgentCommerceV1PayArgs, options?: CreateApiAgentCommerceV1PayOptions) => { const {baseUrl = "https://mondoir.art", fetch: fetchFn = fetch, agentBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (agentBearer !== undefined) headers.set('authorization', `Bearer ${agentBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/agent-commerce/v1/pay${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 validateResponse(createApiAgentCommerceV1PayResponse, await res.json()) };