@prenta/cli 1.3.3 → 1.4.0

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.
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Reads a deployed `/api/cms/health` response for `prenta verify`.
3
+ *
4
+ * Answering is not the same as working: a deploy without a rate-limit store
5
+ * answers `/health` with `status: "unhealthy"` while refusing every sign-in
6
+ * and save (#1261), so the verdict comes from the body, not only the status.
7
+ */
8
+ export type HealthVerdict = 'pass' | 'warn' | 'fail';
9
+ export interface HealthCheckResult {
10
+ verdict: HealthVerdict;
11
+ /** One line per finding, the first being the summary. */
12
+ lines: string[];
13
+ }
14
+ export declare function checkHealthResponse(response: Response, url: string): Promise<HealthCheckResult>;
15
+ //# sourceMappingURL=health-check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health-check.d.ts","sourceRoot":"","sources":["../../src/deployment/health-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAEpD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,aAAa,CAAA;IACtB,yDAAyD;IACzD,KAAK,EAAE,MAAM,EAAE,CAAA;CAChB;AA4CD,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,iBAAiB,CAAC,CAoD5B"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Reads a deployed `/api/cms/health` response for `prenta verify`.
3
+ *
4
+ * Answering is not the same as working: a deploy without a rate-limit store
5
+ * answers `/health` with `status: "unhealthy"` while refusing every sign-in
6
+ * and save (#1261), so the verdict comes from the body, not only the status.
7
+ */
8
+ function readBody(json) {
9
+ if (!json || typeof json !== 'object')
10
+ return null;
11
+ const data = json.data;
12
+ if (!data || typeof data !== 'object')
13
+ return null;
14
+ return data;
15
+ }
16
+ /** Why the deploy reports itself unhealthy or degraded, as far as the body says. */
17
+ function reasons(body) {
18
+ const out = [];
19
+ if (body.rateLimitBackendReady === false) {
20
+ out.push('No rate-limit store: set UPSTASH_REDIS_REST_URL/TOKEN or add Upstash from the Vercel Marketplace (KV_REST_API_URL/TOKEN). Until then sign-in, setup and saves are refused with 503.');
21
+ }
22
+ if (body.trustedIpSource === false) {
23
+ out.push(body.trustProxyHint ?? 'No trusted client-IP source: set PRENTA_TRUST_PROXY=1.');
24
+ }
25
+ for (const check of body.env?.checks ?? []) {
26
+ if (check.status === 'error' || check.status === 'missing') {
27
+ out.push(`${check.name ?? 'env'}: ${check.message ?? check.status}`);
28
+ }
29
+ }
30
+ if (body.databaseConnected === false)
31
+ out.push('The database is not reachable.');
32
+ return out;
33
+ }
34
+ export async function checkHealthResponse(response, url) {
35
+ // Deployment Protection or an auth gate in front of the site: the route is
36
+ // there, but its report cannot be read.
37
+ if (response.status === 401 || response.status === 302) {
38
+ return {
39
+ verdict: 'warn',
40
+ lines: [
41
+ `Health route at ${url} answered HTTP ${response.status}, so its status could not be read (Deployment Protection?).`,
42
+ ],
43
+ };
44
+ }
45
+ let body = null;
46
+ try {
47
+ body = readBody(await response.json());
48
+ }
49
+ catch {
50
+ body = null;
51
+ }
52
+ if (!body?.status) {
53
+ return response.ok
54
+ ? {
55
+ verdict: 'warn',
56
+ lines: [
57
+ `Health route at ${url} answered HTTP ${response.status} without a health report.`,
58
+ ],
59
+ }
60
+ : { verdict: 'fail', lines: [`Health route returned HTTP ${response.status} at ${url}.`] };
61
+ }
62
+ if (body.status === 'unhealthy') {
63
+ return {
64
+ verdict: 'fail',
65
+ lines: [
66
+ `Health route at ${url} reports "unhealthy" (HTTP ${response.status}).`,
67
+ ...reasons(body),
68
+ ],
69
+ };
70
+ }
71
+ if (!response.ok) {
72
+ return {
73
+ verdict: 'fail',
74
+ lines: [`Health route returned HTTP ${response.status} at ${url} (status "${body.status}").`],
75
+ };
76
+ }
77
+ if (body.status === 'degraded') {
78
+ return {
79
+ verdict: 'warn',
80
+ lines: [`Health route at ${url} reports "degraded".`, ...reasons(body)],
81
+ };
82
+ }
83
+ return { verdict: 'pass', lines: [`Health route at ${url} reports "${body.status}".`] };
84
+ }
85
+ //# sourceMappingURL=health-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health-check.js","sourceRoot":"","sources":["../../src/deployment/health-check.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAyBH,SAAS,QAAQ,CAAC,IAAa;IAC7B,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAClD,MAAM,IAAI,GAAI,IAA2B,CAAC,IAAI,CAAA;IAC9C,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAClD,OAAO,IAAkB,CAAA;AAC3B,CAAC;AAED,oFAAoF;AACpF,SAAS,OAAO,CAAC,IAAgB;IAC/B,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,IAAI,IAAI,CAAC,qBAAqB,KAAK,KAAK,EAAE,CAAC;QACzC,GAAG,CAAC,IAAI,CACN,qLAAqL,CACtL,CAAA;IACH,CAAC;IACD,IAAI,IAAI,CAAC,eAAe,KAAK,KAAK,EAAE,CAAC;QACnC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,wDAAwD,CAAC,CAAA;IAC3F,CAAC;IACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC;QAC3C,IAAI,KAAK,CAAC,MAAM,KAAK,OAAO,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC3D,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;QACtE,CAAC;IACH,CAAC;IACD,IAAI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Q,CAAC,EAAE,EAAE,CAAC;QACjB,OAAO;YACL,OAAO,EAAE,MAAM;YACf,KAAK,EAAE,CAAC,8BAA8B,QAAQ,CAAC,MAAM,OAAO,GAAG,aAAa,IAAI,CAAC,MAAM,KAAK,CAAC;SAC9F,CAAA;IACH,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;QAC/B,OAAO;YACL,OAAO,EAAE,MAAM;YACf,KAAK,EAAE,CAAC,mBAAmB,GAAG,sBAAsB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;SACxE,CAAA;IACH,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,mBAAmB,GAAG,aAAa,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAA;AACzF,CAAC"}
@@ -19,7 +19,17 @@ export interface EnvMatrix {
19
19
  targets: VercelTarget[];
20
20
  }[];
21
21
  }
22
- export declare function buildEnvMatrix(envVars: VercelEnvVar[], requiredKeys: readonly string[], optionalKeys?: readonly string[]): EnvMatrix;
22
+ /**
23
+ * A requirement any one of several sets of variables satisfies, such as the
24
+ * rate-limit store, which reads either the Upstash console names or the names
25
+ * Vercel Marketplace Upstash provisions.
26
+ */
27
+ export interface RequiredOneOf {
28
+ /** Shown in `missingCritical` when no alternative is complete on a target. */
29
+ label: string;
30
+ alternatives: readonly (readonly string[])[];
31
+ }
32
+ export declare function buildEnvMatrix(envVars: VercelEnvVar[], requiredKeys: readonly string[], optionalKeys?: readonly string[], requiredOneOf?: readonly RequiredOneOf[]): EnvMatrix;
23
33
  export type BlobLinkStatus = 'ok' | 'partial' | 'none';
24
34
  export interface BlobLinkReport {
25
35
  /** True when any BLOB_* var indicates a store is connected to the project. */
@@ -1 +1 @@
1
- {"version":3,"file":"env-matrix.d.ts","sourceRoot":"","sources":["../../src/vercel/env-matrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,YAAY,EAAE,KAAK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  }
19
19
  /** Production and preview are the deploy-blocking targets; development is local-only. */
20
20
  const DEPLOY_TARGETS = ['production', 'preview'];
21
- export function buildEnvMatrix(envVars, requiredKeys, optionalKeys = []) {
21
+ export function buildEnvMatrix(envVars, requiredKeys, optionalKeys = [], requiredOneOf = []) {
22
22
  const rows = [];
23
23
  const seen = new Set();
24
24
  const missingCritical = [];
@@ -36,6 +36,11 @@ export function buildEnvMatrix(envVars, requiredKeys, optionalKeys = []) {
36
36
  seen.add(key);
37
37
  rows.push({ key, required: false, presence: presenceForKey(envVars, key) });
38
38
  }
39
+ for (const requirement of requiredOneOf) {
40
+ const missing = DEPLOY_TARGETS.filter((target) => !requirement.alternatives.some((keys) => keys.every((key) => presenceForKey(envVars, key)[target])));
41
+ if (missing.length > 0)
42
+ missingCritical.push({ key: requirement.label, targets: missing });
43
+ }
39
44
  return { rows, missingCritical };
40
45
  }
41
46
  const BLOB_LINK_SIGNALS = ['BLOB_STORE_ID', 'BLOB_WEBHOOK_PUBLIC_KEY', 'BLOB_READ_WRITE_TOKEN'];
@@ -1 +1 @@
1
- {"version":3,"file":"env-matrix.js","sourceRoot":"","sources":["../../src/vercel/env-matrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwC,MAAM,aAAa,CAAA;AASlF,SAAS,aAAa;IACpB,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAA;AAClE,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,cAAc,CAAC,OAAuB,EAAE,GAAW;IACjE,MAAM,QAAQ,GAAG,aAAa,EAAE,CAAA;IAChC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,GAAG,CAAC,GAAG,KAAK,GAAG;YAAE,SAAQ;QAC7B,KAAK,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YAChC,IAAK,cAAoC,CAAC,QAAQ,CAAC,M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AAE/F,MAAM,UAAU,gBAAgB,CAAC,OAAuB;IACtD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CACzB,CAAC,GAAG,EAAE,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,OAAO,CAAC,CAC5E,CAAA;IACD,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAA;IACtE,MAAM,aAAa,GAAG,cAAc,CAAC,OAAO,EAAE,eAAe,CAAC,CAAA;IAE9D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,MAAM,EAAE,KAAK;YACb,aAAa;YACb,aAAa;YACb,cAAc,EAAE,EAAE;YAClB,MAAM,EAAE,MAAM;SACf,CAAA;IACH,CAAC;IAED,MAAM,aAAa,GAAG,CAAC,MAAoB,EAAE,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,CAAA;IAE9F,MAAM,cAAc,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IACtE,MAAM,eAAe,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;IACrE,OAAO;QACL,MAAM,EAAE,IAAI;QACZ,aAAa;QACb,aAAa;QACb,cAAc;QACd,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;KAC3C,CAAA;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prenta/cli",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "license": "MIT",
5
5
  "description": "CLI for Prenta CMS — migrations, codegen, imports, exports, and upgrades",
6
6
  "repository": {
@@ -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.22.0"
39
+ "@prenta/core": "8.23.0"
40
40
  },
41
41
  "scripts": {
42
42
  "build": "tsc",
@@ -0,0 +1,259 @@
1
+ /**
2
+ * #1261: a production deploy without a rate-limit store refuses sign-in,
3
+ * setup and saves. `prenta doctor` / `deploy:check` must say so before the
4
+ * deploy, and `prenta verify` must not pass a deploy whose /health says
5
+ * "unhealthy".
6
+ */
7
+ import { Command } from 'commander'
8
+ import { afterEach, describe, expect, it, vi } from 'vitest'
9
+
10
+ import { registerVerifyCommand } from '../commands/doctor.js'
11
+ import {
12
+ createDiagnosticReport,
13
+ detectRateLimitBackend,
14
+ VERCEL_MATRIX_OPTIONAL,
15
+ VERCEL_MATRIX_REQUIRED,
16
+ VERCEL_MATRIX_REQUIRED_ONE_OF,
17
+ } from '../deployment/diagnostics.js'
18
+ import { checkHealthResponse } from '../deployment/health-check.js'
19
+ import type { VercelEnvVar } from '../vercel/client.js'
20
+ import { buildEnvMatrix } from '../vercel/env-matrix.js'
21
+
22
+ const BASE_ENV = {
23
+ DATABASE_URL: 'postgresql://example',
24
+ DIRECT_DATABASE_URL: 'postgresql://example',
25
+ CMS_SECRET: 'x'.repeat(40),
26
+ CMS_ENCRYPTION_KEY: 'ab'.repeat(32),
27
+ NEXT_PUBLIC_SITE_URL: 'https://example.com',
28
+ }
29
+
30
+ function rateLimitCheck(env: Record<string, string | undefined>, mode?: 'doctor' | 'deploy') {
31
+ const report = createDiagnosticReport({
32
+ schemaModels: new Set(),
33
+ env,
34
+ packageManager: 'pnpm',
35
+ schemaPath: 'prisma/schema.prisma',
36
+ mode,
37
+ })
38
+ return { report, check: report.checks.find((c) => c.id === 'rate-limit-backend') }
39
+ }
40
+
41
+ describe('rate-limit store check (doctor / deploy:check)', () => {
42
+ it('fails deploy:check when neither name pair is set, and names both', () => {
43
+ const { report, check } = rateLimitCheck(BASE_ENV, 'deploy')
44
+ expect(check?.status).toBe('fail')
45
+ expect(report.status).toBe('fail')
46
+ expect(check?.message).toContain('UPSTASH_REDIS_REST_URL')
47
+ expect(check?.message).toContain('KV_REST_API_URL')
48
+ expect(check?.message).toContain('503')
49
+ expect(check?.fix).toContain('Vercel Marketplace')
50
+ })
51
+
52
+ it('fails doctor when the environment is production', () => {
53
+ expect(rateLimitCheck({ ...BASE_ENV, NODE_ENV: 'production' }, 'doctor').check?.status).toBe(
54
+ 'fail',
55
+ )
56
+ expect(rateLimitCheck({ ...BASE_ENV, VERCEL_ENV: 'production' }, 'doctor').check?.status).toBe(
57
+ 'fail',
58
+ )
59
+ })
60
+
61
+ it('only warns in local doctor runs, where an in-memory limiter is used', () => {
62
+ expect(rateLimitCheck(BASE_ENV, 'doctor').check?.status).toBe('warn')
63
+ })
64
+
65
+ it('passes with the Vercel Marketplace KV_REST_API_* names', () => {
66
+ const { check } = rateLimitCheck(
67
+ { ...BASE_ENV, KV_REST_API_URL: 'https://kv.example.com', KV_REST_API_TOKEN: 't' },
68
+ 'deploy',
69
+ )
70
+ expect(check?.status).toBe('pass')
71
+ expect(check?.message).toContain('KV_REST_API_URL')
72
+ })
73
+
74
+ it('passes with the Upstash console names', () => {
75
+ const { check } = rateLimitCheck(
76
+ {
77
+ ...BASE_ENV,
78
+ UPSTASH_REDIS_REST_URL: 'https://u.example.com',
79
+ UPSTASH_REDIS_REST_TOKEN: 't',
80
+ },
81
+ 'deploy',
82
+ )
83
+ expect(check?.status).toBe('pass')
84
+ })
85
+
86
+ it('names the missing half of a half-set pair', () => {
87
+ const { check } = rateLimitCheck({ ...BASE_ENV, KV_REST_API_URL: 'https://kv' }, 'deploy')
88
+ expect(check?.status).toBe('fail')
89
+ expect(check?.message).toContain('UPSTASH_REDIS_REST_TOKEN (or KV_REST_API_TOKEN)')
90
+ })
91
+
92
+ it('mixes names per variable, like the core does', () => {
93
+ expect(
94
+ detectRateLimitBackend({ UPSTASH_REDIS_REST_URL: 'https://u', KV_REST_API_TOKEN: 't' }).state,
95
+ ).toBe('ok')
96
+ })
97
+ })
98
+
99
+ describe('deploy:check --vercel matrix', () => {
100
+ const env = (key: string, target: VercelEnvVar['target']): VercelEnvVar => ({ key, target })
101
+ const required = VERCEL_MATRIX_REQUIRED.map((key) =>
102
+ env(key, ['production', 'preview', 'development']),
103
+ )
104
+ const matrix = (vars: VercelEnvVar[]) =>
105
+ buildEnvMatrix(
106
+ [...required, ...vars],
107
+ VERCEL_MATRIX_REQUIRED,
108
+ VERCEL_MATRIX_OPTIONAL,
109
+ VERCEL_MATRIX_REQUIRED_ONE_OF,
110
+ )
111
+
112
+ it('blocks a project with no rate-limit store on production or preview', () => {
113
+ expect(matrix([]).missingCritical).toEqual([
114
+ {
115
+ key: expect.stringContaining('KV_REST_API_URL'),
116
+ targets: ['production', 'preview'],
117
+ },
118
+ ])
119
+ })
120
+
121
+ it('accepts the Marketplace KV names', () => {
122
+ const all: VercelEnvVar['target'] = ['production', 'preview']
123
+ expect(
124
+ matrix([env('KV_REST_API_URL', all), env('KV_REST_API_TOKEN', all)]).missingCritical,
125
+ ).toEqual([])
126
+ })
127
+
128
+ it('does not accept a pair split across targets', () => {
129
+ const result = matrix([
130
+ env('KV_REST_API_URL', ['production', 'preview']),
131
+ env('KV_REST_API_TOKEN', ['production']),
132
+ ])
133
+ expect(result.missingCritical).toEqual([
134
+ { key: expect.stringContaining('rate-limit'), targets: ['preview'] },
135
+ ])
136
+ })
137
+
138
+ it('shows both name pairs in the matrix', () => {
139
+ const keys = matrix([]).rows.map((r) => r.key)
140
+ expect(keys).toEqual(
141
+ expect.arrayContaining([
142
+ 'UPSTASH_REDIS_REST_URL',
143
+ 'UPSTASH_REDIS_REST_TOKEN',
144
+ 'KV_REST_API_URL',
145
+ 'KV_REST_API_TOKEN',
146
+ ]),
147
+ )
148
+ })
149
+ })
150
+
151
+ function healthResponse(data: unknown, status: number): Response {
152
+ return new Response(JSON.stringify({ data }), {
153
+ status,
154
+ headers: { 'Content-Type': 'application/json' },
155
+ })
156
+ }
157
+
158
+ const URL_ = 'https://example.com/api/cms/health'
159
+
160
+ describe('checkHealthResponse', () => {
161
+ it('fails an unhealthy deploy that answers 200 (cores before #1261)', async () => {
162
+ const result = await checkHealthResponse(
163
+ healthResponse({ status: 'unhealthy', rateLimitBackendReady: false }, 200),
164
+ URL_,
165
+ )
166
+ expect(result.verdict).toBe('fail')
167
+ expect(result.lines.join('\n')).toContain('KV_REST_API_URL')
168
+ })
169
+
170
+ it('fails an unhealthy deploy that answers 503 and says why', async () => {
171
+ const result = await checkHealthResponse(
172
+ healthResponse(
173
+ {
174
+ status: 'unhealthy',
175
+ rateLimitBackendReady: true,
176
+ trustedIpSource: false,
177
+ trustProxyHint: 'Set PRENTA_TRUST_PROXY=1 behind a trusted reverse proxy.',
178
+ env: { checks: [{ name: 'CMS_SECRET', status: 'error', message: 'too short' }] },
179
+ },
180
+ 503,
181
+ ),
182
+ URL_,
183
+ )
184
+ expect(result.verdict).toBe('fail')
185
+ expect(result.lines).toEqual(
186
+ expect.arrayContaining([
187
+ expect.stringContaining('PRENTA_TRUST_PROXY'),
188
+ 'CMS_SECRET: too short',
189
+ ]),
190
+ )
191
+ })
192
+
193
+ it('passes a healthy deploy', async () => {
194
+ expect(
195
+ (await checkHealthResponse(healthResponse({ status: 'healthy' }, 200), URL_)).verdict,
196
+ ).toBe('pass')
197
+ })
198
+
199
+ it('warns on degraded', async () => {
200
+ const result = await checkHealthResponse(
201
+ healthResponse({ status: 'degraded', databaseConnected: false }, 200),
202
+ URL_,
203
+ )
204
+ expect(result.verdict).toBe('warn')
205
+ })
206
+
207
+ it('warns, not passes, when Deployment Protection hides the report', async () => {
208
+ expect((await checkHealthResponse(new Response('', { status: 401 }), URL_)).verdict).toBe(
209
+ 'warn',
210
+ )
211
+ })
212
+
213
+ it('fails a 5xx without a report', async () => {
214
+ expect((await checkHealthResponse(new Response('oops', { status: 500 }), URL_)).verdict).toBe(
215
+ 'fail',
216
+ )
217
+ })
218
+ })
219
+
220
+ describe('prenta verify --url', () => {
221
+ afterEach(() => {
222
+ vi.unstubAllGlobals()
223
+ vi.restoreAllMocks()
224
+ process.exitCode = undefined
225
+ })
226
+
227
+ async function verify(health: () => Response): Promise<{ exitCode: unknown; out: string }> {
228
+ vi.stubGlobal(
229
+ 'fetch',
230
+ vi.fn(async (url: string) =>
231
+ url.endsWith('/api/cms/health') ? health() : new Response('', { status: 302 }),
232
+ ),
233
+ )
234
+ const lines: string[] = []
235
+ vi.spyOn(console, 'log').mockImplementation((...args: unknown[]) => {
236
+ lines.push(args.join(' '))
237
+ })
238
+ const program = new Command()
239
+ program.exitOverride()
240
+ registerVerifyCommand(program)
241
+ await program.parseAsync(['node', 'prenta', 'verify', '--full', '--url', 'https://example.com'])
242
+ return { exitCode: process.exitCode, out: lines.join('\n') }
243
+ }
244
+
245
+ it('fails when /health reports unhealthy, even with HTTP 200', async () => {
246
+ const { exitCode, out } = await verify(() =>
247
+ healthResponse({ status: 'unhealthy', rateLimitBackendReady: false }, 200),
248
+ )
249
+ expect(exitCode).toBe(1)
250
+ expect(out).toContain('FAIL')
251
+ expect(out).toContain('unhealthy')
252
+ })
253
+
254
+ it('passes when /health reports healthy', async () => {
255
+ const { exitCode, out } = await verify(() => healthResponse({ status: 'healthy' }, 200))
256
+ expect(exitCode).toBeUndefined()
257
+ expect(out).toContain('PASS Health route')
258
+ })
259
+ })
@@ -10,8 +10,10 @@ import {
10
10
  type ProjectFileSignals,
11
11
  VERCEL_MATRIX_OPTIONAL,
12
12
  VERCEL_MATRIX_REQUIRED,
13
+ VERCEL_MATRIX_REQUIRED_ONE_OF,
13
14
  type DiagnosticReport,
14
15
  } from '../deployment/diagnostics.js'
16
+ import { checkHealthResponse } from '../deployment/health-check.js'
15
17
  import {
16
18
  createVercelClient,
17
19
  readVercelLink,
@@ -231,7 +233,12 @@ async function runVercelMatrix(opts: {
231
233
  const client = createVercelClient({ token, teamId: link.orgId ?? opts.org })
232
234
  try {
233
235
  const envVars = await client.listProjectEnv(link.projectId)
234
- const matrix = buildEnvMatrix(envVars, VERCEL_MATRIX_REQUIRED, VERCEL_MATRIX_OPTIONAL)
236
+ const matrix = buildEnvMatrix(
237
+ envVars,
238
+ VERCEL_MATRIX_REQUIRED,
239
+ VERCEL_MATRIX_OPTIONAL,
240
+ VERCEL_MATRIX_REQUIRED_ONE_OF,
241
+ )
235
242
  if (!opts.json) {
236
243
  printEnvMatrix(matrix)
237
244
  if (matrix.missingCritical.length > 0) {
@@ -336,10 +343,22 @@ export function registerVerifyCommand(program: Command): void {
336
343
  const adminUrl = `${origin}${manifest.routes.adminDefault}`
337
344
  let failed = false
338
345
 
339
- for (const [label, url] of [
340
- ['Health', healthUrl],
341
- ['Admin', adminUrl],
342
- ] as const) {
346
+ try {
347
+ const health = await checkHealthResponse(
348
+ await fetch(healthUrl, { method: 'GET' }),
349
+ healthUrl,
350
+ )
351
+ if (health.verdict === 'fail') failed = true
352
+ const [summary, ...details] = health.lines
353
+ console.log(`${health.verdict.toUpperCase()} ${summary}`)
354
+ for (const line of details) console.log(chalk.dim(` ${line}`))
355
+ } catch (error) {
356
+ failed = true
357
+ const message = error instanceof Error ? error.message : String(error)
358
+ console.log(`FAIL Health route could not be reached at ${healthUrl}: ${message}`)
359
+ }
360
+
361
+ for (const [label, url] of [['Admin', adminUrl]] as const) {
343
362
  try {
344
363
  const response = await fetch(url, { method: 'GET' })
345
364
  if (response.ok || response.status === 302 || response.status === 401) {
@@ -51,11 +51,29 @@ export const VERCEL_MATRIX_REQUIRED = [
51
51
  /** Vars the matrix surfaces as advisory (feature-gated, not deploy-blocking). */
52
52
  export const VERCEL_MATRIX_OPTIONAL = [
53
53
  'BLOB_READ_WRITE_TOKEN',
54
+ // The rate-limit store: either pair. Shown here so both names appear; the
55
+ // either-or requirement is `VERCEL_MATRIX_REQUIRED_ONE_OF`.
54
56
  'UPSTASH_REDIS_REST_URL',
55
57
  'UPSTASH_REDIS_REST_TOKEN',
58
+ 'KV_REST_API_URL',
59
+ 'KV_REST_API_TOKEN',
56
60
  'RESEND_API_KEY',
57
61
  ] as const
58
62
 
63
+ /** The two names for the shared rate-limit store; either pair is enough. */
64
+ export const RATE_LIMIT_ENV_PAIRS = [
65
+ ['UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN'],
66
+ ['KV_REST_API_URL', 'KV_REST_API_TOKEN'],
67
+ ] as const
68
+
69
+ /** Deploy-blocking requirements any one of several variable sets satisfies. */
70
+ export const VERCEL_MATRIX_REQUIRED_ONE_OF = [
71
+ {
72
+ label: 'UPSTASH_REDIS_REST_URL/TOKEN or KV_REST_API_URL/TOKEN (rate-limit store)',
73
+ alternatives: RATE_LIMIT_ENV_PAIRS,
74
+ },
75
+ ] as const
76
+
59
77
  export interface DiagnosticInput {
60
78
  schemaModels: Set<string>
61
79
  schemaContent?: string
@@ -133,6 +151,79 @@ export function detectBlobLinkState(
133
151
  return hasPartialSignals ? 'partial' : 'none'
134
152
  }
135
153
 
154
+ export type RateLimitBackendState =
155
+ | { state: 'ok'; pair: readonly [string, string] }
156
+ | { state: 'partial'; missing: string[] }
157
+ | { state: 'none' }
158
+
159
+ /**
160
+ * Whether the shared rate-limit store is configured, under either the Upstash
161
+ * console names or the names Vercel Marketplace Upstash provisions. Mirrors
162
+ * `resolveUpstashCredentials` in `@prenta/core`, which takes `UPSTASH_*` first
163
+ * and falls back to `KV_REST_API_*` per variable.
164
+ */
165
+ export function detectRateLimitBackend(
166
+ env: Record<string, string | undefined>,
167
+ ): RateLimitBackendState {
168
+ const url = env.UPSTASH_REDIS_REST_URL || env.KV_REST_API_URL
169
+ const token = env.UPSTASH_REDIS_REST_TOKEN || env.KV_REST_API_TOKEN
170
+ if (url && token) {
171
+ const pair = RATE_LIMIT_ENV_PAIRS.find(([u, t]) => env[u] && env[t]) ?? RATE_LIMIT_ENV_PAIRS[0]
172
+ return { state: 'ok', pair }
173
+ }
174
+ if (!url && !token) return { state: 'none' }
175
+ return {
176
+ state: 'partial',
177
+ missing: url
178
+ ? ['UPSTASH_REDIS_REST_TOKEN (or KV_REST_API_TOKEN)']
179
+ : ['UPSTASH_REDIS_REST_URL (or KV_REST_API_URL)'],
180
+ }
181
+ }
182
+
183
+ function isProductionTarget(input: DiagnosticInput): boolean {
184
+ return (
185
+ input.mode === 'deploy' ||
186
+ input.env.NODE_ENV === 'production' ||
187
+ input.env.VERCEL_ENV === 'production'
188
+ )
189
+ }
190
+
191
+ /**
192
+ * In production every fail-closed limiter (writes, sign-in, setup, admin reads)
193
+ * refuses all requests with a 503 when no shared store is configured, so a
194
+ * deploy without one cannot be used (#1261). Locally it is only a warning: dev
195
+ * falls back to an in-memory counter.
196
+ */
197
+ function rateLimitBackendCheck(input: DiagnosticInput): DiagnosticCheck {
198
+ const backend = detectRateLimitBackend(input.env)
199
+ const label = 'Rate-limit store (Upstash Redis)'
200
+ const docs = 'https://prentacms.dev/docs/deployment'
201
+ const fix =
202
+ 'Add Upstash from the Vercel Marketplace (Storage tab, sets KV_REST_API_URL and KV_REST_API_TOKEN), or set UPSTASH_REDIS_REST_URL and UPSTASH_REDIS_REST_TOKEN from the Upstash console, then redeploy.'
203
+ if (backend.state === 'ok') {
204
+ return {
205
+ id: 'rate-limit-backend',
206
+ label,
207
+ status: 'pass',
208
+ message: `Shared rate-limit store configured (${backend.pair.join(' + ')}).`,
209
+ }
210
+ }
211
+ const production = isProductionTarget(input)
212
+ const consequence =
213
+ 'In production every write, sign-in, setup request and admin read is refused with HTTP 503 (rate_limit_backend_missing) until it is set.'
214
+ return {
215
+ id: 'rate-limit-backend',
216
+ label,
217
+ status: production ? 'fail' : 'warn',
218
+ message:
219
+ backend.state === 'partial'
220
+ ? `Rate-limit store is half configured: missing ${backend.missing.join(', ')}. ${consequence}`
221
+ : `Neither UPSTASH_REDIS_REST_URL + UPSTASH_REDIS_REST_TOKEN nor KV_REST_API_URL + KV_REST_API_TOKEN is set. ${consequence}${production ? '' : ' Local development uses an in-memory limiter.'}`,
222
+ fix,
223
+ docs,
224
+ }
225
+ }
226
+
136
227
  export function detectPackageManager(lockfiles: Set<string>): string {
137
228
  if (lockfiles.has('pnpm-lock.yaml')) return 'pnpm'
138
229
  if (lockfiles.has('yarn.lock')) return 'yarn'
@@ -200,6 +291,8 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
200
291
  docs: 'https://prentacms.dev/docs/environment-variables',
201
292
  })
202
293
 
294
+ checks.push(rateLimitBackendCheck(input))
295
+
203
296
  const blobState = detectBlobLinkState(input.env, input.configContent)
204
297
  checks.push({
205
298
  id: 'blob-storage',
@@ -493,10 +586,10 @@ export function buildDeploymentManifest() {
493
586
  'CMS_ADMIN_PASSWORD',
494
587
  'CRON_SECRET',
495
588
  'BLOB_READ_WRITE_TOKEN',
496
- 'UPSTASH_REDIS_REST_URL',
497
- 'UPSTASH_REDIS_REST_TOKEN',
498
589
  'RESEND_API_KEY',
499
590
  ],
591
+ /** Required in production; either pair satisfies it. */
592
+ rateLimitEnv: RATE_LIMIT_ENV_PAIRS.map((pair) => [...pair]),
500
593
  routes: {
501
594
  apiHealth: '/api/cms/health',
502
595
  apiBase: '/api/cms',