@factorypure/client-helpers 1.1.21 → 1.1.23
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 +28 -0
- package/dist/index.js +60 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -389,6 +389,8 @@ export declare const scrapeResultsSchema: z.ZodObject<{
|
|
|
389
389
|
is_immersive: z.ZodOptional<z.ZodNull>;
|
|
390
390
|
brand: z.ZodOptional<z.ZodNull>;
|
|
391
391
|
company_id: z.ZodOptional<z.ZodNull>;
|
|
392
|
+
candidate_result: z.ZodOptional<z.ZodAny>;
|
|
393
|
+
confidence_override_active: z.ZodOptional<z.ZodBoolean>;
|
|
392
394
|
}, z.core.$strip>;
|
|
393
395
|
export declare const immersiveScrapeResultsSchema: z.ZodObject<{
|
|
394
396
|
id: z.ZodNumber;
|
|
@@ -516,6 +518,8 @@ export declare const immersiveScrapeResultsSchema: z.ZodObject<{
|
|
|
516
518
|
listing_hash: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
517
519
|
inline_link: z.ZodOptional<z.ZodNull>;
|
|
518
520
|
delivery: z.ZodOptional<z.ZodNull>;
|
|
521
|
+
candidate_result: z.ZodOptional<z.ZodAny>;
|
|
522
|
+
confidence_override_active: z.ZodOptional<z.ZodBoolean>;
|
|
519
523
|
}, z.core.$strip>;
|
|
520
524
|
export type ScrapeResultsType = z.infer<typeof scrapeResultsSchema>;
|
|
521
525
|
export type ImmersiveScrapeResultsType = z.infer<typeof immersiveScrapeResultsSchema>;
|
|
@@ -685,6 +689,30 @@ export declare const HIDE_OVERRIDE_REASONS: {
|
|
|
685
689
|
};
|
|
686
690
|
export declare const TOO_CHEAP_MULTIPLIER = 0.75;
|
|
687
691
|
export declare const TOO_EXPENSIVE_MULTIPLIER = 1.15;
|
|
692
|
+
/**
|
|
693
|
+
* Rule IDs that are absolute blocks — high matching-engine confidence cannot override them.
|
|
694
|
+
* These represent explicit user intent or unambiguously bad data.
|
|
695
|
+
*/
|
|
696
|
+
export declare const ABSOLUTE_BLOCK_RULE_IDS: readonly string[];
|
|
697
|
+
/**
|
|
698
|
+
* Rule IDs that can be overridden when the matching-engine confidence is high enough.
|
|
699
|
+
* These represent heuristics that may be wrong when identifier/title matching is strong.
|
|
700
|
+
*/
|
|
701
|
+
export declare const CONFIDENCE_OVERRIDABLE_RULE_IDS: readonly string[];
|
|
702
|
+
/**
|
|
703
|
+
* Evaluates whether a result should be surfaced given its filter state and matching confidence.
|
|
704
|
+
*
|
|
705
|
+
* Returns:
|
|
706
|
+
* - `'hide'` — result must not be shown
|
|
707
|
+
* - `'show'` — result passes all filters normally
|
|
708
|
+
* - `'show_with_override'`— result failed soft filters but confidence is high enough to surface it anyway
|
|
709
|
+
*
|
|
710
|
+
* @param filterResults The filter_results array from the filter engine
|
|
711
|
+
* @param visibilityState The visibility_state computed by the filter engine
|
|
712
|
+
* @param confidence Matching-engine confidence score (0–100)
|
|
713
|
+
* @param overrideThreshold Minimum confidence to override a soft BLOCK rule (default 80)
|
|
714
|
+
*/
|
|
715
|
+
export declare function evaluateConfidenceOverride(filterResults: FilterResult[], visibilityState: VisibilityState, confidence: number, overrideThreshold?: number): 'show' | 'show_with_override' | 'hide';
|
|
688
716
|
/**
|
|
689
717
|
* Registry for filter rules with configuration management
|
|
690
718
|
*/
|
package/dist/index.js
CHANGED
|
@@ -280,6 +280,9 @@ export const scrapeResultsSchema = z.object({
|
|
|
280
280
|
is_immersive: z.null().optional(),
|
|
281
281
|
brand: z.null().optional(),
|
|
282
282
|
company_id: z.null().optional(),
|
|
283
|
+
// Populated by matching engine helpers
|
|
284
|
+
candidate_result: z.any().optional(),
|
|
285
|
+
confidence_override_active: z.boolean().optional(),
|
|
283
286
|
});
|
|
284
287
|
export const immersiveScrapeResultsSchema = z.object({
|
|
285
288
|
id: z.number(),
|
|
@@ -342,6 +345,9 @@ export const immersiveScrapeResultsSchema = z.object({
|
|
|
342
345
|
listing_hash: z.string().nullable().optional(),
|
|
343
346
|
inline_link: z.null().optional(),
|
|
344
347
|
delivery: z.null().optional(),
|
|
348
|
+
// Populated by matching engine helpers
|
|
349
|
+
candidate_result: z.any().optional(),
|
|
350
|
+
confidence_override_active: z.boolean().optional(),
|
|
345
351
|
});
|
|
346
352
|
export const ResultIgnoreSchema = z.object({
|
|
347
353
|
id: z.number(),
|
|
@@ -444,6 +450,60 @@ const HIDE_ALWAYS_MAP = {
|
|
|
444
450
|
};
|
|
445
451
|
export const TOO_CHEAP_MULTIPLIER = 0.75;
|
|
446
452
|
export const TOO_EXPENSIVE_MULTIPLIER = 1.15;
|
|
453
|
+
/**
|
|
454
|
+
* Rule IDs that are absolute blocks — high matching-engine confidence cannot override them.
|
|
455
|
+
* These represent explicit user intent or unambiguously bad data.
|
|
456
|
+
*/
|
|
457
|
+
export const ABSOLUTE_BLOCK_RULE_IDS = [
|
|
458
|
+
'manually_ignored',
|
|
459
|
+
'scam_source_exclusion',
|
|
460
|
+
'duplicate',
|
|
461
|
+
'high_price_outlier',
|
|
462
|
+
'low_price_outlier',
|
|
463
|
+
'skip_sku',
|
|
464
|
+
];
|
|
465
|
+
/**
|
|
466
|
+
* Rule IDs that can be overridden when the matching-engine confidence is high enough.
|
|
467
|
+
* These represent heuristics that may be wrong when identifier/title matching is strong.
|
|
468
|
+
*/
|
|
469
|
+
export const CONFIDENCE_OVERRIDABLE_RULE_IDS = [
|
|
470
|
+
'ai_comparison_mismatch',
|
|
471
|
+
'ai_sku_mismatch',
|
|
472
|
+
'calculated_sku_mismatch',
|
|
473
|
+
'search_exclusion',
|
|
474
|
+
'brand_mismatch',
|
|
475
|
+
'vendor_exclusion',
|
|
476
|
+
'competitor_exclusion',
|
|
477
|
+
'date_outlier',
|
|
478
|
+
'critical_spec_mismatch',
|
|
479
|
+
];
|
|
480
|
+
/**
|
|
481
|
+
* Evaluates whether a result should be surfaced given its filter state and matching confidence.
|
|
482
|
+
*
|
|
483
|
+
* Returns:
|
|
484
|
+
* - `'hide'` — result must not be shown
|
|
485
|
+
* - `'show'` — result passes all filters normally
|
|
486
|
+
* - `'show_with_override'`— result failed soft filters but confidence is high enough to surface it anyway
|
|
487
|
+
*
|
|
488
|
+
* @param filterResults The filter_results array from the filter engine
|
|
489
|
+
* @param visibilityState The visibility_state computed by the filter engine
|
|
490
|
+
* @param confidence Matching-engine confidence score (0–100)
|
|
491
|
+
* @param overrideThreshold Minimum confidence to override a soft BLOCK rule (default 80)
|
|
492
|
+
*/
|
|
493
|
+
export function evaluateConfidenceOverride(filterResults, visibilityState, confidence, overrideThreshold = 80) {
|
|
494
|
+
// Absolute blocks can never be overridden regardless of confidence
|
|
495
|
+
const hasAbsoluteBlock = filterResults.some((fr) => ABSOLUTE_BLOCK_RULE_IDS.includes(fr.ruleId));
|
|
496
|
+
if (hasAbsoluteBlock)
|
|
497
|
+
return 'hide';
|
|
498
|
+
if (visibilityState !== VisibilityState.HIDDEN)
|
|
499
|
+
return 'show';
|
|
500
|
+
// Result is hidden — check if all BLOCK-severity rules are confidence-overridable
|
|
501
|
+
const blockRules = filterResults.filter((fr) => fr.severity === FilterSeverity.BLOCK);
|
|
502
|
+
const allBlocksOverridable = blockRules.length > 0 && blockRules.every((fr) => CONFIDENCE_OVERRIDABLE_RULE_IDS.includes(fr.ruleId));
|
|
503
|
+
if (allBlocksOverridable && confidence >= overrideThreshold)
|
|
504
|
+
return 'show_with_override';
|
|
505
|
+
return 'hide';
|
|
506
|
+
}
|
|
447
507
|
// const wattages = Array.from({ length: 41 }, (_, i) => (5000 + i * 500).toString())
|
|
448
508
|
// ===============================
|
|
449
509
|
// Filter Rule Registry
|