Brand Studio docs
Engineering manualAPI route source

/api/brand-studio/brand-presence

Exact current route handler: hosted-app/app/api/brand-studio/brand-presence/route.js

Methods: GET. Input signals: query parameters. Literal response-status signals: 200.

Source: hosted-app/app/api/brand-studio/brand-presence/route.js. Imports: ../../../../lib/comprehensive-pull-handler.mjs, ../../../../lib/report-capture-source.mjs, ../../../../lib/report-downloads.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

// brand.md — "download this brand" from the report's own menu.
//
// One markdown page distilled from the capture: name, palette with the hexes,
// the type that was actually declared, the logos, the handles that were
// verified, and the voice read off the brand's own copy. Built by the same
// pure renderer the panel uses, so the file is the same file.
export const runtime = "nodejs";
export const dynamic = "force-dynamic";

import { supabaseConfigFromEnv } from "../../../../lib/supabase-rest.mjs";
import { bearerTokenFromHeader } from "../../../../lib/comprehensive-pull-handler.mjs";
import { resolveCaptureForDownload } from "../../../../lib/report-capture-source.mjs";
import { brandMarkdownForCapture, brandPresenceForCapture } from "../../../../lib/report-downloads.mjs";
import { NextResponse } from "next/server";

const fileSlug = (value) => String(value || "brand").replace(/[^\w.-]+/g, "-").replace(/^-+|-+$/g, "") || "brand";

export async function GET(request) {
  const url = new URL(request.url);
  const runId = url.searchParams.get("run_id") || "";
  const format = (url.searchParams.get("format") || "json").toLowerCase();
  const token = bearerTokenFromHeader(request.headers.get("authorization"));

  const source = await resolveCaptureForDownload({
    runId,
    token,
    config: supabaseConfigFromEnv(process.env)
  });
  if (!source.ok) return NextResponse.json(source.body, { status: source.http_status });

  if (format === "md" || format === "markdown") {
    const markdown = brandMarkdownForCapture(source.captureResult, source.runId, { reportId: source.reportId || source.runId, overrides: source.overrides });
    return new NextResponse(markdown, {
      status: 200,
      headers: {
        "content-type": "text/markdown; charset=utf-8",
        "cache-control": "no-store",
        "content-disposition": `attachment; filename="${fileSlug(source.domain || source.runId)}-brand.md"`
      }
    });
  }

  return NextResponse.json(
    {
      schema_version: "brand-studio-all-rest-brand-presence/v1",
      run_id: source.runId,
      capture_route: "all_rest",
      ...brandPresenceForCapture(source.captureResult, { runId: source.runId, reportId: source.reportId || source.runId, overrides: source.overrides })
    },
    { status: 200, headers: { "cache-control": "no-store" } }
  );
}