()
| 8 | import { isEnvTruthy } from './envUtils.js' |
| 9 | |
| 10 | export function hasConsoleBillingAccess(): boolean { |
| 11 | // Check if cost reporting is disabled via environment variable |
| 12 | if (isEnvTruthy(process.env.DISABLE_COST_WARNINGS)) { |
| 13 | return false |
| 14 | } |
| 15 | |
| 16 | const isSubscriber = isClaudeAISubscriber() |
| 17 | |
| 18 | // This might be wrong if user is signed into Max but also using an API key, but |
| 19 | // we already show a warning on launch in that case |
| 20 | if (isSubscriber) return false |
| 21 | |
| 22 | // Check if user has any form of authentication |
| 23 | const authSource = getAuthTokenSource() |
| 24 | const hasApiKey = getAnthropicApiKey() !== null |
| 25 | |
| 26 | // If user has no authentication at all (logged out), don't show costs |
| 27 | if (!authSource.hasToken && !hasApiKey) { |
| 28 | return false |
| 29 | } |
| 30 | |
| 31 | const config = getGlobalConfig() |
| 32 | const orgRole = config.oauthAccount?.organizationRole |
| 33 | const workspaceRole = config.oauthAccount?.workspaceRole |
| 34 | |
| 35 | if (!orgRole || !workspaceRole) { |
| 36 | return false // hide cost for grandfathered users who have not re-authed since we've added roles |
| 37 | } |
| 38 | |
| 39 | // Users have billing access if they are admins or billing roles at either workspace or organization level |
| 40 | return ( |
| 41 | ['admin', 'billing'].includes(orgRole) || |
| 42 | ['workspace_admin', 'workspace_billing'].includes(workspaceRole) |
| 43 | ) |
| 44 | } |
| 45 | |
| 46 | // Mock billing access for /mock-limits testing (set by mockRateLimits.ts) |
| 47 | let mockBillingAccessOverride: boolean | null = null |
no test coverage detected