@factorypure/client-helpers 1.2.0 → 1.3.0
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 +58 -25
- package/dist/index.js +345 -136
- package/dist/repricing.d.ts +156 -0
- package/dist/repricing.js +411 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MatchResult } from '@factorypure/matching-engine';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
export * from './repricing.js';
|
|
3
4
|
/**
|
|
4
5
|
* @packageDocumentation
|
|
5
6
|
* @module @factorypure/client-helpers
|
|
@@ -257,6 +258,19 @@ export declare enum VisibilityState {
|
|
|
257
258
|
VISIBLE_WITH_WARNINGS = "VISIBLE_WITH_WARNINGS",
|
|
258
259
|
VISIBLE = "VISIBLE"
|
|
259
260
|
}
|
|
261
|
+
/**
|
|
262
|
+
* Result groups that replace VisibilityState with richer classification.
|
|
263
|
+
* Each result is assigned a group after all filter rules run:
|
|
264
|
+
* MATCH — no active blocks (shown; undercut determination is a separate downstream step)
|
|
265
|
+
* LOW_LIKELIHOOD — medium confidence only (50–79); shown in "needs review" if cheaper
|
|
266
|
+
* NO_MATCH — low confidence or has an active block rule (hidden)
|
|
267
|
+
*/
|
|
268
|
+
export declare enum ResultGroup {
|
|
269
|
+
MATCH = "match",
|
|
270
|
+
LOW_LIKELIHOOD = "low_likelihood",
|
|
271
|
+
NO_MATCH = "no_match",
|
|
272
|
+
EXCLUDED = "excluded"
|
|
273
|
+
}
|
|
260
274
|
/**
|
|
261
275
|
* Structured result from a filter rule evaluation
|
|
262
276
|
*/
|
|
@@ -310,7 +324,7 @@ export declare const scrapeResultsSchema: z.ZodObject<{
|
|
|
310
324
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
311
325
|
timestamp: z.ZodString;
|
|
312
326
|
}, z.core.$strip>>>;
|
|
313
|
-
visibility_state: z.ZodOptional<z.ZodEnum<typeof
|
|
327
|
+
visibility_state: z.ZodOptional<z.ZodEnum<typeof ResultGroup>>;
|
|
314
328
|
regexUnitResults: z.ZodNullable<z.ZodObject<{
|
|
315
329
|
inch: z.ZodArray<z.ZodObject<{
|
|
316
330
|
value: z.ZodString;
|
|
@@ -445,7 +459,7 @@ export declare const immersiveScrapeResultsSchema: z.ZodObject<{
|
|
|
445
459
|
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
446
460
|
timestamp: z.ZodString;
|
|
447
461
|
}, z.core.$strip>>>;
|
|
448
|
-
visibility_state: z.ZodOptional<z.ZodEnum<typeof
|
|
462
|
+
visibility_state: z.ZodOptional<z.ZodEnum<typeof ResultGroup>>;
|
|
449
463
|
brand: z.ZodNullable<z.ZodString>;
|
|
450
464
|
company_id: z.ZodNullable<z.ZodNumber>;
|
|
451
465
|
regexUnitResults: z.ZodNullable<z.ZodObject<{
|
|
@@ -702,6 +716,8 @@ export declare const HIDE_REASONS: {
|
|
|
702
716
|
CALCULATED_BRAND_MISMATCH: string;
|
|
703
717
|
SCAM_SOURCE_EXCLUSION: string;
|
|
704
718
|
AI_COMPARISON_MISMATCH: string;
|
|
719
|
+
ABSOLUTE_LOW_PRICE_OUTLIER: string;
|
|
720
|
+
ABSOLUTE_HIGH_PRICE_OUTLIER: string;
|
|
705
721
|
};
|
|
706
722
|
export declare const HIDE_OVERRIDE_REASONS: {
|
|
707
723
|
SKU_MATCH: string;
|
|
@@ -719,23 +735,23 @@ export declare const TOO_EXPENSIVE_MULTIPLIER = 1.15;
|
|
|
719
735
|
* These represent explicit user intent or unambiguously bad data.
|
|
720
736
|
*/
|
|
721
737
|
export declare const ABSOLUTE_BLOCK_RULE_IDS: readonly string[];
|
|
738
|
+
/**
|
|
739
|
+
* Rule IDs that represent explicit admin/security decisions.
|
|
740
|
+
* These are the ONLY blocks respected when a confidence override or match confirmation is present.
|
|
741
|
+
* Operational blocks (out_of_stock, price outliers, etc.) are superseded by overrides.
|
|
742
|
+
*/
|
|
743
|
+
export declare const MANUAL_EXCLUSION_RULE_IDS: readonly string[];
|
|
722
744
|
/**
|
|
723
745
|
* Rule IDs that can be overridden when the matching-engine confidence is high enough.
|
|
724
746
|
* These represent heuristics that may be wrong when identifier/title matching is strong.
|
|
725
747
|
*/
|
|
726
748
|
export declare const CONFIDENCE_OVERRIDABLE_RULE_IDS: readonly string[];
|
|
727
749
|
/**
|
|
728
|
-
*
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
* - `'show_with_override'`— result failed soft filters but confidence is high enough to surface it anyway
|
|
734
|
-
*
|
|
735
|
-
* @param filterResults The filter_results array from the filter engine
|
|
736
|
-
* @param visibilityState The visibility_state computed by the filter engine
|
|
737
|
-
* @param confidence Matching-engine confidence score (0–100)
|
|
738
|
-
* @param overrideThreshold Minimum confidence to override a soft BLOCK rule (default 80)
|
|
750
|
+
* @deprecated Confidence overrides are now handled by the filter engine.
|
|
751
|
+
* Pass a `confidenceMap` to `filterScrapeResultsV2` — the engine injects a synthetic
|
|
752
|
+
* `high_confidence_override` rule result when confidence ≥ 80, which is listed in the
|
|
753
|
+
* `overridableBy` array of all soft block/warning rules. `visibility_state` on each result
|
|
754
|
+
* is then accurate and final before `getShownResults` is called.
|
|
739
755
|
*/
|
|
740
756
|
export declare function evaluateConfidenceOverride(filterResults: FilterResult[], visibilityState: VisibilityState, confidence: number, overrideThreshold?: number): 'show' | 'show_with_override' | 'hide';
|
|
741
757
|
/**
|
|
@@ -782,11 +798,18 @@ export declare class FilterEngine {
|
|
|
782
798
|
/**
|
|
783
799
|
* Evaluate rules for a batch of results
|
|
784
800
|
*/
|
|
785
|
-
evaluateBatch<T extends ScrapeResultsType | ImmersiveScrapeResultsType>(results: T[], variant: FilterContext<T>['variant'], variantScrapeOptions: VariantScrapeOptionsType, vendorScrapeOptions: VendorScrapeOptionsType, globalScrapeOptions: GlobalScrapeOptionsType, comparisonMap?: ComparisonMapType, matchConfirmationMap?: MatchConfirmationMapType): T[];
|
|
801
|
+
evaluateBatch<T extends ScrapeResultsType | ImmersiveScrapeResultsType>(results: T[], variant: FilterContext<T>['variant'], variantScrapeOptions: VariantScrapeOptionsType, vendorScrapeOptions: VendorScrapeOptionsType, globalScrapeOptions: GlobalScrapeOptionsType, comparisonMap?: ComparisonMapType, matchConfirmationMap?: MatchConfirmationMapType, matchResult?: MatchResult): T[];
|
|
786
802
|
/**
|
|
787
|
-
* Calculate
|
|
803
|
+
* Calculate which result group a scrape result belongs to.
|
|
804
|
+
* MATCH — no manual blocks, and either an override is present or no blocks at all
|
|
805
|
+
* LOW_LIKELIHOOD — no overrides, medium_confidence is the only block (worth reviewing if cheaper)
|
|
806
|
+
* NO_MATCH — manual/security block present, or no overrides and more than one active block
|
|
807
|
+
*
|
|
808
|
+
* Key rule: any override (high_confidence_override, match_confirmation_override, sku_match, etc.)
|
|
809
|
+
* supersedes ALL operational blocks (out_of_stock, price outliers, mismatch rules, etc.).
|
|
810
|
+
* Only explicit admin decisions in MANUAL_EXCLUSION_RULE_IDS can block an overridden result.
|
|
788
811
|
*/
|
|
789
|
-
|
|
812
|
+
calculateGroup(filterResults: FilterResult[], resultPrice: number, variantPrice: number): ResultGroup;
|
|
790
813
|
}
|
|
791
814
|
/**
|
|
792
815
|
* Create and populate a registry with all built-in rules
|
|
@@ -829,7 +852,7 @@ export declare function createCustomFilterRule(config: {
|
|
|
829
852
|
* Filter scrape results using the new rule-based engine
|
|
830
853
|
* This provides more flexibility and better extensibility than the legacy filterScrapeResults
|
|
831
854
|
*/
|
|
832
|
-
export declare const filterScrapeResultsV2: <T extends ScrapeResultsType | ImmersiveScrapeResultsType>({ scrapeResults, variant, variantScrapeOptions, vendorScrapeOptions, globalScrapeOptions, filterConfig, customRules, comparisonMap, matchConfirmationMap, }: {
|
|
855
|
+
export declare const filterScrapeResultsV2: <T extends ScrapeResultsType | ImmersiveScrapeResultsType>({ scrapeResults, variant, variantScrapeOptions, vendorScrapeOptions, globalScrapeOptions, filterConfig, customRules, comparisonMap, matchConfirmationMap, matchResult, }: {
|
|
833
856
|
scrapeResults: T[];
|
|
834
857
|
variant: {
|
|
835
858
|
id: number;
|
|
@@ -847,6 +870,7 @@ export declare const filterScrapeResultsV2: <T extends ScrapeResultsType | Immer
|
|
|
847
870
|
customRules?: FilterRule[];
|
|
848
871
|
comparisonMap?: ComparisonMapType;
|
|
849
872
|
matchConfirmationMap?: MatchConfirmationMapType;
|
|
873
|
+
matchResult?: MatchResult;
|
|
850
874
|
}) => T[];
|
|
851
875
|
export declare const filterScrapeResults: <T extends ScrapeResultsType | ImmersiveScrapeResultsType>({ scrapeResults, variant, variantScrapeOptions, vendorScrapeOptions, globalScrapeOptions, }: {
|
|
852
876
|
scrapeResults: T[];
|
|
@@ -889,14 +913,23 @@ export declare function findUnitVariations(data: any): any;
|
|
|
889
913
|
* confidence is at or above overrideThreshold.
|
|
890
914
|
* Results are sorted by price ascending by default; pass sortDirection to override.
|
|
891
915
|
*/
|
|
892
|
-
export declare function getShownResults(
|
|
916
|
+
export declare function getShownResults(sortedResults: (ScrapeResultsType | ImmersiveScrapeResultsType)[], sortDirection?: 'asc' | 'desc'): (ScrapeResultsType | ImmersiveScrapeResultsType)[];
|
|
917
|
+
/**
|
|
918
|
+
* Extracts undercut results from the MATCH group — competitors selling strictly cheaper
|
|
919
|
+
* than the variant price (price < variantPrice).
|
|
920
|
+
*
|
|
921
|
+
* This is the downstream step that divides getShownResults output into two categories:
|
|
922
|
+
* - Undercuts: price < variantPrice (competitors beating our price)
|
|
923
|
+
* - Other matches: price ≥ variantPrice (competitors at or above our price)
|
|
924
|
+
*
|
|
925
|
+
* @param shownResults Output of getShownResults (already filtered to MATCH group)
|
|
926
|
+
* @param variantPrice The variant's current selling price
|
|
927
|
+
*/
|
|
928
|
+
export declare function getUndercutResults(shownResults: (ScrapeResultsType | ImmersiveScrapeResultsType)[], variantPrice: number): (ScrapeResultsType | ImmersiveScrapeResultsType)[];
|
|
893
929
|
/**
|
|
894
|
-
* Derives the needs-review results from
|
|
895
|
-
*
|
|
896
|
-
*
|
|
897
|
-
* Also includes high-confidence candidates whose visibility_state is not VISIBLE but meet
|
|
898
|
-
* the same price conditions.
|
|
930
|
+
* Derives the needs-review results from sortedResults.
|
|
931
|
+
* Returns LOW_LIKELIHOOD results (medium confidence, no other active blocks) that are
|
|
932
|
+
* cheaper than both the variant price and the cheapest shown result.
|
|
899
933
|
* Results are sorted by price ascending.
|
|
900
934
|
*/
|
|
901
|
-
export declare function getNeedsReviewResults(
|
|
902
|
-
export {};
|
|
935
|
+
export declare function getNeedsReviewResults(sortedResults: (ScrapeResultsType | ImmersiveScrapeResultsType)[], shownResults: (ScrapeResultsType | ImmersiveScrapeResultsType)[], variantPrice: number): (ScrapeResultsType | ImmersiveScrapeResultsType)[];
|