# `Threadline.OperatorSurface.Router`
[🔗](https://github.com/szTheory/threadline/blob/v1.2.0/lib/threadline/operator_surface/router.ex#L2)

Mounts Threadline's operator interface in a Phoenix router with host-owned
authorization and query scoping.

A mount must provide a usable one-argument `:authorize_fn` or the exact
literal `adopter_acknowledges_unauthenticated: true` opt-out. A host
`pipe_through` remains responsible for middleware such as authentication,
sessions and CSRF, but does not establish Threadline authorization.

## HTTP endpoints

When Phoenix is available at compile time, the macro emits a sibling
`POST <path>/theme` route and a sibling `scope <path>/exports` block with
GET routes for `/changes.csv`, `/changes.json`, `/changes.ndjson`, and
completed export downloads. These HTTP endpoints use the mount's
authorization callbacks independently from the LiveView session.

The HTTP scopes remain outside `live_session :threadline` because LiveView
`on_mount` callbacks do not apply to controller routes. Route helper names
and the host router's alias namespace remain untouched.

# `threadline_operator_surface`
*macro* 

Adds the Threadline operator LiveView and sibling HTTP routes to the host router.

The macro requires a usable one-argument `:authorize_fn` or an explicit
literal acknowledgement that the mount is intentionally unauthenticated.
Keep the host's `pipe_through` middleware; it does not replace
`:authorize_fn`.

## Mount options

- `:exports` — boolean; defaults to `true`. Set to `false` to suppress the
  sibling export-controller scope (rare LV-only adopters).
- `:scope_query_fn` — `(Ecto.Query.t(), scope, %{surface: atom(), params: map()} -> Ecto.Query.t())`; optional. This host-owned query transform is used when `:authorize_fn` returns `{:ok, scope}`. Threadline treats `scope` as opaque data and calls this function for timeline, actor-history, transaction, and export flows.
- `:export_authorize_fn` — `(Plug.Conn.t() -> :ok | true | {:ok, scope} | _)`; defaults to delegating to `:authorize_fn` via a synthetic `%{assigns: conn.assigns}` mirror. Use a separate callback when HTTP authorization needs more than the assigns inspected by the LiveView callback; the synthetic mirror is sufficient when authorization only reads values such as `assigns.current_user`.
- `:coverage_authorize_fn` — `(%{assigns: map()} -> boolean | :ok | {:ok, scope} | _)`; optional. Explicitly gates the coverage dashboard and related badge, and defaults to fail closed.
- `:policy_authorize_fn` — `(%{assigns: map()} -> boolean | :ok | {:ok, scope} | _)`; optional. Explicitly gates policy and retention surfaces, and defaults to fail closed.
- `:evidence_authorize_fn` — `(%{assigns: map()} -> boolean | :ok | {:ok, scope} | _)`; optional. Explicitly gates the mounted evidence surface, and defaults to fail closed.
- `:theme` — `:dark | :light | :system`; defaults to `:dark`. Selects the default server-rendered operator-surface theme lane. `:system` follows the visitor's OS preference through scoped CSS only. A runtime dark/light/system theme picker is available in the shell (session-backed and resolved server-side; a response cookie mirrors the choice); Threadline adds no JavaScript and no local storage.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
