Skip to content

feat: organization guardrails and team seat billing (#581-582)#742

Open
2witstudios wants to merge 4 commits intomasterfrom
ppg/orgs-billing
Open

feat: organization guardrails and team seat billing (#581-582)#742
2witstudios wants to merge 4 commits intomasterfrom
ppg/orgs-billing

Conversation

@2witstudios
Copy link
Owner

Summary

  • Organization schema with guardrail settings (allowedAIProviders, maxStorage, maxAITokens, requireMFA, allowExternalSharing, allowedDomains)
  • Org membership system with OWNER/ADMIN/MEMBER roles and domain-restricted invites
  • Stripe per-seat billing with 4 tiers: Free / Pro ($14/seat) / Business ($28/seat) / Enterprise
  • Auto seat adjustment on member add/remove with prorated billing and 3-day grace period
  • API routes: org CRUD, settings, members, billing, seats, invoices
  • Enforcement middleware with pure guardrail check functions
  • 35 passing unit tests across guardrails and billing plans

Test plan

  • Guardrail enforcement works (AI provider, storage, domain, external sharing checks)
  • Org CRUD and member management API routes respond correctly
  • Stripe per-seat subscription creation and seat adjustment
  • Invoice listing via Stripe API
  • Unit tests pass: cd apps/web && pnpm vitest run src/lib/orgs/__tests__/

🤖 Generated with Claude Code

2witstudios and others added 2 commits February 27, 2026 22:55
- Organizations table with guardrail settings: allowedAIProviders,
  maxStorage, maxAITokens, requireMFA, allowExternalSharing, allowedDomains
- Org members table with OWNER/ADMIN/MEMBER roles
- Org drives junction table to link drives to orgs
- Org subscriptions table for per-seat billing
- Pure guardrail check functions with 19 passing unit tests
- Org auth middleware (withOrgAuth, withOrgAdminAuth, withOrgOwnerAuth)
- CRUD API routes: orgs, org details, settings, members
- Drizzle migration generated

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 4-tier org billing: Free/Pro($14/seat)/Business($28/seat)/Enterprise
- Seat manager: auto-adjust quantity on member add/remove
- Prorated billing on seat changes with 3-day grace period
- API routes: GET/POST billing, GET/PUT seats, GET invoices
- Org webhook handlers for subscription lifecycle events
- 16 passing unit tests for billing plans

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 28, 2026

Warning

Rate limit exceeded

@2witstudios has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 23 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between afb36e6 and 057295a.

📒 Files selected for processing (21)
  • apps/web/src/app/api/orgs/[orgId]/billing/invoices/route.ts
  • apps/web/src/app/api/orgs/[orgId]/billing/route.ts
  • apps/web/src/app/api/orgs/[orgId]/billing/seats/route.ts
  • apps/web/src/app/api/orgs/[orgId]/members/[userId]/route.ts
  • apps/web/src/app/api/orgs/[orgId]/members/route.ts
  • apps/web/src/app/api/orgs/[orgId]/route.ts
  • apps/web/src/app/api/orgs/[orgId]/settings/route.ts
  • apps/web/src/app/api/orgs/route.ts
  • apps/web/src/lib/orgs/__tests__/billing-plans.test.ts
  • apps/web/src/lib/orgs/__tests__/guardrails.test.ts
  • apps/web/src/lib/orgs/billing-plans.ts
  • apps/web/src/lib/orgs/guardrail-checks.ts
  • apps/web/src/lib/orgs/guardrails.ts
  • apps/web/src/lib/orgs/org-auth.ts
  • apps/web/src/lib/orgs/org-webhook-handlers.ts
  • apps/web/src/lib/orgs/seat-manager.ts
  • packages/db/drizzle/0090_youthful_black_widow.sql
  • packages/db/drizzle/meta/0090_snapshot.json
  • packages/db/drizzle/meta/_journal.json
  • packages/db/src/schema.ts
  • packages/db/src/schema/organizations.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ppg/orgs-billing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

2witstudios and others added 2 commits February 28, 2026 08:11
- Remove unused 'and' import from org-webhook-handlers.ts
- Remove unused 'orgMembers' import from seat-manager.ts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Follow existing codebase pattern for accessing confirmation_secret
from expanded latest_invoice, using proper Stripe.Invoice type
intersection instead of Record<string, unknown> cast.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant