@factorypure/client-helpers 1.1.1 → 1.1.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 CHANGED
@@ -314,9 +314,9 @@ export type ScrapeFiltersType = {
314
314
  found_id_exclusions: string[] | null;
315
315
  competitor_exclusions: string[];
316
316
  match_values: string[];
317
- skip_skus: string[];
317
+ default_skip_skus: string[];
318
318
  skip_vendors: string[];
319
- vendor_search_exclusions: string[];
319
+ vendor_skip_skus: string[];
320
320
  search_exclusions: string[];
321
321
  result_ignore_keys: ResultIgnoreType[] | null;
322
322
  brand_name_alternates: string[];
@@ -329,6 +329,7 @@ export declare const variantScrapeOptionsSchema: z.ZodObject<{
329
329
  custom_search_value: z.ZodString;
330
330
  match_values: z.ZodArray<z.ZodString>;
331
331
  competitor_exclusions: z.ZodArray<z.ZodString>;
332
+ found_product_ids: z.ZodArray<z.ZodString>;
332
333
  result_ignore_keys: z.ZodNullable<z.ZodArray<z.ZodObject<{
333
334
  id: z.ZodNumber;
334
335
  variant_id: z.ZodNumber;
@@ -344,8 +345,9 @@ export declare const variantScrapeOptionsSchema: z.ZodObject<{
344
345
  }, z.core.$strip>;
345
346
  export type VariantScrapeOptionsType = z.infer<typeof variantScrapeOptionsSchema>;
346
347
  export declare const vendorScrapeOptionsSchema: z.ZodObject<{
347
- vendor_search_exclusions: z.ZodArray<z.ZodString>;
348
- skip_skus: z.ZodArray<z.ZodString>;
348
+ vendor_skip_skus: z.ZodArray<z.ZodString>;
349
+ default_skip_skus: z.ZodArray<z.ZodString>;
350
+ default_skip_vendors: z.ZodArray<z.ZodString>;
349
351
  sku_regex: z.ZodNullable<z.ZodString>;
350
352
  brand_name_alternates: z.ZodArray<z.ZodString>;
351
353
  }, z.core.$strip>;
@@ -384,7 +386,7 @@ export declare const HIDE_OVERRIDE_REASONS: {
384
386
  };
385
387
  export declare const TOO_CHEAP_MULTIPLIER = 0.75;
386
388
  export declare const TOO_EXPENSIVE_MULTIPLIER = 1.15;
387
- export declare const filterScrapeResults: <T extends ScrapeResultsType | ImmersiveScrapeResultsType>({ scrapeResults, variant, filters, globalScrapeOptions, }: {
389
+ export declare const filterScrapeResults: <T extends ScrapeResultsType | ImmersiveScrapeResultsType>({ scrapeResults, variant, variantScrapeOptions, vendorScrapeOptions, globalScrapeOptions, }: {
388
390
  scrapeResults: T[];
389
391
  variant: {
390
392
  id: number;
@@ -393,8 +395,9 @@ export declare const filterScrapeResults: <T extends ScrapeResultsType | Immersi
393
395
  price: number;
394
396
  vendor: string;
395
397
  };
396
- filters: ScrapeFiltersType;
397
- globalScrapeOptions?: any;
398
+ variantScrapeOptions: VariantScrapeOptionsType;
399
+ vendorScrapeOptions: VendorScrapeOptionsType;
400
+ globalScrapeOptions: GlobalScrapeOptionsType;
398
401
  }) => T[];
399
402
  export declare const getRefurbishedKeywords: (variant: {
400
403
  sku?: string;
package/dist/index.js CHANGED
@@ -143,12 +143,14 @@ export const variantScrapeOptionsSchema = z.object({
143
143
  custom_search_value: z.string(),
144
144
  match_values: z.array(z.string()),
145
145
  competitor_exclusions: z.array(z.string()),
146
+ found_product_ids: z.array(z.string()),
146
147
  result_ignore_keys: z.array(ResultIgnoreSchema).nullable(),
147
148
  day_window: z.string().nullable(),
148
149
  });
149
150
  export const vendorScrapeOptionsSchema = z.object({
150
- vendor_search_exclusions: z.array(z.string()),
151
- skip_skus: z.array(z.string()),
151
+ vendor_skip_skus: z.array(z.string()),
152
+ default_skip_skus: z.array(z.string()),
153
+ default_skip_vendors: z.array(z.string()),
152
154
  sku_regex: z.string().nullable(),
153
155
  brand_name_alternates: z.array(z.string()),
154
156
  });
@@ -202,22 +204,22 @@ const HIDE_ALWAYS_MAP = {
202
204
  export const TOO_CHEAP_MULTIPLIER = 0.75;
203
205
  export const TOO_EXPENSIVE_MULTIPLIER = 1.15;
204
206
  // const wattages = Array.from({ length: 41 }, (_, i) => (5000 + i * 500).toString())
205
- export const filterScrapeResults = ({ scrapeResults, variant, filters, globalScrapeOptions, }) => {
207
+ export const filterScrapeResults = ({ scrapeResults, variant, variantScrapeOptions, vendorScrapeOptions, globalScrapeOptions, }) => {
206
208
  let filteredResults = scrapeResults;
207
209
  filteredResults = filterPriceOutliers(filteredResults, variant.price, globalScrapeOptions);
208
- filteredResults = filterDateWindow(filteredResults, filters.dayWindow);
209
- filteredResults = filterCompetitors(filteredResults, filters.competitor_exclusions);
210
+ filteredResults = filterDateWindow(filteredResults, variantScrapeOptions.day_window);
211
+ filteredResults = filterCompetitors(filteredResults, variantScrapeOptions.competitor_exclusions);
210
212
  filteredResults = filterDuplicateResults(filteredResults);
211
- filteredResults = handleExclusionsSearch(filteredResults, filters, variant);
212
- filteredResults = handleSkipSkuSearch(filteredResults, filters, variant);
213
- filteredResults = handleVendorExclusions(filteredResults, filters, variant);
213
+ filteredResults = handleExclusionsSearch(filteredResults, variantScrapeOptions, variant);
214
+ filteredResults = handleSkipSkuSearch(filteredResults, vendorScrapeOptions, variant);
215
+ filteredResults = handleVendorExclusions(filteredResults, vendorScrapeOptions, variant);
214
216
  filteredResults = filterScamExclusions(filteredResults, globalScrapeOptions?.scam_sources || []);
215
217
  return filteredResults;
216
218
  };
217
- const handleVendorExclusions = (dataToSearch, filters, variant) => {
219
+ const handleVendorExclusions = (dataToSearch, options, variant) => {
218
220
  // Build exclusion list
219
221
  const nots = [];
220
- const formatted = filters.skip_vendors
222
+ const formatted = options.default_skip_vendors
221
223
  .filter((s) => s.toLowerCase() !== variant.vendor.toLowerCase())
222
224
  .map((s) => `${s}`);
223
225
  nots.push(...formatted);
@@ -228,7 +230,7 @@ const handleVendorExclusions = (dataToSearch, filters, variant) => {
228
230
  const hasExclusion = nots.some((sku) => {
229
231
  const escaped = sku.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
230
232
  const matchRegex = new RegExp(`(?: |\/|\&|\=|"|'|\`)${escaped}(?: |\/|\&|\=|"|'|\`)`, 'gi');
231
- const matches = item.title.match(matchRegex);
233
+ const matches = item?.title?.match(matchRegex);
232
234
  return matches && matches.length > 0;
233
235
  });
234
236
  if (!hasExclusion) {
@@ -247,12 +249,14 @@ const handleVendorExclusions = (dataToSearch, filters, variant) => {
247
249
  }
248
250
  return dataToSearch;
249
251
  };
250
- const handleSkipSkuSearch = (dataToSearch, filters, variant) => {
252
+ const handleSkipSkuSearch = (dataToSearch, options, variant) => {
251
253
  // Build exclusion list
252
254
  const nots = [];
253
- const formatted = filters.skip_skus.filter((s) => s.toLowerCase() !== variant.sku.toLowerCase()).map((s) => `${s}`);
255
+ const formatted = options.default_skip_skus
256
+ .filter((s) => s.toLowerCase() !== variant.sku.toLowerCase())
257
+ .map((s) => `${s}`);
254
258
  nots.push(...formatted);
255
- nots.push(...filters.vendor_search_exclusions.filter((s) => s.toLowerCase() !== variant.sku.toLowerCase()));
259
+ nots.push(...options.vendor_skip_skus.filter((s) => s.toLowerCase() !== variant.sku.toLowerCase()));
256
260
  // Find matching indices based on search criteria
257
261
  const matchingIndices = [];
258
262
  dataToSearch.forEach((item, index) => {
@@ -261,7 +265,7 @@ const handleSkipSkuSearch = (dataToSearch, filters, variant) => {
261
265
  const escapedSku = sku.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
262
266
  // this regex will pick up values from url eg. /product/sku12345/ without picking up partial matches and double counting eg. 15000 being counted twice in 15000 and xp15000
263
267
  const skuRegex = new RegExp(`(?: |\/|\&|\=|"|'|\`)${escapedSku}(?: |\/|\&|\=|"|'|\`)`, 'gi');
264
- const skuMatches = item.title.match(skuRegex);
268
+ const skuMatches = item?.title?.match(skuRegex);
265
269
  return skuMatches && skuMatches.length > 0;
266
270
  });
267
271
  if (!hasExclusion) {
@@ -280,8 +284,8 @@ const handleSkipSkuSearch = (dataToSearch, filters, variant) => {
280
284
  }
281
285
  return dataToSearch;
282
286
  };
283
- const handleExclusionsSearch = (dataToSearch, filters, variant) => {
284
- if (!filters.search_exclusions || filters.search_exclusions.length === 0) {
287
+ const handleExclusionsSearch = (dataToSearch, options, variant) => {
288
+ if (!options.search_exclusions || options.search_exclusions.length === 0) {
285
289
  return dataToSearch;
286
290
  }
287
291
  const { title, sku } = variant;
@@ -307,7 +311,7 @@ const handleExclusionsSearch = (dataToSearch, filters, variant) => {
307
311
  dataToSearch.forEach((item, id) => {
308
312
  index.add(id, item.title);
309
313
  });
310
- const searchTerms = filters.match_values;
314
+ const searchTerms = options.match_values;
311
315
  let final = null;
312
316
  searchTerms.forEach((term) => {
313
317
  if (final === null) {
@@ -332,7 +336,7 @@ const handleExclusionsSearch = (dataToSearch, filters, variant) => {
332
336
  suggest: true,
333
337
  });
334
338
  const nots = [];
335
- nots.push(...filters.search_exclusions);
339
+ nots.push(...options.search_exclusions);
336
340
  nots.forEach((term) => {
337
341
  final = final.not({
338
342
  index: index,
@@ -374,13 +378,13 @@ const filterPriceOutliers = (results, variantPrice, globalScrapeOptions) => {
374
378
  const filtered = results;
375
379
  return filtered;
376
380
  };
377
- const filterDateWindow = (results, dayWindow) => {
381
+ const filterDateWindow = (results, day_window) => {
378
382
  results.forEach((item) => {
379
383
  if (!item.hide_reasons) {
380
384
  item.hide_reasons = [];
381
385
  }
382
386
  const itemDate = new Date(item.created_at);
383
- const variantDate = startOfDay(subDays(new Date(), Number(dayWindow) || 3));
387
+ const variantDate = startOfDay(subDays(new Date(), Number(day_window) || 3));
384
388
  if (itemDate < variantDate) {
385
389
  item.hide_reasons.push(HIDE_REASONS.DATE_OUTLIER);
386
390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorypure/client-helpers",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",