- KDS manifest: 23 typed settings (prep zone, board, waiting-time minutes and colours,
behaviour) replacing the KDS page's localStorage settings.
- ConfigField: colour type, "after" ordering (warning < late < flash), groups for the
manager's dialogs, ".none" text for an empty ref choice.
- routers/kds.py: a KDS device gets only its zone's orders, prints to its zone by default
and signs waiter messages with its zone/name. New GET /api/kds/context and
POST /api/kds/orders/{id}/retry-print so the screen never leaves its kds.* scope.
Unused v1 /items and /items/{id}/status endpoints removed (D-21).
- PATCH /api/devices/me/config: a screen changes its own settings when the signed-in
person holds core.devices.manage.
- Manager Devices dialogs: settings in sections, colour pickers, "All zones".
- Tests: test_kds_device.py, colour/ordered fields; terminal.mjs scope + zone checks;
manager.mjs settings sections; stack.mjs detaches the non-LAN network before the
restart check (one flaky 403).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
4.4 KiB
Python
111 lines
4.4 KiB
Python
"""What a module manifest is made of (APPS_PLATFORM §4.1, D-19).
|
|
|
|
A module = one thing the venue can have or not: a manager feature (tabs, CRM...), an
|
|
app a device runs (KDS, POS...), or an integration (caller ID, fiscal...). Everything
|
|
is a module, including `core`. Each one is described by modules/<key>/manifest.py,
|
|
which exports MODULE = Module(...).
|
|
|
|
Agent notes:
|
|
- Display text (name, descriptions) is the English source. The i18n key is derived:
|
|
module.<key>.name, perm.<perm key>, limit.<key>.<limit>, setting.<setting key>.
|
|
- `routers` lists Mounts: the module's existing router objects and their URL prefix.
|
|
main.py mounts every Mount from the registry; non-core mounts get
|
|
Depends(module_required(key)) so a disabled module answers `module.disabled`.
|
|
- `workers` are "package.module:function" strings naming async functions that run
|
|
forever. The supervisor imports and starts them while the module is effective and
|
|
cancels them when it isn't. Strings keep manifests cheap to import.
|
|
- `Perm(..., overridable=True)`: a user without the key gets access.override_possible
|
|
and can retry with a manager's one-time approval (core/access/override.py, D-10).
|
|
- Permission keys are "<module>.<area>.<action>" (or "<module>.<action>"). Role lists
|
|
are the default role template (superadmin always has every key, D-7, so it's
|
|
never listed).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Literal, Optional
|
|
|
|
Kind = Literal["core", "feature", "app", "integration"]
|
|
SettingType = Literal["bool", "int", "str", "json", "enum"]
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Perm:
|
|
key: str
|
|
description: str
|
|
roles: tuple[str, ...] = ()
|
|
overridable: bool = False # a manager may approve it once with their PIN (D-10)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Limit:
|
|
key: str
|
|
description: str
|
|
free: Optional[int] = 0 # value in the free tier (D-5); None = unlimited
|
|
licensed_default: Optional[int] = None # value when licensed but the token sets none; None = unlimited
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class SettingDef:
|
|
key: str
|
|
default: str # stored as text in pos_settings, like every setting
|
|
description: str
|
|
type: SettingType = "str"
|
|
choices: tuple[str, ...] = () # for type "enum"
|
|
|
|
|
|
ConfigType = Literal["bool", "int", "str", "enum", "ref", "color"]
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ConfigField:
|
|
"""One setting of a device running an app (plan step 3.1a). Stored in devices.config,
|
|
validated by core/modules/device_config.py, edited in the manager's pair/edit dialogs.
|
|
Texts: modules:<app>.config.<key>.label (+ .hint optional, + .choices.<value> for each
|
|
choice, + .none for a ref's empty choice; groups: modules:<app>.config_groups.<group>),
|
|
checked by tests/test_module_texts.py."""
|
|
key: str
|
|
type: ConfigType
|
|
default: object = None
|
|
choices: tuple = () # enum, or int limited to these values
|
|
min: Optional[int] = None # int
|
|
max: Optional[int] = None # int
|
|
choices_from: Optional[str] = None # ref: "prep_zones" | "devices:<app_key>"; value = id or None
|
|
group: Optional[str] = None # section in the manager's dialogs (3.2a)
|
|
after: Optional[str] = None # int: must be greater than this other field (age thresholds)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class DeviceApp:
|
|
"""For kind="app" modules that run on a paired device (step 1.8, D-8)."""
|
|
login_modes: tuple[str, ...] = ("pin", "tap", "password")
|
|
scope: tuple[str, ...] = () # permission-key patterns the device token may use
|
|
config: tuple[ConfigField, ...] = () # per-device settings (3.1a)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Mount:
|
|
module: str # python import path, e.g. "routers.tabs"
|
|
prefix: str # URL prefix, e.g. "/api/tabs"
|
|
attr: str = "router" # attribute holding the APIRouter
|
|
tags: tuple[str, ...] = ()
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Module:
|
|
key: str
|
|
kind: Kind
|
|
name: str
|
|
description: str = ""
|
|
depends: tuple[str, ...] = ()
|
|
permissions: tuple[Perm, ...] = ()
|
|
limits: tuple[Limit, ...] = ()
|
|
settings: tuple[SettingDef, ...] = ()
|
|
device_app: Optional[DeviceApp] = None
|
|
routers: tuple[Mount, ...] = ()
|
|
workers: tuple[str, ...] = () # "package.module:async_function", imported when started
|
|
|
|
@property
|
|
def can_disable(self) -> bool:
|
|
return self.kind != "core"
|