import {z} from 'zod' export type CustomerCorrespondence = {contactDateTime?: (string | null) | undefined, contactDescription?: (string | null) | undefined, contactId: string, contactReason?: ('CANCELING' | 'EXCHANGE' | 'SICKNESS' | 'NAME_CHANGE' | 'INR' | 'OTHER' | null) | undefined}; export type ProofOfCreditBalance = {amount?: (number | null) | undefined, appliedDate: string, currency?: (string | null) | undefined}; export type ProofOfDelivery = {carrier?: (string | null) | undefined, date?: (string | null) | undefined, deliveryStatus?: (string | null) | undefined, didCustomerSignForDelivery?: (boolean | null) | undefined, trackingNumber?: (string | null) | undefined}; export type ProofOfPickup = {pickupDate?: (string | null) | undefined, providedIdentityVerificationMethods?: (Array<'PERSONAL_ID' | 'EMAIL_RECEIPT' | 'PAYMENT_METHOD' | 'ORDER_NUMBER'> | null) | undefined, status: 'NOT_PICKED_UP' | 'PICKED_UP'}; export type ProofOfRefund = {refundAmount?: (number | null) | undefined, refundAuthorizationCode?: (string | null) | undefined, refundChargeId?: (string | null) | undefined, refundCurrency?: (string | null) | undefined, refundDate?: (string | null) | undefined, refundTransactionId: string, replacementItems?: (Array | null) | undefined}; export type ProofOfReplacement = {replacementAmount?: (number | null) | undefined, replacementCurrency?: (string | null) | undefined, replacementDate?: (string | null) | undefined, replacementId: string, replacementItems?: (Array | null) | undefined, replacementTrackingNumber?: (string | null) | undefined, shippingCarrier?: (string | null) | undefined}; export type SubscriptionDetails = {billingAgreementPolicy?: (string | null) | undefined, isRecurringCharge: boolean}; export type DisputeEvidenceDatapointsRequestRequest = {airlineTicketNumbers?: (Array | null) | undefined, customerCorrespondences?: (Array | null) | undefined, itemsHeldInCustoms?: (Array | null) | undefined, orderId?: (string | null) | undefined, processorCaseNumber?: (string | null) | undefined, processorChargeId?: (string | null) | undefined, proofsOfCreditBalance?: (Array | null) | undefined, proofsOfDelivery?: (Array | null) | undefined, proofsOfPickup?: (Array | null) | undefined, proofsOfRefund?: (Array | null) | undefined, proofsOfReplacement?: (Array | null) | undefined, reservationIds?: (Array | null) | undefined, subscriptionDetails?: (Array | null) | undefined}; export type CreateApiV3DisputesEvidenceDatapointsArgs = {'api-version': string, 'x-forter-siteid': string, Authorization: string, body: DisputeEvidenceDatapointsRequestRequest}; export type CreateApiV3DisputesEvidenceDatapointsOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const invalidEvidenceDataPoint = z.object({datapointPath: z.string(), failureReason: z.string().max(255)}); export const disputeEvidenceDatapointsResponse = z.object({invalidEvidenceDatapoints: z.array(invalidEvidenceDataPoint).nullable().optional(), 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 * * POST /v3/disputes/evidence/datapoints */ export const createApiV3DisputesEvidenceDatapoints = async (args: CreateApiV3DisputesEvidenceDatapointsArgs, options?: CreateApiV3DisputesEvidenceDatapointsOptions) => { 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/datapoints${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(disputeEvidenceDatapointsResponse, await res.json()) };