Initial working state: CL3.5 complete (Plesk sync + suspend/unsuspend)

This commit is contained in:
2026-03-05 06:47:43 +00:00
commit a36d55eae5
53 changed files with 9925 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { assertAgencyAdmin, getRouteAgencyContextOrThrow } from "@/lib/agency";
import { assertRateLimit } from "@/lib/api/rate-limit";
import { assertSameOrigin } from "@/lib/api/security";
import { syncPleskInstance } from "@/lib/plesk/sync";
import { createSupabaseRouteClient } from "@/lib/supabase/route";
const syncSchema = z.object({
instanceId: z.string().uuid(),
});
export async function POST(req: Request) {
try {
assertSameOrigin(req);
const context = await getRouteAgencyContextOrThrow();
assertAgencyAdmin(context);
assertRateLimit(`plesk-sync:${context.userId}`, 8, 60_000);
const payload = syncSchema.parse(await req.json());
const supabase = createSupabaseRouteClient() as any;
const {
data: { user },
} = await supabase.auth.getUser();
console.log("SYNC USER:", user?.id, user?.email);
const { data: instance, error: instanceError } = await supabase
.from("plesk_instances")
.select(
"id, agency_id, base_url, auth_type, encrypted_secret, last_connected_at",
)
.eq("id", payload.instanceId)
.eq("agency_id", context.agencyId)
.single();
if (instanceError || !instance) throw new Error("Plesk instance not found");
const result = await syncPleskInstance(
supabase,
instance,
context.userId,
"sync",
);
return NextResponse.json({
subscriptionsUpserted: result.subscriptionsUpserted,
domainsUpserted: result.domainsUpserted,
skipped: result.skipped,
reason: result.reason,
});
} catch (error) {
return NextResponse.json(
{ error: error instanceof Error ? error.message : "Sync failed" },
{ status: 400 },
);
}
}