From 1dd657b38650b1d4f7a293c42107af541790f166 Mon Sep 17 00:00:00 2001 From: Victor Noguera Date: Tue, 7 Apr 2026 23:33:11 -0400 Subject: [PATCH] feat: enhance printResults function to filter and display FBA/FBM leads with detailed profit calculations --- src/writer.ts | 58 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/src/writer.ts b/src/writer.ts index a7b5063..977b823 100644 --- a/src/writer.ts +++ b/src/writer.ts @@ -51,18 +51,56 @@ function buildRow(r: AnalysisResult) { } export function printResults(results: AnalysisResult[]): void { - const rows = results.map((r) => { - const row = buildRow(r); - return { - ...row, - Name: row.Name.slice(0, 40), - Category: String(row.Category).slice(0, 20), - Reasoning: row.Reasoning.slice(0, 60), - }; - }); + const rows = results + .filter((r) => r.verdict.verdict === "FBA" || r.verdict.verdict === "FBM") + .map((r) => { + const sellingPrice = + r.product.keepa?.currentPrice ?? + r.product.record.sellingPriceFromSheet ?? + r.product.spApi.estimatedSalePrice; + const referralFee = + sellingPrice != null + ? sellingPrice * (r.product.spApi.referralFeePercent / 100) + : null; + const fulfillmentFee = + r.verdict.verdict === "FBA" + ? r.product.spApi.fbaFee + : r.product.spApi.fbmFee; + const netProfit = + sellingPrice != null + ? Math.round( + (sellingPrice - + r.product.record.unitCost - + fulfillmentFee - + (referralFee ?? 0)) * + 100, + ) / 100 + : ""; + + return { + ASIN: r.product.record.asin, + Name: r.product.record.name.slice(0, 40), + Category: String( + r.product.record.category ?? + r.product.keepa?.categoryTree?.join(" > ") ?? + "", + ).slice(0, 20), + "Unit Cost": r.product.record.unitCost, + "Selling Price": sellingPrice ?? "", + "Net Profit": netProfit, + "Monthly Sold": r.product.keepa?.monthlySold ?? "", + "Sold 90 Day": r.product.keepa?.salesRankDrops90 ?? "", + Confidence: r.verdict.confidence, + Reasoning: r.verdict.reasoning.slice(0, 60), + }; + }); console.log("\n=== Analysis Results ===\n"); - console.table(rows); + if (rows.length === 0) { + console.log("No FBA/FBM leads found."); + } else { + console.table(rows); + } const summary = { FBA: results.filter((r) => r.verdict.verdict === "FBA").length,