Repository navigation
fix(shopping): parse Copilot shoppingProducts wrapper into per-product cards - #255
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 hastype/layout/products— so:products[](name, price, image, rating) were silently dropped100% of stored Copilot cards (28/28) were affected; Perplexity / Google AI Mode are unaffected (different, already-flat shapes).
Fix
normalizeShoppingCards— flattenproducts[]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-indexedposition(kept unique per result). Older fallbacks (productName,imageUrl, numericrating) retained.parsePrice— derive the ISO currency fromcurrencySymbol(e.g.₺→TRY,$→USD) whencurrencyis null, which it is for non-US Copilot resultsTests
Adds
server/src/lib/shopping-cards.test.js(8 tests) covering the wrapper flatten,nameextraction, symbol-only currency,images[].url, the rating object, and brand fallback.vitest+prettier+eslintclean.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_cardsviabackfill-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.