Plan step 4.1. No visible change to layout or flows. - api/client.js on @xenia/api createApiClient (CS-8 baseURL, 401 → sign out, no answer → backend-offline, err.xenia, the manager-approval retry); the PIN login handles its own 401 (before, a wrong PIN reloaded the page). - <AccessProvider> at the root with an i18n instance: modules, permission keys, venue, language from bootstrap; who is signed in comes with it (no more /api/auth/me polling). packages/access: AccessProvider gains `cache` (the last bootstrap per session; used when the server can't be reached, `offline` in the context, keeps retrying) and `failed` (the app's own screen when there's nothing cached). The waiter caches per venue, shows its offline page (server search) on a first start without a server, retries every 5 s; ServerRediscovery and BundleSync run outside the bootstrap. - Role names → keys: the shift gate and the user menu use core.dashboard.access. - One shared, offline-cached read of the venue settings (api/venueSettings.js) instead of seven GET /api/settings/ calls; apiError() shows backend error codes in the user's language (17 places). - Lint: 78 errors → 0 (unused code, empty catches, two duplicate style keys, a component created during render, refs read during render → state, hooks after an early return); set-state-in-effect is a warning like the manager/terminal; lint in run-all. - Tests: tests/bootstrapCache.test.mjs; e2e browser: an offline restart stays signed in. Android rediscovery waits for what the screen shows instead of fixed sleeps: 10/10 three runs in a row (KI-009). Terminal 3.4 waits for both displays before the sale. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.3 KiB
JavaScript
30 lines
1.3 KiB
JavaScript
// The waiter's cached bootstrap (plan step 4.1): offline it starts with the last bootstrap of
|
|
// the same session only.
|
|
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
import { makeBootstrapCache } from '../src/logic/bootstrapCache.js'
|
|
|
|
function memory() {
|
|
const m = new Map()
|
|
return { getItem: k => (m.has(k) ? m.get(k) : null), setItem: (k, v) => m.set(k, String(v)) }
|
|
}
|
|
|
|
test('the same session gets its saved bootstrap back; another session or none gets nothing', () => {
|
|
const store = memory()
|
|
const cache = makeBootstrapCache(store, () => 'xenia:site:bootstrap')
|
|
assert.equal(cache.load('tok-a'), null)
|
|
cache.save('tok-a', { user: { id: 7 }, permissions: ['ordering.orders.open'] })
|
|
assert.deepEqual(cache.load('tok-a'), { user: { id: 7 }, permissions: ['ordering.orders.open'] })
|
|
assert.equal(cache.load('tok-b'), null, "another waiter's session never sees it")
|
|
assert.equal(cache.load(null), null)
|
|
cache.save(null, { user: null })
|
|
assert.deepEqual(cache.load(null), { user: null }, 'signed out: the anonymous bootstrap')
|
|
assert.equal(cache.load('tok-a'), null)
|
|
})
|
|
|
|
test('a damaged entry is ignored', () => {
|
|
const store = memory()
|
|
store.setItem('k', '{not json')
|
|
assert.equal(makeBootstrapCache(store, () => 'k').load('t'), null)
|
|
})
|