import {z} from 'zod' export type GetApiV1ShopsShopIdDisputesArgs = {body: {page?: (number | null) | undefined, perPage?: (number | null) | undefined, statuses?: (Array<'needs_response' | 'under_review' | 'won' | 'lost' | 'accepted' | 'expired' | 'prevented' | 'canceled' | 'closed'>) | undefined, reasons?: Array | undefined, gateways?: Array | undefined, due?: ('24h' | '72h' | '7d' | null) | undefined, search?: (string | null) | undefined, opened_at_start?: (string | null) | undefined, opened_at_end?: (string | null) | undefined, closed_at_start?: (string | null) | undefined, closed_at_end?: (string | null) | undefined, orderColumn?: ('id' | 'opened_at' | 'evidence_due_at' | 'amount_usd' | null) | undefined, orderDirection?: ('asc' | 'desc' | null) | undefined, warnings?: (boolean | null) | undefined}}; export type GetApiV1ShopsShopIdDisputesOptions = {baseUrl?: string | undefined, defaultValue?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV1ShopsShopIdDisputesResponse = z.object({current_page: z.number().int().optional(), data: z.array(z.object({id: z.number().int().optional(), shop_id: z.number().int().optional(), invoice_id: z.number().int().optional(), payment_id: z.string().nullable().optional(), payment_method_id: z.string().nullable().optional(), gateway: z.string().optional(), gateway_dispute_id: z.string().optional(), gateway_payment_ref: z.string().optional(), stage: z.string().optional(), status: z.string().optional(), is_final: z.boolean().optional(), funds_status: z.string().optional(), reason: z.string().optional(), contestable: z.boolean().optional(), gateway_status: z.string().optional(), gateway_substatus: z.string().nullable().optional(), gateway_reason: z.string().optional(), network_reason_code: z.string().optional(), card_brand: z.string().optional(), amount: z.string().optional(), currency: z.string().optional(), amount_usd: z.string().optional(), fee: z.string().optional(), fee_currency: z.string().optional(), fee_usd: z.string().optional(), is_partial: z.boolean().optional(), evidence_due_at: z.string().optional(), opened_at: z.string().optional(), responded_at: z.string().nullable().optional(), closed_at: z.string().nullable().optional(), gateway_updated_at: z.string().optional(), gateway_version: z.string().nullable().optional(), fetched: z.boolean().optional(), invoice_status_before: z.string().nullable().optional(), invoice_flipped_at: z.string().nullable().optional(), livemode: z.boolean().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), invoice: z.object({id: z.number().int().optional(), salt: z.string().optional(), email: z.string().optional(), price: z.string().optional(), currency: z.string().optional(), status: z.string().optional(), gateway: z.string().optional(), unique_id: z.string().optional()}).optional()})).optional(), first_page_url: z.string().optional(), from: z.number().int().optional(), last_page: z.number().int().optional(), last_page_url: z.string().optional(), links: z.array(z.object({url: z.string().nullable().optional(), label: z.string().optional(), page: z.string().nullable().optional(), active: z.boolean().optional()})).optional(), next_page_url: z.string().nullable().optional(), path: z.string().optional(), per_page: z.number().int().optional(), prev_page_url: z.string().nullable().optional(), to: z.number().int().optional(), total: z.number().int().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 }; /** * Get Disputes * * GET /v1/shops/{shopId}/disputes */ export const getApiV1ShopsShopIdDisputes = async (args: GetApiV1ShopsShopIdDisputesArgs, options?: GetApiV1ShopsShopIdDisputesOptions) => { const {baseUrl = "https://api.sellauth.com", fetch: fetchFn = fetch, defaultValue} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (defaultValue !== undefined) headers.set('authorization', `Bearer ${defaultValue}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/shops/${encodeURIComponent(String(args.shopId))}/disputes${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", 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(getApiV1ShopsShopIdDisputesResponse, await res.json()) };