import {z} from 'zod' export type GetApiDisputeDisputesAlertsAlertIdArgs = {alertId: string}; export type GetApiDisputeDisputesAlertsAlertIdOptions = {baseUrl?: string | undefined, BearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiDisputeDisputesAlertsAlertIdResponse = z.object({id: z.string(), createdAt: z.string(), updatedAt: z.string(), workspaceId: z.string().nullable().optional(), enrollmentId: z.string(), externalReference: z.string(), providerCreatedAt: z.string().nullable().optional(), program: z.enum(["Ethoca", "CDRN", "RDR", "SAFE", "TC40", "Discover", "AMEX", "JCB", "Unknown"]), alertType: z.string().nullable().optional(), amount: z.object({value: z.string(), currency: z.string()}), cardBIN: z.string().nullable().optional(), cardLast4: z.string().nullable().optional(), network: z.string().nullable().optional(), descriptor: z.string().nullable().optional(), arn: z.string().nullable().optional(), authCode: z.string().nullable().optional(), transactionDate: z.string().nullable().optional(), expiresAt: z.string().nullable().optional(), paymentId: z.string().nullable().optional(), matchState: z.enum(["matched", "unmatched", "ambiguous", "retrying"]), status: z.enum(["Received", "Resolved", "Declined", "WillExpire", "Expired", "ActionFailed"]), reason: z.string().nullable().optional(), outcome: z.enum(["Resolved", "AlreadyRefunded", "AlreadyChargeback", "Ineligible", "MIDLost", "NotMyDescriptor", "EscalateChargeback", "TDS", "UnmatchedCannotFindTransaction"]).nullable().optional(), displayStatus: z.enum(["Processing", "ActionNeeded", "Ignored", "Refunded", "Expired", "Unrecognized"]).optional(), actionedVia: z.string().nullable().optional(), actionedByUserId: z.string().nullable().optional(), actionedAt: z.string().nullable().optional(), lastError: z.string().nullable().optional(), ruleset: z.string().nullable().optional(), disputeId: z.string().nullable().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 Dispute Alert by ID * * GET /dispute/disputes/alerts/{alertId} */ export const getApiDisputeDisputesAlertsAlertId = async (args: GetApiDisputeDisputesAlertsAlertIdArgs, options?: GetApiDisputeDisputesAlertsAlertIdOptions) => { const {baseUrl = "https://api.staging.payrails.io", fetch: fetchFn = fetch, BearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (BearerToken !== undefined) headers.set('authorization', `Bearer ${BearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/dispute/disputes/alerts/${encodeURIComponent(String(args.alertId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiDisputeDisputesAlertsAlertIdResponse, await res.json()) };