import type { CartLine } from './cart.js'; import type { CurrencyCode, MinorUnits, ShippingOption } from './types.js'; /** * What a merchant adapter read off the page, before any of it is believed. * * Every field is a raw string, deliberately. An adapter that returned numbers * would be doing the parsing, which would put a copy of the parse rules in every * adapter and make each new merchant a new chance to get them wrong. */ export interface RawCheckoutReading { readonly lines: readonly { readonly label: string; readonly quantity: string; readonly unitPrice: string; }[]; readonly tax: string | null; readonly fees: readonly { readonly label: string; readonly amount: string; }[]; readonly shippingOptions: readonly { readonly label: string; readonly cost: string; }[]; /** The page's own stated grand total. Used to contradict us, never to inform us. */ readonly statedTotal: string | null; /** ISO-4217 as the page presented it, when it presented one at all. */ readonly currency: string | null; /** * The order summary as text, for `detectRecurringCharge`. * * The one place raw page text is read to look for a reason to STOP. Untrusted * content may always talk us out of an action; what it may never do is talk us * into one. */ readonly orderSummaryText: string; } /** The same checkout, in integers this code produced. */ export interface ExtractedCheckout { readonly currency: CurrencyCode; readonly lines: readonly CartLine[]; readonly itemMinorUnits: MinorUnits; readonly taxMinorUnits: MinorUnits; readonly feesMinorUnits: MinorUnits; readonly feeLabels: readonly string[]; readonly shippingOptions: readonly ShippingOption[]; /** Item + tax + fees. Delivery is added once a tier is chosen. */ readonly subtotalMinorUnits: MinorUnits; readonly orderSummaryText: string; } export type ExtractionResult = { readonly ok: true; readonly checkout: ExtractedCheckout; } | { readonly ok: false; readonly reason: string; readonly field: string; }; /** * Turn a reading into integers, or refuse and say which field defeated it. * * `fallbackCurrency` is the budget's currency, used only when the page states * none. It is not used to override a currency the page DID state: a page priced * in one currency and a budget in another is a mismatch `decidePurchase` refuses * on, and quietly relabelling the page's number with our currency code is how * that refusal would be bypassed. */ export declare function extractCheckout(raw: RawCheckoutReading, fallbackCurrency: CurrencyCode): ExtractionResult; //# sourceMappingURL=checkout-extraction.d.ts.map