import {z} from 'zod' export type IsoCurrencyCode = 'AED' | 'AUD' | 'BHD' | 'BRL' | 'BSD' | 'CAD' | 'CHF' | 'CNY' | 'COP' | 'CRC' | 'CZK' | 'DKK' | 'DOP' | 'EGP' | 'EUR' | 'GBP' | 'GHS' | 'GTQ' | 'HKD' | 'HNL' | 'HUF' | 'IDR' | 'INR' | 'ILS' | 'JPY' | 'KES' | 'KRW' | 'KWD' | 'KZT' | 'MOP' | 'MXN' | 'MYR' | 'NGN' | 'NIO' | 'NOK' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PHP' | 'PKR' | 'PLN' | 'QAR' | 'RON' | 'SAR' | 'SEK' | 'SGD' | 'THB' | 'TRY' | 'TWD' | 'UGX' | 'USD' | 'UYU' | 'VND' | 'ZAR'; export type LedgersNetsuiteNetSuiteAccount = {id: string}; export type LedgersNetsuiteNetSuiteClass = {id: string}; export type LedgersNetsuiteNetSuiteLocation = {id: string}; export type LedgersNetsuiteNetSuitePostingPeriod = {id: string}; export type LedgersQboQBOClass = {id: string}; export type LedgersQboQBODepartment = {id: string}; export type LedgersNetsuiteNetSuiteAmortizationSchedule = {id: string}; export type LedgersNetsuiteNetSuiteDepartment = {id: string}; export type LedgersSageSageAccount = {id: string}; export type LedgersSageSageClass = {id: string}; export type LedgersSageSageContract = {id: string}; export type LedgersSageSageDepartment = {id: string}; export type LedgersSageSageEmployee = {id: string}; export type LedgersSageSageItem = {id: string}; export type LedgersSageSageLocation = {id: string}; export type LedgersSageSageProject = {id: string}; export type LedgersSageSageTask = {id: string}; export type LedgersSageSageWarehouse = {id: string}; export type ItemsPayablesCommonNewPayableLineItem = {account?: {id: string} | undefined, amount: unknown, description: string, is_taxable?: boolean | undefined, item?: {id: string} | undefined, quantity?: unknown | undefined, style?: 'item' | undefined, tax?: {id: string} | undefined, unit_price: unknown, ledger?: ({[key: string]: unknown} | {billable?: ('billable' | 'not-billable') | undefined, class?: LedgersQboQBOClass | undefined, customer_ref?: string | undefined, department?: LedgersQboQBODepartment | undefined, markup?: unknown | undefined} | {[key: string]: unknown} | {amortiz_start_date?: string | undefined, amortization_end_date?: string | undefined, amortization_residual?: string | undefined, amortization_sched?: LedgersNetsuiteNetSuiteAmortizationSchedule | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, customer_ref?: string | undefined, department?: LedgersNetsuiteNetSuiteDepartment | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined} | {[key: string]: unknown} | {account?: LedgersSageSageAccount | undefined, class?: LedgersSageSageClass | undefined, contract?: LedgersSageSageContract | undefined, customer_ref?: string | undefined, department?: LedgersSageSageDepartment | undefined, employee?: LedgersSageSageEmployee | undefined, item?: LedgersSageSageItem | undefined, location?: LedgersSageSageLocation | undefined, project?: LedgersSageSageProject | undefined, task?: LedgersSageSageTask | undefined, vendor_ref?: string | undefined, warehouse?: LedgersSageSageWarehouse | undefined}) | undefined, purchase_order_id?: string | undefined, purchase_order_line_item_id?: string | undefined}; export type ItemsPayablesAchACHDeliveryMethod = 'ach_expedited' | 'ach_next_day' | 'ach_same_day' | 'ach_standard' | 'real_time_payment'; export type ItemsPayablesAchNewPayableACHTypeDetails = {addenda_record?: string | undefined}; export type ItemsPayablesAchNewPayableACH = {acting_team_member: string, amount: unknown, attachments?: (Array<{data_uri: string, name: string, include_in_check_insert?: (boolean | null) | undefined}>) | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, message?: string | undefined, reference?: string | undefined, due_on?: string | undefined, ledger?: ({memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown} | {memo?: string | undefined} | {[key: string]: unknown} | {account?: LedgersNetsuiteNetSuiteAccount | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined, memo?: string | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}) | undefined, line_items: Array, pay_to_company: string, withdraw_from_account: string, delivery_method: ItemsPayablesAchACHDeliveryMethod, pay_to_payment_method?: string | undefined, type: 'ach', type_details?: ItemsPayablesAchNewPayableACHTypeDetails | undefined, send_on: string | null}; export type ItemsPayablesCardNewPayableCard = {acting_team_member: string, amount: unknown, attachments?: (Array<{data_uri: string, name: string, include_in_check_insert?: (boolean | null) | undefined}>) | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, message?: string | undefined, reference?: string | undefined, due_on?: string | undefined, ledger?: ({memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown} | {memo?: string | undefined} | {[key: string]: unknown} | {account?: LedgersNetsuiteNetSuiteAccount | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined, memo?: string | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}) | undefined, line_items: Array, pay_to_company: string, withdraw_from_account: string, delivery_method: 'card_instant', pay_to_payment_method: string, send_on: string | null, type: 'card'}; export type ItemsPayablesCheckCheckDeliveryMethod = 'check_international' | 'check_next_day' | 'check_priority' | 'check_priority_express' | 'check_priority_signature' | 'check_standard' | 'check_standard_certified' | 'check_two_day'; export type ItemsPayablesCheckNewPayableCheckTypeDetails = {stub_details?: ({columns?: Array | undefined, rows?: Array> | undefined}) | undefined}; export type ItemsPayablesCheckNewPayableCheck = {acting_team_member: string, amount: unknown, attachments?: (Array<{data_uri: string, name: string, include_in_check_insert?: (boolean | null) | undefined}>) | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, message?: string | undefined, reference?: string | undefined, due_on?: string | undefined, ledger?: ({memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown} | {memo?: string | undefined} | {[key: string]: unknown} | {account?: LedgersNetsuiteNetSuiteAccount | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined, memo?: string | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}) | undefined, line_items: Array, pay_to_company: string, withdraw_from_account: string, delivery_method: ItemsPayablesCheckCheckDeliveryMethod, pay_to_payment_method?: string | undefined, type: 'check', send_on: string | null, type_details?: ItemsPayablesCheckNewPayableCheckTypeDetails | undefined}; export type ItemsPayablesExternalNewPayableExternalTypeDetails = {paid_on: string, payment_method: 'ach' | 'check' | 'credit_card' | 'debit_card' | 'other' | 'payment_platform' | 'paypal' | 'wire_domestic' | 'wire_international', reference: string}; export type ItemsPayablesExternalNewPayableExternal = {acting_team_member: string, amount: unknown, attachments?: (Array<{data_uri: string, name: string, include_in_check_insert?: (boolean | null) | undefined}>) | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, message?: string | undefined, reference?: string | undefined, due_on?: string | undefined, ledger?: ({memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown} | {memo?: string | undefined} | {[key: string]: unknown} | {account?: LedgersNetsuiteNetSuiteAccount | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined, memo?: string | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}) | undefined, line_items: Array, pay_to_company: string, withdraw_from_account: string, type: 'external', type_details: ItemsPayablesExternalNewPayableExternalTypeDetails}; export type SharedSwiftChargeOption = 'sha' | 'our' | null; export type ItemsPayablesInternationalNewPayableInternationalTypeDetails = {addenda_record?: (string | null) | undefined, purpose_code?: (string | null) | undefined, swift_charge_option?: SharedSwiftChargeOption | undefined}; export type ItemsPayablesInternationalNewPayableInternational = {acting_team_member: string, amount: unknown, attachments?: (Array<{data_uri: string, name: string, include_in_check_insert?: (boolean | null) | undefined}>) | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, message?: string | undefined, reference?: string | undefined, due_on?: string | undefined, ledger?: ({memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown} | {memo?: string | undefined} | {[key: string]: unknown} | {account?: LedgersNetsuiteNetSuiteAccount | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined, memo?: string | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}) | undefined, line_items: Array, pay_to_company: string, withdraw_from_account: string, currency_code_recipient?: IsoCurrencyCode | undefined, delivery_method: 'international_ach' | 'international_swift' | 'international_vendor_choice', pay_to_payment_method?: string | undefined, send_on: string | null, type: 'international', type_details?: ItemsPayablesInternationalNewPayableInternationalTypeDetails | undefined}; export type ItemsPayablesPaypalNewPayablePayPal = {acting_team_member: string, amount: unknown, attachments?: (Array<{data_uri: string, name: string, include_in_check_insert?: (boolean | null) | undefined}>) | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, message?: string | undefined, reference?: string | undefined, due_on?: string | undefined, ledger?: ({memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown} | {memo?: string | undefined} | {[key: string]: unknown} | {account?: LedgersNetsuiteNetSuiteAccount | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined, memo?: string | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}) | undefined, line_items: Array, pay_to_company: string, withdraw_from_account: string, delivery_method?: 'paypal_direct' | undefined, pay_to_payment_method: string, type: 'paypal', send_on: string | null}; export type ItemsPayablesVendorChoiceNewPayableVendorChoiceTypeDetails = {delivery_method_choices?: (Array<'ach' | 'card' | 'check' | 'paypal'>) | undefined}; export type ItemsPayablesVendorChoiceNewPayableVendorChoice = {acting_team_member: string, amount: unknown, attachments?: (Array<{data_uri: string, name: string, include_in_check_insert?: (boolean | null) | undefined}>) | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, message?: string | undefined, reference?: string | undefined, due_on?: string | undefined, ledger?: ({memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown} | {memo?: string | undefined} | {[key: string]: unknown} | {account?: LedgersNetsuiteNetSuiteAccount | undefined, class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined, memo?: string | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}) | undefined, line_items: Array, pay_to_company: string, withdraw_from_account: string, type: 'vendor_choice', type_details?: ItemsPayablesVendorChoiceNewPayableVendorChoiceTypeDetails | undefined, send_on: string | null}; export type ItemsPayablesDiscriminatedNewPayable = ItemsPayablesAchNewPayableACH | ItemsPayablesCardNewPayableCard | ItemsPayablesCheckNewPayableCheck | ItemsPayablesExternalNewPayableExternal | ItemsPayablesInternationalNewPayableInternational | ItemsPayablesPaypalNewPayablePayPal | ItemsPayablesVendorChoiceNewPayableVendorChoice; export type CreateApiV1PayablesRateEstimatesArgs = {body: ItemsPayablesDiscriminatedNewPayable}; export type CreateApiV1PayablesRateEstimatesOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const isoCountryCode = z.enum(["AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BW", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CL", "CM", "CN", "CO", "CR", "CV", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IQ", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MX", "MW", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RW", "SA", "SB", "SC", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "ST", "SV", "SX", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VI", "VN", "VU", "XK", "WF", "WS", "XX", "YE", "YT", "ZA", "ZM", "ZW"]).min(2).max(2); export const isoCurrencyCode = z.enum(["AED", "AUD", "BHD", "BRL", "BSD", "CAD", "CHF", "CNY", "COP", "CRC", "CZK", "DKK", "DOP", "EGP", "EUR", "GBP", "GHS", "GTQ", "HKD", "HNL", "HUF", "IDR", "INR", "ILS", "JPY", "KES", "KRW", "KWD", "KZT", "MOP", "MXN", "MYR", "NGN", "NIO", "NOK", "NZD", "OMR", "PAB", "PEN", "PHP", "PKR", "PLN", "QAR", "RON", "SAR", "SEK", "SGD", "THB", "TRY", "TWD", "UGX", "USD", "UYU", "VND", "ZAR"]).min(3).max(3); export const currenciesFee = z.object({object: z.literal("Fee"), amount: z.string(), amount_maximum: z.string(), currency_code: isoCurrencyCode, is_estimate: z.boolean(), name: z.string()}); export const currenciesRateEstimate = z.object({object: z.literal("RateEstimate"), amount_receiver: z.string(), amount_sender: z.string(), country_code_receiver: isoCountryCode, country_code_sender: isoCountryCode, currency_code_receiver: isoCurrencyCode.optional(), currency_code_sender: isoCurrencyCode.optional(), delivery_method: z.enum(["international_ach", "international_swift"]), exchange_rate: z.string(), exchange_rate_retrieved_at: z.string(), fees: z.array(currenciesFee).optional(), payment_method: z.enum(["ach", "card", "check", "external", "international", "paypal", "vendor_choice"])}); 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 }; /** * Estimate Fees for a Payable * * POST /v1/payables/rate-estimates */ export const createApiV1PayablesRateEstimates = async (args: CreateApiV1PayablesRateEstimatesArgs, options?: CreateApiV1PayablesRateEstimatesOptions) => { const {baseUrl = "https://api.routable.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/payables/rate-estimates${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(currenciesRateEstimate, await res.json()) };