import { a as cleanup, g as getDecision, s as setDecision } from './pending-requests-D8UiTw7L.js';
import { v as validateAuth } from './auth-DuunT7Cg.js';
import { t as toErrorMessage } from './error-DDXB3duW.js';
import { j as json } from './index-CoD1IJuy.js';
import './shared-server-DaWdgxVh.js';
import 'crypto';

const POST = async ({ request }) => {
  cleanup();
  const authError = validateAuth(request);
  if (authError) {
    return authError;
  }
  let body;
  try {
    body = await request.json();
  } catch {
    return json({ error: "Invalid JSON in request body" }, { status: 400 });
  }
  try {
    const { decision, requestId } = body;
    if (!requestId || !decision) {
      return json({ error: "requestId and decision are required" }, { status: 400 });
    }
    if (decision !== "allow" && decision !== "deny") {
      return json({ error: 'decision must be "allow" or "deny"' }, { status: 400 });
    }
    const found = setDecision(requestId, decision);
    if (!found) {
      return json({ error: "Request not found or expired" }, { status: 404 });
    }
    console.log(`[response] Decision received: ${decision} for request ${requestId}`);
    return json({
      message: "Decision recorded",
      success: true,
      timestamp: (/* @__PURE__ */ new Date()).toISOString()
    });
  } catch (error) {
    console.error("[response] Failed to process response:", toErrorMessage(error));
    return json({ error: "Failed to process response" }, { status: 500 });
  }
};
const GET = ({ request, url }) => {
  cleanup();
  const authErr = validateAuth(request);
  if (authErr) {
    return authErr;
  }
  const requestId = url.searchParams.get("requestId");
  if (!requestId) {
    return json({ error: "requestId query parameter is required" }, { status: 400 });
  }
  const result = getDecision(requestId);
  if (result.status === "not_found") {
    return json({ error: "Request not found or expired" }, { status: 404 });
  }
  return json({
    decision: result.decision ?? null,
    status: result.status,
    timestamp: (/* @__PURE__ */ new Date()).toISOString()
  });
};

export { GET, POST };
//# sourceMappingURL=_server.ts-DkPPTUPo.js.map
