import {z} from 'zod' export type SharedNewAttachment = {data_uri: string, name: string}; 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 LedgersXeroXeroNewReceivableMeta = {memo?: string | undefined, tax_style?: ('exclusive' | 'inclusive' | 'none') | undefined} | {[key: string]: unknown}; export type LedgersQboQBOClass = {id: string}; export type LedgersQboQBODepartment = {id: string}; export type LedgersQboQBONewReceivableMeta = {class?: LedgersQboQBOClass | undefined, department?: LedgersQboQBODepartment | undefined, discount?: number | undefined, discount_calculation?: ('amount' | 'percentage') | undefined, discount_style?: string | undefined, memo?: string | undefined, tax_auto?: boolean | undefined, tax_code?: {id: string} | undefined} | {[key: string]: unknown}; export type LedgersNetsuiteNetSuiteDepartment = {id: string}; export type LedgersNetsuiteNetSuitePostingPeriod = {id: string}; export type LedgersNetsuiteNetSuiteNewReceivableMeta = {department?: LedgersNetsuiteNetSuiteDepartment | undefined, posting_period?: LedgersNetsuiteNetSuitePostingPeriod | undefined} | {[key: string]: unknown}; export type LedgersXeroXeroNewPayableLineItemMeta = {[key: string]: unknown}; export type LedgersNetsuiteNetSuiteClass = {id: string}; export type LedgersNetsuiteNetSuiteLocation = {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 LedgersSageSageNewPayableLineItemMeta = {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}; export type ItemsReceivablesCommonNewReceivableLineItem = {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, discount?: number | undefined, ledger?: (LedgersXeroXeroNewPayableLineItemMeta | {class?: LedgersQboQBOClass | undefined} | {[key: string]: unknown} | {class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined} | {[key: string]: unknown} | LedgersSageSageNewPayableLineItemMeta) | undefined}; export type LedgersXeroXeroNewReceivableLineItemMeta = {[key: string]: unknown}; export type LedgersQboQBONewReceivableLineItemMeta = {class?: LedgersQboQBOClass | undefined} | {[key: string]: unknown}; export type LedgersNetsuiteNetSuiteNewReceivableLineItemMeta = {class?: LedgersNetsuiteNetSuiteClass | undefined, location?: LedgersNetsuiteNetSuiteLocation | undefined} | {[key: string]: unknown}; export type ItemsReceivablesCommonUpdateReceivableLineItem = {account?: {id: string} | undefined, amount?: unknown | undefined, description?: string | undefined, is_taxable?: boolean | undefined, item?: {id: string} | undefined, quantity?: unknown | undefined, style?: 'item' | undefined, tax?: {id: string} | undefined, unit_price?: unknown | undefined, id: string, discount?: number | undefined, ledger?: (LedgersXeroXeroNewReceivableLineItemMeta | LedgersQboQBONewReceivableLineItemMeta | LedgersNetsuiteNetSuiteNewReceivableLineItemMeta | LedgersSageSageNewPayableLineItemMeta) | undefined}; export type ItemsCommonReceivableTerms = 'net30' | 'net60' | 'see_invoice' | 'upon_receipt'; export type ItemsReceivablesExternalExternalReceivableTypeDetails = {paid_on: string, payment_method: 'ach' | 'check' | 'credit_card' | 'debit_card' | 'other' | 'payment_platform' | 'paypal' | 'wire_domestic' | 'wire_international', reference: string}; export type ItemsReceivablesDiscriminatedUpdateReceivable = {acting_team_member: string, amount?: unknown | undefined, attachments?: Array | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, deposit_into_account?: string | undefined, due_from_company?: string | undefined, due_on?: string | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, item?: {id: string} | undefined, ledger?: (LedgersXeroXeroNewReceivableMeta | LedgersQboQBONewReceivableMeta | LedgersNetsuiteNetSuiteNewReceivableMeta) | undefined, line_items?: (Array) | undefined, message?: string | undefined, reference?: string | undefined, send_on?: (string | null) | undefined, terms?: ItemsCommonReceivableTerms | undefined, type?: 'external' | undefined, version: number, type_details?: ItemsReceivablesExternalExternalReceivableTypeDetails | undefined} | {acting_team_member: string, amount?: unknown | undefined, attachments?: Array | undefined, bill_number?: string | undefined, currency_code?: IsoCurrencyCode | undefined, deposit_into_account?: string | undefined, due_from_company?: string | undefined, due_on?: string | undefined, external_id?: (string | null) | undefined, issued_on?: string | undefined, item?: {id: string} | undefined, ledger?: (LedgersXeroXeroNewReceivableMeta | LedgersQboQBONewReceivableMeta | LedgersNetsuiteNetSuiteNewReceivableMeta) | undefined, line_items?: (Array) | undefined, message?: string | undefined, reference?: string | undefined, send_on?: (string | null) | undefined, terms?: ItemsCommonReceivableTerms | undefined, type?: 'invoice' | undefined, version: number}; export type PatchApiV1ReceivablesIdArgs = {'Idempotency-Key'?: string | undefined, id: string, body: ItemsReceivablesDiscriminatedUpdateReceivable}; export type PatchApiV1ReceivablesIdOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const itemsCommonStatus = z.enum(["canceled", "completed", "compliance_hold", "created", "externally_paid", "failed", "initiated", "issue", "needs_approval", "pending", "po_discrepancy_hold", "processing", "ready_to_send", "scheduled"]); export const itemsCommonStatusChangeItem = z.object({changed_at: z.string(), status: z.enum(["analyzing", "canceled", "completed", "compliance_hold", "created", "externally_paid", "failed", "import", "initiated", "issue", "needs_approval", "new", "ocr", "pending", "po_discrepancy_hold", "processing", "ready_to_send", "scheduled"])}); export const sharedSelfLink = z.string(); export const itemsCommonItemLinks = z.object({self: sharedSelfLink, confirmation: z.string().nullable().optional()}); export const accountsAccountLinks = z.object({self: sharedSelfLink}); export const accountsAccountBankTypeDetails = z.object({account_number: z.string(), account_type: z.enum(["checking", "savings"]), institution_name: z.string(), logo: z.string().optional(), primary_color: z.string().min(4).max(7).optional(), routing_number: z.string().min(9).max(9)}); export const accountsCompactAccountBank = z.object({object: z.literal("Account"), id: z.string(), type: z.literal("bank"), links: accountsAccountLinks, type_details: accountsAccountBankTypeDetails}); export const companiesCompanyLinks = z.object({self: sharedSelfLink, compliance_checks: z.string(), contacts: z.string(), payables: z.string(), payment_methods: z.string(), receivables: z.string(), tax_forms: z.string()}); export const companiesCompactCompany = z.object({object: z.literal("Company"), id: z.string(), display_name: z.string(), links: companiesCompanyLinks}); export const itemsCommonReceivableTerms = z.enum(["net30", "net60", "see_invoice", "upon_receipt"]); export const sharedAttachment = z.object({object: z.literal("Attachment"), id: z.string(), name: z.string(), mime_type: z.string(), url: z.string()}); export const ledgersQboQBOClass = z.object({id: z.string()}); export const ledgersQboQBODepartment = z.object({id: z.string()}); export const ledgersNetsuiteNetSuiteDepartment = z.object({id: z.string()}); export const ledgersNetsuiteNetSuitePostingPeriod = z.object({id: z.string()}); export const ledgersXeroXeroNewReceivableLineItemMeta = z.record(z.string(), z.unknown()); export const ledgersQboQBONewReceivableLineItemMeta = z.object({class: ledgersQboQBOClass.optional()}).and(z.record(z.string(), z.unknown())); export const ledgersNetsuiteNetSuiteClass = z.object({id: z.string()}); export const ledgersNetsuiteNetSuiteLocation = z.object({id: z.string()}); export const ledgersNetsuiteNetSuiteNewReceivableLineItemMeta = z.object({class: ledgersNetsuiteNetSuiteClass.optional(), location: ledgersNetsuiteNetSuiteLocation.optional()}).and(z.record(z.string(), z.unknown())); export const ledgersSageSageAccount = z.object({id: z.string()}); export const ledgersSageSageClass = z.object({id: z.string()}); export const ledgersSageSageContract = z.object({id: z.string()}); export const ledgersSageSageDepartment = z.object({id: z.string()}); export const ledgersSageSageEmployee = z.object({id: z.string()}); export const ledgersSageSageItem = z.object({id: z.string()}); export const ledgersSageSageLocation = z.object({id: z.string()}); export const ledgersSageSageProject = z.object({id: z.string()}); export const ledgersSageSageTask = z.object({id: z.string()}); export const ledgersSageSageWarehouse = z.object({id: z.string()}); export const ledgersSageSageNewPayableLineItemMeta = z.object({account: ledgersSageSageAccount.optional(), class: ledgersSageSageClass.optional(), contract: ledgersSageSageContract.optional(), customer_ref: z.string().optional(), department: ledgersSageSageDepartment.optional(), employee: ledgersSageSageEmployee.optional(), item: ledgersSageSageItem.optional(), location: ledgersSageSageLocation.optional(), project: ledgersSageSageProject.optional(), task: ledgersSageSageTask.optional(), vendor_ref: z.string().optional(), warehouse: ledgersSageSageWarehouse.optional()}); export const itemsReceivablesCommonReceivableLineItem = z.object({account: z.object({id: z.string()}).optional(), amount: z.string().optional(), description: z.string().optional(), is_taxable: z.boolean().optional(), item: z.object({id: z.string()}).optional(), quantity: z.string().optional(), style: z.literal("item").optional(), tax: z.object({id: z.string()}).optional(), unit_price: z.string().optional(), object: z.literal("LineItem"), id: z.string().nullable().optional(), discount: z.number().optional(), ledger: z.union([ledgersXeroXeroNewReceivableLineItemMeta, ledgersQboQBONewReceivableLineItemMeta, ledgersNetsuiteNetSuiteNewReceivableLineItemMeta, ledgersSageSageNewPayableLineItemMeta]).optional()}); export const itemsReceivablesDiscriminatedReceivable = z.union([z.object({id: z.string(), amount: z.string(), amount_due: z.string(), amount_recipient: z.number().optional(), amount_sender: z.number().optional(), amount_paid: z.string(), approved_at: z.string().nullable(), bill_number: z.string().nullable(), created_at: z.string(), currency_code: 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).nullable().optional(), currency_code_recipient: 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).nullable().optional(), currency_code_sender: 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).nullable().optional(), due_on: z.string(), exchange_rate: z.string().optional(), expected_on: z.string().nullable(), external_id: z.string().nullable(), fixed_side: z.enum(["sender", "recipient"]).optional(), issued_on: z.string(), is_exchange_rate_locked: z.boolean().optional(), reference: z.string().nullable().optional(), sent_on: z.string().nullable(), status: itemsCommonStatus, status_changed_at: z.string(), status_changes: z.array(itemsCommonStatusChangeItem), links: itemsCommonItemLinks, version: z.number().int().gte(1).optional(), object: z.literal("Receivable"), deposit_into_account: accountsCompactAccountBank.optional(), due_from_company: companiesCompactCompany, send_on: z.string().nullable().optional(), terms: itemsCommonReceivableTerms.optional(), type: z.literal("external"), attachments: z.object({object: z.literal("List"), results: z.array(sharedAttachment)}), ledger: z.union([z.object({memo: z.string().optional(), tax_style: z.enum(["exclusive", "inclusive", "none"]).optional(), id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()}), z.object({class: ledgersQboQBOClass.optional(), department: ledgersQboQBODepartment.optional(), discount: z.number().optional(), discount_calculation: z.enum(["amount", "percentage"]).optional(), discount_style: z.string().optional(), memo: z.string().optional(), tax_auto: z.boolean().optional(), tax_code: z.object({id: z.string()}).optional(), id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()}), z.object({department: ledgersNetsuiteNetSuiteDepartment.optional(), posting_period: ledgersNetsuiteNetSuitePostingPeriod.optional(), id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()}), z.object({id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()})]).optional(), line_items: z.object({object: z.literal("List"), results: z.array(itemsReceivablesCommonReceivableLineItem)}).optional(), type_details: z.object({paid_on: z.string(), payment_method: z.enum(["ach", "check", "credit_card", "debit_card", "other", "payment_platform", "paypal", "wire_domestic", "wire_international"]), reference: z.string()}).nullable().optional()}), z.object({id: z.string(), amount: z.string(), amount_due: z.string(), amount_recipient: z.number().optional(), amount_sender: z.number().optional(), amount_paid: z.string(), approved_at: z.string().nullable(), bill_number: z.string().nullable(), created_at: z.string(), currency_code: 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).nullable().optional(), currency_code_recipient: 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).nullable().optional(), currency_code_sender: 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).nullable().optional(), due_on: z.string(), exchange_rate: z.string().optional(), expected_on: z.string().nullable(), external_id: z.string().nullable(), fixed_side: z.enum(["sender", "recipient"]).optional(), issued_on: z.string(), is_exchange_rate_locked: z.boolean().optional(), reference: z.string().nullable().optional(), sent_on: z.string().nullable(), status: itemsCommonStatus, status_changed_at: z.string(), status_changes: z.array(itemsCommonStatusChangeItem), links: itemsCommonItemLinks, version: z.number().int().gte(1).optional(), object: z.literal("Receivable"), deposit_into_account: accountsCompactAccountBank.optional(), due_from_company: companiesCompactCompany, send_on: z.string().nullable().optional(), terms: itemsCommonReceivableTerms.optional(), type: z.literal("invoice"), attachments: z.object({object: z.literal("List"), results: z.array(sharedAttachment)}), ledger: z.union([z.object({memo: z.string().optional(), tax_style: z.enum(["exclusive", "inclusive", "none"]).optional(), id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()}), z.object({class: ledgersQboQBOClass.optional(), department: ledgersQboQBODepartment.optional(), discount: z.number().optional(), discount_calculation: z.enum(["amount", "percentage"]).optional(), discount_style: z.string().optional(), memo: z.string().optional(), tax_auto: z.boolean().optional(), tax_code: z.object({id: z.string()}).optional(), id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()}), z.object({department: ledgersNetsuiteNetSuiteDepartment.optional(), posting_period: ledgersNetsuiteNetSuitePostingPeriod.optional(), id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()}), z.object({id: z.string().nullable().optional(), status: z.enum(["canceled", "deleted", "draft", "error", "needs_approval", "needs_import", "no_ledger", "not_synced", "paid", "pending"]).optional()})]).optional(), line_items: z.object({object: z.literal("List"), results: z.array(itemsReceivablesCommonReceivableLineItem)}).optional(), type_details: z.object({payment_delivery_method: z.literal("ach_standard").nullable().optional(), payment_type: z.literal("ach").optional(), transaction_id: z.string().max(65).nullable().optional()}).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 }; /** * Update a Receivable * * PATCH /v1/receivables/{id} */ export const patchApiV1ReceivablesId = async (args: PatchApiV1ReceivablesIdArgs, options?: PatchApiV1ReceivablesIdOptions) => { 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 (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/receivables/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(itemsReceivablesDiscriminatedReceivable, await res.json()) };