MCPcopy Create free account
hub / github.com/Noumena-Network/code / hasManagedPlanBillingAccessForSession

Function hasManagedPlanBillingAccessForSession

src/utils/billing.ts:38–67  ·  view source on GitHub ↗
(
  session: Pick<ResolvedAuthSession, 'principalSource' | 'sessionState' | 'subscription'>,
  roles: {
    organizationRole: string | null | undefined
  },
)

Source from the content-addressed store, hash-verified

36}
37
38export function hasManagedPlanBillingAccessForSession(
39 session: Pick<ResolvedAuthSession, 'principalSource' | 'sessionState' | 'subscription'>,
40 roles: {
41 organizationRole: string | null | undefined
42 },
43): boolean {
44 if (
45 session.principalSource !== 'managed_oauth' ||
46 session.sessionState !== 'usable'
47 ) {
48 return false
49 }
50
51 const subscriptionType = session.subscription.subscriptionType
52
53 if (!subscriptionType) {
54 return false
55 }
56
57 if (subscriptionType === 'max' || subscriptionType === 'pro') {
58 return true
59 }
60
61 return (
62 !!roles.organizationRole &&
63 ['admin', 'billing', 'owner', 'primary_owner'].includes(
64 roles.organizationRole,
65 )
66 )
67}
68
69export function hasConsoleBillingAccess(): boolean {
70 // Check if cost reporting is disabled via environment variable

Callers 2

billing.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected