diff --git a/apps/console/README.md b/apps/console/README.md index 948e5549..d760e9a4 100644 --- a/apps/console/README.md +++ b/apps/console/README.md @@ -43,6 +43,10 @@ Usage, Billing), one primary action on each, a pause switch and one-click cancel | `INSIGHTS_API_URL` | var | Insights tenant API base (Wave P PY1.3); empty keeps the Insights page on "No data yet" | | `FLAGS_API_URL` | var | Railyard Flags (Wave P PY2.1): base URL of the flags service on box 2 (through the tunnel). With `FLAGS_ADMIN_TOKEN` set, new flag environments are made there; without them, flags live in the console's own tables (migration 0005), the fallback. | | `FLAGS_ADMIN_TOKEN` | secret | The flags service's instance admin token (`Token ...` auth). Only this console holds it; apps read flags with their public flags key. | +| `RAILYARD_WATCH_LIVE` | var | Railyard Watch (Wave P PY2.2). `1` turns on uptime checks, the Watch screen, the public status pages and the alert email. Unset (the default): no check runs and nothing about Watch is shown (denylist rule `railyard-slot-watch`). Set it only after the customer checks stack on box 1 passes its drill. | +| `WATCH_AGENT_TOKEN` | secret | Bearer token of the box 1 checks agent (`stacks/gatus-customers/agent.sh`), at least 32 characters; the same value sits in `/etc/products/watch-agent.token` on box 1. Unset keeps the agent API off (503). | +| `RALLY_TX_URL` | var | Rally Send transactional endpoint (https) for Watch alert email, product `railyard`. | +| `RALLY_TX_KEY` | secret | Rally Send key minted for product `railyard`. Without it, alerts are logged, not sent. | | `INSIGHTS_API_TOKEN` | secret | Bearer token of the Insights tenant API | | `SITES` | KV binding | The edge collector's site entries; written when an app is added and on every plan, add-on or pause change | | `RELAY_URL` | var | Relay's OpenAI-compatible base for the AI gateway (Wave P PY1.4) | diff --git a/apps/console/app/(app)/layout.tsx b/apps/console/app/(app)/layout.tsx index 0fa02039..43e243ee 100644 --- a/apps/console/app/(app)/layout.tsx +++ b/apps/console/app/(app)/layout.tsx @@ -2,6 +2,7 @@ import { redirect } from "next/navigation"; import type { ReactNode } from "react"; import { Nav } from "../../components/Nav.tsx"; import { currentSession } from "../../lib/current.ts"; +import { deps } from "../../lib/deps.ts"; export const dynamic = "force-dynamic"; @@ -9,7 +10,7 @@ export default async function AppLayout({ children }: { children: ReactNode }) { if (!(await currentSession())) redirect("/"); return (
-
); diff --git a/apps/console/app/(app)/watch/page.tsx b/apps/console/app/(app)/watch/page.tsx new file mode 100644 index 00000000..f76f02b1 --- /dev/null +++ b/apps/console/app/(app)/watch/page.tsx @@ -0,0 +1,30 @@ +import { WatchPanel } from "../../../components/WatchPanel.tsx"; +import { currentSession } from "../../../lib/current.ts"; +import { deps } from "../../../lib/deps.ts"; +import { listWithState } from "../../../lib/watch/service.ts"; + +// Uptime checks and status pages (Wave P PY2.2, RYP-E4). Checks run every +// minute; two failures in a row turn a check red and email the owner. +export default async function WatchPage() { + const { repo, watch } = deps(); + if (!watch.live) { + return ( + <> +

Watch

+
+

Watch is arriving. Nothing to set up yet.

+
+ + ); + } + const s = (await currentSession())!; + const [apps, checks] = await Promise.all([repo.listApps(s.org), listWithState(watch, s.org)]); + return ( + <> +

Watch

+
+ a.name)} checks={checks} /> +
+ + ); +} diff --git a/apps/console/app/api/v1/bridge/scribase/bridge.test.ts b/apps/console/app/api/v1/bridge/scribase/bridge.test.ts index 6093beea..558c6fea 100644 --- a/apps/console/app/api/v1/bridge/scribase/bridge.test.ts +++ b/apps/console/app/api/v1/bridge/scribase/bridge.test.ts @@ -449,3 +449,93 @@ test("flags: the console writes only its own org's environments, for apps it has assert.equal((await consoleSetFlag(flags, repo, other, { app: "shop", env: "production", flag: { key: "banner", enabled: false } }, T0)).status, 404); assert.equal((await flags.store.listEnvs(org.id)).length, 1); }); + +// ---- Uptime (PY2.2) ------------------------------------------------------------- +import { MemoryWatchStore } from "../../../../../lib/watch/store.ts"; +import { recordResults, type WatchDeps } from "../../../../../lib/watch/service.ts"; +import { agentList, agentResults, consoleWatch } from "../../../../../lib/watch/http.ts"; + +function watchDeps(repo: MemoryRepo): WatchDeps & { sent: string[] } { + const sent: string[] = []; + return { store: new MemoryWatchStore(), repo, mailer: { send: async (m) => (sent.push(`${m.to}|${m.subject}`), true) }, consoleUrl: "https://railyard.example", agentToken: "agent-token-0123456789abcdef-0123", live: true, sent }; +} + +test("uptime: a check for the project's address, its status page, the first result is the proof, red emails the owner", async () => { + const repo = new MemoryRepo(() => T0); + const watch = watchDeps(repo); + await call(repo, "orgs", { scribase_org_id: "org_u", name: "U", addon: addon(true, ["uptime"]) }); + const r = await call(repo, "uptime", { scribase_org_id: "org_u", app: "shop", url: "https://shop.example.com", owner_email: "owner@example.com" }, { extra: { watch } }); + assert.equal(r.status, 200, JSON.stringify(r.body)); + assert.equal(r.body.created, true); + const check = (r.body.checks as { id: string; status_url: string; state: string }[])[0]; + assert.match(check.status_url, /^https:\/\/railyard\.example\/status\/shop-/); + assert.equal(check.state, "waiting"); + let proof = await call(repo, "proof", { scribase_org_id: "org_u", slot: "uptime" }, { extra: { watch } }); + assert.equal(proof.body.state, "no_proof_yet"); + const at = (m: number) => new Date(T0.getTime() + m * 60_000).toISOString(); + await recordResults(watch, { results: [{ id: check.id, ok: true, at: at(1), ms: 80 }, { id: check.id, ok: false, at: at(2), ms: 1 }, { id: check.id, ok: false, at: at(3), ms: 1 }] }, new Date(at(3))); + proof = await call(repo, "proof", { scribase_org_id: "org_u", slot: "uptime" }, { extra: { watch } }); + assert.deepEqual(proof.body.proof, { kind: "check_result", id: check.id, at: at(1) }); + assert.deepEqual(watch.sent, ["owner@example.com|shop is down"]); + const again = await call(repo, "uptime", { scribase_org_id: "org_u", app: "shop" }, { extra: { watch } }); + assert.equal(again.body.created, false); + assert.equal((again.body.checks as { state: string }[])[0].state, "down"); +}); + +test("uptime: without a URL the app's latest live deploy is checked; with neither it asks for the address", async () => { + const repo = new MemoryRepo(() => T0); + const watch = watchDeps(repo); + const orgId = (await call(repo, "orgs", { scribase_org_id: "org_d", name: "D", addon: addon(true, ["uptime", "deploy"]) })).body.org_id as string; + assert.equal((await call(repo, "uptime", { scribase_org_id: "org_d", app: "shop" }, { extra: { watch } })).status, 400); + await addApp(repo, orgId, "shop", T0); + await recordDeploy(repo, orgId, parseDeployInput({ app: "shop", branch: "main", framework: "vite", status: "succeeded", url: "https://shop.acct.workers.dev" }) as never, T0); + const r = await call(repo, "uptime", { scribase_org_id: "org_d", app: "shop" }, { extra: { watch } }); + assert.equal(r.status, 200); + assert.equal((r.body.checks as { url: string }[])[0].url, "https://shop.acct.workers.dev/"); +}); + +test("uptime: 402 outside the add-on, 503 before Watch exists, 400 for a private address", async () => { + const repo = new MemoryRepo(() => T0); + const watch = watchDeps(repo); + await call(repo, "orgs", { scribase_org_id: "org_n", name: "N", addon: addon(true, ["deploy"]) }); + assert.equal((await call(repo, "uptime", { scribase_org_id: "org_n", app: "shop", url: "https://shop.example.com" }, { extra: { watch } })).status, 402); + await call(repo, "orgs", { scribase_org_id: "org_m", name: "M", addon: addon(true, ["uptime"]) }); + assert.equal((await call(repo, "uptime", { scribase_org_id: "org_m", app: "shop", url: "https://shop.example.com" })).status, 503); + assert.equal((await call(repo, "uptime", { scribase_org_id: "org_m", app: "shop", url: "https://10.0.0.5" }, { extra: { watch } })).status, 400); + // RAILYARD_WATCH_LIVE off: the slot is arriving, nothing is created. + const off = { ...watch, live: false }; + assert.equal((await call(repo, "uptime", { scribase_org_id: "org_m", app: "shop", url: "https://shop.example.com" }, { extra: { watch: off } })).status, 503); + assert.equal((await call(repo, "proof", { scribase_org_id: "org_m", slot: "uptime" }, { extra: { watch: off } })).body.state, "arriving"); +}); + +test("uptime agent API: bearer token only; the list has ids and URLs; results flow in", async () => { + const repo = new MemoryRepo(() => T0); + const watch = watchDeps(repo); + await call(repo, "orgs", { scribase_org_id: "org_a2", name: "A", addon: addon(true, ["uptime"]) }); + const id = ((await call(repo, "uptime", { scribase_org_id: "org_a2", app: "shop", name: "Shop", url: "https://shop.example.com" }, { extra: { watch } })).body.checks as { id: string }[])[0].id; + const auth = { authorization: `Bearer ${watch.agentToken}` }; + assert.equal((await agentList(watch, new Request("https://c/x"), T0)).status, 401); + const list = (await (await agentList(watch, new Request("https://c/x", { headers: auth }), T0)).json()) as { checks: Record[] }; + assert.deepEqual(list.checks, [{ id, url: "https://shop.example.com/", interval_s: 60 }]); + assert.ok(!JSON.stringify(list).includes("Shop"), "no customer text reaches the checker"); + const post = await agentResults(watch, new Request("https://c/x", { method: "POST", headers: auth, body: JSON.stringify({ results: [{ id, ok: true, at: T0.toISOString(), ms: 50 }] }) }), T0); + assert.equal(((await post.json()) as { accepted: number }).accepted, 1); + assert.equal((await agentResults({ ...watch, agentToken: null }, new Request("https://c/x", { method: "POST" }), T0)).status, 503); +}); + +test("uptime console: only the org's own apps and checks", async () => { + const repo = new MemoryRepo(() => T0); + const watch = watchDeps(repo); + const org = await repo.createOrgForUser({ userId: "w1", email: "w@example.com", name: "W" }); + await repo.saveEntitlement({ ...(await import("../../../../../lib/types.ts")).emptyEntitlement(org.id, T0), plan: "railyard", status: "active", apps_limit: 3 }); + await addApp(repo, org.id, "shop", T0); + const s = { org: org.id, email: "w@example.com" }; + assert.equal((await consoleWatch(watch, repo, null, {})).status, 401); + assert.equal((await consoleWatch(watch, repo, s, { app: "nope", url: "https://x.example.com" })).status, 404); + const ok = await consoleWatch(watch, repo, s, { app: "shop", url: "https://shop.example.com" }); + assert.equal(ok.status, 200); + const id = (ok.body.checks as { id: string }[])[0].id; + assert.equal((await watch.store.getCheck(id))?.owner_email, "w@example.com"); + assert.equal((await consoleWatch(watch, repo, { org: "other", email: "o@example.com" }, { id, paused: true })).status, 404); + assert.equal((await consoleWatch(watch, repo, s, { id, paused: true })).status, 200); +}); diff --git a/apps/console/app/api/v1/bridge/scribase/service.ts b/apps/console/app/api/v1/bridge/scribase/service.ts index fff504a2..49b6c0f9 100644 --- a/apps/console/app/api/v1/bridge/scribase/service.ts +++ b/apps/console/app/api/v1/bridge/scribase/service.ts @@ -32,6 +32,7 @@ import { verify, type WebhookHeaders } from "../../../../../lib/standard-webhook import { createApprovedDevice } from "../../../../../lib/tokens.ts"; import { emptyEntitlement, type Entitlement } from "../../../../../lib/types.ts"; import { ensureEnv, firstRead, FlagsError, listFlags, setFlag, type FlagsDeps } from "../../../../../lib/flags/service.ts"; +import { createCheck, listWithState, WatchError, type WatchDeps } from "../../../../../lib/watch/service.ts"; export const CLAIM_TTL_SECONDS = 120; @@ -49,7 +50,7 @@ export const BRIDGE_SLOTS = { analytics: { pkg: "PY1.3", landed: true, proof: "first_event" }, ai: { pkg: "PY1.4", landed: true, proof: "gateway_key" }, flags: { pkg: "PY2.1", landed: true, proof: "first_flag_read" }, - uptime: { pkg: "PY2.2", landed: false, proof: "check_result" }, + uptime: { pkg: "PY2.2", landed: true, proof: "check_result" }, billing: { pkg: "PY2.3", landed: false, proof: "test_purchase" }, consent: { pkg: "PY2.5", landed: false, proof: "consent_record" }, } as const; @@ -68,6 +69,8 @@ export interface BridgeDeps { insightsUrl?: string; /** Railyard Flags (PY2.1); absent in tests that do not need them. */ flags?: FlagsDeps; + /** Railyard Watch (PY2.2); absent in tests that do not need it. */ + watch?: WatchDeps; /** P-Y1 transition: accept unbound ids and orgs syncs without `addon.as_of` (RAILYARD_BRIDGE_ACCEPT_LEGACY=1). */ acceptLegacy?: boolean; } @@ -243,6 +246,7 @@ export async function slotProof( landed: Partial> = {}, insights: InsightsClient | null = null, flags: FlagsDeps | null = null, + watch: WatchDeps | null = null, ): Promise { const isLanded = landed[slot] ?? BRIDGE_SLOTS[slot].landed; if (!isLanded) { @@ -273,6 +277,14 @@ export async function slotProof( ? { slot, state: "live", live: true, proof: read, next: null } : { slot, state: "no_proof_yet", live: true, proof: null, next: "Read a flag from the app (or run the add command again) to see the first read here." }; } + if (slot === "uptime") { + if (!watch?.live) return { slot, state: "arriving", live: false, proof: null, next: "This slot is arriving (PY2.2); nothing was changed." }; + const checks = await listWithState(watch, orgId); + const first = checks.filter((c) => c.first_result_at).sort((a, b) => (a.first_result_at! < b.first_result_at! ? -1 : 1))[0]; + return first + ? { slot, state: "live", live: true, proof: { kind: "check_result", id: first.id, at: first.first_result_at! }, next: null } + : { slot, state: "no_proof_yet", live: true, proof: null, next: checks.length ? "The first result arrives within two minutes." : "Add your app's address to check." }; + } return { slot, state: "no_proof_yet", live: true, proof: null, next: null }; } @@ -285,7 +297,7 @@ async function proofFor(deps: BridgeDeps, body: Record): Promis if (!BRIDGE_SLOTS[s].landed) return { status: 200, body: { ...(await slotProof(deps.repo, "", s)) } }; const bound = await deps.repo.findScribaseBinding(scribaseOrgId); if (!bound) return { status: 200, body: { slot: s, state: "not_entitled", live: false, proof: null, next: "Turn on the add-on first." } }; - return { status: 200, body: { ...(await slotProof(deps.repo, bound.org_id, s, {}, deps.insights ?? null, deps.flags ?? null)) } }; + return { status: 200, body: { ...(await slotProof(deps.repo, bound.org_id, s, {}, deps.insights ?? null, deps.flags ?? null, deps.watch ?? null)) } }; } async function deploysFor(deps: BridgeDeps, body: Record): Promise { @@ -442,7 +454,42 @@ async function flagsFor(deps: BridgeDeps, body: Record): Promis } } -export type BridgeRoute = "orgs" | "claims" | "proof" | "deploys" | "sites" | "insights" | "ai" | "ai_usage" | "flags"; +/** + * Uptime for one Scribase project (PY2.2): `{scribase_org_id, app, url?, + * name?, owner_email?}`. With a URL (or, without one, the app's latest live + * deploy) it adds a check; it always answers the app's checks with their + * state and public status page. + */ +async function uptimeFor(deps: BridgeDeps, body: Record): Promise { + const scribaseOrgId = parseOrgRef(body); + if (!scribaseOrgId) return fail(400, "scribase_org_id is required"); + const app = typeof body.app === "string" ? normaliseAppName(body.app) : ""; + if (!/^[a-z0-9][a-z0-9-]{0,39}$/.test(app)) return fail(400, "app must be a project name (letters, numbers, dashes)"); + const now = deps.now(); + const who = await entitledOrg(deps.repo, scribaseOrgId, "uptime", now); + if ("status" in who) return who; + if (!deps.watch || !deps.watch.live) return fail(503, "This slot is arriving (PY2.2). Nothing was changed."); + const ownerEmail = typeof body.owner_email === "string" && body.owner_email.length <= 254 ? body.owner_email : null; + let url = typeof body.url === "string" && body.url.trim() ? body.url.trim() : null; + if (!url) { + const railyardApp = await deps.repo.findAppByName(who.orgId, app); + const live = railyardApp ? (await deps.repo.listDeploys(who.orgId, railyardApp.id)).find((d) => d.status === "succeeded") : undefined; + url = live?.url ?? null; + } + try { + const before = (await deps.watch.store.listChecks(who.orgId)).length; + if (url) await createCheck(deps.watch, { orgId: who.orgId, app, name: body.name, url, ownerEmail }); + const checks = await listWithState(deps.watch, who.orgId, app); + if (checks.length === 0) return fail(400, "Give the https address of your app to check, or deploy it first."); + const created = (await deps.watch.store.listChecks(who.orgId)).length > before; + return { status: 200, body: { app, created, checks } }; + } catch (e) { + if (e instanceof WatchError) return fail(e.status, e.message); + throw e; + } +} + +export type BridgeRoute = "orgs" | "claims" | "proof" | "deploys" | "sites" | "insights" | "ai" | "ai_usage" | "flags" | "uptime"; /** * The route a signed message id names (P-Y1). Scribase sends @@ -490,5 +537,7 @@ export async function handleBridge(deps: BridgeDeps, route: BridgeRoute, headers return aiUsageFor(deps, b); case "flags": return flagsFor(deps, b); + case "uptime": + return uptimeFor(deps, b); } } diff --git a/apps/console/app/api/v1/bridge/scribase/uptime/route.ts b/apps/console/app/api/v1/bridge/scribase/uptime/route.ts new file mode 100644 index 00000000..b598a13d --- /dev/null +++ b/apps/console/app/api/v1/bridge/scribase/uptime/route.ts @@ -0,0 +1,17 @@ +import { deps } from "../../../../../../lib/deps.ts"; +import { json } from "../../../../../../lib/http.ts"; +import { handleBridge } from "../service.ts"; + +export const dynamic = "force-dynamic"; + +export async function POST(req: Request) { + const { cfg, repo, sites, insights, flags, watch } = deps(); + if (!cfg.scribaseBridgeSecret) return json({ error: "bridge_not_configured" }, 503); + const r = await handleBridge( + { repo, secret: cfg.scribaseBridgeSecret, consoleUrl: cfg.consoleUrl, now: () => new Date(), sites, insights, insightsUrl: cfg.insightsUrl, acceptLegacy: cfg.bridgeAcceptLegacy, flags, watch }, + "uptime", + { id: req.headers.get("webhook-id"), timestamp: req.headers.get("webhook-timestamp"), signature: req.headers.get("webhook-signature") }, + await req.text(), + ); + return json(r.body, r.status); +} diff --git a/apps/console/app/api/v1/watch/agent/checks/route.ts b/apps/console/app/api/v1/watch/agent/checks/route.ts new file mode 100644 index 00000000..dabc80da --- /dev/null +++ b/apps/console/app/api/v1/watch/agent/checks/route.ts @@ -0,0 +1,8 @@ +import { deps } from "../../../../../../lib/deps.ts"; +import { agentList } from "../../../../../../lib/watch/http.ts"; + +export const dynamic = "force-dynamic"; + +export async function GET(req: Request) { + return agentList(deps().watch, req, new Date()); +} diff --git a/apps/console/app/api/v1/watch/agent/results/route.ts b/apps/console/app/api/v1/watch/agent/results/route.ts new file mode 100644 index 00000000..c849755f --- /dev/null +++ b/apps/console/app/api/v1/watch/agent/results/route.ts @@ -0,0 +1,8 @@ +import { deps } from "../../../../../../lib/deps.ts"; +import { agentResults } from "../../../../../../lib/watch/http.ts"; + +export const dynamic = "force-dynamic"; + +export async function POST(req: Request) { + return agentResults(deps().watch, req, new Date()); +} diff --git a/apps/console/app/api/watch/route.ts b/apps/console/app/api/watch/route.ts new file mode 100644 index 00000000..00e8dba5 --- /dev/null +++ b/apps/console/app/api/watch/route.ts @@ -0,0 +1,12 @@ +import { sessionFromRequest } from "../../../lib/current.ts"; +import { deps } from "../../../lib/deps.ts"; +import { json, sameOrigin } from "../../../lib/http.ts"; +import { consoleWatch } from "../../../lib/watch/http.ts"; + +// Add, pause or resume an uptime check from the Watch screen (PY2.2). +export async function POST(req: Request) { + const { cfg, repo, watch } = deps(); + if (!sameOrigin(req, cfg.consoleUrl)) return json({ error: "Forbidden" }, 403); + const r = await consoleWatch(watch, repo, await sessionFromRequest(req), await req.json().catch(() => null)); + return json(r.body, r.status); +} diff --git a/apps/console/app/globals.css b/apps/console/app/globals.css index 087c3f81..d3dc1a27 100644 --- a/apps/console/app/globals.css +++ b/apps/console/app/globals.css @@ -37,6 +37,7 @@ pre { background: #1d2433; color: #e8ecf5; padding: 14px 16px; border-radius: 12 .list { list-style: none; padding: 0; margin: 0; } .list li { padding: 12px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; } .error { color: #b42318; } +.ok { color: #1d7a4f; } .center { min-height: 100vh; display: grid; place-items: center; } .switch { display: inline-flex; gap: 4px; background: var(--glass); border-radius: 12px; padding: 4px; border: 1px solid var(--line); } .switch button { border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; cursor: pointer; font: inherit; color: var(--muted); } diff --git a/apps/console/app/status/[app]/page.tsx b/apps/console/app/status/[app]/page.tsx new file mode 100644 index 00000000..b1568864 --- /dev/null +++ b/apps/console/app/status/[app]/page.tsx @@ -0,0 +1,41 @@ +import { notFound } from "next/navigation"; +import { deps } from "../../../lib/deps.ts"; +import { statusView } from "../../../lib/watch/service.ts"; +import { SLUG } from "../../../lib/watch/types.ts"; + +// A public status page per app (Wave P PY2.2, RYP-E4): live results only, +// the check's name and never its address, host or any vendor name. +export const revalidate = 30; + +export async function generateMetadata({ params }: { params: { app: string } }) { + const check = deps().watch.live && SLUG.test(params.app) ? await deps().watch.store.findCheckBySlug(params.app) : null; + return { title: check ? `${check.name} status` : "Status", robots: { index: false } }; +} + +export default async function StatusPage({ params }: { params: { app: string } }) { + const { watch } = deps(); + if (!watch.live || !SLUG.test(params.app)) notFound(); + const check = await watch.store.findCheckBySlug(params.app); + if (!check || check.paused) notFound(); + const view = statusView(check, await watch.store.getStatus(check.id)); + const tone = view.state === "up" ? "ok" : view.state === "down" ? "error" : "muted"; + return ( +
+

{view.name}

+
+

+ {view.label} +

+ {view.uptime ?

{view.uptime}

: null} + {view.lastChecked ?

Last checked {view.lastChecked}

:

The first check runs within two minutes.

} + {view.bars.length ? ( +
+ {view.bars.map((b) => ( + + ))} +
+ ) : null} +
+
+ ); +} diff --git a/apps/console/components/Nav.tsx b/apps/console/components/Nav.tsx index 9ab7d819..25b1938a 100644 --- a/apps/console/components/Nav.tsx +++ b/apps/console/components/Nav.tsx @@ -10,12 +10,14 @@ const LINKS = [ { href: "/billing", label: "Billing" }, ]; -export function Nav() { +/** `watch` adds the Watch screen once RAILYARD_WATCH_LIVE is on (PY2.2). */ +export function Nav({ watch = false }: { watch?: boolean }) { const path = usePathname(); + const links = watch ? [...LINKS.slice(0, 3), { href: "/watch", label: "Watch" }, ...LINKS.slice(3)] : LINKS; return (