@shopkit/apps-capabilities
v0.1.0
Published
Apps Platform capability catalog: single source of truth for SCOPES, METHOD_CAPABILITIES, SURFACE_ALLOWLIST, and shared message-envelope types. Consumed by apps-platform (runtime), apps-manifest (validator), and app-sdk (iframe client).
Readme
@shopkit/apps-capabilities
Single source of truth for the Apps Platform capability model. Zero runtime dependencies; consumed by:
@shopkit/apps-platform— runtime capability validation inHostAdapter@shopkit/apps-manifest— declared-capabilities ⊆ catalog check at upload time@shopkit/app-sdk— message envelope types for the iframe-side RPC client
What's in here
| Export | Purpose |
| --- | --- |
| SCOPES | The exhaustive catalog of capability strings. Adding/removing here is a platform-wide change. |
| Capability | TypeScript union narrowed to SCOPES. |
| isCapability(value) | Runtime type-guard for inbound manifest values. |
| SURFACES | The 5 surfaces (embed, block, account-extension, checkout-extension, admin-extension). |
| SurfaceType | TypeScript union narrowed to SURFACES. |
| SURFACE_ALLOWLIST | Per-surface capability whitelist. Stage-2 of capability validation. |
| METHOD_CAPABILITIES | RPC method → required capability map. The runtime trusts this; an unknown method denies as unknown_method. |
| RpcMethod | TypeScript union narrowed to Object.keys(METHOD_CAPABILITIES). |
| IframeReadyMessage / LoadAppCodeMessage / AppReadyMessage / IframeErrorMessage | Lifecycle envelopes. |
| RpcRequestMessage / RpcResultMessage / RpcErrorCode | RPC envelopes. |
| IframeOutboundMessage / HostOutboundMessage | Discriminated unions for exhaustive switches. |
Adding a new capability
- Add the string to
SCOPESinscopes.ts. - Add the RPC method(s) → scope mapping in
methods.ts. - Add the scope to the appropriate surface(s) in
SURFACE_ALLOWLIST(surfaces.ts).
Test invariants will fail if you forget step 2 or 3 (every scope must be required by ≥1 method; every method's required capability must exist in SCOPES; every capability on a surface allowlist must exist in SCOPES).
Why a separate package
Both the runtime (apps-platform, browser) and the manifest validator (apps-manifest, Node/CLI/server) need to agree on the catalog. Duplicating drifts. Importing across runtime↔server boundaries couples them. A zero-dep contracts package is the clean cut.
