📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
fix: sync account limits with plan lifecycle
Blue Mousecd21f9033809
diff --git a/backend/apps/cloud/src/task-manager/task-manager.service.ts b/backend/apps/cloud/src/task-manager/task-manager.service.tsindex 89763ec08..eee920f76 100644--- a/backend/apps/cloud/src/task-manager/task-manager.service.ts+++ b/backend/apps/cloud/src/task-manager/task-manager.service.ts@@ -38,6 +38,7 @@ import {getNextPlan,DashboardBlockReason,ReportFrequency as UserReportFrequency,+ getDefaultAccountLimitUpdates,} from '../user/entities/user.entity'import {SEND_WARNING_AT_PERC,@@ -1470,6 +1471,8 @@ export class TaskManagerService {subUpdateURL: null,subCancelURL: null,billingFrequency: BillingFrequency.Monthly,+ planType: null,+ ...getDefaultAccountLimitUpdates(),})await this.projectService.clearProjectsRedisCache(user.id)}diff --git a/backend/apps/cloud/src/user/entities/user.entity.ts b/backend/apps/cloud/src/user/entities/user.entity.tsindex de98a081d..d1e3b0fc9 100644--- a/backend/apps/cloud/src/user/entities/user.entity.ts+++ b/backend/apps/cloud/src/user/entities/user.entity.ts@@ -60,6 +60,14 @@ interface PlanSignature {ypid?: string}+type AccountLimitUpdates = {+ maxProjects?: number+ maxApiKeyRequestsPerHour?: number+}++export const DEFAULT_MAX_PROJECTS = 50+export const DEFAULT_API_KEY_REQUESTS_PER_HOUR = 300+export const PLAN_TYPE_ENTITLEMENTS = {[PlanType.standard]: {websites: 50,@@ -119,9 +127,48 @@ export const getEffectivePlanType = (return null}-export const getPlanTypeEntitlements = (+export const getPlanTypeEntitlements = (planType?: PlanType | null) =>+ PLAN_TYPE_ENTITLEMENTS[planType || PlanType.standard]++const getNumericLimitOverride = (+ overrides: Record<string, unknown> | null | undefined,+ key: string,+) => {+ const value = overrides?.[key]++ return typeof value === 'number' ? value : null+}++export const getDefaultAccountLimitUpdates = () => ({+ maxProjects: DEFAULT_MAX_PROJECTS,+ maxApiKeyRequestsPerHour: DEFAULT_API_KEY_REQUESTS_PER_HOUR,+})++export const getPlanTypeAccountLimitUpdates = (planType?: PlanType | null,-) => PLAN_TYPE_ENTITLEMENTS[planType || PlanType.standard]+ entitlementOverrides?: Record<string, unknown> | null,+): AccountLimitUpdates => {+ const entitlements = getPlanTypeEntitlements(planType)+ const maxProjects =+ typeof entitlements.websites === 'number'+ ? entitlements.websites+ : getNumericLimitOverride(entitlementOverrides, 'websites')+ const maxApiKeyRequestsPerHour =+ typeof entitlements.apiRateLimitPerHour === 'number'+ ? entitlements.apiRateLimitPerHour+ : getNumericLimitOverride(entitlementOverrides, 'apiRateLimitPerHour')+ const updates: AccountLimitUpdates = {}++ if (typeof maxProjects === 'number') {+ updates.maxProjects = maxProjects+ }++ if (typeof maxApiKeyRequestsPerHour === 'number') {+ updates.maxApiKeyRequestsPerHour = maxApiKeyRequestsPerHour+ }++ return updates+}export const planTypeHasFeature = (planType: PlanType | null | undefined,@@ -433,10 +480,10 @@ export class User {@Column('varchar', { length: 60, nullable: true })twoFactorRecoveryCode: string- @Column('int', { default: 50 })+ @Column('int', { default: DEFAULT_MAX_PROJECTS })maxProjects: number- @Column('int', { default: 300 })+ @Column('int', { default: DEFAULT_API_KEY_REQUESTS_PER_HOUR })maxApiKeyRequestsPerHour: number@Column({ default: false })diff --git a/backend/apps/cloud/src/user/user.service.ts b/backend/apps/cloud/src/user/user.service.tsindex 0981a02a4..2d8c43c45 100644--- a/backend/apps/cloud/src/user/user.service.ts+++ b/backend/apps/cloud/src/user/user.service.ts@@ -35,6 +35,7 @@ import {PlanType,getEffectivePlanType,getPlanTypeEntitlements,+ getPlanTypeAccountLimitUpdates,} from './entities/user.entity'import { UserProfileDTO } from './dto/user.dto'import { RefreshToken } from './entities/refresh-token.entity'@@ -512,21 +513,6 @@ export class UserService {return PlanType.standard}- private getAccountLimitUpdates(planType?: PlanType | null) {- const entitlements = getPlanTypeEntitlements(planType)- const updates: Record<string, unknown> = {}-- if (typeof entitlements.websites === 'number') {- updates.maxProjects = entitlements.websites- }-- if (typeof entitlements.apiRateLimitPerHour === 'number') {- updates.maxApiKeyRequestsPerHour = entitlements.apiRateLimitPerHour- }-- return updates- }-getPlanById(planId: number, requestedPlanType?: string | null) {if (!planId) {return null@@ -770,7 +756,7 @@ export class UserService {nextBillDate: date,billingFrequency,tierCurrency: currency,- ...this.getAccountLimitUpdates(planType),+ ...getPlanTypeAccountLimitUpdates(planType, user.entitlementOverrides),}await this.update(id, updateParams)diff --git a/backend/apps/cloud/src/webhook/webhook.controller.ts b/backend/apps/cloud/src/webhook/webhook.controller.tsindex 35479e1a4..fe96b6aa3 100644--- a/backend/apps/cloud/src/webhook/webhook.controller.ts+++ b/backend/apps/cloud/src/webhook/webhook.controller.ts@@ -18,7 +18,7 @@ import {BillingFrequency,DashboardBlockReason,PlanType,- getPlanTypeEntitlements,+ getPlanTypeAccountLimitUpdates,isNextPlan,} from '../user/entities/user.entity'import { UserService } from '../user/user.service'@@ -171,18 +171,6 @@ export class WebhookController {: {}const planType = requestedPlanType || PlanType.standard- const entitlements = getPlanTypeEntitlements(planType)- const limitParams: Record<string, any> = {}-- if (typeof entitlements.websites === 'number') {- limitParams.maxProjects = entitlements.websites- }-- if (typeof entitlements.apiRateLimitPerHour === 'number') {- limitParams.maxApiKeyRequestsPerHour =- entitlements.apiRateLimitPerHour- }-const updateParams: Record<string, any> = {planCode: plan.id,planType,@@ -196,7 +184,10 @@ export class WebhookController {tierCurrency: currency,cancellationEffectiveDate: null,...statusParams,- ...limitParams,+ ...getPlanTypeAccountLimitUpdates(+ planType,+ currentUser.entitlementOverrides,+ ),}if (isTrialing && nextBillDate) {diff --git a/backend/migrations/mysql/2026_06_01_api_rate_limit_default.sql b/backend/migrations/mysql/2026_06_01_api_rate_limit_default.sqlnew file mode 100644index 000000000..dff2b390f--- /dev/null+++ b/backend/migrations/mysql/2026_06_01_api_rate_limit_default.sql@@ -0,0 +1 @@+ALTER TABLE `user` MODIFY COLUMN `maxApiKeyRequestsPerHour` int NOT NULL DEFAULT '300';