@fabricorg/sdui-release 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,334 @@
1
+ import { PortableJsonSchema } from '@fabricorg/platform';
2
+ export { JsonValue } from '@fabricorg/platform';
3
+ import { UsageContractDocument } from '@fabricorg/gen-capability';
4
+ import { AssemblyLockfile } from '@fabricorg/assembly';
5
+
6
+ /**
7
+ * Version of the SDUI document contract. A vertical negotiates on this, not on
8
+ * this package's version, and it moves only when the serialized shape changes.
9
+ */
10
+ declare const SDUI_DOCUMENT_FORMAT_VERSION: 1;
11
+ /**
12
+ * Version of the SDUI token-set contract.
13
+ */
14
+ declare const SDUI_TOKEN_SET_FORMAT_VERSION: 1;
15
+ /**
16
+ * Version of the SDUI component-pack contract.
17
+ */
18
+ declare const SDUI_COMPONENT_PACK_FORMAT_VERSION: 1;
19
+ /**
20
+ * Version of the promoted SDUI release contract.
21
+ */
22
+ declare const SDUI_RELEASE_FORMAT_VERSION: 2;
23
+ /**
24
+ * A capability read reference embedded in fragment props. The `capability://`
25
+ * scheme ties a data binding to a published view; the host resolves it through
26
+ * `ProjectionHost`, never through a direct query.
27
+ */
28
+ interface SduiCapabilityRef {
29
+ $ref: `capability://${string}`;
30
+ }
31
+ /**
32
+ * A value that may appear in fragment props: a JSON literal, an array, an
33
+ * object, or a `capability://` read reference. Direct mutation endpoints,
34
+ * API URLs, or code strings are not valid fragment values.
35
+ */
36
+ type SduiFragmentValue = string | number | boolean | null | SduiFragmentValue[] | SduiCapabilityRef | {
37
+ [key: string]: SduiFragmentValue;
38
+ };
39
+ /**
40
+ * An action declared on a fragment. The `intent` must be a `capability://`
41
+ * reference to a published action intent; the host dispatches it through
42
+ * `PlatformHost`, preserving governance. A bare endpoint URL, function name,
43
+ * or inline script is a mutation bypass and is rejected.
44
+ */
45
+ interface SduiActionRef {
46
+ intent: `capability://${string}`;
47
+ params?: Record<string, SduiFragmentValue>;
48
+ }
49
+ /**
50
+ * A node in an SDUI document tree. A fragment either renders a component from
51
+ * a declared pack, binds data from a capability view, or both. Actions on a
52
+ * fragment are always capability action-intent references — never direct
53
+ * mutations.
54
+ */
55
+ interface SduiFragment {
56
+ /** Unique identifier within the document. */
57
+ id: string;
58
+ /** Namespaced component (`pack.Component`) or a core component name. */
59
+ component?: string;
60
+ /** Props for the component; values may be literals or capability refs. */
61
+ props?: Record<string, SduiFragmentValue>;
62
+ /** Named slot this fragment fills in its parent component. */
63
+ slot?: string;
64
+ /** A capability view reference for data-driven fragments. */
65
+ dataRef?: `capability://${string}`;
66
+ /** Action handlers; every entry must be a capability action-intent reference. */
67
+ actions?: Record<string, SduiActionRef>;
68
+ /** Child fragments. */
69
+ children?: SduiFragment[];
70
+ }
71
+ type SduiTokenType = "color" | "spacing" | "fontSize" | "fontWeight" | "radius" | "border" | "shadow";
72
+ interface SduiToken {
73
+ type: SduiTokenType;
74
+ value: string;
75
+ description?: string;
76
+ }
77
+ /**
78
+ * A versioned set of design tokens. Tokens are semantic, not literal CSS — a
79
+ * renderer maps them to its own platform. Two channels consuming the same
80
+ * token set apply the same visual intent through different renderings.
81
+ */
82
+ interface SduiTokenSet {
83
+ formatVersion: typeof SDUI_TOKEN_SET_FORMAT_VERSION;
84
+ name: string;
85
+ version: string;
86
+ tokens: Record<string, SduiToken>;
87
+ }
88
+ interface SduiComponentDefinition {
89
+ /** Roles this component implements (for adoption-binding validation). */
90
+ implements?: string[];
91
+ /** JSON Schema for component props. */
92
+ propsSchema?: PortableJsonSchema;
93
+ /** Named slots this component accepts. */
94
+ slots?: string[];
95
+ }
96
+ /**
97
+ * A versioned pack of SDUI components. Compatible with the adoption-bindings
98
+ * `ComponentPackManifest` but adds prop schemas and slot declarations so a
99
+ * document can be validated without a renderer.
100
+ */
101
+ interface SduiComponentPack {
102
+ formatVersion: typeof SDUI_COMPONENT_PACK_FORMAT_VERSION;
103
+ pack: string;
104
+ namespace: string;
105
+ version: string;
106
+ /** SHA-256 digest of the published component-pack artifact. */
107
+ artifactDigest: string;
108
+ /**
109
+ * Where this pack is loaded from when it is delivered as a federated
110
+ * remote. The artifact digest identifies the pack that was reviewed; this
111
+ * is what a shell actually executes, so validation requires the two to be
112
+ * locked together or the review covers something other than what runs.
113
+ */
114
+ remote?: SduiComponentPackRemote;
115
+ components: Record<string, SduiComponentDefinition>;
116
+ }
117
+ /** Delivery binding for a federated component pack. */
118
+ interface SduiComponentPackRemote {
119
+ /** Remote entry URL the shell loads. */
120
+ entry: string;
121
+ /** Subresource-integrity value for that entry, e.g. `sha384-…`. */
122
+ integrity: string;
123
+ /** Exposed module path keyed by the component name it provides. */
124
+ exposes: Record<string, string>;
125
+ }
126
+ interface SduiComponentPackReference {
127
+ pack: string;
128
+ namespace: string;
129
+ /** Semver range, e.g. `^1.0.0`. */
130
+ range: string;
131
+ }
132
+ interface SduiTokenSetReference {
133
+ name: string;
134
+ version: string;
135
+ }
136
+ /**
137
+ * A versioned SDUI document: a tree of fragments, a token-set reference, and
138
+ * the component packs it depends on. This is the build-time input; the release
139
+ * is the validated, resolved output.
140
+ */
141
+ interface SduiDocument {
142
+ formatVersion: typeof SDUI_DOCUMENT_FORMAT_VERSION;
143
+ name: string;
144
+ version: string;
145
+ /** The tree rendered when no variant is selected. */
146
+ root: SduiFragment;
147
+ /**
148
+ * Alternative trees a compositor may select at request time, for experiment
149
+ * arms and personalization. Every variant is enumerated here and validated
150
+ * against the same grants as `root`, and all of them are covered by the
151
+ * release digest.
152
+ *
153
+ * Enumeration is what makes selection safe. A selector that can produce a
154
+ * tree outside this set cannot be validated at promotion, so "selection may
155
+ * never widen grants" would be unenforceable rather than merely unenforced.
156
+ */
157
+ variants?: SduiVariant[];
158
+ tokenSet: SduiTokenSetReference;
159
+ componentPacks: SduiComponentPackReference[];
160
+ }
161
+ /** One selectable alternative to a document's default tree. */
162
+ interface SduiVariant {
163
+ /** Stable key the compositor matches on. Unique within the document. */
164
+ id: string;
165
+ /** The audience or experiment arm this arm serves. */
166
+ description?: string;
167
+ root: SduiFragment;
168
+ }
169
+ interface ResolvedSduiComponentPack {
170
+ pack: string;
171
+ namespace: string;
172
+ version: string;
173
+ range: string;
174
+ artifactDigest: string;
175
+ /**
176
+ * The locked delivery binding, carried onto the release so the digest
177
+ * identifies which remote a channel is expected to load. Omitting it would
178
+ * let two releases differing only in their remote share a digest.
179
+ */
180
+ remote?: SduiComponentPackRemote;
181
+ }
182
+ /**
183
+ * A promoted, validated, immutable SDUI release. It bundles a document, a
184
+ * resolved token set, and locked component packs. Two channels (web, mobile,
185
+ * CLI) can consume the same release and render it through their own renderers
186
+ * while reads and actions remain capability references.
187
+ */
188
+ interface SduiRelease {
189
+ formatVersion: typeof SDUI_RELEASE_FORMAT_VERSION;
190
+ /** SHA-256 of the canonical document, token set, resolved packs, grants, and assembly identity. */
191
+ releaseDigest: string;
192
+ /** Approved application assembly this release was validated against. */
193
+ assemblyDigest: string;
194
+ document: SduiDocument;
195
+ tokenSet: SduiTokenSet;
196
+ componentPacks: ResolvedSduiComponentPack[];
197
+ grants: SduiAuthorizationGrants;
198
+ }
199
+ type SduiFindingCode = "unknown_component" | "incompatible_pack" | "unauthorized_data_ref" | "denied_view_ref" | "mutation_bypass" | "denied_intent_ref" | "intent_action_not_found" | "invalid_fragment" | "invalid_action_ref" | "unknown_token" | "duplicate_fragment_id" | "invalid_token_set" | "invalid_component_pack" | "invalid_document" | "missing_token_set" | "missing_component_pack" | "component_pack_not_in_assembly" | "capability_contract_not_in_assembly" | "duplicate_variant_id" | "fragment_grant_exceeds_release" | "remote_not_locked";
200
+ interface SduiFinding {
201
+ code: SduiFindingCode;
202
+ path: string;
203
+ message: string;
204
+ }
205
+ interface SduiValidationResult {
206
+ valid: boolean;
207
+ findings: SduiFinding[];
208
+ release: SduiRelease | undefined;
209
+ }
210
+ /**
211
+ * Explicit capability references authorized for an SDUI release.
212
+ *
213
+ * The presence of a view or action in a supplied usage contract proves that
214
+ * the capability publishes it, not that this document may use it. The
215
+ * experience host must therefore provide both grant lists explicitly.
216
+ */
217
+ interface SduiAuthorizationGrants {
218
+ /** Full `capability://namespace/view` references allowed in data bindings. */
219
+ views: readonly string[];
220
+ /** Full `capability://namespace/intent` references allowed in actions. */
221
+ intents: readonly string[];
222
+ /**
223
+ * Per-fragment narrowing, keyed by fragment id.
224
+ *
225
+ * The release-wide lists above are the ceiling. A listed fragment may use
226
+ * only the references named for it, and the narrowing is inherited by that
227
+ * fragment's children, so a page assembled from several teams' fragments
228
+ * gets least privilege rather than the union of everything any of them
229
+ * needs. A fragment entry can only ever narrow: naming a reference outside
230
+ * the release-wide list is an authoring error and is reported rather than
231
+ * silently granted.
232
+ *
233
+ * Keys are fragment ids, which are unique within a tree but may repeat
234
+ * across variants, so two variants using the same fragment id share one
235
+ * entry. Give them distinct ids when they need distinct narrowing. This
236
+ * cannot widen either fragment, since narrowing stays an intersection.
237
+ */
238
+ fragments?: Record<string, SduiFragmentGrants>;
239
+ }
240
+ /** References one fragment subtree may use, drawn from the release-wide lists. */
241
+ interface SduiFragmentGrants {
242
+ views?: readonly string[];
243
+ intents?: readonly string[];
244
+ }
245
+ interface SduiValidationInput {
246
+ document: SduiDocument;
247
+ tokenSet: SduiTokenSet;
248
+ /** Available component packs for version resolution. */
249
+ componentPacks: SduiComponentPack[];
250
+ /** Capability contracts available for data-ref and action validation. */
251
+ contracts: UsageContractDocument[];
252
+ /**
253
+ * Explicit authorization grants for every capability view and action
254
+ * reference used by the document. Contract membership alone never grants
255
+ * access.
256
+ */
257
+ grants: SduiAuthorizationGrants;
258
+ /** Approved resolved application composition. */
259
+ assembly: AssemblyLockfile;
260
+ /** Core component vocabulary every renderer implements. */
261
+ coreComponents?: readonly string[];
262
+ }
263
+
264
+ declare function assertSduiTokenSet(value: unknown, path?: string): asserts value is SduiTokenSet;
265
+ declare function assertSduiComponentPack(value: unknown, path?: string): asserts value is SduiComponentPack;
266
+ declare function assertSduiFragment(value: unknown, path?: string): asserts value is SduiFragment;
267
+ declare function assertSduiDocument(value: unknown, path?: string): asserts value is SduiDocument;
268
+ /**
269
+ * Validate the grant envelope before semantic release checks. Grants are
270
+ * intentionally references rather than capability names: a capability may
271
+ * publish several views and intents with different authorization decisions.
272
+ */
273
+ declare function assertSduiAuthorizationGrants(value: unknown, path?: string): asserts value is SduiAuthorizationGrants;
274
+ /** Validate a promoted release loaded from an untyped persistence or network seam. */
275
+ declare function assertSduiRelease(value: unknown, path?: string): asserts value is SduiRelease;
276
+
277
+ /**
278
+ * Validate an SDUI document and its dependencies, producing a promoted release
279
+ * when every check passes. This is the single build gate: it rejects unknown
280
+ * components, incompatible packs, unauthorized data references, and mutation
281
+ * bypasses. Returns every finding rather than throwing, so one CI run tells a
282
+ * vertical everything it has to change. Use {@link assertSduiReleaseValid} to
283
+ * throw on the first invalid result.
284
+ */
285
+ declare function validateSduiRelease(input: SduiValidationInput): SduiValidationResult;
286
+ /**
287
+ * Throw with every finding listed, for use as a build step. Returns the
288
+ * promoted release when valid.
289
+ */
290
+ declare function assertSduiReleaseValid(input: SduiValidationInput): SduiRelease;
291
+
292
+ /**
293
+ * Compute the canonical release digest for a valid release. Two releases with
294
+ * the same document, token set, and resolved packs produce the same digest,
295
+ * so a channel can verify it is consuming the exact release it was built for.
296
+ */
297
+ declare function computeReleaseDigest(document: SduiDocument, tokenSet: SduiTokenSet, componentPacks: ResolvedSduiComponentPack[], grants: SduiAuthorizationGrants, assemblyDigest: string): string;
298
+ /** Reject promoted release content that no longer matches its immutable digest. */
299
+ declare function assertSduiReleaseIntegrity(release: SduiRelease): void;
300
+
301
+ /**
302
+ * A channel is a rendering target (web, mobile, CLI). A channel consumes a
303
+ * validated release and resolves capability references through its own host
304
+ * adapters. Reads go through `ProjectionHost`; actions go through
305
+ * `PlatformHost`. The channel never interprets or bypasses capability
306
+ * references — it renders fragments and forwards action intents.
307
+ */
308
+ interface SduiChannel {
309
+ id: string;
310
+ /** Core components this channel renderer implements. */
311
+ coreComponents: readonly string[];
312
+ /** Consume a validated release; returns the release if the channel's core
313
+ * vocabulary covers every core component the document uses. */
314
+ consume(release: SduiRelease): SduiChannelConsumptionResult;
315
+ }
316
+ interface SduiChannelConsumptionResult {
317
+ /** The release the channel consumed. */
318
+ release: SduiRelease;
319
+ /** Whether the channel's core vocabulary covers the document. */
320
+ compatible: boolean;
321
+ /** Core components the document uses that the channel does not implement. */
322
+ missingCoreComponents: string[];
323
+ }
324
+ /**
325
+ * Create a channel that consumes a release. The channel verifies that every
326
+ * core component the document references is in its vocabulary; pack-namespaced
327
+ * components are resolved from the release's locked packs, not the channel.
328
+ */
329
+ declare function createSduiChannel(id: string, coreComponents: readonly string[]): SduiChannel;
330
+
331
+ declare const SDUI_DOCUMENT_JSON_SCHEMA: PortableJsonSchema;
332
+ declare const SDUI_RELEASE_JSON_SCHEMA: PortableJsonSchema;
333
+
334
+ export { type ResolvedSduiComponentPack, SDUI_COMPONENT_PACK_FORMAT_VERSION, SDUI_DOCUMENT_FORMAT_VERSION, SDUI_DOCUMENT_JSON_SCHEMA, SDUI_RELEASE_FORMAT_VERSION, SDUI_RELEASE_JSON_SCHEMA, SDUI_TOKEN_SET_FORMAT_VERSION, type SduiActionRef, type SduiAuthorizationGrants, type SduiCapabilityRef, type SduiChannel, type SduiChannelConsumptionResult, type SduiComponentDefinition, type SduiComponentPack, type SduiComponentPackReference, type SduiDocument, type SduiFinding, type SduiFindingCode, type SduiFragment, type SduiFragmentValue, type SduiRelease, type SduiToken, type SduiTokenSet, type SduiTokenSetReference, type SduiTokenType, type SduiValidationInput, type SduiValidationResult, assertSduiAuthorizationGrants, assertSduiComponentPack, assertSduiDocument, assertSduiFragment, assertSduiRelease, assertSduiReleaseIntegrity, assertSduiReleaseValid, assertSduiTokenSet, computeReleaseDigest, createSduiChannel, validateSduiRelease };