Implementa o MVP do Adaptador de Planilhas no Elo Pro.

O módulo usa a identidade Supabase, isola cada workspace e registra storage, TTL, runner e biblioteca XLSX como decisões ainda abertas.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
camilafagundesandCursor committed 2026-10-02 23:02:00 -03:00
commit 6e23f1533b
144 files changed
+19060

No files matched your search

@@ -0,0 +1,31 @@
import { NextResponse } from "next/server";
import { errorResponse, requireReady } from "../../../_lib";
import { downloadOutput } from "@/server/spreadsheet-adapter/process-job";
import type { OutputFormat } from "@/domain/spreadsheet-adapter/types";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET(request: Request, context: { params: Promise<{ id: string }> }) {
try {
const { ctx, deps } = await requireReady();
const { id } = await context.params;
const url = new URL(request.url);
const format = url.searchParams.get("format") as OutputFormat | null;
const sourceId = url.searchParams.get("sourceId");
if (!sourceId || (format !== "xlsx" && format !== "csv" && format !== "pdf")) {
return NextResponse.json({ error: { code: "INVALID_FORMAT", message: "Escolha XLSX, CSV ou PDF." } }, { status: 400 });
}
const file = await downloadOutput(deps, ctx, id, sourceId, format);
return new NextResponse(new Uint8Array(file.body), {
headers: {
"Content-Type": file.contentType,
"Content-Disposition": `attachment; filename="${file.filename}"`,
"Cache-Control": "no-store",
"X-Content-Type-Options": "nosniff",
},
});
} catch (error) {
return errorResponse(error);
}
}
@@ -0,0 +1,22 @@
import { NextResponse } from "next/server";
import { errorResponse, requireReady } from "../../../_lib";
import { rejectWorkspaceForgery, saveMappings } from "@/server/spreadsheet-adapter/service";
import type { MappingInput } from "@/server/spreadsheet-adapter/dto";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function PUT(request: Request, context: { params: Promise<{ id: string }> }) {
try {
const { ctx, deps } = await requireReady();
const { id } = await context.params;
const body = (await request.json()) as { sourceId?: string; mappings?: MappingInput[]; workspace_id?: string };
await rejectWorkspaceForgery(deps, ctx, body.workspace_id);
if (!body.sourceId || !Array.isArray(body.mappings)) {
return NextResponse.json({ error: { code: "MAPPING_INCOMPLETE", message: "Informe o mapeamento." } }, { status: 400 });
}
return NextResponse.json({ job: await saveMappings(deps, ctx, id, body.sourceId, body.mappings) });
} catch (error) {
return errorResponse(error);
}
}
@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";
import { errorResponse, requireReady } from "../../../_lib";
import { previewSource, rejectWorkspaceForgery } from "@/server/spreadsheet-adapter/service";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(request: Request, context: { params: Promise<{ id: string }> }) {
try {
const { ctx, deps } = await requireReady();
const { id } = await context.params;
const body = (await request.json()) as { sourceId?: string; workspace_id?: string };
await rejectWorkspaceForgery(deps, ctx, body.workspace_id);
if (!body.sourceId) return NextResponse.json({ error: { code: "NOT_FOUND", message: "Informe a fonte." } }, { status: 400 });
return NextResponse.json(await previewSource(deps, ctx, id, body.sourceId));
} catch (error) {
return errorResponse(error);
}
}
@@ -0,0 +1,22 @@
import { NextResponse } from "next/server";
import { errorResponse, requireReady } from "../../../_lib";
import { rejectWorkspaceForgery, startProcess } from "@/server/spreadsheet-adapter/service";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(request: Request, context: { params: Promise<{ id: string }> }) {
try {
const { ctx, deps } = await requireReady();
const { id } = await context.params;
const body = (await request.json()) as { sourceId?: string; idempotencyKey?: string; workspace_id?: string };
await rejectWorkspaceForgery(deps, ctx, body.workspace_id);
if (!body.sourceId || !body.idempotencyKey) {
return NextResponse.json({ error: { code: "IDEMPOTENCY_REQUIRED", message: "Informe a fonte e a chave de idempotência." } }, { status: 400 });
}
const job = await startProcess(deps, ctx, id, body.sourceId, body.idempotencyKey);
return NextResponse.json({ job });
} catch (error) {
return errorResponse(error);
}
}
@@ -0,0 +1,16 @@
import { NextResponse } from "next/server";
import { errorResponse, requireReady } from "../../_lib";
import { getJob } from "@/server/spreadsheet-adapter/service";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function GET(_request: Request, context: { params: Promise<{ id: string }> }) {
try {
const { ctx, deps } = await requireReady();
const { id } = await context.params;
return NextResponse.json({ job: await getJob(deps, ctx, id) });
} catch (error) {
return errorResponse(error);
}
}
@@ -0,0 +1,31 @@
import { NextResponse } from "next/server";
import { errorResponse, requireReady } from "../../../../_lib";
import { rejectWorkspaceForgery, removeSource, updateSource } from "@/server/spreadsheet-adapter/service";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function PATCH(request: Request, context: { params: Promise<{ id: string; sourceId: string }> }) {
try {
const { ctx, deps } = await requireReady();
const { id, sourceId } = await context.params;
const body = (await request.json()) as { sheet?: string | null; headerRow?: number; workspace_id?: string };
await rejectWorkspaceForgery(deps, ctx, body.workspace_id);
const result = await updateSource(deps, ctx, id, sourceId, { sheet: body.sheet, headerRow: body.headerRow });
return NextResponse.json(result, { status: result.httpStatus });
} catch (error) {
return errorResponse(error);
}
}
export async function DELETE(request: Request, context: { params: Promise<{ id: string; sourceId: string }> }) {
try {
const { ctx, deps } = await requireReady();
const { id, sourceId } = await context.params;
const body = await request.json().catch(() => ({}));
await rejectWorkspaceForgery(deps, ctx, (body as { workspace_id?: string }).workspace_id);
return NextResponse.json({ job: await removeSource(deps, ctx, id, sourceId) });
} catch (error) {
return errorResponse(error);
}
}
@@ -0,0 +1,19 @@
import { NextResponse } from "next/server";
import { errorResponse, requireReady } from "../_lib";
import { createJob, rejectWorkspaceForgery } from "@/server/spreadsheet-adapter/service";
export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export async function POST(request: Request) {
try {
const { ctx, deps } = await requireReady();
const body = (await request.json()) as { modelId?: string; idempotencyKey?: string; workspace_id?: string };
await rejectWorkspaceForgery(deps, ctx, body.workspace_id);
if (!body.modelId) return NextResponse.json({ error: { code: "NOT_FOUND", message: "Selecione um modelo." } }, { status: 400 });
const job = await createJob(deps, ctx, body.modelId, body.idempotencyKey);
return NextResponse.json({ job }, { status: 201 });
} catch (error) {
return errorResponse(error);
}
}