Compare commits

...
Author SHA1 Message Date
David Santos 3abd4ab804 hotfix(hub): preserve production drift — slimContext/context_data + resolve endpoints
Production CT225 has uncommitted changes not in master:
- recentErrors.ts: add slimContext() to trim large context_data blobs
  and expose context_data in the recent-errors response
- admin-ui resolve-by-pattern/route.ts: new endpoint
- admin-ui resolve-fixed-patterns/route.ts: new endpoint

This commit preserves the drift so it can be PR-reviewed and merged
over 7bc04e8 (PR20).

Paperclip-Issue: BIT-33338
2026-11-25 12:18:20 +00:00
3 changed files with 119 additions and 0 deletions

No files matched your search

@@ -0,0 +1,47 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim();
if (!rawBase) {
return NextResponse.json(
{
success: false,
message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.",
},
{ status: 503 },
);
}
const base = rawBase.replace(/\/$/, "");
const target = `${base}/api/error-monitoring/resolve-by-pattern`;
const body = await request.text();
const headers: Record<string, string> = {
Accept: "application/json",
"Content-Type": request.headers.get("Content-Type") ?? "application/json",
};
const cookie = request.headers.get("cookie");
if (cookie) {
headers.Cookie = cookie;
}
const resolveHdr = request.headers.get("x-error-resolve-key");
if (resolveHdr) {
headers["X-Error-Resolve-Key"] = resolveHdr;
}
const upstream = await fetch(target, {
method: "POST",
headers,
body: body || undefined,
cache: "no-store",
});
const text = await upstream.text();
const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8";
return new NextResponse(text, {
status: upstream.status,
headers: { "Content-Type": ct },
});
}
@@ -0,0 +1,47 @@
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export async function POST(request: NextRequest) {
const rawBase = process.env.ERROR_REPORTING_ADMIN_API_BASE?.trim();
if (!rawBase) {
return NextResponse.json(
{
success: false,
message: "ERROR_REPORTING_ADMIN_API_BASE is not configured.",
},
{ status: 503 },
);
}
const base = rawBase.replace(/\/$/, "");
const target = `${base}/api/error-monitoring/resolve-fixed-patterns`;
const body = await request.text();
const headers: Record<string, string> = {
Accept: "application/json",
"Content-Type": request.headers.get("Content-Type") ?? "application/json",
};
const cookie = request.headers.get("cookie");
if (cookie) {
headers.Cookie = cookie;
}
const resolveHdr = request.headers.get("x-error-resolve-key");
if (resolveHdr) {
headers["X-Error-Resolve-Key"] = resolveHdr;
}
const upstream = await fetch(target, {
method: "POST",
headers,
body: body || undefined,
cache: "no-store",
});
const text = await upstream.text();
const ct = upstream.headers.get("Content-Type") ?? "application/json; charset=utf-8";
return new NextResponse(text, {
status: upstream.status,
headers: { "Content-Type": ct },
});
}
+25
View File
@@ -100,6 +100,29 @@ function parseStatusList(raw: string | undefined): string[] | null {
return parts.length > 0 ? parts : ['open', 'investigating'];
}
function slimContext(ctx: Record<string, unknown> | null): Record<string, unknown> | null {
if (!ctx) return null;
const out: Record<string, unknown> = {};
for (const key of Object.keys(ctx).slice(0, 40)) out[key] = slimContextValue(ctx[key], 0);
return out;
}
function slimContextValue(value: unknown, depth: number): unknown {
if (depth > 3) return '[nested]';
if (typeof value === 'string') return value.length > 1500 ? `${value.slice(0, 1500)}…` : value;
if (value == null || typeof value === 'number' || typeof value === 'boolean') return value;
if (Array.isArray(value)) return value.slice(0, 20).map((item) => slimContextValue(item, depth + 1));
if (typeof value === 'object') {
const nested: Record<string, unknown> = {};
for (const [key, item] of Object.entries(value as Record<string, unknown>).slice(0, 30)) {
nested[key] = slimContextValue(item, depth + 1);
}
return nested;
}
return String(value).slice(0, 500);
}
async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply): Promise<void> {
const db = request.server.db;
@@ -303,6 +326,8 @@ async function handleRecentErrors(request: FastifyRequest, reply: FastifyReply):
if (paperclip_project_id !== '') {
rowOut.paperclip_project_id = paperclip_project_id;
}
const contextData = slimContext(ctx);
if (contextData) rowOut.context_data = contextData;
return rowOut;
});