mirror of
https://github.com/bitbaum/petvity.git
synced 2026-12-04 06:38:45 +01:00
The public storefront was a brochure. It shipped a Product/Offer JSON-LD so search engines treat it as purchasable, then the only buy path was "Sign up to buy" -> /register?returnTo=/portal/shop, which both forced registration before a first purchase and dropped the product the visitor came for. Cold traffic could not buy anything. A visitor can now add to cart on the catalogue and the product page, check out in one page with an email and an address, and read their order back from a receipt link. No account anywhere in that path. orders.userId becomes nullable, alongside guestEmail and an unguessable publicToken. A CHECK constraint enforces exactly one of userId / guestEmail, because an order with no reachable buyer cannot be repaired after the fact. The token is the guest's only handle on their order: it is emailed, never listed, and authorises resuming payment and cancelling while pending. Order placement moves to placeOrder() in lib/domain/orders.ts so the authed cart and the guest checkout share one implementation -- the stock reservation and its compensation must not exist twice. setOrderStatus() joins it for the same reason: a cancellation that forgot to restore stock destroys inventory, and that happens when one route remembers and another does not. Two joins were fixed before any UI existed. app/api/orders/seller and app/api/admin/orders inner-joined users on orders.userId; with a nullable column that drops every guest order from the views of the people who have to ship them -- real revenue, invisible, nothing appearing broken. Both are now leftJoin + COALESCE onto the address the buyer typed. Also fixed while reviewing: - toLocale() used `value in LOCALE_CONFIG`, true for inherited keys like "constructor", and the result goes straight into a URL path. - orderShippingSchema accepted any two letters as a country, so "XX" could be stored and printed on an undeliverable label. Checked against a new ISO-3166 SSOT whose names come from Intl.DisplayNames, so all nine locales are translated with no message files to maintain. - Guest input (shippingName, notes) reaches a seller's inbox unauthenticated; email templates now escape it. Guards, not just fixes: locale parity across all nine message files is now a test rather than a convention, and the prod walkthrough places a real guest order and asserts the seller can see the buyer's email -- the check that goes red if anyone reintroduces an inner join there. The public endpoints are deliberately outside PRIVATE_API_PREFIXES; a session guard there would silently delete the feature. They are rate limited per client, and the payment and cancel routes require the order token. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>