@prenta/cli 1.3.0 β†’ 1.3.2

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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @prenta/cli@1.3.0 build /home/runner/work/prenta/prenta/packages/cli
2
+ > @prenta/cli@1.3.2 build /home/runner/work/prenta/prenta/packages/cli
3
3
  > tsc
4
4
 
@@ -1,34 +1,33 @@
1
1
 
2
- > @prenta/cli@1.3.0 test /home/runner/work/prenta/prenta/packages/cli
2
+ > @prenta/cli@1.3.2 test /home/runner/work/prenta/prenta/packages/cli
3
3
  > vitest run "--no-file-parallelism"
4
4
 
5
5
 
6
6
   RUN  v4.1.12 /home/runner/work/prenta/prenta/packages/cli
7
7
 
8
- βœ“ src/__tests__/db-restore.test.ts (34 tests) 6914ms
9
- βœ“ requires --target and never defaults to the env database  402ms
10
- βœ“ warns when --target carries a password on argv and recommends PGPASSWORD instead  367ms
11
- βœ“ OIDC mode (VERCEL_OIDC_TOKEN + BLOB_STORE_ID) lists and restores without passing a token  627ms
12
- βœ“ compares the typed name against the normalized database name and never accepts an empty answer  303ms
13
- βœ“ src/__tests__/db-backup.test.ts (27 tests) 4810ms
14
- βœ“ writes the workflow YAML verbatim and exits 0 without touching the database  594ms
15
- βœ“ refuses localhost / 127.0.0.1 unless --allow-local  724ms
16
- βœ“ dumps with the exact argv, encrypts, and writes a verifiable manifest  387ms
17
- βœ“ src/__tests__/deployment-diagnostics.test.ts (23 tests) 315ms
18
- βœ“ src/__tests__/backup-blob-store.test.ts (18 tests) 1045ms
19
- βœ“ src/__tests__/backup-pg-tools.test.ts (26 tests) 502ms
20
- βœ“ src/__tests__/db-sync.test.ts (13 tests) 923ms
21
- βœ“ refreshes an auto-synced schema and adds missing migrations  306ms
22
- βœ“ src/__tests__/chrome.test.ts (11 tests) 18141ms
8
+ βœ“ src/__tests__/db-restore.test.ts (34 tests) 6911ms
9
+ βœ“ requires --target and never defaults to the env database  488ms
10
+ βœ“ warns when --target carries a password on argv and recommends PGPASSWORD instead  424ms
11
+ βœ“ OIDC mode (VERCEL_OIDC_TOKEN + BLOB_STORE_ID) lists and restores without passing a token  500ms
12
+ βœ“ --list prints available backups newest first with stamps and sizes  300ms
13
+ βœ“ "latest" selects the newest stamp under the prefix  348ms
14
+ βœ“ src/__tests__/db-backup.test.ts (27 tests) 3345ms
15
+ βœ“ refuses localhost / 127.0.0.1 unless --allow-local  431ms
16
+ βœ“ src/__tests__/deployment-diagnostics.test.ts (23 tests) 175ms
17
+ βœ“ src/__tests__/backup-blob-store.test.ts (18 tests) 855ms
18
+ βœ“ src/__tests__/backup-pg-tools.test.ts (26 tests) 275ms
19
+ βœ“ src/__tests__/db-sync.test.ts (13 tests) 548ms
20
+ βœ“ src/__tests__/chrome.test.ts (11 tests) 17657ms
23
21
  ↓ src/__tests__/integration/backup-roundtrip.int.test.ts (1 test | 1 skipped)
24
- βœ“ src/__tests__/backup-manifest.test.ts (17 tests) 82ms
22
+ βœ“ src/__tests__/backup-manifest.test.ts (17 tests) 77ms
25
23
  - Resolving target versions…
26
24
  βœ” Target version: 9.0.0
27
- βœ“ src/__tests__/upgrade-workspaces.test.ts (12 tests) 3839ms
28
- βœ“ passes `upgrade --version <ver>` to upgrade instead of printing the CLI version  2227ms
29
- βœ“ prints its own package version for `prenta --version`  1426ms
30
- βœ“ src/__tests__/seed.test.ts (10 tests) 85ms
31
- βœ“ src/__tests__/backup-crypto.test.ts (13 tests) 260ms
25
+ βœ“ src/__tests__/upgrade-workspaces.test.ts (12 tests) 2797ms
26
+ βœ“ passes `upgrade --version <ver>` to upgrade instead of printing the CLI version  1685ms
27
+ βœ“ prints its own package version for `prenta --version`  926ms
28
+ βœ“ src/__tests__/seed.test.ts (10 tests) 63ms
29
+ βœ“ src/__tests__/backup-crypto.test.ts (13 tests) 573ms
30
+ βœ“ detects a flipped auth-tag byte  324ms
32
31
  stdout | src/__tests__/mcp-init.test.ts > mcp:init > creates Claude Code, Cursor, and VS Code configs with placeholder key and git-ignores them
33
32
  βœ” Created .mcp.json
34
33
 
@@ -117,16 +116,16 @@ Next steps
117
116
  stdout | src/__tests__/mcp-init.test.ts > mcp:init > fails on invalid JSON without --force, overwrites with --force
118
117
  βœ” Created .mcp.json
119
118
 
120
- stdout | src/__tests__/mcp-init.test.ts > mcp:init > fails on invalid JSON without --force, overwrites with --force
121
119
  stderr | src/__tests__/mcp-init.test.ts > mcp:init > fails on invalid JSON without --force, overwrites with --force
122
- βœ– .cursor/mcp.json contains invalid JSON β€” fix it or re-run with --force.
120
+ stdout | src/__tests__/mcp-init.test.ts > mcp:init > fails on invalid JSON without --force, overwrites with --force
123
121
  βœ” Created .vscode/mcp.json
124
122
 
125
-
126
123
  stdout | src/__tests__/mcp-init.test.ts > mcp:init > fails on invalid JSON without --force, overwrites with --force
127
124
  βœ” Added to .gitignore: .mcp.json, .cursor/mcp.json, .vscode/mcp.json
128
125
 
129
126
  Next steps
127
+ βœ– .cursor/mcp.json contains invalid JSON β€” fix it or re-run with --force.
128
+
130
129
  1. Mint an API key in Admin β†’ Settings β†’ API Keys (act_sk_...)
131
130
  2. Replace act_sk_REPLACE_WITH_YOUR_KEY in the MCP config files with the real key
132
131
  3. Restart Claude Code / Cursor / VS Code so the MCP server is picked up
@@ -167,10 +166,10 @@ Next steps
167
166
 
168
167
  stdout | src/__tests__/mcp-init.test.ts > mcp:init > refuses to write a real key into a config git already tracks
169
168
  βœ” Updated .mcp.json
170
-
171
169
  stderr | src/__tests__/mcp-init.test.ts > mcp:init > refuses to write a real key into a config git already tracks
172
170
  ⚠ .cursor/mcp.json already has an "prenta" server β€” use --force to replace it.
173
171
 
172
+
174
173
  stderr | src/__tests__/mcp-init.test.ts > mcp:init > refuses to write a real key into a config git already tracks
175
174
  ⚠ .vscode/mcp.json already has an "prenta" server β€” use --force to replace it.
176
175
 
@@ -217,20 +216,20 @@ Next steps
217
216
  3. Restart Claude Code / Cursor / VS Code so the MCP server is picked up
218
217
  Tip: pass --url https://your-site.com to target a deployed CMS instead.
219
218
 
220
- βœ“ src/__tests__/mcp-init.test.ts (7 tests) 450ms
221
- βœ“ src/__tests__/backup-common.test.ts (14 tests) 31ms
219
+ βœ“ src/__tests__/mcp-init.test.ts (7 tests) 562ms
220
+ βœ“ src/__tests__/backup-common.test.ts (14 tests) 88ms
222
221
  - Reading canonical Prenta schema...
223
222
  βœ” Prenta CMS models added to schema.
224
- - Running prisma generate...
225
223
  stdout | src/__tests__/db-init.test.ts > db:init (WS-D D5 β€” canonical schema, no stale fragment) > command > injects canonical models with @@map and no duplicate datasource/generator
226
224
  βœ” Prisma client generated.
225
+ - Running prisma generate...
227
226
  β„Ή Run `npx prisma migrate dev --name prenta-cms` to create the migration.
228
227
 
228
+ - Reading canonical Prenta schema...
229
+ βœ– Could not locate @prenta/core.
229
230
  stdout | src/__tests__/db-init.test.ts > db:init (WS-D D5 β€” canonical schema, no stale fragment) > command > fails clearly when cms-core cannot be located
230
231
  β„Ή Install it first: `npm install @prenta/core`.
231
232
 
232
- - Reading canonical Prenta schema...
233
- βœ– Could not locate @prenta/core.
234
233
  - Reading canonical Prenta schema...
235
234
  βœ” Prenta CMS models added to schema.
236
235
  - Running prisma generate...
@@ -240,30 +239,31 @@ Next steps
240
239
 
241
240
  - Reading canonical Prenta schema...
242
241
  β„Ή Prenta CMS models already present in schema. Use --force to overwrite.
243
- βœ“ src/__tests__/db-init.test.ts (4 tests) 156ms
244
- βœ“ src/__tests__/seed-sanitize.test.ts (9 tests) 55ms
245
- βœ“ src/__tests__/prisma-client-path.test.ts (8 tests) 77ms
246
- βœ“ src/__tests__/form-seed.test.ts (10 tests) 39ms
247
- βœ“ src/__tests__/import-typescript.test.ts (9 tests) 505ms
248
- βœ“ loads a TypeScript file that imports a sibling without appending ?namespace=  435ms
249
- βœ“ src/__tests__/vercel-env-matrix.test.ts (6 tests) 73ms
250
- βœ“ src/__tests__/upgrade.test.ts (3 tests) 20ms
251
- βœ“ src/__tests__/repo-root.test.ts (4 tests) 54ms
252
- βœ“ src/__tests__/load-dotenv.test.ts (3 tests) 37ms
253
- βœ“ src/__tests__/import-typescript-hooks.test.ts (2 tests) 40ms
242
+ βœ“ src/__tests__/db-init.test.ts (4 tests) 132ms
243
+ βœ“ src/__tests__/seed-sanitize.test.ts (9 tests) 54ms
244
+ βœ“ src/__tests__/prisma-client-path.test.ts (8 tests) 30ms
245
+ βœ“ src/__tests__/form-seed.test.ts (10 tests) 27ms
246
+ βœ“ src/__tests__/pg-ssl-mode.test.ts (8 tests) 25ms
247
+ βœ“ src/__tests__/import-typescript.test.ts (9 tests) 259ms
248
+ βœ“ src/__tests__/vercel-env-matrix.test.ts (6 tests) 16ms
249
+ βœ“ src/__tests__/upgrade.test.ts (3 tests) 23ms
250
+ βœ“ src/__tests__/repo-root.test.ts (4 tests) 80ms
251
+ βœ“ src/__tests__/load-dotenv.test.ts (3 tests) 25ms
252
+ βœ“ src/__tests__/import-typescript-hooks.test.ts (2 tests) 70ms
254
253
  - Reading canonical Prenta schema...
255
- βœ” Prenta CMS models added to schema.
256
- - Running prisma generate...
257
254
  stdout | src/__tests__/schema-fragment.test.ts > db:init schema fragment > injects all deploy-critical Prenta models
255
+ βœ” Prenta CMS models added to schema.
258
256
  βœ” Prisma client generated.
259
257
  β„Ή Run `npx prisma migrate dev --name prenta-cms` to create the migration.
260
258
 
261
- βœ“ src/__tests__/schema-fragment.test.ts (1 test) 131ms
262
- βœ“ src/__tests__/db-sync-resolver.test.ts (4 tests) 22ms
259
+ - Running prisma generate...
260
+ βœ“ src/__tests__/schema-fragment.test.ts (1 test) 50ms
261
+ βœ“ src/__tests__/db-sync-resolver.test.ts (4 tests) 16ms
262
+ βœ“ src/__tests__/pg-ssl-mode-in-step.test.ts (2 tests) 9ms
263
263
  βœ“ src/__tests__/init.test.ts (2 tests) 25ms
264
264
 
265
-  Test Files  26 passed | 1 skipped (27)
266
-  Tests  290 passed | 1 skipped (291)
267
-  Start at  01:05:08
268
-  Duration  88.88s (transform 21.13s, setup 0ms, import 18.32s, tests 38.63s, environment 9ms)
265
+  Test Files  28 passed | 1 skipped (29)
266
+  Tests  300 passed | 1 skipped (301)
267
+  Start at  09:03:26
268
+  Duration  74.96s (transform 20.08s, setup 0ms, import 15.45s, tests 34.77s, environment 3ms)
269
269
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @actuate-media/cli
2
2
 
3
+ ## 1.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 5230917: Point repository links at github.com/Prenta-dev/prenta, where the source now lives. The `repository` field on npm, the importer adapters' docs links, the section editor's help link and the docs link `create-prenta` prints all moved from `actuate-media/prenta`. No behaviour changes.
8
+
9
+ ## 1.3.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 5c7026c: Stop pg's SSL mode warning from the core Postgres adapter and the CLI. Both handed the connection string straight to `pg`, which logs a SECURITY WARNING for `sslmode=require` because `pg` 9 will stop verifying the certificate for it. `createPostgresAdapter` and the CLI commands that open a database connection (`seed`, `populate`, `migrate:*`) now rewrite `prefer`, `require` and `verify-ca` to `verify-full` first: the same behaviour today, no warning, and full verification kept under `pg` 9. A URL with `uselibpqcompat=true` is left as it is.
14
+
3
15
  ## 1.3.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @prenta/cli
2
2
 
3
- CLI for [Prenta CMS](https://github.com/actuate-media/prenta) β€”
3
+ CLI for [Prenta CMS](https://github.com/Prenta-dev/prenta) β€”
4
4
  migrations, codegen, seeding, imports/exports, verification, and upgrades.
5
5
 
6
6
  ```bash
@@ -23,7 +23,7 @@ Run `prenta --help` for the full command list.
23
23
  ## Release notes
24
24
 
25
25
  See [CHANGELOG.md](./CHANGELOG.md) (shipped with the package) or the
26
- [GitHub releases](https://github.com/actuate-media/prenta/releases).
26
+ [GitHub releases](https://github.com/Prenta-dev/prenta/releases).
27
27
 
28
28
  ## License
29
29
 
@@ -1 +1 @@
1
- {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC;IAEtD,EAAE,EAAE,GAAG,CAAA;IACP,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC,CAAC,CAiBD"}
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC;IAEtD,EAAE,EAAE,GAAG,CAAA;IACP,UAAU,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAChC,CAAC,CAiBD"}
@@ -2,6 +2,7 @@ import { createRequire } from 'node:module';
2
2
  import path from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
4
  import { importProjectTypescript } from './import-typescript.js';
5
+ import { withExplicitSslMode } from './pg-ssl-mode.js';
5
6
  import { resolvePrismaClientLoadPlan } from './prisma-client-path.js';
6
7
  /**
7
8
  * Shared helper for CLI commands that need a live connection to the consumer
@@ -95,7 +96,7 @@ async function createClientFromGenerated(generatedClient) {
95
96
  }
96
97
  const { PrismaPg } = adapterModule;
97
98
  const pg = pgModule.default ?? pgModule;
98
- const pool = new pg.Pool({ connectionString: url });
99
+ const pool = new pg.Pool({ connectionString: withExplicitSslMode(url) });
99
100
  const adapter = new PrismaPg(pool);
100
101
  return new PrismaClient({ adapter });
101
102
  }
@@ -1 +1 @@
1
- {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,uBAAuB,EAAE,MAAM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I,CAAC,MAAM,KAAK,YAAY,EAAE,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACzD,IAAI,OAAO;YAAE,OAAO,OAAO,CAAA;IAC7B,CAAC;IAED,MAAM,kBAAkB,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC,CAAA;IAClF,MAAM,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,gBAAgB,EAAE,kBAAkB,CAAC,CAE7E,CAAA;IACD,OAAO,IAAI,YAAY,CAAC,YAAY,EAAE,CAAA;AACxC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Make a Postgres connection string's TLS mode explicit.
3
+ *
4
+ * `pg` 8 treats `sslmode=prefer`, `require` and `verify-ca` as aliases
5
+ * for `verify-full`, and logs a SECURITY WARNING the first time it parses
6
+ * one, to say that `pg` 9 will weaken them to libpq's meaning (no
7
+ * certificate verification for `require`). Hosted providers hand out
8
+ * `sslmode=require` strings, so the warning shows up on every cold start.
9
+ *
10
+ * Rewriting those modes to `verify-full` asks for exactly what `pg` 8
11
+ * already does: the warning stops, and full certificate verification stays
12
+ * when `pg` 9 arrives.
13
+ *
14
+ * A string that opts in to libpq semantics with `uselibpqcompat=true` is
15
+ * left alone, as is one with no `sslmode`, `sslmode=disable` or
16
+ * `sslmode=no-verify`.
17
+ *
18
+ * The query is read the way `pg` reads it: names and values are
19
+ * percent-decoded, and the last of a repeated parameter wins. Only the one
20
+ * `sslmode` segment that takes effect is replaced; every other character,
21
+ * credentials included, is returned as it was given.
22
+ *
23
+ * A copy of `packages/cms-core/src/db/pg-ssl-mode.ts`. The CLI supports
24
+ * older `@prenta/core` versions, so it cannot import this from core. Keep
25
+ * the two in step.
26
+ */
27
+ export declare function withExplicitSslMode<T extends string | undefined>(connectionString: T): T;
28
+ //# sourceMappingURL=pg-ssl-mode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pg-ssl-mode.d.ts","sourceRoot":"","sources":["../../src/utils/pg-ssl-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAAE,gBAAgB,EAAE,CAAC,GAAG,CAAC,CAyBxF"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Make a Postgres connection string's TLS mode explicit.
3
+ *
4
+ * `pg` 8 treats `sslmode=prefer`, `require` and `verify-ca` as aliases
5
+ * for `verify-full`, and logs a SECURITY WARNING the first time it parses
6
+ * one, to say that `pg` 9 will weaken them to libpq's meaning (no
7
+ * certificate verification for `require`). Hosted providers hand out
8
+ * `sslmode=require` strings, so the warning shows up on every cold start.
9
+ *
10
+ * Rewriting those modes to `verify-full` asks for exactly what `pg` 8
11
+ * already does: the warning stops, and full certificate verification stays
12
+ * when `pg` 9 arrives.
13
+ *
14
+ * A string that opts in to libpq semantics with `uselibpqcompat=true` is
15
+ * left alone, as is one with no `sslmode`, `sslmode=disable` or
16
+ * `sslmode=no-verify`.
17
+ *
18
+ * The query is read the way `pg` reads it: names and values are
19
+ * percent-decoded, and the last of a repeated parameter wins. Only the one
20
+ * `sslmode` segment that takes effect is replaced; every other character,
21
+ * credentials included, is returned as it was given.
22
+ *
23
+ * A copy of `packages/cms-core/src/db/pg-ssl-mode.ts`. The CLI supports
24
+ * older `@prenta/core` versions, so it cannot import this from core. Keep
25
+ * the two in step.
26
+ */
27
+ export function withExplicitSslMode(connectionString) {
28
+ if (!connectionString)
29
+ return connectionString;
30
+ const queryStart = connectionString.indexOf('?');
31
+ if (queryStart === -1)
32
+ return connectionString;
33
+ const base = connectionString.slice(0, queryStart);
34
+ const afterQuestionMark = connectionString.slice(queryStart + 1);
35
+ const fragmentStart = afterQuestionMark.indexOf('#');
36
+ const query = fragmentStart === -1 ? afterQuestionMark : afterQuestionMark.slice(0, fragmentStart);
37
+ const fragment = fragmentStart === -1 ? '' : afterQuestionMark.slice(fragmentStart);
38
+ const params = new URLSearchParams(query);
39
+ // pg honours this flag only as the exact value "true".
40
+ if (params.getAll('uselibpqcompat').pop() === 'true')
41
+ return connectionString;
42
+ const mode = params.getAll('sslmode').pop();
43
+ if (mode !== 'prefer' && mode !== 'require' && mode !== 'verify-ca')
44
+ return connectionString;
45
+ const segments = query.split('&');
46
+ let effective = -1;
47
+ segments.forEach((segment, index) => {
48
+ if (new URLSearchParams(segment).has('sslmode'))
49
+ effective = index;
50
+ });
51
+ if (effective === -1)
52
+ return connectionString;
53
+ segments[effective] = 'sslmode=verify-full';
54
+ return (base + '?' + segments.join('&') + fragment);
55
+ }
56
+ //# sourceMappingURL=pg-ssl-mode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pg-ssl-mode.js","sourceRoot":"","sources":["../../src/utils/pg-ssl-mode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,mBAAmB,CAA+B,gBAAmB;IACnF,IAAI,CAAC,gBAAgB;QAAE,OAAO,gBAAgB,CAAA;IAC9C,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IAChD,IAAI,UAAU,KAAK,CAAC,CAAC;QAAE,OAAO,gBAAgB,CAAA;IAE9C,MAAM,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;IAClD,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,KAAK,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;IAChE,MAAM,aAAa,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACpD,MAAM,KAAK,GAAG,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,EAAE,aAAa,CAAC,CAAA;IAClG,MAAM,QAAQ,GAAG,aAAa,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;IAEnF,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC,KAAK,CAAC,CAAA;IACzC,uDAAuD;IACvD,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,GAAG,EAAE,KAAK,MAAM;QAAE,OAAO,gBAAgB,CAAA;IAC7E,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,CAAA;IAC3C,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,WAAW;QAAE,OAAO,gBAAgB,CAAA;IAE5F,MAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACjC,IAAI,SAAS,GAAG,CAAC,CAAC,CAAA;IAClB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;QAClC,IAAI,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,SAAS,GAAG,KAAK,CAAA;IACpE,CAAC,CAAC,CAAA;IACF,IAAI,SAAS,KAAK,CAAC,CAAC;QAAE,OAAO,gBAAgB,CAAA;IAC7C,QAAQ,CAAC,SAAS,CAAC,GAAG,qBAAqB,CAAA;IAC3C,OAAO,CAAC,IAAI,GAAG,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAM,CAAA;AAC1D,CAAC"}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@prenta/cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "license": "MIT",
5
5
  "description": "CLI for Prenta CMS β€” migrations, codegen, imports, exports, and upgrades",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/actuate-media/prenta.git",
8
+ "url": "https://github.com/Prenta-dev/prenta.git",
9
9
  "directory": "packages/cli"
10
10
  },
11
11
  "publishConfig": {
@@ -36,7 +36,7 @@
36
36
  "@vercel/blob": "^2.3.1",
37
37
  "typescript": "^5.7.0",
38
38
  "vitest": "^4.1.12",
39
- "@prenta/core": "8.21.3"
39
+ "@prenta/core": "8.21.11"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsc",
@@ -0,0 +1,29 @@
1
+ import { readFile } from 'node:fs/promises'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { describe, expect, it } from 'vitest'
5
+
6
+ const here = path.dirname(fileURLToPath(import.meta.url))
7
+ const cliCopy = path.join(here, '..', 'utils', 'pg-ssl-mode.ts')
8
+ const coreCopy = path.join(here, '..', '..', '..', 'cms-core', 'src', 'db', 'pg-ssl-mode.ts')
9
+ const cliDatabase = path.join(here, '..', 'utils', 'database.ts')
10
+
11
+ /** Everything from the function signature on: the doc comments differ on purpose. */
12
+ function implementation(source: string): string {
13
+ const start = source.indexOf('export function withExplicitSslMode')
14
+ if (start === -1) throw new Error('withExplicitSslMode not found')
15
+ return source.slice(start).replace(/\r\n/g, '\n')
16
+ }
17
+
18
+ describe('pg sslmode helper', () => {
19
+ it('is the same in the CLI as in @prenta/core', async () => {
20
+ const [cli, core] = await Promise.all([readFile(cliCopy, 'utf-8'), readFile(coreCopy, 'utf-8')])
21
+ expect(implementation(cli)).toBe(implementation(core))
22
+ })
23
+
24
+ it('wraps the connection string the CLI hands to pg', async () => {
25
+ const source = await readFile(cliDatabase, 'utf-8')
26
+ expect(source).toContain('.Pool({ connectionString: withExplicitSslMode(url) })')
27
+ expect(source).not.toContain('.Pool({ connectionString: url })')
28
+ })
29
+ })
@@ -0,0 +1,78 @@
1
+ import { describe, expect, it } from 'vitest'
2
+ import { withExplicitSslMode } from '../utils/pg-ssl-mode.js'
3
+
4
+ const BASE = 'postgres://user:p%40ss%2Fword@db.example.com:5432/app'
5
+
6
+ describe('withExplicitSslMode', () => {
7
+ it('rewrites the modes pg 8 treats as verify-full', () => {
8
+ for (const mode of ['prefer', 'require', 'verify-ca']) {
9
+ expect(withExplicitSslMode(`${BASE}?sslmode=${mode}`)).toBe(`${BASE}?sslmode=verify-full`)
10
+ }
11
+ })
12
+
13
+ it('keeps the other query parameters, their order and the credentials', () => {
14
+ expect(withExplicitSslMode(`${BASE}?connection_limit=5&sslmode=require&pgbouncer=true`)).toBe(
15
+ `${BASE}?connection_limit=5&sslmode=verify-full&pgbouncer=true`,
16
+ )
17
+ })
18
+
19
+ it('leaves strings it should not change', () => {
20
+ for (const url of [
21
+ BASE,
22
+ `${BASE}?sslmode=verify-full`,
23
+ `${BASE}?sslmode=disable`,
24
+ `${BASE}?sslmode=no-verify`,
25
+ `${BASE}?uselibpqcompat=true&sslmode=require`,
26
+ `${BASE}?sslmode=require&uselibpqcompat=true`,
27
+ `${BASE}?application_name=sslmode=require-ish`,
28
+ 'prisma+postgres://accelerate.prisma-data.net/?api_key=abc',
29
+ ]) {
30
+ expect(withExplicitSslMode(url)).toBe(url)
31
+ }
32
+ })
33
+
34
+ it('reads percent-encoded names and values the way pg does', () => {
35
+ expect(withExplicitSslMode(`${BASE}?sslmode=%72equire`)).toBe(`${BASE}?sslmode=verify-full`)
36
+ expect(withExplicitSslMode(`${BASE}?%73slmode=require&x=1`)).toBe(
37
+ `${BASE}?sslmode=verify-full&x=1`,
38
+ )
39
+ // An encoded opt-in to libpq semantics is still an opt-in.
40
+ for (const url of [
41
+ `${BASE}?sslmode=require&uselibpqcompat=%74rue`,
42
+ `${BASE}?%75selibpqcompat=true&sslmode=require`,
43
+ ]) {
44
+ expect(withExplicitSslMode(url)).toBe(url)
45
+ }
46
+ })
47
+
48
+ it('lets the last of a repeated parameter win, as pg does', () => {
49
+ expect(withExplicitSslMode(`${BASE}?sslmode=disable&sslmode=require`)).toBe(
50
+ `${BASE}?sslmode=disable&sslmode=verify-full`,
51
+ )
52
+ const disabledLast = `${BASE}?sslmode=require&sslmode=disable`
53
+ expect(withExplicitSslMode(disabledLast)).toBe(disabledLast)
54
+
55
+ const compatLast = `${BASE}?uselibpqcompat=false&sslmode=require&uselibpqcompat=true`
56
+ expect(withExplicitSslMode(compatLast)).toBe(compatLast)
57
+ expect(
58
+ withExplicitSslMode(`${BASE}?uselibpqcompat=true&sslmode=require&uselibpqcompat=false`),
59
+ ).toBe(`${BASE}?uselibpqcompat=true&sslmode=verify-full&uselibpqcompat=false`)
60
+ })
61
+
62
+ it('rewrites when the libpq flag is not the exact value pg honours', () => {
63
+ expect(withExplicitSslMode(`${BASE}?sslmode=require&uselibpqcompat=TRUE`)).toBe(
64
+ `${BASE}?sslmode=verify-full&uselibpqcompat=TRUE`,
65
+ )
66
+ })
67
+
68
+ it('keeps a fragment out of the sslmode value', () => {
69
+ expect(withExplicitSslMode(`${BASE}?sslmode=require#frag`)).toBe(
70
+ `${BASE}?sslmode=verify-full#frag`,
71
+ )
72
+ })
73
+
74
+ it('passes an unset connection string through', () => {
75
+ expect(withExplicitSslMode(undefined)).toBeUndefined()
76
+ expect(withExplicitSslMode('')).toBe('')
77
+ })
78
+ })
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
  import { pathToFileURL } from 'node:url'
4
4
 
5
5
  import { importProjectTypescript } from './import-typescript.js'
6
+ import { withExplicitSslMode } from './pg-ssl-mode.js'
6
7
  import { resolvePrismaClientLoadPlan } from './prisma-client-path.js'
7
8
 
8
9
  /**
@@ -115,7 +116,7 @@ async function createClientFromGenerated(generatedClient: string): Promise<any>
115
116
 
116
117
  const { PrismaPg } = adapterModule as { PrismaPg: new (pool: unknown) => unknown }
117
118
  const pg = (pgModule as { default?: typeof pgModule }).default ?? pgModule
118
- const pool = new (pg as any).Pool({ connectionString: url })
119
+ const pool = new (pg as any).Pool({ connectionString: withExplicitSslMode(url) })
119
120
  const adapter = new PrismaPg(pool)
120
121
  return new PrismaClient({ adapter } as any)
121
122
  }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Make a Postgres connection string's TLS mode explicit.
3
+ *
4
+ * `pg` 8 treats `sslmode=prefer`, `require` and `verify-ca` as aliases
5
+ * for `verify-full`, and logs a SECURITY WARNING the first time it parses
6
+ * one, to say that `pg` 9 will weaken them to libpq's meaning (no
7
+ * certificate verification for `require`). Hosted providers hand out
8
+ * `sslmode=require` strings, so the warning shows up on every cold start.
9
+ *
10
+ * Rewriting those modes to `verify-full` asks for exactly what `pg` 8
11
+ * already does: the warning stops, and full certificate verification stays
12
+ * when `pg` 9 arrives.
13
+ *
14
+ * A string that opts in to libpq semantics with `uselibpqcompat=true` is
15
+ * left alone, as is one with no `sslmode`, `sslmode=disable` or
16
+ * `sslmode=no-verify`.
17
+ *
18
+ * The query is read the way `pg` reads it: names and values are
19
+ * percent-decoded, and the last of a repeated parameter wins. Only the one
20
+ * `sslmode` segment that takes effect is replaced; every other character,
21
+ * credentials included, is returned as it was given.
22
+ *
23
+ * A copy of `packages/cms-core/src/db/pg-ssl-mode.ts`. The CLI supports
24
+ * older `@prenta/core` versions, so it cannot import this from core. Keep
25
+ * the two in step.
26
+ */
27
+ export function withExplicitSslMode<T extends string | undefined>(connectionString: T): T {
28
+ if (!connectionString) return connectionString
29
+ const queryStart = connectionString.indexOf('?')
30
+ if (queryStart === -1) return connectionString
31
+
32
+ const base = connectionString.slice(0, queryStart)
33
+ const afterQuestionMark = connectionString.slice(queryStart + 1)
34
+ const fragmentStart = afterQuestionMark.indexOf('#')
35
+ const query = fragmentStart === -1 ? afterQuestionMark : afterQuestionMark.slice(0, fragmentStart)
36
+ const fragment = fragmentStart === -1 ? '' : afterQuestionMark.slice(fragmentStart)
37
+
38
+ const params = new URLSearchParams(query)
39
+ // pg honours this flag only as the exact value "true".
40
+ if (params.getAll('uselibpqcompat').pop() === 'true') return connectionString
41
+ const mode = params.getAll('sslmode').pop()
42
+ if (mode !== 'prefer' && mode !== 'require' && mode !== 'verify-ca') return connectionString
43
+
44
+ const segments = query.split('&')
45
+ let effective = -1
46
+ segments.forEach((segment, index) => {
47
+ if (new URLSearchParams(segment).has('sslmode')) effective = index
48
+ })
49
+ if (effective === -1) return connectionString
50
+ segments[effective] = 'sslmode=verify-full'
51
+ return (base + '?' + segments.join('&') + fragment) as T
52
+ }