Skip to content

feat(shopping): normalize prompt_result_shopping_cards + parser worker #103

Closed

Description

@gkhngyk

Context

We now capture shopping cards from three platforms into prompt_results.shopping_cards as raw provider-shape JSONB:

The raw JSONB is fine for storage but useless for analytics — querying "which competitor's products are in my shopping cards?" today means scanning every prompt_result and JSON-parsing in app code. The forthcoming Shopping dashboard page (see B–D below) and the MCP shopping tool (E) both need normalized rows.

Acceptance criteria

  • Migration adds prompt_result_shopping_cards table — one row per card per prompt_result, with columns: prompt_result_id, brand_id (denorm for fast org-scoped queries), position, product_title, product_brand, price_amount, price_currency, image_url, merchant_url, merchant_domain, rating, review_count, raw (original card jsonb, future-proof), matched_brand_id, matched_brand_role (own | competitor | other), plus denorm platform, region, created_at.
  • Indexes: (brand_id, matched_brand_role), (product_brand), (merchant_domain).
  • RLS policy mirrors prompt_results (org-scoped).
  • Parser module at server/src/lib/shopping-cards.js with one normalizer per provider (parsePerplexityCard, parseAiModeCard, parseCopilotCard). Each handles the live provider shape — not the docs shape (see feat(tracking): capture Google AI Mode shopping_cards data into prompt_results #49 retro: AI Mode is camelCase not snake_case).
  • cloro-result-handler.js calls the normalizer after the prompt_results insert, inserts normalized rows in a single statement.
  • Brand matching is delegated to the existing brand/competitor matcher used by citations — own if card brand/title contains tracked brand name OR merchant_domain matches tracked brand domain; competitor if it matches any tracked competitor; else other.
  • Backfill script: server/src/scripts/backfill-shopping-cards.js walks existing prompt_results.shopping_cards rows (last 90d) and populates the normalized table.
  • Backfill is idempotent (ON CONFLICT (prompt_result_id, position) DO NOTHING or similar).

Out of scope

Notes

This is the blocker for the Shopping page work — open this first, merge first, then B/C/D can land in parallel.

Activity

  1. added
    enhancement
    on May 26, 2026
  2. added a commit that references this issue on Jun 1, 2026
    048e5d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions