@factorypure/client-helpers 1.0.2 → 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 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[];
@@ -35,3 +37,7 @@ export declare const filterScrapeResults: ({ scrapeResults, variant, filters, fi
35
37
  filters: ScrapeFiltersType;
36
38
  filterOptions?: FilterOptionsType;
37
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
@@ -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);
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,12 @@ const filterFoundProductIdExclusions = (results, found_id_exclusions) => {
199
203
  });
200
204
  return filtered;
201
205
  };
206
+ const filterIgnoredResults = (results) => {
207
+ const filtered = results.filter((item) => {
208
+ return item.ignore_result ? false : true;
209
+ });
210
+ return filtered;
211
+ };
202
212
  const filterPriceOutliers = (results, variantPrice, showHighPriceOutliers, showLowPriceOutliers) => {
203
213
  const filtered = results.filter((item) => {
204
214
  const showMoreExpensive = showHighPriceOutliers === true;
@@ -254,3 +264,39 @@ const filterDuplicateResults = (results) => {
254
264
  const filtered = Object.values(filteredUniqueResultsMap);
255
265
  return filtered;
256
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorypure/client-helpers",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",