Reward Engine
packages/reward-engine/src/evaluate.ts is the canonical reward logic package.
What It Does
The package is pure and deterministic:
- no I/O
- no database access
- no side effects
- the same inputs always produce the same result
Earn Calculation
evaluateReward(input) performs the current earn logic:
- Reject amounts below
minSpendMinorUnits. - Convert minor units to dollars.
- Multiply by
conversionRate. - Apply the campaign multiplier.
- Cap at
maxPointsPerTransaction. - Apply the configured rounding policy.
Redemption Eligibility
checkRedemptionEligibility(balance, cartAmountMinorUnits, rule) decides whether a redemption is allowed and how many points can be redeemed.
It enforces:
- minimum balance to redeem
- cart-value redemption cap
Stored Rule Shape
The reward rule config stored in Postgres currently contains:
conversionRateminSpendMinorUnitsmaxPointsPerTransactionminBalanceToRedeemmaxRedemptionPercentageroundingPolicy
Operational Notes
- reward rules are versioned per tenant
- only one rule version is active at a time
- reward events link the transaction to the exact rule version used
- ingestion passes the active earn-multiplier window, or
1when no window is active
Written byDhruv Doshi