import {z} from 'zod' export type DeleteApiBillsBillIdDocumentsDocumentIdArgs = {document_id: string, bill_id: string, 'x-entity-id'?: string | undefined}; export type DeleteApiBillsBillIdDocumentsDocumentIdOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const billStatusEnum = z.enum(["CANCELED", "DRAFT_PROCESSING", "DRAFT", "PAYMENT_INFO_NEEDED", "PENDING", "APPROVED", "REJECTED", "SCHEDULED", "PAYMENT_INITIATED", "PAYMENT_DELIVERED", "PAYMENT_FAILED", "PAYMENT_CANCELED"]); export const dateString = z.string(); 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 billPaymentTypeEnum = z.enum(["ACH", "CRYPTO", "INTERNATIONAL_PAYMENT_FX", "WIRE", "CHECK"]); export const billCreationSourceEnum = z.enum(["USER", "EMAIL", "SCHEDULE"]); export const timestamp = z.string(); export const billLineItemTypeEnum = z.enum(["EXPENSE", "ITEM"]); export const billLineItemResponse = z.object({id: z.string(), amount: z.string(), quantity: z.string().nullable().optional(), description: z.string(), type: billLineItemTypeEnum, amount_total: z.string(), split_group: z.string().nullable().optional(), expense_account_external_id: z.string().nullable().optional(), class_external_id: 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 billPaymentDetailsResponse = z.object({account_id: z.string().nullable().optional(), payment_type: billPaymentTypeEnum.nullable().optional(), currency: iso4217Code.nullable().optional(), scheduled_payment_date: dateString.nullable().optional(), crypto_destination: cryptoContactDestinationResponse.nullable().optional(), ach_transfer_id: z.string().nullable().optional(), wire_transfer_id: z.string().nullable().optional(), crypto_transaction_hash: z.string().nullable().optional()}); export const billDocumentResponse = z.object({id: z.string(), name: z.string(), url: z.string(), created_at: timestamp}); export const integrationBillSyncStatus = z.enum(["synced", "requires_sync", "sync_complete", "sync_failed"]); export const integrationBillPaymentSyncStatus = z.enum(["synced", "requires_sync", "sync_complete", "sync_failed"]); export const integrationVendor = z.enum(["QuickBooks", "Xero", "NetSuite", "Puzzle", "Ramp", "Stripe", "Wave", "Relay", "Mastercard"]); export const billResponse = z.object({id: z.string(), status: billStatusEnum, vendor_name: z.string(), invoice_number: z.string().nullable().optional(), description: z.string().nullable().optional(), memo: z.string().nullable().optional(), bill_date: dateString.nullable().optional(), bill_due_date: dateString.nullable().optional(), bill_total: z.string().nullable().optional(), currency: iso4217Code.nullable().optional(), payment_type: billPaymentTypeEnum.nullable().optional(), contact_id: z.string().nullable().optional(), category_id: z.string().nullable().optional(), category_name: z.string().nullable().optional(), creation_source: billCreationSourceEnum, created_by: z.string(), created_at: timestamp, updated_at: timestamp.nullable().optional(), submitted_at: timestamp.nullable().optional(), submitted_by: z.string().nullable().optional(), paid_at: timestamp.nullable().optional(), paid_by: z.string().nullable().optional(), scheduled_at: timestamp.nullable().optional(), resolved_at: timestamp.nullable().optional(), canceled_at: timestamp.nullable().optional(), canceled_by: z.string().nullable().optional(), bill_schedule_id: z.string().nullable().optional(), ordinal: z.number().int().nullable().optional(), line_items: z.array(billLineItemResponse).optional(), bill_payment_details: billPaymentDetailsResponse.nullable().optional(), additional_documents: z.array(billDocumentResponse).optional(), img_url: z.string().nullable().optional(), rrule: z.string().min(1).max(120).nullable().optional(), auto_approval_enabled: z.boolean().nullable().optional(), bill_sync_status: integrationBillSyncStatus.nullable().optional(), payment_sync_status: integrationBillPaymentSyncStatus.nullable().optional(), accounting_vendor: integrationVendor.nullable().optional(), accounting_bill_id: z.string().nullable().optional(), is_excluded_from_accounting: z.boolean().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 }; /** * Delete Bill Document * * DELETE /bills/{bill_id}/documents/{document_id} */ export const deleteApiBillsBillIdDocumentsDocumentId = async (args: DeleteApiBillsBillIdDocumentsDocumentIdArgs, options?: DeleteApiBillsBillIdDocumentsDocumentIdOptions) => { 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['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(/\/+$/, '')}/bills/${encodeURIComponent(String(args.bill_id))}/documents/${encodeURIComponent(String(args.document_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(billResponse, await res.json()) };