The entitlement decision
POST /api/instances/entitlement lives on the registry portal
(src/Memex.Portal.Shared/Api/InstanceEntitlementEndpoints.cs, mapped next to the token exchange). A
standalone package service serves sealed bundle bytes to consumer instances from its own storage. It
must make the same licence decision this registry makes, and must not reimplement the model behind
it: grant entries and their terms, the instance's plan, the plan ladder (Admin/Tiers/*), the
catalog's tier per package, and the anchor that says which source carries a package. So it forwards
the consumer's key and asks here, one batch per request.
Wire contract
Request
POST /api/instances/entitlement
Authorization: Bearer mwi_… (or Basic, exactly what the bundle routes accept)
Content-Type: application/json
{"packages":[{"source":"Plugins","package":"Essentials"}, …]} 1..256 entries
Answers
| status | when | body |
|---|---|---|
| 200 | the key resolved and the body is valid | {"instanceId":"…","decisions":[…]}, one decision per entry, in request order |
| 400 | no packages, 0 or more than 256 entries, an entry without source or package, unparsable or over 256 KiB |
{error} |
| 401 | no key, an unknown or revoked key, or a short-lived mwa_ token (only the durable key decides here) |
{error} |
503 + Retry-After |
the key could not be resolved (InstanceAuthResponses.Unavailable); the catalog could not be read in full and a requested package is therefore UNKNOWN; or any other fault kept the registry from establishing an answer. The fault is logged, and its text never reaches the caller |
{error} |
The key is judged before the body, and the body is not even read until the key resolves. A refused key gets 401 whatever it sent. No other status is answered.
One decision
{"source":"<as requested>","package":"<as requested>",
"outcome":"granted" | "plan-required" | "denied",
"packageTier":"<canonical tier, or null>",
"heldTier":"<widest plan the caller holds in that source, or null>",
"publicationSource":"<the source the decision resolved, or null>"}
| outcome | meaning | packageTier |
heldTier |
publicationSource |
|---|---|---|---|---|
granted |
the caller may have it | the catalog's tier (null = baseline) | held in the resolved source | the resolved source. Fetch from this one |
plan-required |
a current grant entry matches the pair, but the instance's plan (narrowed by the entry's cap) does not cover the package's tier | the tier it needs | held in the resolved source | the resolved source |
denied |
no current grant entry matches the pair | always null | held in the requested source | always null |
heldTier is computed over every current entry for that source: the instance plan narrowed by the
entry's cap, in canonical form, with free when the record names no plan. It is null when the grant
is revoked or holds no current entry for the source.
How the decision is made
It is the bundle route's decision (PluginBundleEndpoints.Decide):
PackageEntitlementAnchor.Resolve over the anchor's source for the package, with
caller.Allows(source, package, tier), where the tier is the registry catalog's. It is not
PluginGrantEntry.Matches, which ignores the plan tier. A plan-required answer is
AuthenticatedInstance.TierRefusal, the same rule the catalog listing uses (#4097). Every decision
is recorded on the PackageEntitlementLedger, one per asked package.
What it leaves out on purpose:
- No install-record cache and no compile state. The answering registry keeps no install records for the packages it carries, and nothing here reads a NodeType release record. The decision uses grants and the catalog only. While the anchor has answered in full, the source the caller named takes the cache's place, so a package the catalog does not carry is decided by the grant over that source.
- No existence check of its own. Two cases follow, and both are pinned by tests:
- With no matching grant, every name reads
denied, whether the package exists or not. The bodies are byte-identical apart from the echoed package name: no tier, no source, and the held tier is a fact about the caller's grant only. Nothing reveals that a package exists. - Under a matching wildcard grant (
Source/*,Source/*@tier), the anchor and the grant decide. An unknown name readsgranted, because the grant covers every name in the source and there are no bytes behind the name. An existing package above the plan readsplan-requiredwith itspackageTier.
- With no matching grant, every name reads
- "Could not find out" is never "denied". If the catalog could not be listed in full and a
requested package is in no snapshot the anchor holds,
ResolvereturnsIndeterminate. The wire has no fourth outcome for that, so the whole request answers 503 +Retry-After. In that state the named source is not used as a fallback. With the tier unknown, a null tier would read as the baseline, and a free-plan wildcard holder would be granted a paid package.
Tests: src/Memex.Portal.Shared.Test/InstanceEntitlementEndpointTest.cs. The platform's
registry-API documentation (core Doc/Architecture/PluginRegistry,
Doc/Architecture/PluginBundlesInTheRegistry) does not describe this route yet. Add it there in a
core change.