Skip to content

Portal modules

Every page of the platform portal is a module that an implementer can add, replace or hide; the shell does routing, navigation, sign-in, permission and capability gating, error display, translations and theming. This page is for implementers who build their own portal from the open source repository (pryv/app-web-platform-portal, React, TypeScript, Vite, Tailwind, BSD-3-Clause); its README.md is the reference for the details. A custom build is served like the published one, with static: (Serving the portal).

A module is one folder under src/modules/<id>/ exporting a manifest. It never handles a credential: the shell gives it routing, navigation, gating, a context and an API client.

src/modules/x-acme-billing/manifest.tsx
import { defineModule } from "../../contract";
import en from "./locales/en.json";
import Billing from "./Billing";
export default defineModule({
id: "x-acme-billing", // implementers' modules use the x- prefix
space: "admin", // "admin" or "developer"
nav: [{ label: "x-acme-billing:nav", path: "billing", order: 50 }],
routes: [{ path: "billing", element: <Billing /> }],
requires: {
capabilities: ["config"], // all offered by the current core
permissions: ["config:read"], // all granted on the current core
},
locales: { en }, // loaded under the namespace "x-acme-billing"
});

Inside the module, usePortal() gives the current core, the list of cores, the portal context, readOnly (a required capability is locked readonly on this core: disable the forms) and api:

  • api.admin(path, init): a call on <current core>/system/<path> with the administrator session; the shell handles step-up;
  • api.adminOn(core, path, init): the same on another core, for modules that read several cores;
  • api.account(path, init): a call on the signed-in account’s own API endpoint (the developer space’s way in);
  • api.setup(path, init), api.setupFirstAdmin(): the setup steps, with the setup session.

Errors arrive as ApiError (status, id, data, stepUpRequired, mfaRequired, notHere when the core’s admin gate refuses this administrator there). The contract also gives the UI kit (buttons, form fields, tables, notices, modals, a confirmation dialog: never the browser’s native confirm, alert or prompt), the fan-out helpers (one call and one section per core) and serverNames (the server’s roles, permissions, capabilities, step-up and platform-only permissions). Everything a module imports comes from src/contract/.

To Do
add a module create its folder, add one line to MODULES in src/modules.ts, add each route to pages in src/routes.json (developer routes as developer/<path>); a test refuses a list that disagrees with the modules
replace a module point its line in src/modules.ts at your folder; keep its id when the platforms you serve switch it off or order it by that id
hide a module on one platform on the core, list its id in portal.modules.disabled (portal settings): no rebuild
remove it from your build delete its line in src/modules.ts and its routes in src/routes.json
contribute a setup step wizardStep: { order, optional } with requires.setup: "pending" (admin space); a step that needs the signed-in first administrator says signIn: true
add an after-setup entry afterSetup: [{ label, hint, path, order }]
mock its routes src/modules/<id>/mock.ts, found by the in-memory mock (npm run dev:mock), never in a regular build

Routes have no path parameters, so that every route is a known page of the static build. What a page is about goes in the URL fragment: selectionPath("/users/account", { core, username }) gives users/account#core=...&username=..., read back with useSelection(). Filters and page numbers may use the query string.

The registry refuses, at start and in the tests: an id declared twice, a malformed id or path, a path parameter, two routes on one address (or on a shell page: setup, developer, claim, my-roles, after-setup), a navigation entry pointing to no route of its module, permission or capability requirements in the developer space (it runs on a plain account session, without a portal context) and on setup steps.

Gate From Effect
space switched off the core’s portal settings spaces the space’s pages say so
module switched off portal settings modules.disabled no navigation entry, its pages say so
requires.setup GET /system/setup/status setup steps only while pending, the rest once ready
requires.capabilities portal context capabilities (this core) absent from navigation, “not available”
requires.permissions portal context permissions (this core, this administrator) absent from navigation, “not available” (with the reason when it is the core’s local policy)
lockdown hidden on a required capability portal context lockdown absent from navigation
lockdown readonly on a required capability portal context lockdown shown with a notice, readOnly: true

Permission and capability names are the server’s, a list that only grows (permissions, lockdown capabilities). The build keeps a snapshot of the core’s administration contract (src/shell/server-snapshot.json, written from a core checkout by node scripts/server-snapshot.mjs <open-pryv.io checkout>, --check to compare): the tests refuse a module that requires a name outside it (it would be gated on every core), a shell call that is not a route of the core, and a mock route whose permission differs from the core’s. The gates are a convenience: the core checks every call.

From open-pryv.io 2.0.0-rc.93 a platform names capabilities of its own, for its own modules:

portal:
customCapabilities: [x-billing, x-reports]

Each name is x- followed by 1 to 40 of a-z 0-9 -, at most 50 names, the same on every core; an invalid list stops the boot and bin/check-config.js reports it. The core offers them in the portal context after the built-in capabilities, so a module gated on requires.capabilities: ["x-billing"] shows only on platforms that list it (the portal’s tests accept any x- name besides the server’s). No server route reads them: what the module calls must still be allowed by the core (for example routes of your own service, or core routes under their own permissions).

A fork adapts the portal by replacing a few files, each with a stable interface:

File Replace with Keep stable
src/modules.ts, src/routes.json your module list MODULES, pages
src/brand.tsx, src/brand.css product and portal names, logo, fonts (bundled, never from another host) brand, Logo
src/index.css :root tokens your colours the --color-* names
src/shell/api/ your own client the PortalApi interface
public/settings.json your deployment’s defaults its keys
src/contract/ nothing: it is the interface modules depend on everything
Terminal window
npm install
npm run dev:mock # against the in-memory mock (no core needed)
npm run dev # against a real platform (platform.apiRoot in public/settings.json), behind backloop.dev
npm test
npm run lint
npm run typecheck
npm run build # dist/, one page per route, with the CSP check
node scripts/server-snapshot.mjs ../open-pryv.io --check

npm run build fails when a page, a style sheet or a script needs more than the policy cores add on the portal site (no inline script or style, no data: URL, nothing from another host). Serve the result with a static: hosted site, as for a downloaded release (static:).