import {z} from 'zod' export type BankingTransactionMethod = 'INCOMING_ACH' | 'INCOMING_WIRE' | 'OUTGOING_ACH' | 'OUTGOING_WIRE' | 'CHECK_DEPOSIT' | 'BOOK_TRANSFER' | 'ISSUED_CHECK' | 'HOLD' | 'CARD' | 'INTEREST' | 'MANUAL_POST' | 'INTERNATIONAL_PAYMENT' | 'INCOMING_INSTANT_PAYMENT' | 'OUTGOING_INSTANT_PAYMENT' | 'MEOW_INSTANT_NETWORK' | 'INTERNATIONAL_PAYMENT_FEE'; export type TransactionStatus = 'AUTHORIZATION' | 'MEMO' | 'PENDING' | 'POSTED'; export type GetApiAccountsAccountIdTransactionsArgs = {account_id: string, start_time?: (string | null) | undefined, end_time?: (string | null) | undefined, offset?: (string | null) | undefined, limit?: (number | null) | undefined, transfer_method?: (BankingTransactionMethod | null) | undefined, deposit_tx_hash?: (string | null) | undefined, status?: (Array | null) | undefined, 'x-entity-id'?: string | undefined}; export type GetApiAccountsAccountIdTransactionsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const pageMetadata = z.object({nextOffset: z.string().nullable().optional()}); export const identifier = z.string().max(256); export const timestamp = z.string(); export const debitCreditMemo = z.enum(["CREDIT", "DEBIT", "MEMO", "NONE"]); export const transactionStatus = z.enum(["AUTHORIZATION", "MEMO", "PENDING", "POSTED"]); export const iso4217Code = z.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SLE", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "UYI", "UYU", "UYW", "UZS", "VED", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX", "YER", "ZAR", "ZMW", "ZWG", "ZWL"]); export const currency = z.object({currencyCode: iso4217Code}); export const depositTransactionType = z.enum(["ADJUSTMENT", "ATMDEPOSIT", "ATMWITHDRAWAL", "BILLPAYMENT", "CHECK", "DEPOSIT", "DIRECTDEPOSIT", "DIVIDEND", "FEE", "INTEREST", "POSCREDIT", "POSDEBIT", "TRANSFER", "WITHDRAWAL", "NONE"]); export const string255 = z.string().max(255); export const depositTransaction = z.object({transactionId: identifier, referenceTransactionId: identifier.nullable().optional(), postedTimestamp: timestamp.nullable().optional(), transactionTimestamp: timestamp, description: z.string(), debitCreditMemo: debitCreditMemo, category: z.string().nullable().optional(), subCategory: z.string().nullable().optional(), status: transactionStatus, amount: z.number(), currency: currency, foreignAmount: z.number().nullable().optional(), foreignCurrency: iso4217Code.nullable().optional(), card_id: z.string().nullable().optional(), transactionType: depositTransactionType.nullable().optional(), payee: string255.nullable().optional(), checkNumber: z.string().nullable().optional()}); export const depositTransactionModel = z.object({depositTransaction: depositTransaction}); export const investmentTransactionType = z.enum(["ADJUSTMENT", "ATM", "CASH", "CHECK", "CLOSURE", "CLOSUREOPT", "CONTRIBUTION", "DEP", "DEPOSIT", "DIRECTDEBIT", "DIRECTDEP", "DIV", "DIVIDEND", "DIVIDENDREINVEST", "EXPENSE", "FEE", "INCOME", "INTEREST", "INVEXPENSE", "JRNLFUND", "JRNLSEC", "MARGININTEREST", "OPTIONEXERCISE", "OPTIONEXPIRATION", "OTHER", "PAYMENT", "POS", "PURCHASED", "PURCHASEDTOCOVER", "PURCHASETOCLOSE", "PURCHASETOOPEN", "REINVESTOFINCOME", "REPEATPMT", "RETURNOFCAPITAL", "SOLD", "SOLDTOCLOSE", "SOLDTOOPEN", "SPLIT", "SRVCHG", "TRANSFER", "XFER"]); export const customerApiV1AppTransactionsModelsSecurityIdType = z.enum(["CUSIP", "ISIN", "SEDOL", "SICC", "VALOR", "WKN"]); export const securityType = z.enum(["BOND", "DEBT", "MUTUALFUND", "OPTION", "OTHER", "STOCK", "SWEEP"]); export const unitType = z.enum(["CURRENCY", "SHARES"]); export const investmentTransaction = z.object({transactionId: identifier, referenceTransactionId: identifier.nullable().optional(), postedTimestamp: timestamp.nullable().optional(), transactionTimestamp: timestamp, description: z.string(), debitCreditMemo: debitCreditMemo, category: z.string().nullable().optional(), subCategory: z.string().nullable().optional(), status: transactionStatus, amount: z.number(), currency: currency, foreignAmount: z.number().nullable().optional(), foreignCurrency: iso4217Code.nullable().optional(), card_id: z.string().nullable().optional(), transactionType: investmentTransactionType, securityId: z.string().nullable().optional(), securityIdType: customerApiV1AppTransactionsModelsSecurityIdType.nullable().optional(), securityType: securityType.nullable().optional(), symbol: z.string().nullable().optional(), commission: z.number().nullable().optional(), fees: z.number(), unitPrice: z.number().nullable().optional(), units: z.number().nullable().optional(), unitType: unitType.nullable().optional()}); export const investmentTransactionModel = z.object({investmentTransaction: investmentTransaction}); export const digitalWalletTransactionType = z.enum(["DEPOSIT", "WITHDRAWAL", "FEE", "INTEREST"]); export const digitalWalletTransaction = z.object({transactionId: identifier, referenceTransactionId: identifier.nullable().optional(), postedTimestamp: timestamp.nullable().optional(), transactionTimestamp: timestamp, description: z.string(), debitCreditMemo: debitCreditMemo, category: z.string().nullable().optional(), subCategory: z.string().nullable().optional(), status: transactionStatus, amount: z.number(), currency: currency, foreignAmount: z.number().nullable().optional(), foreignCurrency: iso4217Code.nullable().optional(), card_id: z.string().nullable().optional(), transactionType: digitalWalletTransactionType.nullable().optional(), payee: string255.nullable().optional()}); export const digitalWalletTransactionModel = z.object({digitalWalletTransaction: digitalWalletTransaction}); export const transactions = z.object({page: pageMetadata.nullable().optional(), transactions: z.array(z.union([depositTransactionModel, investmentTransactionModel, digitalWalletTransactionModel]))}); 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 Transactions for an Account * * GET /accounts/{account_id}/transactions */ export const getApiAccountsAccountIdTransactions = async (args: GetApiAccountsAccountIdTransactionsArgs, options?: GetApiAccountsAccountIdTransactionsOptions) => { const {baseUrl = "https://api.meow.com/v1", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.start_time != null) query.append("start_time", String(args.start_time)) if (args.end_time != null) query.append("end_time", String(args.end_time)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.transfer_method != null) query.append("transfer_method", String(args.transfer_method)) if (args.deposit_tx_hash != null) query.append("deposit_tx_hash", String(args.deposit_tx_hash)) for (const item of args.status ?? []) query.append("status", String(item)) if (args['x-entity-id'] != null) headers.set("x-entity-id", String(args['x-entity-id'])) if (apiKeyAuth !== undefined) headers.set("x-api-key", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.account_id))}/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(transactions, await res.json()) };