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:
+22
-22
@@ -1,17 +1,20 @@
|
||||
// The terminal app's root (plan step 3.1b, APPS_PLATFORM D-2, §9): one web app for every
|
||||
// paired screen, served on :8082 (LAN only). <AccessProvider> loads the platform bootstrap
|
||||
// (venue, language, modules) with the screen's session, if any.
|
||||
// Routes in 3.1b: "/" the start screen, "/app/:appKey" an app by key (its lazy chunk).
|
||||
// 3.1c replaces them with pairing → sign-in → the device's own app (by GET /api/devices/me).
|
||||
import { lazy, Suspense, useState } from 'react'
|
||||
import { BrowserRouter, Route, Routes, useParams } from 'react-router-dom'
|
||||
// The terminal app's root (plan steps 3.1b, 3.1c; APPS_PLATFORM D-2, D-8, §9): one web app
|
||||
// for every paired screen, served on :8082 (LAN only).
|
||||
// DeviceProvider the device (pairing, GET /api/devices/me), who is signed in, the live
|
||||
// connection, offline
|
||||
// AccessProvider platform bootstrap (venue, language, modules, keys) for that session;
|
||||
// retries by itself while the server can't be reached (unattended screens)
|
||||
// Terminal pairing → sign-in → the device's own app, or a "can't run" screen
|
||||
// The screen follows the device, not the URL; only the dev pages have routes.
|
||||
import { lazy, Suspense } from 'react'
|
||||
import { BrowserRouter, Route, Routes } from 'react-router-dom'
|
||||
import { AccessProvider } from '@xenia/access'
|
||||
import { createI18n } from '@xenia/i18n'
|
||||
import { Spinner } from '@xenia/ui'
|
||||
import client from './api/client'
|
||||
import AppHost from './apps/AppHost'
|
||||
import { deviceStore } from './device/storage'
|
||||
import StartScreen from './screens/StartScreen'
|
||||
import DeviceProvider from './device/DeviceProvider'
|
||||
import { useDevice } from './device/context'
|
||||
import Terminal from './screens/Terminal'
|
||||
|
||||
const i18n = createI18n({ defaultNS: 'terminal' })
|
||||
|
||||
@@ -20,27 +23,24 @@ const UiGallery = import.meta.env.DEV ? lazy(() => import('@xenia/ui/gallery'))
|
||||
const I18nSample = import.meta.env.DEV ? lazy(() => import('@xenia/i18n/sample')) : null
|
||||
|
||||
const loading = <main className="min-h-screen flex items-center justify-center"><Spinner /></main>
|
||||
const AUTO_RETRY_MS = 5_000
|
||||
|
||||
function AppRoute() {
|
||||
const { appKey } = useParams()
|
||||
return <AppHost appKey={appKey} />
|
||||
function Root() {
|
||||
const { sessionKey } = useDevice()
|
||||
return (
|
||||
<AccessProvider client={client} token={sessionKey} i18n={i18n} loading={loading} autoRetryMs={AUTO_RETRY_MS}>
|
||||
<Terminal />
|
||||
</AccessProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [token] = useState(() => deviceStore.sessionToken())
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
{UiGallery && <Route path="/ui-gallery" element={<Suspense fallback={null}><UiGallery /></Suspense>} />}
|
||||
{I18nSample && <Route path="/i18n-sample" element={<Suspense fallback={null}><I18nSample /></Suspense>} />}
|
||||
<Route path="*" element={
|
||||
<AccessProvider client={client} token={token} i18n={i18n} loading={loading}>
|
||||
<Routes>
|
||||
<Route path="/app/:appKey" element={<AppRoute />} />
|
||||
<Route path="*" element={<StartScreen />} />
|
||||
</Routes>
|
||||
</AccessProvider>
|
||||
} />
|
||||
<Route path="*" element={<DeviceProvider><Root /></DeviceProvider>} />
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user