@substrat-run/adapter-cloudflare 0.197.1 → 0.199.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/host.d.ts +11 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +36 -9
- package/dist/host.js.map +1 -1
- package/dist/scope-do.d.ts.map +1 -1
- package/dist/scope-do.js +80 -27
- package/dist/scope-do.js.map +1 -1
- package/package.json +9 -9
package/dist/scope-do.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope-do.d.ts","sourceRoot":"","sources":["../src/scope-do.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAwDL,KAAK,QAAQ,EAmBd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAgEL,KAAK,mBAAmB,EASxB,KAAK,SAAS,EA2Bd,KAAK,kBAAkB,EAEvB,KAAK,gBAAgB,EA+HtB,MAAM,sBAAsB,CAAC;AAsD9B,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EA0BL,kBAAkB,
|
|
1
|
+
{"version":3,"file":"scope-do.d.ts","sourceRoot":"","sources":["../src/scope-do.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAwDL,KAAK,QAAQ,EAmBd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAgEL,KAAK,mBAAmB,EASxB,KAAK,SAAS,EA2Bd,KAAK,kBAAkB,EAEvB,KAAK,gBAAgB,EA+HtB,MAAM,sBAAsB,CAAC;AAsD9B,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAGtD,OAAO,EA0BL,kBAAkB,EA4FnB,MAAM,sBAAsB,CAAC;AA2B9B;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,UAAU;IACzB;;;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
import { DurableObject } from 'cloudflare:workers';
|
|
4
4
|
import { ATTACHMENT_ADDED, ATTACHMENT_REMOVED, CAPTURE_REFUSALS, attachmentRecord, domainEvent, domainEventInput, eventId, instant, objectRef, entityObjectRef, assertModuleEmittableType, assertKernelAuthoredType, toWireFailure, grantRefFromProof, principalId, principalBecomeCapabilityInput, principalBindLinkInput, scopeId as scopeIdOf, tenantId as tenantIdOf, platformRequestInput, platformRequestId, MAX_PENDING_PLATFORM_REQUESTS, MAX_PENDING_SWEEP_RUNS, SWEEP_RUNS_KIND, SCOPE_DUMP_PAGE_MAX_BYTES, SCOPE_TABLE_PAGE_MAX, SCOPE_QUERY_ROW_MAX, listLimitOf, pageOf, countedPageOf, requestFingerprint, substratError, errorCodeOf, assertReplayableDump, DUMP_OBJECTS_QUERY, dumpObjectsOf, replayDumpObjects, dumpObjectsAudit, REDRAIN_BATCH, } from '@substrat-run/contracts';
|
|
5
|
-
import { ulid, DO_SQL_LIMITS, unknownRoleError, createUlid, assertAllowed, ConnectionSealingKeyUnavailableError, noSealingKeyMessage, sealTo, assertReadOnlyQuery,
|
|
5
|
+
import { ulid, DO_SQL_LIMITS, unknownRoleError, createUlid, assertAllowed, ConnectionSealingKeyUnavailableError, noSealingKeyMessage, sealTo, assertReadOnlyQuery, refuseEntitlement, platformRequestHistoryQuery, platformRequestOf, PLATFORM_REQUEST_COLUMNS, PLATFORM_REQUEST_REDACTION_SQL, platformRequestRedactionParams, platformRequestRedactionQuery, intentPayloadCarriesSubject, redactSubjectJobRuns, eraseSubjectFromModules, moduleErasurePlan, redactSubjectScopeText, assertRowLimit, assertRowOffset, JOB_RUN_PATCH_SQL, JOB_RUN_CLAIM_SQL, JOB_RUN_RENEW_SQL, JOB_RUN_BEGIN_SQL, JOB_RUN_MISS_SQL, JOB_RUN_MISS_SETTLE_SQL, admissionMissOutcome, JOB_LEASE_EXPIRED_NOTE, JOB_STEP_RECORD_SQL, DELIVERY_ERROR_REDACTION_SQL, REDACTED_DELIVERY_NOTE, seatScopeTuple, delegatedRevokeSql, writeExplicitTupleIn, grantEntityShapeIn, grantEntityShapeOnceIn, topUpEntityGrantShapes, applyScopeRoleChange, changeScopeRole, revokeScopeRoles, scopeRoleHolders, assertModuleDeclared, noteDeclaredKeys, noteReservedKeys, SCOPE_SEATED_ROLES_SQL, inUnitRoleRefusal, loadedRoleSetRefusedRole, reservedRoleSetRefusedRole, reservedGrantRefusal, reservedRoleRefusal, reservedShapeRefusal, effectiveRoleGrantQuery, switchRecordedOff, switchSystemSchedules, peerGrantsStatus, systemGrantsStatus, systemScheduleState, systemSwitchedOff, OUTBOX_PRUNED_DDL, outboxSubscribersOf, pruneDrainedOutbox, denialListQuery, refusalListQuery, mapRefusalRow, denialSummaryQuery, denialTotalsQuery, DENIAL_WINDOW_QUERY, mapDenialRow, mapDenialSummaryBuckets, PermissionDenied, assertImpersonationAdmitted, assertImpersonationWrites, assertModuleEnqueueableKind, impersonationStampOf, createAtomic, NotSearchable, isSearchIndexTable, rowCountTable, searchIndexPlans, NotListable, listIndexPlans, moduleMigrations, REGISTERED_MIGRATIONS, registeredMigrationsOf, MIGRATION_DIGEST_FENCE_DDL, MIGRATION_DIGEST_MARK_LEGACY, assertJournalDumpCoherent, assertMigrationSql, migrationDivergence, migrationFailedError, migrationSetDivergence, migrationSteps, planMigrations, listQuery, cursorOf, searchLimit, searchMatchExpression, searchQuery, ATTACHMENT_TEXT_DDL, ATTACHMENT_BYTES_SQL, ATTACHMENT_CONDEMNED_DDL, ATTACHMENT_SWEEP_LICENCE_DDL, ATTACHMENT_SWEEP_LICENCE_TABLE, WIRE_NONCE_DDL, WIRE_NONCE_FULL, claimWireNonceIn, isWireNonceTable, isWireNonceWrite, clearOrphanSweepLicence, condemnLicensedOrphanAttachments, consumeOrphanSweepLicence, licensedOrphanIds, recordOrphanSweepLicence, refuseUnlicensedOrphanSweep, refuseCondemnedAttachment, refuseCondemnedInDump, rowlessAttachmentIds, attachmentRecordOfRow, enqueueAttachmentText, reconcileAttachmentText, queueAttachmentTextBackfill, startAttachmentTextBackfill, recordAttachmentText, searchAttachments, IDEMPOTENCY_DDL, REFUSALS_TABLE_DDL, REFUSALS_INDEX, refusalInsert, refusalOf, markGuardRefusal, REFUSALS_REBUILD, refusalsAdmitGuards, assertIdempotencyKey, assertPermissionKey, idempotencyLookupQuery, idempotencyPruneStatement, idempotencyRecordStatement, idempotencyOptedOutMessage, replayFor, entityVersionQuery, entityVersionOf, assertIfMatch, OUTBOX_ENTITY_INDEX, SCHEDULE_STATE_DDL, SCHEDULE_STATE_REBUILD, scheduleStateHasKind, VERTICAL_EVENTS_DDL, EXPORT_HOPS_SQL, emptyImportResult, IMPORT_CURSORS_SQL, IMPORT_CURSOR_OF_SQL, OUTBOX_MARK_SQL, exportedSinceQuery, emittedSinceQuery, emittedReportOf, EMITTED_REPORT_CAP, noteTransitionInto, withTransitions, IMPORT_CURSOR_ADVANCE_SQL, IMPORT_RECORD_SQL, moveImportCursor, CrossVerticalRegistry, exportReadPlan, exportReadQuery, planExportBatch, withheldNote, JOB_RUN_DDL, JOB_RUN_DUE_AT, jobRunListLimit, SYSTEM_DOOR_WAIT, ancestorsWithin, } from '@substrat-run/kernel';
|
|
6
6
|
import { isUpgradeRequest, readSubscription, LIVE_DECIDE_ATTEMPTS, LIVE_FANOUT_LIMIT, LIVE_PRINCIPAL_HEADER, LIVE_SCOPE_HEADER, LIVE_SUBSCRIBE_PATH, LIVE_TENANT_HEADER, LIVE_WITHIN_HEADER, LIVE_EXPIRES_HEADER, LIVE_CLOSE, LIVE_SOCKETS_PER_PRINCIPAL, decodeLiveWithin, liveInstant, liveRefusal, liveRefusalStatus, } from './live-reads.js';
|
|
7
7
|
import { replyOf } from './do-reply.js';
|
|
8
8
|
import { OperationQueue } from './serialization.js';
|
|
9
9
|
import { assertNoWorkerdStorage, doScopedSql, doBuiltColumnsOf, doRedactionSql, doSpineSql } from './sql.js';
|
|
10
|
-
import { actorOf, admitPeer, boundToPeerDeclarations, collectPeers, switchPeer, peerSubjectRef, subjectGrantState, assertNoSecret, CAPABILITY_DDL, UPLOAD_LINK_DDL, DOWNLOAD_LINK_DDL, createAttachmentVerbs, inspectUploadLink, resolveDownloadLink, redeemUploadLinkInTransaction, COPY_ORIGIN_DDL, ENTITY_STATE_MOVES_DDL, SWITCH_FENCES_DDL, TABLE_OWNERS_DDL, assertMigrationLeavesLedgerAlone, recordOwnershipSteps, runMigrationStatements, splitSqlStatements, executableSqlStatements, blankSqlComments, CAPABILITY_EXCHANGE_OPERATION, CAPABILITY_BECOME_MINT_OPERATION, becomeMintCheck, mintBecomeCapabilityAsPrincipal, CAPABILITY_BIND_MINT_OPERATION, bindLinkMintCheck, mintBindLinkAsPrincipal, revokeBecomeCapabilityAsPrincipal, readBecomeLinkStates, ENTITY_UNBIND_OPERATION, allowedFor, unbindEntityHolderBounded, capabilityAttachmentWriteRefused, createCapabilityVerbs, createEntityEdgeVerbs, createEntityStateVerbs, createTrashedReads, CONTINUATION_POSITION_CAP, visibleContinuation, searchStateWhere, uncheckedView, addStatePlans, addUpdatedStampPlans, watchUpdatedStamps, assertNoCallerPurge, isUnreachableParent, PURGE_BATCH, heldPurgePass, lifecycleRefusal, purgeHeldBy, assertPlatformRequestRoom, purgeDueOf, purgeOnlyKeysOf, runPurgePass, refuseTrashedTarget, assertBoundOperations, checkHeldOperationsOf, countChecks, noteUncheckedCompletion, registerTrashTargets, withheldKeysFor, statefulTablesOf, afterMigration, afterRuntimeDdl, derivesAnything, repairDerivedObjects, StateColumnLost, exchangeCapability, exchangeBecomeLinkById, guardSecrets, mintBecomeCapability, redactSecrets, redactSecretText, moduleLog, asyncInvocationId, asyncLinePass, resolveCapabilitySession, revokeCapabilityAsPlatform, readCapabilityPage, domainEventOf, facetEvents, readDeadLetters, readLifecycleFlow, readOperationSeries, readHistory, readInvocation, readUndrainedOutbox, walkEventCause, walkEventEffects, } from '@substrat-run/kernel';
|
|
10
|
+
import { actorOf, admitPeer, boundToPeerDeclarations, collectPeers, switchPeer, peerSubjectRef, subjectGrantState, assertNoSecret, CAPABILITY_DDL, UPLOAD_LINK_DDL, DOWNLOAD_LINK_DDL, createAttachmentVerbs, inspectUploadLink, resolveDownloadLink, redeemUploadLinkInTransaction, COPY_ORIGIN_DDL, ENTITY_STATE_MOVES_DDL, SWITCH_FENCES_DDL, TABLE_OWNERS_DDL, assertMigrationLeavesLedgerAlone, recordOwnershipSteps, runMigrationStatements, splitSqlStatements, executableSqlStatements, blankSqlComments, CAPABILITY_EXCHANGE_OPERATION, CAPABILITY_BECOME_MINT_OPERATION, becomeMintCheck, mintBecomeCapabilityAsPrincipal, CAPABILITY_BIND_MINT_OPERATION, bindLinkMintCheck, mintBindLinkAsPrincipal, revokeBecomeCapabilityAsPrincipal, readBecomeLinkStates, ENTITY_UNBIND_OPERATION, allowedFor, unbindEntityHolderBounded, capabilityAttachmentWriteRefused, createCapabilityVerbs, createEntityEdgeVerbs, createEntityStateVerbs, createTrashedReads, CONTINUATION_POSITION_CAP, visibleContinuation, searchStateWhere, uncheckedView, addStatePlans, addUpdatedStampPlans, watchUpdatedStamps, assertNoCallerPurge, isUnreachableParent, PURGE_BATCH, heldPurgePass, lifecycleRefusal, purgeHeldBy, assertPlatformRequestRoom, purgeDueOf, purgeOnlyKeysOf, runPurgePass, refuseTrashedTarget, assertBoundOperations, checkHeldOperationsOf, countChecks, noteUncheckedCompletion, registerTrashTargets, withheldKeysFor, capCoverage, delegationCeilingOf, delegationStampOf, outsideCeiling, parseScopeDelegation, statefulTablesOf, afterMigration, afterRuntimeDdl, derivesAnything, repairDerivedObjects, StateColumnLost, exchangeCapability, exchangeBecomeLinkById, guardSecrets, mintBecomeCapability, redactSecrets, redactSecretText, moduleLog, asyncInvocationId, asyncLinePass, resolveCapabilitySession, revokeCapabilityAsPlatform, readCapabilityPage, domainEventOf, facetEvents, readDeadLetters, readLifecycleFlow, readOperationSeries, readHistory, readInvocation, readUndrainedOutbox, walkEventCause, walkEventEffects, } from '@substrat-run/kernel';
|
|
11
11
|
import { COPY_RESTORE_FENCE_LAPSED, copyRestoreFenceLapsed, orphanSweepVersionRefusal } from '@substrat-run/kernel';
|
|
12
12
|
import { createDoTupleChecker, createLocalControlPlaneReader, scopeTupleReader } from './checker.js';
|
|
13
13
|
import { settlePlatformRequestIn } from '@substrat-run/kernel';
|
|
@@ -95,6 +95,10 @@ const KERNEL_DDL = `
|
|
|
95
95
|
-- session/by). NULL is the ordinary case -- nobody was impersonating -- and the
|
|
96
96
|
-- actor column above stays the principal the permission model answered about.
|
|
97
97
|
impersonation TEXT,
|
|
98
|
+
-- #3176: the app that made this call FOR the person (JSON {actor}), when it was a
|
|
99
|
+
-- delegated call (#3161). NULL is the ordinary case -- nobody acted for anyone -- and
|
|
100
|
+
-- the actor column above stays the person, as it does under impersonation.
|
|
101
|
+
delegation TEXT,
|
|
98
102
|
-- #1231: the invoke() string this event was emitted from. NULL is two facts the
|
|
99
103
|
-- spine cannot tell apart afterwards: a consumer emit (no operation ran), and a
|
|
100
104
|
-- row written before the column.
|
|
@@ -167,6 +171,8 @@ const KERNEL_DDL = `
|
|
|
167
171
|
operation TEXT,
|
|
168
172
|
-- K-42: WHICH of the two actors was refused is exactly what this log is for.
|
|
169
173
|
impersonation TEXT,
|
|
174
|
+
-- #3176: the app a refused delegated call was made by (JSON {actor}). NULL = nobody.
|
|
175
|
+
delegation TEXT,
|
|
170
176
|
-- #1525: the INVOCATION this refusal happened during, the same id #1237 stamps on
|
|
171
177
|
-- every event of a call. A denial joins to nothing but actor and time otherwise --
|
|
172
178
|
-- the operation column names what was attempted, never WHICH attempt -- so "what
|
|
@@ -2295,7 +2301,13 @@ options = {}) {
|
|
|
2295
2301
|
*/
|
|
2296
2302
|
systemDoorInstance,
|
|
2297
2303
|
/** K-61: the person's verified address, which only the coordinator's `getScope` sends. */
|
|
2298
|
-
verifiedEmail
|
|
2304
|
+
verifiedEmail,
|
|
2305
|
+
/**
|
|
2306
|
+
* #3161: the person is acting through another app, and `scope` caps every check the call
|
|
2307
|
+
* makes. Plain data, re-parsed here. An old DO that ignored it would run the call uncapped,
|
|
2308
|
+
* so the reply carries `delegation.honoured` and the coordinator refuses a success without it.
|
|
2309
|
+
*/
|
|
2310
|
+
delegation) {
|
|
2299
2311
|
// #2762: filled by `ctx.log` while the queued body runs. Only reported when asked, so the
|
|
2300
2312
|
// envelope of a caller that did not ask is what it was, and only once the queued body ran:
|
|
2301
2313
|
// a call refused before it (an unknown operation, an input that fails its parse) is "not
|
|
@@ -2306,7 +2318,7 @@ options = {}) {
|
|
|
2306
2318
|
// Legacy path, byte-for-byte what it was: rewrapped so a non-plain error (a
|
|
2307
2319
|
// ZodError, whose `message` is a getter) still arrives with its message.
|
|
2308
2320
|
try {
|
|
2309
|
-
return await this.#invokeOrThrow(operation, input, principal, tenantId, scopeId, connectionId, requiredEntitlement, systemModuleId, invokeOptions, impersonation, capabilitySession, verticalCaller, systemDoorInstance, undefined, undefined, verifiedEmail);
|
|
2321
|
+
return await this.#invokeOrThrow(operation, input, principal, tenantId, scopeId, connectionId, requiredEntitlement, systemModuleId, invokeOptions, impersonation, capabilitySession, verticalCaller, systemDoorInstance, undefined, undefined, verifiedEmail, delegation);
|
|
2310
2322
|
}
|
|
2311
2323
|
catch (err) {
|
|
2312
2324
|
if (err instanceof SystemDoorMovedError)
|
|
@@ -2315,7 +2327,7 @@ options = {}) {
|
|
|
2315
2327
|
}
|
|
2316
2328
|
}
|
|
2317
2329
|
try {
|
|
2318
|
-
return withLogLines(await this.#invokeOrThrow(operation, input, principal, tenantId, scopeId, connectionId, requiredEntitlement, systemModuleId, invokeOptions, impersonation, capabilitySession, verticalCaller, systemDoorInstance, undefined, logTally, verifiedEmail));
|
|
2330
|
+
return withLogLines(await this.#invokeOrThrow(operation, input, principal, tenantId, scopeId, connectionId, requiredEntitlement, systemModuleId, invokeOptions, impersonation, capabilitySession, verticalCaller, systemDoorInstance, undefined, logTally, verifiedEmail, delegation));
|
|
2319
2331
|
}
|
|
2320
2332
|
catch (err) {
|
|
2321
2333
|
// #1834: the pin missed — an answer, never a failure an operation could have produced.
|
|
@@ -2348,7 +2360,12 @@ options = {}) {
|
|
|
2348
2360
|
/** #2762: where this call's `ctx.log` lines are counted — `invoke`'s, never an RPC argument. */
|
|
2349
2361
|
logTally,
|
|
2350
2362
|
/** K-61: see `invoke` above. */
|
|
2351
|
-
verifiedEmail
|
|
2363
|
+
verifiedEmail,
|
|
2364
|
+
/** #3161: see `invoke` above. */
|
|
2365
|
+
delegation) {
|
|
2366
|
+
// #3161: the RPC is a boundary of its own, so the ceiling is parsed here too, before anything.
|
|
2367
|
+
const delegated = parseScopeDelegation(delegation);
|
|
2368
|
+
const ceiling = delegationCeilingOf(delegated);
|
|
2352
2369
|
await this.ensureMigrations();
|
|
2353
2370
|
const handler = this.operations.get(operation);
|
|
2354
2371
|
// `not_found`, not a bare throw (#113): every vertical hand-matched this message
|
|
@@ -2368,17 +2385,25 @@ options = {}) {
|
|
|
2368
2385
|
WHERE tenant_id = ? AND entitlement_key = ? AND (expires_at IS NULL OR expires_at > ?)`, tenantId, requiredEntitlement, new Date().toISOString())
|
|
2369
2386
|
.toArray()[0];
|
|
2370
2387
|
if (!held) {
|
|
2371
|
-
// The whole projected set, so the
|
|
2372
|
-
//
|
|
2388
|
+
// The whole projected set, so the operator's line names required AND held (#691);
|
|
2389
|
+
// the caller reads the operation and the key only (#3105). Only read on the failure
|
|
2390
|
+
// path — the hot path stays the single lookup above.
|
|
2373
2391
|
const now = new Date().toISOString();
|
|
2374
2392
|
const all = this.sql
|
|
2375
2393
|
.exec(`SELECT entitlement_key, expires_at FROM _substrat_entitlements
|
|
2376
2394
|
WHERE tenant_id = ? ORDER BY entitlement_key`, tenantId)
|
|
2377
2395
|
.toArray();
|
|
2378
|
-
throw
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2396
|
+
throw refuseEntitlement({
|
|
2397
|
+
operation,
|
|
2398
|
+
requiredKey: requiredEntitlement,
|
|
2399
|
+
held: all.map((r) => ({
|
|
2400
|
+
key: r.entitlement_key,
|
|
2401
|
+
expired: r.expires_at !== null && r.expires_at <= now,
|
|
2402
|
+
})),
|
|
2403
|
+
tenantId,
|
|
2404
|
+
scopeId,
|
|
2405
|
+
requestId: invokeOptions?.invocationId,
|
|
2406
|
+
});
|
|
2382
2407
|
}
|
|
2383
2408
|
}
|
|
2384
2409
|
// #893: parse, don't trust — at the scope door, from the operation's own
|
|
@@ -2462,6 +2487,12 @@ options = {}) {
|
|
|
2462
2487
|
peerSubject = admitPeer(this.switchSql(), this.peers, verticalCaller, operation);
|
|
2463
2488
|
idempotencySubjectRef = peerSubject;
|
|
2464
2489
|
}
|
|
2490
|
+
// #3161: a person's call arriving through a peer passes that peer's door too, on the same
|
|
2491
|
+
// terms: the pin, then declared and switched on. No allowlist: the ceiling governs.
|
|
2492
|
+
if (delegated?.via !== undefined) {
|
|
2493
|
+
this.assertPeerDoor(delegated.via.vertical, systemDoorInstance);
|
|
2494
|
+
admitPeer(this.switchSql(), this.peers, delegated.via, null);
|
|
2495
|
+
}
|
|
2465
2496
|
// #1672: the secrets this call mints — withheld from its idempotency recording, and
|
|
2466
2497
|
// what the tripwire on its writes looks for.
|
|
2467
2498
|
const minted = [];
|
|
@@ -2532,13 +2563,13 @@ options = {}) {
|
|
|
2532
2563
|
: undefined;
|
|
2533
2564
|
await this.revision.transaction(async () => {
|
|
2534
2565
|
const checks = { calls: 0 };
|
|
2535
|
-
const ctx = this.operationContext(principal, tenantId, scopeId, undefined, connectionId, systemDoor, signals, impersonation, operation, capabilityId, minted, undefined, peerSubject, undefined, withheld, checks, verifiedEmail);
|
|
2566
|
+
const ctx = this.operationContext(principal, tenantId, scopeId, undefined, connectionId, systemDoor, signals, impersonation, operation, capabilityId, minted, undefined, peerSubject, undefined, withheld, checks, verifiedEmail, ceiling, delegated);
|
|
2536
2567
|
// #116: a retry is answered from the recording, and nothing else runs
|
|
2537
2568
|
// — not the guards, not the handler, not the permission check inside
|
|
2538
2569
|
// it. Keyed by SUBJECT, so a caller only ever reaches its own
|
|
2539
2570
|
// responses; `idempotency.ts` states what that does not promise.
|
|
2540
2571
|
if (idempotencyKey !== undefined && fingerprint !== undefined) {
|
|
2541
|
-
const lookup = idempotencyLookupQuery(idempotencySubjectRef, idempotencyKey);
|
|
2572
|
+
const lookup = idempotencyLookupQuery(idempotencySubjectRef, idempotencyKey, delegated);
|
|
2542
2573
|
const prior = this.sql.exec(lookup.sql, ...lookup.params).toArray()[0];
|
|
2543
2574
|
if (prior) {
|
|
2544
2575
|
const replay = replayFor(idempotencyKey, fingerprint, prior);
|
|
@@ -2585,7 +2616,7 @@ options = {}) {
|
|
|
2585
2616
|
const at = new Date().toISOString();
|
|
2586
2617
|
const record = idempotencyRecordStatement(idempotencySubjectRef, idempotencyKey, operation, fingerprint,
|
|
2587
2618
|
// #1672: a replay of a mint returns the placeholder, never the secret.
|
|
2588
|
-
redactSecrets(result, minted), committedVersion, at);
|
|
2619
|
+
redactSecrets(result, minted), committedVersion, at, delegated);
|
|
2589
2620
|
this.sql.exec(record.sql, ...record.params);
|
|
2590
2621
|
const prune = idempotencyPruneStatement(at);
|
|
2591
2622
|
this.sql.exec(prune.sql, ...prune.params);
|
|
@@ -2608,6 +2639,7 @@ options = {}) {
|
|
|
2608
2639
|
result,
|
|
2609
2640
|
platformRequests: 0,
|
|
2610
2641
|
impersonation: { honoured: true },
|
|
2642
|
+
...(delegation !== undefined ? { delegation: { honoured: true } } : {}),
|
|
2611
2643
|
...(capabilitySession !== undefined ? { capability: { honoured: true } } : {}),
|
|
2612
2644
|
...(verticalCaller !== undefined ? { vertical: { honoured: true } } : {}),
|
|
2613
2645
|
...(systemDoorInstance !== undefined ? { systemDoor: { honoured: true } } : {}),
|
|
@@ -2632,7 +2664,7 @@ options = {}) {
|
|
|
2632
2664
|
idempotencySubjectRef, tenantId, operation, err,
|
|
2633
2665
|
// Inside the queued body, which is the one region where this call holds
|
|
2634
2666
|
// the DO to itself — so the field is this call's own (#1237).
|
|
2635
|
-
this.invocationId, impersonation);
|
|
2667
|
+
this.invocationId, impersonation, delegated);
|
|
2636
2668
|
}
|
|
2637
2669
|
// #1745: a refused transition, recorded the same way — the rollback took the
|
|
2638
2670
|
// attempt with it, and nothing else would remember it.
|
|
@@ -2671,6 +2703,8 @@ options = {}) {
|
|
|
2671
2703
|
...(exported > 0 ? { exported } : {}),
|
|
2672
2704
|
...(emitted ? { emitted } : {}),
|
|
2673
2705
|
...(impersonation ? { impersonation: { honoured: true } } : {}),
|
|
2706
|
+
// #3161: the same, for a delegated person's ceiling.
|
|
2707
|
+
...(delegation !== undefined ? { delegation: { honoured: true } } : {}),
|
|
2674
2708
|
// #1672: the acknowledgement the coordinator's skew check reads — see `invoke`.
|
|
2675
2709
|
...(capabilitySession !== undefined ? { capability: { honoured: true } } : {}),
|
|
2676
2710
|
// #1706: the same, for the peer door.
|
|
@@ -4182,11 +4216,13 @@ options = {}) {
|
|
|
4182
4216
|
* The one resolution both `ctx.canAssign` and `canAssignFor` answer from; `null`
|
|
4183
4217
|
* when the tenant defines no such role.
|
|
4184
4218
|
*/
|
|
4185
|
-
async assignmentBound(subject, tenantId, scopeId, roleKey
|
|
4219
|
+
async assignmentBound(subject, tenantId, scopeId, roleKey,
|
|
4220
|
+
/** #3161: a delegated call's ceiling — a role carrying a key above it is not covered. */
|
|
4221
|
+
ceiling) {
|
|
4186
4222
|
const role = await this.controlPlaneReader().getRole(tenantId, roleKey);
|
|
4187
4223
|
if (!role)
|
|
4188
4224
|
return null;
|
|
4189
|
-
return this.checker.covers(subject, role.permissions, { tenantId, scopeId });
|
|
4225
|
+
return capCoverage(await this.checker.covers(subject, role.permissions, { tenantId, scopeId }), role.permissions, ceiling);
|
|
4190
4226
|
}
|
|
4191
4227
|
/**
|
|
4192
4228
|
* Every module this scope holds or has held system authority for, and where each
|
|
@@ -6137,6 +6173,10 @@ options = {}) {
|
|
|
6137
6173
|
'ALTER TABLE _substrat_outbox ADD COLUMN impersonation TEXT',
|
|
6138
6174
|
'ALTER TABLE _substrat_platform_requests ADD COLUMN impersonation TEXT',
|
|
6139
6175
|
'ALTER TABLE _substrat_denials ADD COLUMN impersonation TEXT',
|
|
6176
|
+
// #3176: the delegated-call stamp, on K-42's terms: nullable, and the null on every row
|
|
6177
|
+
// already there means "nobody acted for anyone", since none of them could have.
|
|
6178
|
+
'ALTER TABLE _substrat_outbox ADD COLUMN delegation TEXT',
|
|
6179
|
+
'ALTER TABLE _substrat_denials ADD COLUMN delegation TEXT',
|
|
6140
6180
|
// #1525: the invocation a refusal happened during, on a scope DO created before
|
|
6141
6181
|
// the column. Nullable, and the null is honestly "no id was carried" — a past
|
|
6142
6182
|
// denial's call cannot be decided afterwards, as #1237's outbox column argued.
|
|
@@ -7350,7 +7390,9 @@ options = {}) {
|
|
|
7350
7390
|
* costs one argument. No test accompanies it — the condition could not be
|
|
7351
7391
|
* reproduced, and a test that passes either way would be worse than none.
|
|
7352
7392
|
*/
|
|
7353
|
-
invocationId, impersonation
|
|
7393
|
+
invocationId, impersonation,
|
|
7394
|
+
/** #3176: the delegation the refused call was made under, when it was made for a person. */
|
|
7395
|
+
delegation) {
|
|
7354
7396
|
// Only an ENFORCED denial (assertAllowed, which attaches the checked permission +
|
|
7355
7397
|
// node) is recorded. A module's own hand-thrown `new PermissionDenied('…')` carries
|
|
7356
7398
|
// no permission key and is left to the module.
|
|
@@ -7359,8 +7401,8 @@ options = {}) {
|
|
|
7359
7401
|
const actor = actorOf(subject);
|
|
7360
7402
|
this.sql.exec(`INSERT INTO _substrat_denials
|
|
7361
7403
|
(id, actor, permission, tenant_id, scope_id, operation, impersonation,
|
|
7362
|
-
invocation_id, at)
|
|
7363
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`, ulid(), JSON.stringify(actor), err.permission, err.node.tenantId, err.node.scopeId ?? null, operation, impersonation ? JSON.stringify(impersonationStampOf(impersonation)) : null,
|
|
7404
|
+
delegation, invocation_id, at)
|
|
7405
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, ulid(), JSON.stringify(actor), err.permission, err.node.tenantId, err.node.scopeId ?? null, operation, impersonation ? JSON.stringify(impersonationStampOf(impersonation)) : null, delegation ? JSON.stringify(delegationStampOf(delegation)) : null,
|
|
7364
7406
|
// #1525: the call this refusal belongs to, as the caller named it.
|
|
7365
7407
|
invocationId, new Date().toISOString());
|
|
7366
7408
|
}
|
|
@@ -7421,7 +7463,15 @@ options = {}) {
|
|
|
7421
7463
|
/** #2387: where this invocation's checks are counted; absent where nothing reads the count. */
|
|
7422
7464
|
checks,
|
|
7423
7465
|
/** K-61: the person's verified address, from `getScope` alone. */
|
|
7424
|
-
verifiedEmail
|
|
7466
|
+
verifiedEmail,
|
|
7467
|
+
/** #3161: a delegated call's ceiling — keys outside it are refused like `withheld`. */
|
|
7468
|
+
ceiling,
|
|
7469
|
+
/**
|
|
7470
|
+
* #3176: the delegation this invocation was made under, stamped on every event it emits
|
|
7471
|
+
* (sub-transactions and the kernel's own events included). Only the invoke path passes
|
|
7472
|
+
* one, so a consumer's, a schedule's or an import's context never carries it.
|
|
7473
|
+
*/
|
|
7474
|
+
delegation) {
|
|
7425
7475
|
const checker = this.checker;
|
|
7426
7476
|
const relations = this.relations;
|
|
7427
7477
|
const searchPlans = this.searchPlans;
|
|
@@ -7462,6 +7512,8 @@ options = {}) {
|
|
|
7462
7512
|
// operation writes about who did what carries it, and module code can
|
|
7463
7513
|
// neither add it nor drop it.
|
|
7464
7514
|
const stamp = impersonation ? impersonationStampOf(impersonation) : undefined;
|
|
7515
|
+
// #3176: the app acting for the person, computed once on the same terms.
|
|
7516
|
+
const delegationStamp = delegation ? delegationStampOf(delegation) : undefined;
|
|
7465
7517
|
/**
|
|
7466
7518
|
* The scope host's half of `ctx.atomic` (#770) — everything else is the
|
|
7467
7519
|
* kernel's (`createAtomic`).
|
|
@@ -7482,7 +7534,7 @@ options = {}) {
|
|
|
7482
7534
|
// #1642: parsed before the system actor's early return, which never reaches
|
|
7483
7535
|
// the checker — a cast key would otherwise become that path's proof relation.
|
|
7484
7536
|
const permission = assertPermissionKey(unparsed);
|
|
7485
|
-
if (withheld?.has(permission)) {
|
|
7537
|
+
if (withheld?.has(permission) || outsideCeiling(ceiling, permission)) {
|
|
7486
7538
|
return { allowed: false, checked: permission, node: { tenantId, scopeId } };
|
|
7487
7539
|
}
|
|
7488
7540
|
if (systemActor) {
|
|
@@ -7514,7 +7566,7 @@ options = {}) {
|
|
|
7514
7566
|
const refused = await this.reservedRoleRefusalFor(tenantId, roleKey, 'person');
|
|
7515
7567
|
if (refused)
|
|
7516
7568
|
throw substratError('forbidden', refused);
|
|
7517
|
-
const bound = await this.assignmentBound(subject, tenantId, scopeId, roleKey);
|
|
7569
|
+
const bound = await this.assignmentBound(subject, tenantId, scopeId, roleKey, ceiling);
|
|
7518
7570
|
if (!bound) {
|
|
7519
7571
|
throw unknownRoleError(roleKey);
|
|
7520
7572
|
}
|
|
@@ -7545,6 +7597,7 @@ options = {}) {
|
|
|
7545
7597
|
actor: systemActor ?? derivedActor,
|
|
7546
7598
|
...(passed.length ? { authorization: passed.map((p) => ({ ...p })) } : {}),
|
|
7547
7599
|
...(stamp ? { impersonation: stamp } : {}),
|
|
7600
|
+
...(delegationStamp ? { delegation: delegationStamp } : {}),
|
|
7548
7601
|
// #1231: kernel-stamped like the two above — `domainEventInput.parse`
|
|
7549
7602
|
// already stripped anything module code tried to smuggle under this key.
|
|
7550
7603
|
...(operation ? { operation } : {}),
|
|
@@ -7552,8 +7605,8 @@ options = {}) {
|
|
|
7552
7605
|
sql.exec(`INSERT INTO _substrat_outbox
|
|
7553
7606
|
(id, type, schema_version, occurred_at, tenant_id, scope_id, actor,
|
|
7554
7607
|
entity_type, entity_id, pii_class, subject_id, authorization,
|
|
7555
|
-
impersonation, operation, version, caused_by, invocation_id, payload)
|
|
7556
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, full.id, full.type, full.schemaVersion, full.occurredAt, full.tenantId, full.scopeId, JSON.stringify(full.actor), full.entity.entityType, full.entity.entityId, full.piiClass, full.subjectId ?? null, full.authorization ? JSON.stringify(full.authorization) : null, full.impersonation ? JSON.stringify(full.impersonation) : null, full.operation ?? null,
|
|
7608
|
+
impersonation, delegation, operation, version, caused_by, invocation_id, payload)
|
|
7609
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, full.id, full.type, full.schemaVersion, full.occurredAt, full.tenantId, full.scopeId, JSON.stringify(full.actor), full.entity.entityType, full.entity.entityId, full.piiClass, full.subjectId ?? null, full.authorization ? JSON.stringify(full.authorization) : null, full.impersonation ? JSON.stringify(full.impersonation) : null, full.delegation ? JSON.stringify(full.delegation) : null, full.operation ?? null,
|
|
7557
7610
|
// #1242: script configuration, not envelope data — the version is a fact
|
|
7558
7611
|
// about the deploy, so it never rides `DomainEvent` for module code to
|
|
7559
7612
|
// branch on; it exists for the observability joins the column serves.
|
|
@@ -7648,7 +7701,7 @@ options = {}) {
|
|
|
7648
7701
|
check: runCheck,
|
|
7649
7702
|
grantedEntities: async (unparsed, entityType, options) => {
|
|
7650
7703
|
const permission = assertPermissionKey(unparsed);
|
|
7651
|
-
return grantedEntitiesForContext(checker, subject, permission, { tenantId, scopeId }, entityType, options, runCheck, withheld, Boolean(systemActor));
|
|
7704
|
+
return grantedEntitiesForContext(checker, subject, permission, { tenantId, scopeId }, entityType, options, runCheck, withheld, Boolean(systemActor), ceiling);
|
|
7652
7705
|
},
|
|
7653
7706
|
canAssign: runCanAssign,
|
|
7654
7707
|
// #827. Mirror of the pure adapter: the plan comes from registration, the
|