Repository navigation
feat(builder): show plan and usage quotas in sidebar (cloud-only) - #609
Merged
Merged
Conversation
| columns: { tenantId: true }, | ||
| }) | ||
|
|
||
| let tenantId = ROOT_TENANT_ID |
Add quota/usage display to the builder, gated to the hosted cloud edition (self-hosted community/enterprise installs keep every feature free): - NavUsage sidebar component renders per-metric progress bars (contacts, workspaces, channels, team members), only for metrics that have a limit. - NavUser dropdown shows the current plan label and an "Upgrade plan" link to /pricing when running in cloud mode. - Workspaces page shows a "used / limit" counter, highlighting when the workspace limit is reached. - Layout resolves quota via userQuotaService only when isCloud(). - Add planName / planStatus columns to UserQuota (written by the enterprise billing layer; null = free tier) with the accompanying Drizzle migration. - Add billing.plan / billing.usage / actions.upgradePlan i18n strings (en, vi).
Extend the cloud quota system from per-user limits to a dual-level (user + reseller pool) model, add trial visibility, and wire default-plan provisioning through the private billing portal. Cloud-only — self-hosted community/enterprise installs keep every feature free. Enforcement - New quotaEnforcementService gates resource creation against BOTH the user's own UserQuota and the pooled tenant (reseller) limit. All call sites (contact, inbox, workspace, invitation, received-message, contact import) migrate from userQuotaService.* to it. - New tenantQuotaService + TenantQuotaUsage table track pooled per-tenant usage (Redis live counter + DB high-water-mark reconciliation, mirroring UserQuotaService), with a syncTenantQuota scheduled job. - userQuotaService gains hasCapacity/consume/getLimit/metricValues and clearWhiteLabelEntitlements; tenantService gains suspend/reactivate/ downgrade for white-label lifecycle. Billing & trials - onUserCreated auth hook (packages/auth) provisions a new user's default plan via billingService, reached only through the builder's same-origin /portal/* micro-frontend proxy — no portal URL or secret in this repo. - planName/planStatus columns on UserQuota; TrialBanner + quota-metrics derive trial state and escalate info -> warning -> expired. UI - NavUsage/UsageBars sidebar bars, redesigned WorkspacesList + AccountRail, iframe UpgradePlanDialog, and an alert "warning" variant. Review fixes - Remove debug console.log from quotaEnforcementService. - Lock pooled contact-import on the tenant-pool key (resolveQuotaLockKey) so two sub-accounts can't both overrun the shared pool. - Serialize the non-pooled tryConsume path under a per-user lock. - Gate getAtLimitMap behind isCloud() on the homepage. - TrialBanner waits for hydration before hiding a dismissed banner (no flash).
…rlay - Gate workspace access on cloud once a trial is consumed/expired, redirecting to a new /trial-expired page; derive access state from the already-fetched quota to avoid a redundant query. - Add UserQuotaService.getAccessStateFromQuota plus default-plan entitlement overlay so free-tier users inherit published platform limits. - Show trial days-left banner in the sidebar usage nav. - Enqueue publishEntitlements on the cross-repo quota queue at sign-up instead of importing the billing service directly.
…t reconciliation Add Redis-backed live usage counters (workspaces, channels, team members, contacts, mac) in a shared quota counter store that fails closed on corrupt values, with monthly-active-contact (MAC) tracking wired through the analytics repository/service and the sync-user-quota schedule. Provision and suspend reseller tenants via a scheduled reconcile-tenants safety net behind upgrade-time provisioning, with an enterprise reconcile-tenant-entitlement action and tenant-unique-owner-id migration. Replace the trial banner with a usage-ring UI in the sidebar/account rail and centralize trial messaging.
The usage display read `used` from the DB columns synced by the `sync-user-quota` job (default every 60s) plus a 60s row cache, so a metric like `macUsed` could lag real activity by up to ~120s even though the fresh value already sat in the Redis live counter that enforcement reads. Add a batched `getLiveCounts` to the shared LiveCounterStore (one HMGET for all metrics, single-fetch cold-seeding of missing/corrupt fields, fail-closed to the DB on Redis error) and expose `getLiveUsage` on the user and tenant quota services. `getUsageSummary` now sources `used` from the live counters (limit still from the quota row), and `atLimitForMetric` uses the live `isLimitReached` so the badge matches the gates and display.
Declare the backfillDefaultPlan action and its job-data variant on the quota queue. Enqueued by the enterprise admin after a default-plan change to reconcile every existing user's entitlement snapshot (existing users hold a UserQuota row, so the published default-plan snapshot alone never reaches them); consumed by the enterprise quota-worker's backfill loop.
realcodesiman
force-pushed
the
feat/workspace-quota-usage-display
branch
from
June 23, 2026 23:33
97f79e0 to
a21a0c8
Compare
viethung0o0
pushed a commit
that referenced
this pull request
Sep 7, 2026
* feat(builder): show plan and usage quotas in sidebar (cloud-only) Add quota/usage display to the builder, gated to the hosted cloud edition (self-hosted community/enterprise installs keep every feature free): - NavUsage sidebar component renders per-metric progress bars (contacts, workspaces, channels, team members), only for metrics that have a limit. - NavUser dropdown shows the current plan label and an "Upgrade plan" link to /pricing when running in cloud mode. - Workspaces page shows a "used / limit" counter, highlighting when the workspace limit is reached. - Layout resolves quota via userQuotaService only when isCloud(). - Add planName / planStatus columns to UserQuota (written by the enterprise billing layer; null = free tier) with the accompanying Drizzle migration. - Add billing.plan / billing.usage / actions.upgradePlan i18n strings (en, vi). * feat(business): two-level quota enforcement, trials, and billing seam Extend the cloud quota system from per-user limits to a dual-level (user + reseller pool) model, add trial visibility, and wire default-plan provisioning through the private billing portal. Cloud-only — self-hosted community/enterprise installs keep every feature free. Enforcement - New quotaEnforcementService gates resource creation against BOTH the user's own UserQuota and the pooled tenant (reseller) limit. All call sites (contact, inbox, workspace, invitation, received-message, contact import) migrate from userQuotaService.* to it. - New tenantQuotaService + TenantQuotaUsage table track pooled per-tenant usage (Redis live counter + DB high-water-mark reconciliation, mirroring UserQuotaService), with a syncTenantQuota scheduled job. - userQuotaService gains hasCapacity/consume/getLimit/metricValues and clearWhiteLabelEntitlements; tenantService gains suspend/reactivate/ downgrade for white-label lifecycle. Billing & trials - onUserCreated auth hook (packages/auth) provisions a new user's default plan via billingService, reached only through the builder's same-origin /portal/* micro-frontend proxy — no portal URL or secret in this repo. - planName/planStatus columns on UserQuota; TrialBanner + quota-metrics derive trial state and escalate info -> warning -> expired. UI - NavUsage/UsageBars sidebar bars, redesigned WorkspacesList + AccountRail, iframe UpgradePlanDialog, and an alert "warning" variant. Review fixes - Remove debug console.log from quotaEnforcementService. - Lock pooled contact-import on the tenant-pool key (resolveQuotaLockKey) so two sub-accounts can't both overrun the shared pool. - Serialize the non-pooled tryConsume path under a per-user lock. - Gate getAtLimitMap behind isCloud() on the homepage. - TrialBanner waits for hydration before hiding a dismissed banner (no flash). * feat(builder): self-managed trial gate and default-plan free-tier overlay - Gate workspace access on cloud once a trial is consumed/expired, redirecting to a new /trial-expired page; derive access state from the already-fetched quota to avoid a redundant query. - Add UserQuotaService.getAccessStateFromQuota plus default-plan entitlement overlay so free-tier users inherit published platform limits. - Show trial days-left banner in the sidebar usage nav. - Enqueue publishEntitlements on the cross-repo quota queue at sign-up instead of importing the billing service directly. * feat(quota): live usage counters, MAC tracking, and tenant entitlement reconciliation Add Redis-backed live usage counters (workspaces, channels, team members, contacts, mac) in a shared quota counter store that fails closed on corrupt values, with monthly-active-contact (MAC) tracking wired through the analytics repository/service and the sync-user-quota schedule. Provision and suspend reseller tenants via a scheduled reconcile-tenants safety net behind upgrade-time provisioning, with an enterprise reconcile-tenant-entitlement action and tenant-unique-owner-id migration. Replace the trial banner with a usage-ring UI in the sidebar/account rail and centralize trial messaging. * feat(business): serve quota usage display from live counters The usage display read `used` from the DB columns synced by the `sync-user-quota` job (default every 60s) plus a 60s row cache, so a metric like `macUsed` could lag real activity by up to ~120s even though the fresh value already sat in the Redis live counter that enforcement reads. Add a batched `getLiveCounts` to the shared LiveCounterStore (one HMGET for all metrics, single-fetch cold-seeding of missing/corrupt fields, fail-closed to the DB on Redis error) and expose `getLiveUsage` on the user and tenant quota services. `getUsageSummary` now sources `used` from the live counters (limit still from the quota row), and `atLimitForMetric` uses the live `isLimitReached` so the badge matches the gates and display. * feat(worker-config): add backfillDefaultPlan quota job action Declare the backfillDefaultPlan action and its job-data variant on the quota queue. Enqueued by the enterprise admin after a default-plan change to reconcile every existing user's entitlement snapshot (existing users hold a UserQuota row, so the published default-plan snapshot alone never reaches them); consumed by the enterprise quota-worker's backfill loop.
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Surfaces plan and usage quotas in the builder UI, gated to the hosted cloud edition. Self-hosted community/enterprise installs keep every feature free — no quota gating, no upgrade prompts.
NavUsage(new sidebar component) renders per-metric progress bars for monthly active contacts, workspaces, channels, team members. Only metrics that actually have a numeric limit are shown; nothing renders on the free tier or when the sidebar is collapsed to icons.NavUserdropdown now shows the current plan label and an "Upgrade plan" link to/pricing— only whenisCloud().used / limitcounter next to the heading, highlighted intext-destructivewhen the limit is reached.userQuotaService.getForUseronly whenisCloud(); otherwise skips the call entirely (Promise.resolve(null)).UserQuotaschema gainsplanName/planStatustext columns (written by the enterprise billing layer'spublishEntitlements;null= free tier / not yet synced), with the accompanying Drizzle migration.billing.plan.*,billing.usage.*, andactions.upgradePlanin en and vi.Notes
planName/planStatuscolumns require running the migration:pnpm --filter @chatbotx.io/database db:migrate.Test plan
/pricing; plan label reflectsplanName(or "Free").used / limit; counter turns red at the limit; hidden when no limit set.planName/planStatusdefault to null.pnpm lintandpnpm --filter builder check-typespass.