gencow 0.1.299 → 0.2.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/bin/gencow.mjs +0 -6
- package/core/package.json +1 -1
- package/docs/packaging.md +14 -4
- package/lib/cli-artifact-guard.mjs +53 -3
- package/lib/cli-dev-runtime.mjs +1 -0
- package/lib/cli-project-runtime.mjs +26 -14
- package/lib/codegen-command.mjs +16 -0
- package/lib/coding-guardrails.mjs +2 -0
- package/lib/dashboard-artifact.mjs +65 -0
- package/lib/dashboard-assets.mjs +20 -0
- package/lib/db-command.mjs +121 -80
- package/lib/db-migration-command-steps.mjs +19 -16
- package/lib/db-push-command.mjs +1 -1
- package/lib/deploy-codegen-preflight.mjs +1 -0
- package/lib/dev-cloud-command.mjs +1 -1
- package/lib/dev-local-command.mjs +19 -56
- package/lib/document-local-converter.mjs +11 -0
- package/lib/local-dashboard-plan.mjs +60 -0
- package/lib/local-database-commands.mjs +127 -0
- package/lib/local-development-migrations.mjs +157 -0
- package/lib/local-drizzle-database.config.mjs +10 -0
- package/lib/local-runtime-features.mjs +12 -0
- package/lib/rag-selection.mjs +7 -0
- package/lib/runtime-local-worker.mjs +116 -0
- package/lib/runtime-mode.mjs +3 -0
- package/lib/standalone-codegen-adapter.mjs +91 -0
- package/lib/ts-codegen-import-extension.mjs +228 -19
- package/package.json +16 -9
- package/runtime/config.mjs +218 -2
- package/runtime/engine/chunk-2HA4CUMS.mjs +90 -0
- package/runtime/engine/chunk-2JLO3KMM.mjs +305 -0
- package/runtime/engine/chunk-2SR2M7SR.mjs +1045 -0
- package/runtime/engine/chunk-3D7MHEUC.mjs +253 -0
- package/runtime/engine/chunk-3R7COBWG.mjs +309 -0
- package/runtime/engine/chunk-3ZKA54UW.mjs +1560 -0
- package/runtime/engine/chunk-45I4YR2J.mjs +9 -0
- package/runtime/engine/chunk-4MLRXO7F.mjs +74 -0
- package/runtime/engine/chunk-5575APCJ.mjs +215 -0
- package/runtime/engine/chunk-5GUJZQF3.mjs +114 -0
- package/runtime/engine/chunk-5MXY3T75.mjs +428 -0
- package/runtime/engine/chunk-5TACQ2US.mjs +44 -0
- package/runtime/engine/chunk-66G4YEDT.mjs +3104 -0
- package/runtime/engine/chunk-67YO53WW.mjs +1426 -0
- package/runtime/engine/chunk-6GQRM7XY.mjs +87 -0
- package/runtime/engine/chunk-6JO72SPP.mjs +68 -0
- package/runtime/engine/chunk-6W653LXI.mjs +13 -0
- package/runtime/engine/chunk-7ITSMI3S.mjs +69 -0
- package/runtime/engine/chunk-7KUJ2H2S.mjs +128 -0
- package/runtime/engine/chunk-A5BMQ5IC.mjs +45 -0
- package/runtime/engine/chunk-ADF3UR6L.mjs +428 -0
- package/runtime/engine/chunk-AEBW7XZJ.mjs +4510 -0
- package/runtime/engine/chunk-AGPQ5XIV.mjs +156 -0
- package/runtime/engine/chunk-CPU4OZSX.mjs +753 -0
- package/runtime/engine/chunk-CSWPPWBL.mjs +50 -0
- package/runtime/engine/chunk-DPWXSMWO.mjs +53 -0
- package/runtime/engine/chunk-EAIELFKU.mjs +151 -0
- package/runtime/engine/chunk-EDU5CBKT.mjs +10 -0
- package/runtime/engine/chunk-EQCTAET7.mjs +173 -0
- package/runtime/engine/chunk-EQCXDF2Z.mjs +70 -0
- package/runtime/engine/chunk-F3G4UGV4.mjs +330 -0
- package/runtime/engine/chunk-F62NUNOO.mjs +26 -0
- package/runtime/engine/chunk-FKPNIFRP.mjs +2492 -0
- package/runtime/engine/chunk-FM23RGVI.mjs +81 -0
- package/runtime/engine/chunk-FW5AK4YP.mjs +1041 -0
- package/runtime/engine/chunk-GDWYAGWV.mjs +23 -0
- package/runtime/engine/chunk-GO5PZUYW.mjs +53 -0
- package/runtime/engine/chunk-GOLP7OSG.mjs +340 -0
- package/runtime/engine/chunk-GSLM44EF.mjs +242 -0
- package/runtime/engine/chunk-GYAJ7OX2.mjs +125 -0
- package/runtime/engine/chunk-I3GWR43K.mjs +14 -0
- package/runtime/engine/chunk-IFMOTJNU.mjs +106 -0
- package/runtime/engine/chunk-IKQKBE2G.mjs +128 -0
- package/runtime/engine/chunk-ITH2NEKM.mjs +282 -0
- package/runtime/engine/chunk-J6SDRCG4.mjs +96 -0
- package/runtime/engine/chunk-JODRNM3S.mjs +29596 -0
- package/runtime/engine/chunk-JUDKX53X.mjs +137 -0
- package/runtime/engine/chunk-K2YZVPJ4.mjs +827 -0
- package/runtime/engine/chunk-KEZJUXEE.mjs +151 -0
- package/runtime/engine/chunk-KVLTJFCH.mjs +234 -0
- package/runtime/engine/chunk-KX2PRQPS.mjs +126 -0
- package/runtime/engine/chunk-LEW5ZMLR.mjs +76 -0
- package/runtime/engine/chunk-LINVSJEM.mjs +175 -0
- package/runtime/engine/chunk-M7K2ICSM.mjs +11 -0
- package/runtime/engine/chunk-MZXDXSDC.mjs +292 -0
- package/runtime/engine/chunk-N2TA2IK2.mjs +678 -0
- package/runtime/engine/chunk-N4LTCKJP.mjs +695 -0
- package/runtime/engine/chunk-N6GCLOUX.mjs +13 -0
- package/runtime/engine/chunk-NAG2OXS5.mjs +37 -0
- package/runtime/engine/chunk-NNZ2QJUG.mjs +381 -0
- package/runtime/engine/chunk-NZPPLDNW.mjs +15 -0
- package/runtime/engine/chunk-ODWM57W6.mjs +138 -0
- package/runtime/engine/chunk-P5IIXAIE.mjs +23 -0
- package/runtime/engine/chunk-PBOXB2BV.mjs +6 -0
- package/runtime/engine/chunk-PMOJLN2P.mjs +8 -0
- package/runtime/engine/chunk-PZFMKFHO.mjs +180 -0
- package/runtime/engine/chunk-QL2TQX2N.mjs +114 -0
- package/runtime/engine/chunk-RITT2RSJ.mjs +258 -0
- package/runtime/engine/chunk-RODBVJ5M.mjs +135 -0
- package/runtime/engine/chunk-RW65MPVY.mjs +261 -0
- package/runtime/engine/chunk-S67UYPB6.mjs +25 -0
- package/runtime/engine/chunk-SVJCOUI3.mjs +47 -0
- package/runtime/engine/chunk-TCN3ZASV.mjs +957 -0
- package/runtime/engine/chunk-U2NRG6KC.mjs +32 -0
- package/runtime/engine/chunk-UM3F7HUV.mjs +432 -0
- package/runtime/engine/chunk-VWU7JJ3P.mjs +146 -0
- package/runtime/engine/chunk-WDTKPPMU.mjs +310 -0
- package/runtime/engine/chunk-WJOO4XTB.mjs +31 -0
- package/runtime/engine/chunk-XNFVL2OY.mjs +63 -0
- package/runtime/engine/chunk-XPWJXP2J.mjs +58 -0
- package/runtime/engine/chunk-Y3HSBJ3I.mjs +1132 -0
- package/runtime/engine/chunk-YMH4RYSX.mjs +317 -0
- package/runtime/engine/chunk-YNOMPSGS.mjs +8 -0
- package/runtime/engine/chunk-YRBAYTEZ.mjs +251 -0
- package/runtime/engine/chunk-YRHM272W.mjs +528 -0
- package/runtime/engine/chunk-ZQUZAGIQ.mjs +149 -0
- package/runtime/engine/chunk-ZXMM7QFP.mjs +176 -0
- package/runtime/engine/chunk-ZZJSIPV2.mjs +262 -0
- package/runtime/engine/composition.mjs +325 -0
- package/runtime/engine/document-local.mjs +504 -0
- package/runtime/engine/graph.json +4134 -0
- package/runtime/engine/index.mjs +265 -0
- package/runtime/engine/local-postgres-support.mjs +69 -0
- package/runtime/engine/local.mjs +3275 -0
- package/runtime/engine/pglite-directory-lock.mjs +8 -0
- package/runtime/engine/rag.mjs +11 -0
- package/runtime/engine/search.mjs +18 -0
- package/runtime/framework-migrations/foundation-bootstrap/rag.sql +115 -0
- package/runtime/framework-migrations/foundation-bootstrap/workflow.sql +194 -0
- package/runtime/framework-migrations/journal-bootstrap/migration.sql +26 -0
- package/runtime/framework-migrations/manifest.json +56 -0
- package/runtime/framework-migrations/rag/20261006111509_mushy_warhawk/migration.sql +121 -0
- package/runtime/framework-migrations/rag/20261013234621_rag_v2_lifecycle_markers/migration.sql +6 -0
- package/runtime/framework-migrations/workflow/20261006111508_perpetual_star_brand/migration.sql +31 -0
- package/runtime/runtime-metadata.json +27 -0
- package/runtime/tooling.mjs +10399 -8951
- package/scripts/bundle-runtime-config.mjs +23 -0
- package/scripts/bundle-runtime.mjs +100 -0
- package/scripts/bundle-runtime.test.mjs +33 -0
- package/scripts/bundle-shared.mjs +3 -0
- package/scripts/copy-dashboard.mjs +16 -0
- package/scripts/pre-publish-check.mjs +23 -11
- package/templateFeature/sso/sso-auth-callback.tsx +37 -5
- package/templateFeature/tools/manifest.json +2 -1
- package/templateFeature/tools/tools.ts +3 -3
- package/runtime/server.mjs +0 -14389
- package/scripts/bundle-server.mjs +0 -223
- package/server/config.js +0 -1
- package/server/index.js +0 -1
- package/server/package.json +0 -6
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadRuntimeFrameworkMigrationBundle
|
|
3
|
+
} from "./chunk-PZFMKFHO.mjs";
|
|
4
|
+
import {
|
|
5
|
+
runtimeDatabaseSetupError
|
|
6
|
+
} from "./chunk-SVJCOUI3.mjs";
|
|
7
|
+
|
|
8
|
+
// ../runtime/dist/workflow/terminal-guard-schema.js
|
|
9
|
+
import { isDeepStrictEqual } from "node:util";
|
|
10
|
+
|
|
11
|
+
// ../runtime/dist/workflow/terminal-guard-contract.js
|
|
12
|
+
var workflowTerminalGuardTable = "_gencow_workflow_terminal_guard";
|
|
13
|
+
var workflowTerminalGuardTrigger = "_gencow_workflow_terminal_guard_check";
|
|
14
|
+
var workflowTerminalGuardBody = `DECLARE erased integer;
|
|
15
|
+
BEGIN
|
|
16
|
+
IF NEW.backend_pid <> pg_catalog.pg_backend_pid() OR NEW.transaction_id <> pg_catalog.pg_current_xact_id() THEN
|
|
17
|
+
RAISE EXCEPTION 'Workflow terminal fence identity unavailable' USING ERRCODE='GCW02';
|
|
18
|
+
END IF;
|
|
19
|
+
IF pg_catalog.lower(pg_catalog.btrim(pg_catalog.current_query())) NOT IN ('commit','commit;') THEN
|
|
20
|
+
RAISE EXCEPTION 'Workflow terminal fence boundary unavailable' USING ERRCODE='GCW02';
|
|
21
|
+
END IF;
|
|
22
|
+
IF pg_catalog.clock_timestamp() >= NEW.original_deadline THEN
|
|
23
|
+
RAISE EXCEPTION 'Workflow completion lease expired' USING ERRCODE='GCW01';
|
|
24
|
+
END IF;
|
|
25
|
+
DELETE FROM public._gencow_workflow_terminal_guard WHERE id=NEW.id;
|
|
26
|
+
GET DIAGNOSTICS erased = ROW_COUNT;
|
|
27
|
+
IF erased <> 1 THEN
|
|
28
|
+
RAISE EXCEPTION 'Workflow terminal fence cleanup unavailable' USING ERRCODE='GCW02';
|
|
29
|
+
END IF;
|
|
30
|
+
RETURN NEW;
|
|
31
|
+
END`;
|
|
32
|
+
var workflowTerminalGuardStatements = [
|
|
33
|
+
`CREATE TABLE public.${workflowTerminalGuardTable} (id uuid PRIMARY KEY,backend_pid integer NOT NULL,
|
|
34
|
+
transaction_id xid8 NOT NULL,original_deadline timestamptz NOT NULL)`,
|
|
35
|
+
`CREATE FUNCTION public.${workflowTerminalGuardTrigger}() RETURNS trigger LANGUAGE plpgsql
|
|
36
|
+
SECURITY INVOKER SET search_path=pg_catalog AS $guard$${workflowTerminalGuardBody}$guard$`,
|
|
37
|
+
`CREATE CONSTRAINT TRIGGER ${workflowTerminalGuardTrigger} AFTER INSERT ON public.${workflowTerminalGuardTable}
|
|
38
|
+
DEFERRABLE INITIALLY DEFERRED FOR EACH ROW EXECUTE FUNCTION public.${workflowTerminalGuardTrigger}()`,
|
|
39
|
+
`ALTER TABLE public.${workflowTerminalGuardTable} ENABLE ALWAYS TRIGGER ${workflowTerminalGuardTrigger}`
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
// ../runtime/dist/workflow/terminal-guard-schema.js
|
|
43
|
+
var table = {
|
|
44
|
+
kind: "table",
|
|
45
|
+
rowSecurity: false,
|
|
46
|
+
forceRowSecurity: false,
|
|
47
|
+
schema: "public",
|
|
48
|
+
name: workflowTerminalGuardTable,
|
|
49
|
+
columns: [
|
|
50
|
+
{ name: "id", type: "uuid", nullable: false, defaultValue: null },
|
|
51
|
+
{ name: "backend_pid", type: "int4", nullable: false, defaultValue: null },
|
|
52
|
+
{ name: "transaction_id", type: "xid8", nullable: false, defaultValue: null },
|
|
53
|
+
{ name: "original_deadline", type: "timestamptz", nullable: false, defaultValue: null }
|
|
54
|
+
],
|
|
55
|
+
constraints: [
|
|
56
|
+
{ kind: "primary", columns: ["id"], creationIndexName: "_gencow_workflow_terminal_guard_pkey" }
|
|
57
|
+
],
|
|
58
|
+
paths: ["maintenance"],
|
|
59
|
+
privileges: ["SELECT", "INSERT", "DELETE"]
|
|
60
|
+
};
|
|
61
|
+
var routine = {
|
|
62
|
+
kind: "function",
|
|
63
|
+
schema: "public",
|
|
64
|
+
name: workflowTerminalGuardTrigger,
|
|
65
|
+
body: workflowTerminalGuardBody,
|
|
66
|
+
language: "plpgsql",
|
|
67
|
+
returnType: "trigger",
|
|
68
|
+
securityDefiner: false,
|
|
69
|
+
configuration: ["search_path=pg_catalog"]
|
|
70
|
+
};
|
|
71
|
+
var trigger = {
|
|
72
|
+
kind: "trigger",
|
|
73
|
+
schema: "public",
|
|
74
|
+
name: workflowTerminalGuardTrigger,
|
|
75
|
+
table: workflowTerminalGuardTable,
|
|
76
|
+
functionSchema: "public",
|
|
77
|
+
functionName: workflowTerminalGuardTrigger,
|
|
78
|
+
type: 5,
|
|
79
|
+
deferrable: true,
|
|
80
|
+
initiallyDeferred: true,
|
|
81
|
+
enabled: "A",
|
|
82
|
+
argumentCount: 0,
|
|
83
|
+
predicate: null
|
|
84
|
+
};
|
|
85
|
+
function guardStatements() {
|
|
86
|
+
const migration = loadRuntimeFrameworkMigrationBundle("workflow").migrations[0];
|
|
87
|
+
if (!migration || migration.statements.length !== 4)
|
|
88
|
+
throw runtimeDatabaseSetupError("RUNTIME_DATABASE_SETUP_COMPONENT_INVALID");
|
|
89
|
+
return migration.statements;
|
|
90
|
+
}
|
|
91
|
+
var workflowTerminalGuardSchema = {
|
|
92
|
+
id: "workflow-terminal-guard",
|
|
93
|
+
contractVersion: 1,
|
|
94
|
+
dependsOn: [],
|
|
95
|
+
objects: [table, routine, trigger],
|
|
96
|
+
steps: [
|
|
97
|
+
{
|
|
98
|
+
id: "create-workflow-terminal-guard",
|
|
99
|
+
get statements() {
|
|
100
|
+
return guardStatements().slice(0, 1);
|
|
101
|
+
},
|
|
102
|
+
affectedObjects: [table],
|
|
103
|
+
grants: []
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
id: "create-workflow-terminal-guard-function",
|
|
107
|
+
get statements() {
|
|
108
|
+
return guardStatements().slice(1, 2);
|
|
109
|
+
},
|
|
110
|
+
affectedObjects: [routine],
|
|
111
|
+
grants: []
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
id: "create-workflow-terminal-guard-trigger",
|
|
115
|
+
get statements() {
|
|
116
|
+
return guardStatements().slice(2);
|
|
117
|
+
},
|
|
118
|
+
affectedObjects: [trigger],
|
|
119
|
+
grants: []
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
id: "access-workflow-terminal-guard",
|
|
123
|
+
statements: [],
|
|
124
|
+
affectedObjects: [table],
|
|
125
|
+
grants: [{ object: table, paths: table.paths, privileges: table.privileges }]
|
|
126
|
+
}
|
|
127
|
+
],
|
|
128
|
+
inspect(snapshot) {
|
|
129
|
+
const invalid = () => ({ state: "incompatible", reason: "shape-incompatible" });
|
|
130
|
+
const selected = [];
|
|
131
|
+
const relation = snapshot.relations.find((row) => row.schema === table.schema && row.name === table.name);
|
|
132
|
+
if (!relation) {
|
|
133
|
+
if (snapshot.relations.some((row) => row.schema === table.schema && row.name === table.constraints[0].creationIndexName))
|
|
134
|
+
return invalid();
|
|
135
|
+
selected.push("create-workflow-terminal-guard");
|
|
136
|
+
} else {
|
|
137
|
+
if (relation.kind !== "r" || relation.rowSecurity !== false || relation.forceRowSecurity !== false)
|
|
138
|
+
return invalid();
|
|
139
|
+
const columns = snapshot.columns.filter((row) => row.schema === table.schema && row.table === table.name);
|
|
140
|
+
if (columns.some((actual) => !table.columns.some((expected) => expected.name === actual.name) && !actual.nullable && actual.defaultValue === null && !actual.identity && !actual.generated) || table.columns.some((expected) => !columns.some((actual) => actual.name === expected.name && actual.type === expected.type && actual.nullable === expected.nullable && actual.defaultValue === null && !actual.identity && !actual.generated)))
|
|
141
|
+
return invalid();
|
|
142
|
+
const constraints = snapshot.constraints.filter((row) => row.schema === table.schema && row.table === table.name);
|
|
143
|
+
if (!constraints.some((row) => row.kind === "primary" && row.validated && !row.deferrable && isDeepStrictEqual(row.columns, ["id"])))
|
|
144
|
+
return invalid();
|
|
145
|
+
if (constraints.some((row) => row.kind !== "primary" && !(row.kind === "trigger" && row.name === trigger.name)))
|
|
146
|
+
return invalid();
|
|
147
|
+
if (snapshot.indexes.some((row) => row.schema === table.schema && row.table === table.name && row.unique && !row.constraintOwned && !row.keys.includes("id")))
|
|
148
|
+
return invalid();
|
|
149
|
+
}
|
|
150
|
+
const routines = (snapshot.routines ?? []).filter((row) => row.schema === routine.schema && row.name === routine.name);
|
|
151
|
+
if (!routines.length)
|
|
152
|
+
selected.push("create-workflow-terminal-guard-function");
|
|
153
|
+
else {
|
|
154
|
+
const { kind, argumentCount, volatility, ...actual } = routines[0];
|
|
155
|
+
const { kind: _, ...expected } = routine;
|
|
156
|
+
if (routines.length !== 1 || kind !== "f" || argumentCount !== 0 || volatility !== "v" || !isDeepStrictEqual(actual, expected))
|
|
157
|
+
return invalid();
|
|
158
|
+
}
|
|
159
|
+
const triggers = (snapshot.triggers ?? []).filter((row) => row.schema === trigger.schema && row.table === trigger.table);
|
|
160
|
+
if (!triggers.length)
|
|
161
|
+
selected.push("create-workflow-terminal-guard-trigger");
|
|
162
|
+
else {
|
|
163
|
+
const { internal, ...actual } = triggers[0];
|
|
164
|
+
const { kind: _, ...expected } = trigger;
|
|
165
|
+
if (triggers.length !== 1 || internal || !isDeepStrictEqual(actual, expected))
|
|
166
|
+
return invalid();
|
|
167
|
+
}
|
|
168
|
+
if (!snapshot.access.some((row) => row.path === "maintenance" && row.kind === "table" && row.schema === table.schema && row.name === table.name && table.privileges.every((privilege) => row.privileges.includes(privilege))))
|
|
169
|
+
selected.push("access-workflow-terminal-guard");
|
|
170
|
+
return selected.length ? { state: "compatible-change", stepIds: selected } : { state: "ready" };
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
workflowTerminalGuardSchema
|
|
176
|
+
};
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import {
|
|
2
|
+
captureDatabaseSecurityPolicy,
|
|
3
|
+
verifyCapturedDatabaseSecurityPolicy
|
|
4
|
+
} from "./chunk-ITH2NEKM.mjs";
|
|
5
|
+
import {
|
|
6
|
+
RuntimeDiagnosticError
|
|
7
|
+
} from "./chunk-AEBW7XZJ.mjs";
|
|
8
|
+
|
|
9
|
+
// ../runtime/dist/database-setup/security-policy.js
|
|
10
|
+
import { randomUUID } from "node:crypto";
|
|
11
|
+
function invalidSelection(reason) {
|
|
12
|
+
throw new RuntimeDiagnosticError({
|
|
13
|
+
code: "RUNTIME_DATABASE_SECURITY_POLICY_INVALID",
|
|
14
|
+
stage: "startup",
|
|
15
|
+
servingStarted: false,
|
|
16
|
+
dataImpact: "none",
|
|
17
|
+
capability: "database",
|
|
18
|
+
retryable: false,
|
|
19
|
+
retryPrecondition: "Select a supported trusted local database policy whose definition matches the installed Runtime and CLI before restarting.",
|
|
20
|
+
nextAction: "Use a matching Runtime/CLI release and select `local-development@1` or `local-strict@1` in trusted local bootstrap configuration. Preserve application data and applied migration history.",
|
|
21
|
+
correlationId: randomUUID(),
|
|
22
|
+
databaseSecurityPolicyFailure: reason
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function captureTrustedLocalDatabaseSecurityPolicy(selection) {
|
|
26
|
+
let result;
|
|
27
|
+
if (selection === void 0)
|
|
28
|
+
result = captureDatabaseSecurityPolicy();
|
|
29
|
+
else {
|
|
30
|
+
const digest = typeof selection === "object" && selection !== null ? Object.getOwnPropertyDescriptor(selection, "definitionDigest") : void 0;
|
|
31
|
+
result = digest && "value" in digest ? verifyCapturedDatabaseSecurityPolicy(selection) : captureDatabaseSecurityPolicy(selection);
|
|
32
|
+
}
|
|
33
|
+
if (!result.ok)
|
|
34
|
+
invalidSelection(result.reason);
|
|
35
|
+
return result.policy;
|
|
36
|
+
}
|
|
37
|
+
function verifyTrustedLocalDatabaseSecurityPolicy(candidate) {
|
|
38
|
+
const result = verifyCapturedDatabaseSecurityPolicy(candidate);
|
|
39
|
+
if (!result.ok)
|
|
40
|
+
invalidSelection(result.reason);
|
|
41
|
+
return result.policy;
|
|
42
|
+
}
|
|
43
|
+
function assertTrustedLocalDatabaseSecurityPolicyMatches(candidate, expected) {
|
|
44
|
+
const actual = verifyTrustedLocalDatabaseSecurityPolicy(candidate);
|
|
45
|
+
const capturedExpected = verifyTrustedLocalDatabaseSecurityPolicy(expected);
|
|
46
|
+
if (actual.id !== capturedExpected.id || actual.version !== capturedExpected.version || actual.definitionDigest !== capturedExpected.definitionDigest)
|
|
47
|
+
invalidSelection("definition-digest-mismatch");
|
|
48
|
+
return actual;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ../runtime/dist/database-setup/local-security-warning.js
|
|
52
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
53
|
+
function withRuntimeLocalDatabaseWarningOutput(sink, logger) {
|
|
54
|
+
try {
|
|
55
|
+
sink.bindOutput?.(logger);
|
|
56
|
+
} catch {
|
|
57
|
+
}
|
|
58
|
+
let legacyRenderCalled = false;
|
|
59
|
+
const render = (output) => {
|
|
60
|
+
try {
|
|
61
|
+
if (!sink.finish) {
|
|
62
|
+
if (legacyRenderCalled || !sink.snapshot())
|
|
63
|
+
return;
|
|
64
|
+
legacyRenderCalled = true;
|
|
65
|
+
}
|
|
66
|
+
sink.render(output);
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const finish = (output) => {
|
|
71
|
+
try {
|
|
72
|
+
if (sink.finish)
|
|
73
|
+
sink.finish(output);
|
|
74
|
+
else
|
|
75
|
+
render(output);
|
|
76
|
+
} catch {
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
return Object.freeze({
|
|
80
|
+
observe: (reasons) => sink.observe(reasons),
|
|
81
|
+
observePolicyAssessment: (evaluation) => sink.observePolicyAssessment?.(evaluation),
|
|
82
|
+
observePolicySummary: (summary) => sink.observePolicySummary?.(summary),
|
|
83
|
+
snapshot: () => sink.snapshot(),
|
|
84
|
+
render,
|
|
85
|
+
finish,
|
|
86
|
+
beforeMutation: () => render(logger)
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function policyOutcomeNote(outcome) {
|
|
90
|
+
if (outcome === "allow" || outcome === "warn")
|
|
91
|
+
return " The current database security assessment allows this operation to proceed; later startup checks may still fail.";
|
|
92
|
+
if (outcome === "unknown")
|
|
93
|
+
return " This observation does not establish whether the overall Runtime startup will succeed.";
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
function nextAction(reasons, outcome) {
|
|
97
|
+
if (reasons.has("security-observation-unavailable")) {
|
|
98
|
+
const observed = reasons.size > 1 ? " Observed credentials also share serving or schema privileges." : "";
|
|
99
|
+
return "Local database security metadata could not be inspected; PostgreSQL RLS isolation is not fully assessed." + observed + " Check local database configuration and security-metadata visibility before relying on RLS isolation; restart after visibility is restored for a fresh assessment. Required connection and identity were verified." + policyOutcomeNote(outcome);
|
|
100
|
+
}
|
|
101
|
+
return "Local credentials share serving or schema privileges; PostgreSQL RLS isolation may be weaker. For stronger isolation, configure DATABASE_URL, GENCOW_UNSAFE_DATABASE_URL and GENCOW_SETUP_DATABASE_URL with separate suitable roles." + policyOutcomeNote(outcome);
|
|
102
|
+
}
|
|
103
|
+
function createRuntimeLocalDatabaseWarningSink() {
|
|
104
|
+
const reasons = /* @__PURE__ */ new Set();
|
|
105
|
+
let policy;
|
|
106
|
+
const assessments = /* @__PURE__ */ new Map();
|
|
107
|
+
const warningFindingIds = /* @__PURE__ */ new Set();
|
|
108
|
+
const correlationId = randomUUID2();
|
|
109
|
+
let policyNextAction;
|
|
110
|
+
let policyOutcome = "unknown";
|
|
111
|
+
let rendered = false;
|
|
112
|
+
let output;
|
|
113
|
+
let lastPublishedSnapshot;
|
|
114
|
+
let summaryEmitted = false;
|
|
115
|
+
const logAttributes = (warning, overrides = {}) => {
|
|
116
|
+
const attributes = {
|
|
117
|
+
code: warning.code,
|
|
118
|
+
severity: warning.severity,
|
|
119
|
+
reasons: warning.reasons,
|
|
120
|
+
dataImpact: warning.dataImpact,
|
|
121
|
+
servingImpact: warning.servingImpact,
|
|
122
|
+
nextAction: warning.nextAction,
|
|
123
|
+
correlationId: warning.correlationId
|
|
124
|
+
};
|
|
125
|
+
if (warning.databaseSecurityPolicy)
|
|
126
|
+
attributes.databaseSecurityPolicy = `${warning.databaseSecurityPolicy.id}@${warning.databaseSecurityPolicy.version}`;
|
|
127
|
+
if (warning.databaseSecurityAssessments)
|
|
128
|
+
attributes.databaseSecurityAssessments = Object.freeze(warning.databaseSecurityAssessments.map(({ stage, complete, findingIds }) => `${stage}:${complete ? "complete" : "incomplete"}:${findingIds.join(",")}`));
|
|
129
|
+
if (warning.databaseSecurityFindingIds)
|
|
130
|
+
attributes.databaseSecurityFindingIds = warning.databaseSecurityFindingIds;
|
|
131
|
+
return Object.freeze({ ...attributes, ...overrides });
|
|
132
|
+
};
|
|
133
|
+
const snapshot = () => reasons.size === 0 && warningFindingIds.size === 0 ? void 0 : Object.freeze({
|
|
134
|
+
code: "RUNTIME_LOCAL_DATABASE_SECURITY_WARNING",
|
|
135
|
+
severity: "warning",
|
|
136
|
+
reasons: Object.freeze([...reasons].sort()),
|
|
137
|
+
dataImpact: "none",
|
|
138
|
+
servingImpact: "unchanged",
|
|
139
|
+
nextAction: policyOutcome === "reject" ? policyNextAction ?? "Correct the observed local database role and ownership posture with its trusted database owner, then restart. Preserve application data and applied migration history." : reasons.size > 0 ? nextAction(reasons, policyOutcome) : policyNextAction ? policyNextAction + policyOutcomeNote(policyOutcome) : nextAction(reasons, policyOutcome),
|
|
140
|
+
correlationId,
|
|
141
|
+
...policy ? { databaseSecurityPolicy: policy } : {},
|
|
142
|
+
...assessments.size ? {
|
|
143
|
+
databaseSecurityAssessments: Object.freeze([...assessments.values()].sort((left, right) => left.stage.localeCompare(right.stage)))
|
|
144
|
+
} : {},
|
|
145
|
+
...warningFindingIds.size ? { databaseSecurityFindingIds: Object.freeze([...warningFindingIds].sort()) } : {}
|
|
146
|
+
});
|
|
147
|
+
const render = (logger) => {
|
|
148
|
+
const warning = snapshot();
|
|
149
|
+
if (!warning || rendered)
|
|
150
|
+
return;
|
|
151
|
+
try {
|
|
152
|
+
rendered = true;
|
|
153
|
+
lastPublishedSnapshot = warning;
|
|
154
|
+
logger.warn(warning.code, logAttributes(warning));
|
|
155
|
+
} catch {
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
const finish = (logger) => {
|
|
159
|
+
const warning = snapshot();
|
|
160
|
+
if (!warning)
|
|
161
|
+
return;
|
|
162
|
+
if (!rendered) {
|
|
163
|
+
render(logger);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const previous = lastPublishedSnapshot;
|
|
167
|
+
if (!previous || JSON.stringify(previous) === JSON.stringify(warning))
|
|
168
|
+
return;
|
|
169
|
+
if (summaryEmitted) {
|
|
170
|
+
lastPublishedSnapshot = warning;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
try {
|
|
174
|
+
const previousStages = new Map((previous.databaseSecurityAssessments ?? []).map((assessment) => [assessment.stage, assessment]));
|
|
175
|
+
const currentStages = new Map((warning.databaseSecurityAssessments ?? []).map((assessment) => [assessment.stage, assessment]));
|
|
176
|
+
const databaseSecurityChangedStages = [.../* @__PURE__ */ new Set([...previousStages.keys(), ...currentStages.keys()])].filter((stage) => JSON.stringify(previousStages.get(stage)) !== JSON.stringify(currentStages.get(stage))).sort();
|
|
177
|
+
const previousFindings = new Set(previous.databaseSecurityFindingIds ?? []);
|
|
178
|
+
const previousReasons = new Set(previous.reasons);
|
|
179
|
+
summaryEmitted = true;
|
|
180
|
+
lastPublishedSnapshot = warning;
|
|
181
|
+
logger.info("runtime.boot.summary", logAttributes(warning, {
|
|
182
|
+
databaseSecuritySnapshotChanged: true,
|
|
183
|
+
databaseSecurityChangedStages: Object.freeze(databaseSecurityChangedStages),
|
|
184
|
+
databaseSecurityNewFindingIds: Object.freeze((warning.databaseSecurityFindingIds ?? []).filter((id) => !previousFindings.has(id))),
|
|
185
|
+
databaseSecurityNewReasons: Object.freeze(warning.reasons.filter((reason) => !previousReasons.has(reason))),
|
|
186
|
+
databaseSecurityPolicyChanged: JSON.stringify(previous.databaseSecurityPolicy) !== JSON.stringify(warning.databaseSecurityPolicy)
|
|
187
|
+
}));
|
|
188
|
+
} catch {
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
return Object.freeze({
|
|
192
|
+
observe(observations) {
|
|
193
|
+
for (const reason of observations)
|
|
194
|
+
reasons.add(reason);
|
|
195
|
+
},
|
|
196
|
+
observePolicyAssessment(evaluation) {
|
|
197
|
+
if (!evaluation.ok)
|
|
198
|
+
return;
|
|
199
|
+
const findingIds = Object.freeze([...new Set(evaluation.findings.map(({ id }) => id))].sort());
|
|
200
|
+
const outcome = evaluation.denials.length > 0 ? "reject" : evaluation.warnings.length > 0 ? "warn" : "allow";
|
|
201
|
+
if (outcome === "reject") {
|
|
202
|
+
policyOutcome = "reject";
|
|
203
|
+
policyNextAction = evaluation.denials.find(({ id }) => id === "security-evidence-unavailable")?.nextAction ?? evaluation.denials[0]?.nextAction ?? "Correct the observed local database role and ownership posture with its trusted database owner, then restart. Preserve application data and applied migration history.";
|
|
204
|
+
} else if (policyOutcome !== "reject") {
|
|
205
|
+
if (outcome === "warn" || policyOutcome === "unknown")
|
|
206
|
+
policyOutcome = outcome;
|
|
207
|
+
if (evaluation.warnings.length > 0)
|
|
208
|
+
policyNextAction ??= evaluation.warnings[0].nextAction;
|
|
209
|
+
}
|
|
210
|
+
this.observePolicySummary?.({
|
|
211
|
+
policy: Object.freeze({ id: evaluation.policy.id, version: evaluation.policy.version }),
|
|
212
|
+
stage: evaluation.stage,
|
|
213
|
+
complete: evaluation.complete,
|
|
214
|
+
findingIds
|
|
215
|
+
});
|
|
216
|
+
},
|
|
217
|
+
observePolicySummary(summary) {
|
|
218
|
+
if (!summary || !summary.policy || summary.policy.id !== "local-development" && summary.policy.id !== "local-strict" || summary.policy.version !== 1 || !["resource-admission", "cli-prewrite", "preparation", "prewrite", "precommit", "readback"].includes(summary.stage) || typeof summary.complete !== "boolean" || !Array.isArray(summary.findingIds) || summary.findingIds.length > 13 || summary.findingIds.some((id) => ![
|
|
219
|
+
"shared-operational-principal",
|
|
220
|
+
"setup-shares-operational-principal",
|
|
221
|
+
"application-owns-nonsystem-table",
|
|
222
|
+
"application-reaches-rls-owner",
|
|
223
|
+
"application-privileged",
|
|
224
|
+
"serving-reaches-selected-rag-owner",
|
|
225
|
+
"application-reaches-framework-journal-owner",
|
|
226
|
+
"application-can-mutate-framework-journal",
|
|
227
|
+
"application-can-create-schema",
|
|
228
|
+
"maintenance-bypasses-rls",
|
|
229
|
+
"maintenance-unauthorized-elevation",
|
|
230
|
+
"setup-unauthorized-elevation",
|
|
231
|
+
"security-evidence-unavailable"
|
|
232
|
+
].includes(id)))
|
|
233
|
+
return;
|
|
234
|
+
policy ??= Object.freeze({ id: summary.policy.id, version: 1 });
|
|
235
|
+
const findingIds = Object.freeze([...new Set(summary.findingIds)].sort());
|
|
236
|
+
if (findingIds.length > 0) {
|
|
237
|
+
policyNextAction ??= "Review the local PostgreSQL role and ownership findings with its trusted database owner, correct the observed posture, and restart for a fresh assessment. Preserve application data and applied migration history.";
|
|
238
|
+
}
|
|
239
|
+
assessments.set(summary.stage, Object.freeze({ stage: summary.stage, complete: summary.complete, findingIds }));
|
|
240
|
+
for (const id of findingIds)
|
|
241
|
+
warningFindingIds.add(id);
|
|
242
|
+
},
|
|
243
|
+
snapshot,
|
|
244
|
+
render,
|
|
245
|
+
finish,
|
|
246
|
+
bindOutput(logger) {
|
|
247
|
+
output = logger;
|
|
248
|
+
},
|
|
249
|
+
beforeMutation() {
|
|
250
|
+
if (output)
|
|
251
|
+
render(output);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export {
|
|
257
|
+
captureTrustedLocalDatabaseSecurityPolicy,
|
|
258
|
+
verifyTrustedLocalDatabaseSecurityPolicy,
|
|
259
|
+
assertTrustedLocalDatabaseSecurityPolicyMatches,
|
|
260
|
+
withRuntimeLocalDatabaseWarningOutput,
|
|
261
|
+
createRuntimeLocalDatabaseWarningSink
|
|
262
|
+
};
|