feat: add plan stacking
This commit is contained in:
@@ -60,6 +60,7 @@ export async function migrate() {
|
||||
|
||||
await sql`ALTER TABLE accounts ADD COLUMN IF NOT EXISTS plan TEXT NOT NULL DEFAULT 'free'`;
|
||||
await sql`ALTER TABLE accounts ADD COLUMN IF NOT EXISTS plan_expires_at TIMESTAMPTZ`;
|
||||
await sql`ALTER TABLE accounts ADD COLUMN IF NOT EXISTS plan_stack JSONB NOT NULL DEFAULT '[]'`;
|
||||
|
||||
await sql`CREATE INDEX IF NOT EXISTS idx_pings_monitor ON pings(monitor_id, checked_at DESC)`;
|
||||
await sql`CREATE INDEX IF NOT EXISTS idx_pings_checked_at ON pings(checked_at)`;
|
||||
|
||||
@@ -115,7 +115,7 @@ export const account = new Elysia({ prefix: "/account" })
|
||||
.use(requireAuth)
|
||||
|
||||
.get("/settings", async ({ accountId }) => {
|
||||
const [acc] = await sql`SELECT id, email_hash, plan, plan_expires_at, created_at FROM accounts WHERE id = ${accountId}`;
|
||||
const [acc] = await sql`SELECT id, email_hash, plan, plan_expires_at, plan_stack, created_at FROM accounts WHERE id = ${accountId}`;
|
||||
const keys = await sql`SELECT id, key, label, created_at, last_used_at FROM api_keys WHERE account_id = ${accountId} ORDER BY created_at DESC`;
|
||||
const [{ count: monitorCount }] = await sql`SELECT COUNT(*)::int as count FROM monitors WHERE account_id = ${accountId}`;
|
||||
const limits = getPlanLimits(acc.plan);
|
||||
@@ -124,6 +124,7 @@ export const account = new Elysia({ prefix: "/account" })
|
||||
has_email: !!acc.email_hash,
|
||||
plan: acc.plan,
|
||||
plan_expires_at: acc.plan_expires_at,
|
||||
plan_stack: acc.plan_stack || [],
|
||||
monitor_count: monitorCount,
|
||||
limits,
|
||||
created_at: acc.created_at,
|
||||
|
||||
@@ -31,3 +31,12 @@ export const PRO_MULTIPLIERS = [
|
||||
|
||||
export const PRO_MONTHLY_USD = 12;
|
||||
export const LIFETIME_USD = 140;
|
||||
|
||||
// Tier ranking for plan stacking decisions
|
||||
const PLAN_RANK: Record<string, number> = {
|
||||
free: 0, pro: 1, lifetime: 1, pro2x: 2, pro4x: 3,
|
||||
};
|
||||
|
||||
export function planTier(plan: string): number {
|
||||
return PLAN_RANK[plan] ?? 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user