feat(terminal): pairing, sign-in per mode, device app router and live states (platform-v2 3.1c)

- Pairing screen: requests a code, shows it big, polls with the secret, new code on
  expiry, keeps the device token; "removed from the venue" notice after a revoke.
- Sign-in per device mode: PIN (name + PinPad), tap your name, password (name +
  password), none (straight into the app). Names = holders of <app>.access, refreshed
  every 30 s and on reconnect. Slim bar with screen, user and Sign out; idle sign-out
  after the device's auto_sign_out_minutes; hourly token refresh (same session).
- DeviceProvider: GET /api/devices/me (retried while unreachable), session, the live
  connection with credentials in the first frame (device.updated -> reload, app moved ->
  sign out, device.revoked -> forget, session.ended -> sign out), offline banner;
  useLiveEvent for apps. Screen choice is pure (device/flow.js, unit-tested).
- Blocked screen: app turned off / not licensed / device refused, recovers by itself.
- @xenia/access AccessProvider: autoRetryMs (retry bootstrap while unreachable).
- Tests: terminal unit tests (screen choice, live actions, idle, pairing polls), new
  tests/e2e/terminal.mjs (18 checks), manager.mjs owner flow now pairs and signs in on
  the real terminal screen; run-all runs terminal.mjs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 17:29:18 +02:00
co-authored by Claude Opus 5.5
parent 7ff3c3b48e
commit c24cb72640
22 changed files with 928 additions and 83 deletions
+27 -11
View File
@@ -5,26 +5,42 @@ import { deviceStore } from '../device/storage'
// The shared client (@xenia/api, CS-18). Same origin: the image's nginx (or Vite in dev)
// forwards /api to the backend. Every request carries the screen's device token
// (X-Xenia-Device) and, when someone is signed in, their session token.
// A 401 = the session ended (signed out elsewhere, idle, device reassigned): drop the session
// token; the screen goes back to its sign-in (3.1c). Pairing/sign-in forms pass
// { xenia: { ignoreUnauthorized: true } } for their own 401s.
const listeners = new Set()
// - A 401 = the session ended (signed out elsewhere, idle, device reassigned) or the device
// was removed: DeviceProvider listens (onUnauthorized) and signs out / forgets the device.
// Pairing and sign-in forms pass { xenia: { ignoreUnauthorized: true } } for their own 401s.
// - No answer at all = the venue server is unreachable: DeviceProvider shows a banner until
// a request gets an answer again (onReachable).
const unauthorized = new Set()
const reachability = new Set()
const client = createApiClient({
axios,
baseURL: '',
getToken: () => deviceStore.sessionToken(),
getDeviceToken: () => deviceStore.deviceToken(),
onUnauthorized: x => {
deviceStore.setSessionToken(null)
listeners.forEach(fn => fn(x))
},
onUnauthorized: x => unauthorized.forEach(fn => fn(x)),
onOffline: () => reachability.forEach(fn => fn(false)),
})
/** Called with err.xenia whenever a request comes back 401 (see above). */
// Any answer, even an error, means the server is there
client.interceptors.response.use(
res => { reachability.forEach(fn => fn(true)); return res },
err => { if (err?.response) reachability.forEach(fn => fn(true)); throw err },
)
/** fn(err.xenia) whenever a request comes back 401. Returns an unsubscribe function. */
export function onUnauthorized(fn) {
listeners.add(fn)
return () => listeners.delete(fn)
unauthorized.add(fn)
return () => unauthorized.delete(fn)
}
/** fn(true | false) whenever the server answers / can't be reached. */
export function onReachable(fn) {
reachability.add(fn)
return () => reachability.delete(fn)
}
// Dev builds only: lets the e2e suite (tests/e2e/terminal.mjs) drive requests through this client
if (import.meta.env?.DEV) window.__xeniaClient = client
export default client