/** * What a cart recovery link (`buildCartRecoveryUrl`) does. The link's route * (`cartRecover`) keeps the token in the session; `/cart/recover` * (`cartRecoverConfirm`) asks `decideCartRecovery`, shows a button when the * cart can be restored, and its POST calls `restoreCart`. * * Opening the link changes nothing: only the button does. Email security * scanners open every link in an email as soon as it arrives, never click, * and a link works once: a restore on opening would let a scanner use it up. */ declare module 'express-session' { interface SessionData { /** The recovery link the visitor opened, or `restored` once it was used */ cartRecovery?: { token?: string; restored?: boolean; }; } } export interface RecoverableCart { cart_id: number; uuid: string; sid: string | null; customer_id: number | null; } export interface CartRecoveryVisitor { sessionId: string; /** The signed-in customer, as `request.getCurrentCustomer()` gives it */ customer?: { customer_id: number; email?: string; group_id?: number; full_name?: string; } | null; } export type CartRecoveryDecision = /** Bad or expired link, an ordered cart, or another customer's */ { action: 'invalid'; } /** * The link was used already: its cart was closed by a restore (closed, * and no order from it is alive: none, or only orders canceled before they * were placed, whose cart `cancelAbandonedOrder` gave back). An email flow * puts the same link in every email, so a shopper can come back to it. */ | { action: 'restored'; } /** A customer's cart and the visitor is not signed in */ | { action: 'login'; } /** The visitor may restore it */ | { action: 'ready'; cart: RecoverableCart; }; export declare function decideCartRecovery(token: string | undefined, visitor: CartRecoveryVisitor): Promise; /** * The saved cart's items for the page to list, as the cart service builds * them (today's price, image, options). Items the cart service would refuse * (a disabled or out-of-stock product) are left out: `restoreCart` skips them * too. Deleted products are already gone (`cart_item` cascades). */ export declare function savedCartItems(cart: RecoverableCart): Promise>>; /** * Gives the visitor the saved cart's products: they are added to the * visitor's own cart (a new one when there is none) through the cart service, * so stock and prices are checked; an item that cannot be added (disabled, * out of stock) is skipped. The saved cart's coupon is applied when the * visitor's cart has none. The saved cart itself is closed first, in one * statement, so the link works once even when clicked twice at the same * moment; its email and addresses never reach another browser, and whoever * knew its uuid learns nothing about the visitor. The visitor's cart is never * closed. */ export declare function restoreCart(saved: RecoverableCart, visitor: CartRecoveryVisitor, context?: Record): Promise<{ added: number; skipped: number; }>;