@fabrika/auth-core 0.9.0-dev.3 → 0.9.0-dev.30
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.
- package/package.json +3 -2
- package/src/canonical-path.ts +18 -0
- package/src/client-address.ts +74 -0
- package/src/contract-canonical.ts +159 -1
- package/src/contract-encoding.ts +181 -0
- package/src/contract.ts +203 -11
- package/src/dev-environment.ts +6 -0
- package/src/egress.ts +97 -0
- package/src/endpoint-digest.ts +22 -2
- package/src/framework-release.ts +72 -0
- package/src/framework-variables.ts +15 -0
- package/src/iam-mail.ts +354 -0
- package/src/index.ts +9 -0
- package/src/locale.ts +13 -1
- package/src/managed-environment.ts +140 -0
- package/src/membership.ts +12 -4
- package/src/ops.ts +1933 -0
- package/src/permissions.ts +42 -0
- package/src/public-egress.ts +168 -0
- package/src/requirement.ts +5 -2
- package/src/rpc.ts +8 -8
- package/src/sha256.ts +52 -14
- package/src/terminal.ts +105 -0
- package/src/token.ts +73 -13
- package/src/types.ts +63 -2
- package/src/wire.ts +7 -0
- package/types/src/canonical-path.d.ts +6 -0
- package/types/src/client-address.d.ts +7 -0
- package/types/src/contract-canonical.d.ts +11 -1
- package/types/src/contract-encoding.d.ts +18 -0
- package/types/src/contract.d.ts +188 -10
- package/types/src/dev-environment.d.ts +5 -0
- package/types/src/egress.d.ts +27 -0
- package/types/src/endpoint-digest.d.ts +5 -0
- package/types/src/framework-release.d.ts +25 -0
- package/types/src/framework-variables.d.ts +12 -1
- package/types/src/iam-mail.d.ts +92 -0
- package/types/src/index.d.ts +9 -0
- package/types/src/locale.d.ts +11 -1
- package/types/src/managed-environment.d.ts +32 -0
- package/types/src/membership.d.ts +8 -3
- package/types/src/ops.d.ts +657 -0
- package/types/src/permissions.d.ts +12 -0
- package/types/src/public-egress.d.ts +31 -0
- package/types/src/requirement.d.ts +2 -2
- package/types/src/rpc.d.ts +5 -5
- package/types/src/sha256.d.ts +10 -0
- package/types/src/terminal.d.ts +72 -0
- package/types/src/token.d.ts +36 -11
- package/types/src/types.d.ts +42 -2
- package/types/src/wire.d.ts +6 -0
package/src/token.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The IAM-issued token contract — the SECOND thing (after `IamRpc`) that must not drift
|
|
3
3
|
* between the Worker and the SDK.
|
|
4
4
|
*
|
|
5
5
|
* Background: today a request is authorized by the Worker resolving a Cloudflare Access JWT on
|
|
6
6
|
* every call over RPC (the CF token carries only identity, so authz needs a round-trip). When
|
|
7
|
-
*
|
|
7
|
+
* IAM issues its OWN token it can embed the already-resolved permission set, and the SDK
|
|
8
8
|
* authorizes LOCALLY — no per-request round-trip. This module is the wire shape of that token:
|
|
9
9
|
*
|
|
10
10
|
* - the Worker BUILDS claims here and signs them (`buildAccessClaims`);
|
|
@@ -47,7 +47,7 @@ export const FABRIKA_COOKIE_PREFIX = '__Host-px_'
|
|
|
47
47
|
* because those origins are potentially trustworthy.
|
|
48
48
|
*/
|
|
49
49
|
export const SESSION_COOKIE = `${FABRIKA_COOKIE_PREFIX}session`
|
|
50
|
-
/** Prefix marking
|
|
50
|
+
/** Prefix marking an IAM opaque credential (API key / share link), e.g. `Bearer px_<random>`. */
|
|
51
51
|
export const API_KEY_PREFIX = 'px_'
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -56,7 +56,7 @@ export const API_KEY_PREFIX = 'px_'
|
|
|
56
56
|
*/
|
|
57
57
|
export const WORKLOAD_TOKEN_PATH = '/auth/workload/token'
|
|
58
58
|
|
|
59
|
-
/** Signing algorithm
|
|
59
|
+
/** Signing algorithm IAM issues with and the SDK verifies (ECDSA P-256 — compact, ubiquitous). */
|
|
60
60
|
export const TOKEN_ALG = 'ES256'
|
|
61
61
|
/** JWT `typ` of an OAuth resource access token (RFC 9068). Native app tokens carry no `typ`. */
|
|
62
62
|
export const RESOURCE_ACCESS_TOKEN_TYP = 'at+jwt'
|
|
@@ -70,22 +70,32 @@ export const DEFAULT_TOKEN_TTL_SECONDS = 300
|
|
|
70
70
|
export const TOKEN_REFRESH_SKEW_SECONDS = 30
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
|
-
* The largest access token IAM signs, in bytes (a JWT is ASCII)
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
73
|
+
* The largest access token IAM signs, in bytes (a JWT is ASCII), except an application token below. A client sends
|
|
74
|
+
* such a token itself (an OAuth access token, a console bearer), so it crosses Caddy's `forward_auth` into the proxy's
|
|
75
|
+
* auth service and reaches installation services, which run on Bun with its default: a request's headers at most
|
|
76
|
+
* 16 KiB in total. 8 KiB leaves the rest for the request's own headers and cookies.
|
|
77
77
|
*/
|
|
78
78
|
export const MAX_ACCESS_TOKEN_BYTES = 8192
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* The largest token IAM mints for the proxy to inject toward a contract application, in bytes. No client sends it; on
|
|
82
|
+
* that hop it travels twice (`X-Fabrika-Token`, and `Authorization` on a bearer request), so two copies and 16 KiB of
|
|
83
|
+
* the request's own headers fit the header limit the platform starts the application's Bun with.
|
|
84
|
+
*/
|
|
85
|
+
export const MAX_APPLICATION_TOKEN_BYTES = 24576
|
|
86
|
+
|
|
87
|
+
/** The request-header limit the platform starts an application's Bun server with (`--max-http-header-size`). */
|
|
88
|
+
export const APPLICATION_SERVER_MAX_HEADER_BYTES = 65536
|
|
89
|
+
|
|
80
90
|
// ── Claim shape (one, no discriminator) ────────────────────────────────────────
|
|
81
91
|
|
|
82
92
|
/**
|
|
83
|
-
* The
|
|
93
|
+
* The IAM access token. `perms` is always present (matched via `permits`); `ptype` is present
|
|
84
94
|
* only when `sub` is a principal. `label` is the audit actor — the principal's label when bound, the
|
|
85
95
|
* credential label otherwise (or null).
|
|
86
96
|
*/
|
|
87
97
|
export interface AccessTokenClaims {
|
|
88
|
-
/** Issuer —
|
|
98
|
+
/** Issuer — IAM's own origin (e.g. `https://iam.example.com`). */
|
|
89
99
|
iss: string
|
|
90
100
|
/** The app id this token is scoped to. The SDK REJECTS a token whose `aud` is not its app. */
|
|
91
101
|
aud: string
|
|
@@ -117,12 +127,29 @@ export interface AccessTokenClaims {
|
|
|
117
127
|
* key carries what the key's own grants narrow, so a check that resolves the person's permissions requires this.
|
|
118
128
|
*/
|
|
119
129
|
session?: true
|
|
130
|
+
/**
|
|
131
|
+
* Present only on a session token of a person an application asserted at an enrolled terminal (ADR-0067), and
|
|
132
|
+
* always together with `terminal`.
|
|
133
|
+
*/
|
|
134
|
+
amr?: TerminalAuthenticationMethod
|
|
135
|
+
/** The terminal the person is signed in on; present exactly when `amr` is. */
|
|
136
|
+
terminal?: TerminalTokenClaims
|
|
120
137
|
/** Present only on an OAuth resource token (`aud` is then a resource URI, not an app id). */
|
|
121
138
|
oauth?: OAuthTokenClaims
|
|
122
139
|
/** Present only on a share-link token, which has no `ptype`: `sub` is then the link key's id. */
|
|
123
140
|
link?: LinkTokenClaims
|
|
124
141
|
}
|
|
125
142
|
|
|
143
|
+
/** The `amr` value of a session an application asserted at a terminal. */
|
|
144
|
+
export const TERMINAL_AUTHENTICATION_METHOD = 'terminal_assertion'
|
|
145
|
+
export type TerminalAuthenticationMethod = typeof TERMINAL_AUTHENTICATION_METHOD
|
|
146
|
+
|
|
147
|
+
/** The terminal a person's session was asserted on: its principal id and the label an administrator gave it. */
|
|
148
|
+
export interface TerminalTokenClaims {
|
|
149
|
+
id: string
|
|
150
|
+
label: string
|
|
151
|
+
}
|
|
152
|
+
|
|
126
153
|
/** What a share-link token adds: the link mount that issued the key and the chain the key is bound to. */
|
|
127
154
|
export interface LinkTokenClaims {
|
|
128
155
|
mount: string
|
|
@@ -162,7 +189,7 @@ export type TokenAudienceProfile = { kind: 'app'; app: string } | { kind: 'resou
|
|
|
162
189
|
//
|
|
163
190
|
// Transport is the IAM service binding (`getJwks()` RPC), NOT a public HTTPS URL: app↔IAM is
|
|
164
191
|
// RPC over the binding, which never traverses the Access edge — so the SDK reaches the key set
|
|
165
|
-
// even while
|
|
192
|
+
// even while IAM's own hostname is still gated by Cloudflare Access. The Worker also
|
|
166
193
|
// serves the standard `/.well-known/jwks.json`, for when Access is gone. Both emit this shape.
|
|
167
194
|
|
|
168
195
|
/** A published public signing key (EC P-256 / ES256). A jose-compatible JWK subset. */
|
|
@@ -184,7 +211,7 @@ export interface Jwks {
|
|
|
184
211
|
// ── Build (Worker side, pre-sign) ──────────────────────────────────────────────
|
|
185
212
|
|
|
186
213
|
export interface AccessTokenParams {
|
|
187
|
-
/** Issuer (
|
|
214
|
+
/** Issuer (IAM origin). */
|
|
188
215
|
iss: string
|
|
189
216
|
/** App id this token is for (becomes `aud`). */
|
|
190
217
|
app: string
|
|
@@ -200,6 +227,8 @@ export interface AccessTokenParams {
|
|
|
200
227
|
email?: string
|
|
201
228
|
/** Minted from a signed-in session; refused on a token without `type` or of a workload. */
|
|
202
229
|
session?: true
|
|
230
|
+
/** The terminal of a person's session asserted on one; sets `amr` too, and requires a user `type` and `session`. */
|
|
231
|
+
terminal?: TerminalTokenClaims
|
|
203
232
|
permissions: PermissionEntry[]
|
|
204
233
|
issuedAt: number
|
|
205
234
|
expiresAt: number
|
|
@@ -284,6 +313,13 @@ export function buildAccessClaims(params: AccessTokenParams): AccessTokenClaims
|
|
|
284
313
|
if (params.type === undefined || isWorkloadKind(params.type)) throw new Error("Only a person's or a service's token is minted from a session")
|
|
285
314
|
claims.session = params.session
|
|
286
315
|
}
|
|
316
|
+
if (params.terminal !== undefined) {
|
|
317
|
+
if (params.type !== 'user' || params.session !== true || !isTerminalClaims(params.terminal)) {
|
|
318
|
+
throw new Error("Only a person's session token names a terminal, and only by a non-empty id and label")
|
|
319
|
+
}
|
|
320
|
+
claims.amr = TERMINAL_AUTHENTICATION_METHOD
|
|
321
|
+
claims.terminal = { id: params.terminal.id, label: params.terminal.label }
|
|
322
|
+
}
|
|
287
323
|
if (params.link !== undefined) {
|
|
288
324
|
if (params.type !== undefined) throw new Error('A share-link token has no principal type')
|
|
289
325
|
claims.link = { mount: params.link.mount, chain: params.link.chain.map((scope) => ({ type: scope.type, value: scope.value })) }
|
|
@@ -333,6 +369,10 @@ export function parseAccessClaims(payload: unknown): AccessTokenClaims | null {
|
|
|
333
369
|
if (session !== undefined && (session !== true || ptype === null || isWorkloadKind(ptype) || oauth !== null)) {
|
|
334
370
|
return null
|
|
335
371
|
}
|
|
372
|
+
const terminal = parseTerminalClaims(prop(payload, 'amr'), prop(payload, 'terminal'))
|
|
373
|
+
if (terminal === undefined || (terminal !== null && (ptype !== 'user' || session !== true || oauth !== null))) {
|
|
374
|
+
return null
|
|
375
|
+
}
|
|
336
376
|
const claims: AccessTokenClaims = { iss, aud, sub, iat, exp, perms, label }
|
|
337
377
|
if (ptype !== null) {
|
|
338
378
|
claims.ptype = ptype
|
|
@@ -346,6 +386,10 @@ export function parseAccessClaims(payload: unknown): AccessTokenClaims | null {
|
|
|
346
386
|
if (session === true) {
|
|
347
387
|
claims.session = true
|
|
348
388
|
}
|
|
389
|
+
if (terminal !== null) {
|
|
390
|
+
claims.amr = TERMINAL_AUTHENTICATION_METHOD
|
|
391
|
+
claims.terminal = terminal
|
|
392
|
+
}
|
|
349
393
|
if (oauth !== null) {
|
|
350
394
|
claims.oauth = oauth
|
|
351
395
|
}
|
|
@@ -379,6 +423,22 @@ function parseEmail(value: unknown, ptype: TokenPrincipalType | null): string |
|
|
|
379
423
|
return ptype === 'user' && typeof value === 'string' && isNormalizedMailbox(value) ? value : undefined
|
|
380
424
|
}
|
|
381
425
|
|
|
426
|
+
/** Both absent → null; `amr` naming the terminal method beside a well-formed `terminal` → it; anything else → undefined. */
|
|
427
|
+
function parseTerminalClaims(amr: unknown, value: unknown): TerminalTokenClaims | null | undefined {
|
|
428
|
+
if (amr === undefined && value === undefined) {
|
|
429
|
+
return null
|
|
430
|
+
}
|
|
431
|
+
if (amr !== TERMINAL_AUTHENTICATION_METHOD) {
|
|
432
|
+
return undefined
|
|
433
|
+
}
|
|
434
|
+
const terminal = { id: stringField(value, 'id'), label: stringField(value, 'label') }
|
|
435
|
+
return isTerminalClaims(terminal) ? { id: terminal.id, label: terminal.label } : undefined
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function isTerminalClaims(value: { id: string | undefined; label: string | undefined }): value is TerminalTokenClaims {
|
|
439
|
+
return value.id !== undefined && value.id !== '' && value.label !== undefined && value.label !== ''
|
|
440
|
+
}
|
|
441
|
+
|
|
382
442
|
/** Absent → null; a mount and a non-empty chain → the claims; anything else → undefined. */
|
|
383
443
|
function parseLinkClaims(value: unknown): LinkTokenClaims | null | undefined {
|
|
384
444
|
if (value === undefined) {
|
|
@@ -470,7 +530,7 @@ function parseScope(value: unknown): Scope | null | undefined {
|
|
|
470
530
|
|
|
471
531
|
/** Validate `source` against the union — our own token, but read without `as`. */
|
|
472
532
|
function parseSource(value: unknown): PermissionSource | null {
|
|
473
|
-
if (value === 'grant' || value === 'bootstrap') {
|
|
533
|
+
if (value === 'grant' || value === 'bootstrap' || value === 'terminal') {
|
|
474
534
|
return value
|
|
475
535
|
}
|
|
476
536
|
if (typeof value === 'string' && value.startsWith('group:')) {
|
package/src/types.ts
CHANGED
|
@@ -31,8 +31,9 @@ export function isWorkloadKind(value: unknown): value is WorkloadKind {
|
|
|
31
31
|
* - 'grant' — explicit `grants` row
|
|
32
32
|
* - 'bootstrap' — IAM_BOOTSTRAP_ADMINS env match (resolution-time only)
|
|
33
33
|
* - `group:${groupRef}` — IdP group → role mapping (the `<org>/<team>` ref)
|
|
34
|
+
* - 'terminal' — a grant of the terminal a person is signed in on (ADR-0067)
|
|
34
35
|
*/
|
|
35
|
-
export type PermissionSource = 'grant' | 'bootstrap' | `group:${string}`
|
|
36
|
+
export type PermissionSource = 'grant' | 'bootstrap' | 'terminal' | `group:${string}`
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* A flat, app-owned scope coordinate — one dimension (`type`) and an opaque value.
|
|
@@ -44,6 +45,57 @@ export interface Scope {
|
|
|
44
45
|
value: string
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The pseudo-scope of a relation entry: `{ type: '~rel', value: <relation> }` means the action is held where a row of
|
|
50
|
+
* the application names the principal in that relation. No dimension may start with `~`, so no reader that compares
|
|
51
|
+
* scopes by `(type, value)` mistakes one for a dimension value, and none resolves it but the framework.
|
|
52
|
+
*/
|
|
53
|
+
export const RELATION_SCOPE_TYPE = '~rel'
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The pseudo-scope of a relation entry held inside one node: `{ type: '~relin', value: '<relation>:<dimension>:<node>' }`
|
|
57
|
+
* means the action is held where a row names the principal in that relation, on rows that lie inside `node` of
|
|
58
|
+
* `dimension`. IAM gives it a grant at that node of a role with `via`. Its own type, never `~rel`: a release that reads
|
|
59
|
+
* `~rel` as "the relation anywhere" ignores this one and reaches less.
|
|
60
|
+
*/
|
|
61
|
+
export const RELATION_INSIDE_SCOPE_TYPE = '~relin'
|
|
62
|
+
|
|
63
|
+
/** A relation held inside one node of a dimension, as a `~relin` entry names it. */
|
|
64
|
+
export interface RelationInside {
|
|
65
|
+
readonly relation: string
|
|
66
|
+
readonly dimension: string
|
|
67
|
+
readonly node: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The `~relin` scope of `relation` inside `node` of `dimension`. A relation or dimension name never holds `:` (the
|
|
72
|
+
* contract's names do not), so the node, last, is read back verbatim, colons included; a name that holds one is refused.
|
|
73
|
+
*/
|
|
74
|
+
export function relationInsideScope(inside: RelationInside): Scope {
|
|
75
|
+
if (inside.relation === '' || inside.dimension === '' || inside.relation.includes(':') || inside.dimension.includes(':')) {
|
|
76
|
+
throw new Error('a relation held inside a node names a relation and a dimension without ":"')
|
|
77
|
+
}
|
|
78
|
+
return { type: RELATION_INSIDE_SCOPE_TYPE, value: `${inside.relation}:${inside.dimension}:${inside.node}` }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The relation, dimension and node of a `~relin` scope, or null for any other scope or a malformed value. */
|
|
82
|
+
export function parseRelationInside(scope: Scope): RelationInside | null {
|
|
83
|
+
if (scope.type !== RELATION_INSIDE_SCOPE_TYPE) {
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
const first = scope.value.indexOf(':')
|
|
87
|
+
const second = first === -1 ? -1 : scope.value.indexOf(':', first + 1)
|
|
88
|
+
if (first <= 0 || second <= first + 1 || second === scope.value.length - 1) {
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
return { relation: scope.value.slice(0, first), dimension: scope.value.slice(first + 1, second), node: scope.value.slice(second + 1) }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
95
|
+
export function isReservedScopeType(type: string): boolean {
|
|
96
|
+
return type.startsWith('~')
|
|
97
|
+
}
|
|
98
|
+
|
|
47
99
|
export interface PermissionEntry {
|
|
48
100
|
action: string
|
|
49
101
|
/** null = global / all scopes */
|
|
@@ -79,6 +131,13 @@ export interface RoleDef {
|
|
|
79
131
|
member?: { scope: string; assignableBy?: string[] }
|
|
80
132
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
81
133
|
external?: true
|
|
134
|
+
/**
|
|
135
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
136
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation. A
|
|
137
|
+
* grant at a node carries `~relin` instead (`relationInsideScope`): the relation holds only inside that node. Only an
|
|
138
|
+
* internal role declares it.
|
|
139
|
+
*/
|
|
140
|
+
via?: Record<string, string[]>
|
|
82
141
|
}
|
|
83
142
|
|
|
84
143
|
/**
|
|
@@ -146,7 +205,7 @@ export interface AppDelegationDef {
|
|
|
146
205
|
purpose: 'members' | 'creates'
|
|
147
206
|
}
|
|
148
207
|
|
|
149
|
-
/** An app's full authz vocabulary, declared in the app's code, reconciled into
|
|
208
|
+
/** An app's full authz vocabulary, declared in the app's code, reconciled into IAM. */
|
|
150
209
|
export interface AppSchema {
|
|
151
210
|
scopes: AppScopeDef[]
|
|
152
211
|
actions: AppActionDef[]
|
|
@@ -177,6 +236,8 @@ export interface AppSchema {
|
|
|
177
236
|
members?: { manage: string; list: string }
|
|
178
237
|
/** `labels`: a holder of the app's `members.list` also sees each member's label. Absent, labels stay with `members.manage`. */
|
|
179
238
|
directory?: 'labels'
|
|
239
|
+
/** The app's identification page for a person at an enrolled terminal (ADR-0067); absent, no terminal lists it. */
|
|
240
|
+
terminal?: { identify: string }
|
|
180
241
|
}
|
|
181
242
|
|
|
182
243
|
/**
|
package/src/wire.ts
CHANGED
|
@@ -63,6 +63,13 @@ export function proxySecretVariable(id: string): string {
|
|
|
63
63
|
return `${FABRIKA_PROXY_SECRET}_${sha256Hex(id).slice(0, 32).toUpperCase()}`
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* The variable holding the secret the platform proxy sends IAM's installation entry in `PROXY_SECRET_HEADER`. The proxy
|
|
68
|
+
* and IAM hold it under this one name. It proves only who wrote IAM's request-id header; IAM keys every request without
|
|
69
|
+
* it on one shared client bucket.
|
|
70
|
+
*/
|
|
71
|
+
export const IAM_PROXY_SECRET_VARIABLE = 'FABRIKA_INSTALLATION_PROXY_SECRET_IAM'
|
|
72
|
+
|
|
66
73
|
/**
|
|
67
74
|
* Every `X-Fabrika-*` name a proxy hop carries to an application. Caddy's first step and the Cloudflare proxy Worker
|
|
68
75
|
* delete each of them from the client's request before anything else, then set only what the decision asserts. A new
|
|
@@ -18,3 +18,9 @@ export declare function splitRequestTarget(target: string): RequestTarget;
|
|
|
18
18
|
* the string because `new URL()` resolves dot segments and so hides the very paths that must be refused.
|
|
19
19
|
*/
|
|
20
20
|
export declare function rawRequestTarget(url: string): RequestTarget;
|
|
21
|
+
/**
|
|
22
|
+
* The absolute URL of `path` on `origin`, or `null` when `path` is not a path of that origin: the one rule for a
|
|
23
|
+
* redirect or return target that must stay on its own origin. A leading `//` or any `\` would make a browser read a
|
|
24
|
+
* host from it, and a browser strips a tab or newline before parsing, so no control character is admitted.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sameOriginTarget(origin: string, path: string): string | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client a client-address header value counts as: an IPv4 address, or an IPv6 address's /64 (one subscriber's
|
|
3
|
+
* prefix, of which it may hold every address); an IPv4-mapped IPv6 address counts as its IPv4 address. Only the first
|
|
4
|
+
* value counts, so a caller that appends a second copy cannot change the key. `null` when the value is absent or no
|
|
5
|
+
* IP address.
|
|
6
|
+
*/
|
|
7
|
+
export declare function clientAddressKey(header: string | null): string | null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BodyAdmission, ContractArtifact, OutputShape, SchemaShape, TableActionArtifact } from './contract';
|
|
1
|
+
import type { BodyAdmission, ConditionArtifact, ContractArtifact, OutputShape, SchemaShape, TableActionArtifact } from './contract';
|
|
2
2
|
/**
|
|
3
3
|
* The artifact with every array whose order carries no meaning sorted: endpoints by id, and every list of names.
|
|
4
4
|
* Tuple items and union options keep their order, because it changes what a schema admits. Object keys are left
|
|
@@ -11,9 +11,19 @@ export declare function canonicalArtifactJson(artifact: ContractArtifact): strin
|
|
|
11
11
|
export declare function canonicalJson(value: unknown): string;
|
|
12
12
|
/** Each action of one table operation, `[]` for none: how a reader of the artifact reads `actions.read` and the others. */
|
|
13
13
|
export declare function tableActions(actions: TableActionArtifact | null): readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* A condition with its connectives' operands and its `in` / `notIn` lists sorted by their canonical JSON: AND and OR
|
|
16
|
+
* commute and a list is a set, so neither order changes which rows it admits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalCondition(condition: ConditionArtifact): ConditionArtifact;
|
|
14
19
|
/** A body admission with its content types sorted. */
|
|
15
20
|
export declare function canonicalAdmission(admission: BodyAdmission): BodyAdmission;
|
|
16
21
|
/** An output shape: an attachment keeps its column order, which is the file's; each column's shape is canonical. */
|
|
17
22
|
export declare function canonicalOutput(shape: OutputShape): OutputShape;
|
|
18
23
|
/** A schema shape with its enum values sorted; tuple items and union options keep their order. */
|
|
19
24
|
export declare function canonicalShape(shape: SchemaShape): SchemaShape;
|
|
25
|
+
/**
|
|
26
|
+
* `canonicalJson(value)` written in pieces to `write`, so a digest of a large value never holds its whole text. Each
|
|
27
|
+
* object is rebuilt as `sortKeys` rebuilds it, so integer-like keys come first exactly as `JSON.stringify` orders them.
|
|
28
|
+
*/
|
|
29
|
+
export declare function writeCanonicalJson(value: unknown, write: (piece: string) => void): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ContractArtifact } from './contract';
|
|
2
|
+
/** The `encoding` of an encoded artifact; a plain artifact has no such key. */
|
|
3
|
+
export declare const SHARED_SHAPES_ENCODING = "shared-shapes";
|
|
4
|
+
/** In place of a shape: `shapes[index]` of the encoded artifact, which is always written before it is referenced. */
|
|
5
|
+
export interface SharedShapeReference {
|
|
6
|
+
readonly type: 'shared';
|
|
7
|
+
readonly index: number;
|
|
8
|
+
}
|
|
9
|
+
/** An artifact in the shared encoding, as JSON. */
|
|
10
|
+
export interface EncodedArtifact {
|
|
11
|
+
readonly encoding: typeof SHARED_SHAPES_ENCODING;
|
|
12
|
+
readonly shapes: readonly object[];
|
|
13
|
+
readonly artifact: object;
|
|
14
|
+
}
|
|
15
|
+
/** The canonical artifact in the shared encoding. */
|
|
16
|
+
export declare function encodeArtifact(artifact: ContractArtifact): EncodedArtifact;
|
|
17
|
+
/** The encoded artifact as text, keys sorted: what a build bundles. */
|
|
18
|
+
export declare function encodedArtifactJson(artifact: ContractArtifact): string;
|