import {z} from 'zod' export type GetApiContactsArgs = {nickname_query?: (string | null) | undefined, limit?: number | undefined, offset?: (string | null) | undefined, 'x-entity-id'?: string | undefined}; export type GetApiContactsOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const countryCodeAlpha2 = z.enum(["AW", "AF", "AO", "AI", "AX", "AL", "AD", "AE", "AR", "AM", "AS", "AQ", "TF", "AG", "AU", "AT", "AZ", "BI", "BE", "BJ", "BQ", "BF", "BD", "BG", "BH", "BS", "BA", "BL", "BY", "BZ", "BM", "BO", "BR", "BB", "BN", "BT", "BV", "BW", "CF", "CA", "CC", "CH", "CL", "CN", "CI", "CM", "CD", "CG", "CK", "CO", "KM", "CV", "CR", "CU", "CW", "CX", "KY", "CY", "CZ", "DE", "DJ", "DM", "DK", "DO", "DZ", "EC", "EG", "ER", "EH", "ES", "EE", "ET", "FI", "FJ", "FK", "FR", "FO", "FM", "GA", "GB", "GE", "GG", "GH", "GI", "GN", "GP", "GM", "GW", "GQ", "GR", "GD", "GL", "GT", "GF", "GU", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IM", "IN", "IO", "IE", "IR", "IQ", "IS", "IL", "IT", "JM", "JE", "JO", "JP", "KZ", "KE", "KG", "KH", "KI", "KN", "KR", "KW", "LA", "LB", "LR", "LY", "LC", "LI", "LK", "LS", "LT", "LU", "LV", "MO", "MF", "MA", "MC", "MD", "MG", "MV", "MX", "MH", "MK", "ML", "MT", "MM", "ME", "MN", "MP", "MZ", "MR", "MS", "MQ", "MU", "MW", "MY", "YT", "NA", "NC", "NE", "NF", "NG", "NI", "NU", "NL", "NO", "NP", "NR", "NZ", "OM", "PK", "PA", "PN", "PE", "PH", "PW", "PG", "PL", "PR", "KP", "PT", "PY", "PS", "PF", "QA", "RE", "RO", "RU", "RW", "SA", "SD", "SN", "SG", "GS", "SH", "SJ", "SB", "SL", "SV", "SM", "SO", "PM", "RS", "SS", "ST", "SR", "SK", "SI", "SE", "SZ", "SX", "SC", "SY", "TC", "TD", "TG", "TH", "TJ", "TK", "TM", "TL", "TO", "TT", "TN", "TR", "TV", "TW", "TZ", "UG", "UA", "UM", "UY", "US", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XK", "YE", "ZA", "ZM", "ZW"]); export const addressResponse = z.object({street_line_1: z.string().nullable().optional(), street_line_2: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), country: countryCodeAlpha2.nullable().optional(), postal_code: z.string().nullable().optional()}); export const treasuryPrimeAccountType = z.enum(["checking", "savings"]); export const meowApiAddress = z.object({street_line_1: z.string().min(1).max(300), street_line_2: z.string().max(300).nullable().optional(), city: z.string().max(21), state: z.string().max(3).nullable().optional(), country: countryCodeAlpha2, postal_code: z.string().min(1).max(20)}); export const customerApiAchPaymentMethod = z.object({counterparty_id: z.string(), name_on_account: z.string(), nickname: z.string(), account_type: treasuryPrimeAccountType, account_number: z.string(), routing_number: z.string(), address_on_account: meowApiAddress.nullable().optional()}); export const customerApiWireIntermediaryBank = z.object({name: z.string(), routing_number: z.string(), address: meowApiAddress}); export const customerApiWirePaymentMethod = z.object({counterparty_id: z.string(), name_on_account: z.string(), nickname: z.string(), bank_name: z.string(), account_number: z.string(), routing_number: z.string(), beneficiary_address: meowApiAddress, bank_address: meowApiAddress, intermediary_bank: customerApiWireIntermediaryBank.nullable().optional()}); export const customerApiCheckPaymentMethod = z.object({counterparty_id: z.string(), name_on_account: z.string(), nickname: z.string(), mailing_address: meowApiAddress}); 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 internationalPaymentMethod = z.enum(["SWIFT", "LOCAL"]); export const internationalBeneficiaryType = z.enum(["individual", "company"]); export const internationalRoutingCodeType = z.enum(["SortCode", "ABA", "BSBCode", "InstitutionNo", "BankCode", "BranchCode", "Clabe", "Cnaps", "Ifsc"]); export const customerApiInternationalPaymentMethod = z.object({beneficiary_id: z.string().nullable().optional(), international_beneficiary_id: z.string().nullable().optional(), preferred_currency: iso4217Code.nullable().optional(), payment_methods: z.array(internationalPaymentMethod).optional(), beneficiary_type: internationalBeneficiaryType.nullable().optional(), first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), company_name: z.string().nullable().optional(), date_of_birth: z.string().nullable().optional(), address: addressResponse.nullable().optional(), currency: iso4217Code.nullable().optional(), account_number: z.string().nullable().optional(), iban: z.string().nullable().optional(), bic_swift: z.string().nullable().optional(), bank_name: z.string().nullable().optional(), bank_country: countryCodeAlpha2.nullable().optional(), bank_address: z.string().nullable().optional(), routing_code_type: internationalRoutingCodeType.nullable().optional(), routing_code_value: z.string().nullable().optional(), routing_code_type_2: internationalRoutingCodeType.nullable().optional(), routing_code_value_2: z.string().nullable().optional(), correspondent_bank_name: z.string().nullable().optional(), correspondent_bank_bic_swift: z.string().nullable().optional()}); export const extBridgePaymentRail = z.enum(["arbitrum", "avalanche_c_chain", "base", "ethereum", "optimism", "polygon", "solana", "stellar", "sui", "tempo", "tron", "xdc", "ach", "ach_push", "ach_same_day", "fednow", "wire", "swift", "sepa", "faster_payments", "spei", "bridge_transfer"]); export const extBridgeCryptocurrency = z.enum(["usdb", "usdc", "usdt", "dai", "pyusd", "cash", "usdg", "usdv", "eurc", "usd", "eur", "gbp", "mxn", "path_usd", "ousd"]); export const cryptoCurrency = z.enum(["usdc", "usdt", "pyusd", "cash", "usdg", "usdv", "eurc", "eth", "sol", "btc", "xrp", "path_usd", "ousd"]); export const cryptoNetwork = z.enum(["ethereum", "base", "solana", "arbitrum", "polygon", "optimism", "tron", "stellar", "avalanche_c_chain", "binance", "sui", "tempo", "xdc", "bitcoin", "ripple"]); export const cryptoContactDestinationResponse = z.object({id: z.string(), destination_address: z.string(), destination_payment_rail: extBridgePaymentRail.nullable().optional(), destination_currency: extBridgeCryptocurrency.nullable().optional(), currency: cryptoCurrency.nullable().optional(), network: cryptoNetwork.nullable().optional(), destination_tag: z.string().nullable().optional()}); export const bridgeStaticMemoResponse = z.object({id: z.string(), destination_address: z.string(), destination_payment_rail: extBridgePaymentRail, destination_payment_currency: extBridgeCryptocurrency}); export const customerApiPaymentMethods = z.object({ach: customerApiAchPaymentMethod.nullable().optional(), wire: customerApiWirePaymentMethod.nullable().optional(), check: customerApiCheckPaymentMethod.nullable().optional(), international: customerApiInternationalPaymentMethod.nullable().optional(), crypto: z.array(cryptoContactDestinationResponse).optional(), static_memos: z.array(bridgeStaticMemoResponse).optional()}); export const customerApiPaymentMethodType = z.enum(["ach", "wire", "check", "international", "crypto", "static_memo"]); export const extAwxPaymentReason = z.enum(["audio_visual_services", "bill_payment", "business_expenses", "construction", "donation_charitable_contribution", "education_training", "family_support", "freight", "goods_purchased", "investment_capital", "investment_proceeds", "living_expenses", "loan_credit_repayment", "medical_services", "pension", "personal_remittance", "professional_business_services", "real_estate", "taxes", "technical_services", "transfer_to_own_account", "travel", "wages_salary", "other_services"]); export const customerApiContact = z.object({id: z.string(), nickname: z.string().min(1).max(400), email: z.string().nullable().optional(), address: addressResponse.nullable().optional(), payment_methods: customerApiPaymentMethods, supported_payment_methods: z.array(customerApiPaymentMethodType), last_payment_reason: extAwxPaymentReason.nullable().optional()}); export const pageMetadata = z.object({nextOffset: z.string().nullable().optional()}); export const customerApiContactsList = z.object({contacts: z.array(customerApiContact), page: pageMetadata.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 }; /** * List Contacts * * GET /contacts */ export const getApiContacts = async (args: GetApiContactsArgs, options?: GetApiContactsOptions) => { 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.nickname_query != null) query.append("nickname_query", String(args.nickname_query)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) 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(/\/+$/, '')}/contacts${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(customerApiContactsList, await res.json()) };