@fabrika/auth-core 0.8.2 → 0.9.0-cloudflare.1

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.
Files changed (42) hide show
  1. package/package.json +4 -3
  2. package/src/contract-canonical.ts +1 -0
  3. package/src/contract.ts +6 -0
  4. package/src/dev-environment.ts +45 -0
  5. package/src/framework-release.ts +2 -0
  6. package/src/framework-variables.ts +14 -2
  7. package/src/index.ts +5 -0
  8. package/src/managed-environment.ts +136 -0
  9. package/src/ops.ts +497 -0
  10. package/src/terminal.ts +105 -0
  11. package/src/token.ts +65 -5
  12. package/src/types.ts +4 -1
  13. package/types/src/app-environment.d.ts +24 -0
  14. package/types/src/canonical-path.d.ts +20 -0
  15. package/types/src/contract-canonical.d.ts +19 -0
  16. package/types/src/contract.d.ts +800 -0
  17. package/types/src/dev-environment.d.ts +37 -0
  18. package/types/src/device.d.ts +144 -0
  19. package/types/src/endpoint-digest.d.ts +58 -0
  20. package/types/src/endpoints.d.ts +65 -0
  21. package/types/src/environment.d.ts +58 -0
  22. package/types/src/framework-release.d.ts +2 -0
  23. package/types/src/framework-variables.d.ts +86 -0
  24. package/types/src/index.d.ts +28 -0
  25. package/types/src/installation-endpoint.d.ts +46 -0
  26. package/types/src/json.d.ts +13 -0
  27. package/types/src/locale.d.ts +14 -0
  28. package/types/src/mail.d.ts +67 -0
  29. package/types/src/managed-environment.d.ts +32 -0
  30. package/types/src/membership.d.ts +318 -0
  31. package/types/src/oauth.d.ts +7 -0
  32. package/types/src/ops.d.ts +181 -0
  33. package/types/src/path-segment.d.ts +5 -0
  34. package/types/src/permissions.d.ts +50 -0
  35. package/types/src/requirement.d.ts +24 -0
  36. package/types/src/rpc.d.ts +283 -0
  37. package/types/src/sha256.d.ts +2 -0
  38. package/types/src/terminal.d.ts +72 -0
  39. package/types/src/token.d.ts +240 -0
  40. package/types/src/types.d.ts +196 -0
  41. package/types/src/wire.d.ts +65 -0
  42. package/types/src/workloads.d.ts +25 -0
@@ -0,0 +1,800 @@
1
+ import type { Locale } from './locale';
2
+ import type { MailTemplates } from './mail';
3
+ import type { TerminalArtifact } from './terminal';
4
+ /**
5
+ * The artifact format this release writes. A release that changes the artifact raises it, and Control upcasts every
6
+ * older format of its window to this one (ADR-0062). The 0.4, 0.5 and 0.6 artifacts carry no `format`.
7
+ */
8
+ export declare const CONTRACT_FORMAT = 2;
9
+ /**
10
+ * An application's whole access surface as plain JSON. `compileContract` produces it from the evaluated contract and
11
+ * the static reader from source; both must produce the same value for the same contract. Every optional authored
12
+ * field is normalized to `null`, `[]` or `{}`, so a field is always present. Key order and the order of `endpoints`
13
+ * carry no meaning.
14
+ */
15
+ export interface ContractArtifact extends EndpointTable {
16
+ readonly format: typeof CONTRACT_FORMAT;
17
+ readonly app: string;
18
+ readonly dimensions: Readonly<Record<string, DimensionArtifact>>;
19
+ /** Action → description. Exact actions only; the artifact holds no wildcard. */
20
+ readonly actions: Readonly<Record<string, string>>;
21
+ readonly roles: Readonly<Record<string, RoleArtifact>>;
22
+ readonly mounts: Readonly<Record<string, MountArtifact>>;
23
+ readonly files: Readonly<Record<string, FileCollectionArtifact>>;
24
+ /**
25
+ * The file kinds (`c.files({ types, maxBytes, scan? })`): classes of stored files a table's file column holds. A kind
26
+ * has no owner and no endpoint; the table that holds a file is its authority. Absent unless declared, so the digest stays.
27
+ */
28
+ readonly fileKinds?: Readonly<Record<string, FileKindArtifact>>;
29
+ readonly jobs: Readonly<Record<string, JobArtifact>>;
30
+ readonly exports: Readonly<Record<string, ExportArtifact>>;
31
+ readonly imports: Readonly<Record<string, ImportArtifact>>;
32
+ readonly csp: CspExtensions;
33
+ readonly tables: Readonly<Record<string, TablePolicyArtifact>>;
34
+ /**
35
+ * The reach each site declares off the paved road, by site: an endpoint's id (a procedure or a webhook), or
36
+ * `job:<name>`; a site that declares nothing has no entry. Present for a contract of the staged kit, whose sites
37
+ * reach only what they declare; absent for a `defineContract` one, so its digest stays what it was.
38
+ */
39
+ readonly declared?: Readonly<Record<string, DeclaredReach>>;
40
+ /**
41
+ * The member directory each endpoint reads (`ctx.members` without management), by endpoint id: derived from the
42
+ * dimensions by `directoryReach` and recorded so the approval sees and the digest covers it. Absent when no endpoint
43
+ * reads one, so the digest of such a contract stays.
44
+ */
45
+ readonly directories?: Readonly<Record<string, {
46
+ readonly dimension: string;
47
+ readonly lists: boolean;
48
+ }>>;
49
+ /** The language IAM speaks to this application's people. Absent unless declared, so the digest stays. */
50
+ readonly locale?: Locale;
51
+ /** The name IAM shows on its pages and e-mails for this application. Absent unless declared, so the digest stays. */
52
+ readonly displayName?: string;
53
+ /** The application's wording of IAM's e-mails. Absent unless declared, so the digest stays. */
54
+ readonly mail?: MailTemplates;
55
+ /**
56
+ * The application's own people, every holder of one of its roles: `manage` held globally administers its global roles in
57
+ * IAM's console, `list` held globally reads its member directory (`ctx.members` of an `app` endpoint of that action).
58
+ * Absent unless declared, so the digest stays.
59
+ */
60
+ readonly members?: {
61
+ readonly manage: string;
62
+ readonly list: string;
63
+ };
64
+ /** `labels`: the application's directory shows labels to `members.list` holders. Absent unless declared, so digests stay. */
65
+ readonly directory?: 'labels';
66
+ /**
67
+ * The page on the application's own origin that identifies a person at an enrolled terminal (ADR-0067): IAM sends a
68
+ * terminal's browser there, and only an application that declares it may assert a person. Absent unless declared.
69
+ */
70
+ readonly terminal?: TerminalArtifact;
71
+ /**
72
+ * What each procedure of the staged kit admits and how long it runs, by endpoint id, with every default applied: the
73
+ * rules the application applies itself, beside the row the proxy applies. Absent for a contract with no such
74
+ * procedure (a `defineContract` one, an older release's), so its digest stays.
75
+ */
76
+ readonly procedures?: Readonly<Record<string, ProcedureArtifact>>;
77
+ /**
78
+ * The purposes of the signed tokens the application issues (`token(Claims, { maxDays })` of `defineApp`'s options): each
79
+ * purpose's claims and the longest lifetime a token of it may have. Control keeps a retired signing key verifying until
80
+ * the last token it signed may expire. Absent unless declared, so the digest stays.
81
+ */
82
+ readonly tokens?: Readonly<Record<string, TokenPurposeArtifact>>;
83
+ }
84
+ /** One token purpose: the claims a token of it carries, and the most days a site may sign one for. */
85
+ export interface TokenPurposeArtifact {
86
+ readonly claims: SchemaShape;
87
+ readonly maxDays: number;
88
+ }
89
+ /**
90
+ * One procedure's own admission and time limit, effective values only. The body limit and codec are the row's
91
+ * `admission`, the origin rule its `crossOrigin`.
92
+ */
93
+ export interface ProcedureArtifact {
94
+ readonly rate: AdmissionRate;
95
+ /** The challenge the framework verifies before the handler; a public procedure only. */
96
+ readonly challenge: ProcedureChallenge | null;
97
+ /** How long the handler may run after the last body byte, in ms. */
98
+ readonly timeoutMs: number;
99
+ /** A POST's flat schema of the URL's parameters, the handler's `query`; absent without one, so digests stay. */
100
+ readonly query?: SchemaShape;
101
+ /**
102
+ * A public mutation served on `GET` (its input holds a signed token): a link scanner that follows the URL changes
103
+ * state. Absent otherwise, so digests stay.
104
+ */
105
+ readonly changesStateOnGet?: true;
106
+ }
107
+ /**
108
+ * A procedure's buckets, per minute and shared by every instance; `null` is no bucket. `perClient` counts by the client
109
+ * address (public only), `perCaller` by the principal or link key (credentialed and link only), `perEndpoint` every
110
+ * call. Every bucket is charged before the body is read and stays charged whatever the handler does.
111
+ */
112
+ export interface AdmissionRate {
113
+ readonly perClient: number | null;
114
+ readonly perCaller: number | null;
115
+ readonly perEndpoint: number | null;
116
+ /** The bytes the procedure's file fields may write per hour, all calls together. */
117
+ readonly bytesPerHour: number | null;
118
+ }
119
+ /** What `planEndpoint` selects from: the endpoint rows and the prefixes reserved for procedures. */
120
+ export interface EndpointTable {
121
+ readonly endpoints: readonly EndpointRow[];
122
+ /**
123
+ * Literal path prefixes of procedure mounts (`/api`). A path under one (`/api/…`) is served only by an endpoint
124
+ * declared under it, so an unknown procedure never reaches a broader endpoint such as the SPA.
125
+ */
126
+ readonly reservedPrefixes: readonly string[];
127
+ }
128
+ /** Who may call a credentialed endpoint. There is no public caller: anonymous traffic is a fixed endpoint kind. */
129
+ export type Caller = 'human' | 'machine' | 'link' | `app:${string}`;
130
+ /** `app:<id>`: the connector of the consuming application `<id>`. */
131
+ export declare const APP_CALLER_PREFIX = "app:";
132
+ /** Every export procedure and description is served under this prefix; an `app:<id>` caller reaches nothing else. */
133
+ export declare const CONNECT_PREFIX = "/__fabrika/connect";
134
+ /** An RPC mount's callers: a link holder reaches only its own link mount, and an `app:<id>` only an export. */
135
+ export type RpcCaller = 'human' | 'machine';
136
+ export type EndpointMethod = 'GET' | 'POST';
137
+ /** Kinds that verify a credential, check the caller kind and the requirement. */
138
+ export type CredentialedEndpointKind = 'query' | 'mutation' | 'spa' | 'upload' | 'download';
139
+ /**
140
+ * Fixed anonymous kinds: no caller, no requirement, no token. `link-spa` is the shell of a link mount's SPA;
141
+ * `public-spa` is an SPA anyone opens (`access: { public: true }`); `public` is a procedure anyone calls, whose handler
142
+ * runs as the endpoint's own workload. A proxy that does not know `public` refuses the manifest that holds one, so no
143
+ * proxy serves a public procedure without its admission rules.
144
+ */
145
+ export type AnonymousEndpointKind = 'health' | 'form' | 'webhook' | 'link-spa' | 'public-spa' | 'public';
146
+ export type EndpointKind = CredentialedEndpointKind | AnonymousEndpointKind;
147
+ /**
148
+ * The contract entry that declared an endpoint. A `challenge` row is the framework's own: the endpoint that issues the
149
+ * ALTCHA challenge of the public procedure `name`.
150
+ */
151
+ export interface EndpointSource {
152
+ readonly kind: 'mount' | 'export' | 'files' | 'challenge';
153
+ readonly name: string;
154
+ }
155
+ interface EndpointRowBase {
156
+ /** Unique in the table: the framework dispatches by it and the proxy names it in `X-Fabrika-Endpoint`. */
157
+ readonly id: string;
158
+ readonly source: EndpointSource;
159
+ readonly method: EndpointMethod;
160
+ /**
161
+ * Matched against the raw path, case-sensitively. Segments are literals, `:name` (one non-empty segment) or a
162
+ * terminal `*`. A non-root `*` needs the slash before it, and a trailing `/` is a literal empty segment.
163
+ */
164
+ readonly path: string;
165
+ /** The request body the endpoint admits; `null` admits none. */
166
+ readonly admission: BodyAdmission | null;
167
+ readonly input: SchemaShape | null;
168
+ readonly output: OutputShape | null;
169
+ /**
170
+ * Whether a page on another origin may call the endpoint (ADR-0022 "Cross-origin endpoints"): `environment` from
171
+ * the origins its environment lists, `any` (a form or a public procedure only) from every origin. Absent unless
172
+ * declared, so every other row keeps its digest. Only an RPC procedure, a public procedure and a form may carry it.
173
+ */
174
+ readonly crossOrigin?: CrossOriginForm;
175
+ /**
176
+ * `file`: the procedure answers a stored file (an output `file('<kind>')`), so the proxy and the application give every
177
+ * answer of it, a denial included, ADR-0022's file treatment. Absent otherwise, so every other row keeps its digest.
178
+ */
179
+ readonly response?: EndpointResponse;
180
+ /**
181
+ * How long a browser or a CDN may reuse a successful answer: a public `GET` query only (`http.cache`). Absent for
182
+ * every other row, which answers `no-store`, so every row without it keeps its digest.
183
+ */
184
+ readonly cache?: EndpointCache;
185
+ /**
186
+ * `forward`: the proxy passes the request's own `Authorization` to the application, never reading it as a platform
187
+ * credential: a webhook row whose verifier (`basic`, `bearer`) compares it with the binding's secret. A value that
188
+ * carries a `px_` key is still removed, and every other anonymous row loses the header (ADR-0022 rule 3). Absent
189
+ * otherwise, so every other row keeps its digest.
190
+ */
191
+ readonly authorization?: EndpointAuthorization;
192
+ }
193
+ /** What the proxy does with an anonymous request's `Authorization` on a row that names it: forward it to the application. */
194
+ export type EndpointAuthorization = 'forward';
195
+ /** The answer profile of a row that answers a stored file. */
196
+ export type EndpointResponse = 'file';
197
+ /** A cacheable row's lifetime: `maxAgeSeconds`, or `immutable`, a year, for an input that names an immutable value. */
198
+ export type EndpointCache = {
199
+ readonly maxAgeSeconds: number;
200
+ } | 'immutable';
201
+ /** The longest `maxAgeSeconds`: one year, the lifetime the proxy gives `immutable` too. */
202
+ export declare const MAX_CACHE_AGE_SECONDS = 31536000;
203
+ /** The endpoint kinds whose row may answer a stored file: a procedure's. */
204
+ export declare const FILE_RESPONSE_KINDS: readonly EndpointKind[];
205
+ /** Whether every answer of a row gets the file treatment: a collection's download, or a procedure that answers a file. */
206
+ export declare function answersFile(row: {
207
+ readonly kind: string;
208
+ readonly response?: EndpointResponse;
209
+ }): boolean;
210
+ /** How an endpoint admits another origin: from the environment's list, or (a form or a public procedure) from any origin. */
211
+ export type CrossOriginForm = 'environment' | 'any';
212
+ /** The endpoint kinds that may declare `crossOrigin`, and those of them that may admit any origin. */
213
+ export declare const CROSS_ORIGIN_KINDS: readonly EndpointKind[];
214
+ export declare const ANY_ORIGIN_KINDS: readonly EndpointKind[];
215
+ export interface CredentialedEndpoint extends EndpointRowBase {
216
+ readonly kind: CredentialedEndpointKind;
217
+ readonly callers: readonly [Caller, ...Caller[]];
218
+ readonly requirement: EndpointRequirement;
219
+ }
220
+ export interface AnonymousEndpoint extends EndpointRowBase {
221
+ readonly kind: AnonymousEndpointKind;
222
+ readonly callers: readonly [];
223
+ readonly requirement: null;
224
+ }
225
+ export type EndpointRow = CredentialedEndpoint | AnonymousEndpoint;
226
+ export interface BodyAdmission {
227
+ readonly contentTypes: readonly [string, ...string[]];
228
+ readonly maxBytes: number | null;
229
+ }
230
+ /**
231
+ * What the token must carry before the request reaches a handler. `member` is any permission of this application;
232
+ * `action` is that action in some scope, global included, and only globally under the `app` form. The access form is
233
+ * what the framework then resolves.
234
+ */
235
+ export type EndpointRequirement = MemberRequirement | ActionRequirement | CapabilitiesRequirement;
236
+ export interface MemberRequirement {
237
+ readonly kind: 'member';
238
+ }
239
+ export interface ActionRequirement {
240
+ readonly kind: 'action';
241
+ readonly action: string;
242
+ readonly access: AccessForm;
243
+ }
244
+ /**
245
+ * Several capabilities (`access: { capabilities }`), by the name the handler reads each under (`ctx.capabilities.<name>`):
246
+ * the token must carry every action, and the access form of each narrows it as it narrows a single one. At least two.
247
+ */
248
+ export interface CapabilitiesRequirement {
249
+ readonly kind: 'capabilities';
250
+ readonly capabilities: Readonly<Record<string, CapabilityRequirement>>;
251
+ }
252
+ /** One capability of several: an action in a dimension, its value read from an input field or listed `over` it. */
253
+ export interface CapabilityRequirement {
254
+ readonly action: string;
255
+ readonly access: CapabilityAccessForm;
256
+ }
257
+ export type CapabilityAccessForm = {
258
+ readonly form: 'over';
259
+ readonly dimension: string;
260
+ } | {
261
+ readonly form: 'in';
262
+ readonly dimension: string;
263
+ readonly from: string;
264
+ } | {
265
+ readonly form: 'on';
266
+ readonly dimension: string;
267
+ readonly from: string;
268
+ };
269
+ /** `from` names an input field or a path parameter of the endpoint. */
270
+ export type AccessForm = {
271
+ readonly form: 'over';
272
+ readonly dimension: string;
273
+ } | {
274
+ readonly form: 'in';
275
+ readonly dimension: string;
276
+ readonly from: string;
277
+ }
278
+ /** `from: null` is the object a link key is bound to. */
279
+ | {
280
+ readonly form: 'on';
281
+ readonly dimension: string;
282
+ readonly from: string | null;
283
+ } | {
284
+ readonly form: 'creates';
285
+ readonly dimension: string;
286
+ }
287
+ /** The action held as a global grant: data of the whole application, in no dimension. */
288
+ | {
289
+ readonly form: 'app';
290
+ };
291
+ /**
292
+ * The structure and constraints of an input or output schema. Objects are always strict: a contract admits no other.
293
+ * The union is closed; a schema form it cannot represent is refused where the contract is compiled or read. A
294
+ * default makes a value optional to the caller, so it is `optional`; a discriminated union is a `union`.
295
+ */
296
+ export type SchemaShape = StringShape | NumberShape | {
297
+ readonly type: 'boolean' | 'null';
298
+ } | {
299
+ readonly type: 'literal';
300
+ readonly value: string | number | boolean | null;
301
+ } | {
302
+ readonly type: 'enum';
303
+ readonly values: readonly string[];
304
+ } | ArrayShape | TupleShape | RecordShape | {
305
+ readonly type: 'object';
306
+ readonly fields: Readonly<Record<string, SchemaShape>>;
307
+ } | {
308
+ readonly type: 'optional';
309
+ readonly inner: SchemaShape;
310
+ } | {
311
+ readonly type: 'nullable';
312
+ readonly inner: SchemaShape;
313
+ } | {
314
+ readonly type: 'union';
315
+ readonly options: readonly SchemaShape[];
316
+ } | TokenShape | FileShape;
317
+ /**
318
+ * A signed token of a declared purpose (`signedToken('<purpose>')`): on the wire a string, verified by the application's
319
+ * framework as it parses the input (an HMAC over the purpose and the claims, and the expiry), and handed to the handler
320
+ * as the purpose's typed claims. Only a top-level field of a procedure's input or its `http.query`.
321
+ */
322
+ export interface TokenShape {
323
+ readonly type: 'token';
324
+ readonly purpose: string;
325
+ }
326
+ /**
327
+ * A stored file of a declared kind (`file('<kind>')`). In an input it is a top-level field, optional, or a bounded
328
+ * array of them: a multipart part of its own beside the JSON input. As an output it is the file the procedure answers.
329
+ */
330
+ export interface FileShape {
331
+ readonly type: 'file';
332
+ readonly kind: string;
333
+ }
334
+ export declare function isFileShape(shape: OutputShape): shape is FileShape;
335
+ /**
336
+ * What a procedure answers: a JSON value of a schema, a file of rows (`attachment()` of `@fabrika/app/contract`), or a
337
+ * redirect (`redirect()`).
338
+ */
339
+ export type OutputShape = SchemaShape | AttachmentShape | RedirectShape;
340
+ /**
341
+ * A procedure whose handler returns `{ to }` and whose answer is a redirect there: 303 after a POST, 302 after a GET.
342
+ * A target is a path of the application's own origin or a URL of one of `origins`; anything else fails the invocation.
343
+ */
344
+ export interface RedirectShape {
345
+ readonly type: 'redirect';
346
+ /** Exact `https://` origins a target may name, besides the application's own. */
347
+ readonly origins: readonly string[];
348
+ }
349
+ export declare function isRedirectShape(shape: OutputShape): shape is RedirectShape;
350
+ /** An output answered as JSON of a schema: neither a file nor a redirect. */
351
+ export declare function isSchemaOutput(shape: OutputShape): shape is SchemaShape;
352
+ /**
353
+ * A procedure whose handler returns rows and whose answer is a file the framework encodes from them. The columns are
354
+ * the row schema's fields in their declared order, which is the file's column order; each is a scalar cell.
355
+ */
356
+ export interface AttachmentShape {
357
+ readonly type: 'attachment';
358
+ /** `csv`: RFC 4180 text; `xlsx`: one sheet of typed cells. */
359
+ readonly format: AttachmentFormat;
360
+ /** The `Content-Disposition` file name: a fixed name the contract declares, never one a request sends. */
361
+ readonly filename: string;
362
+ /** The encoded file's limit, in bytes: an encoding over it fails the invocation and sends no body. */
363
+ readonly maxBytes: number;
364
+ readonly maxRows: number;
365
+ readonly columns: readonly AttachmentColumn[];
366
+ }
367
+ export type AttachmentFormat = 'csv' | 'xlsx';
368
+ export interface AttachmentColumn {
369
+ readonly name: string;
370
+ readonly shape: SchemaShape;
371
+ }
372
+ export declare function isAttachmentShape(shape: OutputShape): shape is AttachmentShape;
373
+ export interface StringShape {
374
+ readonly type: 'string';
375
+ /** `datetime`, `date`, `time` and `duration` are the ISO 8601 forms of `z.iso`. */
376
+ readonly format: 'uuid' | 'email' | 'url' | 'datetime' | 'date' | 'time' | 'duration' | null;
377
+ readonly minLength: number | null;
378
+ readonly maxLength: number | null;
379
+ /** The regular expression's source, without flags. */
380
+ readonly pattern: string | null;
381
+ readonly startsWith: string | null;
382
+ readonly endsWith: string | null;
383
+ readonly includes: string | null;
384
+ }
385
+ /** `exclusiveMin` and `exclusiveMax` are `false` when their bound is `null`. */
386
+ export interface NumberShape {
387
+ readonly type: 'number';
388
+ readonly int: boolean;
389
+ readonly min: number | null;
390
+ readonly exclusiveMin: boolean;
391
+ readonly max: number | null;
392
+ readonly exclusiveMax: boolean;
393
+ readonly multipleOf: number | null;
394
+ }
395
+ /** Fixed positions, then any number of `rest` values when it is not `null`. */
396
+ export interface TupleShape {
397
+ readonly type: 'tuple';
398
+ readonly items: readonly SchemaShape[];
399
+ readonly rest: SchemaShape | null;
400
+ }
401
+ export interface RecordShape {
402
+ readonly type: 'record';
403
+ readonly key: SchemaShape;
404
+ readonly value: SchemaShape;
405
+ }
406
+ export interface ArrayShape {
407
+ readonly type: 'array';
408
+ readonly items: SchemaShape;
409
+ readonly minItems: number | null;
410
+ readonly maxItems: number | null;
411
+ }
412
+ export interface DimensionArtifact {
413
+ /** The dimension that contains every value of this one (`note` is in `workspace`). */
414
+ readonly in: string | null;
415
+ /** The role `creates` grants the caller in a new value of this dimension. */
416
+ readonly creator: string | null;
417
+ readonly members: {
418
+ readonly manage: string;
419
+ readonly list: string;
420
+ } | null;
421
+ /** `labels`: the member directory shows labels to `members.list` holders. Absent unless declared, so digests stay. */
422
+ readonly directory?: 'labels';
423
+ }
424
+ export interface RoleArtifact {
425
+ readonly grants: readonly string[];
426
+ /**
427
+ * A membership role is granted only in a value of `scope`, by a holder of one of the `assignableBy` roles: there,
428
+ * or globally for an application-wide role (one with no `member`).
429
+ */
430
+ readonly member: {
431
+ readonly scope: string;
432
+ readonly assignableBy: readonly string[];
433
+ } | null;
434
+ /** An external principal may hold this membership role (ADR-0051). Absent unless declared, so digests stay. */
435
+ readonly external?: true;
436
+ }
437
+ export type MountArtifact = RpcMountArtifact | LinkMountArtifact | SpaMountArtifact | HealthMountArtifact | FormMountArtifact | WebhookMountArtifact;
438
+ export interface RpcMountArtifact {
439
+ readonly kind: 'rpc';
440
+ readonly prefix: string;
441
+ /** The callers of its credentialed procedures; none when every procedure it mounts is public. */
442
+ readonly callers: readonly RpcCaller[];
443
+ /**
444
+ * `backward`: Control refuses a publication that breaks a caller of a procedure it mounts (`incompatibleMountChanges`).
445
+ * Absent for the default, `unchecked`, so every other mount keeps its digest.
446
+ */
447
+ readonly compatibility?: MountCompatibility;
448
+ }
449
+ /** The promise a mount makes its callers; only `backward` is recorded. */
450
+ export type MountCompatibility = 'backward';
451
+ export interface LinkMountArtifact {
452
+ readonly kind: 'link';
453
+ readonly prefix: string;
454
+ /** The directory of the share SPA. */
455
+ readonly spa: string;
456
+ readonly dimension: string;
457
+ /** Frozen into every key the mount issues. */
458
+ readonly grants: readonly string[];
459
+ /** The action a `Ref` must carry to issue a link. */
460
+ readonly issuedBy: string;
461
+ readonly maxDays: number;
462
+ }
463
+ export interface SpaMountArtifact {
464
+ readonly kind: 'spa';
465
+ readonly prefix: string;
466
+ readonly dir: string;
467
+ /** The application variables whose values the mount's pages read from its browser config; present only when declared. */
468
+ readonly public?: readonly string[];
469
+ }
470
+ export interface HealthMountArtifact {
471
+ readonly kind: 'health';
472
+ readonly path: string;
473
+ }
474
+ export interface FormMountArtifact {
475
+ readonly kind: 'form';
476
+ readonly path: string;
477
+ /** The inbox table the form appends to. */
478
+ readonly appendTo: string;
479
+ /** Submissions per minute it admits from one client and accepts in all; each is present only when declared. */
480
+ readonly rate?: FormRate;
481
+ /** The input field that must stay empty; a filled one is answered as accepted and writes nothing. */
482
+ readonly honeypot?: string;
483
+ /** The challenge the framework verifies on the server before it writes the row. */
484
+ readonly challenge?: FormChallenge;
485
+ /** The cron job each accepted submission kicks: one run in the background, coalesced on the job's lease. */
486
+ readonly then?: string;
487
+ /**
488
+ * The files a submission carries beside its input, by field: each lands in its collection owned by nobody, and its
489
+ * id in the inbox column of the field's name, until the job that drains the inbox attaches it to its owner. Present
490
+ * only when declared, so every other form keeps its digest; such a form is `multipart/form-data` and challenged.
491
+ */
492
+ readonly files?: Readonly<Record<string, FormFileArtifact>>;
493
+ }
494
+ /**
495
+ * The media type of a form that takes files. A browser sends it from any page without a CORS preflight, so the proxy
496
+ * refuses such a form's request from an origin its row does not admit (ADR-0061).
497
+ */
498
+ export declare const FORM_MULTIPART_TYPE = "multipart/form-data";
499
+ /** The media type of a public procedure that declares `http: { body: 'urlencoded' }`: flat scalar fields, as a native form posts them. */
500
+ export declare const FORM_URLENCODED_TYPE = "application/x-www-form-urlencoded";
501
+ /** One file field of a form: the collection the file lands in, and whether a submission must carry it. */
502
+ export interface FormFileArtifact {
503
+ readonly collection: string;
504
+ readonly required: boolean;
505
+ }
506
+ export interface FormRate {
507
+ readonly perClient?: number;
508
+ readonly perForm?: number;
509
+ /** The bytes a form that takes files may write per hour, all its submissions together. */
510
+ readonly bytesPerHour?: number;
511
+ }
512
+ /**
513
+ * The closed list of challenge providers. Turnstile is verified at Cloudflare's endpoint and loads its widget from
514
+ * Cloudflare; ALTCHA is issued and verified by the application itself, and its widget is bundled with the page.
515
+ */
516
+ export type ChallengeProvider = 'turnstile' | 'altcha';
517
+ /** A 0.4/0.5 form's challenge: Turnstile, the only provider those releases verified. */
518
+ export interface FormChallenge {
519
+ readonly provider: 'turnstile';
520
+ /** The application variable holding the provider's secret: a name, never the value. */
521
+ readonly secret: string;
522
+ /** The application variable holding the widget's public site key, which every SPA mount's browser config serves. */
523
+ readonly siteKey?: string;
524
+ }
525
+ /** A public procedure's challenge, by provider. */
526
+ export type ProcedureChallenge = TurnstileChallenge | AltchaChallenge;
527
+ /** Turnstile: a form's challenge, and the widget `action` the verification expects back. */
528
+ export interface TurnstileChallenge extends FormChallenge {
529
+ /** The declared `action`, or the endpoint id with `_` for `.`. */
530
+ readonly action: string;
531
+ }
532
+ /**
533
+ * ALTCHA: a proof of work the application issues at its endpoint `GET /__fabrika/challenge/<action>` and verifies itself,
534
+ * signed with the HMAC key the application variable `secret` holds. A challenge carries the action and the host it was
535
+ * issued for, and passes for those only, before it expires.
536
+ */
537
+ export interface AltchaChallenge {
538
+ readonly provider: 'altcha';
539
+ /** The application variable holding the HMAC key: a name, never the value. */
540
+ readonly secret: string;
541
+ /** The declared `action`, or the endpoint id with `_` for `.`. */
542
+ readonly action: string;
543
+ /** The PBKDF2 iterations of one attempt; a visitor's browser makes several thousand attempts. */
544
+ readonly cost: number;
545
+ /** How long an issued challenge may be solved and submitted, in ms; a passed one is recorded as long. */
546
+ readonly maxAgeMs: number;
547
+ }
548
+ export interface WebhookMountArtifact {
549
+ readonly kind: 'webhook';
550
+ readonly path: string;
551
+ readonly scheme: WebhookScheme;
552
+ readonly boundTo: ScopeBinding;
553
+ readonly actions: readonly string[];
554
+ /** How long a delivery's handler may run after the last body byte, in ms; its body limit is its row's `admission`. */
555
+ readonly timeoutMs: number;
556
+ }
557
+ /**
558
+ * The providers whose signature the framework checks by name; every one signs the raw body with the binding's secret,
559
+ * and Twilio the public URL with it. Slack and Twilio post forms as well as JSON.
560
+ */
561
+ export declare const WEBHOOK_PRESETS: readonly ["github-sha256", "slack", "standard-webhooks", "stripe", "twilio"];
562
+ export type WebhookPreset = (typeof WEBHOOK_PRESETS)[number];
563
+ /**
564
+ * How a delivery proves it holds its binding's secret: a preset, an HMAC the framework computes in a declared shape,
565
+ * or the secret itself as a Basic password or a bearer token. A verifier is framework code, never the application's.
566
+ * `basic` and `bearer` read `Authorization`, which the proxy passes only to a row that declares `authorization:
567
+ * 'forward'` (ADR-0022 rule 3).
568
+ */
569
+ export type WebhookScheme = WebhookPreset | {
570
+ readonly hmac: HmacScheme;
571
+ } | {
572
+ readonly basic: true;
573
+ } | {
574
+ readonly bearer: true;
575
+ };
576
+ export type HmacAlgorithm = 'sha1' | 'sha256' | 'sha512';
577
+ /**
578
+ * An HMAC of the binding's secret over the signed content, read from `header` as `prefix` and the encoded digest.
579
+ * `'timestamp.body'` signs `<timestamp>.<body>` with the `timestamp` header's Unix seconds, which must be within five
580
+ * minutes of now; `id` names a header whose value the signed content starts with, as `<id>.`.
581
+ */
582
+ export interface HmacScheme {
583
+ readonly header: string;
584
+ readonly algorithm: HmacAlgorithm;
585
+ readonly encoding: 'hex' | 'base64';
586
+ readonly prefix?: string;
587
+ readonly timestamp?: string;
588
+ readonly signed: 'body' | 'timestamp.body';
589
+ readonly id?: string;
590
+ }
591
+ /** Where a workload's authority applies: the whole application, or one value of a dimension per binding. */
592
+ export type ScopeBinding = {
593
+ readonly kind: 'app';
594
+ } | {
595
+ readonly kind: 'dimension';
596
+ readonly dimension: string;
597
+ };
598
+ export interface FileCollectionArtifact {
599
+ /** The table whose rows own the files; a file inherits its owner's access. */
600
+ readonly owner: string;
601
+ readonly read: string;
602
+ readonly write: string;
603
+ readonly delete: string;
604
+ readonly maxBytes: number;
605
+ readonly types: readonly string[];
606
+ readonly maxPerOwner: number | null;
607
+ /**
608
+ * Whether a share link to the owner reaches the files: `true` through every link mount bound to the owner's
609
+ * dimension, a list through the named link mounts only.
610
+ */
611
+ readonly link: boolean | readonly string[];
612
+ /**
613
+ * Present when every upload waits `quarantined` for a clean malware verdict before it is served. Absent otherwise,
614
+ * so the digest of a contract that does not scan is what it was before the field existed.
615
+ */
616
+ readonly scan?: true;
617
+ }
618
+ /** One file kind: the media types its files may be, the largest file, and whether each waits for a clean scan. */
619
+ export interface FileKindArtifact {
620
+ readonly types: readonly string[];
621
+ readonly maxBytes: number;
622
+ /** Present when every file of the kind waits `quarantined` for a clean malware verdict before it is served. */
623
+ readonly scan?: true;
624
+ }
625
+ export interface JobArtifact {
626
+ readonly schedule: string;
627
+ readonly actions: readonly string[];
628
+ readonly scope: ScopeBinding;
629
+ /** How long one attempt may run, in ms, every default applied. */
630
+ readonly timeoutMs: number;
631
+ readonly retries: number;
632
+ }
633
+ /** An export's procedures are endpoint rows whose source is this export. */
634
+ export interface ExportArtifact {
635
+ readonly version: number;
636
+ readonly consumers: readonly string[];
637
+ readonly audience: string;
638
+ }
639
+ /**
640
+ * What an export's consumer vendors (`fabrika connect add`): the export's identity and each procedure's schemas, by
641
+ * the procedure's dotted path in the export. `digest` is `exportDigest` of the rest, and the consumer's import names it.
642
+ */
643
+ export interface ExportDescription {
644
+ readonly app: string;
645
+ readonly export: string;
646
+ readonly version: number;
647
+ readonly audience: string;
648
+ readonly procedures: Readonly<Record<string, ExportProcedureDescription>>;
649
+ readonly digest: string;
650
+ }
651
+ export interface ExportProcedureDescription {
652
+ readonly input: SchemaShape | null;
653
+ readonly output: SchemaShape;
654
+ }
655
+ export interface ImportArtifact {
656
+ readonly app: string;
657
+ readonly export: string;
658
+ readonly version: number;
659
+ /** The digest of the vendored export snapshot. */
660
+ readonly digest: string;
661
+ readonly procedures: readonly string[];
662
+ /** The endpoint ids whose handlers may call the import. */
663
+ readonly usedBy: readonly string[];
664
+ readonly timeoutMs: number | null;
665
+ }
666
+ /** `job:<name>`: a job's key in `ContractArtifact.declared`; an endpoint is keyed by its id. */
667
+ export declare const JOB_SITE_PREFIX = "job:";
668
+ /**
669
+ * What one site declares beyond its capability: `ctx.sql` in a mode, tables it reaches unscoped and in which mode, the
670
+ * imports it calls, the link mount it issues. A review signal for the approver, never an enforcement decision.
671
+ */
672
+ export interface DeclaredReach {
673
+ readonly sql: 'read' | 'write' | null;
674
+ readonly unscoped: Readonly<Record<string, 'read' | 'write'>>;
675
+ readonly connect: readonly string[];
676
+ readonly issues: string | null;
677
+ /** The cron job this mutation kicks after its commit (an older release's form); absent unless declared, so the digest stays. */
678
+ readonly then?: string;
679
+ /**
680
+ * The cron jobs this site may kick (`ctx.kick`), sorted: a mutation, a webhook or a job. Absent unless declared, so
681
+ * the digest stays. A contract's kick edges between jobs are acyclic.
682
+ */
683
+ readonly kicks?: readonly string[];
684
+ /** The mail transport this job reaches: the installation's or its own; absent unless declared. */
685
+ readonly mailer?: JobMailer;
686
+ /**
687
+ * The webhook whose bindings this mutation creates and removes (`ctx.webhooks('<name>')`), seeing each new binding's
688
+ * secret once. Absent unless declared, so the digest stays.
689
+ */
690
+ readonly binds?: string;
691
+ /**
692
+ * The token purposes this site signs (`ctx.tokens.sign('<purpose>', …)`), sorted. Absent unless declared, so the digest
693
+ * stays.
694
+ */
695
+ readonly signs?: readonly string[];
696
+ /**
697
+ * The HTTPS origins this site's code calls (`fetch`), sorted: a credentialed procedure, a webhook or a job. Absent
698
+ * unless declared, so the digest stays.
699
+ */
700
+ readonly egress?: readonly string[];
701
+ /**
702
+ * A public procedure's workload actions, sorted: all its handler holds, through the key Control issues for the
703
+ * endpoint (`contractWorkloads`). Present only on a public procedure's entry, so every other digest stays.
704
+ */
705
+ readonly actions?: readonly string[];
706
+ }
707
+ /** The mail transports a job may declare: the installation's default, or the application's own. */
708
+ export declare const JOB_MAILERS: readonly ["installation", "own"];
709
+ export type JobMailer = (typeof JOB_MAILERS)[number];
710
+ export interface CspExtensions {
711
+ readonly connectSrc: readonly CspSource[];
712
+ readonly imgSrc: readonly CspSource[];
713
+ readonly frameAncestors: readonly CspSource[];
714
+ /** Present only when the contract names a script origin (or a challenge provider needs one). */
715
+ readonly scriptSrc?: readonly CspSource[];
716
+ /** Present only when the contract names a frame origin; `frame-src` is emitted only then. */
717
+ readonly frameSrc?: readonly CspSource[];
718
+ /** Present only when the contract names a stylesheet origin, such as a hosted font's stylesheet. */
719
+ readonly styleSrc?: readonly CspSource[];
720
+ /** Present only when the contract names a font origin. */
721
+ readonly fontSrc?: readonly CspSource[];
722
+ /**
723
+ * Present only when a challenge provider's widget starts its Web Workers from `blob:` URLs (ALTCHA): its one source is
724
+ * `blob:` (`WORKER_BLOB_SOURCE` of `@fabrika/proxy-core/headers`), never an origin, and the contract cannot declare it.
725
+ */
726
+ readonly workerSrc?: readonly CspSource[];
727
+ }
728
+ export interface CspSource {
729
+ readonly origin: string;
730
+ readonly purpose: string;
731
+ }
732
+ /**
733
+ * The actions of one table operation, any one of which allows it: one action as its text, several as a list of at least
734
+ * two. A single action stays text, so the artifact of a policy that names one keeps its shape and digest.
735
+ */
736
+ export type TableActionArtifact = string | readonly string[];
737
+ export interface TablePolicyArtifact {
738
+ readonly scope: TableScope;
739
+ /** An inbox's read action is `read`; it has no write action, because only its form appends. */
740
+ readonly actions: {
741
+ readonly read: TableActionArtifact;
742
+ readonly insert: TableActionArtifact | null;
743
+ readonly update: TableActionArtifact | null;
744
+ readonly delete: TableActionArtifact | null;
745
+ /**
746
+ * A dimension or child table's actions besides `read` with which an `app` endpoint reads every row, read-only;
747
+ * present only when the policy names one.
748
+ */
749
+ readonly appRead?: readonly string[];
750
+ /** The actions with which an `app` endpoint counts and aggregates every row and reads none; present only when named. */
751
+ readonly appCount?: readonly string[];
752
+ };
753
+ readonly insert: readonly string[];
754
+ readonly update: readonly string[];
755
+ readonly version: string | null;
756
+ readonly createdBy: string | null;
757
+ /**
758
+ * Column → its own actions. A column without a read action falls back to the table's; a column with a write action
759
+ * is updated by that action only, never by the table's update action.
760
+ */
761
+ readonly columns: Readonly<Record<string, ColumnPolicyArtifact>>;
762
+ /**
763
+ * Column → the file kind it holds: a foreign key to `fabrika_files`, written only with a file reference. The table's
764
+ * actions are the file's authority. Absent unless declared, so the digest stays.
765
+ */
766
+ readonly files?: Readonly<Record<string, string>>;
767
+ }
768
+ /** A column's own read action, its own write action, or both; an absent one is left out. */
769
+ export interface ColumnPolicyArtifact {
770
+ readonly read?: string;
771
+ readonly write?: string;
772
+ }
773
+ export type TableScope = {
774
+ readonly mode: 'dimension';
775
+ readonly dimension: string;
776
+ readonly key: string;
777
+ readonly container: {
778
+ readonly dimension: string;
779
+ readonly column: string;
780
+ } | null;
781
+ } | {
782
+ readonly mode: 'child';
783
+ readonly parent: string;
784
+ readonly key: string;
785
+ readonly column: string;
786
+ readonly inherit: readonly string[];
787
+ } | {
788
+ readonly mode: 'inbox';
789
+ readonly form: string;
790
+ } | {
791
+ readonly mode: 'reference';
792
+ readonly reason: string;
793
+ }
794
+ /** Rows of the whole application, in no dimension: an `app` endpoint reads and writes them. */
795
+ | {
796
+ readonly mode: 'app';
797
+ readonly reason: string;
798
+ readonly key: string;
799
+ };
800
+ export {};