Commit e9d048d
committed
refactor(billing): consolidate billing duplication (Commit 2.4)
Consolidates duplicated billing logic into billing-core.ts:
- getOrderedActiveGrantsForOwner: Unified grant fetching for users and orgs
- calculateUsageAndBalanceFromGrants: Pure function for balance calculation
- GRANT_ORDER_BY: Shared ordering constant
Includes comprehensive unit tests (12 tests) for balance calculations.
Fixes boundary condition regressions:
- Uses gt (greater than) instead of gte for expires_at comparisons
- Ensures grants expiring exactly at threshold are treated as expired
- Consistent behavior between consumption and balance calculations1 parent e03bcdf commit e9d048d
File tree
5 files changed
+1449
-230
lines changed- packages/billing/src
- __tests__
5 files changed
+1449
-230
lines changed
0 commit comments