Consolidate audit-fixes branch: webhooks, integrations, and deploy hardening

Batch commit of the pending working tree on security/audit-fixes-2026-07.
Major areas:
- Outbound webhooks / Zapier: schema + signed delivery with retries, public
  v1 API (REST-hook subscribe/unsubscribe), settings UI, cron drain.
- Deploy hardening: email via SMTP2GO (Resend fully removed), verified DB TLS
  (DATABASE_SSL=require + DATABASE_CA), storage fails loud in production when
  Spaces is unconfigured instead of silently using ephemeral disk.
- Integrations & features (concurrent work): accounting (QuickBooks/Xero),
  e-signature (DocuSign/Dropbox Sign), PayPal, geocoding/maps, onboarding,
  expanded legal pages.
- DB migrations 0006–0009.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Leon Serfaty
2026-07-02 13:42:34 -04:00
co-authored by Claude Opus 4.8
parent 969d5d4c8a
commit c9968531e4
282 changed files with 41530 additions and 4013 deletions
+15 -5
View File
@@ -5,16 +5,26 @@ import { profiles } from "@/lib/db/schema"
import { getSessionUser } from "@/lib/session"
import { stripe } from "@/lib/stripe/client"
import { PLAN_PRICES } from "@/lib/stripe/plans"
import { resolvePriceId } from "@/lib/stripe/prices"
export async function POST(request: Request) {
const user = await getSessionUser()
if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
const { plan } = await request.json() as { plan: string }
const { plan, interval } = await request.json() as {
plan: string
interval?: "month" | "year"
}
const planConfig = PLAN_PRICES[plan]
if (!planConfig) return NextResponse.json({ error: "Invalid plan" }, { status: 400 })
const billingInterval = interval === "year" ? "year" : "month"
const priceId = await resolvePriceId(planConfig.plan, billingInterval)
if (!priceId) {
return NextResponse.json({ error: "Could not resolve the plan price. Check STRIPE_SECRET_KEY." }, { status: 400 })
}
const profile = await db.query.profiles.findFirst({
where: eq(profiles.id, user.id),
columns: { stripe_customer_id: true, email: true, full_name: true },
@@ -27,7 +37,7 @@ export async function POST(request: Request) {
const customer = await stripe.customers.create({
email: profile?.email ?? user.email,
name: profile?.full_name ?? undefined,
metadata: { supabase_user_id: user.id },
metadata: { user_id: user.id },
})
customerId = customer.id
@@ -43,16 +53,16 @@ export async function POST(request: Request) {
const session = await stripe.checkout.sessions.create({
customer: customerId,
mode: isLifetime ? "payment" : "subscription",
line_items: [{ price: planConfig.priceId, quantity: 1 }],
line_items: [{ price: priceId, quantity: 1 }],
success_url: `${appUrl}/settings/billing?success=true`,
cancel_url: `${appUrl}/settings/billing?canceled=true`,
metadata: {
supabase_user_id: user.id,
user_id: user.id,
plan: planConfig.plan,
},
...(isLifetime ? {} : {
subscription_data: {
metadata: { supabase_user_id: user.id, plan: planConfig.plan },
metadata: { user_id: user.id, plan: planConfig.plan },
},
}),
})