Skip to content

Commit 553e45b

Browse files
committed
feat(engine): integrate extraction pipeline into import flow and background sync
1 parent 34f6376 commit 553e45b

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

‎src/lib/jobs/product-sync.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
*/
55

66
import { fetchProductPage } from '@/lib/products/fetch';
7-
import { extractMetadata } from '@/lib/products/metadata';
7+
import { runExtractionPipeline } from '@/lib/products/engine';
8+
import { extractDomain } from '@/lib/products/normalize';
89
import { prisma } from '@/lib/prisma';
910

1011
export interface SyncResult {
@@ -53,8 +54,9 @@ export async function syncProduct(productId: string): Promise<SyncResult> {
5354
return { success: false, error: message };
5455
}
5556

56-
// Extract metadata
57-
const metadata = extractMetadata(html);
57+
// Extract metadata via pipeline
58+
const domain = extractDomain(product.canonicalUrl);
59+
const metadata = await runExtractionPipeline({ html, url: product.canonicalUrl, domain });
5860
if (!metadata.title) {
5961
return { success: false, error: 'Could not extract product data.' };
6062
}

‎src/lib/products/index.ts‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import { prisma } from '@/lib/prisma';
99

1010
import { fetchProductPage } from './fetch';
11-
import { extractMetadata } from './metadata';
11+
import { runExtractionPipeline } from './engine';
1212
import { extractDomain, getRetailerName, normalizeUrl } from './normalize';
1313

14-
export type { ExtractedMetadata } from './metadata';
14+
export type { PipelineResult } from './engine';
1515
export type { PriceCandidate, PriceResult } from './price';
1616

1717
// ─────────────────────────────────────────────────────────────────────────────
@@ -143,11 +143,11 @@ export async function importProductFromUrl(rawUrl: string): Promise<ImportOutcom
143143
return { success: false, error: `Could not fetch page: ${message}` };
144144
}
145145

146-
// 4. Extract metadata (pass domain for retailer-specific price parsing)
147-
const metadata = extractMetadata(html, domain);
146+
// 4. Extract metadata via pipeline (parallel extractors + consensus)
147+
const pipelineResult = await runExtractionPipeline({ html, url: normalizedUrl, domain });
148148

149149
// Must have at least a title
150-
if (!metadata.title) {
150+
if (!pipelineResult.title) {
151151
return {
152152
success: false,
153153
error:
@@ -163,19 +163,19 @@ export async function importProductFromUrl(rawUrl: string): Promise<ImportOutcom
163163
canonicalUrl,
164164
normalizedUrl: canonicalUrl.toLowerCase(),
165165
domain,
166-
retailer: metadata.retailer ?? retailerFromDomain ?? domain,
167-
title: metadata.title,
168-
description: metadata.description,
169-
brand: metadata.brand,
170-
sku: metadata.sku,
171-
mpn: metadata.mpn,
172-
gtin: metadata.gtin,
173-
image: metadata.image,
174-
gallery: metadata.gallery,
175-
currentPrice: metadata.price,
176-
currency: metadata.currency ?? 'USD',
177-
inStock: metadata.inStock,
178-
availability: metadata.availability,
166+
retailer: pipelineResult.retailer ?? retailerFromDomain ?? domain,
167+
title: pipelineResult.title,
168+
description: pipelineResult.description,
169+
brand: pipelineResult.brand,
170+
sku: pipelineResult.sku,
171+
mpn: pipelineResult.mpn,
172+
gtin: pipelineResult.gtin,
173+
image: pipelineResult.image,
174+
gallery: pipelineResult.gallery,
175+
currentPrice: pipelineResult.price,
176+
currency: pipelineResult.currency ?? 'USD',
177+
inStock: pipelineResult.inStock,
178+
availability: pipelineResult.availability,
179179
};
180180

181181
return { success: true, data };

0 commit comments

Comments
 (0)