@substrat-run/adapter-cloudflare 0.241.0 → 0.242.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/connection-sweep-do.d.ts +12 -0
- package/dist/connection-sweep-do.d.ts.map +1 -1
- package/dist/connection-sweep-do.js +28 -6
- package/dist/connection-sweep-do.js.map +1 -1
- package/dist/control-plane-do.d.ts +22 -0
- package/dist/control-plane-do.d.ts.map +1 -1
- package/dist/control-plane-do.js +60 -13
- package/dist/control-plane-do.js.map +1 -1
- package/dist/control-plane-object.d.ts +23 -0
- package/dist/control-plane-object.d.ts.map +1 -0
- package/dist/control-plane-object.js +92 -0
- package/dist/control-plane-object.js.map +1 -0
- package/dist/directory-placement.d.ts.map +1 -1
- package/dist/directory-placement.js +7 -0
- package/dist/directory-placement.js.map +1 -1
- package/dist/egress-gate.d.ts +1 -1
- package/dist/egress-gate.d.ts.map +1 -1
- package/dist/egress-gate.js +2 -1
- package/dist/egress-gate.js.map +1 -1
- package/dist/host.d.ts +1058 -18
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +135 -29
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/listed-object.d.ts +24 -0
- package/dist/listed-object.d.ts.map +1 -0
- package/dist/listed-object.js +43 -0
- package/dist/listed-object.js.map +1 -0
- package/dist/route-resolver.d.ts +21 -0
- package/dist/route-resolver.d.ts.map +1 -1
- package/dist/scope-do.d.ts +5 -0
- package/dist/scope-do.d.ts.map +1 -1
- package/dist/scope-do.js +9 -1
- package/dist/scope-do.js.map +1 -1
- package/dist/scope-object.d.ts +28 -0
- package/dist/scope-object.d.ts.map +1 -0
- package/dist/scope-object.js +13 -0
- package/dist/scope-object.js.map +1 -0
- package/dist/scope-supervisor-do.d.ts.map +1 -1
- package/dist/scope-supervisor-do.js +5 -4
- package/dist/scope-supervisor-do.js.map +1 -1
- package/dist/supplied-pass-box.d.ts +16 -2
- package/dist/supplied-pass-box.d.ts.map +1 -1
- package/dist/supplied-pass-box.js +92 -28
- package/dist/supplied-pass-box.js.map +1 -1
- package/dist/tenant-due-index-do.d.ts +33 -0
- package/dist/tenant-due-index-do.d.ts.map +1 -1
- package/dist/tenant-due-index-do.js +47 -0
- package/dist/tenant-due-index-do.js.map +1 -1
- package/dist/tenant-due-work-do.d.ts +18 -0
- package/dist/tenant-due-work-do.d.ts.map +1 -1
- package/dist/tenant-due-work-do.js +21 -0
- package/dist/tenant-due-work-do.js.map +1 -1
- package/package.json +13 -12
package/dist/control-plane-do.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { scopeCopyOwnedByTenant, scopeCopyProbeOf, tenantDueWorkName } from './tenant-due-work-do.js';
|
|
1
|
+
import { scopeCopyOwnedByTenant, scopeCopyProbeOf, scopeCopySelectorSeen, tenantDueWorkName } from './tenant-due-work-do.js';
|
|
2
2
|
import { DurableObject } from 'cloudflare:workers';
|
|
3
|
-
import { membershipFencesBackfillSql, MEMBERSHIP_FENCES_DDL, MEMBERSHIP_FENCES_TABLE, membershipFencesTableExists, IMPERSONATION_COLUMNS, IMPERSONATION_DDL, impersonationByIdQuery, impersonationListQuery, impersonationRowValues, ISSUE_RETENTION_DAYS, telemetryRetentionStatements, FINDINGS_DDL, SCOPE_STORAGE_DDL, forgetScopeStorage, retireScopeStorage, listScopeStorageAttemptRows, listScopeStorageRows, listScopeAttachmentStorageRows, listScopeStoreStorageRows, pruneScopeStorageRows, recordScopeStorageRows, readBoundedTenantStorageGauge, REQUEST_ROLLUP_DDL, listRequestDayRows, listRequestRollupDayRows, pruneRequestDayRows, recordRequestDayRows, readTenantRequestMeterRows, readRequestMeterDayRows, COST_ROLLUP_DDL, listCostDayRows, listCostRollupDayRows, sumCostDayRows, pruneCostDayRows, recordCostDayRows, recordCostContainerRows, recordScopeObjectRow, scopeObjectsDueRows, METER_DAYS_DDL, STALE_SCOPES_DDL, listStaleScopeRows, listStaleScopeTakeRows, recordStaleScopeRows, VERTICAL_OWNERS_BACKFILL, VERTICAL_OWNERS_DDL, closeVerticalOwnerRow, listVerticalOwnerRows, openVerticalOwnerRow, verticalOwnerNow, listMeterDayRows, listMeterDayTakeRows, pruneMeterDayRows, recordMeterDayRows, DIRECTORY_LAKE_DDL, ackDirectoryOutbox, ensureDirectoryLakeTriggers, advanceDirectoryLakeBackfill, pruneDirectoryLakeWindow, readDirectoryLakeBackfill, readDirectoryLakeCapture, readDirectoryOutbox, setDirectoryLakeCapture, CONNECT_LINKS_DDL, createFindingRule, findingOfOpsFailure, findingOfSweepRun, pruneFindings, listFindingRules, listFindings, observeFinding, revokeFindingRule, setFindingStatus, assertRowLimit, OPS_FAILURE_RETENTION_DAYS, SWEEP_RUN_RETENTION_DAYS, SWEEP_RUNS_INTENT_INDEX, sweepRunsIntentHasKind, CONNECTIONS_LIVE_INDEX, connectionsLiveIndexHasOwner, PEER_SWITCHES_DDL, PEER_BINDINGS_DDL, APP_ENVIRONMENTS_DDL, claimEnvironmentServeIn, defineEnvironmentIn, ENVIRONMENT_SCRIPT_JOIN_SQL, environmentPeerResolutionIn, environmentsOf, HOME_SCOPE_TYPE, homeScopeIn, secondHomeRefusal, releaseEnvironmentServeIn, removeEnvironmentIn, setEnvironmentServingIn, environmentBindRefusalIn, setEnvironmentEffectsIn, connectionReachIn, SWITCH_OWED_DDL, DEPENDENT_ERASURES_DDL, DEPENDENT_ERASURE_DUE_SQL, DEPENDENT_ERASURE_HOLD_SQL, DEPENDENT_ERASURE_OWE_SQL, DEPENDENT_ERASURE_SETTLE_SQL, nextDependentErasureAt, clearSwitchOwed, markSwitchOwed, scopeOwesSwitch, switchesOwedOf, SWITCH_KINDS, SYSTEM_SWITCHES_DDL, forgetSwitchesOf, listSystemSwitchRecords, recordSwitchedOff, recordSwitchedOn, recordWriteSuperseded, restoreSwitchRecord, scopesSwitchedOffFor, switchRecordStatesOf, switchRecordsOf, switchesBackfillSqlOf, switchesDdlOf, switchesTableExists, switchesTableOf, tenantHeldOf, VERSION_MIGRATIONS_DDL, VERTICAL_SCOPE_STORES_DDL, DEPLOYMENT_WIRE_AUTH_DDL, deploymentWireAuthOf, forgetVerticalWireAuth, writeDeploymentWireAuth, STORE_DRIVER_RELEASES_DDL, approveStoreDriverReleaseIn, legacyStoreDriverConflict, legacyStoreDriverRenames, beginStoreDriverRolloutIn, finishStoreDriverRolloutIn, holdStoreDriverIn, advanceStoreDriverRebuildIn, claimStoreDriverRebuildIn, storeDriverRebuildIn, driverDeclarationsOf, recordStoreDriverReleaseIn, recordStoreDriverRevokeWalkIn, releaseStoreDriverHoldIn, revokeStoreDriverReleaseIn, liveStoreDriverApprovalIn, storeDriverApprovalsIn, storeDriverRevokeWalkIn, storeDriverReleaseIn, storeDriverStateIn, storeDriverRolloutPendingIn, storeDriverRolloutWalkedIn, forgetVerticalScopeStores, indexVersionScopeStores, verticalScopeStoresOf, splitVersionMigrationsBatch, versionMigrationsOf, versionMigrationsExtractedOf, recordVersionMigrationsExtracted, versionsAwaitSplit, versionsAwaitDigest, deriveMigrationDigestsBatch, deriveVersionMigrationDigest, writeVersionMigrations, MODEL_USAGE_RETENTION_DAYS, BUILD_USAGE_RETENTION_DAYS, DO_SQL_LIMITS, ulid, isPrimaryScopeRow, samePeerVertical, peerVerticalSpellings, resolveVerticalInstanceFrom, resolvePeerInstanceFrom, LEGACY_SCOPE_ROWS_BACKFILL, loadDirectoryDump, storesFencedRefusal, redactSubjectDirectoryText, ISSUE_EXEMPLAR_OWNER_BACKFILL_SQL, issueExemplarOwner, SETTLE_INTENT_SQL, SETTLE_OUTCOME_SQL, settleOutcomeParamsOf, unknownOutcomeOf, ADMIN_LOG_INDEX_DDL, ADMIN_LOG_INDEXES_SQL, readAuditedOperations, } from '@substrat-run/kernel';
|
|
3
|
+
import { membershipFencesBackfillSql, MEMBERSHIP_FENCES_DDL, MEMBERSHIP_FENCES_TABLE, membershipFencesTableExists, IMPERSONATION_COLUMNS, IMPERSONATION_DDL, impersonationByIdQuery, impersonationListQuery, impersonationRowValues, ISSUE_RETENTION_DAYS, telemetryRetentionStatements, FINDINGS_DDL, SCOPE_STORAGE_DDL, forgetScopeStorage, retireScopeStorage, listScopeStorageAttemptRows, listScopeStorageRows, listScopeAttachmentStorageRows, listScopeStoreStorageRows, pruneScopeStorageRows, recordScopeStorageRows, readBoundedTenantStorageGauge, REQUEST_ROLLUP_DDL, listRequestDayRows, listRequestRollupDayRows, pruneRequestDayRows, recordRequestDayRows, readTenantRequestMeterRows, readRequestMeterDayRows, COST_ROLLUP_DDL, listCostDayRows, listCostRollupDayRows, sumCostDayRows, pruneCostDayRows, recordCostDayRows, recordCostContainerRows, recordScopeObjectRow, scopeObjectsDueRows, METER_DAYS_DDL, STALE_SCOPES_DDL, listStaleScopeRows, listStaleScopeTakeRows, recordStaleScopeRows, VERTICAL_OWNERS_BACKFILL, VERTICAL_OWNERS_DDL, closeVerticalOwnerRow, listVerticalOwnerRows, openVerticalOwnerRow, verticalOwnerNow, listMeterDayRows, listMeterDayTakeRows, pruneMeterDayRows, recordMeterDayRows, DIRECTORY_LAKE_DDL, ackDirectoryOutbox, ensureDirectoryLakeTriggers, advanceDirectoryLakeBackfill, pruneDirectoryLakeWindow, readDirectoryLakeBackfill, readDirectoryLakeCapture, readDirectoryOutbox, setDirectoryLakeCapture, CONNECT_LINKS_DDL, createFindingRule, findingOfOpsFailure, findingOfSweepRun, pruneFindings, listFindingRules, listFindings, observeFinding, revokeFindingRule, setFindingStatus, assertRowLimit, OPS_FAILURE_RETENTION_DAYS, SWEEP_RUN_RETENTION_DAYS, SWEEP_RUNS_INTENT_INDEX, sweepRunsIntentHasKind, CONNECTIONS_LIVE_INDEX, connectionsLiveIndexHasOwner, PEER_SWITCHES_DDL, PEER_BINDINGS_DDL, APP_ENVIRONMENTS_DDL, claimEnvironmentServeIn, defineEnvironmentIn, ENVIRONMENT_SCRIPT_JOIN_SQL, environmentPeerResolutionIn, environmentsOf, HOME_SCOPE_TYPE, homeScopeIn, secondHomeRefusal, releaseEnvironmentServeIn, removeEnvironmentIn, setEnvironmentServingIn, environmentBindRefusalIn, setEnvironmentEffectsIn, connectionReachIn, SWITCH_OWED_DDL, DEPENDENT_ERASURES_DDL, DEPENDENT_ERASURE_DUE_SQL, DEPENDENT_ERASURE_HOLD_SQL, DEPENDENT_ERASURE_OWE_SQL, DEPENDENT_ERASURE_SETTLE_SQL, nextDependentErasureAt, clearSwitchOwed, markSwitchOwed, scopeOwesSwitch, switchesOwedOf, SWITCH_KINDS, SYSTEM_SWITCHES_DDL, OLDEST_WRAPPED_SECRET_SQL, SECRET_BOX_CANARY_DDL, SECRET_BOX_CANARY_ID, forgetSwitchesOf, listSystemSwitchRecords, recordSwitchedOff, recordSwitchedOn, recordWriteSuperseded, restoreSwitchRecord, scopesSwitchedOffFor, switchRecordStatesOf, switchRecordsOf, switchesBackfillSqlOf, switchesDdlOf, switchesTableExists, switchesTableOf, tenantHeldOf, VERSION_MIGRATIONS_DDL, VERTICAL_SCOPE_STORES_DDL, DEPLOYMENT_WIRE_AUTH_DDL, deploymentWireAuthOf, forgetVerticalWireAuth, writeDeploymentWireAuth, STORE_DRIVER_RELEASES_DDL, approveStoreDriverReleaseIn, legacyStoreDriverConflict, legacyStoreDriverRenames, beginStoreDriverRolloutIn, finishStoreDriverRolloutIn, holdStoreDriverIn, advanceStoreDriverRebuildIn, claimStoreDriverRebuildIn, storeDriverRebuildIn, driverDeclarationsOf, recordStoreDriverReleaseIn, recordStoreDriverRevokeWalkIn, releaseStoreDriverHoldIn, revokeStoreDriverReleaseIn, liveStoreDriverApprovalIn, storeDriverApprovalsIn, storeDriverRevokeWalkIn, storeDriverReleaseIn, storeDriverStateIn, storeDriverRolloutPendingIn, storeDriverRolloutWalkedIn, forgetVerticalScopeStores, indexVersionScopeStores, verticalScopeStoresOf, splitVersionMigrationsBatch, versionMigrationsOf, versionMigrationsExtractedOf, recordVersionMigrationsExtracted, versionsAwaitSplit, versionsAwaitDigest, deriveMigrationDigestsBatch, deriveVersionMigrationDigest, writeVersionMigrations, MODEL_USAGE_RETENTION_DAYS, BUILD_USAGE_RETENTION_DAYS, DO_SQL_LIMITS, ulid, isPrimaryScopeRow, samePeerVertical, peerVerticalSpellings, resolveVerticalInstanceFrom, resolvePeerInstanceFrom, LEGACY_SCOPE_ROWS_BACKFILL, loadDirectoryDump, storesFencedRefusal, redactSubjectDirectoryText, ISSUE_EXEMPLAR_OWNER_BACKFILL_SQL, issueExemplarOwner, SETTLE_INTENT_SQL, SETTLE_OUTCOME_SQL, settleOutcomeParamsOf, unknownOutcomeOf, ADMIN_LOG_INDEX_DDL, ADMIN_LOG_INDEXES_SQL, readAuditedOperations, } from '@substrat-run/kernel';
|
|
4
4
|
import { MARKUP_INSERT_SQL, MARKUP_SELECT_FOR_TENANT_SQL, MARKUP_SELECT_SQL, } from '@substrat-run/kernel';
|
|
5
5
|
import { replyOf } from './do-reply.js';
|
|
6
6
|
import { rowBytes, switchSqlOver } from './scope-do.js';
|
|
@@ -465,8 +465,9 @@ const DIRECTORY_DDL = `
|
|
|
465
465
|
owner_scope_id TEXT
|
|
466
466
|
);
|
|
467
467
|
-- One LIVE connection per (tenant, vertical, provider, account, owner): see the
|
|
468
|
-
-- kernel's fragment.
|
|
469
|
-
-- (IF NOT EXISTS matches the name),
|
|
468
|
+
-- kernel's fragment. Held back by planDirectoryDdl until owner_scope_id exists; on a
|
|
469
|
+
-- directory that already has the index it is a no-op (IF NOT EXISTS matches the name),
|
|
470
|
+
-- and ensureConnectionsLiveIndex re-keys it.
|
|
470
471
|
${CONNECTIONS_LIVE_INDEX}
|
|
471
472
|
CREATE TABLE IF NOT EXISTS _substrat_connection_secrets (
|
|
472
473
|
connection_id TEXT PRIMARY KEY,
|
|
@@ -566,6 +567,9 @@ const DIRECTORY_DDL = `
|
|
|
566
567
|
shredded_at TEXT,
|
|
567
568
|
PRIMARY KEY (scope_id, subject_id)
|
|
568
569
|
);
|
|
570
|
+
-- #3464: the canary every seal opens first when the host is told a mode (kernel secret-box-canary.ts).
|
|
571
|
+
-- One row, sealed by the coordinator's SecretBox; this object holds only its ciphertext.
|
|
572
|
+
${SECRET_BOX_CANARY_DDL}
|
|
569
573
|
${IMPERSONATION_DDL}
|
|
570
574
|
${SYSTEM_SWITCHES_DDL}
|
|
571
575
|
${MEMBERSHIP_FENCES_DDL}
|
|
@@ -856,8 +860,14 @@ export function planDirectoryDdl(ddl) {
|
|
|
856
860
|
// `_substrat_sweep_runs` predates `request_id`, the loop meets the index before
|
|
857
861
|
// `ensureDirectoryColumns` adds the column: "no such column: request_id", on every construction,
|
|
858
862
|
// so the column is never added and the directory never starts again (the test directory, from
|
|
859
|
-
// 2026-09-07, #3395). Held back to run once the columns exist.
|
|
860
|
-
|
|
863
|
+
// 2026-09-07, #3395). Held back to run once the columns exist. The live-connection index names
|
|
864
|
+
// `owner_scope_id` (#2732) the same way: a directory whose `_substrat_connections` has neither the
|
|
865
|
+
// column nor the index (the test dashboard's) met it in the loop and could not start.
|
|
866
|
+
const afterColumns = [
|
|
867
|
+
...executableSqlStatements(VERSION_MIGRATIONS_DDL),
|
|
868
|
+
...executableSqlStatements(SWEEP_RUNS_INTENT_INDEX),
|
|
869
|
+
...executableSqlStatements(CONNECTIONS_LIVE_INDEX),
|
|
870
|
+
];
|
|
861
871
|
const held = new Set(afterColumns);
|
|
862
872
|
return {
|
|
863
873
|
loop: all.filter((stmt) => !held.has(stmt)),
|
|
@@ -868,7 +878,7 @@ export function planDirectoryDdl(ddl) {
|
|
|
868
878
|
/** Refuses a plan whose held-back statements the DDL does not carry; returns it otherwise. */
|
|
869
879
|
export function assertDirectoryDdlPlan(plan) {
|
|
870
880
|
if (plan.missing.length > 0) {
|
|
871
|
-
throw new Error(`the directory DDL does not carry ${plan.missing.length} statement(s) it holds back until the columns exist (VERSION_MIGRATIONS_DDL, the sweep-runs
|
|
881
|
+
throw new Error(`the directory DDL does not carry ${plan.missing.length} statement(s) it holds back until the columns exist (VERSION_MIGRATIONS_DDL, the sweep-runs and live-connection indexes) — ` +
|
|
872
882
|
`interpolate the fragment whole: ${plan.missing[0]}`);
|
|
873
883
|
}
|
|
874
884
|
return plan;
|
|
@@ -1124,6 +1134,15 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1124
1134
|
}
|
|
1125
1135
|
async handOverScopeCopy(tenantId, scopeId, dueAt) {
|
|
1126
1136
|
const env = this.env;
|
|
1137
|
+
// #3540: while a copy selector names this tenant, one line per copy-ledger write that hands copies
|
|
1138
|
+
// over (a recorded copy, a confirmed move from an eligible source, a settle to eligible: the only
|
|
1139
|
+
// callers of this method) saying what this instance saw. Workers Logs stamps it with the script version; an instance still on an earlier
|
|
1140
|
+
// version sees no selector and writes none, so its absence is the trace a lost handoff leaves.
|
|
1141
|
+
const seen = scopeCopySelectorSeen(env, tenantId, scopeId);
|
|
1142
|
+
if (seen.names) {
|
|
1143
|
+
console.log(JSON.stringify({ scopeCopyHandoff: seen.via, tenantId, scopeId, probe: seen.probe, named: seen.named,
|
|
1144
|
+
dueAt: new Date(dueAt).toISOString() }));
|
|
1145
|
+
}
|
|
1127
1146
|
if (scopeCopyOwnedByTenant(env, tenantId)) {
|
|
1128
1147
|
await this.handOverTenantDueWork(tenantId, [{ kind: 'copies', unit: tenantId, dueAt }]);
|
|
1129
1148
|
return;
|
|
@@ -1837,7 +1856,11 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
1837
1856
|
const row = this.sql
|
|
1838
1857
|
.exec("SELECT sql FROM sqlite_master WHERE type = 'index' AND name = ?", '_substrat_connections_live_account')
|
|
1839
1858
|
.toArray()[0];
|
|
1840
|
-
|
|
1859
|
+
// None at all (a fresh or restored directory, or one whose index never got built): the held-back
|
|
1860
|
+
// `DIRECTORY_DDL_PLAN.afterColumns` creates it right after this, as for the sweep-runs index.
|
|
1861
|
+
if (!row)
|
|
1862
|
+
return;
|
|
1863
|
+
if (connectionsLiveIndexHasOwner(row.sql))
|
|
1841
1864
|
return;
|
|
1842
1865
|
this.rebuildAtomically(['DROP INDEX IF EXISTS _substrat_connections_live_account', CONNECTIONS_LIVE_INDEX]);
|
|
1843
1866
|
}
|
|
@@ -2879,19 +2902,21 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
2879
2902
|
releaseStoreDriverHoldIn(this.kernelSql, input);
|
|
2880
2903
|
}
|
|
2881
2904
|
beginStoreDriverRollout(input, audit) {
|
|
2905
|
+
const { registrationDigest, ...rest } = input;
|
|
2882
2906
|
let row;
|
|
2883
2907
|
this.writeAndAudit(() => {
|
|
2884
|
-
row = beginStoreDriverRolloutIn(this.kernelSql, { ...
|
|
2908
|
+
row = beginStoreDriverRolloutIn(this.kernelSql, { ...rest, nowMs: Date.now() });
|
|
2885
2909
|
return true;
|
|
2886
|
-
}, audit ? () => ({ ...audit, after: row }) : undefined);
|
|
2910
|
+
}, audit ? () => ({ ...audit, after: registrationDigest === undefined ? row : { ...row, registrationDigest } }) : undefined);
|
|
2887
2911
|
return row;
|
|
2888
2912
|
}
|
|
2889
2913
|
finishStoreDriverRollout(input, audit) {
|
|
2914
|
+
const { registrationDigest, ...rest } = input;
|
|
2890
2915
|
let row;
|
|
2891
2916
|
this.writeAndAudit(() => {
|
|
2892
|
-
row = finishStoreDriverRolloutIn(this.kernelSql, { ...
|
|
2917
|
+
row = finishStoreDriverRolloutIn(this.kernelSql, { ...rest, nowMs: Date.now() });
|
|
2893
2918
|
return true;
|
|
2894
|
-
}, audit ? () => ({ ...audit, action: row.action === 'rollback' ? 'rollBackStoreDriver' : 'rollOutStoreDriver', after: row }) : undefined);
|
|
2919
|
+
}, audit ? () => ({ ...audit, action: row.action === 'rollback' ? 'rollBackStoreDriver' : 'rollOutStoreDriver', after: registrationDigest === undefined ? row : { ...row, registrationDigest } }) : undefined);
|
|
2895
2920
|
return row;
|
|
2896
2921
|
}
|
|
2897
2922
|
storeDriverRebuild(driver) {
|
|
@@ -5822,6 +5847,23 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
5822
5847
|
}, audit ? () => ({ ...audit, after: { pruned } }) : undefined);
|
|
5823
5848
|
return pruned;
|
|
5824
5849
|
}
|
|
5850
|
+
// -- the SecretBox canary (#3464) ------------------------------------------
|
|
5851
|
+
// The three row operations `guardSecretBox` needs, each one statement outside any transaction, as
|
|
5852
|
+
// the subject keys' are. The crypto, and the decision, are the coordinator's.
|
|
5853
|
+
readSecretBoxCanary() {
|
|
5854
|
+
const row = this.sql
|
|
5855
|
+
.exec('SELECT key_id, ciphertext FROM _substrat_secret_box_canary WHERE id = ?', SECRET_BOX_CANARY_ID)
|
|
5856
|
+
.toArray()[0];
|
|
5857
|
+
return row ? { keyId: row.key_id, ciphertext: row.ciphertext } : undefined;
|
|
5858
|
+
}
|
|
5859
|
+
/** `OR IGNORE`: the first canary stays, and the coordinator reads back which one that is. */
|
|
5860
|
+
insertSecretBoxCanary(row) {
|
|
5861
|
+
this.sql.exec('INSERT OR IGNORE INTO _substrat_secret_box_canary (id, key_id, ciphertext, created_at) VALUES (?, ?, ?, ?)', SECRET_BOX_CANARY_ID, row.keyId, row.ciphertext, row.createdAt);
|
|
5862
|
+
}
|
|
5863
|
+
oldestWrappedSecret() {
|
|
5864
|
+
const row = this.sql.exec(OLDEST_WRAPPED_SECRET_SQL).toArray()[0];
|
|
5865
|
+
return row ? { keyId: row.key_id, ciphertext: row.ciphertext } : undefined;
|
|
5866
|
+
}
|
|
5825
5867
|
// -- per-subject keys (#37) -------------------------------------------------
|
|
5826
5868
|
// The three row operations `createSubjectKeys` needs. The crypto is the kernel's; what
|
|
5827
5869
|
// lives here is storage, which is the only part that differs between adapters.
|
|
@@ -6015,6 +6057,10 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
6015
6057
|
}
|
|
6016
6058
|
if (filter.unrecorded)
|
|
6017
6059
|
where.push('COALESCE(r.tenant_recorded, 0) <> 1');
|
|
6060
|
+
if (filter.askedBefore !== undefined) {
|
|
6061
|
+
where.push('(a.asked_at IS NULL OR a.asked_at <= ?)');
|
|
6062
|
+
params.push(filter.askedBefore);
|
|
6063
|
+
}
|
|
6018
6064
|
// #3119: the heal leaves out a scope backing off from the receipt it still wants, at the
|
|
6019
6065
|
// deployment it still has. A transition's own delivery (scopeId, tenantId) never waits.
|
|
6020
6066
|
if (filter.drift || filter.unrecorded) {
|
|
@@ -6036,7 +6082,8 @@ export class ControlPlaneDO extends DurableObject {
|
|
|
6036
6082
|
return this.sql
|
|
6037
6083
|
.exec(`SELECT s.tenant_id, s.scope_id, s.status AS scope_status, t.status AS tenant_status, r.delivered,
|
|
6038
6084
|
${epoch} AS epoch, COALESCE(rs.revision, 0) AS scope_rev, COALESCE(rt.revision, 0) AS tenant_rev,
|
|
6039
|
-
${LIFECYCLE_DEPLOYMENT} AS deployment, f.retry_at, r.deployment AS receipt_deployment
|
|
6085
|
+
${LIFECYCLE_DEPLOYMENT} AS deployment, f.retry_at, r.deployment AS receipt_deployment,
|
|
6086
|
+
r.tenant_recorded, a.asked_at
|
|
6040
6087
|
FROM scopes s
|
|
6041
6088
|
JOIN tenants t ON t.tenant_id = s.tenant_id
|
|
6042
6089
|
LEFT JOIN verticals v ON v.slug = s.vertical
|