@everystack/server 0.4.32 → 0.4.33

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/CHANGELOG.md CHANGED
@@ -4,6 +4,17 @@ All notable changes to `@everystack/server` are documented here.
4
4
 
5
5
  Format based on [Keep a Changelog](https://keepachangelog.com/).
6
6
 
7
+ ## [0.4.33] - 2026-09-24
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ - a declared owner needs USAGE on its schema; db:apply refuses without it, db:provision (server 0.4.33) grants it
12
+
13
+ ### Fixed
14
+
15
+ - name USAGE with CREATE for a missing schema; review follow-ups
16
+ - reject offset-less datetime strings (ambiguous: server-local, not UTC)
17
+
7
18
  ## [0.4.32] - 2026-09-21
8
19
 
9
20
  ### Fixed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@everystack/server",
3
- "version": "0.4.32",
3
+ "version": "0.4.33",
4
4
  "description": "Server runtime primitives for Lambda — event adapters, routing, SSR, image processing",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Scalable Technology, Inc. <licensing@scalable.technology>",
@@ -187,8 +187,8 @@
187
187
  "sst": "4.13.1",
188
188
  "ts-jest": "29.4.9",
189
189
  "typescript": "5.9.3",
190
- "@everystack/auth": "0.4.5",
191
- "@everystack/cli": "0.4.87"
190
+ "@everystack/auth": "0.4.6",
191
+ "@everystack/cli": "0.4.93"
192
192
  },
193
193
  "scripts": {
194
194
  "test": "jest",
@@ -11,6 +11,9 @@
11
11
  * explicit SET ROLE, never inheriting the owner's privileges ambiently.
12
12
  * 2. `GRANT CREATE ON SCHEMA <schema> TO <owner>` — so the CREATE, which runs AS the owner,
13
13
  * can place the object.
14
+ * 3. `GRANT USAGE ON SCHEMA <schema> TO <owner>` — so the owner's GRANT/REVOKE on that object,
15
+ * which name it as `schema.object`, can resolve it. CREATE alone let the CREATE through and
16
+ * then failed the object's own `REVOKE ALL … FROM PUBLIC` with `permission denied for schema`.
14
17
  *
15
18
  * These are privileged, idempotent SETUP — the same category as the role chain — so they belong
16
19
  * in db:provision, not in the least-privilege reconcile lane (which structurally cannot run them).
@@ -75,6 +78,8 @@ export interface OwnerFactRow {
75
78
  canSetRole: boolean;
76
79
  /** The owner already holds `CREATE` on the schema — no create grant needed. */
77
80
  ownerCanCreate: boolean;
81
+ /** The owner already holds `USAGE` on the schema — no usage grant needed. */
82
+ ownerCanUse: boolean;
78
83
  }
79
84
 
80
85
  /**
@@ -88,6 +93,8 @@ export interface GranterCapabilityRow {
88
93
  schema: string;
89
94
  canGrantMembership: boolean;
90
95
  canGrantCreate: boolean;
96
+ /** Can `GRANT USAGE ON SCHEMA` — owns the schema, holds USAGE WITH GRANT OPTION, or is a superuser. */
97
+ canGrantUsage: boolean;
91
98
  }
92
99
 
93
100
  /** Which connection runs a unit's statements. */
@@ -175,7 +182,8 @@ function assertIdent(name: string, what: string): void {
175
182
 
176
183
  /**
177
184
  * The connection-independent probe: for each (owner, schema), does the owner exist, does the
178
- * schema exist, can `operator` already SET ROLE the owner, and does the owner already hold CREATE.
185
+ * schema exist, can `operator` already SET ROLE the owner, and does the owner already hold CREATE
186
+ * and USAGE.
179
187
  * `has_schema_privilege` throws on an absent schema, so the schema is LEFT JOINed and the privilege
180
188
  * is evaluated only when the schema is really there. Run once, on either connection.
181
189
  */
@@ -195,7 +203,9 @@ SELECT
195
203
  (n.oid IS NOT NULL) AS schema_exists,
196
204
  CASE WHEN r.oid IS NULL THEN false ELSE pg_has_role('${operator}', r.oid, 'SET') END AS can_set_role,
197
205
  CASE WHEN r.oid IS NULL OR n.oid IS NULL THEN false
198
- ELSE has_schema_privilege(r.oid, n.oid, 'CREATE') END AS owner_can_create
206
+ ELSE has_schema_privilege(r.oid, n.oid, 'CREATE') END AS owner_can_create,
207
+ CASE WHEN r.oid IS NULL OR n.oid IS NULL THEN false
208
+ ELSE has_schema_privilege(r.oid, n.oid, 'USAGE') END AS owner_can_use
199
209
  FROM declared d
200
210
  LEFT JOIN pg_roles r ON r.rolname = d.owner_name
201
211
  LEFT JOIN pg_namespace n ON n.nspname = d.schema_name
@@ -207,7 +217,8 @@ ORDER BY d.owner_name, d.schema_name
207
217
  * The connection-DEPENDENT probe: run on a connection to learn what CURRENT_USER can grant.
208
218
  * Can it `GRANT <owner> TO <operator>` — it holds ADMIN OPTION on the owner, directly or through a
209
219
  * group. Can it `GRANT CREATE ON SCHEMA <schema>` — it owns the schema or holds CREATE WITH GRANT
210
- * OPTION. A REAL superuser can do both unconditionally. Run on the operator's connection and, when
220
+ * OPTION, and `GRANT USAGE ON SCHEMA` — it owns the schema or holds USAGE WITH GRANT OPTION. A REAL
221
+ * superuser can do all three unconditionally. Run on the operator's connection and, when
211
222
  * present, on the master's; the router merges the two.
212
223
  *
213
224
  * MEMBERSHIP IN `rds_superuser` IS NOT SUPERUSER, and this probe no longer pretends it is. RDS's
@@ -238,7 +249,9 @@ SELECT
238
249
  d.schema_name AS schema,
239
250
  COALESCE(me.is_super OR pg_has_role(me.oid, r.oid, 'MEMBER WITH ADMIN OPTION'), false) AS can_grant_membership,
240
251
  COALESCE(me.is_super OR n.nspowner = me.oid
241
- OR has_schema_privilege(me.oid, n.oid, 'CREATE WITH GRANT OPTION'), false) AS can_grant_create
252
+ OR has_schema_privilege(me.oid, n.oid, 'CREATE WITH GRANT OPTION'), false) AS can_grant_create,
253
+ COALESCE(me.is_super OR n.nspowner = me.oid
254
+ OR has_schema_privilege(me.oid, n.oid, 'USAGE WITH GRANT OPTION'), false) AS can_grant_usage
242
255
  FROM declared d
243
256
  CROSS JOIN me
244
257
  LEFT JOIN pg_roles r ON r.rolname = d.owner_name
@@ -250,7 +263,8 @@ ORDER BY d.owner_name, d.schema_name
250
263
  const keyOf = (owner: string, schema: string) => `${owner}\u0000${schema}`;
251
264
 
252
265
  /**
253
- * Route the two grants each (owner, schema) may need onto the connection that can run them.
266
+ * Route the three grants each (owner, schema) may need — membership, CREATE, USAGE — onto the
267
+ * connection that can run them.
254
268
  *
255
269
  * `operator` is the least-privilege role (`migrator`). `masterCaps` is null when no master
256
270
  * connection is available — then anything the operator cannot do is a refusal, never an
@@ -305,6 +319,16 @@ export function planOwnerEnactment(
305
319
  `Run as the schema owner: ${stmt};`,
306
320
  );
307
321
  }
322
+ // 3. Usage: the owner's GRANT/REVOKE on the object name `schema.object` — resolving it needs USAGE.
323
+ if (f.schemaExists && !f.ownerCanUse) {
324
+ const stmt = `GRANT USAGE ON SCHEMA ${f.schema} TO ${f.owner}`;
325
+ if (op?.canGrantUsage) addUnit(b, subject, 'operator', [stmt]);
326
+ else if (master?.canGrantUsage) addUnit(b, subject, 'master', [stmt]);
327
+ else plan.refusals.push(
328
+ `cannot GRANT USAGE ON SCHEMA ${f.schema} TO ${f.owner}: neither connection owns the schema or holds USAGE WITH GRANT OPTION. ` +
329
+ `Run as the schema owner: ${stmt};`,
330
+ );
331
+ }
308
332
  // An absent schema is not enacted here — it is created by the reconcile builder, whose own
309
333
  // preflight then names the owner's missing CREATE. Enactment acts only on what exists.
310
334
  }
package/src/provision.ts CHANGED
@@ -606,6 +606,7 @@ function toFacts(rows: any[]): OwnerFactRow[] {
606
606
  schemaExists: truthy(r.schema_exists),
607
607
  canSetRole: truthy(r.can_set_role),
608
608
  ownerCanCreate: truthy(r.owner_can_create),
609
+ ownerCanUse: truthy(r.owner_can_use),
609
610
  }));
610
611
  }
611
612
 
@@ -615,6 +616,7 @@ function toCaps(rows: any[]): GranterCapabilityRow[] {
615
616
  schema: String(r.schema),
616
617
  canGrantMembership: truthy(r.can_grant_membership),
617
618
  canGrantCreate: truthy(r.can_grant_create),
619
+ canGrantUsage: truthy(r.can_grant_usage),
618
620
  }));
619
621
  }
620
622