feat(modules): venue-module registry — entitled ∩ activated, requireModule, Setup panel
Groundwork for the Car Wash pilot (wiki/decisions/venue-modules.md, build-order
steps 1 + 3). No Car Wash code yet; validation is the first module behind the
seam, unchanged in behaviour.
- @parking/shared: MODULE_IDS, ModuleManifest, MODULES (parking required;
validation dependsOn parking), parseEntitledModules / resolveModuleActivation
/ effectiveModules as pure functions.
- DB: site_config.modules_json (migration 0026, hand-written + journal;
additive, nullable = everything entitled).
- Server: modules.ts (entitledModules from MODULES_ENTITLED env, activated
from site_config, effective set, requireModule preHandler → 403
module_disabled); modules/index.ts registers folder-based modules by
iterating the registry (modules/validation); site-config GET exposes
modules/modulesEntitled/modulesActivated, PUT takes the full desired set,
enforces entitlement + dependency rules (400 with reason) and signs one
config_change per module that actually flips; /api/auth/me carries the
effective set; validation routes guarded requireModule → requirePermission.
- Web: lib/modules.ts + modules/{index,validation}; router.tsx spreads
WEB_MODULES into nav + route tree (validate route no longer named there);
Setup → Site "Modules" panel (required shown disabled, dependencies as
hints, server refusal shown verbatim); validation sections + programs fetch
gated on the module; App invalidates the router whenever the session
changes (route-context consumers only re-read on navigation — the nav was
stale after a flip, and after every other setUser too).
- Lavazh validation station retired (STATIONS = ["bar"]; rows untouched).
- Deploy: MODULES_ENTITLED=parking,validation explicit in both booth stacks;
documented in .env.example.
- Tests: modules.test.ts (7); suite 329/329; web build clean; Playwright
round-trip on /setup/site verified live.
Claude-Session: https://claude.ai/code/session_01FWncR69HgGPuei1dLrW3cU
This commit is contained in:
@@ -56,6 +56,16 @@ export const en: Catalog = {
|
||||
changeServer: "Change server",
|
||||
changeServerConfirm: "This signs you out and asks for a new server address on next launch. Continue?",
|
||||
},
|
||||
modules: {
|
||||
sectionTitle: "Modules",
|
||||
sectionHint: "Optional parts of the system this site uses. What can be switched on here is decided at deployment; switching one off hides it and refuses its actions — nothing is deleted.",
|
||||
required: "Always on.",
|
||||
requires: "Requires: {{deps}}",
|
||||
name: {
|
||||
parking: "Parking",
|
||||
validation: "Merchant validations (Bar)",
|
||||
},
|
||||
},
|
||||
update: {
|
||||
available: "Update available",
|
||||
prompt: "Version {{version}} is available. Install now and restart? (Installing requires the administrator password.)",
|
||||
@@ -756,9 +766,8 @@ export const en: Catalog = {
|
||||
val: {
|
||||
// /setup/site
|
||||
sectionTitle: "Merchant validations",
|
||||
sectionHint: "An in-park merchant (bar / car-wash) scans the customer's ticket and grants a parking discount — payment and the receipt always stay at the booth.",
|
||||
sectionHint: "An in-park merchant (the bar) scans the customer's ticket and grants a parking discount — payment and the receipt always stay at the booth.",
|
||||
enableBar: "Bar",
|
||||
enableLavazh: "Car wash",
|
||||
labelName: "Receipt label",
|
||||
labelNamePh: "e.g. Car wash — first hour free",
|
||||
mode: "Discount type",
|
||||
|
||||
@@ -59,6 +59,16 @@ export const sq = {
|
||||
changeServer: "Ndrysho serverin",
|
||||
changeServerConfirm: "Kjo do t'ju dalë nga sesioni dhe do kërkojë adresë të re serveri në hapjen tjetër. Vazhdo?",
|
||||
},
|
||||
modules: {
|
||||
sectionTitle: "Modulet",
|
||||
sectionHint: "Pjesët opsionale të sistemit që përdor ky park. Çfarë mund të aktivizohet këtu vendoset gjatë instalimit; çaktivizimi e fsheh modulin dhe refuzon veprimet e tij — asgjë nuk fshihet.",
|
||||
required: "Gjithmonë aktiv.",
|
||||
requires: "Kërkon: {{deps}}",
|
||||
name: {
|
||||
parking: "Parkimi",
|
||||
validation: "Validime tregtare (Bar)",
|
||||
},
|
||||
},
|
||||
update: {
|
||||
available: "Përditësim i disponueshëm",
|
||||
prompt: "Versioni {{version}} është i disponueshëm. Ta instaloj tani dhe ta rinis? (Instalimi kërkon fjalëkalimin e administratorit.)",
|
||||
@@ -769,9 +779,8 @@ export const sq = {
|
||||
val: {
|
||||
// /setup/site
|
||||
sectionTitle: "Validime tregtare",
|
||||
sectionHint: "Shërbime të tjera brenda parkut (bar / lavazh) skanojnë biletën e hyrjes dhe bëjnë zbritje — pagesa dhe fatura bëhen në kabinë.",
|
||||
sectionHint: "Bari brenda parkut skanon biletën e hyrjes dhe bën zbritje — pagesa dhe fatura bëhen në kabinë.",
|
||||
enableBar: "Bar",
|
||||
enableLavazh: "Lavazh",
|
||||
labelName: "Etiketa në faturë",
|
||||
labelNamePh: "p.sh. Lavazh — 1 orë falas",
|
||||
mode: "Lloji i zbritjes",
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import type { AnyRoute } from "@tanstack/react-router";
|
||||
import type { ModuleId } from "@parking/shared";
|
||||
import type { Permission, SessionUser } from "../api.js";
|
||||
import type { rootRoute } from "../router.js";
|
||||
|
||||
/** The app's root route (type only — a runtime import here would be a cycle). */
|
||||
export type RootRoute = typeof rootRoute;
|
||||
|
||||
// Venue modules — the web side. The server ENFORCES the effective set
|
||||
// (requireModule); this file only decides what to SHOW. A module's nav entries and
|
||||
// routes live in its own folder (apps/web/src/modules/<id>/index.tsx) and are
|
||||
// discovered through WEB_MODULES below, so router.tsx never names a module's screens.
|
||||
// See wiki/decisions/venue-modules.md.
|
||||
|
||||
/** Is the module effective for this session? `modules` comes from /api/auth/me
|
||||
* (entitled ∩ activated); a server too old to send it hides every module rather
|
||||
* than showing something it would 403 — fail closed on the display side too. */
|
||||
export function moduleOn(user: SessionUser | null, id: ModuleId): boolean {
|
||||
return !!user && Array.isArray(user.modules) && user.modules.includes(id);
|
||||
}
|
||||
|
||||
export interface WebModuleNav {
|
||||
to: string;
|
||||
/** i18n key for the header label. */
|
||||
labelKey: string;
|
||||
/** Shown only if the role holds this permission (and the module is on). */
|
||||
perm: Permission;
|
||||
}
|
||||
|
||||
export interface WebModule {
|
||||
id: ModuleId;
|
||||
/** Header nav entries, in display order. */
|
||||
nav: readonly WebModuleNav[];
|
||||
/** Build this module's routes under the given root. Called once at router
|
||||
* assembly; each route's own beforeLoad must gate on moduleOn + permission. */
|
||||
routes(root: RootRoute): AnyRoute[];
|
||||
}
|
||||
Reference in New Issue
Block a user