Declaring capabilities in a permission set
Define an authorization capability in a package with defineCapability, then follow it into the catalogue, a permission-set grant and a runtime check.
Every other page in this module is about consuming a capability: granting one through a permission set, requiring one on an object or an action, reading one back in an access matrix. This page is about the other end — how a package defines the capability in the first place, and what happens to that name afterwards.
Two arrays, similar words, unrelated vocabularies. A stack can carry both
capabilities: and requires:. They have nothing to do with each other, and
picking the wrong one produces metadata that validates and then does nothing.
Read the next section before you write either.
capabilities: is not requires:
capabilities: [...] | requires: [...] | |
|---|---|---|
| Declares | An authorization capability this package offers | A platform service this package needs |
| Answers | "What new privilege can an administrator now grant?" | "What must be installed for this app to boot?" |
| Vocabulary | Author-chosen names, ^[a-z][a-z0-9_.]*$ — export_data, billing.refund | A closed vocabulary: canonical kebab-case tokens from PLATFORM_CAPABILITY_TOKENS — ai, automation, hierarchy-security |
| Entry shape | defineCapability({ name, label, description, scope }) (CapabilityDeclarationSchema) | A plain string |
| Unknown value | There is no "unknown" — you are minting the name | A defineStack error at authoring time (a typo, or a token no runtime provides) |
| Needed but undeclared | Nothing to detect — a name is minted here, then granted | A defineStack error too: a hierarchy scope (unit / unit_and_below / own_and_reports) needs hierarchy-security, and a record_change / schedule / time_relative / api flow needs triggers and automation (the triggers install into the automation engine) — without them the runtime fails closed (owner-only visibility) or, for flows, silently never fires. ⚠️ triggers is a capability, not the whole declaration: a schedule / time_relative flow also declares the organization it runs as, and one that does not is refused at bind rather than fired org-less |
| Consumed by | systemPermissions (grant) and requiredPermissions (requirement), by name string | The runtime capability loader, which resolves each token to a service plugin |
| When it bites | Never at boot — an ungranted capability is simply held by nobody | Fail-fast at startup: a declared-but-missing provider aborts boot instead of degrading silently |
| Spec | ADR-0066 D1 | Platform service vocabulary — see the CLI reference |
The word "capability" is doing double duty across two protocols, which is why
this trap is easy to fall into and expensive to leave in place. The one-line
test: capabilities: is about people, requires: is about packages. If the
sentence you are trying to write ends in "…may do this", it belongs in
capabilities:. If it ends in "…must be installed", it belongs in requires:.
The whole loop
Each of the other pages in this module shows one segment of this. End to end, a capability name travels through five stations:
① DECLARE capabilities: [defineCapability({ name: 'export_data' })]
│ packages/<your-app>/src
▼
② REGISTER AppPlugin → metadata.registerInMemory('capability', name)
│ (also: **/*.capability.ts files)
▼
③ SERVE registry item (capability kind) → catalog read, /meta door
│ owning-package provenance, one holder per name
▼
④ GRANT permission set: systemPermissions: ['export_data']
│ assigned to positions / users
▼
⑤ CHECK resource: requiredPermissions: ['export_data']
AND-gated ahead of any CRUD grant- Declare —
defineCapability(...)on the stack'scapabilitiesarray, or a*.capability.ts/*.capability.ymlfile the filesystem loader globs. - Register — at boot,
AppPluginputs each stack-declared capability into the metadata registry under thecapabilitykind, so the security catalog and runtime resolvers can list it. - Serve — the registry is the capability's one home. It records the
owning package as provenance, which is what makes the capability
attributable. The security catalog read and
GET /api/v1/meta/capability/:nameanswer its definition. Nosys_capabilityrow is written for it. - Grant — an administrator (or a permission set your package ships) lists
the name in
systemPermissions. - Check — a resource lists the name in
requiredPermissions, and the evaluator AND-gates it against the union ofsystemPermissionsacross the caller's resolved permission sets.
Stations ④ and ⑤ are covered in depth by Permission Sets and Authorization Architecture. Everything below is about ① – ③.
The declaration shape
import { defineCapability } from '@objectstack/spec';
export const ExportDataCapability = defineCapability({
name: 'export_data',
label: 'Export Data',
description: 'Bulk-export records to CSV/XLSX.',
scope: 'org',
});Collect the declarations on the stack, next to the permission set that grants them:
import { defineStack } from '@objectstack/spec';
import { ExportDataCapability } from './capabilities/export-data.capability';
export default defineStack({
manifest: {
name: 'billing',
namespace: 'billing',
version: '1.0.0',
/* …full ObjectStackManifest… */
},
capabilities: [ExportDataCapability], // ← ① DEFINE
permissions: [
{ name: 'billing_admin', systemPermissions: ['export_data'] }, // ← ④ GRANT
],
// and on a resource: requiredPermissions: ['export_data'] // ← ⑤ REQUIRE
});Fields
| Field | Type | Required | Notes |
|---|---|---|---|
name | string | ✅ | The contract. ^[a-z][a-z0-9_.]*$ — lowercase, digits, _ and . |
label | string | optional | Shown to the administrator who grants it. Defaults to a humanized name |
description | string | optional | What holding the capability permits |
scope | 'platform' | 'org' | optional | Defaults to 'platform'. org = scoped to the caller's organization |
packageId | string | optional | Author-declared fallback provenance (ADR-0086 D3). Normally the registry stamps this for you |
The shape is strict: an unrecognised key is a parse error at authoring
time, not a silently dropped field. Three near-miss keys get a named refusal
rather than a generic one, because each is a real inversion of the three-way
separation — permissionSets (a capability never names its own holders),
requiredPermissions (that is the requirement side, authored on the resource)
and inputs (a capability is a name, not a contract). The full generated field
reference lives in Security schemas.
The name is the contract
Resolution is by string, everywhere. systemPermissions and
requiredPermissions both carry plain names, and the evaluator compares them as
plain names. Three consequences worth internalising before you pick one:
- Your name lands in the same flat namespace as the platform's own. There
is no per-package prefixing applied for you. Namespace it yourself —
billing.refundreads unambiguously;refundwill collide with somebody. - A typo fails closed, and quietly.
mange_usersis a perfectly valid capability name; it is simply held by nobody, so the caller is denied. That is the safe direction, but nothing about the denial says the name exists nowhere. The authoring lintvalidateCapabilityReferences(ADR-0066 ⑨) closes part of this gap: it resolves everyrequiredPermissionsreference against the capabilities known at author time and warns on the unresolved ones. It reads every package of the artifact being built, so a grant in a sibling package of the same artifact counts, as it does at run time. It is a warning, not an error, because the lint cannot see capabilities declared by packages installed from other artifacts.systemPermissionsis deliberately not flagged — that is the declaration side. - Renaming a shipped capability is a breaking change for every permission set and every resource that references the old string, including ones in other packages you cannot see.
You cannot take a platform name. A declaration whose name collides with a
curated platform capability (manage_users, manage_metadata,
setup.access, …) is refused at boot by the registry's one-holder rule
(422) — those are platform-owned, and the platform declares them itself.
"Or" is one capability, granted twice
requiredPermissions is the one way to require a capability on an entry — an
app, a navigation item, an action, a record block, and a list view or a
dashboard — and everywhere it means the same thing: a list of names the user
must all hold. There is no any-of form. To show an entry to two audiences —
the legal team or an administrator — declare one capability for the entry
and grant it to both permission sets:
capabilities: [
defineCapability({ name: 'clm_legal_workbench.view', label: 'Open the legal workbench' }),
],
permissions: [
{ name: 'clm_legal', systemPermissions: ['clm_legal_workbench.view'] },
{ name: 'clm_admin', systemPermissions: ['clm_legal_workbench.view'] },
],
// …and on the entry itself: requiredPermissions: ['clm_legal_workbench.view']Listing each audience's own capability instead —
requiredPermissions: ['clm_legal.access', 'clm_admin.access'] — requires both,
so it shuts out everyone who holds only one of them.
A list view's and a dashboard's requiredPermissions are enforced by the
server. A user who does not hold every capability listed is not served the
view or the dashboard: it is left out of their lists — the view switcher
included — and opening it by name or by its direct URL is refused. The named
list views of a view container, and an object's own list views, are left out
the same way; a user who may edit the object still reads all of its list views,
so a save of what they loaded keeps them.
One holder per name
Each capability name has exactly one holder in the registry. When a package
registers a declaration, the registry records that package as its owner.
Package uninstall then removes it with the rest of the package. Two cases are
refused at boot, with a 422 that names the name and both holders:
| Situation | Outcome |
|---|---|
| The name is a curated platform capability | Refused; the platform holds its own definition |
| Another installed package already declares the name | Refused; a package never takes over another package's capability |
Declaring a capability writes no sys_capability row. Its label, description,
scope and provenance live on the registry item, and that is what the catalog
read and the metadata door serve.
No authorization check reads a sys_capability row. Permission-set grants
and resource requiredPermissions match capability names as strings. The
boot writes no row for a capability, declared or curated: both are served by
the registry. The sys_capability object itself is retired and no longer
registered (ADR-0131 D3): a row an older database still holds is served by no
route and read by nothing. os migrate organization-ownership --apply reports the authored rows and
deletes the seeded copies (ADR-0131 D10).
Withdraw a capability by withdrawing the grant.
Declaring a capability in the environment
capability is a registered metadata kind, and its registry entry declares
allowRuntimeCreate: true with allowEnvironmentOverlay: false. So an
environment may declare a capability of its own through the metadata door
(PUT /api/v1/meta/capability/:name), but never re-declare one a package
ships. An unmanaged install is the write that needs this: it copies an app
into the environment, and an app that gates its actions on its own
capabilities copies them too (below).
Every such write is judged before anything is stored:
- The body by
CapabilityDeclarationSchema; a malformed one is422 INVALID_METADATA. - A platform capability's name (
manage_users,manage_metadata, …) is refused422 NAMESPACE_CONFLICT. A declaration under it would re-declare a platform power'sscope, and the scope decides whether an organization administrator may hand out the sets that grant it. - A name another holder declares — a package, the environment, or another
copy — is refused
422 NAMESPACE_CONFLICT, naming the holder. A grant and a requirement match a capability by name across the whole deployment, so one name has one holder.
At the everyone anchor, a token a package's declaration names is the app's
own and is excused (ADR-0090 D5): one an app ships, one an unmanaged copy
writes, and one saved into a package the environment can write (a copy, a
duplicate, a base you author). A capability saved with no package is not,
whatever package its own packageId names: binding a permission set that grants it to everyone is judged as for any
undeclared token, and refused as high-privilege. The two refusals above are
what bounds this. No declaration can take a platform capability's name, so a
platform power is never excused, and none can take a name a package already
declares. A name nobody declares, such as a token an app grants or requires
without declaring it, can be declared once inside a writable package, and that
declaration decides its scope and excuses it at the anchor. Only a holder of
manage_metadata can save one.
Under a group or isolated tenancy posture, a caller below the platform
operator reads the walled refusal every environment-metadata write takes there
(ADR-0131 D3, D12 items 7–8) before any of these.
The package-declaration channel is untouched: AppPlugin registers stack
capabilities[] through the in-memory registry and the filesystem loader globs
filePatterns; neither goes through the runtime write door.
supportsOverlay: false still holds — a capability is a name, a label and a
scope, with no merge semantic.
In an unmanaged copy
A package that permits installModes: ['unmanaged'] may declare capabilities.
The copy writes each one into the environment, owned by the copy. Installed
under a targetNamespace, a capability the package names with its namespace
(demoasset.manage_assets, or demoasset_manage_assets) takes the target's
(trial1.manage_assets), and every systemPermissions grant and
requiredPermissions requirement of it in the copy follows. So two copies of
one app never share a gate. The name follows into a component's visibleWhen
too, where current_user.hasCapability('<name>') gates it with a quoted name.
A capability named after an object the copy renames (crm.crm_invoice.void)
keeps one name in the copy, the declaration's (shop.crm_invoice.void), in
every place that names it. A name the package does not declare — a platform
capability it grants or requires, or another package's — is not renamed as a
capability. It keeps its name, unless it is spelled with the name of an object
the copy renames: then it follows the object, as other text does, in the
grant, the requirement and the predicate alike (crm_invoice.void copies as
shop_invoice.void).
A capability the package declares without its namespace prefix keeps its name. An unmanaged install keeps it; a second holder of that name refuses the whole install. Duplicating a package refuses that capability, and every item that grants, requires or tests for it, because the source stays installed beside the copy and the two would share one gate. Prefix your capability names.
Checklist
- Name is namespaced and lowercase, and does not shadow a platform capability
-
labelanddescriptionare written for the administrator who will grant it -
scopeisorgunless the privilege really is platform-wide - The declaration is reachable from the stack (
capabilities: [...]) or a*.capability.tsfile - No other installed package declares the same name — the registry refuses a second holder at boot
- Something actually requires the name (
requiredPermissions), and something grants it (systemPermissions)
See also
- Authorization Architecture — capability / assignment / requirement, and the enforcement chain
- Permission Sets — the granting half
- Permission Metadata —
systemPermissionsin a permission-set body - Access Recipes — worked end-to-end scenarios
- Security schemas — generated field reference
Permission Metadata
Define access control with permission sets — object CRUD, field security, tab visibility, and row-level security
Security Permissions Matrix
Visual reference for ObjectStack security — permission types, the object × permission-set matrix, field security, sharing rules and business-unit depth.