Kaizen
Browse modulesPricingpricing/sharedFunctions

Function: partitionPricingResult()

function partitionPricingResult<TContext extends EvaluatePricingContext>(
   matchResult: MatchResult<
  | {
  actions: (
     | {
     adjustmentKind: "fee" | "tax" | "platform_fee";
     glCode?: string;
     label: string;
     method: "flat" | "percentage";
     responsibleParty?: "platform" | "tenant" | "tax_authority" | "processor";
     scaling: "once" | "per_unit";
     type: "FEE";
     value: number;
   }
     | {
     adjustmentKind: "discount";
     glCode?: string;
     label: string;
     method: "flat" | "percentage";
     responsibleParty?: "platform" | "tenant" | "tax_authority" | "processor";
     scaling: "once" | "per_unit";
     type: "DISCOUNT";
     value: number;
  })[];
  calculation_phase: "compounding" | "non_compounding" | "post";
  level: "line" | "order";
}
  | {
  actions: {
     adjustmentKind: "base_price";
     amount_cents: number;
     glCode?: string;
     label: string;
     per?: "day" | "hour" | "night";
     responsibleParty?: "platform" | "tenant" | "tax_authority" | "processor";
     type: "BASE_PRICE";
     unit: "flat" | "unit" | "year" | "month" | "day" | "hour" | "night" | "person";
  }[];
  calculation_phase: "base";
  level: "line" | "order";
}>, 
   context: TContext, 
   options?: PartitionPricingResultOptions<TContext>
): PricingEvaluationResult<TContext>;

Defined in: shared/pricing/partition-rules-result.ts:71

Distributes a MatchResult<PricingDomainConfig> (typically produced by matchRules from @the-kaizen-labs/taproot/rules/server) into the pricing-shaped PricingEvaluationResult. Pure — depends only on its inputs and the supplied (or built-in) line-item scope mapping.

Three axes:

  • matchedByLevel — line vs. order
  • matchedByPhase — base / compounding / non_compounding / post
  • matchedByLineItem — for each line item in the context, the subset of line-level matched rules whose line-item scopes match that item. Computed by re-flattening each line item against lineItemScopes and re-running matchScopes with only the line-shape scopes from each rule. Order-level rules are not attached to line items.

scoped comes straight from the input MatchResult; matched keeps full-context order matches and replaces line matches with rules that pass for at least one individual line. The engine's allRules is intentionally dropped here — pricing callers only need the post-scope view. The original context is echoed back on the result for traceability.

Type Parameters

Type Parameter
TContext extends EvaluatePricingContext

Parameters

ParameterType
matchResultMatchResult< | { actions: ( | { adjustmentKind: "fee" | "tax" | "platform_fee"; glCode?: string; label: string; method: "flat" | "percentage"; responsibleParty?: "platform" | "tenant" | "tax_authority" | "processor"; scaling: "once" | "per_unit"; type: "FEE"; value: number; } | { adjustmentKind: "discount"; glCode?: string; label: string; method: "flat" | "percentage"; responsibleParty?: "platform" | "tenant" | "tax_authority" | "processor"; scaling: "once" | "per_unit"; type: "DISCOUNT"; value: number; })[]; calculation_phase: "compounding" | "non_compounding" | "post"; level: "line" | "order"; } | { actions: { adjustmentKind: "base_price"; amount_cents: number; glCode?: string; label: string; per?: "day" | "hour" | "night"; responsibleParty?: "platform" | "tenant" | "tax_authority" | "processor"; type: "BASE_PRICE"; unit: "flat" | "unit" | "year" | "month" | "day" | "hour" | "night" | "person"; }[]; calculation_phase: "base"; level: "line" | "order"; }>
contextTContext
optionsPartitionPricingResultOptions<TContext>

Returns

PricingEvaluationResult<TContext>

On this page