@factorypure/client-helpers 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.js +39 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -37,3 +37,7 @@ export declare const filterScrapeResults: ({ scrapeResults, variant, filters, fi
|
|
|
37
37
|
filters: ScrapeFiltersType;
|
|
38
38
|
filterOptions?: FilterOptionsType;
|
|
39
39
|
}) => z.infer<any>[];
|
|
40
|
+
export declare const calculateIgnoreStatus: (result: ScrapeResultsType, variant: {
|
|
41
|
+
id: number;
|
|
42
|
+
sku?: string;
|
|
43
|
+
}, result_ignore_keys: string[] | null) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -61,7 +61,7 @@ export const filterScrapeResults = ({ scrapeResults, variant, filters, filterOpt
|
|
|
61
61
|
filteredResults = filterFoundProductIdExclusions(filteredResults, filters.found_id_exclusions);
|
|
62
62
|
}
|
|
63
63
|
if (filterOptions.exclude_ignored_keys_enabled) {
|
|
64
|
-
filteredResults = filterIgnoredResults(filteredResults
|
|
64
|
+
filteredResults = filterIgnoredResults(filteredResults);
|
|
65
65
|
}
|
|
66
66
|
if (filterOptions.price_filter_enabled) {
|
|
67
67
|
filteredResults = filterPriceOutliers(filteredResults, variant.price, filters.showHighPriceOutliers, filters.showLowPriceOutliers);
|
|
@@ -203,15 +203,9 @@ const filterFoundProductIdExclusions = (results, found_id_exclusions) => {
|
|
|
203
203
|
});
|
|
204
204
|
return filtered;
|
|
205
205
|
};
|
|
206
|
-
const filterIgnoredResults = (results
|
|
206
|
+
const filterIgnoredResults = (results) => {
|
|
207
207
|
const filtered = results.filter((item) => {
|
|
208
|
-
|
|
209
|
-
const resultKey = `${variantId}-${item.title}-${item.extracted_price}-${item.source}`;
|
|
210
|
-
if (result_ignore_keys.includes(resultKey)) {
|
|
211
|
-
return false;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return true;
|
|
208
|
+
return item.ignore_result ? false : true;
|
|
215
209
|
});
|
|
216
210
|
return filtered;
|
|
217
211
|
};
|
|
@@ -270,3 +264,39 @@ const filterDuplicateResults = (results) => {
|
|
|
270
264
|
const filtered = Object.values(filteredUniqueResultsMap);
|
|
271
265
|
return filtered;
|
|
272
266
|
};
|
|
267
|
+
export const calculateIgnoreStatus = (result, variant, result_ignore_keys) => {
|
|
268
|
+
let ignore = false;
|
|
269
|
+
const resultKey = `${variant.id}-${result.title}-${result.extracted_price}-${result.source}`;
|
|
270
|
+
if (result_ignore_keys && result_ignore_keys.includes(resultKey)) {
|
|
271
|
+
ignore = true;
|
|
272
|
+
}
|
|
273
|
+
if (result.details_and_offers &&
|
|
274
|
+
result.details_and_offers.includes("Out of stock online")) {
|
|
275
|
+
ignore = true;
|
|
276
|
+
}
|
|
277
|
+
const refurbishedKeywords = [
|
|
278
|
+
"refurbished",
|
|
279
|
+
"renewed",
|
|
280
|
+
"reconditioned",
|
|
281
|
+
"refurb",
|
|
282
|
+
"remanufactured",
|
|
283
|
+
"scratch",
|
|
284
|
+
"dent",
|
|
285
|
+
"used",
|
|
286
|
+
`${variant.sku}-R`,
|
|
287
|
+
`${variant.sku}-R`.toLowerCase(),
|
|
288
|
+
`${variant.sku}-R`.toUpperCase(),
|
|
289
|
+
`${variant.sku?.toLowerCase()}-R`,
|
|
290
|
+
`${variant.sku?.toUpperCase()}-R`,
|
|
291
|
+
];
|
|
292
|
+
const normalizedTitle = result.title
|
|
293
|
+
.toLowerCase()
|
|
294
|
+
.replace(/[^a-z0-9-]/g, " ");
|
|
295
|
+
const isRefurbished = refurbishedKeywords.some((keyword) => normalizedTitle.split(/\s+/).includes(keyword)) ||
|
|
296
|
+
(result.details_and_offers &&
|
|
297
|
+
result.details_and_offers.includes("Pre-owned"));
|
|
298
|
+
if (isRefurbished) {
|
|
299
|
+
ignore = true;
|
|
300
|
+
}
|
|
301
|
+
return ignore;
|
|
302
|
+
};
|