Rewrite Next.js local BFF routes and mock catalog.
Projects, report, and graph JSON handlers overlay from periscope/src. Clerk proxy stays the inherited open-core seam.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
const SIBLING_ROOT = path.resolve(process.cwd(), "..");
|
||||
|
||||
function safeSegment(id: string): string | null {
|
||||
if (!id || id.includes("/") || id.includes("\\") || id === "." || id === "..") {
|
||||
return null;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
export async function jsonFromProjectFile(
|
||||
id: string,
|
||||
filename: string,
|
||||
missing: string,
|
||||
): Promise<NextResponse> {
|
||||
const projectId = safeSegment(id);
|
||||
if (!projectId) {
|
||||
return NextResponse.json({ error: missing }, { status: 404 });
|
||||
}
|
||||
const filePath = path.join(SIBLING_ROOT, projectId, filename);
|
||||
try {
|
||||
const raw = await readFile(filePath, "utf-8");
|
||||
return NextResponse.json(JSON.parse(raw) as unknown);
|
||||
} catch {
|
||||
return NextResponse.json({ error: missing }, { status: 404 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { jsonFromProjectFile } from "../../_project-json";
|
||||
|
||||
export async function GET(
|
||||
_req: Request,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
return jsonFromProjectFile(id, "design_graph.json", "Graph not found");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { PROJECTS } from "@/lib/mock-data";
|
||||
|
||||
export async function GET() {
|
||||
return NextResponse.json(PROJECTS);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { jsonFromProjectFile } from "../../_project-json";
|
||||
|
||||
export async function GET(
|
||||
_req: Request,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const { id } = await params;
|
||||
return jsonFromProjectFile(id, "report.json", "Report not found");
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import type { PipelineStep, Project } from "./types";
|
||||
|
||||
/** Demo row for the local Next BFF when the FastAPI catalog is not in front. */
|
||||
export const PROJECTS: Project[] = [
|
||||
{
|
||||
id: "simple_project",
|
||||
name: "TI MSP Tutorial Board",
|
||||
created: "2026-04-09T00:00:00Z",
|
||||
status: "complete",
|
||||
summary: { total: 8, ERROR: 2, WARNING: 4, INFO: 2 },
|
||||
hasNetlist: true,
|
||||
hasBom: true,
|
||||
datasheetCount: 3,
|
||||
},
|
||||
];
|
||||
|
||||
function pending(title: string, description: string, substeps: PipelineStep["substeps"]): PipelineStep {
|
||||
return { title, description, status: "pending", substeps };
|
||||
}
|
||||
|
||||
function pendingItem(key: string, label: string) {
|
||||
return { key, label, status: "pending" as const };
|
||||
}
|
||||
|
||||
export function createPipelineSteps(): PipelineStep[] {
|
||||
return [
|
||||
pending("IC Datasheet Extraction", "Parse component datasheets and extract constraints", [
|
||||
pendingItem("SPX3819M5-L-3-3/TR", "SPX3819M5-L-3-3/TR (U1)"),
|
||||
pendingItem("CH340E", "CH340E (U2)"),
|
||||
pendingItem("MSPM0G3507SPTR", "MSPM0G3507SPTR (U3)"),
|
||||
]),
|
||||
pending("Passive Pattern Extraction", "Resolve passive component values from MPN patterns", [
|
||||
pendingItem("samsung", "Samsung capacitors"),
|
||||
pendingItem("uniroyal", "Uniroyal resistors"),
|
||||
]),
|
||||
pending("Build Design Graph", "Parse BOM and netlist into structured graph", [
|
||||
pendingItem("parse-bom", "Parse BOM (17 components)"),
|
||||
pendingItem("parse-netlist", "Parse netlist (36 nets)"),
|
||||
pendingItem("enrich", "Enrich with datasheet data"),
|
||||
]),
|
||||
pending("Review Design", "Review each IC against its datasheet", [
|
||||
pendingItem("U1", "Review U1 — LDO"),
|
||||
pendingItem("U2", "Review U2 — USB Bridge"),
|
||||
pendingItem("U3", "Review U3 — MCU"),
|
||||
]),
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user