merge: unify GitHub main into Gitea main (0pt)
Merges github/main (6 commits: 17-bug audit fix, CI quality gate,
.env.example + .gitignore fix, missing platform clients + registry
services, docs accuracy overhaul) into gitea/main (8 commits: Iceberg
write boundary + live ST0RE verification, lakehouse mapping routes,
Waves 1-4 foundational hardening).
16 conflicts. Both sides had independently written the four
src/clients/*.ts and the two registry services, so those are combined
rather than picked:
- st0re-client.ts: GitHub's endpoint wins on evidence. POST goes to
/v1/st0re/artifacts/register, not /v1/st0re/artifacts -- verified in
sax3l/st0re src/api/routes/artifacts.ts, where the bare path is a
GET-only list route. Gitea's URL normalisation, error-body text and
mock kept.
- n0d-client.ts: field is `status`, not `state`, with N0D's real 13-state
union -- verified in sax3l/n0d packages/schemas/n0d.job.schema.json,
which says explicitly not to add "succeeded". Gitea's mock echo,
URL normalisation and error-body text kept.
- cl0ud-client.ts: Gitea's fail-closed HTTP normalisation kept (a 200
with no `decision` reads as "deny", not as a silent allow). GitHub's
PolicyDecision/PolicyDecisionValue naming kept; PolicyResult retained
as an alias.
- aud0-client.ts: permissive union of both input types (optional
payload/metadata/correlation_id), GitHub's echo return, Gitea's URL
normalisation and error-body text, plus a JSON-parse fallback so a
successful POST with an empty body does not throw.
- dataset-service.ts / source-service.ts: GitHub's record/DTO split and
event naming (0pt.source_created / 0pt.create_source, which the merged
docs already reference) plus Gitea's name validation, description /
created_by fields and actor_id derivation. List filters are the union.
- lakehouse mapping routes: GitHub's shared lakehouse-mapping-registry
singletons (without which every write 400'd "mapping not found") AND
Gitea's Zod parseBody validation. Both, not either.
- src/types/source.ts, src/types/dataset.ts: unions of both vocabularies;
GitHub's `access` legal-sourcing field kept.
- .env.example: GitHub's audited inventory plus Gitea's Zitadel /
AUTH_ENFORCE block.
- CLAUDE.md, docs/ICEBERG_WRITE_BOUNDARY.md: GitHub's corrections kept,
Gitea's live-verification kept and marked as superseding the
"would 400 outright" finding (Gitea had already added the required
X-Tenant-Id/X-Actor-Id headers).
- pnpm-lock.yaml: regenerated with pnpm 9.15.9, not merged.
Also corrects CLAUDE.md's claim that the banned services/scrapers stack
was "since removed" -- the removal PR is open, not merged, and this
branch inherits that code from Gitea main. Nothing here resurrects,
extends or re-wires any of it; services/scrapers/ is byte-identical to
Gitea main.
Verified on the merged tree: typecheck (src/ + tests/) clean;
17 test files, 121 passed, 1 skipped (the realinfra test skipping
honestly on ST0RE HTTP 401), 0 failures. Gitea main baseline was the
same 121/1; GitHub main baseline could not even `pnpm install`
("packages field missing or empty") -- Gitea's pnpm-workspace.yaml fix
resolves that. Whole-repo `typecheck:app` reports 9 errors, an identical
set to Gitea main's baseline, so it is advisory in both CI workflows
rather than deleted. Lint: 16 problems, identical to Gitea baseline.
Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5
commit
bcf285f057
@@ -21,7 +21,17 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
|
||||
return NextResponse.json(result, { status: 201 });
|
||||
} catch (error: unknown) {
|
||||
const message = error instanceof Error ? error.message : "Unknown error";
|
||||
return NextResponse.json({ error: message }, { status: 400 });
|
||||
if (/not configured/i.test(message)) {
|
||||
return NextResponse.json({ error: message }, { status: 501 });
|
||||
}
|
||||
if (/^Policy denied/i.test(message)) {
|
||||
return NextResponse.json({ error: message }, { status: 403 });
|
||||
}
|
||||
if (/^Policy requires approval/i.test(message)) {
|
||||
return NextResponse.json({ error: message }, { status: 409 });
|
||||
}
|
||||
const status = /not found/i.test(message) ? 404 : 400;
|
||||
return NextResponse.json({ error: message }, { status });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { DatasetIcebergMappingService } from "@/src/services/dataset-iceberg-mapping-service";
|
||||
|
||||
const mappingService = new DatasetIcebergMappingService();
|
||||
import { mappingService } from "@/src/services/lakehouse-mapping-registry";
|
||||
|
||||
export async function GET(_request: Request, { params }: { params: Promise<{ mappingId: string }> }) {
|
||||
try {
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, requestIcebergWriteSchema } from "@/src/validation/0pt-schemas";
|
||||
import { IcebergWriteService } from "@/src/services/iceberg-write-service";
|
||||
|
||||
const writeService = new IcebergWriteService();
|
||||
import { writeService } from "@/src/services/lakehouse-mapping-registry";
|
||||
|
||||
// Registers a new Iceberg snapshot (a write) through ST0RE's table registry
|
||||
// for an already-mapped dataset. See docs/ICEBERG_WRITE_BOUNDARY.md.
|
||||
//
|
||||
// `writeService` is the SHARED instance from
|
||||
// src/services/lakehouse-mapping-registry.ts -- this route used to construct
|
||||
// its own `new IcebergWriteService()`, which held a private in-memory mapping
|
||||
// registry, so a mapping created via POST /lakehouse/mappings was never
|
||||
// visible here and every write failed with "mapping not found".
|
||||
//
|
||||
// The body is validated against requestIcebergWriteSchema before it reaches
|
||||
// the service (Wave 2 hardening).
|
||||
export async function POST(request: NextRequest, { params }: { params: Promise<{ mappingId: string }> }) {
|
||||
try {
|
||||
const { mappingId } = await params;
|
||||
|
||||
@@ -1,20 +1,25 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { parseBody, mapDatasetToIcebergTableSchema } from "@/src/validation/0pt-schemas";
|
||||
import { IcebergWriteService } from "@/src/services/iceberg-write-service";
|
||||
import { DatasetIcebergMappingService } from "@/src/services/dataset-iceberg-mapping-service";
|
||||
import { mappingService, writeService } from "@/src/services/lakehouse-mapping-registry";
|
||||
|
||||
// Shared instances so a mapping created via POST is visible to a later GET
|
||||
// within the same server process, matching the in-memory-per-module
|
||||
// convention already used by app/api/0pt/datasets and app/api/0pt/quality
|
||||
// (Postgres persistence exists in sql/ but is not wired into route handlers
|
||||
// in this pass -- same limitation those routes already have).
|
||||
const mappingService = new DatasetIcebergMappingService();
|
||||
const writeService = new IcebergWriteService({ mappingService });
|
||||
// Shared instances come from src/services/lakehouse-mapping-registry.ts so a
|
||||
// mapping created via POST is visible to a later GET, AND to the sibling
|
||||
// /{mappingId}/writes route, within the same server process. (Each route file
|
||||
// previously constructed its own DatasetIcebergMappingService/
|
||||
// IcebergWriteService, so a mapping created here was invisible to the writes
|
||||
// route -- every write failed with "mapping not found".) This still matches the
|
||||
// in-memory-per-module convention app/api/0pt/datasets and app/api/0pt/quality
|
||||
// use; Postgres persistence exists in sql/ but is not wired into route handlers
|
||||
// in this pass -- same limitation those routes already have.
|
||||
|
||||
// POST registers a NEW Iceberg table in ST0RE's table registry (via
|
||||
// IcebergWriteService.mapDatasetToIcebergTable) and records the
|
||||
// dataset_iceberg_mapping row that points at it -- this is 0pt's write-path
|
||||
// entrypoint, see docs/ICEBERG_WRITE_BOUNDARY.md.
|
||||
//
|
||||
// The body is validated against mapDatasetToIcebergTableSchema BEFORE it
|
||||
// reaches the service (Wave 2 hardening): an unvalidated request body used to
|
||||
// be passed straight into the capability call.
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const __raw = await request.json();
|
||||
|
||||
@@ -10,8 +10,13 @@
|
||||
* is not shared across route modules yet — see the "Singleton note" in
|
||||
* src/services/document-capture-service.ts for prior art on this same repo
|
||||
* limitation). A source registered via POST /api/0pt/sources will not be
|
||||
* resolvable here until SourceService is backed by shared persistence
|
||||
* (sql/002_p0_dataset_quality.sql already defines `opt_sources` for that).
|
||||
* resolvable here until SourceService is backed by shared persistence.
|
||||
* Correction: this comment previously claimed `sql/002_p0_dataset_quality.sql`
|
||||
* already defined an `opt_sources` table for that. That file does not exist
|
||||
* and never has (git log --all: zero commits, any branch, ever). sql/ today
|
||||
* has only 001_init.sql and 004_iceberg_write_boundary.sql. The real fix —
|
||||
* backing SourceService with real persistence — is still open; no migration
|
||||
* for it exists yet.
|
||||
* Details: docs/P0_QUERY_SOURCE_FLOW.md.
|
||||
*/
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
@@ -24,7 +24,9 @@ const DEST: [RegExp, string][] = [
|
||||
];
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const { text } = await req.json().catch(() => ({ text: "" }));
|
||||
const parsed = await req.json().catch(() => ({ text: "" }));
|
||||
const body = parsed && typeof parsed === "object" ? parsed : { text: "" };
|
||||
const { text } = body as { text?: string };
|
||||
if (!text) return NextResponse.json({ error: { code: "bad_request", message: "text krävs" } }, { status: 400 });
|
||||
|
||||
const eng = await engineFetch("/ai/parse", { method: "POST", body: JSON.stringify({ text }) });
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { timingSafeEqual } from "node:crypto";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { signSession, SESSION_COOKIE } from "@/lib/auth";
|
||||
|
||||
@@ -9,7 +10,13 @@ export async function POST(req: NextRequest) {
|
||||
return NextResponse.json({ error: { code: "auth_not_configured", message: "AUTH_SECRET saknas" } }, { status: 501 });
|
||||
}
|
||||
const devKey = process.env.DEV_LOGIN_KEY;
|
||||
if (!devKey || key !== devKey) {
|
||||
// Constant-time compare: a plain !== leaks the number of matching leading
|
||||
// bytes via response timing, letting an attacker recover DEV_LOGIN_KEY
|
||||
// byte-by-byte instead of it being an all-or-nothing guess.
|
||||
const keyBuf = Buffer.from(typeof key === "string" ? key : "");
|
||||
const devKeyBuf = Buffer.from(devKey ?? "");
|
||||
const keysMatch = Boolean(devKey) && keyBuf.length === devKeyBuf.length && timingSafeEqual(keyBuf, devKeyBuf);
|
||||
if (!keysMatch) {
|
||||
return NextResponse.json({ error: { code: "forbidden", message: "Dev-login kräver giltig nyckel" } }, { status: 403 });
|
||||
}
|
||||
if (!email) {
|
||||
|
||||
@@ -11,6 +11,9 @@ export async function POST(req: NextRequest) {
|
||||
} catch {
|
||||
return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON body" } }, { status: 400 });
|
||||
}
|
||||
if (!body || typeof body !== "object") {
|
||||
return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON body" } }, { status: 400 });
|
||||
}
|
||||
|
||||
// Defer to the FastAPI data engine when it's running; fall back to local math.
|
||||
const eng = await engineFetch("/estimates", { method: "POST", body: JSON.stringify(body) });
|
||||
|
||||
@@ -19,6 +19,9 @@ export async function PATCH(req: NextRequest, ctx: { params: Promise<{ id: strin
|
||||
} catch {
|
||||
return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON" } }, { status: 400 });
|
||||
}
|
||||
if (!body || typeof body !== "object") {
|
||||
return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON body" } }, { status: 400 });
|
||||
}
|
||||
const allowed = ["draft", "quoted", "deposit_pending", "in_production", "review", "revision", "accepted", "delivered"];
|
||||
if (!body.status || !allowed.includes(body.status)) {
|
||||
return NextResponse.json({ error: { code: "bad_status", message: "Ogiltig status" } }, { status: 400 });
|
||||
|
||||
@@ -9,6 +9,9 @@ export async function POST(req: NextRequest) {
|
||||
} catch {
|
||||
return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON" } }, { status: 400 });
|
||||
}
|
||||
if (!body || typeof body !== "object") {
|
||||
return NextResponse.json({ error: { code: "bad_json", message: "Invalid JSON body" } }, { status: 400 });
|
||||
}
|
||||
const flow = body.flow || "custom";
|
||||
const config = body.config || {};
|
||||
const order = await createOrder(flow, config);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { getOrder } from "@/lib/orders-store";
|
||||
|
||||
// POST /api/payments/[order_id]/deposit
|
||||
// Returns { url } for Stripe Checkout. Returns 501 when STRIPE_SECRET_KEY is absent.
|
||||
@@ -13,19 +14,15 @@ export async function POST(
|
||||
return NextResponse.json({ error: "payment_not_configured" }, { status: 501 });
|
||||
}
|
||||
|
||||
const origin =
|
||||
request.headers.get("origin") ??
|
||||
process.env.NEXT_PUBLIC_APP_URL ??
|
||||
"http://localhost:3000";
|
||||
// Never derive from the client-supplied Origin header (SSRF + open-redirect vector) —
|
||||
// request.nextUrl.origin reflects the actual request URL, not attacker-controlled input.
|
||||
const origin = request.nextUrl.origin;
|
||||
|
||||
let depositOre = 44750;
|
||||
try {
|
||||
const orderRes = await fetch(`${origin}/api/orders/${order_id}`);
|
||||
if (orderRes.ok) {
|
||||
const order = (await orderRes.json()) as { deposit_ore?: number; total_ore?: number };
|
||||
depositOre = order.deposit_ore ?? Math.round((order.total_ore ?? 89500) / 2);
|
||||
}
|
||||
} catch {}
|
||||
const order = await getOrder(order_id);
|
||||
if (!order) {
|
||||
return NextResponse.json({ error: { code: "not_found", message: "Order saknas" } }, { status: 404 });
|
||||
}
|
||||
const depositOre = order.deposit_ore ?? Math.round((order.total_ore ?? 89500) / 2);
|
||||
|
||||
const body = new URLSearchParams({
|
||||
"payment_method_types[0]": "card",
|
||||
|
||||
@@ -7,7 +7,8 @@ export async function GET() {
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const parsed = await req.json().catch(() => ({}));
|
||||
const body = parsed && typeof parsed === "object" ? parsed : {};
|
||||
if (!body.order_id) {
|
||||
return NextResponse.json({ error: { code: "bad_request", message: "order_id krävs" } }, { status: 400 });
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// GET /api/uploads — list uploaded files. Returns 501 until storage is configured.
|
||||
export async function GET() {
|
||||
@@ -10,9 +10,10 @@ export async function GET() {
|
||||
}
|
||||
|
||||
// POST /api/uploads (docs/04) — issue a presigned R2 PUT URL. Env-guarded:
|
||||
// returns 501 until R2 storage is configured. Client then PUTs the file directly.
|
||||
export async function POST(req: NextRequest) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
// returns 501 until R2 storage is configured, and until presign generation
|
||||
// is implemented — a configured-but-unimplemented state must not report
|
||||
// success. Client then PUTs the file directly.
|
||||
export async function POST() {
|
||||
const haveR2 = process.env.R2_ACCESS_KEY_ID && process.env.R2_BUCKET && process.env.R2_ENDPOINT;
|
||||
if (!haveR2) {
|
||||
return NextResponse.json(
|
||||
@@ -20,6 +21,10 @@ export async function POST(req: NextRequest) {
|
||||
{ status: 501 },
|
||||
);
|
||||
}
|
||||
// With R2 configured: build a presigned PUT (S3-compatible) and return it.
|
||||
return NextResponse.json({ file_id: crypto.randomUUID(), put_url: null, name: body?.name ?? null });
|
||||
// TODO: presigned PUT generation not implemented yet — keep returning 501
|
||||
// instead of a fake 200/null success shape until real R2 presign wiring exists.
|
||||
return NextResponse.json(
|
||||
{ error: { code: "storage_not_configured", message: "Presignerad uppladdning är inte implementerad än" } },
|
||||
{ status: 501 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@ import { engineFetch } from "@/lib/engine";
|
||||
// GET /api/vehicles?plate=XX-99-YY — RDW (NL) open vehicle data (technical/fleet
|
||||
// only, no owner PII). Defers to the engine when running; else calls RDW directly.
|
||||
export async function GET(req: NextRequest) {
|
||||
const plate = (req.nextUrl.searchParams.get("plate") ?? "").toUpperCase().replace(/[-\s]/g, "");
|
||||
const plate = (req.nextUrl.searchParams.get("plate") ?? "").toUpperCase().replace(/[-\s]/g, "").replace(/[^A-Z0-9]/g, "");
|
||||
if (!plate) return NextResponse.json({ error: { code: "bad_request", message: "plate krävs" } }, { status: 400 });
|
||||
|
||||
const eng = await engineFetch(`/vehicles/${plate}`);
|
||||
if (eng && eng.ok) return NextResponse.json(await eng.json());
|
||||
|
||||
try {
|
||||
const r = await fetch(`https://opendata.rdw.nl/resource/m9d7-ebf2.json?kenteken=${plate}`, {
|
||||
const r = await fetch(`https://opendata.rdw.nl/resource/m9d7-ebf2.json?kenteken=${encodeURIComponent(plate)}`, {
|
||||
headers: { "User-Agent": "0pt/0.1 (+https://0pt.app; SIAX)" },
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user