import { t as StandardSchemaV1 } from "./standard-DIedMFAS.js"; import { a as StandardParseResult } from "./index-BUFkuwVT.js"; //#region src/core/commerce/cart.d.ts /** A cart line as far as verification cares. Extra fields ride along untouched. */ interface CartLine { variantId: string; quantity: number; /** * The unit price the customer was shown, in minor units—compared against * the live price as given. If modifiers are priced by the provider (Square * does), this is the BASE price and modifier prices are not compared. */ unitPriceCents: number; /** Selected add-ons. Only their `id` is read; `name` etc. ride along. */ modifiers?: M[]; } type CartIssue = /** The variant still sells, at a different price. `unitPriceCents` is now. */ { kind: "price-changed"; variantId: string; unitPriceCents: number; wasCents: number; } | /** The variant is gone from the catalog (or not sold where this order is placed). */ { kind: "unavailable"; variantId: string; } | /** The variant exists and is priced, but has no stock. */ { kind: "out-of-stock"; variantId: string; } | /** A selected add-on was deleted. The provider would reject the whole order. */ { kind: "modifier-unavailable"; modifierId: string; }; interface CatalogSnapshot { /** Live unit prices by variant id, minor units. A variant absent here is unavailable. */ prices: ReadonlyMap; /** * Variants that are priced but sold out. Checked BEFORE the price: a * sold-out variant usually still has one, and reading the price first would * let the charge through. */ outOfStock?: ReadonlySet; /** * Add-on ids that still exist. Omit to skip the add-on check entirely (for a * catalog without add-ons); pass an empty set to treat every add-on as gone. */ liveModifierIds?: ReadonlySet; } /** * Every way `lines` disagrees with the live catalog—not just the first—in * cart order, one issue per variant or add-on however many lines share it. * An empty array means the cart can be charged as shown. * * Validate the lines first (integer quantity ≥ 1, finite price): this compares * a well-formed cart against the catalog, it does not police input. */ declare function cartIssues(lines: readonly CartLine[], catalog: CatalogSnapshot): CartIssue[]; /** Every add-on ID across `lines`, de-duplicated—what to ask the provider about. */ declare function cartModifierIds(lines: readonly CartLine[]): string[]; /** What {@link repairCart} did, as data—the site words it for its customers. */ type CartChange = { kind: "repriced"; line: L; fromCents: number; toCents: number; } | { kind: "removed"; line: L; reason: "unavailable" | "out-of-stock"; } | { kind: "modifier-removed"; line: L; modifier: NonNullable[number]; } | /** * Removing an add-on made `line` identical to `into`, so they were combined. * `droppedQuantity` is how much the cap cut off (0 when nothing was lost). */ { kind: "merged"; line: L; into: L; droppedQuantity: number; }; interface RepairCartOptions { /** * What makes two lines "the same thing"—merged after an add-on is * removed. Default: the variant plus its sorted add-on IDs. */ key?: (line: L) => string; /** Per-line quantity cap applied when merging. Default: none. */ maxQuantity?: number; } /** * Apply `issues` to `lines`: reprice changed variants, remove unavailable and * sold-out ones, strip deleted add-ons—then fold together any lines that * became identical. Returns the new lines (inputs are not mutated) and every * change made, in order, for the site to tell the customer about. */ declare function repairCart(lines: readonly L[], issues: readonly CartIssue[], options?: RepairCartOptions): { lines: L[]; changes: CartChange[]; }; //#endregion //#region src/core/commerce/checkout-session.d.ts /** The slice of the Web Storage API a session uses. */ interface CheckoutSessionStorage { getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; } interface CheckoutSessionOptions { /** The storage key the ID lives under. One per cart, so two carts on one * origin never share an attempt. */ storageKey: string; /** * How long an unused ID stays current, in milliseconds. Each call to `id()` * restarts it, up to `maxAgeMs`. No default: how long a leftover cart stays * the same order is the shop's call. */ idleMs: number; /** * The longest an ID lives from when it was minted, in milliseconds, however * often it's used. At least `idleMs`. Keep the server's record of an * attempt's outcome longer than this, so every retry the client still calls * this attempt finds that record. Without a cap, a retry every hour would * keep the ID past any record's expiry. */ maxAgeMs: number; /** Where the ID persists. Defaults to `globalThis.localStorage`, read on each * call. */ storage?: CheckoutSessionStorage; } interface CheckoutSession { /** * The ID for the cart `fingerprint` describes: the stored one while it was * minted for that fingerprint, used within `idleMs`, and minted within * `maxAgeMs`, otherwise a new one, stored before it's returned. */ id(fingerprint: string, now?: number): string; /** Retire the ID, so the next checkout is a new attempt: after an order is * placed, or after a definite decline, when nothing was charged. */ rotate(): void; } /** * A checkout-session ID that persists beside a stored cart and changes only * when the cart does, after `idleMs` unused, `maxAgeMs` after it was minted, or * on `rotate()`. * * Send `session.id(cartFingerprint(lines))` with each checkout, call * `rotate()` once an order is placed and after a definite decline, and derive * the server's payment idempotency key from the ID and the lines as chosen, * never from prices or a tip. * * Storage that throws (private browsing, a full quota) moves the ID to page * memory for the rest of the page's life, where a reload starts a new attempt. * While storage works, it alone is the truth, so another tab's `rotate()` * retires the ID here too. Storage has no compare-and-set, so this narrows * the window without closing it: two tabs that mint an ID for the same cart * at the same moment can still send different ones. * * A browser primitive. On a server, where there's no `document`, memory is * shared by every request, so without a `storage` option a session keeps * nothing between calls: two customers with the same cart must never share an * ID, or the second one's payment is deduplicated into the first one's. */ declare function checkoutSession(options: CheckoutSessionOptions): CheckoutSession; /** * What makes two carts the same order, for {@link checkoutSession}: how many of * each variant-and-add-ons combination they hold. Prices are left out, so a * price repair keeps the attempt. Line order, add-on order, and how the * quantity is split across lines don't matter. */ declare function cartFingerprint(lines: readonly Pick[]): string; //#endregion //#region src/core/commerce/sync.d.ts interface VanishedRowsOptions { /** The provider's id for a stored row, or `null` for a row the provider doesn't own. */ externalId: (row: T) => string | null; /** * Whether the row is already marked as gone. Such rows are skipped, so the * mark is idempotent—a product gone for a month is not re-stamped (and, if * marking also unpublishes, not re-unpublished) on every sync. */ alreadyMarked?: (row: T) => boolean; } /** * Stored rows a completed catalog read did NOT contain: the products the * provider dropped. Pure, so the decision of what gets taken off a shop is * testable without a live catalog. * * Diffed in memory rather than as a SQL `NOT IN (…)`: SQLite (D1 included) caps * bound parameters, so a large enough catalog would turn that clause into an * error—at exactly the size where nobody can check by hand. * * What to DO with the result is policy, and the dangerous part: call this only * after a read you know is complete, and never act on an empty `seen`. A revoked * token or an endpoint answering `[]` reads as "the provider has nothing", and * would retire the whole shop on a schedule. */ declare function vanishedRows(stored: readonly T[], seen: ReadonlySet, options: VanishedRowsOptions): T[]; //#endregion //#region src/core/commerce/money.d.ts /** * The number of minor-unit digits `currency` uses: 2 for USD, 0 for JPY, 3 for * BHD. Read from `Intl`, so it's right for every ISO 4217 code the runtime * knows. Throws a `RangeError` for a malformed code. */ declare function currencyDigits(currency: string): number; /** * Minor units to major units: `2500` is `25`. * * `fractionDigits` is the currency's minor-unit count, as for * {@link majorToCents}. The default of 2 is right only for a two-decimal * currency such as USD. For a `Money`, pass `currencyDigits(money.currency)`, * or use {@link formatMoney} if the result is for a person to read. */ declare function centsToMajor(cents: number, fractionDigits?: number): number; /** * A major-unit amount (dollars) as minor units (cents), rounded half away from * zero at the minor unit. * * `Math.round(amount * 100)` is the usual version, and it is wrong for amounts * whose binary form sits just under the half: `1.005 * 100` is * `100.49999999999999`, so it rounds to 100, not 101. This shifts the decimal * point in the number's decimal STRING instead, which is exact for every * amount that has one. * * `fractionDigits` is the currency's minor-unit count—2 for USD, 0 for JPY, * 3 for BHD. */ declare function majorToCents(amount: number, fractionDigits?: number): number; /** * Money a person typed—"12", "12.5", "12.50"—as minor units, or `null` if it * isn't a plain non-negative amount with at most `fractionDigits` decimals. * * Parsed as text, never through `parseFloat`, so nothing drifts. Strict on * purpose: no sign, no thousands separators, no currency symbol, no exponent, * no locale decimal comma. Strip a symbol before calling if your field shows * one; a form that must accept "1.234,50" needs a locale-aware parser this is * not. Surrounding whitespace is allowed. */ declare function parseMoneyInput(input: string, fractionDigits?: number): number | null; /** Options for {@link formatMoney}: a locale plus any `Intl.NumberFormat` option. */ interface FormatMoneyOptions extends Omit { /** BCP 47 locale the text is for, for example, `"en-US"`. A site fact, so no default. */ locale: string; } /** * A `Money` as text for a person: `{ amount: 125000, currency: "USD" }` is * `"$1,250.00"` in `en-US`, and `{ amount: 1250, currency: "JPY" }` is * `"¥1,250"`. The minor-unit count comes from the currency, never an assumed 2. * * Any other `Intl.NumberFormat` option passes through. For a dashboard total * in whole units, pass `maximumFractionDigits: 0`. By default a price keeps * the currency's full minor unit (`"$12.50"`, never `"$12.5"`). */ declare function formatMoney(money: Money, options: FormatMoneyOptions): string; /** Options for {@link parseMoney}. Both are site facts, so neither has a default. */ interface ParseMoneyOptions { /** BCP 47 locale the text was typed in. It decides which of `.` and `,` is the decimal point. */ locale: string; /** ISO 4217 code, for example, `"USD"`. It decides the symbol and the minor-unit count. */ currency: string; } /** * Money a person typed the way {@link formatMoney} displays it, as minor units, * or `null`. What one prints, the other reads: in `en-US` with USD, * `"$1,200.50"`, `"1,200.50"`, and `"1200.5"` are all `120050`, and in `de-DE` * with EUR, `"1.200,50 €"` is too. * * It removes the currency's symbol and code and any whitespace, checks that * group separators sit where the locale puts them, turns the locale's decimal * separator into a point, and hands the rest to {@link parseMoneyInput} with * the currency's minor-unit count. So it's forgiving about format and still * strict about the amount: no sign, no exponent, no more decimals than the * currency has. `"12.5"` in `de-DE` is `null`, not 125 euros, because `.` * there groups thousands and a group holds three digits. */ declare function parseMoney(input: string, options: ParseMoneyOptions): number | null; //#endregion //#region src/core/commerce/tip.d.ts /** The cap on a tip, from {@link tipCap}'s options. Both bounds are shop policy. */ interface TipCapOptions { /** The cap never falls below this, however small the order: a $3 coffee can still take a $5 tip. */ floorCents: number; /** The cap never rises above this, however large the order. */ ceilingCents: number; /** * The cap as a percentage of the subtotal, before the floor and ceiling * apply. Defaults to 100: a tip up to the order's own size. */ subtotalPercent?: number; } /** * `percent` of `subtotalCents`, in cents, rounded half away from zero at the * cent: 15 percent of 1,005 cents is 151, not 150. * * Computed in integers, so a fractional percentage such as 12.5 or 17.3 is * exact up to six decimals. Throws a `RangeError` for a negative or fractional * subtotal, or a negative percentage. */ declare function percentTip(subtotalCents: number, percent: number): number; /** * The largest tip a shop accepts on `subtotalCents`: `subtotalPercent` of the * subtotal (100 by default), raised to `floorCents` and lowered to * `ceilingCents`. With a floor of 2,000 and a ceiling of 10,000, a 900-cent * order caps at 2,000, a 4,500-cent order at 4,500, and a 25,000-cent order at * 10,000. * * Take the subtotal from the payment provider's calculated order, on the * client and the server both. Two sides that each add up their own subtotal * disagree near the cap, and then a tip the page offered is one the server * refuses. With Square, that's `orderSubtotal` from * `louise-toolkit/commerce/square`. * * Throws a `RangeError` when a bound isn't whole cents or the floor is above * the ceiling. */ declare function tipCap(subtotalCents: number, options: TipCapOptions): number; /** * A tip from a request body as whole cents, or 0. * * A non-negative number is rounded to the nearest cent, so a page that sends * `150.75` from unrounded percentage math charges 151, not nothing. A string * of digits alone (`"150"`, surrounding whitespace allowed) reads the same * way, for a form-encoded body. Everything else is 0: a negative number, * `NaN`, `Infinity`, `"1.50"`, `"$2"`, `null`, and a missing field. A tip the * server can't read charges nothing, rather than a guess at what the customer * meant. To read a tip a person typed in dollars, use `parseMoneyInput` * instead. */ declare function parseTipCents(value: unknown): number; /** * `tipCents` limited to {@link tipCap} on `subtotalCents`: what the server * charges. A tip under the cap passes through unchanged. Run a tip from a * request through {@link parseTipCents} first, which turns anything that isn't * whole cents into 0. * * To refuse an over-cap tip rather than lower it, compare against * {@link tipCap} yourself: whether to charge less than the customer chose, or * ask them again, is the shop's call. */ declare function clampTip(tipCents: number, subtotalCents: number, cap: TipCapOptions): number; //#endregion //#region src/core/commerce/index.d.ts /** * Parse a signature-verified webhook body against its event schema. Run this * AFTER the provider's `verify…Signature` returns true: the HMAC proves the * sender, this proves the *shape*—a signature can't tell you the provider * didn't change the payload. Malformed JSON or a shape mismatch both come back * as violations (never a throw), so a handler can reject uniformly. Each * provider module exports its schema—{@link * import("./stripe.js").stripeWebhookEventSchema}, * {@link import("./square.js").squareWebhookEventSchema}, * {@link import("./fourthwall.js").fourthwallOrderEventSchema}. */ declare function parseWebhookEvent(schema: Schema, rawBody: string): Promise>>; /** A money amount, expressed in a currency's minor unit (for example, cents). */ interface Money { /** Amount in the currency's minor unit—cents for USD. */ amount: number; /** ISO 4217 currency code, for example, "USD". */ currency: string; } /** HMAC-SHA256 of `message` under `secret`, hex-encoded (Stripe's encoding). */ declare function hmacSha256Hex(secret: string, message: string): Promise; /** HMAC-SHA256 of `message` under `secret`, base64-encoded (Square + Fourthwall). */ declare function hmacSha256Base64(secret: string, message: string): Promise; /** * Constant-time-ish string compare (avoids early-exit timing leaks). Compare a * freshly-computed signature against the value from a request header with this. */ declare function safeEqual(a: string, b: string): boolean; //#endregion export { RepairCartOptions as A, CheckoutSessionStorage as C, CartIssue as D, CartChange as E, cartModifierIds as M, repairCart as N, CartLine as O, CheckoutSessionOptions as S, checkoutSession as T, parseMoney as _, safeEqual as a, vanishedRows as b, parseTipCents as c, FormatMoneyOptions as d, ParseMoneyOptions as f, majorToCents as g, formatMoney as h, parseWebhookEvent as i, cartIssues as j, CatalogSnapshot as k, percentTip as l, currencyDigits as m, hmacSha256Base64 as n, TipCapOptions as o, centsToMajor as p, hmacSha256Hex as r, clampTip as s, Money as t, tipCap as u, parseMoneyInput as v, cartFingerprint as w, CheckoutSession as x, VanishedRowsOptions as y };