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:

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.