feat(credits): enterprise-domain accounts get pro credits; PRO_CREDITS → 9,999

Merged
SW
5mo ago
+137-10

Part of recoupable/chat#1841 (item "Open — credits").

What

  1. Enterprise-domain accounts resolve pro in the credits system. getAccountSubscriptionState was Stripe-only, so enterprise customers without a Stripe subscription (e.g. all of Seeker Music) fell to the 333 free tier. New SRP helper lib/enterprise/isEnterpriseAccount.ts checks whether any of the account's emails (lib/supabase/account_emails/selectAccountEmails) has a domain (extractDomain) in ENTERPRISE_DOMAINS; the check runs in parallel with the two existing Stripe lookups.
  2. PRO_CREDITS raised from 1,000 to 9,999 in lib/credits/const.ts.

Design notes

  • activeSubscription stays Stripe-only. It feeds checkAndResetCredits's early-refill via current_period_start; an enterprise match returns isPro: true, activeSubscription: null, so enterprise-pro accounts refill only on the ≥1-month path. The AccountSubscriptionState interface shape is unchanged.
  • Coordination: the sibling chat PR must land back-to-back — chat duplicates the credits stack (its own PRO_CREDITS and 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_CREDITS 1000 ≠ 9999 / enterprise case isPro: 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 lint clean; 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 keeps activeSubscription Stripe-only; existing Stripe-only cases unchanged.
  • lib/credits/__tests__/const.test.ts — pins PRO_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.ts to match account email domains against ENTERPRISE_DOMAINS (via extractDomain) and wired it into getAccountSubscriptionState alongside Stripe account/org checks.
    • activeSubscription stays Stripe-only; enterprise-only accounts get isPro: true with activeSubscription: null to avoid early refill via current_period_start.
  • 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.