feat: add guarded document workbench foundations
CI (SIAX Cloud) / integration (push) Skipped
CI (SIAX Cloud) / sonar (push) Skipped
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (push) Successful in 16s
CI (SIAX Cloud) / sonar (pull_request) Skipped
masterplan-lock / check (pull_request) Successful in 7s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Successful in 1m17s
CI (SIAX Cloud) / integration (pull_request) Successful in 54s
CI (SIAX Cloud) / quality (pull_request) Successful in 1m7s

This commit is contained in:
2026-11-02 01:26:36 +01:00
parent cb01f948eb
commit bd1c20edb2
34 changed files with 1992 additions and 19 deletions
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { parseBody, documentExtractionSchema } from "@/src/validation/0pt-schemas";
import { documentExtractionService } from "@/src/services/document-extraction-service";
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
import { assertTenantMatchesVerified, resolveDocumentActor } from "@/src/http/tenant-guard";
export async function POST(request: NextRequest, { params }: { params: Promise<{ documentId: string }> }) {
try {
@@ -14,11 +14,16 @@ export async function POST(request: NextRequest, { params }: { params: Promise<{
const body = __parsed.data;
const tenantGuard = assertTenantMatchesVerified(request, body.tenant_id);
if (tenantGuard) return tenantGuard;
const actor = resolveDocumentActor(request, body.actor_id);
if (actor.response) return actor.response;
if (!actor.actorId || !body.model_id) {
return NextResponse.json({ error: "actor and model_id are required" }, { status: 400 });
}
const result = await documentExtractionService.extractDocument(documentId, {
tenant_id: body.tenant_id,
project_id: body.project_id,
actor_id: body.actor_id,
correlation_id: body.correlation_id,
actor_id: actor.actorId,
correlation_id: body.correlation_id ?? crypto.randomUUID(),
model_id: body.model_id,
});
return NextResponse.json(result, { status: 201 });
+6 -12
View File
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { parseBody, documentCaptureSchema } from "@/src/validation/0pt-schemas";
import { documentCaptureService } from "@/src/services/document-capture-service";
import { assertTenantMatchesVerified } from "@/src/http/tenant-guard";
import { assertTenantMatchesVerified, resolveDocumentActor } from "@/src/http/tenant-guard";
export async function POST(request: NextRequest) {
try {
@@ -13,6 +13,8 @@ export async function POST(request: NextRequest) {
const body = __parsed.data;
const tenantGuard = assertTenantMatchesVerified(request, body.tenant_id);
if (tenantGuard) return tenantGuard;
const actor = resolveDocumentActor(request, body.actor_id);
if (actor.response) return actor.response;
const result = await documentCaptureService.captureFromMailbox(
{
mailbox: {
@@ -29,17 +31,9 @@ export async function POST(request: NextRequest) {
{
tenant_id: body.tenant_id,
project_id: body.project_id,
// documentCaptureSchema types these optional (pre-existing, listed
// among package.json's "9 pre-existing errors ... Wave 2 Zod
// schemas type fields as plain string while the services want
// narrower unions" -- deliberately left to its own change, not
// widened here). CaptureMailboxContext requires actor_id as a
// non-empty string and captureFromMailbox already throws a clear
// "missing tenant_id/project_id/actor_id" error when it's falsy, so
// `?? ""` changes no runtime behavior -- it only satisfies the type
// checker, which previously never saw this file (nothing under
// tests/ imported it before P014's cross-tenant regression tests).
actor_id: body.actor_id ?? "",
// In enforced mode middleware supplies the verified subject; the
// body can only agree with it. Development retains the old fallback.
actor_id: actor.actorId ?? "",
correlation_id: body.correlation_id ?? "",
},
);