@factorypure/client-helpers 1.1.0 → 1.1.2

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,7 +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_id_exclusions: z.ZodNullable<z.ZodArray<z.ZodNumber>>;
332
+ found_product_ids: z.ZodArray<z.ZodString>;
333
333
  result_ignore_keys: z.ZodNullable<z.ZodArray<z.ZodObject<{
334
334
  id: z.ZodNumber;
335
335
  variant_id: z.ZodNumber;
@@ -341,23 +341,15 @@ export declare const variantScrapeOptionsSchema: z.ZodObject<{
341
341
  created_by: z.ZodNumber;
342
342
  key_parts: z.ZodString;
343
343
  }, z.core.$strip>>>;
344
+ day_window: z.ZodNullable<z.ZodString>;
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>;
349
- result_ignore_keys: z.ZodNullable<z.ZodArray<z.ZodObject<{
350
- id: z.ZodNumber;
351
- variant_id: z.ZodNumber;
352
- title: z.ZodString;
353
- price: z.ZodString;
354
- source: z.ZodString;
355
- reason: z.ZodString;
356
- duration_days: z.ZodNumber;
357
- created_by: z.ZodNumber;
358
- key_parts: z.ZodString;
359
- }, z.core.$strip>>>;
360
- brand_name_alternates: z.ZodNullable<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>;
351
+ sku_regex: z.ZodNullable<z.ZodString>;
352
+ brand_name_alternates: z.ZodArray<z.ZodString>;
361
353
  }, z.core.$strip>;
362
354
  export type VendorScrapeOptionsType = z.infer<typeof vendorScrapeOptionsSchema>;
363
355
  export declare const globalScrapeOptionsSchema: z.ZodObject<{
@@ -394,7 +386,7 @@ export declare const HIDE_OVERRIDE_REASONS: {
394
386
  };
395
387
  export declare const TOO_CHEAP_MULTIPLIER = 0.75;
396
388
  export declare const TOO_EXPENSIVE_MULTIPLIER = 1.15;
397
- 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, }: {
398
390
  scrapeResults: T[];
399
391
  variant: {
400
392
  id: number;
@@ -403,8 +395,9 @@ export declare const filterScrapeResults: <T extends ScrapeResultsType | Immersi
403
395
  price: number;
404
396
  vendor: string;
405
397
  };
406
- filters: ScrapeFiltersType;
407
- globalScrapeOptions?: any;
398
+ variantScrapeOptions: VariantScrapeOptionsType;
399
+ vendorScrapeOptions: VendorScrapeOptionsType;
400
+ globalScrapeOptions: GlobalScrapeOptionsType;
408
401
  }) => T[];
409
402
  export declare const getRefurbishedKeywords: (variant: {
410
403
  sku?: string;
package/dist/index.js CHANGED
@@ -143,14 +143,16 @@ 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_id_exclusions: z.array(z.number()).nullable(),
146
+ found_product_ids: z.array(z.string()),
147
147
  result_ignore_keys: z.array(ResultIgnoreSchema).nullable(),
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()),
152
- result_ignore_keys: z.array(ResultIgnoreSchema).nullable(),
153
- brand_name_alternates: z.array(z.string()).nullable(),
151
+ vendor_skip_skus: z.array(z.string()),
152
+ default_skip_skus: z.array(z.string()),
153
+ default_skip_vendors: z.array(z.string()),
154
+ sku_regex: z.string().nullable(),
155
+ brand_name_alternates: z.array(z.string()),
154
156
  });
155
157
  export const globalScrapeOptionsSchema = z.object({
156
158
  undercut_threshold_ranges: z.array(z.object({
@@ -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);
@@ -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) => {
@@ -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.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",