import {z} from 'zod' export type PatchApiDisputesIdResponseArgs = {id: string, Authorization: string, body: {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 PatchApiDisputesIdResponseOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiDisputesIdResponseResponse = z.object({id: z.string().optional(), type: z.string().optional(), data: 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()}).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 }; /** * Update dispute response * * PATCH /disputes/{id}/response */ export const patchApiDisputesIdResponse = async (args: PatchApiDisputesIdResponseArgs, options?: PatchApiDisputesIdResponseOptions) => { 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: "PATCH", 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(patchApiDisputesIdResponseResponse, await res.json()) };