import {z} from 'zod' export type DisputeEvidenceFileRequestRequest = {evidenceType: 'ACCEPTANCE_OF_RECURRING_BILLING_AGREEMENT' | 'AUTHENTICATION_CERTIFICATE' | 'BUYER_REVIEW_SURVEY' | 'CARDHOLDER_VERIFICATION_DOCUMENT' | 'CHARGEBACK_NOTIFICATION' | 'CONTRACT_PAGE' | 'CREDIT_BALANCE' | 'CUSTOMER_CORRESPONDENCE' | 'DELAY_DISCLOSURE' | 'DISPUTE_LETTER' | 'EMAIL_CONFIRMATION' | 'FLIGHT_MANIFEST' | 'HOTEL_NO_SHOW' | 'INVOICE' | 'OTHER' | 'PASSENGER_OR_CUSTOMER_DETAILS' | 'PROOF_OF_DELIVERY' | 'PROOF_OF_ORDER_REPLACEMENT' | 'PROOF_OF_POSSESSION_OR_USAGE' | 'PROOF_OF_RECURRING_AGREEMENT_NOTICE' | 'PROOF_OF_REFUND' | 'PROOF_OF_REQUESTED_CANCELLATION' | 'PROOF_OF_RESIDENCE' | 'PURCHASE_HELD_IN_CUSTOMS' | 'RECEIPT' | 'RECURRING_BILLING_AGREEMENT' | 'RELATED_INVOICE_HISTORY' | 'SIGNED_DELIVERY_FORM' | 'SIGNED_ORDER_FORM' | 'SOCIAL_NETWORK_REPUTATION' | 'STATEMENT_OF_UNAUTHORIZED_DEBIT' | 'TERMS_AND_CONDITIONS' | 'USER_TERMS_AND_CONDITION_ACCEPTANCE', filePath: string, orderId?: (string | null) | undefined, processorCaseNumber?: (string | null) | undefined, processorChargeId?: (string | null) | undefined}; export type CreateApiV3DisputesEvidenceFileArgs = {'api-version': string, 'x-forter-siteid': string, Authorization: string, body: DisputeEvidenceFileRequestRequest}; export type CreateApiV3DisputesEvidenceFileOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const disputeEvidenceFileResponse = z.object({message: z.enum(["EVIDENCE_UPLOADED", "SERVICE_UNAVAILABLE", "SCHEMA_VALIDATION_FAILED", "CLAIM_NOT_FOUND"]).max(1000), status: z.enum(["SUCCESS", "FAILED"]).max(50)}); 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 }; /** * Evidence file upload * * POST /v3/disputes/evidence/file */ export const createApiV3DisputesEvidenceFile = async (args: CreateApiV3DisputesEvidenceFileArgs, options?: CreateApiV3DisputesEvidenceFileOptions) => { const {baseUrl = "https://api.forter-secure.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['api-version'] != null) headers.set("api-version", String(args['api-version'])) if (args['x-forter-siteid'] != null) headers.set("x-forter-siteid", String(args['x-forter-siteid'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/disputes/evidence/file${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(disputeEvidenceFileResponse, await res.json()) };