← Back to Pull requests

feat: brand list prices on buy-from-brand links (Looks shopping list, wishlist rows, detail) #406

Closed
unknown closed this pull request without merging on Oct 23, 2026 00:40 UTC
View on GitHub
unknown unknown commented on Oct 23, 2026 00:27 UTC
Author

Carries brand list prices from ingestion to the "Buy from brand" link (#267 follow-up) and shows them on the Looks shopping list, wishlist/catalog rows, the detail page and the mobile detail screen.

What changed

Ingestion (lib/product-price.ts)

  • Connectors write price (decimal string, major units) and currency (ISO 4217 or null) into external_product.normalized_json.

  • Shopify-style stores (Holo Taco + every generic Shopify source) use the lowest price among available variants, or the lowest of all variants when every one is sold out. Zero, non-numeric and absurd prices are ignored.

  • The Shopify store currency comes from data_source.metadata.currency when that is set. Otherwise the connector asks the shop's /meta.json once per run, and only when some product has a price. If neither gives a currency it stays null; USD is never assumed. Job metrics record storeCurrency / storeCurrencySource.

  • MakeupAPI: the price is normalized, and its ISO currency is kept only when present. price_sign is never turned into a currency.

  • OpenBeautyFacts has no price data, so nothing changes there.

  • New npm run backfill:product-price (dry run by default; --write, --source, --no-fetch-currency, --limit, --verbose) re-derives prices from raw_json with the same helpers. Per source, the currency comes from metadata, then from currencies earlier ingests already stored, then from /meta.json. It never clears a currency already stored on a row.
  • API (lib/buy-link.ts)

  • selectBuyFromBrandLink returns { url, price?, currency?, priceSeenAt? }, all from the same chosen product (a runner-up's price is never used).

  • Polish list/detail and catalog search/shade responses gain optional buyPrice / buyCurrency / buyPriceSeenAt (shared types). These appear only when both an amount and a valid currency are stored. priceSeenAt is external_product.fetched_at.

  • These are vendor list prices, never the user's purchasePrice. polishes.ts is unchanged (the fields come through withBuyUrls).
  • Web

  • BuyFromBrandLink takes an optional price and renders it with Intl.NumberFormat plus a small "as of <date>" hint.

  • /polishes shows it on wishlist and catalog rows (not owned rows); the detail page always shows it.

  • The Looks shopping list shows each item's price and a per-currency subtotal. Currencies are never added together, the same rule as collection stats. The copied text includes the prices and the subtotal.
  • Mobile

  • The detail screen shows "Brand price $X · as of …" under the buy button.
  • Docs

  • CLAUDE.md (Buy from brand + Dev Commands), README, functions/shared/web/mobile READMEs, the Looks plan status, and the docs/schema.sql comment for data_source.metadata.currency.
  • Verification


  • ✅ npm run typecheck, npm run lint (no new warnings), and unit tests all pass: functions 2352 passed, 0 failed (1 skipped); web 649 passed; mobile and shared pass.

  • ✅ New tests:

  • - tests/product-price.unit.test.cjs, with fixture tests/fixtures/shopify-price-products.json. It covers several variants, sold-out variants, unpriced variants, a missing currency, a configured currency, the /meta.json lookup and failures, MakeupAPI, and the backfill plan/run.
    - buy-link price tests in buy-link.unit.test.cjs.
    - Web buy-price.test.ts and looks-detail.test.ts for per-currency subtotal grouping.
    - Mobile buy-price.test.ts.
  • ✅ Live connector run (no DB writes) against LightsLacquerShopify: 182 of 182 products priced; currency USD learned from /meta.json.

  • ✅ Backfill against the local dev Postgres (localhost:55432; no Azure database touched):

  • - The dry run reported 306 of 306 external_product rows would update (HoloTaco 155, Mooncat 101, Lights Lacquer 50), all 306 priced with a currency. All three stores answered /meta.json with USD.
    - Those products link 223 shades with a buy URL.
    - I then ran --write locally; a second dry run reports 0 to update, so the backfill is idempotent.
  • ✅ Local Functions + web check:

  • - GET /api/polishes returns buyPrice/buyCurrency/buyPriceSeenAt (176 of 200 rows on the first page).
    - /polishes rows show "Buy from brand ↗ $18.00 as of Feb 14, 2026".
    - The detail page shows "$13.00 as of Feb 14, 2026" beside the button.
  • ⚠️ Not checked in the browser:

  • - The Looks shopping list with prices. The dev user owns a match for every look I generated, so the dialog never had missing items. The subtotal and price logic is unit-tested.
    - The mobile screen (unit-tested and typechecked only).
  • ℹ️ Reviews:

  • - The access-control review found no issues. One optional hardening was noted: the /meta.json fetch follows redirects, the same as the existing products.json fetch, and only a validated ISO code is ever used.
    - The docs-sync check found only the mobile README gaps, now fixed.

    After deploy


  • Run npm run backfill:product-price --workspace=swatchwatch-functions (dry run first) against each environment by hand. Not run against any Azure database in this PR.

  • Optional: set data_source.metadata.currency for a store whose /meta.json is blocked.
  • 🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Brand list prices and “as of” dates now appear beside purchase links on web and mobile when valid price and currency information is available.
    Shopping lists show item prices and subtotals grouped by currency, count items without known prices, and include price details in copied list text. Different currencies are never combined.
    * Catalog and purchase-link details now include optional brand price information.

    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: mattmck Review duration: 13m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.52) × (1 − Review Confidence (0.53)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 83% · Reviewer familiarity: 35%
    52%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #406"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 52.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 52.6% · Lower = rushed or shallow review
    52.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.7% · Safe to merge
    24.7%