feat(api): @xenia/api + @xenia/access; the manager logs in and loads bootstrap through them
Platform-v2 step 2.5 (APPS_PLATFORM D-7, D-10, §9): - @xenia/api: createApiClient (app passes its axios; session/device headers, err.xenia codes, 401/offline hooks, manager-override retry: ask PIN, grant, retry once with X-Xenia-Override); errorMessage; createLiveClient = the waiter's WebSocket logic (cursor replay, backoff, online) moved unchanged - @xenia/access: AccessProvider (bootstrap per session token, language + venue formats, translated ui labels, approval dialog), useAccess/useCan/ useModule, Can, RequireModule - i18n: errors namespace for every backend code (en/el, test vs core/errors.py), override/access texts - manager: client from createApiClient, AccessProvider in a layout route, /kds behind RequireModule, usePermissions from bootstrap keys; login and unlock no longer treat a wrong password/PIN as "session ended" (a wrong lock-screen PIN used to log the manager out) - waiter: useWebSocket is a thin wrapper over createLiveClient - tests: api/access unit tests; new e2e suite tests/e2e/manager.mjs; CS-18 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// Every error code the backend can return has a text in every language, using only
|
||||
// params the backend sends (local_backend/core/errors.py CODES).
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { test } from 'node:test'
|
||||
|
||||
const py = readFileSync(new URL('../../../local_backend/core/errors.py', import.meta.url), 'utf8')
|
||||
const start = py.indexOf('CODES: dict')
|
||||
const block = py.slice(start, py.indexOf('\n}\n', start))
|
||||
const ENTRY = /^\s*"([\w.]+)":\s*\(\d+,\s*"((?:[^"\\]|\\.)*)"\)/gm
|
||||
const codes = Object.fromEntries([...block.matchAll(ENTRY)].map(m => [m[1], m[2]]))
|
||||
const flat = (o, p = '') => Object.entries(o).flatMap(([k, v]) => (typeof v === 'object' ? flat(v, `${p}${k}.`) : [[`${p}${k}`, v]]))
|
||||
const load = lang => Object.fromEntries(flat(JSON.parse(readFileSync(new URL(`../locales/${lang}/errors.json`, import.meta.url), 'utf8'))))
|
||||
|
||||
test('the backend registry was read', () => {
|
||||
assert.ok(Object.keys(codes).length >= 40, String(Object.keys(codes).length))
|
||||
assert.ok('order.not_found' in codes)
|
||||
})
|
||||
|
||||
for (const lang of ['en', 'el']) {
|
||||
test(`${lang}: every backend code has a text with backend params only`, () => {
|
||||
const texts = load(lang)
|
||||
const missing = Object.keys(codes).filter(c => !(c in texts))
|
||||
assert.deepEqual(missing, [])
|
||||
const bad = Object.keys(codes).filter(c => {
|
||||
const params = new Set([...codes[c].matchAll(/\{(\w+)/g)].map(m => m[1]))
|
||||
return [...texts[c].matchAll(/\{\{\s*(\w+)/g)].some(m => !params.has(m[1]))
|
||||
})
|
||||
assert.deepEqual(bad, [], 'placeholders the backend never sends')
|
||||
assert.ok(texts.generic && texts['network.offline'])
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user