import {z} from 'zod' export type GetApiPaymentsPreChargebackAlertsAlertsArgs = {status?: ('ACTION_REQUIRED' | 'RESOLVED' | 'INVALID') | undefined, merchantId?: string | undefined, alertReceivedAtGte?: string | undefined, alertReceivedAtLte?: string | undefined, sort?: ('-alertReceivedAt' | 'alertReceivedAt' | '-actionRequiredDeadline' | 'actionRequiredDeadline') | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiPaymentsPreChargebackAlertsAlertsOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const preChargebackAlert = z.object({id: z.string(), merchantId: z.string(), alertType: z.enum(["ETHOCA_ALERT", "VERIFI_RDR"]), alertNetworkId: z.string().nullable().optional(), status: z.enum(["ACTION_REQUIRED", "RESOLVED", "INVALID"]), chargebackReasonCode: z.string().nullable().optional(), transactionAmountInCents: z.number().int().nullable().optional(), transactionCurrencyCode: z.string().nullable().optional(), transactionAuthorizedAt: z.string().nullable().optional(), actionRequiredDeadline: z.string().nullable().optional(), transactionAuthorizationCode: z.string().nullable().optional(), transactionAcquirerReferenceNumber: z.string().nullable().optional(), transactionStatementDescriptor: z.string().nullable().optional(), transactionCardBin: z.string().nullable().optional(), card: z.object({bin: z.string().nullable().optional(), lastFour: z.string().nullable().optional(), brand: z.string().nullable().optional(), issuer: z.string().nullable().optional()}).nullable().optional(), transactionRefundOutcome: z.enum(["REFUNDED", "NOT_REFUNDED", "null"]).nullable().optional(), transactionNetworkId: z.string().nullable().optional(), subscriptionCancelOutcome: z.string().nullable().optional(), note: z.string().nullable().optional(), integrationId: z.string().nullable().optional(), integrationTransactionId: z.string().nullable().optional(), createdAt: z.string()}); export const getApiPaymentsPreChargebackAlertsAlertsResponse = z.object({items: z.array(preChargebackAlert), count: z.number().int()}); 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 }; /** * List Pre-Chargeback Alerts * * GET /payments/pre-chargeback-alerts/alerts */ export const getApiPaymentsPreChargebackAlertsAlerts = async (args: GetApiPaymentsPreChargebackAlertsAlertsArgs, options?: GetApiPaymentsPreChargebackAlertsAlertsOptions) => { const {baseUrl = "https://api.evervault.com", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.merchantId != null) query.append("merchantId", String(args.merchantId)) if (args.alertReceivedAtGte != null) query.append("alertReceivedAtGte", String(args.alertReceivedAtGte)) if (args.alertReceivedAtLte != null) query.append("alertReceivedAtLte", String(args.alertReceivedAtLte)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/payments/pre-chargeback-alerts/alerts${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(getApiPaymentsPreChargebackAlertsAlertsResponse, await res.json()) };