Initial import: property management SaaS + security hardening + admin dashboard
Property Management Network — Next.js 16 (App Router), Better Auth, Drizzle ORM over PostgreSQL, Stripe, OpenAI, Resend. Includes: - Security hardening: access-control/IDOR fixes, TLS-by-default DB layer, constant-time cron auth, strict security headers, atomic AI quota gating, HTML/email output encoding, demo-backdoor disabled in production. - Superadmin dashboard at /admin (overview/MRR, server-paginated users with ban/impersonate/plan/delete, billing, platform activity + admin audit log, AI usage, system health) via the Better Auth admin plugin. - Seed/migration utility scripts under scripts/. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import Stripe from "stripe"
|
||||
|
||||
// Lazily construct the Stripe client so `next build` (which evaluates route
|
||||
// modules to collect page data) does NOT require STRIPE_SECRET_KEY. The key is
|
||||
// only needed at runtime. Call sites keep using `stripe.xxx` unchanged — the
|
||||
// Proxy builds the real client on first property access.
|
||||
let _stripe: Stripe | null = null
|
||||
|
||||
function getStripe(): Stripe {
|
||||
if (!_stripe) {
|
||||
const key = process.env.STRIPE_SECRET_KEY
|
||||
if (!key) throw new Error("STRIPE_SECRET_KEY is not set")
|
||||
_stripe = new Stripe(key, {
|
||||
apiVersion: "2025-03-31.basil",
|
||||
typescript: true,
|
||||
})
|
||||
}
|
||||
return _stripe
|
||||
}
|
||||
|
||||
export const stripe = new Proxy({} as Stripe, {
|
||||
get(_target, prop, receiver) {
|
||||
const client = getStripe()
|
||||
const value = Reflect.get(client, prop, receiver)
|
||||
return typeof value === "function" ? value.bind(client) : value
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,46 @@
|
||||
import { stripe } from "./client"
|
||||
|
||||
export async function createRentPaymentLink({
|
||||
tenantName,
|
||||
propertyName,
|
||||
unitNumber,
|
||||
amount,
|
||||
tenantId,
|
||||
paymentId,
|
||||
}: {
|
||||
tenantName: string
|
||||
propertyName: string
|
||||
unitNumber: string
|
||||
amount: number
|
||||
tenantId: string
|
||||
paymentId: string
|
||||
}) {
|
||||
const paymentLink = await stripe.paymentLinks.create({
|
||||
line_items: [
|
||||
{
|
||||
price_data: {
|
||||
currency: "usd",
|
||||
unit_amount: Math.round(amount * 100),
|
||||
product_data: {
|
||||
name: `Rent Payment — ${propertyName} Unit ${unitNumber}`,
|
||||
description: `Tenant: ${tenantName}`,
|
||||
},
|
||||
},
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
metadata: {
|
||||
tenant_id: tenantId,
|
||||
payment_id: paymentId,
|
||||
type: "rent_payment",
|
||||
},
|
||||
after_completion: {
|
||||
type: "redirect",
|
||||
redirect: {
|
||||
url: `${process.env.NEXT_PUBLIC_APP_URL}/tenant-portal/payment-success`,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
return paymentLink
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
import type { Plan, PlanLimits } from "@/types"
|
||||
|
||||
export const PLAN_LIMITS: Record<Plan, PlanLimits> = {
|
||||
starter: {
|
||||
maxProperties: 1,
|
||||
maxTenants: 3,
|
||||
maxAiCalls: 0,
|
||||
maxStorageMB: 100,
|
||||
hasTeamAccess: false,
|
||||
hasWhiteLabel: false,
|
||||
},
|
||||
pro: {
|
||||
maxProperties: 10,
|
||||
maxTenants: Infinity,
|
||||
maxAiCalls: 50,
|
||||
maxStorageMB: 5120,
|
||||
hasTeamAccess: false,
|
||||
hasWhiteLabel: false,
|
||||
},
|
||||
landlord: {
|
||||
maxProperties: Infinity,
|
||||
maxTenants: Infinity,
|
||||
maxAiCalls: 200,
|
||||
maxStorageMB: 25600,
|
||||
hasTeamAccess: true,
|
||||
hasWhiteLabel: true,
|
||||
},
|
||||
lifetime: {
|
||||
maxProperties: Infinity,
|
||||
maxTenants: Infinity,
|
||||
maxAiCalls: 200,
|
||||
maxStorageMB: 25600,
|
||||
hasTeamAccess: true,
|
||||
hasWhiteLabel: true,
|
||||
},
|
||||
}
|
||||
|
||||
export const PLAN_PRICES: Record<string, { plan: Plan; priceId: string; amount: number; interval: string }> = {
|
||||
pro: {
|
||||
plan: "pro",
|
||||
priceId: process.env.STRIPE_PRO_MONTHLY_PRICE_ID!,
|
||||
amount: 29,
|
||||
interval: "month",
|
||||
},
|
||||
landlord: {
|
||||
plan: "landlord",
|
||||
priceId: process.env.STRIPE_LANDLORD_MONTHLY_PRICE_ID!,
|
||||
amount: 59,
|
||||
interval: "month",
|
||||
},
|
||||
lifetime: {
|
||||
plan: "lifetime",
|
||||
priceId: process.env.STRIPE_LIFETIME_PRICE_ID!,
|
||||
amount: 199,
|
||||
interval: "one_time",
|
||||
},
|
||||
}
|
||||
|
||||
export function checkLimit(
|
||||
plan: Plan,
|
||||
resource: keyof PlanLimits,
|
||||
currentCount: number
|
||||
): boolean {
|
||||
const limit = PLAN_LIMITS[plan][resource]
|
||||
if (typeof limit === "boolean") return limit
|
||||
return currentCount < (limit as number)
|
||||
}
|
||||
|
||||
export function getPlanLabel(plan: Plan): string {
|
||||
const labels: Record<Plan, string> = {
|
||||
starter: "Starter",
|
||||
pro: "Pro",
|
||||
landlord: "Landlord",
|
||||
lifetime: "Lifetime",
|
||||
}
|
||||
return labels[plan]
|
||||
}
|
||||
Reference in New Issue
Block a user