HenniOKF
Documentation

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

  1. In lib/permissions.ts add the name to the type Permission, with a comment saying what it stands for.
  2. Give it in PERMISSIONS to the roles that shall have it; a guest has only what GUEST lists.
  3. In tests/users.test.ts, "permissions", add a row to table with exactly these roles (null for a guest). The test checks every role and the guest.
  4. Update the tables in spec/users.md and 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

  1. app/<path>/page.tsx as a server component with export const dynamic = "force-dynamic".
  2. First await pageRequires("<permission>", "/<path>") from lib/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).
  3. Texts with const { t } = await getDictionary(), from both dictionaries. Exactly one h1. The title of the tab through generateMetadata.
  4. Put the address into one of the lists in e2e/shell.spec.ts: GUEST_PAGES, REVIEWER_PAGES or ADMIN_PAGES. Then the tests check shell and axe.
  5. If it belongs in the menu: an item in items in app/layout.tsx, with a permission if not everyone shall see it.
  6. Its row in spec/routes.md and Routes.

Add a page of the administration

Like a page, plus:

  1. Above the title <BackToSettings t={t} /> from components/settings.tsx.
  2. The address in SETTINGS_PATHS in components/menu.tsx. Then the gear counts as current on it.
  3. A tile, see below.
  4. The address in ADMIN_PAGES in e2e/shell.spec.ts.

A tile under settings

  1. In areas() in components/settings.tsx an entry with title, text, href and image. Title and text come from the dictionaries.
  2. The image as WebP with 960 × 640 pixels under public/settings/. It requires signing in like every file the matcher does not leave out.

Add a route

  1. app/<path>/route.ts with export const runtime = "nodejs" and export const dynamic = "force-dynamic".

  2. Export only the methods that shall exist. For all others Next.js answers 405.

  3. First requirePermission(request, "<permission>") from lib/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.

  4. Check inputs with Zod. Messages of the route stay English.

  5. A test that calls the exported function directly with a Request.

  6. Its row in spec/routes.md and Routes.

Add an open path

Only when something really must be reachable without signing in.

  • An address of the application: in openPath() in lib/access.ts. The function decides by the path alone.
  • Static files from public/: in the matcher in proxy.ts. An image of the sign-in page belongs into public/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

  1. The name in ENV in lib/env.ts, with the prefix HENNIOKF_. tests/env.test.ts checks the prefix.
  2. A function that checks the value with Zod and gives a default otherwise.
  3. A line with an explanation in .env.example, never with a real value.
  4. A row on /status in app/status/page.tsx, with its label in both dictionaries; for a secret only "set" or "not set".
  5. If the VPS needs it: in docker/compose.vps.yml under environment and in docker/vps.env.example.
  6. Restart the running development server.
  7. Update spec/data.md, Environment variables and Variables.

A directory in the root directory

  1. An entry in DIRS in lib/env.ts. ensureDirs() then creates it at start.
  2. A function for its path, with /*turbopackIgnore: true*/ in front of the computed part, as in usersDir().
  3. A row on /status.
  4. If it is not derived: in PARTS in docker/backup.sh, every SQLite file in it also in DATABASES.
  5. Update the tables in spec/data.md.

A stricter header for a route

For example for files that must not run any script:

  1. The path pattern in STRICT_PATHS in next.config.mjs, such as "/files/:path*". For every pattern a rule with STRICT_CSP follows the general rule.
  2. The route sets the same value as STRICT_CSP itself as the header content-security-policy of 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.

  1. Read the part of the SPEC here first; it decides where it differs.
  2. Take over only what concerns OKF bundles. DYXML loader, renderer and findings stay out.
  3. Translate identifiers, file names, comments and texts to English; texts of the UI go into both dictionaries.
  4. 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).
  5. Port its tests too, translated, and add the new pages to e2e/shell.spec.ts.

Next: Writing documentation.