The manifest
export default defineModule({
name: 'appointments', // kebab-case; prefixes everything below
version: '0.1.0',
shade: '^0.1.0', // the SHADE versions it works with
description: '…',
// What it may do: what its parts need, declared; see Capabilities
capabilities: { http: {}, email: {}, accounts: {}, personalData: {} },
// requires: { website: '^1.0.0' } modules it builds on, within one major version: 1.2.0, ^1.2.0, ~1.2.0
// shares: { collections: [...] } its collections the modules that require it may use
// contributes: { website: { starters: [...] } } data for other modules, if they are on
// provides: defineModuleCalls(…) calls the modules that require it may make (see Calls between modules)
// alerts: { rules: [...] } security alert rules of its own (see Alert rules)
// accepts: { starters: schema } what other modules may hand it (trusted modules only)
db: { tables: { appointmentsBookings }, migrationsFolder: 'migrations' },
server: { routes }, // /api/packages/appointments/… and /api/v1/account/appointments/… (public, account)
admin: { pages: [{ path: '/modules/appointments/appointments', file: 'admin/AppointmentsPage.vue' }], sidebar: [...] },
permissions: { actions: APPOINTMENTS_ACTIONS, grants: { editor: [...] } },
guards: async (ctx) => [...], // block or warn before it is switched off
retention: [...], personalData: [...]
})
defineModule checks at compile time that action names start with the module name and are declared. The
capabilities declaration says what the module may do: the loader refuses a capability or
parameter SHADE doesn't know and a required one the module's trust doesn't allow, and shade-module build refuses a
manifest whose parts need one it doesn't declare.
The kernel declares the manifest's core parts; each feature adds its feature part (its manifest.ts: settings,
collections, publishChecks, dataSources, mcp, retention, personalData, consent) and
checks and registers it. The SDK loads them all, so a manifest type-checks with every part; a key no part owns is
refused ("widgets" is not a part SHADE knows) instead of ignored.
A trusted module's ctx.db runs as the module, and row-level security lets it reach only the tables in its own
db.tables and db.collectionTables: core's data it reads and changes through the SDK's services, which run as the
part that owns it. Besides its own tables it reads only what its tables declare a need for, and writes none of it:
contacts, when one of its tables refers to a contact (contactReference), for the SDK'scontactEmail,contactConfirmedandownedByContact;- the views
accounts_for_packages(an account's id and address) andorganisation_members_for_packages, when one of its tables refers to an account or an organisation (accountReference,organisationReference), forownedByandownedByOrganisation; - the view
entry_trash_for_packages(a trashed entry's collection and id), when it has collections, fornotInTrash.
SHADE opens a module's tables to three of its own parts only: the module manager reads and deletes them (the backup
before an uninstall, the instance export, the clean-up), content works on its collection tables and reads the tables
keptVersions names, and accounts read a scope table, a profile table, or a table whose rows go with an organisation
(organisationReference without keep: deleting an organisation first counts them). This guards against mistakes,
not against the module: a trusted module runs in SHADE's process and could get around it, which is why it must be
trusted.
Paths in the manifest (migrationsFolder, admin.locales, admin page file) are relative to the module's folder:
its repository, or where a server package is unpacked (MODULE_PACKAGES_DIR/<name>@<version>/). Never build
them from import.meta.url.
Naming rules (enforced by validateModule)
One rule (shade/kernel/modules/names.ts): identifiers that other code names are written in full
and checked; keys only SHADE uses are written short and registered under the module's name.
| Thing | Rule | Example |
|---|---|---|
| Module name | kebab-case, not a core module, part or namespace, or a word core's tables and routes use (reservedNames(): team, accounts, tokens, media, consent, privacy, retention, data, ai, rebuild, …) | appointments |
| Tables | <snake_name>_… | appointments_bookings |
| Actions | <name>.<verb> or <name>.<resource>.<verb> | appointments.read, commerce.orders.manage |
| Routes | /api/packages/<name>/ (session/token), /api/v1/account/<name>/ (public/account) | /api/v1/account/appointments/book |
| Admin pages | under /modules/<name>/ | /modules/appointments/appointments |
| Widgets, panels, settings sections | a kebab-case id, unique per kind; the file a .vue inside the module's folder | { id: 'to-ship', file: 'admin/ToShipWidget.vue' } |
| MCP tools | <snake_name>_… | shop_list_products (made up: no official module has one) |
| Collections | <name>-…; with two modules shop and shop-extra, shop-extra-items belongs to the longer name | commerce-products |
| Publish checks and prechecks, save checks | only on the module's own collections | publishChecks: { 'commerce-products': … }, publishPrechecks, saveChecks |
| Field checks | a camelCase name, named by a json field as <name>:<check> | fieldChecks: { layout: … }, check: 'shop:layout' |
| Search text of json fields | the name of one of the module's own field checks | searchText: { layout: … } |
| Jobs, retention kinds, personal data sources, consent categories | a short key (lowercase letters, digits, dashes), registered as <name>.<key> | orders → commerce.orders |
Every registry refuses a name that is taken (another module's MCP tool or data source), and every check runs before anything is registered: a catalog that does not check out registers nothing. Loading the catalog again first forgets what the last load registered. The loader also registers the content model (the built-in collections and the modules'), once every module's collection tables are, after checking it as a whole.
Permissions
Actions are type-safe through declaration merging. Declare them once, next to the runtime list:
export const APPOINTMENTS_ACTIONS = { 'appointments.read': [], 'appointments.manage': [] } as const
declare module '@shadestack/core/schema' {
interface ActionRegistry {
'appointments.read': true
'appointments.manage': true
}
}
At startup the loader calls registerActions(name, actions, grants). Admins get every module action
automatically; other roles only what grants lists. Deny by default still holds: an action that was
declared but not registered is refused for everyone. Services check permissions exactly like core:
assertCan(ctx.actor, 'appointments.read').
Each action lists its classes: admin, in-person, reauth, never-package and never-ai (an empty list is a plain
action). A class is a ceiling: a default grant to a role whose ceiling holds the class (editors may not hold admin
actions), or a collection that gives the ai role publish, or delete unless it says aiDeletes, is refused when
the module loads.
A collection may let the AI delete its entries: aiDeletes: true in its definition, and delete in its access.ai.
Core allows it only when the AI member calls with its MCP token and the call runs in a context core made for your
module: your MCP tool (core runs each module tool in such a context, a mark your code can't claim by setting a field),
or your own offered calls, checks and data sources running in that request. An AI member's data token, core's tools and
another module's code are refused. Your offered calls and checks run under the AI's MCP actor too, so don't delete an
aiDeletes entry there: delete it only in your tool, after its checks. Use it for what the AI makes and removes as part
of building, such as the website module's headers and footers, and let your tool refuse what is still in use. It moves
an entry to the trash only: restoring it or deleting it for good stays a person's, and so does publishing, for every
collection.
Conditions on a module's own tables
This part of the SDK is experimental in 0.1. A grant can carry an entries condition: only the rows the team member
created, or those and the rows of their team groups. A collection's entries need nothing of this: the entry services
apply field rules and entry limits themselves. A module that keeps rows in its own tables applies the condition
itself, from @shadestack/module-sdk/server:
assertCan(actor, action, { entry, groups })checks the action and the condition on one row.entryis{ createdBy, groups }, the row's creator and its team groups;groupsis the team member's own groups. It throws FORBIDDEN when the row is outside the condition.conditionsOf(ctx, action)gives the caller'sentriescondition as a filter for queries on the module's own tables (typeEntriesCondition):{ entries: 'own', member }for the rows the member created,{ entries: 'group', member, groups }for the rows of their team groups and their own, ornullfor every row.nullalso comes for a caller who is not a team member: the module's own actor, a program, core's own work.- Check the action with
assertCanfirst.conditionsOfonly narrows what the action allows.
import { assertCan, conditionsOf } from '@shadestack/module-sdk/server'
assertCan(ctx.actor, 'bookings.read')
const condition = await conditionsOf(ctx, 'bookings.read')
const rows = await ctx.db.select().from(bookings).where(
condition === null ? undefined
: condition.entries === 'own' ? eq(bookings.createdBy, condition.member)
: or(eq(bookings.createdBy, condition.member), inArray(bookings.groupId, condition.groups))
)
For now the Roles screen offers the entries condition on collections only. On a module's own actions it comes with
the first module that filters by it (the forms module), so an admin never sets a condition no module reads.
Team roles: permissions.roles
A module can bring team roles of its own, as many as it needs, keyed by a short name. SHADE keeps each as a custom
role of the module, under <plugin>.<role> (commerce.shop-manager). Admins give them to editors on the Team
screen, and see them on the Roles screen as "Shop: Shop manager".
permissions: {
actions: COMMERCE_ACTIONS,
grants: { editor: ['commerce.orders.read', 'commerce.orders.manage', 'commerce.stock.manage'] },
roles: {
'shop-manager': {
label: 'commerce.roles.shopManager.label',
description: 'commerce.roles.shopManager.description',
required: ['commerce.orders.read', 'commerce.orders.refund', { action: 'team.roles.give', roles: ['shop-manager', 'order-handler', 'stock-clerk'] }],
actions: ['commerce.orders.manage', 'commerce.stock.manage']
},
'order-handler': { label: 'commerce.roles.orderHandler.label', required: ['commerce.orders.read', 'commerce.orders.manage'] },
'stock-clerk': { label: 'commerce.roles.stockClerk.label', required: ['commerce.stock.manage'] }
}
}
labelanddescription: keys of the module's admin texts, or plain text. An admin may rename the role.required: the module's actions the role always holds, and its grants. They are locked on the Roles screen.actions: the module's actions it holds by default. An admin may add or remove the module's other actions.{ action: 'team.roles.give', roles: [...] }inrequired: the module's roles whose members a holder may manage on the Team screen. Only roles of the same module, never core roles. Admins can't change it.- Declare
capabilities: { teamRoles: {} }. The consent lists each role with what it holds and manages (Capabilities).
The checks. A role names only the module's own actions (from permissions.actions) and the module's own roles.
A core action, another module's action or another module's role stops the module from loading. Saving a role on the
Roles screen checks the same again: a required action can't be taken off, and nothing outside the module can be
added, also not by a request made by hand.
Managing members. A holder of a role with the team.roles.give grant may, on the Team screen, invite, create and remove team
members whose role is in that list, and move them between those roles. Core checks it in its team services: the
member's current role and the role given must both be in the roles of that grant of the role the caller holds. The holder never
sees other members, never gives another role or makes an admin, and can't change the roles. team.roles.give is a core action
of the classes in-person and never-ai: only a person in the admin, never a token or the AI, holds it, and an admin's
own custom roles can't hold it. The module's code can't use it: there is no SDK service for it yet. One such as inviteTeamMember(ctx, { email, name, role })
may come later, limited to the roles the caller's role manages.
Threat model, in brief. A module role can't hold the team's actions or anything outside the module, so declaring
roles gives the module no more than its own actions already allow. Team management comes only from team.roles.give, checked
in core. An update that changes a role asks for consent again; it adds newly declared actions and never removes what
an admin chose.
Lifecycle. At each start SHADE adds new roles, updates required (with its grants) as declared, and adds newly
declared default actions. A role the module no longer declares goes, as on removal. Switching the module off changes
nothing. Removing its package removes its roles at once and deactivates their members, who keep their audit history.
Untrusted modules have no permissions and so no team roles.
What the module itself may do: uses
Some of a module's work is started by no editor: its schedules, its public and account routes, and its handlers of
events other modules send (a payment's status, for the shop). That work runs as the module's own actor: { id: SYSTEM_ACTOR_ID, role: 'package', name: 'package:<name>', module: '<name>' }. It may do exactly what the manifest lists in uses, and
nothing by default:
export default defineModule({
name: 'newsletter',
// …
uses: ['collections.website-posts.read', 'collections.website-posts.create'],
schedules: [{ name: 'import', intervalMs: 3_600_000, run: ctx => importIssues(ctx) }]
})
- What can be listed: core actions, actions of core's collections and of the module's own
(
collections.<slug>.<verb>), and the module's own actions (declared inpermissions.actions). Another module's action or collection, a repeat, or an action SHADE doesn't know stops the module from loading. - What can never be listed (the
adminandnever-packageclasses,CEILINGS.package): anything underteam.,tokens.,audit.,errors.,plugins.,features.,maintenance.andprograms.; the forms collection (collections.forms.*, which reaches the visitors' submissions);email.send,settings.read,settings.update,private.read,accounts.roles,media.delete,rebuild.read,rebuild.triggerandbuild.report. Of what MCP never reaches (classnever-ai),media.upload,rebuild.requestand publishing and deleting a collection's entries (collections.website-pages.publish) can be listed, each with consent words of its own. Of core's own actions that leavescontent.read,media.read,media.upload,media.updateandrebuild.request; the theme's and the redirects' actions are the website module's own (collections.website-theme.*,website.redirects.*). - Other modules' collections: a module may list actions of the collections a module it
requiresmarks as shared (shares.collections), and only those; see Modules that build on other modules. Any other module's collection stops it loading. - Consent.
usesis signed in the package beside its capabilities: the install consent words each grant (in English and Dutch), and an update that asks for more asks again. - Editors keep their own rights. Session routes act as the editor (or token);
usesnever adds to that.permissions.grantscannot grant to thepackagerole. - Events of another module's work. When module A acts as itself (its job writes a post), module B hears the event
as B, with B's own
uses, never with A's; whoever caused it, B's handler acts as B (decision 0014). - Data sources. A data source runs with the context of whoever asked for it (a read token, the preview, an
editor), with
ctx.pluginset. One that reads with the module's own grants, such as a source listing the module's own collection, asks for them withactAsModule(ctx)(see Content services); the consent says the module acts on its own in its data sources too. Personal data sources, guards,onEnable,onDisableandonUninstallrun for the caller, the admin (or, for a visitor's own export, nobody signed in), with their own rights, in a context made for the module:ctx.dbandmoduleKv(ctx)are the module's own. - Audit. What the module's actor changes through core's services is audited with no actor id, the name
package:<name>and the module inactor_module; the audit screen shows "Module" only from that column, never from a name (a person cannot be called package:…). - Not a signed-in account. Services any signed-in account may call (their own account, the AI changes screen, the admin's
module list) refuse the module's actor (
assertSignedIn). Its permission refusals are counted per module, never per account: ten within an hour raise the security alert Many refused actions by one module, naming it. - Untrusted modules may not have
uses.
A module that only touches its own tables and the shared services (email: it checks no permission) needs no grants: the official modules' schedules and public routes declare none.
Settings
Modules never read the environment: environment variables are the instance's, set by whoever runs it.
shade-module build refuses a package whose own server code reads process.env, naming the files. A module declares
settings: { fields, secrets } in its manifest; admins fill them in on the Modules page, which renders the fields with the standard field components. Labels and help may be
translation keys from the module's admin texts.
- A field's
section(a translation key or plain text) is the heading it is shown under, in the order the sections first appear; fields without one come first. Only how the form looks: the values stay one flat object. Amounts of money are amoneyfield (shown in euros, kept in cents). - Required settings that are empty make the module "Needs setup": it cannot be switched on, and a module that is on cannot lose a required setting.
secretsnames text settings that hold secrets (API keys, webhook signing secrets). They are encrypted in the database with a key derived fromAPP_SECRETand never sent to the browser (the admin only learns whether one is set), nor kept in an uninstall's backup. ChangingAPP_SECRETmakes them unreadable: enter them again.- Server code reads the values with
getModuleSettings(ctx, '<name>')(secrets decrypted): every field as it is defined, a stored value that still fits it or else itsdefaultValue(else its empty value), so nothing needs parsing by hand. Keep the fields in one constant (export const SETTINGS_FIELDS = [...] as const satisfies readonly FieldDescriptor[], both from@shadestack/module-sdk/shared) and read them typed:getModuleSettings<InferSettings<typeof SETTINGS_FIELDS>>(ctx, '<name>')(a field with a default is never null). Anemailsfield gives a checked list of addresses. Its own only, and only on a context core made for the module: the one its routes, event handlers, schedules and data sources get, or one derived from it. Any other is refused (FORBIDDEN): another module's name, and a context the code copied or built itself ({ ...ctx },{ db, vault }), whateverpluginit says. In the module's own tests, make the context withmoduleContext(ctx, '<name>')from@shadestack/module-sdk/testing(it keeps the actor you give it). Awebhookroute'ssecretnames one of the secret settings; while it is empty every call is refused.
Modules that build on other modules
A module names the modules it builds on, each with the versions it works with, within one major
version of it: an exact version (1.2.0), a caret range (^1.2.0: 1.2.0 up to, not including, 2.0.0; for 0.x
npm's meaning, ^0.2.3 up to 0.3.0) or a tilde range (~1.2.0: up to 1.3.0). So a patch or minor release of the
module it builds on needs no new release of yours, and a major version, which may change what you use, is never taken
without one:
export default defineModule({
name: 'clinic',
version: '1.0.0',
shade: '^0.1.0',
description: 'A clinic’s own system, on the website plugin',
requires: { website: '^1.0.0' },
uses: ['collections.website-pages.read']
})
- The loader refuses a module whose required module is missing or of a version outside its range, naming both
(
Module "clinic" requires "website" ^1.0.0, but "website" is 2.0.0), and modules that require each other in a cycle; it loads the required modules first, so their parts are registered first. At the API's start such a module is left out instead, with the modules that build on it, and the Modules screen says why. - The switch: a module counts as off while a module it requires is off. It can only be switched on after them; switching one of them off, uninstalling it or removing its package is refused while a module that is on needs it, naming that module. Admins only, as everything module-related.
- Installing checks the same against what is installed, both ways (see Installing a trusted module).
requiresis a map of names to ranges; the old list of names is refused with a message. A range that isn't within one major version is refused byvalidateModule(at load and byshade-module build) and at install, naming both modules and the rule:*,x, an open end (>=1.0.0,>1.0.0) or a range across major versions (>=1.0.0 <3.0.0,1.x || 2.x). To work with a new major version, release a new version of your module. Theshaderange is not held to this: it keeps every npm form (isVersionRange). Untrusted modules may not haverequiresorshares.
Shared collections. A module decides which of its collections the modules that require it may use:
// website
shares: { collections: ['website-pages'] }
A module that requires it may then list actions of those collections in its uses; its own actor acts on them
through core's content services, with their permission checks and audit, as on core's collections. A collection that
isn't shared, or one of a module it doesn't require, stops it loading (and installing). The consent names both: the
provider's lists what it shares (sharedCollections), the other's lists the modules it builds on and each grant on a
shared collection says whose it is. An update that starts using a shared collection, or shares more, asks again.
Shared account roles. In the same way a module may share account roles:
shares: { accountRoles: ['mechanic'] }. A module that requires it may then check their abilities on its account
routes and in inScope, named with the module's name (auth: { account: 'repairs:jobs.read' }); it sees those
roles as repairs:mechanic in request.account.roles, and never gives them. An ability of a module it doesn't
require, or that no shared role gives, stops it loading (and leaves it out at the API's start). The provider's
consent lists what it shares (sharedVisitorGroups, the signed name, kept). Any other key of shares is refused.
Alert rules: alerts
A trusted module may bring security alert rules of its own (experimental in 0.1): a burst of one of its own audit
actions. The rule is registered as <plugin>:<name> and then works like core's: it is listed under Settings →
Security alerts, an admin can switch it off, and every active admin is emailed when it raises an alert
(Errors and security alerts).
alerts: {
rules: [{
name: 'webhook-refused', // lowercase letters, digits and hyphens
title: { en: 'Payment webhooks are being refused', nl: 'Betaalwebhooks worden geweigerd' },
help: { en: 'Calls to the payment webhook named no Mollie payment…', nl: '…' },
burst: { action: 'payments.webhook-refused', count: 5, windowMinutes: 15 }
}]
}
titleandhelpeach need an English and a Dutch text.burst.actionmust be one of the module's own audit actions (<plugin>.…),counta whole number from 1 andwindowMinutesfrom 1 to 1440. The loader refuses anything else, naming the rule. An untrusted module may not havealerts.- A refusal worth counting is recorded with
recordModuleRefusal(ctx, { action, subject, summary, reason?, windowMs })from@shadestack/module-sdk/server, with the context SHADE gave the module's code. It writes one audit entry for the first refusal of itssubject(a route or a provider, never an address or a secret) in each window of at least a minute, so a flood is one entry per window and the burst counts windows, not requests. It never throws and never changes the answer: the refusal stands when it cannot be recorded.actionmust start with the module's name. Keep personal data out ofsummaryandreason.
The payments module records a refused webhook this way and raises Payment webhooks are being refused after five such minutes in a quarter of an hour.