import {z} from 'zod' export type CreateApiDisputesIdResponseArgs = {id: string, Authorization: string, body: {forfeit: boolean, additional_statement?: string | undefined, cancellation_policy_disclosure?: string | undefined, cancellation_rebuttal?: string | undefined, customer_billing_address?: string | undefined, customer_email_address?: string | undefined, customer_name?: string | undefined, customer_purchase_ip_address?: string | undefined, duplicate_charge_explanation?: string | undefined, product_description?: string | undefined, refund_policy_disclosure?: string | undefined, refund_refusal_explanation?: string | undefined, service_date?: string | undefined, shipping_address?: string | undefined, shipping_carrier?: string | undefined, shipping_date?: string | undefined, shipping_tracking_number?: string | undefined, duplicate_charge_original_payment_id?: string | undefined}}; export type CreateApiDisputesIdResponseOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiDisputesIdResponseResponse = z.object({id: z.string().optional(), type: z.string().optional(), data: z.object({id: z.string().optional(), payment_id: z.string().optional(), account_id: z.string().optional(), amount: z.number().optional(), currency: z.enum(["usd", "cad"]).optional(), reason: z.string().optional(), due_date: z.string().optional(), status: z.enum(["needs_response", "under_review", "won", "lost"]).optional(), metadata: z.object({}).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), dispute_response: z.object({additional_statement: z.string().optional(), cancellation_policy_disclosure: z.string().optional(), cancellation_rebuttal: z.string().optional(), customer_billing_address: z.string().optional(), customer_email_address: z.string().optional(), customer_name: z.string().optional(), customer_purchase_ip_address: z.string().optional(), duplicate_charge_explanation: z.string().optional(), product_description: z.string().optional(), refund_policy_disclosure: z.string().optional(), refund_refusal_explanation: z.string().optional(), service_date: z.string().optional(), shipping_address: z.string().optional(), shipping_carrier: z.string().optional(), shipping_date: z.string().optional(), shipping_tracking_number: z.string().optional(), duplicate_charge_original_payment_id: z.string().optional()}).nullable().optional(), dispute_reversal: z.object({description: z.string().optional(), created_at: z.string().optional()}).nullable().optional()}).optional(), page_info: z.unknown()}); 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 }; /** * Submit dispute response * * POST /disputes/{id}/response */ export const createApiDisputesIdResponse = async (args: CreateApiDisputesIdResponseArgs, options?: CreateApiDisputesIdResponseOptions) => { const {baseUrl = "https://api.justifi.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) const url = `${baseUrl.replace(/\/+$/, '')}/disputes/${encodeURIComponent(String(args.id))}/response${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(createApiDisputesIdResponseResponse, await res.json()) };