UNPKG

@accounter/server

Version:
50 lines (49 loc) 2.33 kB
/** * Auto-Match Provider * * Implements the core auto-match logic for processing all unmatched charges * and automatically merging charges with high-confidence matches (≥0.95). */ import type { Injector } from 'graphql-modules'; import type { ChargeWithData } from '../types.js'; import { type MatchResult } from './single-match.provider.js'; /** * Result of processing a single charge for auto-matching */ export interface ProcessChargeResult { /** Match result if a valid match was found, null otherwise */ match: MatchResult | null; /** Status of the processing */ status: 'matched' | 'skipped' | 'no-match'; /** Reason for the status (useful for debugging/logging) */ reason?: string; } /** * Process a single unmatched charge and find best match * * This function uses findMatches() from single-match provider with NO date window * restriction, then filters for high-confidence matches (≥0.95 threshold). * * @param sourceCharge - Unmatched charge to process (must have only transactions OR only documents) * @param allCandidates - All candidate charges to search (complementary type to source) * @param userId - Current user ID for business extraction * @returns Processing result with match status * * @throws Error if sourceCharge is already matched (has both transactions and documents) * @throws Error if sourceCharge has no transactions or documents * @throws Error if any validation fails (propagated from findMatches) */ export declare function processChargeForAutoMatch(sourceCharge: ChargeWithData, allCandidates: ChargeWithData[], userId: string, injector: Injector): Promise<ProcessChargeResult>; /** * Determine merge direction for two charges * * The merge direction follows these rules: * 1. If one charge is matched (has both transactions and documents), keep the matched one * 2. If both are unmatched, keep the one with transactions (transaction charge is the "anchor") * 3. If neither has transactions, keep the first one (arbitrary but consistent) * * @param charge1 - First charge * @param charge2 - Second charge * @returns [source, target] tuple where source will be merged INTO target (source is deleted) */ export declare function determineMergeDirection(charge1: ChargeWithData, charge2: ChargeWithData): [ChargeWithData, ChargeWithData];