feat: ebay 'buy it now' and 'canada only' filters support

This commit is contained in:
2025-12-17 14:38:52 -05:00
parent 083b862552
commit 497c7995a2
4 changed files with 40 additions and 6 deletions

View File

@@ -1,8 +1,8 @@
import { fetchEbayItems } from "@marketplace-scrapers/core"; import { fetchEbayItems } from "@marketplace-scrapers/core";
/** /**
* GET /api/ebay?q={query}&minPrice={minPrice}&maxPrice={maxPrice}&strictMode={strictMode}&exclusions={exclusions}&keywords={keywords} * GET /api/ebay?q={query}&minPrice={minPrice}&maxPrice={maxPrice}&strictMode={strictMode}&exclusions={exclusions}&keywords={keywords}&buyItNowOnly={buyItNowOnly}&canadaOnly={canadaOnly}
* Search eBay for listings * Search eBay for listings (default: Buy It Now only, Canada only)
*/ */
export async function ebayRoute(req: Request): Promise<Response> { export async function ebayRoute(req: Request): Promise<Response> {
const reqUrl = new URL(req.url); const reqUrl = new URL(req.url);
@@ -26,6 +26,8 @@ export async function ebayRoute(req: Request): Promise<Response> {
? parseInt(reqUrl.searchParams.get("maxPrice")!) ? parseInt(reqUrl.searchParams.get("maxPrice")!)
: undefined; : undefined;
const strictMode = reqUrl.searchParams.get("strictMode") === "true"; const strictMode = reqUrl.searchParams.get("strictMode") === "true";
const buyItNowOnly = reqUrl.searchParams.get("buyItNowOnly") !== "false";
const canadaOnly = reqUrl.searchParams.get("canadaOnly") !== "false";
const exclusionsParam = reqUrl.searchParams.get("exclusions"); const exclusionsParam = reqUrl.searchParams.get("exclusions");
const exclusions = exclusionsParam ? exclusionsParam.split(",").map(s => s.trim()) : []; const exclusions = exclusionsParam ? exclusionsParam.split(",").map(s => s.trim()) : [];
const keywordsParam = reqUrl.searchParams.get("keywords"); const keywordsParam = reqUrl.searchParams.get("keywords");
@@ -38,6 +40,8 @@ export async function ebayRoute(req: Request): Promise<Response> {
strictMode, strictMode,
exclusions, exclusions,
keywords, keywords,
buyItNowOnly,
canadaOnly,
}); });
if (!items || items.length === 0) if (!items || items.length === 0)
return Response.json( return Response.json(

View File

@@ -270,6 +270,8 @@ export default async function fetchEbayItems(
strictMode?: boolean; strictMode?: boolean;
exclusions?: string[]; exclusions?: string[];
keywords?: string[]; keywords?: string[];
buyItNowOnly?: boolean;
canadaOnly?: boolean;
} = {}, } = {},
) { ) {
const { const {
@@ -277,11 +279,27 @@ export default async function fetchEbayItems(
maxPrice = Number.MAX_SAFE_INTEGER, maxPrice = Number.MAX_SAFE_INTEGER,
strictMode = false, strictMode = false,
exclusions = [], exclusions = [],
keywords = [SEARCH_QUERY] // Default to search query if no keywords provided keywords = [SEARCH_QUERY], // Default to search query if no keywords provided
buyItNowOnly = true,
canadaOnly = true,
} = opts; } = opts;
// Build eBay search URL - use Canadian site and tracking parameters like real browser // Build eBay search URL - use Canadian site, Buy It Now filter, and Canada-only preference
const searchUrl = `https://www.ebay.ca/sch/i.html?_nkw=${encodeURIComponent(SEARCH_QUERY)}^&_sacat=0^&_from=R40^&_trksid=p4432023.m570.l1313`; const urlParams = new URLSearchParams({
_nkw: SEARCH_QUERY,
_sacat: "0",
_from: "R40",
});
if (buyItNowOnly) {
urlParams.set("LH_BIN", "1");
}
if (canadaOnly) {
urlParams.set("LH_PrefLoc", "1");
}
const searchUrl = `https://www.ebay.ca/sch/i.html?${urlParams.toString()}`;
const DELAY_MS = Math.max(1, Math.floor(1000 / REQUESTS_PER_SECOND)); const DELAY_MS = Math.max(1, Math.floor(1000 / REQUESTS_PER_SECOND));

View File

@@ -131,6 +131,8 @@ export async function handleMcpRequest(req: Request): Promise<Response> {
strictMode: args.strictMode || false, strictMode: args.strictMode || false,
exclusions: args.exclusions || [], exclusions: args.exclusions || [],
keywords: args.keywords || [query], keywords: args.keywords || [query],
buyItNowOnly: args.buyItNowOnly !== false,
canadaOnly: args.canadaOnly !== false,
}); });
result = items || []; result = items || [];
} else { } else {

View File

@@ -52,7 +52,7 @@ export const tools = [
}, },
{ {
name: "search_ebay", name: "search_ebay",
description: "Search eBay for listings matching a query", description: "Search eBay for listings matching a query (default: Buy It Now only, Canada only)",
inputSchema: { inputSchema: {
type: "object", type: "object",
properties: { properties: {
@@ -83,6 +83,16 @@ export const tools = [
items: { type: "string" }, items: { type: "string" },
description: "Keywords to include in search", description: "Keywords to include in search",
}, },
buyItNowOnly: {
type: "boolean",
description: "Include only Buy It Now listings (exclude auctions)",
default: true,
},
canadaOnly: {
type: "boolean",
description: "Include only Canadian sellers/listings",
default: true,
},
maxItems: { maxItems: {
type: "number", type: "number",
description: "Maximum number of items to return", description: "Maximum number of items to return",