Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(shopping): recover merchant_domain from scheme-less merchant URLs (#888)
Shahzain Shafique129223be7976
diff --git a/server/src/lib/shopping-cards.js b/server/src/lib/shopping-cards.jsindex 98ad1c457..251c01c15 100644--- a/server/src/lib/shopping-cards.js+++ b/server/src/lib/shopping-cards.js@@ -25,8 +25,8 @@* and the cost of `?? otherName` is tiny.*/-import { URL } from 'node:url';import { logger } from './logger.js';+import { extractDomain } from './citation-rows.js';// Loose set of currency codes Perplexity / Copilot embed in price strings// like "$29.99", "EUR 19,90", "₺499". Anything else falls back to null —@@ -160,19 +160,6 @@ function parsePrice(value) {return { amount: null, currency: null };}-/**- * @param {string|null|undefined} url- * @returns {string|null}- */-function extractHostname(url) {- if (!url || typeof url !== 'string') return null;- try {- return new URL(url).hostname.replace(/^www\./i, '').toLowerCase();- } catch {- return null;- }-}-/*** @param {unknown} value* @returns {number|null}@@ -224,7 +211,7 @@ export function parsePerplexityCard(card, position) {price_currency: price.currency,image_url: toStringOrNull(card.image_url ?? card.image),merchant_url: merchantUrl,- merchant_domain: extractHostname(merchantUrl),+ merchant_domain: extractDomain(merchantUrl),rating: toNumber(card.rating),review_count: toInteger(card.review_count ?? card.reviews),raw: card,@@ -250,7 +237,7 @@ export function parseAiModeCard(card, position) {price_currency: price.currency,image_url: toStringOrNull(card.imageUrl ?? card.image),merchant_url: merchantUrl,- merchant_domain: extractHostname(merchantUrl),+ merchant_domain: extractDomain(merchantUrl),rating: toNumber(card.rating),review_count: toInteger(card.reviewCount ?? card.reviews),raw: card,@@ -296,7 +283,7 @@ export function parseCopilotCard(card, position) {price_currency: price.currency,image_url: imageUrl,merchant_url: merchantUrl,- merchant_domain: extractHostname(merchantUrl),+ merchant_domain: extractDomain(merchantUrl),rating: ratingObj ? toNumber(ratingObj.value) : toNumber(card.rating),review_count: ratingObj? toInteger(ratingObj.count)@@ -346,7 +333,7 @@ export function parseChatgptCard(card, position) {? toStringOrNull(card.image_urls[0]): toStringOrNull(card.image_url ?? card.image),merchant_url: merchantUrl,- merchant_domain: extractHostname(merchantUrl),+ merchant_domain: extractDomain(merchantUrl),rating: toNumber(card.rating),review_count: toInteger(card.num_reviews ?? card.review_count),raw: {diff --git a/server/src/lib/shopping-cards.test.js b/server/src/lib/shopping-cards.test.jsindex 2be1c702c..4393d163a 100644--- a/server/src/lib/shopping-cards.test.js+++ b/server/src/lib/shopping-cards.test.js@@ -1,4 +1,10 @@-import { describe, it, expect } from 'vitest';+import { describe, it, expect, vi } from 'vitest';++// shopping-cards now imports extractDomain from citation-rows, which reaches+// the supabase admin client at import time; its config calls process.exit(1)+// when env vars are absent. Stub it so the module loads under test.+vi.mock('../config/supabase.js', () => ({ default: {} }));+import {parsePerplexityCard,parseAiModeCard,@@ -124,6 +130,14 @@ describe('shopping-cards – parsePerplexityCard', () => {expect(result.product_brand).toBe('Acme Inc');});+ it('recovers merchant_domain from a scheme-less merchant URL (#874)', () => {+ // `new URL('shop.example.com/p/1')` throws, so the old local helper stored+ // null and the card dropped out of merchant grouping. The shared+ // extractDomain recovers the host via its regex fallback.+ const card = { title: 'Widget', url: 'shop.example.com/p/1' };+ expect(parsePerplexityCard(card, 0).merchant_domain).toBe('shop.example.com');+ });+it('should round prices with float-precision garbage to exactly two decimals', () => {const card1 = { price: 2999.989990234375 };const card2 = { price: { amount: 2999.989990234375 } };