@factorypure/client-helpers 1.0.15 → 1.0.16

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 CHANGED
@@ -46,7 +46,7 @@ export declare const HIDE_REASONS: {
46
46
  };
47
47
  export declare const TOO_CHEAP_MULTIPLIER = 0.75;
48
48
  export declare const TOO_EXPENSIVE_MULTIPLIER = 1.25;
49
- export declare const filterScrapeResults: ({ scrapeResults, variant, filters, filterOptions, }: {
49
+ export declare const filterScrapeResults: ({ scrapeResults, variant, filters, filterOptions, globalScrapeOptions, }: {
50
50
  scrapeResults: ScrapeResultsType[];
51
51
  variant: {
52
52
  id: number;
@@ -57,6 +57,7 @@ export declare const filterScrapeResults: ({ scrapeResults, variant, filters, fi
57
57
  };
58
58
  filters: ScrapeFiltersType;
59
59
  filterOptions?: FilterOptionsType;
60
+ globalScrapeOptions?: any;
60
61
  }) => z.infer<any>[];
61
62
  export declare const calculateIgnoreStatus: (result: ScrapeResultsType, variant: {
62
63
  id: number;
package/dist/index.js CHANGED
@@ -68,7 +68,7 @@ export const filterScrapeResults = ({ scrapeResults, variant, filters, filterOpt
68
68
  wattage_exclusions_enabled: true,
69
69
  search_exclusions_enabled: true,
70
70
  exclude_ignored_keys_enabled: false,
71
- }, }) => {
71
+ }, globalScrapeOptions, }) => {
72
72
  let filteredResults = scrapeResults;
73
73
  // if (filterOptions.exclude_linked_variants_enabled) {
74
74
  // filteredResults = filterLinkedElsewhereResults(filteredResults, variant.id)
@@ -80,7 +80,7 @@ export const filterScrapeResults = ({ scrapeResults, variant, filters, filterOpt
80
80
  // filteredResults = filterIgnoredResults(filteredResults)
81
81
  // }
82
82
  // if (filterOptions.price_filter_enabled) {
83
- filteredResults = filterPriceOutliers(filteredResults, variant.price, filters.showHighPriceOutliers, filters.showLowPriceOutliers);
83
+ filteredResults = filterPriceOutliers(filteredResults, variant.price, globalScrapeOptions);
84
84
  // }
85
85
  // if (filterOptions.date_filter_enabled) {
86
86
  filteredResults = filterDateWindow(filteredResults, filters.dayWindow);
@@ -490,13 +490,14 @@ const filterIgnoredResults = (results) => {
490
490
  // })
491
491
  return results;
492
492
  };
493
- const filterPriceOutliers = (results, variantPrice, showHighPriceOutliers, showLowPriceOutliers) => {
493
+ const filterPriceOutliers = (results, variantPrice, globalScrapeOptions) => {
494
494
  results.forEach((item) => {
495
495
  if (!item.hide_reasons) {
496
496
  item.hide_reasons = [];
497
497
  }
498
+ const too_cheap_multiplier = getUndercutThreshold(variantPrice, globalScrapeOptions.undercut_threshold_ranges || []);
498
499
  const isMoreExpensive = item.extracted_price > variantPrice * TOO_EXPENSIVE_MULTIPLIER;
499
- const isTooCheap = item.extracted_price < variantPrice * TOO_CHEAP_MULTIPLIER;
500
+ const isTooCheap = item.extracted_price < variantPrice * too_cheap_multiplier;
500
501
  if (isMoreExpensive) {
501
502
  item.hide_reasons.push(HIDE_REASONS.HIGH_PRICE_OUTLIER);
502
503
  }
@@ -625,3 +626,7 @@ export const calculateIgnoreStatus = (result, variant, result_ignore_keys) => {
625
626
  }
626
627
  return ignore;
627
628
  };
629
+ function getUndercutThreshold(price, undercutThresholdRanges) {
630
+ const range = undercutThresholdRanges.find((r) => price >= r.min && price <= r.max);
631
+ return range ? range.threshold : 0.75; // fallback default
632
+ }
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
1
  {
2
- "name": "@factorypure/client-helpers",
3
- "version": "1.0.15",
4
- "description": "",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "files": [
8
- "dist"
9
- ],
10
- "type": "module",
11
- "scripts": {
12
- "build": "tsc",
13
- "test": "echo \"Error: no test specified\" && exit 1"
14
- },
15
- "keywords": [],
16
- "author": "",
17
- "license": "ISC",
18
- "devDependencies": {
19
- "typescript": "^5.6.2"
20
- },
21
- "dependencies": {
22
- "@types/date-fns": "^2.5.3",
23
- "date-fns": "^4.1.0",
24
- "flexsearch": "^0.8.212",
25
- "zod": "^4.3.5"
26
- }
2
+ "name": "@factorypure/client-helpers",
3
+ "version": "1.0.16",
4
+ "description": "",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "type": "module",
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "echo \"Error: no test specified\" && exit 1"
14
+ },
15
+ "keywords": [],
16
+ "author": "",
17
+ "license": "ISC",
18
+ "devDependencies": {
19
+ "typescript": "^5.6.2"
20
+ },
21
+ "dependencies": {
22
+ "@types/date-fns": "^2.5.3",
23
+ "date-fns": "^4.1.0",
24
+ "flexsearch": "^0.8.212",
25
+ "zod": "^4.3.5"
26
+ }
27
27
  }