Brand Studio docs
Engineering manualAPI route source

/api/brands/review-watch/sweep

Exact current route handler: hosted-app/app/api/brands/review-watch/sweep/route.js

Methods: GET, POST. Input signals: none detected. Literal response-status signals: 200.

Source: hosted-app/app/api/brands/review-watch/sweep/route.js. Imports: ../../../../../lib/local/url-safety.mjs, ../../../../../lib/monitoring-sweep.mjs, ../../../../../lib/review-watches.mjs, ../../../../../lib/social-watches.mjs, ../../../../../lib/supabase-rest.mjs, next/server. Exact source is shown for inspection; its presence does not prove authentication, validation or live behavior.

All API routes · API and execution contract

import { runMonitoringSweep } from "../../../../../lib/monitoring-sweep.mjs";
import { NextResponse } from "next/server";
import { supabaseConfigFromEnv } from "../../../../../lib/supabase-rest.mjs";
import { assertPublicHttpTarget } from "../../../../../lib/local/url-safety.mjs";
import { scheduledReportStarter } from "../../../../../lib/social-watches.mjs";
import { runDueReviewChecks } from "../../../../../lib/review-watches.mjs";

export const runtime = "nodejs";
export const dynamic = "force-dynamic";
export const maxDuration = 60;

const authorizeSweep = (request, env) => {
  const queueSecret = env.BRAND_STUDIO_QUEUE_SECRET || "";
  const cronSecret = env.CRON_SECRET || "";
  if (!queueSecret && !cronSecret) return { ok: false, http_status: 503, reason: "no_queue_secret_configured" };
  const provided = request.headers.get("x-queue-secret") || "";
  if (queueSecret && provided && provided === queueSecret) return { ok: true, via: "queue_secret" };
  const authorization = request.headers.get("authorization") || "";
  if (cronSecret && authorization === "Bearer " + cronSecret) return { ok: true, via: "vercel_cron" };
  return { ok: false, http_status: 401, reason: "unauthorized" };
};

const sweep = async (request) => {
  const env = process.env;
  const auth = authorizeSweep(request, env);
  const headers = { "cache-control": "no-store" };
  if (!auth.ok) return NextResponse.json({ status: "refused", reason: auth.reason }, { status: auth.http_status, headers });
  const config = supabaseConfigFromEnv(env);
  const result = await runMonitoringSweep({ lane: "review", config, holder: "sweep-" + auth.via, run: () => env.BRAND_STUDIO_REVIEW_CHECKS === "off" ? ({ status: "skipped", reason: "checks_disabled" }) : runDueReviewChecks({ config, env, startReport: scheduledReportStarter({ config, env }),
    assertTarget: (url) => assertPublicHttpTarget(url), holder: "sweep-" + auth.via }) });
  return NextResponse.json(result, { status: 200, headers });
};

export async function GET(request) { return sweep(request); }
export async function POST(request) { return sweep(request); }