refactor(config): unify tier credit constants across frontend and backend
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
PUBLIC_TIER_MONTHLY_CREDITS,
|
||||
normalizePublicTier,
|
||||
} from "./tier-credits";
|
||||
|
||||
export const SUBSCRIPTION_PRODUCTS = {
|
||||
starter: {
|
||||
polarProductId: "81b6de07-cd41-430f-bd54-f0e7072deec6",
|
||||
@@ -47,15 +52,9 @@ export const TOPUP_PRODUCTS = [
|
||||
] as const;
|
||||
|
||||
export const TIER_MONTHLY_CREDITS = {
|
||||
free: 50,
|
||||
starter: 400,
|
||||
pro: 3300,
|
||||
max: 6700,
|
||||
...PUBLIC_TIER_MONTHLY_CREDITS,
|
||||
} as const;
|
||||
|
||||
export function normalizeTier(tier: string | undefined | null): keyof typeof TIER_MONTHLY_CREDITS {
|
||||
if (!tier || tier === "free") return "free";
|
||||
if (tier === "starter" || tier === "pro" || tier === "max") return tier;
|
||||
if (tier === "business") return "max";
|
||||
return "free";
|
||||
return normalizePublicTier(tier);
|
||||
}
|
||||
|
||||
32
lib/tier-credits.ts
Normal file
32
lib/tier-credits.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user