@factorypure/client-helpers 1.1.25 → 1.1.26

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
@@ -1,3 +1,4 @@
1
+ import { MatchResult } from '@factorypure/matching-engine';
1
2
  import { z } from 'zod';
2
3
  /**
3
4
  * @packageDocumentation
@@ -878,4 +879,21 @@ export declare const calculateHideOverrideReasons: (result: ScrapeResultsType |
878
879
  found_product_ids?: string[];
879
880
  }, sku_alternates: string[]) => string[];
880
881
  export declare function findUnitVariations(data: any): any;
882
+ /**
883
+ * Derives the high-confidence matched results (shownResults) from a MatchResult.
884
+ * Includes candidates at or above minConfidence whose visibility state is not HIDDEN,
885
+ * plus HIDDEN candidates whose filter rules are all confidence-overridable and whose
886
+ * confidence is at or above overrideThreshold.
887
+ * Results are sorted by price ascending by default; pass sortDirection to override.
888
+ */
889
+ export declare function getShownResults(matchResult: MatchResult, sortedResults: (ScrapeResultsType | ImmersiveScrapeResultsType)[], minConfidence: number, sortDirection?: 'asc' | 'desc', overrideThreshold?: number): (ScrapeResultsType | ImmersiveScrapeResultsType)[];
890
+ /**
891
+ * Derives the needs-review results from a MatchResult.
892
+ * Includes medium-confidence candidates (reviewConfidenceMin <= confidence < minConfidence)
893
+ * that are cheaper than both the variant price and the cheapest shown result.
894
+ * Also includes high-confidence candidates whose visibility_state is not VISIBLE but meet
895
+ * the same price conditions.
896
+ * Results are sorted by price ascending.
897
+ */
898
+ export declare function getNeedsReviewResults(matchResult: MatchResult, sortedResults: (ScrapeResultsType | ImmersiveScrapeResultsType)[], shownResults: (ScrapeResultsType | ImmersiveScrapeResultsType)[], variantPrice: number, minConfidence: number, reviewConfidenceMin: number): (ScrapeResultsType | ImmersiveScrapeResultsType)[];
881
899
  export {};
package/dist/index.js CHANGED
@@ -2222,3 +2222,72 @@ export function findUnitVariations(data) {
2222
2222
  });
2223
2223
  return results;
2224
2224
  }
2225
+ /**
2226
+ * Derives the high-confidence matched results (shownResults) from a MatchResult.
2227
+ * Includes candidates at or above minConfidence whose visibility state is not HIDDEN,
2228
+ * plus HIDDEN candidates whose filter rules are all confidence-overridable and whose
2229
+ * confidence is at or above overrideThreshold.
2230
+ * Results are sorted by price ascending by default; pass sortDirection to override.
2231
+ */
2232
+ export function getShownResults(matchResult, sortedResults, minConfidence, sortDirection = 'asc', overrideThreshold = 80) {
2233
+ const shownResults = [];
2234
+ matchResult.candidates.forEach((candidate) => {
2235
+ const foundResult = sortedResults.find((res) => res.id.toString() === candidate.candidateId.toString());
2236
+ if (candidate.confidence >= minConfidence) {
2237
+ if (!foundResult)
2238
+ return;
2239
+ foundResult.candidate_result = candidate;
2240
+ const decision = evaluateConfidenceOverride(foundResult.filter_results ?? [], foundResult.visibility_state ?? VisibilityState.VISIBLE, candidate.confidence, overrideThreshold);
2241
+ if (decision === 'hide')
2242
+ return;
2243
+ if (decision === 'show_with_override') {
2244
+ foundResult.confidence_override_active = true;
2245
+ }
2246
+ shownResults.push(foundResult);
2247
+ }
2248
+ else if (foundResult &&
2249
+ foundResult.filter_results?.map((fr) => fr.ruleId).includes('match_confirmation_override')) {
2250
+ shownResults.push(foundResult);
2251
+ }
2252
+ });
2253
+ shownResults.sort((a, b) => {
2254
+ const aPrice = a.extracted_total || a.extracted_price || 0;
2255
+ const bPrice = b.extracted_total || b.extracted_price || 0;
2256
+ return sortDirection === 'asc' ? aPrice - bPrice : bPrice - aPrice;
2257
+ });
2258
+ return shownResults;
2259
+ }
2260
+ /**
2261
+ * Derives the needs-review results from a MatchResult.
2262
+ * Includes medium-confidence candidates (reviewConfidenceMin <= confidence < minConfidence)
2263
+ * that are cheaper than both the variant price and the cheapest shown result.
2264
+ * Also includes high-confidence candidates whose visibility_state is not VISIBLE but meet
2265
+ * the same price conditions.
2266
+ * Results are sorted by price ascending.
2267
+ */
2268
+ export function getNeedsReviewResults(matchResult, sortedResults, shownResults, variantPrice, minConfidence, reviewConfidenceMin) {
2269
+ const firstValidResult = shownResults[0];
2270
+ const cheapestShownPrice = firstValidResult?.extracted_total ?? firstValidResult?.extracted_price ?? Infinity;
2271
+ const needsReviewResults = [];
2272
+ matchResult.candidates.forEach((candidate) => {
2273
+ if (candidate.confidence >= reviewConfidenceMin && candidate.confidence < minConfidence) {
2274
+ const foundResult = sortedResults.find((res) => res.id.toString() === candidate.candidateId.toString());
2275
+ if (!foundResult)
2276
+ return;
2277
+ const hasAbsoluteBlock = (foundResult.filter_results ?? []).some((fr) => ABSOLUTE_BLOCK_RULE_IDS.includes(fr.ruleId));
2278
+ if (hasAbsoluteBlock)
2279
+ return;
2280
+ const priceTotal = foundResult.extracted_total || foundResult.extracted_price || 0;
2281
+ if (priceTotal < variantPrice && priceTotal < cheapestShownPrice) {
2282
+ foundResult.candidate_result = candidate;
2283
+ needsReviewResults.push(foundResult);
2284
+ }
2285
+ }
2286
+ });
2287
+ needsReviewResults.sort((a, b) => {
2288
+ const aPrice = a.extracted_total || a.extracted_price || 0;
2289
+ const bPrice = b.extracted_total || b.extracted_price || 0;
2290
+ return aPrice - bPrice;
2291
+ });
2292
+ return needsReviewResults;
2293
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@factorypure/client-helpers",
3
- "version": "1.1.25",
3
+ "version": "1.1.26",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -20,6 +20,7 @@
20
20
  "typescript": "^5.6.2"
21
21
  },
22
22
  "dependencies": {
23
+ "@factorypure/matching-engine": "^1.0.8",
23
24
  "@types/date-fns": "^2.5.3",
24
25
  "date-fns": "^4.1.0",
25
26
  "flexsearch": "^0.8.212",