# uniformen Header for Entur. Apps that need a footer use the [Footer from the design system](https://linje.entur.no/komponenter/navigasjon/footer/beta). Changes to what the service renders are listed in [CHANGELOG.md](./CHANGELOG.md). Changes to the client library's API are listed in [its own changelog](./packages/uniformen/CHANGELOG.md). ## Skill for AI coding agents [`skills/entur-uniformen`](./skills/entur-uniformen/SKILL.md) teaches an agent how to add Uniformen to an Entur application. It is published through the Entur plugin marketplace. The marketplace reads the skill directly from this repo and keeps no copy of it. To install it: ```sh claude plugin marketplace add entur/ai claude # then /plugin, and install "entur-uniformen" ``` For Codex CLI, run `codex plugin marketplace add entur/ai`. The marketplace entry points to the `main` branch, so a change to `SKILL.md` on `main` is published right away. See [skills/README.md](./skills/README.md). ## Install To install dependencies: ```sh bun install ``` To run: ```sh bun run dev ``` Then open http://localhost:4123. ## Preview The root path renders the header on a page, so you can look at it in the browser. It takes the same query parameters as `/ssr`, plus a few parameters for testing. Those have a `debug` prefix. The page has a form with a control for every parameter below. The controls are placed like the parts of the bar they change: controls for the left side of the bar on the left, controls for the right side on the right, and the rest in the middle. "Hvem ser på?" sets `debugUser` and `debugEnturUser`, and "Varsler" sets `hideNotifications` and `debugNotifications`. A checkbox or a menu applies the change when you pick a value. A text field applies it when you leave the field. The page also shows the URL for the current settings, so you can copy it. The URL has only the parameters the server accepted, and leaves out unknown parameters and parameters set to their default value. | Parameter | Values | What it does | | -------------------- | -------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `app` | See [src/components/portalApplications.ts](src/components/portalApplications.ts) | Shows the app name beside the logo and marks the app in the app switcher. For Entur users, the environment badge becomes a switcher with links to the environments the app is deployed to. No default. Any other value returns `400`. | | `aiAgent` | `true`, `false` | `true` renders the AI agent button and its chat drawer, but only for a signed-in user who has the `ai-agent` feature flag on in PostHog. If PostHog is slow or fails, the bar is rendered without them. The preview page shows them without checking the flag. Default `false`. Any other value returns `400`. | | `debugEnturUser` | `true`, `false` | `true` renders the bar as for an Entur user, which shows the environment badge. It only works together with `debugUser`. Default `false`. Any other value returns `400`. Preview page only. | | `sidebar` | `true`, `false` | `true` renders the button that collapses the app's side navigation. The preview page also shows a demo sidebar for the button to act on. Default `false`. Any other value returns `400`. | | `simple` | `true`, `false` | `true` hides the app switcher, notifications, the sidebar button and "Mine tilganger". When `true`, `sidebar` is ignored. Default `false`. Any other value returns `400`. | | `hideNotifications` | `true`, `false` | `true` renders the bar without the notifications button, and the service does not look up the user's notifications. Use it in an app that shows its own notifications, so the page does not have two lists. With `simple=true` the button is hidden anyway. Default `false`. Any other value returns `400`. | | `contrast` | `true`, `false` | `true` renders the bar and its panels in the design system's contrast colours. Use it when the page behind the header is dark. In dark mode it has no effect, see [Dark mode](#dark-mode). Default `false`. Any other value returns `400`. | | `colorMode` | `light`, `dark` | `dark` sets `data-color-mode="dark"` on the preview page's ``, which turns on [dark mode](#dark-mode). In an app, the app sets this attribute, so `/ssr` has no such parameter. Default `light`. Any other value returns `400`. Preview page only. | | `loginUrl` | a path on the app's own origin, e.g. `/auth/login`, at most 512 characters | The link target for "Logg inn" on the bar for users who are not signed in. If it is not set, there is no login link. An absolute URL, `//host` or `javascript:` returns `400`. | | `logoutUrl` | a path on the app's own origin, e.g. `/auth/logout`, at most 512 characters | The link target for "Logg ut" in the signed-in user's menu. If it is not set, there is no logout link. An absolute URL, `//host` or `javascript:` returns `400`. | | `actionsUrl` | a path on the app's own origin, e.g. `/uniformen/actions`, at most 512 characters | Where the browser sends the bar's actions, such as marking a notification as read or asking the chat a question. The app's server forwards them to uniformen's `/actions/` routes with the user's access token. If it is not set, the browser calls uniformen directly, with tokens that uniformen puts in the markup. When it is set, the `connect-src` in the response no longer lists uniformen. An absolute URL, `//host` or `javascript:` returns `400`. See [Actions](#actions). | | `locale` | `nb-NO` (default), `nn-NO`, `en-GB` | The language of the header. The preview page also sets `` to this value. Any other value returns `400`. | | `availableLocales` | any of `nb-NO`, `nn-NO`, `en-GB`, repeated: `?availableLocales=nb-NO&availableLocales=en-GB` | The languages the app offers, in the order to list them in the language switcher. For a signed-in user the switcher is a section in the user menu, also with `simple`. For other users it is a separate button next to the login link. The list must include `locale`, which is shown as the selected language. If it is not set, there is no switcher. An unknown value, a repeated value, or a list without `locale` returns `400`. | | `debugUser` | any text, 1–120 characters | Renders the bar as signed in, with this name. If it is not set, the bar is rendered for a user who is not signed in. Text outside the length limits returns `400`. Preview page only. | | `debugOrganisation` | any text, 1–120 characters | The line under the name in the user menu, usually the name of the user's organisation. Text outside the length limits returns `400`. Preview page only. | | `debugNotifications` | `none`, `some`, `max` | How many notifications the panel shows. `none` is an empty panel, `some` shows the first three and `max` shows the five the panel holds at most. Default `max`. The list is test data, unless `DEV_ACCESS_TOKEN` is set, in which case it comes from the notification service and clicking a notification deletes it. Any other value returns `400`. Preview page only. | ``` http://localhost:4123/?app=partner&sidebar=true&debugUser=Navne+Navnesen&debugOrganisation=Entur&debugEnturUser=true ``` Only the preview page reads the `debug` parameters. `/ssr` ignores them, because the signed-in user and their organisation must come from the token, not from the URL. The preview page also ignores them in production. Otherwise anyone could share a production link that shows a signed-in user without a session, or shows controls the viewer does not have access to. ## Actions With `actionsUrl`, the browser sends the bar's actions to the app's own server, with the app's session cookie. The app's server forwards them to uniformen's `/actions/` routes with the user's access token. Use `handleUniformenAction` from [`@entur/uniformen`](./packages/uniformen) if you can. If you write your own forwarding, for example in Kotlin, follow these rules: - Accept only `POST`. - Reject a request without the header `X-Uniformen-Action: 1`, and a request whose `Sec-Fetch-Site` is set to anything other than `same-origin`. The session cookie is the credential, so these checks protect against CSRF. - Forward only paths made of `/` and the characters `A-Z`, `a-z`, `0-9`, `_` and `-`. - Send only the path, the body, `Content-Type` and the access token to uniformen. Do not send the app's cookies. - Answer `401` when the session has expired. Do not redirect to a login page. - Do not follow redirects from uniformen, and set `Cache-Control: no-store` on the answer. | Route | What it does | | --------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `POST /actions/notifications/{id}/read` | Marks the notification as read and answers `204`. The notification center cannot mark notifications as read yet, so uniformen deletes the notification for now. The browser then shows it as read until the next page load. | | `POST /actions/chat` | Sends the user's question to the chat. Only users who see the chat in the bar may use it. | When the user clicks a notification, the bar dispatches a `uniformen:notification` event on `window` with `{ id, referenceId, href, action: "read" }`. On a plain left click, the app can call `preventDefault()` to navigate itself, for example with its router. The bar still marks the notification as read. Call `preventDefault()` before the first `await`. ## Request headers `/ssr` reads two headers for statistics. They do not change what is rendered. | Header | Values | What it does | | ---------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `X-Uniformen-Consumer` | See [src/components/portalApplications.ts](src/components/portalApplications.ts) | The app that calls the service. It sets the `consumer_app` label on `http_server_requests_seconds`. A missing header is counted as `none`, and any other value as `other`. It is separate from the `app` query parameter, which sets the `rendered_app` label on `uniformen_ssr_requests`. | | `X-Uniformen-Client` | `@entur/uniformen@`, sent by the client package | The version of the client package. It sets the `client_version` label on `uniformen_ssr_requests`. | ## Dark mode The header and its panels follow the design system's dark mode. Your app turns it on with the same attribute that the design system's components use: ```html ``` The attribute can also be on another element around the header. Uniformen does not set the attribute and has no query parameter for it. The stylesheet contains both the light and the dark colours, so the `/ssr` response is the same in both modes. If your app lets the user pick "system", read `prefers-color-scheme` in your app and set the attribute to `light` or `dark`. In the design system, the standard colours and the contrast colours have the same dark colours. So in dark mode, `contrast=true` looks the same as `contrast=false`. You can keep sending `contrast=true` for the light mode of a dark page. ## The environment badge The environment badge next to the logo is shown only to users in the Entur organisation. When the app sends `app`, the badge becomes an environment switcher. A user is in the Entur organisation when their userinfo has the claim `https://entur.io/organisationID` set to `ENTUR_ORGANISATION_ID` (`src/auth/enturOrganisation.ts`). All other users, signed in or not, get the bar without the badge. The coloured strip along the top of the header is shown to everyone. It tells the viewer that the page is not production. Production has no strip. The check uses the user's profile from the userinfo lookup. If the lookup fails, the bar is rendered without the badge. ## Contributing Team Portal maintains this repository. We accept pull requests from Entur teams only. [CONTRIBUTING.md](./CONTRIBUTING.md) describes the setup, the checks CI runs, and the rules for commits, changelogs and new query parameters. Anyone can open an issue. Report security problems as described in [SECURITY.md](./SECURITY.md), not in an issue. ## Licence [EUPL-1.2](./LICENSE). © Entur AS.