Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/35157-capability-draft-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/i18n': patch
---

feat(i18n): a count family for capability drafts in the pending-changes summary

Clause-②: no
Metadata-protocol: none

Every locale pack adds `preview.changes.typeCount.capability` (and its plural forms), so the console's pending-changes summary reads "2 capabilities" (`能力 2` in Chinese) instead of the raw type name when a publish carries capability drafts.
12 changes: 12 additions & 0 deletions .changeset/35157-scaffold-no-connector-plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'create-objectstack': minor
---

feat(create-objectstack): the blank scaffold lists no connector plugins until the app declares a connector

Clause-②: no
Metadata-protocol: none

A new project's `objectstack.config.ts` no longer lists `ConnectorRestPlugin`, `ConnectorOpenApiPlugin` and `ConnectorMcpPlugin`, and its `package.json` no longer depends on the three connector packages. A plugin is code, so an app that lists any plugin installs managed only. The scaffold's own plugin list therefore kept every AI-built app from installing as an unmanaged copy, such as a marketplace trial.

To use a connector, install its provider package and add it to `plugins:`, for example `plugins: [new ConnectorRestPlugin()]`. The template's README and the comment in `objectstack.config.ts` show how. The install contract is unchanged: a stack that lists plugins still validates for managed install only.
24 changes: 24 additions & 0 deletions .changeset/35157-unmanaged-copy-capabilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/spec': minor
'@objectstack/metadata-protocol': minor
'@objectstack/objectql': minor
'@objectstack/plugin-security': patch
'@objectstack/cli': patch
---

feat(security): an unmanaged install copies an app's capabilities, renamed with the copy

Clause-②: yes (widening)
Metadata-protocol: added

An app that gates an action on its own capability can now install as an unmanaged copy (`installModes: ['unmanaged']`). Before, `capability` was code-only (`allowRuntimeCreate: false`), so the validator refused the mode for any app that declared one, and the install door had no channel to write the copy's capabilities.

- **`capability` is runtime-creatable.** Its `DEFAULT_METADATA_TYPE_REGISTRY` entry is now `allowRuntimeCreate: true`, and overlays stay closed (`supportsOverlay: false`, `allowEnvironmentOverlay: false`). A body is judged by `CapabilityDeclarationSchema`, as before.
- **The save door refuses two names.**
- A platform capability's name (`manage_users`, `setup.access`, every name in `PLATFORM_CAPABILITIES`) answers `422 NAMESPACE_CONFLICT`. An environment item under that name would shadow the platform's definition, because the registry answers its bare slot first.
- A name an installed package's capability holds answers `422 NAMESPACE_CONFLICT`, naming the holder. A capability holds one name per deployment, the same rule permission sets and positions follow.
- **The environment catalog holds capabilities.** `ENVIRONMENT_HELD_SECURITY_CATALOG_TYPES` is `['position', 'permission', 'capability']`. A package that ships a capability name the environment already authored is refused at boot, as a position or permission-set name is. `os migrate security-catalog-overlays`, the remedy that refusal names, lists and deletes such a capability row too (`capability` and `capabilities` spellings).
- **An unmanaged copy renames its capabilities.** When the copy takes a new namespace, a capability whose name starts with the source namespace (`<ns>.` or `<ns>_`) is renamed into the copy's namespace. Every reference is rewritten with it: a permission set's `systemPermissions` (list or per-operation map), an object's or action's `requiredPermissions`, and a quoted `current_user.hasCapability('<name>')` in a predicate. There the object-name rename never touches a name the package declares, so a capability named after a renamed object has one name in the copy; a token the package does not declare follows a renamed object as before. An unprefixed capability keeps its name. A renamed capability that collides with another package's capability refuses the install, naming both. Install again under another namespace.
- **Duplicating a package refuses a shared gate.** `duplicatePackage` keeps its source installed, so a capability it cannot rename (no source prefix, or a copy name the package already declares) is refused, and so is every copied item that grants, requires or tests for it, each at its own name in `failed[]`.
- **The `everyone` anchor excuses only a declaration that carries a package.** The check that refuses a high-privilege permission set bound to `everyone` excuses the tokens an app declared itself. It now counts only declarations bound to a package (`_packageId`), as ADR-0090 D5 rules: an app's shipped capabilities, an unmanaged copy's, and one saved into a writable package. A capability saved with no package excuses nothing. What bounds a saved declaration is the two refusals above: a platform capability is never excused, and a name a package declares cannot be declared again. A name nobody declares can be declared once, by a `manage_metadata` holder, inside a writable package.
- **The gate is unchanged.** It still matches capability names. The copy's action is gated on the copy's capability: a holder of the copy's permission set passes, and a holder of only the source's set does not.
9 changes: 6 additions & 3 deletions content/docs/automation/connectors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ At boot, the automation service resolves each provider-bound entry:
1. **Look up the provider factory** registered under `entry.provider`. The
three generic executors — `@objectstack/connector-rest`,
`@objectstack/connector-openapi`, `@objectstack/connector-mcp` — each
contribute one; scaffolded projects (`npm create objectstack`) ship all
three in `plugins:` by default, paired with the `automation` capability
that performs the materialization.
contribute one. A scaffolded project (`npm create objectstack`) lists
none: install the provider's package and add its executor to `plugins:`
when the app first declares a connector, beside the `automation`
capability that performs the materialization. A plugin is code, so an app
that lists one installs only as a managed package, never as an editable
(`unmanaged`) copy.
2. **The factory validates `providerConfig`** and the automation service
resolves `auth.credentialRef` to its secret (see
[What `credentialRef` resolves through](#what-credentialref-resolves-through)).
Expand Down
18 changes: 16 additions & 2 deletions content/docs/deployment/install-modes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ while it carries something that door cannot write as environment metadata. The
refusal is `STACK_UNMANAGED_INSTALL_UNCOPYABLE`, with one finding per key:

- items of a metadata type the metadata-type registry declares
runtime-uncreatable (`allowRuntimeCreate: false`);
- code: `functions`, `plugins` and the other keys that carry or describe code;
runtime-uncreatable (`allowRuntimeCreate: false`). A package's own
capabilities are not among them: they are copied, with the permission sets
that grant them and the actions, flows and objects that require them;
- code: `functions`, `plugins` and the other keys that carry or describe code.
A project scaffolded by `npm create objectstack` lists no `plugins`; add a
connector's plugin only when the app declares that connector, and it then
installs managed only;
- extensions of another package's items: `objectExtensions`,
`picklistExtensions`, `navigationContributions`, `contributes`;
- `packages`, which describes an artifact of several packages, while one
Expand Down Expand Up @@ -244,6 +249,14 @@ The copy is renamed by the same rules as duplicating a package:
is a whole prefixed object name (`crm_lead`, never `x_crm_lead`).
- **Translations are named `acme_<locale>`**, with the object keys inside them
renamed.
- **A capability the package names with its prefix takes the new one.**
`crm.approve_deal` copies as `acme.approve_deal` (and `crm_approve_deal` as
`acme_approve_deal`), and every permission set's `systemPermissions` grant and
every `requiredPermissions` requirement of it in the copy follows, so the copy
never shares a gate with the package or another copy. A capability the package
does not declare, a platform one among them, keeps its name, unless it is
spelled with the name of an object the copy renames: then it follows the
object (`crm_lead.convert` copies as `acme_lead.convert`).
- **An object of another package keeps its name**, and so do its view items.

`targetNamespace` follows the rule for a manifest `namespace`, and the
Expand All @@ -256,6 +269,7 @@ refusal is answered before the base exists, so nothing is installed:
| An object whose copy name another object's copy takes (`ticket` beside `crm_ticket`) | `400 INVALID_REQUEST`, naming the object and the rename that clears it |
| A copy name that is not a legal item name, longer than an object's table name may be (63 characters), or longer than an item name may be (255) | `400 INVALID_REQUEST`, naming each item |
| A renamed key that meets a key the item already holds (a permission set granting both `crm_lead` and `acme_lead`) | `400 INVALID_REQUEST`, naming the item and both keys |
| A capability whose copy name another capability of the package declares (`crm.approve` beside `acme.approve`) | `400 INVALID_REQUEST`, naming the capability |
| A renamed name the environment or a managed package already holds | `409 RESOURCE_CONFLICT`, naming each |
| A `targetNamespace` another package owns | `409 RESOURCE_CONFLICT`, naming it |

Expand Down
29 changes: 12 additions & 17 deletions content/docs/getting-started/your-first-project.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ view, action or flow adds a file and one export line to its directory's

```typescript title="objectstack.config.ts"
import { defineStack } from '@objectstack/spec';
import { ConnectorRestPlugin } from '@objectstack/connector-rest';
import { ConnectorOpenApiPlugin } from '@objectstack/connector-openapi';
import { ConnectorMcpPlugin } from '@objectstack/connector-mcp';
import * as objects from './src/objects';
import * as views from './src/views';
import * as actions from './src/actions';
Expand All @@ -162,16 +159,10 @@ export default defineStack({
engines: { protocol: '^18' },
},
// `automation` runs flows and, per ADR-0097, materializes declarative
// `connectors:` entries at boot. The three generic executors below register
// their `rest` / `openapi` / `mcp` provider factories with it. `triggers`
// fires a flow that starts on a record change, the kind `os generate flow`
// writes.
// `connectors:` entries at boot, through the provider factory a connector
// executor in `plugins:` registers. `triggers` fires a flow that starts on
// a record change, the kind `os generate flow` writes.
requires: ['automation', 'triggers'],
plugins: [
new ConnectorRestPlugin(),
new ConnectorOpenApiPlugin(),
new ConnectorMcpPlugin(),
],
objects: exportsOf(objects),
views: exportsOf(views),
actions: exportsOf(actions),
Expand Down Expand Up @@ -216,11 +207,15 @@ them a pattern to rely on:
</Callout>

The REST API needs no configuration — it is on by default for every object
with `apiEnabled`. The `plugins:` array ships the three **generic connector
executors**, so you can integrate an external REST / OpenAPI / MCP service as
pure metadata: add a `connectors:` entry naming a `provider` and the
`automation` capability materializes it into a live connector at boot — see
[Automation → Flows](/docs/automation/flows).
with `apiEnabled`. The starter lists no `plugins:`: a plugin is code, and an app
with code in `plugins:` installs only as a managed package, never as the
editable copy a marketplace trial template is (`manifest.installModes:
['unmanaged']`). To integrate an external REST / OpenAPI / MCP service as pure
metadata, install that **generic connector executor**
(`@objectstack/connector-rest`, `-openapi` or `-mcp`), list it in `plugins:`,
and add a `connectors:` entry naming its `provider`; the `automation`
capability materializes it into a live connector at boot — see
[Automation → Connectors](/docs/automation/connectors).

**`src/objects/note.object.ts`** is a complete data model — schema, validation,
API surface, and searchability in one typed definition:
Expand Down
105 changes: 66 additions & 39 deletions content/docs/permissions/capabilities.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -224,49 +224,76 @@ deletes the seeded copies (ADR-0131 D10).
Withdraw a capability by withdrawing the **grant**.
</Callout>

## `capability` is code-only
## Declaring a capability in the environment

`capability` is a registered metadata kind, and its registry entry declares
`allowRuntimeCreate: false` **and** `allowEnvironmentOverlay: false`. Together those
are the code-only declaration, so:

```
PUT /api/v1/meta/capability/:name
→ 403 NOT_CREATABLE
"Metadata type 'capability' is code-only: the metadata-type registry
declares allowRuntimeCreate=false and allowEnvironmentOverlay=false, so it
cannot be created through the runtime metadata API … on any kernel.
Declare it in source (**/*.capability.ts) and redeploy."
```

The refusal fires **before** the body is validated, on every kernel, in draft
mode as well as active. This is deliberate and follows straight from the
three-way separation: an administrator minting a brand-new capability at runtime
has no counterpart in it — nothing in code would ever *require* the name, so the
result is an unreferenced grant target sitting in the live authorization
namespace. `job` and `agent` carry the same pair for the same reason.
`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 a different refusal, with the same `403` status: the walled
refusal every environment-metadata write takes there (ADR-0131 D3, D12 items
7–8), whose message names the posture, with the code `FORBIDDEN` on the REST
door and `PERMISSION_DENIED` on the runtime dispatcher.
It runs before the code-only refusal, so the block above is the answer the
platform operator reads, and every caller under `single`.

Two things this does **not** close:

- **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`** — a capability is a name, a label and a scope;
there is no merge semantic, and a per-organization overlay of a
package-shipped declaration could re-scope `org` → `platform`.

`OS_METADATA_WRITABLE=capability` remains the one documented operator escape
hatch (ADR-0005). Behind it the write is judged by `CapabilityDeclarationSchema`
and a malformed body is rejected with `422 invalid_metadata` — it is not a way
to store arbitrary JSON on the authorization surface.
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

Expand Down
Loading
Loading