(
userId: string,
billingEntity?: BillingEntity,
billingPeriod?: { start: Date; end: Date }
)
| 160 | } |
| 161 | |
| 162 | async function resolveBillingContext( |
| 163 | userId: string, |
| 164 | billingEntity?: BillingEntity, |
| 165 | billingPeriod?: { start: Date; end: Date } |
| 166 | ): Promise<BillingContext> { |
| 167 | if (billingEntity && billingPeriod) { |
| 168 | return { billingEntity, billingPeriod } |
| 169 | } |
| 170 | |
| 171 | const subscription = await getHighestPrioritySubscription(userId) |
| 172 | const derived = deriveBillingContext(userId, subscription) |
| 173 | return { |
| 174 | billingEntity: billingEntity ?? derived.billingEntity, |
| 175 | billingPeriod: billingPeriod ?? derived.billingPeriod, |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Returns post-cutover usage for an attributed billing entity/period. |
no test coverage detected