refactor(storefront): remove supabase shim and restore customer storefronts

The legacy src/lib/supabase.ts shim returned { data: null } for every
query, so 15+ pages were silently rendering empty state — including the
two customer-facing storefronts (tuxedo, indian-river-direct) and
several v1 admin pages. Replace every caller with canonical access:

- New src/actions/storefront.ts server-action module: brand lookup,
  public stops, active products, stop-by-slug, wholesale settings,
  portal config. Uses the shared pg Pool and SECURITY DEFINER RPCs.
- src/actions/brand-settings.ts: getBrandSettingsPublic inlined the
  brands + brand_settings LEFT JOIN wholesale_settings query (the
  RPC it called did not exist; try/catch was masking the failure).
- src/actions/ai/preferences.ts: switched get/saveAIPreferences to
  pool.query.
- src/actions/square-sync-ui.ts: new getSquareQueueCount action for
  SquareSyncWidget (replaces shim count).
- src/app/api/{tuxedo,indian-river-direct}/schedule-pdf/route.ts:
  use pool.query.
- next.config.ts: redirects /admin/{products/:id,reports,taxes,
  settings/{shipping,integrations,billing}} → their v2 / settings
  equivalents, then deleted those pages.
- Deleted src/lib/supabase.ts (no remaining imports).

Tests: 174/175 (unchanged from baseline; pre-existing getAdminUser
mock issue is tracked in Step 5).
This commit is contained in:
Nora
2026-06-25 17:12:28 -06:00
parent 9f3dc9b68e
commit 2daa8fd4b6
22 changed files with 241 additions and 1146 deletions
+27 -27
View File
@@ -1,44 +1,44 @@
import { NextResponse } from "next/server";
import { PDFDocument, rgb, StandardFonts } from "pdf-lib";
import { supabase } from "@/lib/supabase";
type Settings = {
logo_url: string | null;
contact_email: string | null;
contact_phone: string | null;
schedule_pdf_notes: string | null;
brand_name: string | null;
};
import { pool } from "@/lib/db";
export async function GET() {
const brandSlug = "tuxedo";
const { data: brand } = await supabase
.from("brands")
.select("id, name")
.eq("slug", brandSlug)
.single() as unknown as { data: { id: string; name: string } | null };
const { rows: brandRows } = await pool.query<{ id: string; name: string }>(
`SELECT id, name FROM brands WHERE slug = $1 LIMIT 1`,
[brandSlug],
);
const brand = brandRows[0];
if (!brand?.id) {
return new NextResponse("Brand not found", { status: 404 });
}
const { data: stops } = await supabase
.from("stops")
.select("city, state, date, time, location")
.eq("brand_id", brand.id)
.eq("active", true)
.order("date", { ascending: true }) as unknown as { data: { city: string; state: string; date: string; time: string; location: string }[] | null };
const { rows: stops } = await pool.query<{ city: string; state: string; date: string; time: string; location: string }>(
`SELECT city, state, date::text AS date, time, location
FROM stops
WHERE brand_id = $1 AND is_public = true AND status = 'active'
ORDER BY date ASC, time ASC`,
[brand.id],
);
const { data: settings } = await supabase
.from("brand_settings")
.select("logo_url, email, phone, schedule_pdf_notes")
.eq("brand_id", brand.id)
.single() as unknown as { data: { logo_url: string | null; email: string | null; phone: string | null; schedule_pdf_notes: string | null } | null };
const { rows: settingsRows } = await pool.query<{
logo_url: string | null;
email: string | null;
phone: string | null;
schedule_pdf_notes: string | null;
}>(
`SELECT logo_url, email, phone, schedule_pdf_notes
FROM brand_settings
WHERE brand_id = $1
LIMIT 1`,
[brand.id],
);
const settings = settingsRows[0] ?? null;
const pdfBytes = await buildProfessionalSchedulePdf({
brandName: brand.name,
stops: stops ?? [],
stops: stops,
logoUrl: settings?.logo_url ?? null,
contactEmail: settings?.email ?? null,
contactPhone: settings?.phone ?? null,