/** * QuickBooks Online Integration for WORKWAY * * Unified client for QuickBooks Online accounting operations: Invoices, Customers, Payments. * Designed for financial automation workflows - sync invoices, track payments, * and trigger follow-up actions. * * Zuhandenheit: "Invoices that chase themselves" not "POST /invoice endpoint" * * @example * ```typescript * import { QuickBooks } from '@workwayco/integrations/quickbooks'; * * const qb = new QuickBooks({ * accessToken: tokens.quickbooks.access_token, * realmId: tokens.quickbooks.realm_id, * }); * * // Get overdue invoices * const overdue = await qb.getOverdueInvoices(); * * // Create invoice * const invoice = await qb.createInvoice({ * customerId: '123', * lineItems: [{ description: 'Consulting', amount: 1500 }], * }); * * // Record payment * await qb.recordPayment({ * customerId: '123', * amount: 1500, * invoiceId: invoice.data.Id, * }); * ``` */ import { ActionResult } from '@workwayco/sdk'; import { BaseAPIClient } from '../core/index.js'; /** * QuickBooks integration configuration */ export interface QuickBooksConfig { /** OAuth access token */ accessToken: string; /** QuickBooks company ID (realm ID) */ realmId: string; /** OAuth refresh token for automatic refresh */ refreshToken?: string; /** OAuth client ID (required for token refresh) */ clientId?: string; /** OAuth client secret (required for token refresh) */ clientSecret?: string; /** Callback when token is refreshed */ onTokenRefreshed?: (accessToken: string, refreshToken?: string) => void | Promise; /** Optional: Override API endpoint (for testing or sandbox) */ apiUrl?: string; /** Use sandbox environment */ sandbox?: boolean; /** Request timeout in milliseconds (default: 30000) */ timeout?: number; } /** * QuickBooks Invoice */ export interface QBInvoice { Id: string; DocNumber?: string; TxnDate: string; DueDate?: string; TotalAmt: number; Balance: number; CustomerRef: { value: string; name?: string; }; BillEmail?: { Address: string; }; Line: QBInvoiceLine[]; LinkedTxn?: Array<{ TxnId: string; TxnType: string; }>; EmailStatus?: 'NotSet' | 'NeedToSend' | 'EmailSent'; PrintStatus?: 'NotSet' | 'NeedToPrint' | 'PrintComplete'; MetaData: { CreateTime: string; LastUpdatedTime: string; }; } /** * QuickBooks Invoice Line Item */ export interface QBInvoiceLine { Id?: string; LineNum?: number; Description?: string; Amount: number; DetailType: 'SalesItemLineDetail' | 'SubTotalLineDetail' | 'DescriptionOnly'; SalesItemLineDetail?: { ItemRef?: { value: string; name?: string; }; Qty?: number; UnitPrice?: number; }; } /** * QuickBooks Customer */ export interface QBCustomer { Id: string; DisplayName: string; CompanyName?: string; GivenName?: string; FamilyName?: string; PrimaryEmailAddr?: { Address: string; }; PrimaryPhone?: { FreeFormNumber: string; }; BillAddr?: QBAddress; Balance: number; Active: boolean; MetaData: { CreateTime: string; LastUpdatedTime: string; }; } /** * QuickBooks Address */ export interface QBAddress { Line1?: string; Line2?: string; City?: string; CountrySubDivisionCode?: string; PostalCode?: string; Country?: string; } /** * QuickBooks Payment */ export interface QBPayment { Id: string; TxnDate: string; TotalAmt: number; CustomerRef: { value: string; name?: string; }; Line?: Array<{ Amount: number; LinkedTxn: Array<{ TxnId: string; TxnType: string; }>; }>; PaymentMethodRef?: { value: string; name?: string; }; DepositToAccountRef?: { value: string; name?: string; }; MetaData: { CreateTime: string; LastUpdatedTime: string; }; } /** * QuickBooks Account */ export interface QBAccount { Id: string; Name: string; AccountType: string; AccountSubType?: string; CurrentBalance: number; Active: boolean; } /** * QuickBooks Company Info */ export interface QBCompanyInfo { Id: string; CompanyName: string; LegalName?: string; CompanyAddr?: QBAddress; Email?: { Address: string; }; WebAddr?: { URI: string; }; FiscalYearStartMonth?: string; Country?: string; } /** * QuickBooks query response wrapper */ export interface QBQueryResponse { QueryResponse: { Invoice?: T[]; Customer?: T[]; Payment?: T[]; Account?: T[]; startPosition?: number; maxResults?: number; totalCount?: number; }; } export interface CreateInvoiceOptions { /** Customer ID */ customerId: string; /** Line items */ lineItems: Array<{ description: string; amount: number; quantity?: number; itemId?: string; }>; /** Due date (ISO string) */ dueDate?: string; /** Customer email for sending invoice */ customerEmail?: string; /** Custom invoice number */ docNumber?: string; } export interface UpdateInvoiceOptions { /** Invoice ID */ invoiceId: string; /** Sync token (required for updates) */ syncToken: string; /** Line items to replace */ lineItems?: Array<{ description: string; amount: number; quantity?: number; }>; /** New due date */ dueDate?: string; } export interface ListInvoicesOptions { /** Filter by customer ID */ customerId?: string; /** Filter by status: 'open', 'overdue', 'paid' */ status?: 'open' | 'overdue' | 'paid'; /** Start date for filtering (ISO string) */ startDate?: string; /** End date for filtering (ISO string) */ endDate?: string; /** Maximum results (default: 100, max: 1000) */ limit?: number; /** Start position for pagination */ offset?: number; } export interface CreateCustomerOptions { /** Display name (required) */ displayName: string; /** Company name */ companyName?: string; /** First name */ givenName?: string; /** Last name */ familyName?: string; /** Email address */ email?: string; /** Phone number */ phone?: string; /** Billing address */ billingAddress?: { line1?: string; city?: string; state?: string; postalCode?: string; country?: string; }; } export interface RecordPaymentOptions { /** Customer ID */ customerId: string; /** Payment amount */ amount: number; /** Invoice ID to apply payment to */ invoiceId?: string; /** Payment date (ISO string, defaults to today) */ paymentDate?: string; /** Payment method ID */ paymentMethodId?: string; /** Deposit to account ID */ depositAccountId?: string; } export interface SearchOptions { /** Entity type to search */ entity: 'Customer' | 'Invoice' | 'Payment' | 'Account'; /** Search query (name, email, etc.) */ query: string; /** Maximum results */ limit?: number; } /** * QuickBooks Online Integration * * Weniger, aber besser: Unified accounting client for invoice and payment automation. */ export declare class QuickBooks extends BaseAPIClient { private readonly realmId; constructor(config: QuickBooksConfig); /** * Get company information */ getCompanyInfo(): Promise>; /** * Get an invoice by ID */ getInvoice(invoiceId: string): Promise>; /** * List invoices with optional filters */ listInvoices(options?: ListInvoicesOptions): Promise>; /** * Get overdue invoices (Zuhandenheit API) * * Outcome-focused: "Which invoices need follow-up?" */ getOverdueInvoices(): Promise>; /** * Create an invoice */ createInvoice(options: CreateInvoiceOptions): Promise>; /** * Send invoice by email */ sendInvoice(invoiceId: string, email?: string): Promise>; /** * Void an invoice */ voidInvoice(invoiceId: string, syncToken: string): Promise>; /** * Get a customer by ID */ getCustomer(customerId: string): Promise>; /** * List all customers */ listCustomers(limit?: number, offset?: number): Promise>; /** * Search for a customer by name or email */ searchCustomers(searchTerm: string): Promise>; /** * Create a customer */ createCustomer(options: CreateCustomerOptions): Promise>; /** * Get a payment by ID */ getPayment(paymentId: string): Promise>; /** * List recent payments */ listPayments(limit?: number, offset?: number): Promise>; /** * Record a payment */ recordPayment(options: RecordPaymentOptions): Promise>; /** * List chart of accounts */ listAccounts(): Promise>; /** * Get accounts receivable aging summary (Zuhandenheit API) * * Outcome-focused: "Who owes us money and for how long?" */ getReceivablesAging(): Promise>; /** * Verify QuickBooks webhook signature * * @param payload - Raw request body * @param signature - intuit-signature header * @param webhookVerifierToken - Your webhook verifier token from Intuit */ verifyWebhook(payload: string, signature: string, webhookVerifierToken: string): Promise>; /** * Get capabilities for QuickBooks actions */ private getCapabilities; } export interface QBWebhookEvent { realmId: string; dataChangeEvent?: { entities: Array<{ name: string; id: string; operation: 'Create' | 'Update' | 'Delete' | 'Merge' | 'Void'; lastUpdated: string; }>; }; } //# sourceMappingURL=index.d.ts.map