/** * Shaping transaction data for a model. * * ThriveCart is inconsistent about field names across endpoints and across * account vintages: an amount arrives as `amount` or `total`, a date as `date` * or `created_at`, a product name as `item_name` or `product_name`. Reading * those keys inline at each call site is how a revenue total silently comes * back as zero. `parseFloat(undefined)` is NaN, and NaN added to a running sum * poisons the whole figure without ever throwing. * * So every read of those fields goes through here, and money is summed in * integer cents rather than floats, because 0.1 + 0.2 is not 0.3 and a revenue * report that is off by a penny is a revenue report nobody trusts. */ export type RawTransaction = Record; export declare function itemName(row: RawTransaction): string; /** Transaction date as a Date, or undefined when ThriveCart sent nothing usable. */ export declare function transactionDate(row: RawTransaction): Date | undefined; /** * Transaction amount in integer cents. * * Returns 0 rather than NaN for a row with no readable amount, so one odd row * cannot poison a total. Amounts already in cents (ThriveCart sends these on * some endpoints) are detected by the absence of a decimal point. */ export declare function amountCents(row: RawTransaction): number; export declare function centsToAmount(cents: number): number; /** Pull the transaction array out of whichever envelope ThriveCart used. */ export declare function transactionsFrom(payload: unknown): RawTransaction[]; /** Keep rows inside an inclusive date range. Rows with no date are kept. */ export declare function filterByDate(rows: RawTransaction[], from: string | undefined, to: string | undefined): RawTransaction[]; /** Case-insensitive contains match on the product name. */ export declare function filterByItemName(rows: RawTransaction[], needle: string): RawTransaction[]; export type ProductSummary = { product: string; sales: number; revenue: number; }; /** Group transactions by product, sorted by revenue, highest first. */ export declare function summariseByProduct(rows: RawTransaction[]): { products: ProductSummary[]; totalSales: number; totalRevenue: number; };