@fabrika/auth-core 0.9.0-dev.48 → 0.9.0-dev.49

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/auth-core",
3
- "version": "0.9.0-dev.48",
3
+ "version": "0.9.0-dev.49",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "repository": {
package/src/ops.ts CHANGED
@@ -111,6 +111,12 @@ export function OPS_STATE_KEY(object: string): string {
111
111
  return `__fabrika/ops/${object}.json`
112
112
  }
113
113
 
114
+ /** The R2 key, in the environment's bucket, of the migration record of `object` (ADR-0069 §3). */
115
+ export function OPS_MIGRATION_RECORD_KEY(object: string): string {
116
+ if (parseApplicationObjectName(object) === null) throw new Error('a migration record key needs a valid object name')
117
+ return `__fabrika/ops/${object}.migration.json`
118
+ }
119
+
114
120
  /** The maintenance modes, from the most permissive. */
115
121
  export const OPS_MODES = ['open', 'read-only', 'closed', 'inspect'] as const
116
122
 
@@ -177,10 +183,72 @@ export interface OpsMigration {
177
183
  readonly appliedAt: string
178
184
  }
179
185
 
180
- /** Sent once the migrations ran and the application booted, with the new ledger. */
186
+ /**
187
+ * Sent once the migrations ran and the application booted, with the new ledger. `record` is the object's migration
188
+ * record, `null` when it has none; a release before the migrating boot omits it. `version` is the id of the Worker
189
+ * version that answers, `null` without the version metadata binding; a release before it omits it.
190
+ */
181
191
  export interface OpsMigrateAck {
182
192
  readonly generation: number
183
193
  readonly migrations: readonly OpsMigration[]
194
+ readonly record?: OpsMigrationRecord | null
195
+ readonly version?: string | null
196
+ }
197
+
198
+ /** A file a migration record names: the ledger row's identity and checksum. */
199
+ export interface OpsMigrationFile {
200
+ readonly bundle: string
201
+ readonly name: string
202
+ readonly checksum: string
203
+ }
204
+
205
+ /**
206
+ * What became of a record's transaction: `diverged`, the ledger holds some of its rows (a release before the gate
207
+ * migrated over it); `rewound`, an in-place rewind took the object back to the record's bookmark (ADR-0070 §9).
208
+ */
209
+ export const OPS_MIGRATION_OUTCOMES = ['committed', 'rolled_back', 'diverged', 'rewound'] as const
210
+
211
+ export type OpsMigrationOutcome = (typeof OPS_MIGRATION_OUTCOMES)[number]
212
+
213
+ /**
214
+ * The migration record (ADR-0069 §3), stored in the environment's bucket and answered by `migrate`: what one migrating
215
+ * boot did, written before its transaction and completed after it.
216
+ */
217
+ export interface OpsMigrationRecord {
218
+ /** A UUIDv7 per record; every later put of the record names it. */
219
+ readonly id: string
220
+ /** The id of the Worker version that wrote it; `null` where the runtime has no version metadata, which no rewind accepts. */
221
+ readonly version: string | null
222
+ /** The bookmark before the transaction, the only target of the in-place rewind; `null` where the runtime has none. */
223
+ readonly bookmark: string | null
224
+ /** The digest of the ledger the boot started from (`@fabrika/db`'s `sqliteLedgerDigest`). */
225
+ readonly startDigest: string
226
+ readonly files: readonly OpsMigrationFile[]
227
+ readonly at: string
228
+ readonly outcome: OpsMigrationOutcome | null
229
+ /** With `committed` (and `rewound` after it) only: the bookmark after the commit, or at the reconciliation that found it. */
230
+ readonly committedBookmark: string | null
231
+ /** When a version first booted over the outcome; never with `rewound`. */
232
+ readonly booted: string | null
233
+ }
234
+
235
+ /** Why a migrating boot failed; `record_unwritable` names only the put before the transaction. */
236
+ export const OPS_MIGRATION_FAILURES = ['rolled_back', 'committed', 'record_unwritable'] as const
237
+
238
+ export type OpsMigrationFailureReason = (typeof OPS_MIGRATION_FAILURES)[number]
239
+
240
+ /** The status of a failed migrating boot, answered only by the release that holds the record. */
241
+ export const OPS_MIGRATION_FAILED_STATUS = 422
242
+
243
+ /**
244
+ * 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
245
+ * the Worker version that answers, as in `OpsMigrateAck`; a release before it omits it.
246
+ */
247
+ export interface OpsMigrationFailure {
248
+ readonly refused: 'migration_failed'
249
+ readonly reason: OpsMigrationFailureReason
250
+ readonly record: OpsMigrationRecord
251
+ readonly version?: string | null
184
252
  }
185
253
 
186
254
  export interface OpsMaintenance {
@@ -302,10 +370,62 @@ export function parseOpsStaleRefusal(body: unknown): OpsStaleRefusal | null {
302
370
  }
303
371
 
304
372
  export function parseOpsMigrateAck(body: unknown): OpsMigrateAck | null {
305
- if (!exactKeys(body, ['generation', 'migrations'])) return null
373
+ const withRecord = hasKey(body, 'record')
374
+ const withVersion = hasKey(body, 'version')
375
+ if (!exactKeys(body, ['generation', 'migrations', ...(withRecord ? ['record'] : []), ...(withVersion ? ['version'] : [])])) return null
306
376
  const generation = readGeneration(prop(body, 'generation'))
307
377
  const migrations = readList(prop(body, 'migrations'), readMigration)
308
- return generation === null || migrations === null ? null : { generation, migrations }
378
+ const record = withRecord ? readNullable(prop(body, 'record'), parseOpsMigrationRecord) : null
379
+ const version = withVersion ? readResponderVersion(prop(body, 'version')) : null
380
+ if (generation === null || migrations === null || record === undefined || version === undefined) return null
381
+ return { generation, migrations, ...(withRecord ? { record } : {}), ...(withVersion ? { version } : {}) }
382
+ }
383
+
384
+ /** A stored or answered migration record, parsed strictly: its fields must also agree with each other. */
385
+ export function parseOpsMigrationRecord(body: unknown): OpsMigrationRecord | null {
386
+ const keys = ['id', 'version', 'bookmark', 'startDigest', 'files', 'at', 'outcome', 'committedBookmark', 'booted']
387
+ if (!exactKeys(body, keys)) return null
388
+ const id = readMatch(prop(body, 'id'), UUID)
389
+ const version = readNullable(prop(body, 'version'), (value) => readMatch(value, WORKER_VERSION_ID))
390
+ const bookmark = readNullable(prop(body, 'bookmark'), (value) => readMatch(value, OPAQUE_TOKEN))
391
+ const startDigest = readMatch(prop(body, 'startDigest'), SHA256_HEX)
392
+ const files = readList(prop(body, 'files'), readMigrationFile)
393
+ const at = readTimestamp(prop(body, 'at'))
394
+ const outcome = readNullable(prop(body, 'outcome'), (value) => readEnum(value, OPS_MIGRATION_OUTCOMES))
395
+ const committedBookmark = readNullable(prop(body, 'committedBookmark'), (value) => readMatch(value, OPAQUE_TOKEN))
396
+ const booted = readNullable(prop(body, 'booted'), readTimestamp)
397
+ if (
398
+ id === null || version === undefined || bookmark === undefined || startDigest === null || files === null || files.length === 0 || at === null
399
+ || outcome === undefined || committedBookmark === undefined || booted === undefined
400
+ ) {
401
+ return null
402
+ }
403
+ const committed = outcome === 'committed' || outcome === 'rewound'
404
+ if ((committedBookmark !== null && !committed) || (booted !== null && (outcome === null || outcome === 'rewound'))) return null
405
+ return { id, version, bookmark, startDigest, files, at, outcome, committedBookmark, booted }
406
+ }
407
+
408
+ /** A failed migrating boot's answer; its reason must be what its record says. */
409
+ export function parseOpsMigrationFailure(body: unknown): OpsMigrationFailure | null {
410
+ const withVersion = hasKey(body, 'version')
411
+ const keys = ['refused', 'reason', 'record', ...(withVersion ? ['version'] : [])]
412
+ if (!exactKeys(body, keys) || prop(body, 'refused') !== 'migration_failed') return null
413
+ const reason = readEnum(prop(body, 'reason'), OPS_MIGRATION_FAILURES)
414
+ const record = parseOpsMigrationRecord(prop(body, 'record'))
415
+ const version = withVersion ? readResponderVersion(prop(body, 'version')) : null
416
+ if (reason === null || record === null || version === undefined) return null
417
+ const agrees = reason === 'record_unwritable'
418
+ ? record.outcome === null
419
+ : reason === 'committed'
420
+ ? record.outcome === 'committed' && record.booted === null
421
+ : record.outcome === reason
422
+ if (!agrees) return null
423
+ return withVersion ? { refused: 'migration_failed', reason, record, version } : { refused: 'migration_failed', reason, record }
424
+ }
425
+
426
+ /** The answering Worker version's id, `null` without the binding; `undefined` when it does not parse. */
427
+ function readResponderVersion(value: unknown): string | null | undefined {
428
+ return readNullable(value, (raw) => readMatch(raw, WORKER_VERSION_ID))
309
429
  }
310
430
 
311
431
  export function parseOpsView(body: unknown): OpsView | null {
@@ -1016,7 +1136,7 @@ export function parseOpsImportDiscardAck(body: unknown): OpsImportDiscardAck | n
1016
1136
  * Writes the sentinel (the operation's id) into the object's KV storage, and answers the current bookmark and the
1017
1137
  * bookmark of `at`, which Control records before it arms anything.
1018
1138
  */
1019
- export interface OpsRestorePrepare {
1139
+ export interface OpsRestorePrepareAt {
1020
1140
  readonly step: 'prepare'
1021
1141
  readonly object: string
1022
1142
  readonly generation: number
@@ -1024,6 +1144,20 @@ export interface OpsRestorePrepare {
1024
1144
  readonly at: string
1025
1145
  }
1026
1146
 
1147
+ /**
1148
+ * The in-place rewind of a failed migration (ADR-0070 §9): `record` names the object's migration record, whose bookmark
1149
+ * is the target, and the object checks every guard of the rewind before it writes the sentinel.
1150
+ */
1151
+ export interface OpsRestorePrepareRecord {
1152
+ readonly step: 'prepare'
1153
+ readonly object: string
1154
+ readonly generation: number
1155
+ readonly sentinel: string
1156
+ readonly record: string
1157
+ }
1158
+
1159
+ export type OpsRestorePrepare = OpsRestorePrepareAt | OpsRestorePrepareRecord
1160
+
1027
1161
  /** Arms the restore of `target` for the next session, answers, then resets the object. */
1028
1162
  export interface OpsRestoreArm {
1029
1163
  readonly step: 'arm'
@@ -1031,13 +1165,19 @@ export interface OpsRestoreArm {
1031
1165
  readonly generation: number
1032
1166
  readonly sentinel: string
1033
1167
  readonly target: string
1168
+ /** The migration record of an in-place rewind, whose guards the object checks again; absent for a side restore. */
1169
+ readonly record?: string
1034
1170
  }
1035
1171
 
1036
- /** Reads, after the reset, whether the sentinel is still there. It writes nothing, so it carries no generation. */
1172
+ /**
1173
+ * Reads, after the reset, whether the sentinel is still there; it carries no generation. With `record`, an in-place
1174
+ * rewind's, an absent sentinel also records `rewound` in that migration record, its only write.
1175
+ */
1037
1176
  export interface OpsRestoreVerify {
1038
1177
  readonly step: 'verify'
1039
1178
  readonly object: string
1040
1179
  readonly sentinel: string
1180
+ readonly record?: string
1041
1181
  }
1042
1182
 
1043
1183
  /** `POST /__fabrika/ops/restore`: one step of rewinding an `inspect` object that serves no traffic. */
@@ -1067,18 +1207,31 @@ export function parseOpsRestoreRequest(body: unknown): OpsRestoreRequest | null
1067
1207
  const object = parseApplicationObjectName(prop(body, 'object'))
1068
1208
  const sentinel = readMatch(prop(body, 'sentinel'), UUID)
1069
1209
  if (object === null || sentinel === null) return null
1070
- if (step === 'verify') return exactKeys(body, ['step', 'object', 'sentinel']) ? { step, object, sentinel } : null
1210
+ if (step === 'verify') {
1211
+ if (exactKeys(body, ['step', 'object', 'sentinel', 'record'])) {
1212
+ const record = readMatch(prop(body, 'record'), UUID)
1213
+ return record === null ? null : { step, object, sentinel, record }
1214
+ }
1215
+ return exactKeys(body, ['step', 'object', 'sentinel']) ? { step, object, sentinel } : null
1216
+ }
1071
1217
  const generation = readGeneration(prop(body, 'generation'))
1072
1218
  if (generation === null) return null
1073
1219
  if (step === 'prepare') {
1220
+ if (exactKeys(body, ['step', 'object', 'generation', 'sentinel', 'record'])) {
1221
+ const record = readMatch(prop(body, 'record'), UUID)
1222
+ return record === null ? null : { step, object, generation, sentinel, record }
1223
+ }
1074
1224
  const at = readTimestamp(prop(body, 'at'))
1075
1225
  return exactKeys(body, ['step', 'object', 'generation', 'sentinel', 'at']) && at !== null ? { step, object, generation, sentinel, at } : null
1076
1226
  }
1077
1227
  if (step === 'arm') {
1078
1228
  const target = readMatch(prop(body, 'target'), OPAQUE_TOKEN)
1079
- return exactKeys(body, ['step', 'object', 'generation', 'sentinel', 'target']) && target !== null
1080
- ? { step, object, generation, sentinel, target }
1081
- : null
1229
+ if (target === null) return null
1230
+ if (exactKeys(body, ['step', 'object', 'generation', 'sentinel', 'target', 'record'])) {
1231
+ const record = readMatch(prop(body, 'record'), UUID)
1232
+ return record === null ? null : { step, object, generation, sentinel, target, record }
1233
+ }
1234
+ return exactKeys(body, ['step', 'object', 'generation', 'sentinel', 'target']) ? { step, object, generation, sentinel, target } : null
1082
1235
  }
1083
1236
  return null
1084
1237
  }
@@ -1164,6 +1317,11 @@ export const OPS_DATA_REFUSALS = [
1164
1317
  'verify_mismatch',
1165
1318
  'bookmark_unavailable',
1166
1319
  'row_too_large',
1320
+ // The in-place rewind (ADR-0070 §9): the record is not the one named, or not `committed` without `booted`; the record
1321
+ // has no version, or another Worker version runs than the one that wrote it; the target is not the record's bookmark.
1322
+ 'not_rewindable',
1323
+ 'version_changed',
1324
+ 'wrong_target',
1167
1325
  ] as const
1168
1326
 
1169
1327
  export type OpsDataRefusalReason = (typeof OPS_DATA_REFUSALS)[number]
@@ -1194,6 +1352,8 @@ const CONTRACT_NAME = /^[A-Za-z][A-Za-z0-9_]*$/
1194
1352
  const MIGRATION_BUNDLE = /^[a-z][a-z0-9-]*$/
1195
1353
  const MIGRATION_NAME = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\.sql$/
1196
1354
  const MIGRATION_CHECKSUM = /^[0-9a-f]{64}$/
1355
+ /** A Worker version id as Cloudflare's version metadata answers it. */
1356
+ const WORKER_VERSION_ID = /^[A-Za-z0-9-]{1,64}$/
1197
1357
  const SHA256_HEX = /^[0-9a-f]{64}$/
1198
1358
  /** A dump id or a sentinel: a UUID as Control writes one. */
1199
1359
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
@@ -1283,6 +1443,14 @@ function readMigration(value: unknown): OpsMigration | null {
1283
1443
  return bundle === null || name === null || checksum === null || appliedAt === null ? null : { bundle, name, checksum, appliedAt }
1284
1444
  }
1285
1445
 
1446
+ function readMigrationFile(value: unknown): OpsMigrationFile | null {
1447
+ if (!exactKeys(value, ['bundle', 'name', 'checksum'])) return null
1448
+ const bundle = readMatch(prop(value, 'bundle'), MIGRATION_BUNDLE)
1449
+ const name = readMatch(prop(value, 'name'), MIGRATION_NAME)
1450
+ const checksum = readMatch(prop(value, 'checksum'), MIGRATION_CHECKSUM)
1451
+ return bundle === null || name === null || checksum === null ? null : { bundle, name, checksum }
1452
+ }
1453
+
1286
1454
  function readScheduler(value: unknown): OpsScheduler | null {
1287
1455
  if (!exactKeys(value, ['alarm'])) return null
1288
1456
  const raw = prop(value, 'alarm')
@@ -1339,6 +1507,10 @@ function readBootFailureContent(value: unknown): OpsBootFailureContent | undefin
1339
1507
  }
1340
1508
 
1341
1509
  /** Whether `value` is a plain object holding exactly `keys`: no key missing, none unknown. */
1510
+ function hasKey(value: unknown, key: string): boolean {
1511
+ return typeof value === 'object' && value !== null && !Array.isArray(value) && Object.hasOwn(value, key)
1512
+ }
1513
+
1342
1514
  function exactKeys(value: unknown, keys: readonly string[]): boolean {
1343
1515
  if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
1344
1516
  const own = Object.keys(value)
package/src/rpc.ts CHANGED
@@ -7,7 +7,7 @@ import type {
7
7
  ListOwnDeviceAuthorizationsInput,
8
8
  ListOwnDeviceAuthorizationsResult,
9
9
  } from './device'
10
- import type { Jwks } from './token'
10
+ import { DEFAULT_TOKEN_TTL_SECONDS, type Jwks } from './token'
11
11
  import type { PermissionEntry, PrincipalType, Scope } from './types'
12
12
 
13
13
  // ── IAM-native session auth (mint a per-app permission token from an SSO session) ──
@@ -119,7 +119,7 @@ export type MintFromGrantResult =
119
119
  | { ok: true; token: string; expiresAt: number }
120
120
  /**
121
121
  * `invalid_grant`: the token, its grant, the approving login or the person no longer holds. `write_refused`: the
122
- * environment serves no `write` grant. `token_too_large`: a decided refusal, as for a key.
122
+ * environment's `agent-write` gate serves no `write` grant. `token_too_large`: a decided refusal, as for a key.
123
123
  */
124
124
  | { ok: false; reason: 'invalid_grant' | 'write_refused' | 'token_too_large' }
125
125
 
@@ -128,6 +128,41 @@ export interface IamGrantRpc {
128
128
  mintFromGrant(input: MintFromGrantInput): Promise<MintFromGrantResult>
129
129
  }
130
130
 
131
+ // ── The revocation feed (ADR-0022, "Revocation reaches a cached token") ─────────
132
+ //
133
+ // The proxy verifies a cached token locally until it expires. To end it sooner, it asks IAM which subjects lost
134
+ // something since its last read: a principal disabled, a session, key or OAuth grant revoked. A cached token of such a
135
+ // subject minted no later than the revocation is dropped and minted again, and IAM decides. Like the mint operations it
136
+ // is the proxy's alone, never a member of `IamRpc`.
137
+
138
+ /** How far back the feed reaches: no token outlives `DEFAULT_TOKEN_TTL_SECONDS`, so an older revocation ends nothing. */
139
+ export const REVOCATION_FEED_WINDOW_SECONDS = DEFAULT_TOKEN_TTL_SECONDS
140
+
141
+ /** The most subjects one answer lists; past it the answer is `complete: false` and the proxy drops every cached token. */
142
+ export const REVOCATION_FEED_MAX_SUBJECTS = 5000
143
+
144
+ export interface RevocationsInput {
145
+ /** IAM's clock, unix seconds: the feed answers revocations at or after it, within the window. `null`: the whole window. */
146
+ since: number | null
147
+ }
148
+
149
+ /** A subject (a token's `sub`: a principal, or an anonymous credential) and the latest revocation of it, IAM's clock. */
150
+ export interface RevokedSubject {
151
+ subject: string
152
+ at: number
153
+ }
154
+
155
+ export type RevocationsResult =
156
+ /** `now` is IAM's clock at the read; `complete: false` when more subjects were revoked than one answer lists. */
157
+ | { ok: true; now: number; complete: boolean; subjects: RevokedSubject[] }
158
+ /** The caller is not the proxy (an application's binding on Cloudflare). */
159
+ | { ok: false; reason: 'not_allowed' }
160
+
161
+ /** The revocation feed, as a contract of its own: only the proxy calls it. */
162
+ export interface IamRevocationRpc {
163
+ revocations(input: RevocationsInput): Promise<RevocationsResult>
164
+ }
165
+
131
166
  // ── Sign-in signals for Operations' security alerts ───────────────────────────
132
167
  //
133
168
  // Operations' maintenance pass asks IAM for a bounded summary of its `auth_log` over a time window. Only IAM's full
@@ -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. */
@@ -559,13 +619,25 @@ export declare function parseOpsImportDiscardAck(body: unknown): OpsImportDiscar
559
619
  * Writes the sentinel (the operation's id) into the object's KV storage, and answers the current bookmark and the
560
620
  * bookmark of `at`, which Control records before it arms anything.
561
621
  */
562
- export interface OpsRestorePrepare {
622
+ export interface OpsRestorePrepareAt {
563
623
  readonly step: 'prepare';
564
624
  readonly object: string;
565
625
  readonly generation: number;
566
626
  readonly sentinel: string;
567
627
  readonly at: string;
568
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;
569
641
  /** Arms the restore of `target` for the next session, answers, then resets the object. */
570
642
  export interface OpsRestoreArm {
571
643
  readonly step: 'arm';
@@ -573,12 +645,18 @@ export interface OpsRestoreArm {
573
645
  readonly generation: number;
574
646
  readonly sentinel: string;
575
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;
576
650
  }
577
- /** 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
+ */
578
655
  export interface OpsRestoreVerify {
579
656
  readonly step: 'verify';
580
657
  readonly object: string;
581
658
  readonly sentinel: string;
659
+ readonly record?: string;
582
660
  }
583
661
  /** `POST /__fabrika/ops/restore`: one step of rewinding an `inspect` object that serves no traffic. */
584
662
  export type OpsRestoreRequest = OpsRestorePrepare | OpsRestoreArm | OpsRestoreVerify;
@@ -632,7 +710,7 @@ export declare function parseOpsTimersView(body: unknown): OpsTimersView | null;
632
710
  /** The status of a data operation's refusal. It is answered only after authentication. */
633
711
  export declare const OPS_DATA_REFUSED_STATUS = 422;
634
712
  /** Why the object refused an export, import or restore step. */
635
- 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"];
636
714
  export type OpsDataRefusalReason = (typeof OPS_DATA_REFUSALS)[number];
637
715
  /** The body of a data refusal; `table` names the table at fault, an identifier and never a value. */
638
716
  export interface OpsDataRefusal {
@@ -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). */
@@ -85,7 +85,7 @@ export type MintFromGrantResult = {
85
85
  }
86
86
  /**
87
87
  * `invalid_grant`: the token, its grant, the approving login or the person no longer holds. `write_refused`: the
88
- * environment serves no `write` grant. `token_too_large`: a decided refusal, as for a key.
88
+ * environment's `agent-write` gate serves no `write` grant. `token_too_large`: a decided refusal, as for a key.
89
89
  */
90
90
  | {
91
91
  ok: false;
@@ -95,6 +95,36 @@ export type MintFromGrantResult = {
95
95
  export interface IamGrantRpc {
96
96
  mintFromGrant(input: MintFromGrantInput): Promise<MintFromGrantResult>;
97
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
+ }
98
128
  /** The longest window `signInSignals` answers: a reader that fell further behind reads the last day only. */
99
129
  export declare const SIGN_IN_SIGNALS_MAX_WINDOW_SECONDS: number;
100
130
  /** The most accounts and privileged sign-ins one answer lists; `accountsTruncated`/`privilegedTruncated` say a list was cut. */