Guide
Recipes for extending
Step by step: a permission, a page, a route, an open path, a tile, a variable, a directory, a stricter header, an area of the docs.
Before every recipe
If the change deviates from the SPEC (SPEC.md and the affected part under
spec/), change it there first. If what the docs describe changes, update
the page under docs/. Every new word of the UI goes into both
dictionaries, see Texts in two languages. At the end always:
npm run check
npm run test:e2e
Add a permission
- In
lib/permissions.tsadd the name to the typePermission, with a comment saying what it stands for. - Give it in
PERMISSIONSto the roles that shall have it; a guest has only whatGUESTlists. - In
tests/users.test.ts, "permissions", add a row totablewith exactly these roles (nullfor a guest). The test checks every role and the guest. - Update the tables in
spec/users.mdand Permissions.
A new role needs more: an entry in ROLES, a role in the plugin admin in
create() in lib/users.ts, its name and sentence under roles in both
dictionaries and a case per permission.
Add a page
app/<path>/page.tsxas a server component withexport const dynamic = "force-dynamic".- First
await pageRequires("<permission>", "/<path>")fromlib/page-access.ts. A guest then goes to/sign-in, whoever lacks the permission to the start page. A public page skips that and adds its path to the open paths (see below). - Texts with
const { t } = await getDictionary(), from both dictionaries. Exactly oneh1. The title of the tab throughgenerateMetadata. - Put the address into one of the lists in
e2e/shell.spec.ts:GUEST_PAGES,REVIEWER_PAGESorADMIN_PAGES. Then the tests check shell and axe. - If it belongs in the menu: an item in
itemsinapp/layout.tsx, with apermissionif not everyone shall see it. - Its row in
spec/routes.mdand Routes.
Add a page of the administration
Like a page, plus:
- Above the title
<BackToSettings t={t} />fromcomponents/settings.tsx. - The address in
SETTINGS_PATHSincomponents/menu.tsx. Then the gear counts as current on it. - A tile, see below.
- The address in
ADMIN_PAGESine2e/shell.spec.ts.
A tile under settings
- In
areas()incomponents/settings.tsxan entry withtitle,text,hrefandimage. Title and text come from the dictionaries. - The image as WebP with 960 × 640 pixels under
public/settings/. It requires signing in like every file thematcherdoes not leave out.
Add a route
-
app/<path>/route.tswithexport const runtime = "nodejs"andexport const dynamic = "force-dynamic". -
Export only the methods that shall exist. For all others Next.js answers 405.
-
First
requirePermission(request, "<permission>")fromlib/access.ts:const { who, refusal } = await requirePermission(request, "read"); if (refusal) return refusal;It answers without signing in with 401, without the permission with 403, and checks the origin for a session that wants to change something.
-
Check inputs with Zod. Messages of the route stay English.
-
A test that calls the exported function directly with a
Request. -
Its row in
spec/routes.mdand Routes.
Add an open path
Only when something really must be reachable without signing in.
- An address of the application: in
openPath()inlib/access.ts. The function decides by the path alone. - Static files from
public/: in thematcherinproxy.ts. An image of the sign-in page belongs intopublic/sign-in/, which is open already.
Add a case to tests/access.test.ts (in "leaves reading … open" or in the
test of the matcher) and to e2e/access.spec.ts ("open are …"). Then the
table in spec/security.md and Security.
After a change to proxy.ts restart the development server.
Add an environment variable
- The name in
ENVinlib/env.ts, with the prefixHENNIOKF_.tests/env.test.tschecks the prefix. - A function that checks the value with Zod and gives a default otherwise.
- A line with an explanation in
.env.example, never with a real value. - A row on
/statusinapp/status/page.tsx, with its label in both dictionaries; for a secret only "set" or "not set". - If the VPS needs it: in
docker/compose.vps.ymlunderenvironmentand indocker/vps.env.example. - Restart the running development server.
- Update
spec/data.md, Environment variables and Variables.
A directory in the root directory
- An entry in
DIRSinlib/env.ts.ensureDirs()then creates it at start. - A function for its path, with
/*turbopackIgnore: true*/in front of the computed part, as inusersDir(). - A row on
/status. - If it is not derived: in
PARTSindocker/backup.sh, every SQLite file in it also inDATABASES. - Update the tables in
spec/data.md.
A stricter header for a route
For example for files that must not run any script:
- The path pattern in
STRICT_PATHSinnext.config.mjs, such as"/files/:path*". For every pattern a rule withSTRICT_CSPfollows the general rule. - The route sets the same value as
STRICT_CSPitself as the headercontent-security-policyof its answer.
tests/security-headers.test.ts checks the rules and their order. Without
the rule of its own the general one would override the header of the route,
because Next.js sends one value per header.
Add an area of the docs
See Writing documentation: a directory with an
index.md, a line in docs/index.md and the entry in AREAS in
tests/docs.test.ts.
Port a feature from HenniDYXML
The later phases take features from HenniDYXML. context/origin.md lists its
files per phase.
- Read the part of the SPEC here first; it decides where it differs.
- Take over only what concerns OKF bundles. DYXML loader, renderer and findings stay out.
- Translate identifiers, file names, comments and texts to English; texts of the UI go into both dictionaries.
- Map the roles: the User of HenniDYXML is the reviewer, its Admin's content
work goes to the editor, its configuration stays with the admin
(
spec/users.md). - Port its tests too, translated, and add the new pages to
e2e/shell.spec.ts.
Next: Writing documentation.