ObjectStackObjectStack

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: [...]
DeclaresAn authorization capability this package offersA platform service this package needs
Answers"What new privilege can an administrator now grant?""What must be installed for this app to boot?"
VocabularyAuthor-chosen names, ^[a-z][a-z0-9_.]*$ — export_data, billing.refundA closed vocabulary: canonical kebab-case tokens from PLATFORM_CAPABILITY_TOKENS — ai, automation, hierarchy-security
Entry shapedefineCapability({ name, label, description, scope }) (CapabilityDeclarationSchema)A plain string
Unknown valueThere is no "unknown" — you are minting the nameA defineStack error at authoring time (a typo, or a token no runtime provides)
Needed but undeclaredNothing to detect — a name is minted here, then grantedA 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 bysystemPermissions (grant) and requiredPermissions (requirement), by name stringThe runtime capability loader, which resolves each token to a service plugin
When it bitesNever at boot — an ungranted capability is simply held by nobodyFail-fast at startup: a declared-but-missing provider aborts boot instead of degrading silently
SpecADR-0066 D1Platform 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
  1. Declare — defineCapability(...) on the stack's capabilities array, or a *.capability.ts / *.capability.yml file the filesystem loader globs.
  2. Register — at boot, AppPlugin puts each stack-declared capability into the metadata registry under the capability kind, so the security catalog and runtime resolvers can list it.
  3. 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/:name answer its definition. No sys_capability row is written for it.
  4. Grant — an administrator (or a permission set your package ships) lists the name in systemPermissions.
  5. Check — a resource lists the name in requiredPermissions, and the evaluator AND-gates it against the union of systemPermissions across 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

FieldTypeRequiredNotes
namestring✅The contract. ^[a-z][a-z0-9_.]*$ — lowercase, digits, _ and .
labelstringoptionalShown to the administrator who grants it. Defaults to a humanized name
descriptionstringoptionalWhat holding the capability permits
scope'platform' | 'org'optionalDefaults to 'platform'. org = scoped to the caller's organization
packageIdstringoptionalAuthor-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.refund reads unambiguously; refund will collide with somebody.
  • A typo fails closed, and quietly. mange_users is 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 lint validateCapabilityReferences (ADR-0066 ⑨) closes part of this gap: it resolves every requiredPermissions reference 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. systemPermissions is 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:

SituationOutcome
The name is a curated platform capabilityRefused; the platform holds its own definition
Another installed package already declares the nameRefused; 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 is 422 INVALID_METADATA.
  • A platform capability's name (manage_users, manage_metadata, …) is refused 422 NAMESPACE_CONFLICT. A declaration under it would re-declare a platform power's scope, 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
  • label and description are written for the administrator who will grant it
  • scope is org unless the privilege really is platform-wide
  • The declaration is reachable from the stack (capabilities: [...]) or a *.capability.ts file
  • 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

On this page