feat(credits): enterprise-domain accounts get pro credits; PRO_CREDITS → 9,999
Merged
SW
5mo ago+137+137+012345678901234567890123456789-10-10-01234567890123456789
Part of recoupable/chat#1841 (item "Open — credits").
What
- Enterprise-domain accounts resolve pro in the credits system.
getAccountSubscriptionStatewas Stripe-only, so enterprise customers without a Stripe subscription (e.g. all of Seeker Music) fell to the 333 free tier. New SRP helperlib/enterprise/isEnterpriseAccount.tschecks whether any of the account's emails (lib/supabase/account_emails/selectAccountEmails) has a domain (extractDomain) inENTERPRISE_DOMAINS; the check runs in parallel with the two existing Stripe lookups. PRO_CREDITSraised from 1,000 to 9,999 inlib/credits/const.ts.
Design notes
activeSubscriptionstays Stripe-only. It feedscheckAndResetCredits's early-refill viacurrent_period_start; an enterprise match returnsisPro: true, activeSubscription: null, so enterprise-pro accounts refill only on the ≥1-month path. TheAccountSubscriptionStateinterface shape is unchanged.- Coordination: the sibling chat PR must land back-to-back — chat duplicates the credits stack (its own
PRO_CREDITSand pro resolution), and the two must agree or the sidebar total and the API total diverge. - Heads-up on hand-set balances: the monthly refill OVERWRITES the balance (
remaining_credits := plan total, not an increment). Any account whose balance was hand-set above/below plan will be clobbered to 9,999 (pro) or 333 (free) at its next refill.
Verification
- TDD: new tests written first and confirmed failing (missing module /
PRO_CREDITS1000 ≠ 9999 / enterprise caseisPro: false), then implementation turned them green. - Full suite: 685 test files, 3,772 tests, all passing (
pnpm test). tsc --noEmit: 201 errors on baseline → 200 after (zero new; remainder are pre-existing in untouched test files).pnpm lintclean; prettier check clean on all touched files.
New tests:
lib/enterprise/__tests__/isEnterpriseAccount.test.ts— domain match, case-insensitive, multi-email, non-match, no emails, null/malformed emails.lib/credits/__tests__/getAccountSubscriptionState.test.ts— enterprise-no-Stripe →isPro: true+activeSubscription: null; enterprise + Stripe keepsactiveSubscriptionStripe-only; existing Stripe-only cases unchanged.lib/credits/__tests__/const.test.ts— pinsPRO_CREDITS = 9999,DEFAULT_CREDITS = 333.
🤖 Generated with Claude Code
Summary by cubic
Enterprise-domain accounts now resolve as pro in the credits system without Stripe. PRO_CREDITS increases to 9,999 so enterprise and pro users don’t worry about credits.
-
New Features
- Added
lib/enterprise/isEnterpriseAccount.tsto match account email domains againstENTERPRISE_DOMAINS(viaextractDomain) and wired it intogetAccountSubscriptionStatealongside Stripe account/org checks. activeSubscriptionstays Stripe-only; enterprise-only accounts getisPro: truewithactiveSubscription: nullto avoid early refill viacurrent_period_start.
- Added
-
Migration
- Coordinate with the chat app to apply the same pro resolution so the UI and API totals stay in sync.
- Monthly refill overwrites balances to plan totals; any hand-set balances will reset to 9,999 (pro) or 333 (free) at the next refill.
Summary by CodeRabbit
-
New Features
- Expanded pro access recognition for eligible enterprise email domains.
- Increased monthly pro credit allocation.
-
Bug Fixes
- Pro status now resolves more consistently across account, organization, and enterprise-based eligibility.
- Credit limits now reflect the updated pro-tier allotment.