feat: Integrate Amazon SP-API for product sellability and pricing
- Added `amazon-sp-api` dependency to package.json. - Enhanced configuration to include SP-API credentials and settings. - Implemented SP-API client initialization and error handling in sp-api.ts. - Developed functions to fetch product sellability and pricing data. - Updated main processing logic in index.ts to incorporate sellability checks before fetching pricing. - Modified LLM analysis to account for sellability status and reasons. - Created a new sp-test.ts script for testing SP-API connectivity and sellability. - Updated types.ts to define SellabilityInfo and extend SpApiData. - Enhanced result reporting in writer.ts to include sellability information.
This commit is contained in:
@@ -44,6 +44,14 @@ function buildRow(r: AnalysisResult) {
|
||||
"FBA Fee": r.product.spApi.fbaFee,
|
||||
"FBM Fee": r.product.spApi.fbmFee,
|
||||
"Referral %": r.product.spApi.referralFeePercent,
|
||||
"Can Sell":
|
||||
r.product.spApi.canSell == null
|
||||
? "unknown"
|
||||
: r.product.spApi.canSell
|
||||
? "yes"
|
||||
: "no",
|
||||
Sellability: r.product.spApi.sellabilityStatus,
|
||||
"Sellability Reason": r.product.spApi.sellabilityReason ?? "",
|
||||
Verdict: r.verdict.verdict,
|
||||
Confidence: r.verdict.confidence,
|
||||
Reasoning: r.verdict.reasoning,
|
||||
@@ -90,6 +98,16 @@ export function printResults(results: AnalysisResult[]): void {
|
||||
"Net Profit": netProfit,
|
||||
"Monthly Sold": r.product.keepa?.monthlySold ?? "",
|
||||
"Sold 90 Day": r.product.keepa?.salesRankDrops90 ?? "",
|
||||
"Can Sell":
|
||||
r.product.spApi.canSell == null
|
||||
? "unknown"
|
||||
: r.product.spApi.canSell
|
||||
? "yes"
|
||||
: "no",
|
||||
Sellability: r.product.spApi.sellabilityStatus,
|
||||
"Sellability Reason": String(
|
||||
r.product.spApi.sellabilityReason ?? "",
|
||||
).slice(0, 60),
|
||||
Confidence: r.verdict.confidence,
|
||||
Reasoning: r.verdict.reasoning.slice(0, 60),
|
||||
};
|
||||
@@ -106,10 +124,25 @@ export function printResults(results: AnalysisResult[]): void {
|
||||
FBA: results.filter((r) => r.verdict.verdict === "FBA").length,
|
||||
FBM: results.filter((r) => r.verdict.verdict === "FBM").length,
|
||||
SKIP: results.filter((r) => r.verdict.verdict === "SKIP").length,
|
||||
Available: results.filter(
|
||||
(r) => r.product.spApi.sellabilityStatus === "available",
|
||||
).length,
|
||||
Restricted: results.filter(
|
||||
(r) => r.product.spApi.sellabilityStatus === "restricted",
|
||||
).length,
|
||||
NotAvailable: results.filter(
|
||||
(r) => r.product.spApi.sellabilityStatus === "not_available",
|
||||
).length,
|
||||
Unknown: results.filter(
|
||||
(r) => r.product.spApi.sellabilityStatus === "unknown",
|
||||
).length,
|
||||
};
|
||||
console.log(
|
||||
`\nSummary: ${summary.FBA} FBA | ${summary.FBM} FBM | ${summary.SKIP} SKIP out of ${results.length} products\n`,
|
||||
);
|
||||
console.log(
|
||||
`Sellability: ${summary.Available} available | ${summary.Restricted} restricted | ${summary.NotAvailable} not_available | ${summary.Unknown} unknown\n`,
|
||||
);
|
||||
}
|
||||
|
||||
export function writeResultsCsv(
|
||||
|
||||
Reference in New Issue
Block a user