import {z} from 'zod' export type GetApiV1FinancialAccountsFinancialAccountTokenFinancialTransactionsArgs = {category?: ('ACH' | 'CARD' | 'INTERNAL' | 'TRANSFER') | undefined, result?: ('APPROVED' | 'DECLINED') | undefined, status?: ('DECLINED' | 'EXPIRED' | 'PENDING' | 'RETURNED' | 'SETTLED' | 'VOIDED') | undefined, begin?: string | undefined, end?: string | undefined, ending_before?: string | undefined, financial_account_token: string, page_size?: number | undefined, starting_after?: string | undefined}; export type GetApiV1FinancialAccountsFinancialAccountTokenFinancialTransactionsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const financialEventType = z.enum(["ACH_ORIGINATION_CANCELLED", "ACH_ORIGINATION_INITIATED", "ACH_ORIGINATION_PROCESSED", "ACH_ORIGINATION_RELEASED", "ACH_ORIGINATION_REJECTED", "ACH_ORIGINATION_REVIEWED", "ACH_ORIGINATION_SETTLED", "ACH_RECEIPT_PROCESSED", "ACH_RECEIPT_RELEASED", "ACH_RECEIPT_SETTLED", "ACH_RETURN_INITIATED", "ACH_RETURN_PROCESSED", "ACH_RETURN_REJECTED", "ACH_RETURN_SETTLED", "AUTHORIZATION", "AUTHORIZATION_ADVICE", "AUTHORIZATION_EXPIRY", "AUTHORIZATION_REVERSAL", "BALANCE_INQUIRY", "BILLING_ERROR", "BILLING_ERROR_REVERSAL", "CARD_TO_CARD", "CASH_BACK", "CASH_BACK_REVERSAL", "CLEARING", "COLLECTION", "CORRECTION_CREDIT", "CORRECTION_DEBIT", "CREDIT_AUTHORIZATION", "CREDIT_AUTHORIZATION_ADVICE", "CURRENCY_CONVERSION", "CURRENCY_CONVERSION_REVERSAL", "DISPUTE_WON", "EXTERNAL_ACH_CANCELED", "EXTERNAL_ACH_INITIATED", "EXTERNAL_ACH_RELEASED", "EXTERNAL_ACH_REVERSED", "EXTERNAL_ACH_SETTLED", "EXTERNAL_CHECK_CANCELED", "EXTERNAL_CHECK_INITIATED", "EXTERNAL_CHECK_RELEASED", "EXTERNAL_CHECK_REVERSED", "EXTERNAL_CHECK_SETTLED", "EXTERNAL_FEDNOW_CANCELED", "EXTERNAL_FEDNOW_INITIATED", "EXTERNAL_FEDNOW_RELEASED", "EXTERNAL_FEDNOW_REVERSED", "EXTERNAL_FEDNOW_SETTLED", "EXTERNAL_RTP_CANCELED", "EXTERNAL_RTP_INITIATED", "EXTERNAL_RTP_RELEASED", "EXTERNAL_RTP_REVERSED", "EXTERNAL_RTP_SETTLED", "EXTERNAL_STABLECOIN_CANCELED", "EXTERNAL_STABLECOIN_INITIATED", "EXTERNAL_STABLECOIN_RELEASED", "EXTERNAL_STABLECOIN_REVERSED", "EXTERNAL_STABLECOIN_SETTLED", "EXTERNAL_TRANSFER_CANCELED", "EXTERNAL_TRANSFER_INITIATED", "EXTERNAL_TRANSFER_RELEASED", "EXTERNAL_TRANSFER_REVERSED", "EXTERNAL_TRANSFER_SETTLED", "EXTERNAL_WIRE_CANCELED", "EXTERNAL_WIRE_INITIATED", "EXTERNAL_WIRE_RELEASED", "EXTERNAL_WIRE_REVERSED", "EXTERNAL_WIRE_SETTLED", "FEE", "FEE_REVERSAL", "FINANCIAL_AUTHORIZATION", "FINANCIAL_CREDIT_AUTHORIZATION", "INSTALLMENT_FEE", "INSTALLMENT_FEE_REVERSAL", "INTEREST", "INTEREST_REVERSAL", "INTERNAL_ADJUSTMENT", "INTRA_BANK_CANCELED", "INTRA_BANK_INITIATED", "INTRA_BANK_SETTLED", "LATE_PAYMENT", "LATE_PAYMENT_REVERSAL", "LOSS_WRITE_OFF", "PROVISIONAL_CREDIT", "PROVISIONAL_CREDIT_REVERSAL", "SERVICE", "RETURN", "RETURN_REVERSAL", "TRANSFER", "TRANSFER_INSUFFICIENT_FUNDS", "RETURNED_PAYMENT", "RETURNED_PAYMENT_REVERSAL", "LITHIC_NETWORK_PAYMENT", "LITHIC_PROGRAM_TRANSFER", "BANK_PROGRAM_TRANSFER", "ANNUAL", "ANNUAL_REVERSAL", "QUARTERLY", "QUARTERLY_REVERSAL", "MONTHLY", "MONTHLY_REVERSAL", "ACCOUNT_TO_ACCOUNT", "STABLECOIN_RECEIVED", "STABLECOIN_INITIATED", "STABLECOIN_REVIEWED", "STABLECOIN_SENT", "STABLECOIN_SETTLED", "STABLECOIN_REJECTED", "INSTANCE_TO_INSTANCE"]); export const financialEvent = z.object({amount: z.number().int().optional(), created: z.string().optional(), result: z.enum(["APPROVED", "DECLINED"]).optional(), token: z.string().optional(), type: financialEventType.optional()}); export const financialAccountTransaction = z.object({category: z.enum(["ACH", "CARD", "INTERNAL", "TRANSFER"]), created: z.string(), currency: z.string(), descriptor: z.string(), events: z.array(financialEvent), pending_amount: z.number().int(), result: z.enum(["APPROVED", "DECLINED"]), settled_amount: z.number().int(), status: z.enum(["DECLINED", "EXPIRED", "PENDING", "RETURNED", "SETTLED", "VOIDED"]), token: z.string(), updated: z.string()}); export const getApiV1FinancialAccountsFinancialAccountTokenFinancialTransactionsResponse = z.object({data: z.array(financialAccountTransaction), has_more: z.boolean()}); 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 financial transactions * * GET /v1/financial_accounts/{financial_account_token}/financial_transactions */ export const getApiV1FinancialAccountsFinancialAccountTokenFinancialTransactions = async (args: GetApiV1FinancialAccountsFinancialAccountTokenFinancialTransactionsArgs, options?: GetApiV1FinancialAccountsFinancialAccountTokenFinancialTransactionsOptions) => { const {baseUrl = "https://sandbox.lithic.com", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.category != null) query.append("category", String(args.category)) if (args.result != null) query.append("result", String(args.result)) if (args.status != null) query.append("status", String(args.status)) if (args.begin != null) query.append("begin", String(args.begin)) if (args.end != null) query.append("end", String(args.end)) if (args.ending_before != null) query.append("ending_before", String(args.ending_before)) if (args.page_size != null) query.append("page_size", String(args.page_size)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/financial_accounts/${encodeURIComponent(String(args.financial_account_token))}/financial_transactions${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(getApiV1FinancialAccountsFinancialAccountTokenFinancialTransactionsResponse, await res.json()) };