feat(billing): align enterprise reporting periods - #6851
Conversation
…eporting-period # Conflicts: # apps/sim/lib/admin/dashboard.ts # apps/sim/lib/billing/enterprise-provisioning.ts # packages/db/migrations/meta/0290_snapshot.json # packages/db/migrations/meta/_journal.json # scripts/check-api-validation-contracts.ts
…eporting-period # Conflicts: # scripts/check-api-validation-contracts.ts
…eporting-period # Conflicts: # packages/db/migrations/meta/0292_snapshot.json # packages/db/migrations/meta/_journal.json # scripts/check-api-validation-contracts.ts
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryHigh Risk Overview Org billing and roster APIs paginate members ( Admin dashboard gains Enterprise issuance preflight, billing-terms preview/update, configuration-update and workspace-move retries, paginated organization detail (members, collaborators, workspaces), ledger-based usage on list/detail, historical actor usage, and invoice/cadence fields ( Reviewed by Cursor Bugbot for commit 5338449. Configure here. |
Greptile SummaryThis PR introduces explicit monthly and yearly Enterprise reporting periods and propagates them through billing attribution, usage enforcement, member reporting, and administrative APIs. It also strengthens Stripe/outbox reconciliation, paginates organization reporting data, adds complete usage and actor aggregates, and creates a concurrent covering index for reporting-period usage reads.
Confidence Score: 5/5The PR appears safe to merge because no concrete, changed-code-triggered failure remains after reviewing the billing-period, reporting, reconciliation, pagination, and migration changes. The changed paths consistently introduce explicit reporting-period metadata, bounded pagination, resumable outbox state, and supporting database indexing without an established reachable contract violation or observable failure.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/billing/core/reporting-period.ts | Adds UTC calendar-aligned monthly and yearly Enterprise reporting windows with month-end and leap-year clamping. |
| apps/sim/lib/billing/calculations/usage-monitor.ts | Propagates resolved billing contexts into usage enforcement so Enterprise reporting periods can drive ledger reads. |
| apps/sim/lib/billing/core/organization.ts | Centralizes reporting-period-aware member usage snapshots and complete organization-level usage totals. |
| apps/sim/lib/billing/enterprise-outbox.ts | Extends Enterprise metadata intents with billing terms, delivery revisions, verification state, and member reconciliation payloads. |
| apps/sim/lib/billing/enterprise-provisioning.ts | Adds billing-term updates, resumable workspace/member reconciliation, and Stripe delivery verification. |
| apps/sim/lib/billing/webhooks/enterprise.ts | Makes webhook reconciliation authoritative for applied Enterprise terms and delegates larger reconciliation work to the outbox. |
| apps/sim/lib/admin/dashboard.ts | Adds paginated organization detail collections, aggregate usage reporting, historical actors, and Enterprise billing-term administration. |
| apps/sim/lib/core/outbox/service.ts | Adds bounded bulk event enqueueing and payload checkpoint support used by resumable Enterprise operations. |
| packages/db/migrations/0293_workable_jigsaw.sql | Adds the concurrent covering index needed for organization reporting-period usage aggregation. |
| packages/db/schema.ts | Aligns the Drizzle usage-log index declaration with the new reporting-period query pattern. |
Sequence Diagram
sequenceDiagram
participant Admin
participant API as Admin API
participant DB as Postgres
participant Outbox
participant Stripe
participant Webhook
Admin->>API: Update Enterprise billing terms
API->>DB: Lock subscription and enqueue revision
DB-->>Outbox: Pending metadata-sync event
Outbox->>Stripe: Apply cadence, price, and metadata
Stripe-->>Outbox: Provider state
Outbox->>DB: Checkpoint delivery and verification state
Stripe->>Webhook: Subscription reconciliation event
Webhook->>DB: Persist authoritative applied terms
DB-->>API: Reporting period and usage totals
Reviews (1): Last reviewed commit: "Merge remote-tracking branch 'origin/sta..." | Re-trigger Greptile
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 5338449. Configure here.
…eporting-period # Conflicts: # packages/db/migrations/meta/0293_snapshot.json # packages/db/migrations/meta/_journal.json

Summary
Type of Change
Testing
bun run lintbun run check:auditsbun run check:migrations origin/stagingbun run type-checkChecklist