refactor(config): unify tier credit constants across frontend and backend

This commit is contained in:
2026-04-03 19:20:28 +02:00
parent 7e87a74df9
commit 8639478a11
3 changed files with 47 additions and 15 deletions

32
lib/tier-credits.ts Normal file
View File

@@ -0,0 +1,32 @@
export const MONTHLY_TIER_CREDITS = {
free: 50,
starter: 400,
pro: 3300,
max: 6700,
business: 6700,
} as const;
export type BillingTier = keyof typeof MONTHLY_TIER_CREDITS;
export const PUBLIC_TIER_MONTHLY_CREDITS = {
free: MONTHLY_TIER_CREDITS.free,
starter: MONTHLY_TIER_CREDITS.starter,
pro: MONTHLY_TIER_CREDITS.pro,
max: MONTHLY_TIER_CREDITS.max,
} as const;
export type PublicTier = keyof typeof PUBLIC_TIER_MONTHLY_CREDITS;
export function normalizeBillingTier(tier: string | undefined | null): BillingTier {
if (!tier || tier === "free") return "free";
if (tier === "starter" || tier === "pro" || tier === "max" || tier === "business") {
return tier;
}
return "free";
}
export function normalizePublicTier(tier: string | undefined | null): PublicTier {
const normalizedTier = normalizeBillingTier(tier);
if (normalizedTier === "business") return "max";
return normalizedTier;
}