Skip to content

fix(shopping): parse Copilot shoppingProducts wrapper into per-product cards - #255

Merged
gkhngyk merged 1 commit into
mainfrom
fix/copilot-shopping-cards-wrapper
Jun 15, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/copilot-shopping-cards-wrapper

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Microsoft Copilot returns shopping data as a wrapper object { type, layout, products: [...] }, not a flat array of product cards (confirmed against the Cloro docs). The normalizer treated each wrapper as a single card and looked for the product name at the wrapper level — which only has type / layout / products — so:

  • every Copilot result collapsed to one empty row → the drawer showed "Cards returned (1)" / "Unknown Product"
  • the real products inside products[] (name, price, image, rating) were silently dropped

100% of stored Copilot cards (28/28) were affected; Perplexity / Google AI Mode are unaffected (different, already-flat shapes).

Fix

  • normalizeShoppingCards — flatten products[] wrappers into one normalized card per product (platform-agnostic; flat cards pass through untouched)
  • parseCopilotCard — map the documented product schema: name, brandName / seller, images[].url, rating.{value,count} (object), and the product's flat 1-indexed position (kept unique per result). Older fallbacks (productName, imageUrl, numeric rating) retained.
  • parsePrice — derive the ISO currency from currencySymbol (e.g. ₺ → TRY, $ → USD) when currency is null, which it is for non-US Copilot results

Tests

Adds server/src/lib/shopping-cards.test.js (8 tests) covering the wrapper flatten, name extraction, symbol-only currency, images[].url, the rating object, and brand fallback. vitest + prettier + eslint clean.

Validation

Ran the new normalizer against real stored data: a wrapper that previously produced 1 "Unknown Product" now expands to its 6 real products with title, price, currency, merchant domain, image, and rating all populated.

Data backfill

The 28 stale empty rows have already been removed and re-derived from prompt_results.shopping_cards via backfill-shopping-cards.js (162 correct product cards, 0 null titles). No further data step is needed — this PR only needs a server redeploy so new Copilot results parse correctly going forward.

…t cards

Microsoft Copilot returns shopping data as a wrapper object
{ type, layout, products: [...] } rather than a flat array of cards. The
normalizer treated each wrapper as a single card and looked for the product
name at the wrapper level (which only has type/layout/products), so every
Copilot card landed as one empty row -> 'Unknown Product' in the UI, and the
real products inside products[] were dropped.

- normalizeShoppingCards: flatten products[] wrappers into individual cards
- parseCopilotCard: map the documented Cloro product schema (name,
  brandName/seller, images[].url, rating.{value,count}, flat position)
- parsePrice: derive ISO currency from currencySymbol when currency is null

Adds shopping-cards.test.js covering the wrapper + symbol-only currency.
@gkhngyk
gkhngyk merged commit f2ebd30 into main Jun 15, 2026
4 checks passed
@gkhngyk
gkhngyk deleted the fix/copilot-shopping-cards-wrapper branch June 15, 2026 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant