@ingram-tech/nk-db 0.9.0 → 0.9.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/pglite/dev.js +0 -0
- package/dist/pool.d.ts +15 -0
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +16 -1
- package/dist/pool.js.map +1 -1
- package/package.json +2 -2
package/dist/pglite/dev.js
CHANGED
|
File without changes
|
package/dist/pool.d.ts
CHANGED
|
@@ -7,6 +7,21 @@ export interface CreatePoolConfig {
|
|
|
7
7
|
/** Pool size cap. Defaults to env DATABASE_POOL_MAX, or 1 for a local socket. */
|
|
8
8
|
max?: number;
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Un-escape a PEM CA cert that arrived with literal `\n` instead of real
|
|
12
|
+
* newlines. A multiline secret survives intact in the app's runtime env (e.g.
|
|
13
|
+
* Vercel hands `process.env.DATABASE_CA_CERT` back with real newlines), but
|
|
14
|
+
* `vercel env pull` — and most `.env` serializers — collapse it to a single
|
|
15
|
+
* quoted line with `\n` escapes. A caller that then sources that file (the
|
|
16
|
+
* `nk-pg-migrate` runner, a CI job) gets the literal-`\n` form, which OpenSSL
|
|
17
|
+
* rejects with "self-signed certificate in certificate chain" even though the
|
|
18
|
+
* deployed app verifies the very same cert fine. Normalise here, the one place
|
|
19
|
+
* the cert reaches `pg`, so every caller gets verify-full regardless of how the
|
|
20
|
+
* env was loaded. A correctly-newlined PEM contains no literal `\n`, so this is
|
|
21
|
+
* a no-op there — idempotent and safe (base64 + the BEGIN/END lines never
|
|
22
|
+
* contain a backslash).
|
|
23
|
+
*/
|
|
24
|
+
export declare const normalizeCaCert: (caCert: string | undefined) => string | undefined;
|
|
10
25
|
/**
|
|
11
26
|
* The one shared `pg.Pool`. Reuse this for everything — app queries (via
|
|
12
27
|
* `createQueries` / Drizzle) AND Better Auth's adapter — so there's exactly one
|
package/dist/pool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,IAAI,CAAC;AAG3C,MAAM,WAAW,gBAAgB;IAChC,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAKD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,UAAU,GAAI,SAAQ,gBAAqB,KAAG,IA6B1D,CAAC"}
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,IAAI,CAAC;AAG3C,MAAM,WAAW,gBAAgB;IAChC,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sEAAsE;IACtE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,GAAG,CAAC,EAAE,MAAM,CAAC;CACb;AAKD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,SACN,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,UAAU,GAAI,SAAQ,gBAAqB,KAAG,IA6B1D,CAAC"}
|
package/dist/pool.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { Pool } from "pg";
|
|
2
2
|
import { dbEnv } from "./keys.js";
|
|
3
3
|
const isLocal = (connectionString) => connectionString.includes("127.0.0.1") || connectionString.includes("localhost");
|
|
4
|
+
/**
|
|
5
|
+
* Un-escape a PEM CA cert that arrived with literal `\n` instead of real
|
|
6
|
+
* newlines. A multiline secret survives intact in the app's runtime env (e.g.
|
|
7
|
+
* Vercel hands `process.env.DATABASE_CA_CERT` back with real newlines), but
|
|
8
|
+
* `vercel env pull` — and most `.env` serializers — collapse it to a single
|
|
9
|
+
* quoted line with `\n` escapes. A caller that then sources that file (the
|
|
10
|
+
* `nk-pg-migrate` runner, a CI job) gets the literal-`\n` form, which OpenSSL
|
|
11
|
+
* rejects with "self-signed certificate in certificate chain" even though the
|
|
12
|
+
* deployed app verifies the very same cert fine. Normalise here, the one place
|
|
13
|
+
* the cert reaches `pg`, so every caller gets verify-full regardless of how the
|
|
14
|
+
* env was loaded. A correctly-newlined PEM contains no literal `\n`, so this is
|
|
15
|
+
* a no-op there — idempotent and safe (base64 + the BEGIN/END lines never
|
|
16
|
+
* contain a backslash).
|
|
17
|
+
*/
|
|
18
|
+
export const normalizeCaCert = (caCert) => caCert?.includes("\\n") ? caCert.replace(/\\n/g, "\n") : caCert;
|
|
4
19
|
/**
|
|
5
20
|
* The one shared `pg.Pool`. Reuse this for everything — app queries (via
|
|
6
21
|
* `createQueries` / Drizzle) AND Better Auth's adapter — so there's exactly one
|
|
@@ -29,7 +44,7 @@ export const createPool = (config = {}) => {
|
|
|
29
44
|
if (!connectionString) {
|
|
30
45
|
throw new Error("@ingram-tech/nk-db: createPool needs a connection string.");
|
|
31
46
|
}
|
|
32
|
-
const caCert = config.caCert ?? env?.caCert;
|
|
47
|
+
const caCert = normalizeCaCert(config.caCert ?? env?.caCert);
|
|
33
48
|
const local = isLocal(connectionString);
|
|
34
49
|
const max = config.max ?? env?.poolMax ?? (local ? 1 : undefined);
|
|
35
50
|
const base = max === undefined ? {} : { max };
|
package/dist/pool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAmB,MAAM,IAAI,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAWlC,MAAM,OAAO,GAAG,CAAC,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G,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE;KAClC,CAAC,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingram-tech/nk-db",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "The Ingram Postgres data layer: one TLS-aware pg pool, raw-SQL helpers, Drizzle wiring, and a PGlite (no-Docker) dev/test harness for Next.js sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@electric-sql/pglite": "^0.5.0",
|
|
68
68
|
"@electric-sql/pglite-socket": "^0.2.4",
|
|
69
|
-
"@ingram-tech/nk-dev": "
|
|
69
|
+
"@ingram-tech/nk-dev": "0.2.3",
|
|
70
70
|
"@types/node": "^25.0.0",
|
|
71
71
|
"@types/pg": "^8.11.0",
|
|
72
72
|
"drizzle-orm": "^0.45.0",
|