fix: tighten scraper type contracts
This commit is contained in:
@@ -82,7 +82,10 @@ function parseEbayPrice(
|
||||
cleaned.includes("C $")
|
||||
) {
|
||||
currency = "CAD";
|
||||
} else if (cleaned.toUpperCase().includes("USD")) {
|
||||
} else if (
|
||||
cleaned.toUpperCase().includes("USD") ||
|
||||
cleaned.toUpperCase().includes("US $")
|
||||
) {
|
||||
currency = "USD";
|
||||
}
|
||||
|
||||
@@ -372,20 +375,6 @@ async function loadEbayCookies(): Promise<string | undefined> {
|
||||
|
||||
// ----------------------------- Main -----------------------------
|
||||
|
||||
export default async function fetchEbayItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
opts?: {
|
||||
minPrice?: number;
|
||||
maxPrice?: number;
|
||||
strictMode?: boolean;
|
||||
exclusions?: string[];
|
||||
keywords?: string[];
|
||||
buyItNowOnly?: boolean;
|
||||
canadaOnly?: boolean;
|
||||
},
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<EbayListingDetails[]>;
|
||||
export default async function fetchEbayItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND: number | undefined,
|
||||
@@ -400,6 +389,20 @@ export default async function fetchEbayItems(
|
||||
} | undefined,
|
||||
unstableMode: { hideUnstableResults: true },
|
||||
): Promise<UnstableListingBuckets<EbayListingDetails>>;
|
||||
export default async function fetchEbayItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
opts?: {
|
||||
minPrice?: number;
|
||||
maxPrice?: number;
|
||||
strictMode?: boolean;
|
||||
exclusions?: string[];
|
||||
keywords?: string[];
|
||||
buyItNowOnly?: boolean;
|
||||
canadaOnly?: boolean;
|
||||
},
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<EbayListingDetails[]>;
|
||||
export default async function fetchEbayItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND = 1,
|
||||
|
||||
@@ -918,7 +918,7 @@ export function parseFacebookAds(
|
||||
continue; // No price available
|
||||
}
|
||||
|
||||
if (!Number.isFinite(cents) || cents <= 0) continue;
|
||||
if (!Number.isFinite(cents) || cents < 0) continue;
|
||||
|
||||
// Extract address from location data if available
|
||||
const cityName =
|
||||
@@ -1077,13 +1077,6 @@ export function parseFacebookItem(
|
||||
|
||||
// ----------------------------- Main -----------------------------
|
||||
|
||||
export default async function fetchFacebookItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
LOCATION?: string,
|
||||
MAX_ITEMS?: number,
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<FacebookListingDetails[]>;
|
||||
export default async function fetchFacebookItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND: number | undefined,
|
||||
@@ -1091,6 +1084,13 @@ export default async function fetchFacebookItems(
|
||||
MAX_ITEMS: number | undefined,
|
||||
unstableMode: { hideUnstableResults: true },
|
||||
): Promise<UnstableListingBuckets<FacebookListingDetails>>;
|
||||
export default async function fetchFacebookItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
LOCATION?: string,
|
||||
MAX_ITEMS?: number,
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<FacebookListingDetails[]>;
|
||||
export default async function fetchFacebookItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND = 1,
|
||||
|
||||
@@ -520,8 +520,7 @@ export function parseSearch(
|
||||
|
||||
const results: SearchListing[] = [];
|
||||
for (const [key, value] of Object.entries(apolloState)) {
|
||||
// Heuristic: Kijiji listing keys usually contain "Listing"
|
||||
if (!key.includes("Listing")) continue;
|
||||
if (!key.startsWith("Listing:")) continue;
|
||||
if (!isRecord(value)) continue;
|
||||
|
||||
const item = value as ApolloSearchItem;
|
||||
@@ -762,14 +761,6 @@ export async function parseDetailedListing(
|
||||
|
||||
// ----------------------------- Main -----------------------------
|
||||
|
||||
export default async function fetchKijijiItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
BASE_URL?: string,
|
||||
searchOptions?: SearchOptions,
|
||||
listingOptions?: ListingFetchOptions,
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<DetailedListing[]>;
|
||||
export default async function fetchKijijiItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND: number | undefined,
|
||||
@@ -778,6 +769,14 @@ export default async function fetchKijijiItems(
|
||||
listingOptions: ListingFetchOptions | undefined,
|
||||
unstableMode: { hideUnstableResults: true },
|
||||
): Promise<UnstableListingBuckets<DetailedListing>>;
|
||||
export default async function fetchKijijiItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND?: number,
|
||||
BASE_URL?: string,
|
||||
searchOptions?: SearchOptions,
|
||||
listingOptions?: ListingFetchOptions,
|
||||
unstableMode?: UnstableListingModeOptions,
|
||||
): Promise<DetailedListing[]>;
|
||||
export default async function fetchKijijiItems(
|
||||
SEARCH_QUERY: string,
|
||||
REQUESTS_PER_SECOND = 1,
|
||||
@@ -811,15 +810,18 @@ export default async function fetchKijijiItems(
|
||||
: undefined;
|
||||
|
||||
// Set defaults for configuration
|
||||
const finalSearchOptions: Required<SearchOptions> = {
|
||||
const finalSearchOptions: Omit<Required<SearchOptions>, "priceMin" | "priceMax"> & {
|
||||
priceMin?: number;
|
||||
priceMax?: number;
|
||||
} = {
|
||||
location: searchOptions.location ?? 1700272, // Default to GTA
|
||||
category: searchOptions.category ?? 0, // Default to all categories
|
||||
keywords: searchOptions.keywords ?? SEARCH_QUERY,
|
||||
sortBy: searchOptions.sortBy ?? "relevancy",
|
||||
sortOrder: searchOptions.sortOrder ?? "desc",
|
||||
maxPages: searchOptions.maxPages ?? 5, // Default to 5 pages
|
||||
priceMin: searchOptions.priceMin as number,
|
||||
priceMax: searchOptions.priceMax as number,
|
||||
priceMin: searchOptions.priceMin,
|
||||
priceMax: searchOptions.priceMax,
|
||||
cookies: searchOptions.cookies ?? "",
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user