Brand Studio docs
Engineering manualAPI route source

/api/brands/search-watch

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

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

Source: hosted-app/app/api/brands/search-watch/route.js. Imports: ../../../../lib/bounded-http.mjs, ../../../../lib/comprehensive-pull.mjs, ../../../../lib/search-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

// /api/brands/search-watch — weekly search checks for saved brands (beta).
//
//   GET ?domain=              one brand's check, or all of the account's (read_reports)
//   POST { domain, action }   start | pause | resume | stop one brand's check;
//                             start also sends the market and max_cost_usd from
//                             the live quote the owner saw
//
// Each weekly check reads the provider's free Google data date and buys a
// search snapshot only when it is newer than the brand's latest one. Changing a
// check needs a browser session or an API key with run_pulls; assistant
// connections are read-only. See lib/search-watches.mjs.

import { NextResponse } from "next/server";
import { supabaseConfigFromEnv } from "../../../../lib/supabase-rest.mjs";
import { bearerTokenFromHeader } from "../../../../lib/comprehensive-pull.mjs";
import { readBoundedJsonRequest } from "../../../../lib/bounded-http.mjs";
import { getSearchWatches, setSearchWatch } from "../../../../lib/search-watches.mjs";

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

const PRIVATE = { "cache-control": "private, no-store", "x-content-type-options": "nosniff" };
const reply = (result) => NextResponse.json(result.body, { status: result.http_status, headers: PRIVATE });
const tokenOf = (request) => bearerTokenFromHeader(request.headers.get("authorization"));

export async function GET(request) {
  const domain = new URL(request.url).searchParams.get("domain") || "";
  return reply(await getSearchWatches({ token: tokenOf(request), config: supabaseConfigFromEnv(process.env), domain }));
}

export async function POST(request) {
  let body;
  try { body = await readBoundedJsonRequest(request, 16384); }
  catch (error) { return NextResponse.json({ status: "refused", reason: error.message }, { status: error.httpStatus || 400, headers: PRIVATE }); }
  return reply(await setSearchWatch({ token: tokenOf(request), config: supabaseConfigFromEnv(process.env), body: body || {} }));
}