@factorypure/client-helpers 1.0.2 → 1.0.3
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 +3 -1
- package/dist/index.js +17 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
export declare const scrapeResultsSchema: any;
|
|
3
3
|
export type ScrapeResultsType = z.infer<typeof scrapeResultsSchema>;
|
|
4
4
|
export type ScrapeFiltersType = {
|
|
5
|
-
found_id_exclusions: number[];
|
|
5
|
+
found_id_exclusions: number[] | null;
|
|
6
6
|
showHighPriceOutliers: boolean;
|
|
7
7
|
showLowPriceOutliers: boolean;
|
|
8
8
|
dayWindow: number | null;
|
|
@@ -11,6 +11,7 @@ export type ScrapeFiltersType = {
|
|
|
11
11
|
skip_skus: string[];
|
|
12
12
|
vendor_search_exclusions: string[];
|
|
13
13
|
search_exclusions: string[];
|
|
14
|
+
result_ignore_keys: string[] | null;
|
|
14
15
|
};
|
|
15
16
|
export type FilterOptionsType = {
|
|
16
17
|
exclude_linked_variants_enabled?: boolean;
|
|
@@ -23,6 +24,7 @@ export type FilterOptionsType = {
|
|
|
23
24
|
skip_skus_enabled?: boolean;
|
|
24
25
|
wattage_exclusions_enabled?: boolean;
|
|
25
26
|
search_exclusions_enabled?: boolean;
|
|
27
|
+
exclude_ignored_keys_enabled?: boolean;
|
|
26
28
|
};
|
|
27
29
|
export declare const filterScrapeResults: ({ scrapeResults, variant, filters, filterOptions, }: {
|
|
28
30
|
scrapeResults: ScrapeResultsType[];
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,7 @@ export const filterScrapeResults = ({ scrapeResults, variant, filters, filterOpt
|
|
|
51
51
|
skip_skus_enabled: true,
|
|
52
52
|
wattage_exclusions_enabled: true,
|
|
53
53
|
search_exclusions_enabled: true,
|
|
54
|
+
exclude_ignored_keys_enabled: false,
|
|
54
55
|
}, }) => {
|
|
55
56
|
let filteredResults = scrapeResults;
|
|
56
57
|
if (filterOptions.exclude_linked_variants_enabled) {
|
|
@@ -59,6 +60,9 @@ export const filterScrapeResults = ({ scrapeResults, variant, filters, filterOpt
|
|
|
59
60
|
if (filterOptions.found_id_exclusions_enabled) {
|
|
60
61
|
filteredResults = filterFoundProductIdExclusions(filteredResults, filters.found_id_exclusions);
|
|
61
62
|
}
|
|
63
|
+
if (filterOptions.exclude_ignored_keys_enabled) {
|
|
64
|
+
filteredResults = filterIgnoredResults(filteredResults, variant.id, filters.result_ignore_keys);
|
|
65
|
+
}
|
|
62
66
|
if (filterOptions.price_filter_enabled) {
|
|
63
67
|
filteredResults = filterPriceOutliers(filteredResults, variant.price, filters.showHighPriceOutliers, filters.showLowPriceOutliers);
|
|
64
68
|
}
|
|
@@ -190,7 +194,7 @@ const filterLinkedElsewhereResults = (results, variantId) => {
|
|
|
190
194
|
};
|
|
191
195
|
const filterFoundProductIdExclusions = (results, found_id_exclusions) => {
|
|
192
196
|
const filtered = results.filter((item) => {
|
|
193
|
-
if (found_id_exclusions.length) {
|
|
197
|
+
if (found_id_exclusions && found_id_exclusions.length) {
|
|
194
198
|
if (found_id_exclusions.includes(item.found_product_id)) {
|
|
195
199
|
return false;
|
|
196
200
|
}
|
|
@@ -199,6 +203,18 @@ const filterFoundProductIdExclusions = (results, found_id_exclusions) => {
|
|
|
199
203
|
});
|
|
200
204
|
return filtered;
|
|
201
205
|
};
|
|
206
|
+
const filterIgnoredResults = (results, variantId, result_ignore_keys) => {
|
|
207
|
+
const filtered = results.filter((item) => {
|
|
208
|
+
if (result_ignore_keys && result_ignore_keys.length) {
|
|
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;
|
|
215
|
+
});
|
|
216
|
+
return filtered;
|
|
217
|
+
};
|
|
202
218
|
const filterPriceOutliers = (results, variantPrice, showHighPriceOutliers, showLowPriceOutliers) => {
|
|
203
219
|
const filtered = results.filter((item) => {
|
|
204
220
|
const showMoreExpensive = showHighPriceOutliers === true;
|