fix: create product endpoint for old versions

This commit is contained in:
John Yeo
2025-10-27 17:09:47 -07:00
parent 178af955fe
commit 65963529e3
15 changed files with 297 additions and 84 deletions

View File

@@ -113,3 +113,37 @@ export const cusEntToMaxPurchase = ({
return 0;
};
// NEW CUS ENT UTILS
export const cusEntToGrantedBalance = ({
cusEnt,
entityId,
withRollovers = false,
}: {
cusEnt: FullCusEntWithFullCusProduct;
entityId?: string;
withRollovers?: boolean;
}) => {
const rollover = getRolloverFields({
cusEnt,
entityId,
});
const { count: entityCount } = getCusEntBalance({
cusEnt,
entityId,
});
const grantedBalance = cusEnt.entitlement.allowance || 0;
const total = new Decimal(grantedBalance).mul(entityCount).toNumber();
if (withRollovers && rollover) {
return new Decimal(total)
.add(rollover.balance)
.add(rollover.usage)
.toNumber();
}
return total;
};