( userId: string, subscription: ResolvedSubscription )
| 143 | * place that maps a subscription to a billing context. |
| 144 | */ |
| 145 | export function deriveBillingContext( |
| 146 | userId: string, |
| 147 | subscription: ResolvedSubscription |
| 148 | ): BillingContext { |
| 149 | const billingEntity: BillingEntity = |
| 150 | subscription && isOrgScopedSubscription(subscription, userId) |
| 151 | ? { type: 'organization', id: subscription.referenceId } |
| 152 | : { type: 'user', id: userId } |
| 153 | |
| 154 | const billingPeriod = |
| 155 | subscription?.periodStart && subscription.periodEnd |
| 156 | ? { start: subscription.periodStart, end: subscription.periodEnd } |
| 157 | : defaultBillingPeriod() |
| 158 | |
| 159 | return { billingEntity, billingPeriod } |
| 160 | } |
| 161 | |
| 162 | async function resolveBillingContext( |
| 163 | userId: string, |
no test coverage detected