@fabrika/auth-core 0.9.0-dev.5 → 0.9.0-dev.50

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 (55) hide show
  1. package/package.json +3 -2
  2. package/src/agent.ts +89 -0
  3. package/src/canonical-path.ts +18 -0
  4. package/src/client-address.ts +74 -0
  5. package/src/contract-canonical.ts +168 -2
  6. package/src/contract-encoding.ts +181 -0
  7. package/src/contract.ts +220 -17
  8. package/src/egress.ts +97 -0
  9. package/src/endpoint-digest.ts +22 -2
  10. package/src/framework-release.ts +70 -0
  11. package/src/framework-variables.ts +14 -0
  12. package/src/iam-mail.ts +354 -0
  13. package/src/index.ts +7 -0
  14. package/src/installation-endpoint.ts +3 -2
  15. package/src/locale.ts +13 -1
  16. package/src/managed-environment.ts +11 -0
  17. package/src/membership.ts +12 -4
  18. package/src/oauth.ts +19 -0
  19. package/src/ops.ts +487 -16
  20. package/src/permissions.ts +42 -0
  21. package/src/public-egress.ts +168 -0
  22. package/src/requirement.ts +12 -4
  23. package/src/rpc.ts +137 -9
  24. package/src/scope-values.ts +123 -0
  25. package/src/sha256.ts +52 -14
  26. package/src/token.ts +195 -14
  27. package/src/types.ts +72 -1
  28. package/src/wire.ts +2 -1
  29. package/types/src/agent.d.ts +37 -0
  30. package/types/src/canonical-path.d.ts +6 -0
  31. package/types/src/client-address.d.ts +7 -0
  32. package/types/src/contract-canonical.d.ts +11 -1
  33. package/types/src/contract-encoding.d.ts +18 -0
  34. package/types/src/contract.d.ts +205 -16
  35. package/types/src/egress.d.ts +27 -0
  36. package/types/src/endpoint-digest.d.ts +5 -0
  37. package/types/src/framework-release.d.ts +23 -0
  38. package/types/src/framework-variables.d.ts +6 -1
  39. package/types/src/iam-mail.d.ts +92 -0
  40. package/types/src/index.d.ts +7 -0
  41. package/types/src/installation-endpoint.d.ts +3 -2
  42. package/types/src/locale.d.ts +11 -1
  43. package/types/src/managed-environment.d.ts +1 -1
  44. package/types/src/membership.d.ts +8 -3
  45. package/types/src/oauth.d.ts +11 -0
  46. package/types/src/ops.d.ts +133 -8
  47. package/types/src/permissions.d.ts +12 -0
  48. package/types/src/public-egress.d.ts +31 -0
  49. package/types/src/requirement.d.ts +5 -4
  50. package/types/src/rpc.d.ts +113 -6
  51. package/types/src/scope-values.d.ts +61 -0
  52. package/types/src/sha256.d.ts +10 -0
  53. package/types/src/token.d.ts +70 -8
  54. package/types/src/types.d.ts +48 -1
  55. package/types/src/wire.d.ts +2 -1
@@ -1,4 +1,5 @@
1
1
  import type { ContractArtifact, EndpointRow } from './contract';
2
+ import { type Locale } from './locale';
2
3
  import type { PrincipalAffiliation, Scope } from './types';
3
4
  /**
4
5
  * What an endpoint may ask IAM about the members of its own target (`ctx.members`): `manage` where its action is the
@@ -98,14 +99,18 @@ export declare const MAX_INVITATION_MESSAGE_LENGTH = 1000;
98
99
  * What an invitation by address carries besides its role. `label` is the invited person's company as the application
99
100
  * names it, `message` the inviter's personal note; both are plain text IAM escapes wherever it inserts them. `resend`
100
101
  * rotates the open invitation's link, restarts its lifetime and sends it again; without it, repeating an invitation
101
- * answers the open one and sends nothing.
102
+ * answers the open one and sends nothing. `locale` is the invited person's language, when the application knows it: IAM
103
+ * writes the invitation and the pages its link opens in it, and its acceptance keeps it as the person's, so IAM's later
104
+ * e-mails (a password reset) and pages speak it too. Without one, IAM speaks the language the person already has, else the
105
+ * application's. A resend that names one replaces the stored one.
102
106
  */
103
107
  export interface InvitationOptions {
104
108
  readonly label?: string;
105
109
  readonly message?: string;
106
110
  readonly resend?: boolean;
111
+ readonly locale?: Locale;
107
112
  }
108
- /** Why IAM refuses an invitation's label or message, or `null`. A message may break lines; nothing else is a control character. */
113
+ /** Why IAM refuses an invitation's label, message or locale, or `null`. A message may break lines; nothing else is a control character. */
109
114
  export declare function invitationOptionsProblem(options: InvitationOptions): string | null;
110
115
  /** How long a delegation grant may be held before it is spent. One request, so seconds. */
111
116
  export declare const DELEGATION_GRANT_TTL_SECONDS = 120;
@@ -152,7 +157,7 @@ export interface AssignMemberInput extends MembershipCaller {
152
157
  scope: Scope;
153
158
  role: string;
154
159
  member: MemberTarget;
155
- /** Only with an address: the invitation's label, message and resend (`InvitationOptions`). */
160
+ /** Only with an address: the invitation's label, message, resend and locale (`InvitationOptions`). */
156
161
  invitation?: InvitationOptions;
157
162
  }
158
163
  export type AssignMemberResult = {
@@ -3,5 +3,16 @@
3
3
  export declare function isOAuthResourceUri(value: unknown): value is string;
4
4
  /** Client ID Metadata Document identifier: HTTPS, explicit path, no userinfo, fragment or dot segments. */
5
5
  export declare function isCimdClientId(value: unknown): value is string;
6
+ /**
7
+ * The client id of every installation's own command-line client: a public client IAM knows without a metadata document.
8
+ * It is the one client id that is not a CIMD URL.
9
+ */
10
+ export declare const OAUTH_CLI_CLIENT_ID = "fabrika-cli";
11
+ /** The public device client an agent obtains an application grant with (ADR-0090). It is never served Control's resources. */
12
+ export declare const AGENT_CLIENT_ID = "agent-cli";
13
+ /** A client id a token or revocation request may name: a CIMD document's URL, or one of the two built-in clients. */
14
+ export declare function isOAuthClientId(value: unknown): value is string;
6
15
  /** RFC 6749 scope-token syntax; duplicates and empty sets are refused. */
7
16
  export declare function parseOAuthScopes(value: unknown): string[] | null;
17
+ /** A scope dimension type, or a value of one, as a parameterized scope token carries it (`deploy:alpha`, `read:project=a`). */
18
+ export declare function isScopeParameterText(value: unknown): value is string;
@@ -48,6 +48,8 @@ export interface ApplicationObjects {
48
48
  export declare function parseApplicationObjects(object: string | undefined, objects: string | undefined): ApplicationObjects | null;
49
49
  /** The R2 key, in the environment's bucket, of the maintenance state of `object`. */
50
50
  export declare function OPS_STATE_KEY(object: string): string;
51
+ /** The R2 key, in the environment's bucket, of the migration record of `object` (ADR-0069 §3). */
52
+ export declare function OPS_MIGRATION_RECORD_KEY(object: string): string;
51
53
  /** The maintenance modes, from the most permissive. */
52
54
  export declare const OPS_MODES: readonly ["open", "read-only", "closed", "inspect"];
53
55
  export type OpsMode = (typeof OPS_MODES)[number];
@@ -99,10 +101,64 @@ export interface OpsMigration {
99
101
  readonly checksum: string;
100
102
  readonly appliedAt: string;
101
103
  }
102
- /** Sent once the migrations ran and the application booted, with the new ledger. */
104
+ /**
105
+ * Sent once the migrations ran and the application booted, with the new ledger. `record` is the object's migration
106
+ * record, `null` when it has none; a release before the migrating boot omits it. `version` is the id of the Worker
107
+ * version that answers, `null` without the version metadata binding; a release before it omits it.
108
+ */
103
109
  export interface OpsMigrateAck {
104
110
  readonly generation: number;
105
111
  readonly migrations: readonly OpsMigration[];
112
+ readonly record?: OpsMigrationRecord | null;
113
+ readonly version?: string | null;
114
+ }
115
+ /** A file a migration record names: the ledger row's identity and checksum. */
116
+ export interface OpsMigrationFile {
117
+ readonly bundle: string;
118
+ readonly name: string;
119
+ readonly checksum: string;
120
+ }
121
+ /**
122
+ * What became of a record's transaction: `diverged`, the ledger holds some of its rows (a release before the gate
123
+ * migrated over it); `rewound`, an in-place rewind took the object back to the record's bookmark (ADR-0070 §9).
124
+ */
125
+ export declare const OPS_MIGRATION_OUTCOMES: readonly ["committed", "rolled_back", "diverged", "rewound"];
126
+ export type OpsMigrationOutcome = (typeof OPS_MIGRATION_OUTCOMES)[number];
127
+ /**
128
+ * The migration record (ADR-0069 §3), stored in the environment's bucket and answered by `migrate`: what one migrating
129
+ * boot did, written before its transaction and completed after it.
130
+ */
131
+ export interface OpsMigrationRecord {
132
+ /** A UUIDv7 per record; every later put of the record names it. */
133
+ readonly id: string;
134
+ /** The id of the Worker version that wrote it; `null` where the runtime has no version metadata, which no rewind accepts. */
135
+ readonly version: string | null;
136
+ /** The bookmark before the transaction, the only target of the in-place rewind; `null` where the runtime has none. */
137
+ readonly bookmark: string | null;
138
+ /** The digest of the ledger the boot started from (`@fabrika/db`'s `sqliteLedgerDigest`). */
139
+ readonly startDigest: string;
140
+ readonly files: readonly OpsMigrationFile[];
141
+ readonly at: string;
142
+ readonly outcome: OpsMigrationOutcome | null;
143
+ /** With `committed` (and `rewound` after it) only: the bookmark after the commit, or at the reconciliation that found it. */
144
+ readonly committedBookmark: string | null;
145
+ /** When a version first booted over the outcome; never with `rewound`. */
146
+ readonly booted: string | null;
147
+ }
148
+ /** Why a migrating boot failed; `record_unwritable` names only the put before the transaction. */
149
+ export declare const OPS_MIGRATION_FAILURES: readonly ["rolled_back", "committed", "record_unwritable"];
150
+ export type OpsMigrationFailureReason = (typeof OPS_MIGRATION_FAILURES)[number];
151
+ /** The status of a failed migrating boot, answered only by the release that holds the record. */
152
+ export declare const OPS_MIGRATION_FAILED_STATUS = 422;
153
+ /**
154
+ * The body of a failed migrating boot: the record as it stands, or as the boot tried to write it. `version` is the id of
155
+ * the Worker version that answers, as in `OpsMigrateAck`; a release before it omits it.
156
+ */
157
+ export interface OpsMigrationFailure {
158
+ readonly refused: 'migration_failed';
159
+ readonly reason: OpsMigrationFailureReason;
160
+ readonly record: OpsMigrationRecord;
161
+ readonly version?: string | null;
106
162
  }
107
163
  export interface OpsMaintenance {
108
164
  readonly mode: OpsMode;
@@ -177,6 +233,10 @@ export declare function parseOpsStateAck(body: unknown): OpsStateAck | null;
177
233
  export declare function parseOpsMigrateRequest(body: unknown): OpsMigrateRequest | null;
178
234
  export declare function parseOpsStaleRefusal(body: unknown): OpsStaleRefusal | null;
179
235
  export declare function parseOpsMigrateAck(body: unknown): OpsMigrateAck | null;
236
+ /** A stored or answered migration record, parsed strictly: its fields must also agree with each other. */
237
+ export declare function parseOpsMigrationRecord(body: unknown): OpsMigrationRecord | null;
238
+ /** A failed migrating boot's answer; its reason must be what its record says. */
239
+ export declare function parseOpsMigrationFailure(body: unknown): OpsMigrationFailure | null;
180
240
  export declare function parseOpsView(body: unknown): OpsView | null;
181
241
  export declare function parseOpsContentView(body: unknown): OpsContentView | null;
182
242
  /** The version of the dump format: the value, row and line encodings, the table hash and the manifest. */
@@ -235,6 +295,33 @@ export type OpsDumpValue = null | {
235
295
  export declare function opsDumpColumnProjection(column: string): string;
236
296
  /** The value `opsDumpColumnProjection` read. Throws, naming no value, on a pair it would not produce. */
237
297
  export declare function readOpsDumpValue(type: unknown, value: unknown): OpsDumpValue;
298
+ /**
299
+ * The most result columns, and the most parameters, one statement of workerd's SQLite takes; a table holds at most as
300
+ * many columns.
301
+ */
302
+ export declare const OPS_SQLITE_MAX_COLUMNS = 100;
303
+ /** The most columns of a table one statement of a page read projects: two result columns each, beside the rowid twice. */
304
+ export declare const OPS_DUMP_READ_COLUMNS: number;
305
+ /** One row of a keyset page: its rowid as decimal text, then the rowid and every column as the dump writes them. */
306
+ export interface OpsDumpPageRow {
307
+ readonly rowid: string;
308
+ readonly values: readonly OpsDumpValue[];
309
+ }
310
+ /** Runs one statement of a page read, with the parameters of the read's condition, and answers its rows. */
311
+ export type OpsDumpPageQuery = (sql: string) => readonly Readonly<Record<string, unknown>>[];
312
+ /**
313
+ * One keyset page of `table`: the first `limit` rows by rowid that `condition` (`WHERE …`, or empty) admits, read the
314
+ * way the producer and the importer's verification both read them. Each column reads as two result columns, so a table
315
+ * wider than `OPS_DUMP_READ_COLUMNS` reads in several statements over the same rows, which the caller runs in one
316
+ * synchronous turn, so no write falls between them. The common table expression names every result column, which an
317
+ * expression alone does not.
318
+ */
319
+ export declare function readOpsDumpPage(query: OpsDumpPageQuery, table: OpsDumpTablePlan, condition: string, limit: number): OpsDumpPageRow[];
320
+ /**
321
+ * The SQL that names a dump's rowid inline, so a row of a table at `OPS_SQLITE_MAX_COLUMNS` binds no more parameters
322
+ * than it has columns. It is the checked decimal text in a string literal, cast as `opsDumpValueBinding` casts it.
323
+ */
324
+ export declare function opsDumpRowidSql(rowid: OpsDumpValue): string;
238
325
  /** What a statement binds for one value of a dump. */
239
326
  export type OpsDumpParam = string | number | Uint8Array | null;
240
327
  /** The SQL expression that writes a value back and the parameter its `?` binds. */
@@ -309,8 +396,12 @@ export interface OpsDumpSchemaTable {
309
396
  readonly name: string;
310
397
  readonly virtual: boolean;
311
398
  readonly withoutRowid: boolean;
312
- /** Whether the table's SQL declares a `CHECK` constraint; a reader that cannot tell answers `true`. */
313
- readonly checked: boolean;
399
+ /**
400
+ * Every name a `CHECK` constraint of the table's SQL reads, ASCII-lowercase and unquoted (keywords included), so a
401
+ * column it does not list cannot change what a `CHECK` answers. Empty for a table without one; `null` from a reader
402
+ * that cannot tell, which counts as naming every column.
403
+ */
404
+ readonly checkNames: readonly string[] | null;
314
405
  readonly columns: readonly OpsDumpSchemaColumn[];
315
406
  readonly indexes: readonly OpsDumpSchemaIndex[];
316
407
  readonly foreignKeys: readonly OpsDumpSchemaForeignKey[];
@@ -337,8 +428,9 @@ export interface OpsDumpPlan {
337
428
  * The one rule both the producer, at export `begin`, and the importer, at import `begin`, apply to a schema: the plan
338
429
  * a dump is written and loaded by, or an `unsupported_schema` refusal naming the table. A foreign key whose parent lies
339
430
  * in its own table's cycle (the table itself included) is loaded `NULL` and linked once every row is in, so each of its
340
- * columns must take a temporary `NULL`: nullable, outside the primary key, referenced by no foreign key, in a table
341
- * without a `CHECK`, a `NOT NULL` generated column, or a partial or expression unique index. A `WITHOUT ROWID` or
431
+ * columns must take a temporary `NULL`: nullable, outside the primary key, referenced by no foreign key, named by no
432
+ * `CHECK`, in a table without a `NOT NULL` generated column, a generated column a `CHECK` names, or a partial, expression
433
+ * or generated-column unique index. A `WITHOUT ROWID` or
342
434
  * virtual table, a table without a name that reads its rowid, a foreign key to a table outside the dump or without the
343
435
  * named key, and a foreign key checked only at commit are refused.
344
436
  */
@@ -527,13 +619,25 @@ export declare function parseOpsImportDiscardAck(body: unknown): OpsImportDiscar
527
619
  * Writes the sentinel (the operation's id) into the object's KV storage, and answers the current bookmark and the
528
620
  * bookmark of `at`, which Control records before it arms anything.
529
621
  */
530
- export interface OpsRestorePrepare {
622
+ export interface OpsRestorePrepareAt {
531
623
  readonly step: 'prepare';
532
624
  readonly object: string;
533
625
  readonly generation: number;
534
626
  readonly sentinel: string;
535
627
  readonly at: string;
536
628
  }
629
+ /**
630
+ * The in-place rewind of a failed migration (ADR-0070 §9): `record` names the object's migration record, whose bookmark
631
+ * is the target, and the object checks every guard of the rewind before it writes the sentinel.
632
+ */
633
+ export interface OpsRestorePrepareRecord {
634
+ readonly step: 'prepare';
635
+ readonly object: string;
636
+ readonly generation: number;
637
+ readonly sentinel: string;
638
+ readonly record: string;
639
+ }
640
+ export type OpsRestorePrepare = OpsRestorePrepareAt | OpsRestorePrepareRecord;
537
641
  /** Arms the restore of `target` for the next session, answers, then resets the object. */
538
642
  export interface OpsRestoreArm {
539
643
  readonly step: 'arm';
@@ -541,12 +645,18 @@ export interface OpsRestoreArm {
541
645
  readonly generation: number;
542
646
  readonly sentinel: string;
543
647
  readonly target: string;
648
+ /** The migration record of an in-place rewind, whose guards the object checks again; absent for a side restore. */
649
+ readonly record?: string;
544
650
  }
545
- /** Reads, after the reset, whether the sentinel is still there. It writes nothing, so it carries no generation. */
651
+ /**
652
+ * Reads, after the reset, whether the sentinel is still there; it carries no generation. With `record`, an in-place
653
+ * rewind's, an absent sentinel also records `rewound` in that migration record, its only write.
654
+ */
546
655
  export interface OpsRestoreVerify {
547
656
  readonly step: 'verify';
548
657
  readonly object: string;
549
658
  readonly sentinel: string;
659
+ readonly record?: string;
550
660
  }
551
661
  /** `POST /__fabrika/ops/restore`: one step of rewinding an `inspect` object that serves no traffic. */
552
662
  export type OpsRestoreRequest = OpsRestorePrepare | OpsRestoreArm | OpsRestoreVerify;
@@ -600,7 +710,7 @@ export declare function parseOpsTimersView(body: unknown): OpsTimersView | null;
600
710
  /** The status of a data operation's refusal. It is answered only after authentication. */
601
711
  export declare const OPS_DATA_REFUSED_STATUS = 422;
602
712
  /** Why the object refused an export, import or restore step. */
603
- export declare const OPS_DATA_REFUSALS: readonly ["wrong_mode", "serving_object", "unsupported_schema", "not_fresh", "no_import", "invalid_manifest", "fuzzy_dump", "part_mismatch", "ledger_mismatch", "schema_mismatch", "verify_mismatch", "bookmark_unavailable", "row_too_large"];
713
+ export declare const OPS_DATA_REFUSALS: readonly ["wrong_mode", "serving_object", "unsupported_schema", "not_fresh", "no_import", "invalid_manifest", "fuzzy_dump", "part_mismatch", "ledger_mismatch", "schema_mismatch", "verify_mismatch", "bookmark_unavailable", "row_too_large", "not_rewindable", "version_changed", "wrong_target"];
604
714
  export type OpsDataRefusalReason = (typeof OPS_DATA_REFUSALS)[number];
605
715
  /** The body of a data refusal; `table` names the table at fault, an identifier and never a value. */
606
716
  export interface OpsDataRefusal {
@@ -608,3 +718,18 @@ export interface OpsDataRefusal {
608
718
  readonly table: string | null;
609
719
  }
610
720
  export declare function parseOpsDataRefusal(body: unknown): OpsDataRefusal | null;
721
+ /**
722
+ * The schema `planOpsDump` reads, from the PRAGMAs workerd admits, of every table a dump holds. An `INITIALLY DEFERRED`
723
+ * clause is read from the table's SQL outside its quotes and comments, and marks every foreign key of its table; the
724
+ * names a `CHECK` reads come from the same SQL (`checkNamesOf`).
725
+ */
726
+ export declare function describeOpsDumpSchema(query: OpsDumpSchemaQuery): OpsDumpSchema;
727
+ /**
728
+ * The names the `CHECK` clauses of a table's `sql` read: every word and quoted identifier between a `CHECK` keyword's
729
+ * parentheses, ASCII-lowercase, keywords and numbers included, so it lists at least every column a `CHECK` reads. A
730
+ * string literal and a comment name nothing; a double-quoted string, which SQLite may read as either, counts as a name.
731
+ * `null` when the text does not scan (an unclosed quote, comment or parenthesis), which counts as naming every column.
732
+ */
733
+ export declare function checkNamesOf(sql: string): string[] | null;
734
+ /** One statement's rows, as a Durable Object's `sql.exec(...).toArray()` or a `bun:sqlite` query answers them. */
735
+ export type OpsDumpSchemaQuery = (sql: string, ...bindings: string[]) => readonly Readonly<Record<string, unknown>>[];
@@ -1,3 +1,4 @@
1
+ import type { KeyGrant } from './rpc';
1
2
  import type { PermissionEntry, Scope } from './types';
2
3
  /**
3
4
  * Wildcard action matching. The pattern is one of:
@@ -16,6 +17,11 @@ import type { PermissionEntry, Scope } from './types';
16
17
  * matchAction('project.*', 'projects.read') === false
17
18
  */
18
19
  export declare function matchAction(pattern: string, action: string): boolean;
20
+ /**
21
+ * `entries` with each identical action, scope and source once, the first kept in order: how IAM resolves a principal's
22
+ * permissions, so two roles granting one action at one scope put one entry into the token.
23
+ */
24
+ export declare function uniquePermissions(entries: readonly PermissionEntry[]): PermissionEntry[];
19
25
  /**
20
26
  * Does `entries` grant `action` at the given scope? Mirrors `can()` semantics exactly:
21
27
  * - scope === undefined → scope-less: ONLY entries with scope === null satisfy (global perms only).
@@ -48,3 +54,9 @@ export declare function scopedValues(entries: PermissionEntry[], action: string,
48
54
  * - otherwise → invalid.
49
55
  */
50
56
  export declare function isActionAllowed(pattern: string, catalog: readonly string[]): boolean;
57
+ /**
58
+ * Intersect live permissions with a ceiling: an OAuth scope's grants, or a terminal's patterns for an application. The
59
+ * ceiling never adds anything: each result is the narrower action and the narrower scope of one held entry and one
60
+ * ceiling entry that overlap, so a held `*` under a ceiling `a.read` yields `a.read`.
61
+ */
62
+ export declare function narrowPermissions(live: readonly PermissionEntry[], ceiling: readonly KeyGrant[]): PermissionEntry[];
@@ -0,0 +1,31 @@
1
+ /** The declared form of public egress: every public host, over HTTPS or HTTP, on its default port. */
2
+ export declare const PUBLIC_EGRESS = "public";
3
+ export type PublicEgress = typeof PUBLIC_EGRESS;
4
+ /** What a site declares in `egress`: its exact HTTPS origins, sorted, or every public host (a cron job only). */
5
+ export type DeclaredEgress = readonly string[] | PublicEgress;
6
+ /**
7
+ * The name suffixes public egress refuses, each with every name under it: local and special-use names (RFC 6761,
8
+ * RFC 6762, RFC 8375, RFC 9476), the names private networks conventionally use (`.internal` holds Google's metadata
9
+ * host and Control's own `operations.internal`), and the platform subdomains an installation is served on beside its
10
+ * own domains: Cloudflare's `workers.dev`, where its Workers have their default routes, and Zerops' `zerops.app`, where
11
+ * its proxies, Control and IAM have their subdomains (a namespace proxy's `proxy-…-8080.<region>.zerops.app`), with the
12
+ * `zerops` suffix of a Zerops project's private network. Control knows no list of those subdomains, so every one is
13
+ * refused, another installation's too.
14
+ */
15
+ export declare const PUBLIC_EGRESS_REFUSED_SUFFIXES: readonly ["localhost", "local", "internal", "intranet", "lan", "home", "corp", "private", "arpa", "test", "invalid", "example", "onion", "alt", "zerops", "zerops.app", "workers.dev"];
16
+ /** A host name without its trailing dots, lowercased: the form every comparison here uses. */
17
+ export declare function normalizedHost(hostname: string): string;
18
+ /**
19
+ * Why public egress refuses `url`, or `null` when the URL alone admits it: a scheme other than `https:` and `http:`, a
20
+ * port other than the scheme's default, credentials in the URL, an IP literal, a name of one label, a name under a
21
+ * refused suffix, or one of `refusedHosts` (normalized names). A host it admits may still resolve to a private address,
22
+ * which only a runtime that resolves names refuses.
23
+ */
24
+ export declare function publicEgressRefusal(url: URL, refusedHosts?: ReadonlySet<string>): string | null;
25
+ /**
26
+ * Whether `address` (an IPv4 or IPv6 address, as a resolver answers it) is a public unicast address: not private,
27
+ * loopback, link-local (which holds the cloud metadata address 169.254.169.254), shared, multicast, reserved,
28
+ * documentation, or an IPv6 form that embeds or tunnels an IPv4 address it cannot vouch for. A text that is no address
29
+ * is not public.
30
+ */
31
+ export declare function isPublicAddress(address: string): boolean;
@@ -6,15 +6,16 @@ import type { PermissionEntry } from './types';
6
6
  * Whether a token's permissions meet an endpoint's requirement. This is authorization, not a gate: it reads only the
7
7
  * token. `member` is any permission of this application; an action is that action in some scope, global included.
8
8
  * The access form narrows it to one scope afterwards, against the application's own data. The `app` form is the
9
- * action held as a global grant, so an entry scoped to any value does not meet it. Several capabilities need every
10
- * one of their actions. `authenticated`, which only an installation row carries, needs no permission.
9
+ * action held as a global grant, so an entry scoped to any value does not meet it; `anyOf` is one of its actions held so.
10
+ * Several capabilities need every one of their actions. `authenticated`, which only an installation row carries, needs no permission.
11
11
  */
12
12
  export declare function satisfies(requirement: EndpointRequirement | AuthenticatedRequirement, perms: readonly PermissionEntry[]): boolean;
13
13
  /**
14
14
  * The caller kind a verified token presents: a `user` principal is `human`, a `service` principal is `machine`, a
15
15
  * connector key of application `<id>` is `app:<id>`, and a token bound to no principal is a share link. An OAuth
16
- * resource token is `oauth`, which only an installation row admits. A job, webhook or public procedure token is no
17
- * caller: `null` is refused by every endpoint.
16
+ * resource token is `oauth`, which only an installation row admits. A person's token that acts for an agent (`act`,
17
+ * ADR-0090) is `agent`, admitted only where a row lists it. A job, webhook or public procedure token is no caller:
18
+ * `null` is refused by every endpoint.
18
19
  */
19
20
  export declare function callerOf(claims: AccessTokenClaims): TokenCaller | null;
20
21
  /**
@@ -1,5 +1,5 @@
1
1
  import type { ApproveDeviceAuthorizationInput, ApproveDeviceAuthorizationResult, DenyDeviceAuthorizationResult, InspectDeviceAuthorizationInput, InspectDeviceAuthorizationResult, ListOwnDeviceAuthorizationsInput, ListOwnDeviceAuthorizationsResult } from './device';
2
- import type { Jwks } from './token';
2
+ import { type Jwks } from './token';
3
3
  import type { PermissionEntry, PrincipalType, Scope } from './types';
4
4
  export interface MintTokenInput {
5
5
  /** The app requesting a permission token (the SDK bakes this into its constructor). */
@@ -69,6 +69,113 @@ export type ExchangeAuthCodeResult =
69
69
  export interface IamHandoffRpc {
70
70
  exchangeAuthCode(input: ExchangeAuthCodeInput): Promise<ExchangeAuthCodeResult>;
71
71
  }
72
+ export interface MintFromGrantInput {
73
+ /** The application environment `<app>@<env>` the proxy fronts. */
74
+ app: string;
75
+ /** The resource the proxy serves the request on: the host's origin. */
76
+ resource: string;
77
+ /** The agent's resource access token, as it arrived as the bearer. */
78
+ token: string;
79
+ requestId: string;
80
+ }
81
+ export type MintFromGrantResult = {
82
+ ok: true;
83
+ token: string;
84
+ expiresAt: number;
85
+ }
86
+ /**
87
+ * `invalid_grant`: the token, its grant, the approving login or the person no longer holds. `write_refused`: the
88
+ * environment's `agent-write` gate serves no `write` grant. `token_too_large`: a decided refusal, as for a key.
89
+ */
90
+ | {
91
+ ok: false;
92
+ reason: 'invalid_grant' | 'write_refused' | 'token_too_large';
93
+ };
94
+ /** The exchange of an agent's grant, as a contract of its own: only the proxy calls it. */
95
+ export interface IamGrantRpc {
96
+ mintFromGrant(input: MintFromGrantInput): Promise<MintFromGrantResult>;
97
+ }
98
+ /** How far back the feed reaches: no token outlives `DEFAULT_TOKEN_TTL_SECONDS`, so an older revocation ends nothing. */
99
+ export declare const REVOCATION_FEED_WINDOW_SECONDS = 300;
100
+ /** The most subjects one answer lists; past it the answer is `complete: false` and the proxy drops every cached token. */
101
+ export declare const REVOCATION_FEED_MAX_SUBJECTS = 5000;
102
+ export interface RevocationsInput {
103
+ /** IAM's clock, unix seconds: the feed answers revocations at or after it, within the window. `null`: the whole window. */
104
+ since: number | null;
105
+ }
106
+ /** A subject (a token's `sub`: a principal, or an anonymous credential) and the latest revocation of it, IAM's clock. */
107
+ export interface RevokedSubject {
108
+ subject: string;
109
+ at: number;
110
+ }
111
+ export type RevocationsResult =
112
+ /** `now` is IAM's clock at the read; `complete: false` when more subjects were revoked than one answer lists. */
113
+ {
114
+ ok: true;
115
+ now: number;
116
+ complete: boolean;
117
+ subjects: RevokedSubject[];
118
+ }
119
+ /** The caller is not the proxy (an application's binding on Cloudflare). */
120
+ | {
121
+ ok: false;
122
+ reason: 'not_allowed';
123
+ };
124
+ /** The revocation feed, as a contract of its own: only the proxy calls it. */
125
+ export interface IamRevocationRpc {
126
+ revocations(input: RevocationsInput): Promise<RevocationsResult>;
127
+ }
128
+ /** The longest window `signInSignals` answers: a reader that fell further behind reads the last day only. */
129
+ export declare const SIGN_IN_SIGNALS_MAX_WINDOW_SECONDS: number;
130
+ /** The most accounts and privileged sign-ins one answer lists; `accountsTruncated`/`privilegedTruncated` say a list was cut. */
131
+ export declare const SIGN_IN_SIGNALS_LIMIT = 500;
132
+ export interface SignInSignalsInput {
133
+ /**
134
+ * Unix seconds, inclusive, by `auth_log.created_at`: where privileged sign-ins are listed from. The reader overlaps
135
+ * windows, never resumes from an id.
136
+ */
137
+ since: number;
138
+ /** Unix seconds, inclusive, by `auth_log.created_at`: where refusals are counted from, so a threshold has one window. */
139
+ refusalsSince: number;
140
+ /** Unix seconds, inclusive. */
141
+ until: number;
142
+ }
143
+ export interface SignInAccountRefusals {
144
+ principalId: string;
145
+ /** Refused password sign-ins of this known account from `refusalsSince`. */
146
+ refusals: number;
147
+ }
148
+ export interface SignInRefusalReason {
149
+ reason: string;
150
+ refusals: number;
151
+ }
152
+ export interface PrivilegedSignIn {
153
+ /** The `auth_log` row id, as a string on both engines: the reader's deduplication key. */
154
+ id: string;
155
+ principalId: string;
156
+ reason: string | null;
157
+ /** Unix seconds. */
158
+ at: number;
159
+ }
160
+ export type SignInSignalsResult = {
161
+ ok: true;
162
+ /** Per known account, the most first. */
163
+ accounts: SignInAccountRefusals[];
164
+ /** Every counted refusal from `refusalsSince`, unknown accounts and refused `px_` keys included. */
165
+ refusals: number;
166
+ reasons: SignInRefusalReason[];
167
+ /** Allowed sign-ins of a principal that administers at IAM from `since`, oldest first. */
168
+ privileged: PrivilegedSignIn[];
169
+ accountsTruncated: boolean;
170
+ /** The list stops at its oldest `SIGN_IN_SIGNALS_LIMIT`; a reader resumes after the last one it got. */
171
+ privilegedTruncated: boolean;
172
+ } | {
173
+ ok: false;
174
+ reason: 'invalid_window';
175
+ };
176
+ export interface IamSignInSignalsRpc {
177
+ signInSignals(input: SignInSignalsInput): Promise<SignInSignalsResult>;
178
+ }
72
179
  /**
73
180
  * Where the proxy answers the handoff, on every app host it fronts. Reserved: an app route at this
74
181
  * path is shadowed by the proxy and never reaches the upstream, so it is deliberately namespaced.
@@ -110,8 +217,8 @@ export interface IssueKeyServiceSpec {
110
217
  export interface IssueKeyInput {
111
218
  app: string;
112
219
  /**
113
- * The propustka-native credential the ISSUER is resolved from server-side (never self-asserted):
114
- * a `px_token` access JWT (verified against propustka's signing keys) or a `px_` key. Null = absent.
220
+ * The IAM-native credential the ISSUER is resolved from server-side (never self-asserted):
221
+ * a `px_token` access JWT (verified against IAM's signing keys) or a `px_` key. Null = absent.
115
222
  */
116
223
  credential: string | null;
117
224
  requestId: string;
@@ -185,7 +292,7 @@ export interface AuditInput {
185
292
  }
186
293
  export interface RevokeKeyInput {
187
294
  app: string;
188
- /** The propustka-native credential the CALLER (authorizer) is resolved from; null = absent. */
295
+ /** The IAM-native credential the CALLER (authorizer) is resolved from; null = absent. */
189
296
  credential: string | null;
190
297
  requestId: string;
191
298
  /** The credential id (the `id` returned by `issueKey`), NOT the plaintext `px_` token. */
@@ -203,7 +310,7 @@ export type RevokeKeyResult =
203
310
  export interface ListPrincipalsInput {
204
311
  /** Self-asserted caller app id; superseded by the credential's aud on a valid `px_token`. */
205
312
  app: string;
206
- /** The propustka-native credential the CALLER is resolved from (px_token / px_ key); null = absent. */
313
+ /** The IAM-native credential the CALLER is resolved from (px_token / px_ key); null = absent. */
207
314
  credential: string | null;
208
315
  requestId: string;
209
316
  }
@@ -239,7 +346,7 @@ export interface IamRpc {
239
346
  listOwnDeviceAuthorizations(input: ListOwnDeviceAuthorizationsInput): Promise<ListOwnDeviceAuthorizationsResult>;
240
347
  /**
241
348
  * Mint a short-lived, per-app permission token from the browser's SSO session — the
242
- * propustka-native auth path. The SDK middleware calls this only when its cached permission
349
+ * IAM-native auth path. The SDK middleware calls this only when its cached permission
243
350
  * token is missing/near-expiry (≈ once per TTL), NOT per request: every other request verifies
244
351
  * the cached token locally against `getJwks`.
245
352
  */
@@ -0,0 +1,61 @@
1
+ import type { OutputShape, SchemaShape } from './contract';
2
+ /** One value a dimension lists, with the text the console shows beside it. */
3
+ export interface DimensionValue {
4
+ readonly value: string;
5
+ readonly label?: string;
6
+ }
7
+ /** The most values a dimension lists. */
8
+ export declare const MAX_DIMENSION_VALUES = 500;
9
+ /** The longest label of a listed value. */
10
+ export declare const MAX_DIMENSION_VALUE_LABEL_LENGTH = 120;
11
+ /**
12
+ * Why `values` is not a dimension's list, or `null`: at least one and at most `MAX_DIMENSION_VALUES` values, each a
13
+ * non-empty value no longer than a scope value IAM takes, listed once, with a non-empty label when it has one.
14
+ */
15
+ export declare function dimensionValuesProblem(values: readonly DimensionValue[]): string | null;
16
+ /**
17
+ * Where IAM asks the application for a dimension's values (ADR-0085 §4): the procedure's endpoint id, its path on the
18
+ * application's origin and the action its requirement names. IAM calls it as the administrator, through the proxy.
19
+ */
20
+ export interface DimensionValueSource {
21
+ readonly endpoint: string;
22
+ readonly path: string;
23
+ readonly action: string;
24
+ }
25
+ /** How long IAM waits for a value source's whole answer before the console falls back. */
26
+ export declare const SCOPE_VALUE_SOURCE_TIMEOUT_MS = 3000;
27
+ /** The largest answer IAM reads from a value source. */
28
+ export declare const MAX_SCOPE_VALUE_SOURCE_BYTES: number;
29
+ /** The row of a value-source procedure, as far as its rule reads it. */
30
+ interface ValueSourceRow {
31
+ readonly id: string;
32
+ readonly kind: string;
33
+ readonly method: string;
34
+ readonly callers: readonly string[];
35
+ readonly requirement: {
36
+ readonly kind: string;
37
+ readonly action?: string;
38
+ readonly access?: {
39
+ readonly form: string;
40
+ readonly dimension?: string;
41
+ };
42
+ } | null;
43
+ readonly input: SchemaShape | null;
44
+ readonly output: OutputShape | null;
45
+ }
46
+ /**
47
+ * Why `row` cannot be `dimension`'s value source, or null: a person's `POST` query without input, requiring an action
48
+ * `over` that dimension other than its `members.manage` (`managedBy`), whose output is
49
+ * `{ values: [{ value: string, label?: string }] }`. The proxy decides the call from the row like any other; the
50
+ * requirement's action is what IAM's key for the call carries, and a row of `members.manage` would carry a membership
51
+ * delegation into a call the administrator only reads with.
52
+ */
53
+ export declare function valueSourceProblem(row: ValueSourceRow, dimension: string, managedBy: string | null): string | null;
54
+ /** The output shape `{ values: [{ value: string, label?: string }] }`, strings with any checks. */
55
+ export declare function isDimensionValuesShape(shape: OutputShape): boolean;
56
+ /**
57
+ * The values a source answered, or null when the answer is not `{ values }` of at most `MAX_DIMENSION_VALUES` values
58
+ * `dimensionValuesProblem` admits. An answer is the application's word: the console shows it, IAM decides nothing by it.
59
+ */
60
+ export declare function parseDimensionValues(result: unknown): DimensionValue[] | null;
61
+ export {};
@@ -1,2 +1,12 @@
1
1
  /** The SHA-256 of `text`'s UTF-8 bytes, as 64 lower-case hex digits. */
2
2
  export declare function sha256Hex(text: string): string;
3
+ /**
4
+ * SHA-256 over text fed in pieces, so a digest of a large serialization never needs the whole text in memory. Each
5
+ * piece is whole text: a surrogate pair split across two pieces encodes as two replacement characters.
6
+ */
7
+ export declare class Sha256 {
8
+ #private;
9
+ update(text: string): this;
10
+ /** The digest of everything fed so far; the hash takes no piece after it. */
11
+ hex(): string;
12
+ }