@nodii/db-rls 0.2.1 → 0.3.1
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/configure.d.ts +25 -8
- package/dist/configure.d.ts.map +1 -1
- package/dist/configure.js +48 -17
- package/dist/configure.js.map +1 -1
- package/dist/context.d.ts +8 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +27 -6
- package/dist/context.js.map +1 -1
- package/dist/drizzle-client.d.ts +9 -2
- package/dist/drizzle-client.d.ts.map +1 -1
- package/dist/drizzle-client.js +28 -2
- package/dist/drizzle-client.js.map +1 -1
- package/dist/drizzle-policies.d.ts +23 -0
- package/dist/drizzle-policies.d.ts.map +1 -0
- package/dist/drizzle-policies.js +114 -0
- package/dist/drizzle-policies.js.map +1 -0
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -9
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +14 -5
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +20 -4
- package/dist/init.js.map +1 -1
- package/dist/metrics.d.ts +28 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +263 -0
- package/dist/metrics.js.map +1 -0
- package/dist/migrate-guard.d.ts +14 -0
- package/dist/migrate-guard.d.ts.map +1 -0
- package/dist/migrate-guard.js +33 -0
- package/dist/migrate-guard.js.map +1 -0
- package/dist/pg-pool-adapter.d.ts.map +1 -1
- package/dist/pg-pool-adapter.js +78 -25
- package/dist/pg-pool-adapter.js.map +1 -1
- package/dist/postgres-js-client.d.ts +60 -0
- package/dist/postgres-js-client.d.ts.map +1 -0
- package/dist/postgres-js-client.js +223 -0
- package/dist/postgres-js-client.js.map +1 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +30 -0
- package/dist/types.js.map +1 -1
- package/package.json +20 -5
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { Sql } from "postgres";
|
|
3
|
+
import { type OwnerContextOpts } from "./migrate-guard";
|
|
4
|
+
import { type PgPool, type PgTx, type PoolKind, type SystemContextOpts, type UserContextOpts } from "./types";
|
|
5
|
+
type PostgresJsDrizzleClient<TSchema extends Record<string, unknown> = Record<string, unknown>> = PostgresJsDatabase<TSchema>;
|
|
6
|
+
/**
|
|
7
|
+
* PgPool adapter wrapping a postgres-js `Sql` instance. Caller owns the
|
|
8
|
+
* underlying Sql's lifecycle (creation + .end()).
|
|
9
|
+
*
|
|
10
|
+
* The adapter implements the substrate-agnostic `PgPool` interface from
|
|
11
|
+
* `src/types.ts` so the existing `withUserContext` / `withSystemContext` /
|
|
12
|
+
* `withOwnerContext` helpers (in `src/context.ts`) work transparently
|
|
13
|
+
* against postgres-js — they receive a `PgTx` whose `setConfig` /
|
|
14
|
+
* `exec` calls land on the underlying postgres-js transaction.
|
|
15
|
+
*/
|
|
16
|
+
export declare class PgPostgresJsPool implements PgPool {
|
|
17
|
+
readonly kind: PoolKind;
|
|
18
|
+
private readonly sql;
|
|
19
|
+
private readonly slowAcquireMs;
|
|
20
|
+
private readonly onSlowAcquire?;
|
|
21
|
+
private readonly onTxFinish?;
|
|
22
|
+
constructor(opts: {
|
|
23
|
+
sql: Sql;
|
|
24
|
+
kind: PoolKind;
|
|
25
|
+
slowAcquireMs?: number;
|
|
26
|
+
onSlowAcquire?: (info: {
|
|
27
|
+
pool: PoolKind;
|
|
28
|
+
durationMs: number;
|
|
29
|
+
}) => void;
|
|
30
|
+
onTxFinish?: (info: {
|
|
31
|
+
pool: PoolKind;
|
|
32
|
+
outcome: "committed" | "rolled_back" | "error";
|
|
33
|
+
durationMs: number;
|
|
34
|
+
}) => void;
|
|
35
|
+
});
|
|
36
|
+
/** Direct access to the underlying postgres-js Sql (for ORM clients
|
|
37
|
+
* that need the raw handle — e.g. Drizzle's `drizzle(sql)`). */
|
|
38
|
+
get rawSql(): Sql;
|
|
39
|
+
withTransaction<T>(fn: (tx: PgTx) => Promise<T>): Promise<T>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* postgres-js Drizzle variant of `withUserContext`. Opens a tx on the
|
|
43
|
+
* `authenticated` pool, sets `app.user_id` + `app.tenant_id` via the
|
|
44
|
+
* canonical `auth.init(...)` helper, yields a Drizzle client.
|
|
45
|
+
*/
|
|
46
|
+
export declare function withUserContextDbPostgresJs<T, TSchema extends Record<string, unknown> = Record<string, unknown>>(opts: UserContextOpts, fn: (db: PostgresJsDrizzleClient<TSchema>) => Promise<T>): Promise<T>;
|
|
47
|
+
/**
|
|
48
|
+
* postgres-js Drizzle variant of `withSystemContext`. Opens a tx on the
|
|
49
|
+
* `services` pool with `app.tenant_id` GUC bound; yields a Drizzle client.
|
|
50
|
+
*/
|
|
51
|
+
export declare function withSystemContextDbPostgresJs<T, TSchema extends Record<string, unknown> = Record<string, unknown>>(opts: SystemContextOpts, fn: (db: PostgresJsDrizzleClient<TSchema>) => Promise<T>): Promise<T>;
|
|
52
|
+
/**
|
|
53
|
+
* postgres-js Drizzle variant of `withOwnerContext`. Opens a tx on the
|
|
54
|
+
* `owner` (BYPASSRLS) pool with no GUCs. Migrations only per § 5.3 +
|
|
55
|
+
* doctrine § 10.2 — gated by `NODII_ENV=migrate` or explicit
|
|
56
|
+
* `{ allowOutsideMigrate: true, reason }` opt-in.
|
|
57
|
+
*/
|
|
58
|
+
export declare function withOwnerContextDbPostgresJs<T, TSchema extends Record<string, unknown> = Record<string, unknown>>(fnOrOpts: OwnerContextOpts | ((db: PostgresJsDrizzleClient<TSchema>) => Promise<T>), maybeFn?: (db: PostgresJsDrizzleClient<TSchema>) => Promise<T>): Promise<T>;
|
|
59
|
+
export type { PostgresJsDrizzleClient };
|
|
60
|
+
//# sourceMappingURL=postgres-js-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-js-client.d.ts","sourceRoot":"","sources":["../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,223 @@
|
|
|
1
|
+
// postgres-js adapter per request 813cd066 + 06-library-integration § 4.9.
|
|
2
|
+
//
|
|
3
|
+
// Exposed via subpath `@nodii/db-rls/postgres-js`. nodii-auth uses
|
|
4
|
+
// `postgres` (postgres-js driver) — not `pg` (node-postgres). The
|
|
5
|
+
// existing `drizzle-client.ts` hard-imports `drizzle-orm/node-postgres`
|
|
6
|
+
// + requires `pool instanceof PgClient`, so it's unusable from
|
|
7
|
+
// postgres-js callers. This module mirrors the same surface for the
|
|
8
|
+
// postgres-js driver.
|
|
9
|
+
//
|
|
10
|
+
// Surface:
|
|
11
|
+
// - PgPostgresJsPool — wraps a `postgres.Sql` into the PgPool interface
|
|
12
|
+
// so the existing with*Context helpers in src/context.ts work
|
|
13
|
+
// transparently.
|
|
14
|
+
// - withUserContextDbPostgresJs / withSystemContextDbPostgresJs /
|
|
15
|
+
// withOwnerContextDbPostgresJs — Drizzle-bound helpers that return
|
|
16
|
+
// a `drizzle-orm/postgres-js` client bound to the transaction.
|
|
17
|
+
//
|
|
18
|
+
// Lifecycle per § 5.3 — identical to the node-postgres path:
|
|
19
|
+
// 1. `sql.begin(...)` → BEGIN
|
|
20
|
+
// 2. `tx.unsafe("SELECT set_config(...)")` → GUC binding
|
|
21
|
+
// 3. yield Drizzle client to caller
|
|
22
|
+
// 4. throw → ROLLBACK; clean exit → COMMIT
|
|
23
|
+
// postgres-js handles the BEGIN/COMMIT/ROLLBACK + connection release
|
|
24
|
+
// internally inside `sql.begin(...)`.
|
|
25
|
+
import { drizzle } from "drizzle-orm/postgres-js";
|
|
26
|
+
import { requirePool } from "./init";
|
|
27
|
+
import { emitSlowAcquireSpan, recordAcquisition, recordAcquisitionDuration, recordGucSetFailure, recordOwnerContextInvocation, recordTxDuration, withTxSpan, } from "./metrics";
|
|
28
|
+
import { assertMigrateAllowed } from "./migrate-guard";
|
|
29
|
+
import { MissingTenantContext, TransactionRolledBack, } from "./types";
|
|
30
|
+
/**
|
|
31
|
+
* PgPool adapter wrapping a postgres-js `Sql` instance. Caller owns the
|
|
32
|
+
* underlying Sql's lifecycle (creation + .end()).
|
|
33
|
+
*
|
|
34
|
+
* The adapter implements the substrate-agnostic `PgPool` interface from
|
|
35
|
+
* `src/types.ts` so the existing `withUserContext` / `withSystemContext` /
|
|
36
|
+
* `withOwnerContext` helpers (in `src/context.ts`) work transparently
|
|
37
|
+
* against postgres-js — they receive a `PgTx` whose `setConfig` /
|
|
38
|
+
* `exec` calls land on the underlying postgres-js transaction.
|
|
39
|
+
*/
|
|
40
|
+
export class PgPostgresJsPool {
|
|
41
|
+
kind;
|
|
42
|
+
sql;
|
|
43
|
+
slowAcquireMs;
|
|
44
|
+
onSlowAcquire;
|
|
45
|
+
onTxFinish;
|
|
46
|
+
constructor(opts) {
|
|
47
|
+
this.kind = opts.kind;
|
|
48
|
+
this.sql = opts.sql;
|
|
49
|
+
this.slowAcquireMs = opts.slowAcquireMs ?? 50;
|
|
50
|
+
this.onSlowAcquire = opts.onSlowAcquire;
|
|
51
|
+
this.onTxFinish = opts.onTxFinish;
|
|
52
|
+
}
|
|
53
|
+
/** Direct access to the underlying postgres-js Sql (for ORM clients
|
|
54
|
+
* that need the raw handle — e.g. Drizzle's `drizzle(sql)`). */
|
|
55
|
+
get rawSql() {
|
|
56
|
+
return this.sql;
|
|
57
|
+
}
|
|
58
|
+
async withTransaction(fn) {
|
|
59
|
+
const acquireStart = Date.now();
|
|
60
|
+
const txStart = Date.now();
|
|
61
|
+
let outcome = "error";
|
|
62
|
+
let pendingError;
|
|
63
|
+
try {
|
|
64
|
+
const result = await withTxSpan(this.kind, async (setOutcome) => {
|
|
65
|
+
return await this.sql.begin(async (tx) => {
|
|
66
|
+
const acquireMs = Date.now() - acquireStart;
|
|
67
|
+
recordAcquisition(this.kind, "success");
|
|
68
|
+
recordAcquisitionDuration(this.kind, acquireMs);
|
|
69
|
+
if (acquireMs >= this.slowAcquireMs) {
|
|
70
|
+
emitSlowAcquireSpan(this.kind, acquireMs);
|
|
71
|
+
if (this.onSlowAcquire) {
|
|
72
|
+
try {
|
|
73
|
+
this.onSlowAcquire({ pool: this.kind, durationMs: acquireMs });
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
/* non-fatal */
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const pgTx = new PostgresJsTx(this.kind, tx);
|
|
81
|
+
try {
|
|
82
|
+
const out = await fn(pgTx);
|
|
83
|
+
outcome = "committed";
|
|
84
|
+
setOutcome("committed");
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
outcome = "rolled_back";
|
|
89
|
+
setOutcome("rolled_back");
|
|
90
|
+
pendingError = err;
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
if (outcome === "error") {
|
|
99
|
+
// sql.begin's connect failed (or rethrown unwrapped) — count
|
|
100
|
+
// acquisition failure if we never recorded success.
|
|
101
|
+
recordAcquisition(this.kind, "failure");
|
|
102
|
+
outcome = "rolled_back";
|
|
103
|
+
pendingError = err;
|
|
104
|
+
}
|
|
105
|
+
throw pendingError ?? err;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
const durationMs = Date.now() - txStart;
|
|
109
|
+
recordTxDuration(this.kind, outcome, durationMs);
|
|
110
|
+
try {
|
|
111
|
+
this.onTxFinish?.({ pool: this.kind, outcome, durationMs });
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
/* non-fatal */
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
class PostgresJsTx {
|
|
120
|
+
poolKind;
|
|
121
|
+
raw;
|
|
122
|
+
constructor(kind, raw) {
|
|
123
|
+
this.poolKind = kind;
|
|
124
|
+
this.raw = raw;
|
|
125
|
+
}
|
|
126
|
+
async exec(sql, params = []) {
|
|
127
|
+
await this.raw.unsafe(sql, params);
|
|
128
|
+
}
|
|
129
|
+
async setConfig(key, value) {
|
|
130
|
+
// set_config(name, value, is_local=true) — tx-local per § 5.3.
|
|
131
|
+
try {
|
|
132
|
+
await this.raw.unsafe("SELECT set_config($1, $2, true)", [key, value]);
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
recordGucSetFailure(key);
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function requirePostgresJsPool(kind) {
|
|
141
|
+
const pool = requirePool(kind);
|
|
142
|
+
if (!(pool instanceof PgPostgresJsPool)) {
|
|
143
|
+
throw new Error(`db-rls: ${kind} pool is not a PgPostgresJsPool — the postgres-js Drizzle helpers require a postgres-js-backed pool. Use withUserContextDb (node-postgres) or wire a PgPostgresJsPool for postgres-js.`);
|
|
144
|
+
}
|
|
145
|
+
return pool;
|
|
146
|
+
}
|
|
147
|
+
async function withPostgresJsTx(pool, setup, fn) {
|
|
148
|
+
return pool.withTransaction(async (pgTx) => {
|
|
149
|
+
const raw = pgTx.raw;
|
|
150
|
+
try {
|
|
151
|
+
await setup(raw);
|
|
152
|
+
const db = drizzle(raw);
|
|
153
|
+
return await fn(db);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
throw new TransactionRolledBack(err);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* postgres-js Drizzle variant of `withUserContext`. Opens a tx on the
|
|
162
|
+
* `authenticated` pool, sets `app.user_id` + `app.tenant_id` via the
|
|
163
|
+
* canonical `auth.init(...)` helper, yields a Drizzle client.
|
|
164
|
+
*/
|
|
165
|
+
export async function withUserContextDbPostgresJs(opts, fn) {
|
|
166
|
+
if (!opts.userId)
|
|
167
|
+
throw new MissingTenantContext();
|
|
168
|
+
if (!opts.tenantId)
|
|
169
|
+
throw new MissingTenantContext();
|
|
170
|
+
const pool = requirePostgresJsPool("authenticated");
|
|
171
|
+
return withPostgresJsTx(pool, async (tx) => {
|
|
172
|
+
await tx.unsafe("SELECT auth.init($1::uuid, $2::uuid)", [
|
|
173
|
+
opts.userId,
|
|
174
|
+
opts.tenantId,
|
|
175
|
+
]);
|
|
176
|
+
if (opts.sourceIp !== undefined) {
|
|
177
|
+
await tx.unsafe("SELECT set_config('app.source_ip', $1, true)", [
|
|
178
|
+
opts.sourceIp,
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
}, fn);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* postgres-js Drizzle variant of `withSystemContext`. Opens a tx on the
|
|
185
|
+
* `services` pool with `app.tenant_id` GUC bound; yields a Drizzle client.
|
|
186
|
+
*/
|
|
187
|
+
export async function withSystemContextDbPostgresJs(opts, fn) {
|
|
188
|
+
if (!opts.tenantId)
|
|
189
|
+
throw new MissingTenantContext();
|
|
190
|
+
const pool = requirePostgresJsPool("services");
|
|
191
|
+
return withPostgresJsTx(pool, async (tx) => {
|
|
192
|
+
await tx.unsafe("SELECT auth.init_tenant($1::uuid)", [opts.tenantId]);
|
|
193
|
+
}, fn);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* postgres-js Drizzle variant of `withOwnerContext`. Opens a tx on the
|
|
197
|
+
* `owner` (BYPASSRLS) pool with no GUCs. Migrations only per § 5.3 +
|
|
198
|
+
* doctrine § 10.2 — gated by `NODII_ENV=migrate` or explicit
|
|
199
|
+
* `{ allowOutsideMigrate: true, reason }` opt-in.
|
|
200
|
+
*/
|
|
201
|
+
export async function withOwnerContextDbPostgresJs(fnOrOpts, maybeFn) {
|
|
202
|
+
const { opts, fn } = normalizeOwnerArgs(fnOrOpts, maybeFn);
|
|
203
|
+
try {
|
|
204
|
+
assertMigrateAllowed(opts);
|
|
205
|
+
}
|
|
206
|
+
catch (err) {
|
|
207
|
+
recordOwnerContextInvocation("refused");
|
|
208
|
+
throw err;
|
|
209
|
+
}
|
|
210
|
+
recordOwnerContextInvocation("allowed");
|
|
211
|
+
const pool = requirePostgresJsPool("owner");
|
|
212
|
+
return withPostgresJsTx(pool, async () => { }, fn);
|
|
213
|
+
}
|
|
214
|
+
function normalizeOwnerArgs(fnOrOpts, maybeFn) {
|
|
215
|
+
if (typeof fnOrOpts === "function") {
|
|
216
|
+
return { opts: {}, fn: fnOrOpts };
|
|
217
|
+
}
|
|
218
|
+
if (!maybeFn) {
|
|
219
|
+
throw new TypeError("withOwnerContextDbPostgresJs: when opts are passed, the second argument must be the callback.");
|
|
220
|
+
}
|
|
221
|
+
return { opts: fnOrOpts, fn: maybeFn };
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=postgres-js-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-js-client.js","sourceRoot":"","sources":["../src/postgres-js-client.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,wEAAwE;AACxE,+DAA+D;AAC/D,oEAAoE;AACpE,sBAAsB;AACtB,EAAE;AACF,WAAW;AACX,0EAA0E;AAC1E,kEAAkE;AAClE,qBAAqB;AACrB,oEAAoE;AACpE,uEAAuE;AACvE,mEAAmE;AACnE,EAAE;AACF,6DAA6D;AAC7D,gCAAgC;AAChC,2DAA2D;AAC3D,sCAAsC;AACtC,6CAA6C;AAC7C,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,OAAO,EAA2B,MAAM,yBAAyB,CAAC;AAG3E,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EAChB,UAAU,GACX,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,oBAAoB,EAAyB,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EACL,oBAAoB,EAI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@@ export interface PgPool {
|
|
|
18
18
|
/** Acquire a connection, BEGIN a tx, yield, and COMMIT/ROLLBACK. */
|
|
19
19
|
withTransaction<T>(fn: (tx: PgTx) => Promise<T>): Promise<T>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Pool topology mode. v0.2.x adds the `2-pool` exception per
|
|
23
|
+
* `08-rls-doctrine § 7` — nodii-auth runs owner + services only until
|
|
24
|
+
* its admin portal lands. Default is `3-pool`.
|
|
25
|
+
*/
|
|
26
|
+
export type DbRlsMode = "3-pool" | "2-pool";
|
|
21
27
|
/** Auth context bound by `@nodii/auth-sdk` middleware. Mirrors the
|
|
22
28
|
* fields autoDispatch reads — kept structural so the real auth-sdk
|
|
23
29
|
* context shape can grow without breaking us. */
|
|
@@ -68,4 +74,27 @@ export declare class TransactionRolledBack extends DbRlsError {
|
|
|
68
74
|
readonly cause: unknown;
|
|
69
75
|
constructor(cause: unknown);
|
|
70
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Thrown by `withOwnerContext` / `withOwnerContextDb` when invoked outside
|
|
79
|
+
* `NODII_ENV=migrate` per `08-rls-doctrine § 10.2`. The owner pool runs
|
|
80
|
+
* BYPASSRLS — invoking it from a request handler is a tenant-isolation
|
|
81
|
+
* escape and must be loud + refused by default. Migration scripts opt in
|
|
82
|
+
* by setting `NODII_ENV=migrate`; ops tooling that genuinely needs owner
|
|
83
|
+
* access at runtime opts in by passing `{ allowOutsideMigrate: true }`
|
|
84
|
+
* with an operator-attested reason (audit row emitted in a future slot).
|
|
85
|
+
*/
|
|
86
|
+
export declare class OwnerContextOutsideMigrate extends DbRlsError {
|
|
87
|
+
readonly nodiiEnv: string;
|
|
88
|
+
constructor(nodiiEnv: string);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Thrown by `initDbRls` / `configureDbRls` when the supplied pool topology
|
|
92
|
+
* doesn't match the declared `mode`. E.g. `mode: "3-pool"` without a
|
|
93
|
+
* `services` pool, or `mode: "2-pool"` with an `authenticated` pool
|
|
94
|
+
* supplied (the 2-pool exception has no authenticated role per
|
|
95
|
+
* 08-rls § 7).
|
|
96
|
+
*/
|
|
97
|
+
export declare class DbRlsConfigError extends DbRlsError {
|
|
98
|
+
constructor(message: string);
|
|
99
|
+
}
|
|
71
100
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAoBA,2DAA2D;AAC3D,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,eAAe,CAAC;AAE9D;;wBAEwB;AACxB,MAAM,WAAW,IAAI;IACnB,6CAA6C;IAC7C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,uDAAuD;IACvD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,sEAAsE;AACtE,MAAM,WAAW,MAAM;IACrB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,oEAAoE;IACpE,eAAe,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAC9D;AAED;;kDAEkD;AAClD,MAAM,WAAW,WAAW;IAC1B,mCAAmC;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,4BAA4B;AAC5B,MAAM,WA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AU;IAC7C,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;gBACZ,IAAI,EAAE,QAAQ;CAK3B;AAED,qBAAa,oBAAqB,SAAQ,UAAU;;CAOnD;AAED,qBAAa,qBAAsB,SAAQ,UAAU;IACnD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;gBACZ,KAAK,EAAE,OAAO;CAS3B;AAED;;;;;;;;GAQG;AACH,qBAAa,0BAA2B,SAAQ,UAAU;IACxD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;gBACd,QAAQ,EAAE,MAAM;CAO7B;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;gBAClC,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/types.js
CHANGED
|
@@ -53,4 +53,34 @@ export class TransactionRolledBack extends DbRlsError {
|
|
|
53
53
|
this.cause = cause;
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Thrown by `withOwnerContext` / `withOwnerContextDb` when invoked outside
|
|
58
|
+
* `NODII_ENV=migrate` per `08-rls-doctrine § 10.2`. The owner pool runs
|
|
59
|
+
* BYPASSRLS — invoking it from a request handler is a tenant-isolation
|
|
60
|
+
* escape and must be loud + refused by default. Migration scripts opt in
|
|
61
|
+
* by setting `NODII_ENV=migrate`; ops tooling that genuinely needs owner
|
|
62
|
+
* access at runtime opts in by passing `{ allowOutsideMigrate: true }`
|
|
63
|
+
* with an operator-attested reason (audit row emitted in a future slot).
|
|
64
|
+
*/
|
|
65
|
+
export class OwnerContextOutsideMigrate extends DbRlsError {
|
|
66
|
+
nodiiEnv;
|
|
67
|
+
constructor(nodiiEnv) {
|
|
68
|
+
super(`owner_context_outside_migrate: NODII_ENV=${JSON.stringify(nodiiEnv)}, expected "migrate". Owner pool BYPASSRLS — only callable during migrations (08-rls § 10.2). Set NODII_ENV=migrate for migration scripts, or pass { allowOutsideMigrate: true, reason: "..." } with operator-attested reason.`);
|
|
69
|
+
this.name = "OwnerContextOutsideMigrate";
|
|
70
|
+
this.nodiiEnv = nodiiEnv;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Thrown by `initDbRls` / `configureDbRls` when the supplied pool topology
|
|
75
|
+
* doesn't match the declared `mode`. E.g. `mode: "3-pool"` without a
|
|
76
|
+
* `services` pool, or `mode: "2-pool"` with an `authenticated` pool
|
|
77
|
+
* supplied (the 2-pool exception has no authenticated role per
|
|
78
|
+
* 08-rls § 7).
|
|
79
|
+
*/
|
|
80
|
+
export class DbRlsConfigError extends DbRlsError {
|
|
81
|
+
constructor(message) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.name = "DbRlsConfigError";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
56
86
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,EAAE;AACF,gBAAgB;AAChB,qDAAqD;AACrD,uEAAuE;AACvE,0EAA0E;AAC1E,oDAAoD;AACpD,0EAA0E;AAC1E,wBAAwB;AACxB,+DAA+D;AAC/D,iDAAiD;AACjD,EAAE;AACF,uCAAuC;AACvC,0CAA0C;AAC1C,kDAAkD;AAClD,0EAA0E;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,EAAE;AACF,gBAAgB;AAChB,qDAAqD;AACrD,uEAAuE;AACvE,0EAA0E;AAC1E,oDAAoD;AACpD,0EAA0E;AAC1E,wBAAwB;AACxB,+DAA+D;AAC/D,iDAAiD;AACjD,EAAE;AACF,uCAAuC;AACvC,0CAA0C;AAC1C,kDAAkD;AAClD,0EAA0E;AAsE1E,+EAA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IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodii/db-rls",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Three-pool RLS dispatch + GUC-set + entry-point helpers + RLS policy DDL generator for the Nodii microservice stack. Polyglot per D159 (TS + Python + Go). Spec: planning hub docKey=db-rls.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -13,6 +13,14 @@
|
|
|
13
13
|
".": {
|
|
14
14
|
"types": "./dist/index.d.ts",
|
|
15
15
|
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./drizzle": {
|
|
18
|
+
"types": "./dist/drizzle-policies.d.ts",
|
|
19
|
+
"default": "./dist/drizzle-policies.js"
|
|
20
|
+
},
|
|
21
|
+
"./postgres-js": {
|
|
22
|
+
"types": "./dist/postgres-js-client.d.ts",
|
|
23
|
+
"default": "./dist/postgres-js-client.js"
|
|
16
24
|
}
|
|
17
25
|
},
|
|
18
26
|
"files": [
|
|
@@ -29,29 +37,36 @@
|
|
|
29
37
|
"test": "bun test"
|
|
30
38
|
},
|
|
31
39
|
"peerDependencies": {
|
|
32
|
-
"@nodii/telemetry": "0.1.1",
|
|
33
40
|
"drizzle-orm": "^0.36.0",
|
|
34
|
-
"pg": "^8.13.0"
|
|
41
|
+
"pg": "^8.13.0",
|
|
42
|
+
"postgres": "^3.4.0"
|
|
35
43
|
},
|
|
36
44
|
"peerDependenciesMeta": {
|
|
37
45
|
"drizzle-orm": {
|
|
38
46
|
"optional": false
|
|
39
47
|
},
|
|
40
48
|
"pg": {
|
|
41
|
-
"optional":
|
|
49
|
+
"optional": true
|
|
50
|
+
},
|
|
51
|
+
"postgres": {
|
|
52
|
+
"optional": true
|
|
42
53
|
}
|
|
43
54
|
},
|
|
44
55
|
"devDependencies": {
|
|
45
|
-
"@nodii/telemetry": "0.
|
|
56
|
+
"@nodii/telemetry": "0.3.0",
|
|
46
57
|
"@types/bun": "^1.3.13",
|
|
47
58
|
"@types/pg": "^8.11.10",
|
|
48
59
|
"drizzle-orm": "^0.36.4",
|
|
49
60
|
"pg": "^8.13.1",
|
|
61
|
+
"postgres": "^3.4.0",
|
|
50
62
|
"typescript": "^5.9.3"
|
|
51
63
|
},
|
|
52
64
|
"repository": {
|
|
53
65
|
"type": "git",
|
|
54
66
|
"url": "git+https://github.com/cognion-nucleus/nodii-libs.git",
|
|
55
67
|
"directory": "ts/db-rls"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@nodii/telemetry": "0.3.0"
|
|
56
71
|
}
|
|
57
72
|
}
|