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:
@@ -32,5 +32,20 @@
|
||||
"notifications": "Ειδοποιήσεις",
|
||||
"backspace": "Διαγραφή",
|
||||
"pinProgress": "{{count}} από {{total}} ψηφία"
|
||||
},
|
||||
"override": {
|
||||
"title": "Έγκριση υπευθύνου",
|
||||
"body": "Αυτό χρειάζεται έγκριση υπευθύνου. Ο υπεύθυνος συμπληρώνει εδώ το όνομα χρήστη και το PIN του.",
|
||||
"action": "Ενέργεια",
|
||||
"username": "Όνομα χρήστη υπευθύνου",
|
||||
"pin": "PIN",
|
||||
"approve": "Έγκριση"
|
||||
},
|
||||
"access": {
|
||||
"moduleOffTitle": "Αυτή η λειτουργία είναι απενεργοποιημένη",
|
||||
"moduleOffBody": "Ένας υπεύθυνος μπορεί να την ενεργοποιήσει από τις Εφαρμογές.",
|
||||
"noAccessTitle": "Δεν έχετε πρόσβαση σε αυτή τη σελίδα",
|
||||
"noAccessBody": "Ζητήστε την από έναν υπεύθυνο, αν τη χρειάζεστε.",
|
||||
"loadFailed": "Δεν φορτώθηκαν οι ρυθμίσεις του καταστήματος"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"generic": "Κάτι πήγε στραβά. Δοκιμάστε ξανά.",
|
||||
"network": {
|
||||
"offline": "Δεν υπάρχει σύνδεση με τον διακομιστή. Ελέγξτε τη σύνδεση και δοκιμάστε ξανά."
|
||||
},
|
||||
"access": {
|
||||
"denied": "Δεν έχετε δικαίωμα για αυτή την ενέργεια ({{key}}).",
|
||||
"override_possible": "Αυτή την ενέργεια μπορεί να την εγκρίνει ένας υπεύθυνος ({{key}}).",
|
||||
"override_invalid": "Η έγκριση δεν ισχύει πια. Ζητήστε την ξανά από υπεύθυνο.",
|
||||
"not_overridable": "Το {{key}} δεν μπορεί να εγκριθεί από υπεύθυνο.",
|
||||
"approver_lacks_key": "Αυτός ο λογαριασμός δεν μπορεί να το εγκρίνει ({{key}}).",
|
||||
"override_rate_limited": "Πολλά λάθος PIN. Περιμένετε λίγα λεπτά και δοκιμάστε ξανά.",
|
||||
"unknown_key": "Δεν υπάρχει το δικαίωμα {{key}}.",
|
||||
"cannot_grant": "Μπορείτε να δώσετε μόνο δικαιώματα που έχετε κι εσείς ({{key}})."
|
||||
},
|
||||
"module": {
|
||||
"disabled": "Η λειτουργία {{module}} είναι απενεργοποιημένη.",
|
||||
"not_licensed": "Η άδεια του καταστήματος δεν περιλαμβάνει τη λειτουργία {{module}}.",
|
||||
"unknown": "Δεν υπάρχει η λειτουργία {{module}}.",
|
||||
"cannot_disable": "Η λειτουργία {{module}} είναι βασική και δεν απενεργοποιείται."
|
||||
},
|
||||
"license": {
|
||||
"limit_reached": "Φτάσατε το όριο της άδειας για {{module}} {{limit}} ({{max}}).",
|
||||
"expired": "Η άδεια έχει λήξει.",
|
||||
"history_limited": "Με αυτή την άδεια φαίνονται μόνο οι τελευταίες {{days}} ημέρες ({{module}})."
|
||||
},
|
||||
"auth": {
|
||||
"invalid_credentials": "Λάθος όνομα χρήστη ή κωδικός.",
|
||||
"session_ended": "Η σύνδεσή σας έληξε. Συνδεθείτε ξανά.",
|
||||
"session_exists": "Είστε ήδη συνδεδεμένοι σε άλλο {{client}}. Αποσυνδεθείτε πρώτα από εκεί.",
|
||||
"login_mode_not_allowed": "Αυτός ο τρόπος σύνδεσης δεν είναι ενεργός ({{mode}}).",
|
||||
"mode_needs_device": "Η σύνδεση με {{mode}} γίνεται μόνο σε συζευγμένη συσκευή.",
|
||||
"username_required": "Συμπληρώστε το όνομα χρήστη.",
|
||||
"client_not_allowed": "Αυτός ο λογαριασμός δεν μπορεί να χρησιμοποιήσει την εφαρμογή {{client}}.",
|
||||
"session_not_found": "Η σύνδεση δεν βρέθηκε.",
|
||||
"support_not_configured": "Η πρόσβαση υποστήριξης δεν έχει ρυθμιστεί σε αυτό το κατάστημα.",
|
||||
"support_code_invalid": "Ο κωδικός υποστήριξης είναι λάθος ή έχει λήξει. Ζητήστε νέο κωδικό πρόκλησης.",
|
||||
"support_rate_limited": "Πολλές αιτήσεις υποστήριξης. Περιμένετε λίγα λεπτά και δοκιμάστε ξανά."
|
||||
},
|
||||
"device": {
|
||||
"revoked": "Αυτή η συσκευή αφαιρέθηκε. Κάντε ξανά σύζευξη.",
|
||||
"not_paired": "Αυτή η συσκευή δεν είναι συζευγμένη με το κατάστημα.",
|
||||
"out_of_scope": "Μια συσκευή {{app}} δεν μπορεί να το κάνει αυτό ({{key}}).",
|
||||
"required": "Αυτή η σύνδεση ανήκει σε συζευγμένη συσκευή. Χρησιμοποιήστε την από εκείνη τη συσκευή.",
|
||||
"not_found": "Η συσκευή {{device_id}} δεν βρέθηκε.",
|
||||
"pair_code_invalid": "Ο κωδικός σύζευξης είναι λάθος ή έχει λήξει.",
|
||||
"pair_rate_limited": "Πολλές αιτήσεις σύζευξης. Περιμένετε λίγα λεπτά και δοκιμάστε ξανά.",
|
||||
"not_an_app": "Το {{app}} δεν είναι εφαρμογή που τρέχει σε συσκευή.",
|
||||
"login_mode_invalid": "Μια συσκευή {{app}} δεν μπορεί να χρησιμοποιήσει τον τρόπο σύνδεσης {{mode}}.",
|
||||
"link_invalid": "Η συσκευή {{device_id}} δεν μπορεί να συνδεθεί με αυτή τη συσκευή."
|
||||
},
|
||||
"validation": {
|
||||
"invalid": "Κάποια πεδία δεν είναι σωστά.",
|
||||
"unknown_language": "Μη υποστηριζόμενη γλώσσα: {{language}}.",
|
||||
"unknown_timezone": "Άγνωστη ζώνη ώρας: {{timezone}}.",
|
||||
"setting_value": "Η ρύθμιση {{key}} δεν μπορεί να πάρει την τιμή «{{value}}»."
|
||||
},
|
||||
"internal": {
|
||||
"error": "Κάτι πήγε στραβά στον διακομιστή (αίτημα {{request_id}})."
|
||||
},
|
||||
"order": {
|
||||
"not_found": "Η παραγγελία {{order_id}} δεν βρέθηκε."
|
||||
},
|
||||
"notification": {
|
||||
"not_found": "Η ειδοποίηση {{notification_id}} δεν βρέθηκε."
|
||||
},
|
||||
"catalog": {
|
||||
"unknown_category": "Δεν υπάρχει η κατηγορία {{category_id}}.",
|
||||
"primary_not_listed": "Η κύρια κατηγορία ({{category_id}}) πρέπει να είναι μία από τις κατηγορίες του προϊόντος."
|
||||
}
|
||||
}
|
||||
@@ -32,5 +32,20 @@
|
||||
"notifications": "Notifications",
|
||||
"backspace": "Delete",
|
||||
"pinProgress": "{{count}} of {{total}} digits entered"
|
||||
},
|
||||
"override": {
|
||||
"title": "Manager approval",
|
||||
"body": "This needs a manager's approval. A manager enters their username and PIN here.",
|
||||
"action": "Action",
|
||||
"username": "Manager username",
|
||||
"pin": "PIN",
|
||||
"approve": "Approve"
|
||||
},
|
||||
"access": {
|
||||
"moduleOffTitle": "This feature is turned off",
|
||||
"moduleOffBody": "A manager can turn it on in Apps.",
|
||||
"noAccessTitle": "You don't have access to this page",
|
||||
"noAccessBody": "Ask a manager if you need it.",
|
||||
"loadFailed": "Can't load the venue's settings"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"generic": "Something went wrong. Please try again.",
|
||||
"network": {
|
||||
"offline": "Can't reach the server. Check the connection and try again."
|
||||
},
|
||||
"access": {
|
||||
"denied": "You don't have permission to do this ({{key}}).",
|
||||
"override_possible": "A manager can approve this ({{key}}).",
|
||||
"override_invalid": "This approval isn't valid any more. Ask a manager again.",
|
||||
"not_overridable": "{{key}} can't be approved by a manager.",
|
||||
"approver_lacks_key": "That account can't approve this ({{key}}).",
|
||||
"override_rate_limited": "Too many wrong PINs. Wait a few minutes and try again.",
|
||||
"unknown_key": "There is no permission {{key}}.",
|
||||
"cannot_grant": "You can only give permissions you have yourself ({{key}})."
|
||||
},
|
||||
"module": {
|
||||
"disabled": "The {{module}} module is turned off.",
|
||||
"not_licensed": "This site's license doesn't include {{module}}.",
|
||||
"unknown": "There is no module {{module}}.",
|
||||
"cannot_disable": "{{module}} is part of the core and can't be turned off."
|
||||
},
|
||||
"license": {
|
||||
"limit_reached": "License limit reached for {{module}} {{limit}} ({{max}}).",
|
||||
"expired": "The license has expired.",
|
||||
"history_limited": "This license shows only the last {{days}} days of history ({{module}})."
|
||||
},
|
||||
"auth": {
|
||||
"invalid_credentials": "Wrong username or password.",
|
||||
"session_ended": "Your session has ended. Please log in again.",
|
||||
"session_exists": "You're already logged in on another {{client}}. Log out there first.",
|
||||
"login_mode_not_allowed": "This way of logging in isn't enabled ({{mode}}).",
|
||||
"mode_needs_device": "Logging in by {{mode}} only works on a paired device.",
|
||||
"username_required": "Enter your username.",
|
||||
"client_not_allowed": "This account can't use the {{client}} app.",
|
||||
"session_not_found": "Session not found.",
|
||||
"support_not_configured": "Support access isn't set up on this site.",
|
||||
"support_code_invalid": "That support code is wrong or has expired. Ask for a new challenge.",
|
||||
"support_rate_limited": "Too many support challenges. Wait a few minutes and try again."
|
||||
},
|
||||
"device": {
|
||||
"revoked": "This device was removed. Pair it again.",
|
||||
"not_paired": "This device isn't paired with the venue.",
|
||||
"out_of_scope": "A {{app}} device can't do this ({{key}}).",
|
||||
"required": "This login belongs to a paired device. Use it from that device.",
|
||||
"not_found": "Device {{device_id}} not found.",
|
||||
"pair_code_invalid": "That pairing code is wrong or has expired.",
|
||||
"pair_rate_limited": "Too many pairing requests. Wait a few minutes and try again.",
|
||||
"not_an_app": "{{app}} is not an app that runs on a device.",
|
||||
"login_mode_invalid": "A {{app}} device can't use the login mode {{mode}}.",
|
||||
"link_invalid": "Device {{device_id}} can't be linked to this device."
|
||||
},
|
||||
"validation": {
|
||||
"invalid": "Some fields are invalid.",
|
||||
"unknown_language": "Unsupported language: {{language}}.",
|
||||
"unknown_timezone": "Unknown time zone: {{timezone}}.",
|
||||
"setting_value": "{{key}} can't be set to \"{{value}}\"."
|
||||
},
|
||||
"internal": {
|
||||
"error": "Something went wrong on the server (request {{request_id}})."
|
||||
},
|
||||
"order": {
|
||||
"not_found": "Order {{order_id}} not found."
|
||||
},
|
||||
"notification": {
|
||||
"not_found": "Notification {{notification_id}} not found."
|
||||
},
|
||||
"catalog": {
|
||||
"unknown_category": "There is no category {{category_id}}.",
|
||||
"primary_not_listed": "The main category ({{category_id}}) must be one of the product's categories."
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,18 @@
|
||||
// Every locale file, bundled (they're small; no loading step, no flash of keys).
|
||||
// Layout (APPS_PLATFORM §8): locales/<lang>/<namespace>.json. English is the source.
|
||||
// Namespaces: common (shared words, component labels), dev (sample screens). Apps add
|
||||
// Namespaces: common (shared words, component labels), errors (backend error codes,
|
||||
// local_backend/core/errors.py; tests/errors.test.mjs keeps them complete), dev (sample screens). Apps add
|
||||
// theirs here as they're converted: manager, waiter, terminal, modules.
|
||||
import elCommon from '../locales/el/common.json'
|
||||
import elDev from '../locales/el/dev.json'
|
||||
import elErrors from '../locales/el/errors.json'
|
||||
import enCommon from '../locales/en/common.json'
|
||||
import enDev from '../locales/en/dev.json'
|
||||
import enErrors from '../locales/en/errors.json'
|
||||
|
||||
export const NAMESPACES = ['common', 'dev']
|
||||
export const NAMESPACES = ['common', 'errors', 'dev']
|
||||
|
||||
export const resources = {
|
||||
en: { common: enCommon, dev: enDev },
|
||||
el: { common: elCommon, dev: elDev },
|
||||
en: { common: enCommon, errors: enErrors, dev: enDev },
|
||||
el: { common: elCommon, errors: elErrors, dev: elDev },
|
||||
}
|
||||
|
||||
@@ -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