@rebasepro/server-postgres 0.14.1 → 0.14.2-canary.g27a129e
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/{auth-users-columns-C-FDnL_e.js → auth-users-columns-JJ8ngvy5.js} +59 -17
- package/dist/auth-users-columns-JJ8ngvy5.js.map +1 -0
- package/dist/{backup-service-BH0Dzo_h.js → backup-service-czK-OAuG.js} +2 -2
- package/dist/{backup-service-BH0Dzo_h.js.map → backup-service-czK-OAuG.js.map} +1 -1
- package/dist/{ensure-collection-policies-DoHwhVf8.js → ensure-collection-policies-D5PtQLyR.js} +3 -3
- package/dist/{ensure-collection-policies-DoHwhVf8.js.map → ensure-collection-policies-D5PtQLyR.js.map} +1 -1
- package/dist/{ensure-collection-tables-DT2eq859.js → ensure-collection-tables-BHUjQ-z4.js} +3 -3
- package/dist/{ensure-collection-tables-DT2eq859.js.map → ensure-collection-tables-BHUjQ-z4.js.map} +1 -1
- package/dist/index.es.js +485 -19
- package/dist/index.es.js.map +1 -1
- package/dist/{rls-bootstrap-sql-69hYT8nr.js → rls-bootstrap-sql-B5Sajku6.js} +2 -2
- package/dist/{rls-bootstrap-sql-69hYT8nr.js.map → rls-bootstrap-sql-B5Sajku6.js.map} +1 -1
- package/dist/{rls-enforcement-gUNDfm7l.js → rls-enforcement-BDBfuTD4.js} +4 -3
- package/dist/rls-enforcement-BDBfuTD4.js.map +1 -0
- package/dist/services/FetchService.d.ts +22 -0
- package/dist/{src-DCdn3Val.js → src-BBFsDaeA.js} +60 -2
- package/dist/src-BBFsDaeA.js.map +1 -0
- package/dist/utils/drizzle-conditions.d.ts +168 -1
- package/dist/utils/pg-error-utils.d.ts +27 -0
- package/dist/{websocket-D2jXv0Ds.js → websocket-BVgDVO-V.js} +2 -2
- package/dist/{websocket-D2jXv0Ds.js.map → websocket-BVgDVO-V.js.map} +1 -1
- package/package.json +6 -6
- package/src/services/FetchService.ts +155 -15
- package/src/services/PersistService.ts +23 -2
- package/src/utils/drizzle-conditions.ts +594 -1
- package/src/utils/pg-error-utils.ts +49 -4
- package/dist/auth-users-columns-C-FDnL_e.js.map +0 -1
- package/dist/rls-enforcement-gUNDfm7l.js.map +0 -1
- package/dist/src-DCdn3Val.js.map +0 -1
|
@@ -178,6 +178,38 @@ export function isRoleSwitchingPermissionError(error: unknown): boolean {
|
|
|
178
178
|
return msg.includes("set role") || msg.includes("member of role");
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* Was this `42501` the *caller* being refused by a policy, rather than the
|
|
183
|
+
* server lacking a privilege?
|
|
184
|
+
*
|
|
185
|
+
* Both arrive as `insufficient_privilege`, and they are opposite kinds of
|
|
186
|
+
* problem. A row-level-security refusal is a working access-control system
|
|
187
|
+
* doing its job: the caller asked for something their policies do not permit,
|
|
188
|
+
* which is a 403 and nobody's bug. A missing `GRANT` is the deployment being
|
|
189
|
+
* wrong — the connection role cannot touch the table at all, no policy is
|
|
190
|
+
* involved, and nothing the caller changes about the request will help.
|
|
191
|
+
*
|
|
192
|
+
* Postgres distinguishes them in the message, so this does too:
|
|
193
|
+
*
|
|
194
|
+
* new row violates row-level security policy for table "notes" → the caller
|
|
195
|
+
* permission denied for table notes → the server
|
|
196
|
+
*
|
|
197
|
+
* Only writes reach this. A read that RLS excludes is not an error — the rows
|
|
198
|
+
* are filtered and the caller gets an empty page — so the erroring case is
|
|
199
|
+
* specifically an `INSERT`/`UPDATE` whose row fails a policy's `WITH CHECK`.
|
|
200
|
+
*
|
|
201
|
+
* Matched on the message because that is the only thing carrying the
|
|
202
|
+
* distinction; the SQLSTATE is identical either way. Narrow by design: anything
|
|
203
|
+
* not naming row-level security stays the server's problem, since reporting a
|
|
204
|
+
* genuine privilege misconfiguration as "forbidden" would send an operator
|
|
205
|
+
* hunting for a policy bug that does not exist.
|
|
206
|
+
*/
|
|
207
|
+
export function isRowLevelSecurityDenial(error: unknown): boolean {
|
|
208
|
+
const pgError = extractPgError(error);
|
|
209
|
+
if (!pgError || pgError.code !== "42501") return false;
|
|
210
|
+
return pgError.message.toLowerCase().includes("row-level security policy");
|
|
211
|
+
}
|
|
212
|
+
|
|
181
213
|
/**
|
|
182
214
|
* Translate a raw PostgreSQL error into a user-friendly message.
|
|
183
215
|
*
|
|
@@ -249,10 +281,23 @@ export function pgErrorToFriendlyMessage(pgError: PostgresError, context: string
|
|
|
249
281
|
code
|
|
250
282
|
};
|
|
251
283
|
case "42501": // insufficient_privilege
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
284
|
+
// Two unrelated failures share this SQLSTATE, and the old message
|
|
285
|
+
// named both causes because it could not tell them apart — which
|
|
286
|
+
// meant it was half wrong whichever one had happened, and sent the
|
|
287
|
+
// reader to check the other. Postgres says which in its own message.
|
|
288
|
+
return pgMessage.toLowerCase().includes("row-level security policy")
|
|
289
|
+
? {
|
|
290
|
+
// The caller. Their policies do not permit this row; the
|
|
291
|
+
// deployment is working exactly as configured.
|
|
292
|
+
message: `Not permitted to write this row in "${tableRef}": it does not satisfy the row-level security policy.${suffix}`,
|
|
293
|
+
code
|
|
294
|
+
}
|
|
295
|
+
: {
|
|
296
|
+
// The deployment. No policy is involved — the connecting
|
|
297
|
+
// role cannot touch the table at all.
|
|
298
|
+
message: `Permission denied on "${tableRef}": the database role this server connects as lacks privileges on it.${suffix}`,
|
|
299
|
+
code
|
|
300
|
+
};
|
|
256
301
|
case "28000": // invalid_authorization_specification
|
|
257
302
|
return {
|
|
258
303
|
message: `Authorization failed for "${context}". Check your database credentials.${suffix}`,
|