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 @@
|
||||
import { useContext } from 'react'
|
||||
import { AccessContext } from './context.js'
|
||||
|
||||
/**
|
||||
* Everything bootstrap said (GET /api/platform/bootstrap):
|
||||
* { venue, user, permissions (Set), modules (Set), license, languages, bootstrap (raw), refresh() }
|
||||
* permissions: the keys the signed-in user holds, only for modules that are on (superadmin: all).
|
||||
*/
|
||||
export function useAccess() {
|
||||
const ctx = useContext(AccessContext)
|
||||
if (!ctx) throw new Error('useAccess() needs an <AccessProvider> above it')
|
||||
return ctx
|
||||
}
|
||||
|
||||
/** Is this module licensed and turned on? */
|
||||
export function useModule(key) {
|
||||
return useAccess().modules.has(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* Does the signed-in user hold this key? With a list, ANY of them (like the backend's
|
||||
* require_any); { all: true } for all of them. Hides UI only: the backend always checks too.
|
||||
*/
|
||||
export function useCan(keys, { all = false } = {}) {
|
||||
return can(useAccess().permissions, keys, all)
|
||||
}
|
||||
|
||||
export function can(permissions, keys, all = false) {
|
||||
const list = Array.isArray(keys) ? keys : [keys]
|
||||
if (!list.length) return true
|
||||
return all ? list.every(k => permissions.has(k)) : list.some(k => permissions.has(k))
|
||||
}
|
||||
Reference in New Issue
Block a user