@prenta/cli 1.3.3 → 1.5.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.
Files changed (33) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-test.log +67 -53
  3. package/CHANGELOG.md +48 -0
  4. package/dist/commands/doctor.d.ts.map +1 -1
  5. package/dist/commands/doctor.js +86 -31
  6. package/dist/commands/doctor.js.map +1 -1
  7. package/dist/deployment/diagnostics.d.ts +67 -2
  8. package/dist/deployment/diagnostics.d.ts.map +1 -1
  9. package/dist/deployment/diagnostics.js +500 -90
  10. package/dist/deployment/diagnostics.js.map +1 -1
  11. package/dist/deployment/health-check.d.ts +15 -0
  12. package/dist/deployment/health-check.d.ts.map +1 -0
  13. package/dist/deployment/health-check.js +85 -0
  14. package/dist/deployment/health-check.js.map +1 -0
  15. package/dist/deployment/layout.d.ts +19 -0
  16. package/dist/deployment/layout.d.ts.map +1 -0
  17. package/dist/deployment/layout.js +67 -0
  18. package/dist/deployment/layout.js.map +1 -0
  19. package/dist/vercel/env-matrix.d.ts +11 -1
  20. package/dist/vercel/env-matrix.d.ts.map +1 -1
  21. package/dist/vercel/env-matrix.js +6 -1
  22. package/dist/vercel/env-matrix.js.map +1 -1
  23. package/package.json +3 -3
  24. package/src/__tests__/deployment-diagnostics.test.ts +1 -1
  25. package/src/__tests__/doctor-astro-split.test.ts +376 -0
  26. package/src/__tests__/doctor-env-shape-fallback.test.ts +44 -0
  27. package/src/__tests__/rate-limit-backend.test.ts +259 -0
  28. package/src/__tests__/vercel-cron-plan.test.ts +71 -0
  29. package/src/commands/doctor.ts +104 -29
  30. package/src/deployment/diagnostics.ts +569 -95
  31. package/src/deployment/health-check.ts +114 -0
  32. package/src/deployment/layout.ts +90 -0
  33. package/src/vercel/env-matrix.ts +22 -0
@@ -2,10 +2,16 @@ import { DB_BACKUP_WORKFLOW_PATH } from '../backup/workflow-template.js'
2
2
 
3
3
  export type DiagnosticStatus = 'pass' | 'warn' | 'fail'
4
4
 
5
+ /**
6
+ * A check's verdict. `skip` means the check could not run (its source file or
7
+ * env is not there) and says so, instead of passing on nothing (#1263).
8
+ */
9
+ export type DiagnosticCheckStatus = DiagnosticStatus | 'skip'
10
+
5
11
  export interface DiagnosticCheck {
6
12
  id: string
7
13
  label: string
8
- status: DiagnosticStatus
14
+ status: DiagnosticCheckStatus
9
15
  message: string
10
16
  fix?: string
11
17
  docs?: string
@@ -51,11 +57,29 @@ export const VERCEL_MATRIX_REQUIRED = [
51
57
  /** Vars the matrix surfaces as advisory (feature-gated, not deploy-blocking). */
52
58
  export const VERCEL_MATRIX_OPTIONAL = [
53
59
  'BLOB_READ_WRITE_TOKEN',
60
+ // The rate-limit store: either pair. Shown here so both names appear; the
61
+ // either-or requirement is `VERCEL_MATRIX_REQUIRED_ONE_OF`.
54
62
  'UPSTASH_REDIS_REST_URL',
55
63
  'UPSTASH_REDIS_REST_TOKEN',
64
+ 'KV_REST_API_URL',
65
+ 'KV_REST_API_TOKEN',
56
66
  'RESEND_API_KEY',
57
67
  ] as const
58
68
 
69
+ /** The two names for the shared rate-limit store; either pair is enough. */
70
+ export const RATE_LIMIT_ENV_PAIRS = [
71
+ ['UPSTASH_REDIS_REST_URL', 'UPSTASH_REDIS_REST_TOKEN'],
72
+ ['KV_REST_API_URL', 'KV_REST_API_TOKEN'],
73
+ ] as const
74
+
75
+ /** Deploy-blocking requirements any one of several variable sets satisfies. */
76
+ export const VERCEL_MATRIX_REQUIRED_ONE_OF = [
77
+ {
78
+ label: 'UPSTASH_REDIS_REST_URL/TOKEN or KV_REST_API_URL/TOKEN (rate-limit store)',
79
+ alternatives: RATE_LIMIT_ENV_PAIRS,
80
+ },
81
+ ] as const
82
+
59
83
  export interface DiagnosticInput {
60
84
  schemaModels: Set<string>
61
85
  schemaContent?: string
@@ -65,6 +89,17 @@ export interface DiagnosticInput {
65
89
  schemaPath: string
66
90
  mode?: 'doctor' | 'deploy'
67
91
  projectFiles?: ProjectFileSignals
92
+ /**
93
+ * `validateEnvShape` from `@prenta/core/diagnostics` over the CMS env, or
94
+ * `null` when the installed core predates that entry.
95
+ */
96
+ envShape?: EnvShapeSummary | null
97
+ }
98
+
99
+ /** The subset of core's `EnvCheckSummary` doctor reads. */
100
+ export interface EnvShapeSummary {
101
+ errorCount: number
102
+ checks: Array<{ name: string; status: string; message: string; required: boolean }>
68
103
  }
69
104
 
70
105
  /** Optional on-disk project signals for site-launch checks. */
@@ -86,6 +121,14 @@ export interface ProjectFileSignals {
86
121
  astroConfigPresent?: boolean
87
122
  /** True when `.github/workflows/db-backup.yml` exists (nightly `prenta db:backup`). */
88
123
  backupWorkflowPresent?: boolean
124
+ /** Raw `vercel.json` of the CMS host (project root, or `apps/cms` in astro-split). */
125
+ vercelJson?: string
126
+ /** Where the Astro site was found, relative to the doctor run (`apps/site`). */
127
+ siteLabel?: string
128
+ /** Raw `vercel.json` of the Astro site. */
129
+ siteVercelJson?: string
130
+ /** The Astro site's local .env files, or `undefined` when it has none. */
131
+ siteEnv?: Record<string, string | undefined>
89
132
  }
90
133
 
91
134
  export const RECOMMENDED_PRODUCTION_PLUGINS = [
@@ -133,6 +176,79 @@ export function detectBlobLinkState(
133
176
  return hasPartialSignals ? 'partial' : 'none'
134
177
  }
135
178
 
179
+ export type RateLimitBackendState =
180
+ | { state: 'ok'; pair: readonly [string, string] }
181
+ | { state: 'partial'; missing: string[] }
182
+ | { state: 'none' }
183
+
184
+ /**
185
+ * Whether the shared rate-limit store is configured, under either the Upstash
186
+ * console names or the names Vercel Marketplace Upstash provisions. Mirrors
187
+ * `resolveUpstashCredentials` in `@prenta/core`, which takes `UPSTASH_*` first
188
+ * and falls back to `KV_REST_API_*` per variable.
189
+ */
190
+ export function detectRateLimitBackend(
191
+ env: Record<string, string | undefined>,
192
+ ): RateLimitBackendState {
193
+ const url = env.UPSTASH_REDIS_REST_URL || env.KV_REST_API_URL
194
+ const token = env.UPSTASH_REDIS_REST_TOKEN || env.KV_REST_API_TOKEN
195
+ if (url && token) {
196
+ const pair = RATE_LIMIT_ENV_PAIRS.find(([u, t]) => env[u] && env[t]) ?? RATE_LIMIT_ENV_PAIRS[0]
197
+ return { state: 'ok', pair }
198
+ }
199
+ if (!url && !token) return { state: 'none' }
200
+ return {
201
+ state: 'partial',
202
+ missing: url
203
+ ? ['UPSTASH_REDIS_REST_TOKEN (or KV_REST_API_TOKEN)']
204
+ : ['UPSTASH_REDIS_REST_URL (or KV_REST_API_URL)'],
205
+ }
206
+ }
207
+
208
+ function isProductionTarget(input: DiagnosticInput): boolean {
209
+ return (
210
+ input.mode === 'deploy' ||
211
+ input.env.NODE_ENV === 'production' ||
212
+ input.env.VERCEL_ENV === 'production'
213
+ )
214
+ }
215
+
216
+ /**
217
+ * In production every fail-closed limiter (writes, sign-in, setup, admin reads)
218
+ * refuses all requests with a 503 when no shared store is configured, so a
219
+ * deploy without one cannot be used (#1261). Locally it is only a warning: dev
220
+ * falls back to an in-memory counter.
221
+ */
222
+ function rateLimitBackendCheck(input: DiagnosticInput): DiagnosticCheck {
223
+ const backend = detectRateLimitBackend(input.env)
224
+ const label = 'Rate-limit store (Upstash Redis)'
225
+ const docs = 'https://prentacms.dev/docs/deployment'
226
+ const fix =
227
+ '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.'
228
+ if (backend.state === 'ok') {
229
+ return {
230
+ id: 'rate-limit-backend',
231
+ label,
232
+ status: 'pass',
233
+ message: `Shared rate-limit store configured (${backend.pair.join(' + ')}).`,
234
+ }
235
+ }
236
+ const production = isProductionTarget(input)
237
+ const consequence =
238
+ 'In production every write, sign-in, setup request and admin read is refused with HTTP 503 (rate_limit_backend_missing) until it is set.'
239
+ return {
240
+ id: 'rate-limit-backend',
241
+ label,
242
+ status: production ? 'fail' : 'warn',
243
+ message:
244
+ backend.state === 'partial'
245
+ ? `Rate-limit store is half configured: missing ${backend.missing.join(', ')}. ${consequence}`
246
+ : `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.'}`,
247
+ fix,
248
+ docs,
249
+ }
250
+ }
251
+
136
252
  export function detectPackageManager(lockfiles: Set<string>): string {
137
253
  if (lockfiles.has('pnpm-lock.yaml')) return 'pnpm'
138
254
  if (lockfiles.has('yarn.lock')) return 'yarn'
@@ -200,32 +316,51 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
200
316
  docs: 'https://prentacms.dev/docs/environment-variables',
201
317
  })
202
318
 
319
+ checks.push(rateLimitBackendCheck(input))
320
+
203
321
  const blobState = detectBlobLinkState(input.env, input.configContent)
204
- checks.push({
205
- id: 'blob-storage',
206
- label: 'Vercel Blob storage',
207
- status: blobState === 'partial' ? 'fail' : blobState === 'token-format' ? 'warn' : 'pass',
208
- message:
209
- blobState === 'partial'
210
- ? 'Vercel Blob appears configured (vercel-blob / webhook key) but BLOB_STORE_ID is missing. Media uploads will fail until the store is connected to this project.'
211
- : blobState === 'token-format'
212
- ? 'BLOB_READ_WRITE_TOKEN does not start with `vercel_blob_` — verify it is a real Vercel Blob read-write token.'
213
- : blobState === 'ok'
214
- ? input.env.BLOB_READ_WRITE_TOKEN
215
- ? 'BLOB_READ_WRITE_TOKEN is configured.'
216
- : 'Vercel Marketplace Blob is linked (BLOB_STORE_ID). Uploads use OIDC on Vercel; no read-write token required.'
217
- : 'No Vercel Blob storage configured (skipped).',
218
- fix:
219
- blobState === 'partial'
220
- ? 'Connect a Vercel Blob store to the project from the Storage tab, then `vercel env pull`. Validate with `prenta vercel:blob-link`.'
221
- : blobState === 'token-format'
222
- ? 'Re-copy the read-write token from the Vercel Blob store (Storage tab) and re-pull your environment.'
322
+ const blobRegistered = /createBlobAdapter\s*\(/.test(input.projectFiles?.apiRoute ?? '')
323
+ if (blobState === 'none' && blobRegistered) {
324
+ checks.push({
325
+ id: 'blob-storage',
326
+ label: 'Vercel Blob storage',
327
+ status: isProductionTarget(input) ? 'fail' : 'warn',
328
+ message:
329
+ 'The CMS API route registers createBlobAdapter(), but no Blob store is linked (no BLOB_STORE_ID or BLOB_READ_WRITE_TOKEN). Media uploads will fail.',
330
+ fix: 'Connect a Vercel Blob store to the project from the Storage tab, then `vercel env pull`. Validate with `prenta vercel:blob-link`.',
331
+ docs: 'https://prentacms.dev/docs/deployment',
332
+ })
333
+ } else
334
+ checks.push({
335
+ id: 'blob-storage',
336
+ label: 'Vercel Blob storage',
337
+ status: blobState === 'partial' ? 'fail' : blobState === 'token-format' ? 'warn' : 'pass',
338
+ message:
339
+ blobState === 'partial'
340
+ ? 'Vercel Blob appears configured (vercel-blob / webhook key) but BLOB_STORE_ID is missing. Media uploads will fail until the store is connected to this project.'
341
+ : blobState === 'token-format'
342
+ ? 'BLOB_READ_WRITE_TOKEN does not start with `vercel_blob_` — verify it is a real Vercel Blob read-write token.'
343
+ : blobState === 'ok'
344
+ ? input.env.BLOB_READ_WRITE_TOKEN
345
+ ? 'BLOB_READ_WRITE_TOKEN is configured.'
346
+ : 'Vercel Marketplace Blob is linked (BLOB_STORE_ID). Uploads use OIDC on Vercel; no read-write token required.'
347
+ : 'No Vercel Blob storage configured, and the API route does not register a Blob adapter.',
348
+ fix:
349
+ blobState === 'partial'
350
+ ? 'Connect a Vercel Blob store to the project from the Storage tab, then `vercel env pull`. Validate with `prenta vercel:blob-link`.'
351
+ : blobState === 'token-format'
352
+ ? 'Re-copy the read-write token from the Vercel Blob store (Storage tab) and re-pull your environment.'
353
+ : undefined,
354
+ docs:
355
+ blobState === 'partial' || blobState === 'token-format'
356
+ ? 'https://prentacms.dev/docs/deployment'
223
357
  : undefined,
224
- docs:
225
- blobState === 'partial' || blobState === 'token-format'
226
- ? 'https://prentacms.dev/docs/deployment'
227
- : undefined,
228
- })
358
+ })
359
+
360
+ checks.push(envShapeCheck(input))
361
+ checks.push(cronSecretCheck(input))
362
+ const emailCheck = emailProviderCheck(input)
363
+ if (emailCheck) checks.push(emailCheck)
229
364
 
230
365
  checks.push({
231
366
  id: 'package-manager',
@@ -271,30 +406,44 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
271
406
  })
272
407
 
273
408
  const seoSiteUrlOk = detectSeoSiteUrl(input.configContent, input.env)
274
- checks.push({
275
- id: 'seo-site-url',
276
- label: 'SEO site URL',
277
- status: seoSiteUrlOk ? 'pass' : 'warn',
278
- message: seoSiteUrlOk
279
- ? 'Production site URL is configured via NEXT_PUBLIC_SITE_URL and/or prenta.config.ts seo.siteUrl.'
280
- : 'Neither NEXT_PUBLIC_SITE_URL nor prenta.config.ts seo.siteUrl appears configured — canonical URLs, sitemaps, and JSON-LD may be wrong.',
281
- fix: seoSiteUrlOk
282
- ? undefined
283
- : 'Set NEXT_PUBLIC_SITE_URL to your production origin (no trailing slash) and align prenta.config.ts seo.siteUrl.',
284
- docs: seoSiteUrlOk ? undefined : 'https://prentacms.dev/docs/environment-variables',
285
- })
409
+ const siteUrlProblem = seoSiteUrlOk
410
+ ? productionOriginProblem(input.env.NEXT_PUBLIC_SITE_URL)
411
+ : null
412
+ if (siteUrlProblem) {
413
+ checks.push({
414
+ id: 'seo-site-url',
415
+ label: 'SEO site URL',
416
+ status: isProductionTarget(input) ? 'fail' : 'warn',
417
+ message: `NEXT_PUBLIC_SITE_URL is ${siteUrlProblem}. In production, canonical URLs, sitemaps, feeds and JSON-LD would point there.`,
418
+ fix: 'Set NEXT_PUBLIC_SITE_URL to the public https origin (no trailing slash) in the production environment.',
419
+ docs: 'https://prentacms.dev/docs/environment-variables',
420
+ })
421
+ } else
422
+ checks.push({
423
+ id: 'seo-site-url',
424
+ label: 'SEO site URL',
425
+ status: seoSiteUrlOk ? 'pass' : 'warn',
426
+ message: seoSiteUrlOk
427
+ ? 'Production site URL is configured via NEXT_PUBLIC_SITE_URL and/or prenta.config.ts seo.siteUrl.'
428
+ : 'Neither NEXT_PUBLIC_SITE_URL nor prenta.config.ts seo.siteUrl appears configured — canonical URLs, sitemaps, and JSON-LD may be wrong.',
429
+ fix: seoSiteUrlOk
430
+ ? undefined
431
+ : 'Set NEXT_PUBLIC_SITE_URL to your production origin (no trailing slash) and align prenta.config.ts seo.siteUrl.',
432
+ docs: seoSiteUrlOk ? undefined : 'https://prentacms.dev/docs/environment-variables',
433
+ })
286
434
 
287
435
  if (input.projectFiles) {
288
436
  const astroSplit = detectsAstroSplitSite(input.projectFiles)
437
+ const siteDir = input.projectFiles.siteLabel ?? 'site'
289
438
  if (astroSplit) {
290
439
  checks.push({
291
440
  id: 'astro-split-site',
292
441
  label: 'Astro public site (split)',
293
442
  status: 'pass',
294
- message:
295
- 'Detected an Astro public site (site/) using Prenta site helpers — CMS host should serve admin + /api/cms only.',
443
+ message: `Detected an Astro public site in ${siteDir}/. The CMS host serves the admin and /api/cms only.`,
296
444
  docs: 'https://prentacms.dev/docs/astro-public-site',
297
445
  })
446
+ checks.push(...astroSiteChecks(input, siteDir))
298
447
 
299
448
  const astroCmsOk = detectsAstroCmsHelpers(input.projectFiles)
300
449
  checks.push({
@@ -303,10 +452,10 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
303
452
  status: astroCmsOk ? 'pass' : 'warn',
304
453
  message: astroCmsOk
305
454
  ? 'Astro site uses createAstroSiteHelpers / PRENTA_CMS_URL.'
306
- : 'Astro site/ is present but src/lib/cms.ts does not use createAstroSiteHelpers or PRENTA_CMS_URL.',
455
+ : `${siteDir}/src/lib/cms.ts does not use createAstroSiteHelpers or PRENTA_CMS_URL.`,
307
456
  fix: astroCmsOk
308
457
  ? undefined
309
- : 'In site/src/lib/cms.ts import createAstroSiteHelpers from @prenta/core/astro/site and set PRENTA_CMS_URL.',
458
+ : `In ${siteDir}/src/lib/cms.ts import createAstroSiteHelpers from @prenta/core/astro/site and set PRENTA_CMS_URL.`,
310
459
  docs: 'https://prentacms.dev/docs/astro-public-site',
311
460
  })
312
461
  }
@@ -329,66 +478,104 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
329
478
  docs: seoOk ? undefined : 'https://prentacms.dev/docs/prototype-to-production',
330
479
  })
331
480
 
332
- const uncachedResolve = !astroSplit && detectsUncachedResolvePattern(input.projectFiles)
333
- checks.push({
334
- id: 'cached-resolve',
335
- label: 'Cached /resolve for ISR',
336
- status: uncachedResolve ? 'warn' : 'pass',
337
- message: uncachedResolve
338
- ? 'The public catch-all appears to call resolveDocument() directly for metadata and page renders without createNextSiteHelpers() caching — ISR may be blocked and /resolve may be hit twice per request.'
339
- : astroSplit
340
- ? 'Astro split deploy: use CMS CDN/runtime cache (layers 1–2); Next ISR helpers are optional on the CMS host.'
481
+ const hasCatchAll = Boolean(input.projectFiles.catchAllPage?.trim())
482
+ const noCatchAll = astroSplit
483
+ ? 'Astro split deploy: the public pages are on the Astro site, so this Next catch-all check does not apply.'
484
+ : 'No Next catch-all page (app/(site)/[[...path]]/page.tsx or app/[[...path]]/page.tsx) found, so this was not checked.'
485
+ const uncachedResolve = detectsUncachedResolvePattern(input.projectFiles)
486
+ if (astroSplit || !hasCatchAll) {
487
+ checks.push(
488
+ {
489
+ id: 'cached-resolve',
490
+ label: 'Cached /resolve for ISR',
491
+ status: 'skip',
492
+ message: noCatchAll,
493
+ },
494
+ {
495
+ id: 'public-sections-ssr',
496
+ label: 'Public sections SSR',
497
+ status: 'skip',
498
+ message: noCatchAll,
499
+ },
500
+ {
501
+ id: 'structured-data-html',
502
+ label: 'JSON-LD in page HTML',
503
+ status: 'skip',
504
+ message: noCatchAll,
505
+ },
506
+ )
507
+ } else
508
+ checks.push({
509
+ id: 'cached-resolve',
510
+ label: 'Cached /resolve for ISR',
511
+ status: uncachedResolve ? 'warn' : 'pass',
512
+ message: uncachedResolve
513
+ ? 'The public catch-all appears to call resolveDocument() directly for metadata and page renders without createNextSiteHelpers() caching — ISR may be blocked and /resolve may be hit twice per request.'
341
514
  : 'Published pages use cached /resolve helpers suitable for ISR.',
342
- fix: uncachedResolve
343
- ? 'Adopt createNextSiteHelpers() from @prenta/core/next/site in lib/cms.ts and use getCachedPageMetadata / getCachedPublishedDocument in the catch-all (keep resolveDocument only for ?preview= drafts).'
344
- : undefined,
345
- docs: uncachedResolve ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
346
- })
515
+ fix: uncachedResolve
516
+ ? 'Adopt createNextSiteHelpers() from @prenta/core/next/site in lib/cms.ts and use getCachedPageMetadata / getCachedPublishedDocument in the catch-all (keep resolveDocument only for ?preview= drafts).'
517
+ : undefined,
518
+ docs: uncachedResolve ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
519
+ })
347
520
 
348
- const clientSections = !astroSplit && detectsClientWrappedPublicSections(input.projectFiles)
349
- checks.push({
350
- id: 'public-sections-ssr',
351
- label: 'Public sections SSR',
352
- status: clientSections ? 'warn' : 'pass',
353
- message: clientSections
354
- ? "The public catch-all or its sections wrapper is marked 'use client' — keep <Sections> in a Server Component so HTML ships in the initial response."
355
- : astroSplit
356
- ? 'Astro split: render sections via @astrojs/react SSR (no client-only catch-all).'
521
+ const clientSections = detectsClientWrappedPublicSections(input.projectFiles)
522
+ if (!astroSplit && hasCatchAll)
523
+ checks.push({
524
+ id: 'public-sections-ssr',
525
+ label: 'Public sections SSR',
526
+ status: clientSections ? 'warn' : 'pass',
527
+ message: clientSections
528
+ ? "The public catch-all or its sections wrapper is marked 'use client' — keep <Sections> in a Server Component so HTML ships in the initial response."
357
529
  : 'Public page sections render from a Server Component catch-all.',
358
- fix: clientSections
359
- ? "Remove 'use client' from the catch-all and any PageSections wrapper; register section renderers via a side-effect import in the site layout instead."
360
- : undefined,
361
- docs: clientSections ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
362
- })
530
+ fix: clientSections
531
+ ? "Remove 'use client' from the catch-all and any PageSections wrapper; register section renderers via a side-effect import in the site layout instead."
532
+ : undefined,
533
+ docs: clientSections ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
534
+ })
363
535
 
364
536
  const missingJsonLd =
365
537
  !astroSplit && detectsMissingJsonLdInCatchAll(input.projectFiles.catchAllPage)
366
- checks.push({
367
- id: 'structured-data-html',
368
- label: 'JSON-LD in page HTML',
369
- status: missingJsonLd ? 'warn' : 'pass',
370
- message: missingJsonLd
371
- ? 'The public catch-all does not render JSON-LD from /resolve — Rich Results and some AI crawlers expect structured data in the HTML body.'
372
- : 'Published pages inject JSON-LD from cms-core into the server-rendered HTML.',
373
- fix: missingJsonLd
374
- ? 'Render result.jsonLd as a <script type="application/ld+json"> in the catch-all (see create-prenta scaffold).'
375
- : undefined,
376
- docs: missingJsonLd ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
377
- })
538
+ if (!astroSplit && hasCatchAll)
539
+ checks.push({
540
+ id: 'structured-data-html',
541
+ label: 'JSON-LD in page HTML',
542
+ status: missingJsonLd ? 'warn' : 'pass',
543
+ message: missingJsonLd
544
+ ? 'The public catch-all does not render JSON-LD from /resolve — Rich Results and some AI crawlers expect structured data in the HTML body.'
545
+ : 'Published pages inject JSON-LD from cms-core into the server-rendered HTML.',
546
+ fix: missingJsonLd
547
+ ? 'Render result.jsonLd as a <script type="application/ld+json"> in the catch-all (see create-prenta scaffold).'
548
+ : undefined,
549
+ docs: missingJsonLd ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
550
+ })
378
551
 
379
552
  const missingApiCache = detectsMissingApiCacheWiring(input.projectFiles.apiRoute)
380
- checks.push({
381
- id: 'api-cache-invalidation',
382
- label: 'CMS API cache + invalidation',
383
- status: missingApiCache ? 'warn' : 'pass',
384
- message: missingApiCache
385
- ? 'The CMS API route is missing publicReads caching and/or onInvalidate → revalidateTag wiring — /resolve may hit Postgres every request and ISR may stay stale after publish.'
386
- : 'CMS public reads are CDN-cacheable and writes drain Next ISR via onInvalidate.',
387
- fix: missingApiCache
388
- ? 'Adopt the cache block from create-prenta app/api/cms/[[...cms]]/route.ts (publicReads + onInvalidate with revalidateTag).'
389
- : undefined,
390
- docs: missingApiCache ? 'https://prentacms.dev/docs/caching' : undefined,
391
- })
553
+ if (!input.projectFiles.apiRoute?.trim()) {
554
+ checks.push({
555
+ id: 'api-cache-invalidation',
556
+ label: 'CMS API cache + invalidation',
557
+ status: 'skip',
558
+ message:
559
+ 'No CMS API route (app/api/cms/[[...cms]]/route.ts) found, so this was not checked.',
560
+ })
561
+ } else
562
+ checks.push({
563
+ id: 'api-cache-invalidation',
564
+ label: 'CMS API cache + invalidation',
565
+ status: missingApiCache ? 'warn' : 'pass',
566
+ message: missingApiCache
567
+ ? 'The CMS API route is missing publicReads caching and/or onInvalidate → revalidateTag wiring — /resolve may hit Postgres every request and ISR may stay stale after publish.'
568
+ : 'CMS public reads are CDN-cacheable and writes drain Next ISR via onInvalidate.',
569
+ fix: missingApiCache
570
+ ? 'Adopt the cache block from create-prenta app/api/cms/[[...cms]]/route.ts (publicReads + onInvalidate with revalidateTag).'
571
+ : undefined,
572
+ docs: missingApiCache ? 'https://prentacms.dev/docs/caching' : undefined,
573
+ })
574
+
575
+ if (input.projectFiles.vercelJson) {
576
+ const cronCheck = vercelCronPlanCheck(input.projectFiles.vercelJson)
577
+ if (cronCheck) checks.push(cronCheck)
578
+ }
392
579
 
393
580
  if (input.projectFiles.backupWorkflowPresent !== undefined) {
394
581
  checks.push(
@@ -451,6 +638,241 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
451
638
  return { status, checks }
452
639
  }
453
640
 
641
+ /**
642
+ * Why a site origin is not a production origin, or `null` when it is one:
643
+ * localhost, a loopback address, or plain http.
644
+ */
645
+ export function productionOriginProblem(value: string | undefined): string | null {
646
+ const raw = value?.trim()
647
+ if (!raw) return null
648
+ let url: URL
649
+ try {
650
+ url = new URL(raw)
651
+ } catch {
652
+ return `not a valid URL ("${raw}")`
653
+ }
654
+ const host = url.hostname
655
+ if (
656
+ host === 'localhost' ||
657
+ host.endsWith('.localhost') ||
658
+ host === '127.0.0.1' ||
659
+ host === '[::1]' ||
660
+ host === '0.0.0.0'
661
+ ) {
662
+ return `a local address (${url.origin})`
663
+ }
664
+ if (url.protocol !== 'https:') return `not https (${url.origin})`
665
+ return null
666
+ }
667
+
668
+ /** The env value rules /health applies, surfaced before deploy (#1263). */
669
+ function envShapeCheck(input: DiagnosticInput): DiagnosticCheck {
670
+ const label = 'Environment variable values'
671
+ const docs = 'https://prentacms.dev/docs/environment-variables'
672
+ if (!input.envShape) {
673
+ return {
674
+ id: 'env-shape',
675
+ label,
676
+ status: 'skip',
677
+ message:
678
+ 'The installed @prenta/core has no @prenta/core/diagnostics entry, so only presence was checked. Update @prenta/core for value checks (secret length, key format, placeholders).',
679
+ }
680
+ }
681
+ // Variables another check owns, with context this one lacks: Blob (an OIDC
682
+ // store needs no token, and VERCEL_OIDC_TOKEN only exists at runtime on
683
+ // Vercel), the rate-limit store (either name pair), email (Settings > Email
684
+ // counts too), and plain presence (the `environment` check).
685
+ const ownedElsewhere = new Set([
686
+ 'BLOB_READ_WRITE_TOKEN',
687
+ 'UPSTASH_REDIS_REST_URL',
688
+ 'UPSTASH_REDIS_REST_TOKEN',
689
+ 'RESEND_API_KEY',
690
+ 'CRON_SECRET',
691
+ ])
692
+ const relevant = input.envShape.checks.filter((c) => !ownedElsewhere.has(c.name))
693
+ // Malformed values only: a missing variable is the `environment` check's.
694
+ const errors = relevant.filter((c) => c.status === 'error')
695
+ if (errors.length > 0) {
696
+ return {
697
+ id: 'env-shape',
698
+ label,
699
+ // Like the other new checks: a failure for deploy:check and production,
700
+ // a warning while developing (a local dev key is normal there).
701
+ status: isProductionTarget(input) ? 'fail' : 'warn',
702
+ message: `Invalid environment variables: ${errors.map((c) => `${c.name} (${c.message})`).join('; ')}`,
703
+ fix: 'Fix each value. /api/cms/health reports these as unhealthy too.',
704
+ docs,
705
+ }
706
+ }
707
+ const warnings = relevant.filter((c) => c.status === 'warn')
708
+ if (warnings.length > 0) {
709
+ return {
710
+ id: 'env-shape',
711
+ label,
712
+ status: 'warn',
713
+ message: warnings.map((c) => `${c.name}: ${c.message}`).join('; '),
714
+ docs,
715
+ }
716
+ }
717
+ return {
718
+ id: 'env-shape',
719
+ label,
720
+ status: 'pass',
721
+ message: 'Environment variable values pass the checks /api/cms/health runs.',
722
+ }
723
+ }
724
+
725
+ /** Every /cron route answers 401 to everyone without CRON_SECRET, so nothing scheduled runs. */
726
+ function cronSecretCheck(input: DiagnosticInput): DiagnosticCheck {
727
+ const secret = input.env.CRON_SECRET?.trim() ?? ''
728
+ // Core's rules also catch a placeholder value; they own the wording for it.
729
+ const shapeError = input.envShape?.checks.find(
730
+ (c) => c.name === 'CRON_SECRET' && c.status === 'error',
731
+ )
732
+ if (secret && shapeError) {
733
+ return {
734
+ id: 'cron-secret',
735
+ label: 'Cron secret',
736
+ status: isProductionTarget(input) ? 'fail' : 'warn',
737
+ message: `CRON_SECRET: ${shapeError.message}`,
738
+ fix: 'Set CRON_SECRET to a random string of 16+ characters (for example `openssl rand -hex 32`).',
739
+ docs: 'https://prentacms.dev/docs/deployment',
740
+ }
741
+ }
742
+ if (secret.length >= 16) {
743
+ return {
744
+ id: 'cron-secret',
745
+ label: 'Cron secret',
746
+ status: 'pass',
747
+ message: 'CRON_SECRET is set.',
748
+ }
749
+ }
750
+ return {
751
+ id: 'cron-secret',
752
+ label: 'Cron secret',
753
+ status: isProductionTarget(input) ? 'fail' : 'warn',
754
+ message: secret
755
+ ? 'CRON_SECRET is shorter than 16 characters.'
756
+ : 'CRON_SECRET is not set. Every /api/cms/cron/* route then answers 401, so scheduled publishing, cleanup and SEO jobs never run.',
757
+ fix: 'Set CRON_SECRET to a random string of 16+ characters (for example `openssl rand -hex 32`) in the production environment. Vercel sends it to the crons automatically.',
758
+ docs: 'https://prentacms.dev/docs/deployment',
759
+ }
760
+ }
761
+
762
+ /** Without a provider, password-reset, invite and notification mail is skipped silently. */
763
+ function emailProviderCheck(input: DiagnosticInput): DiagnosticCheck | null {
764
+ if (!/emailPlugin\s*\(/.test(input.configContent ?? '')) return null
765
+ const env = input.env
766
+ const provider = env.EMAIL_PROVIDER?.trim()
767
+ const configured =
768
+ provider === 'smtp'
769
+ ? Boolean(env.SMTP_HOST)
770
+ : provider === 'ses'
771
+ ? Boolean(env.SES_REGION || env.AWS_REGION)
772
+ : provider === 'smtpcom'
773
+ ? Boolean(env.SMTPCOM_API_KEY || env.SMTP_KEY)
774
+ : provider === 'resend'
775
+ ? Boolean(env.RESEND_API_KEY)
776
+ : Boolean(env.SMTP_HOST || env.SMTPCOM_API_KEY || env.SMTP_KEY || env.RESEND_API_KEY)
777
+ if (configured) {
778
+ return {
779
+ id: 'email-provider',
780
+ label: 'Email provider',
781
+ status: 'pass',
782
+ message: 'A transactional email provider is configured.',
783
+ }
784
+ }
785
+ return {
786
+ id: 'email-provider',
787
+ label: 'Email provider',
788
+ status: 'warn',
789
+ message:
790
+ 'emailPlugin() is registered but no provider is configured (RESEND_API_KEY, SMTP_HOST, SMTPCOM_API_KEY or EMAIL_PROVIDER=ses), so password-reset, invite and form-notification mail is skipped without an error. An admin can also set a provider in Settings > Email.',
791
+ fix: 'Set RESEND_API_KEY (or SMTP_HOST / EMAIL_PROVIDER) in the production environment, or configure Settings > Email after deploy.',
792
+ docs: 'https://prentacms.dev/docs/environment-variables',
793
+ }
794
+ }
795
+
796
+ function sameOrigin(a: string, b: string): boolean {
797
+ try {
798
+ return new URL(a).origin === new URL(b).origin
799
+ } catch {
800
+ return false
801
+ }
802
+ }
803
+
804
+ /** The Astro public site's deploy wiring (#1263). */
805
+ function astroSiteChecks(input: DiagnosticInput, siteDir: string): DiagnosticCheck[] {
806
+ const files = input.projectFiles ?? {}
807
+ const checks: DiagnosticCheck[] = []
808
+ const docs = 'https://prentacms.dev/docs/astro-public-site'
809
+
810
+ if (files.siteVercelJson?.includes('CMS_HOST_ORIGIN')) {
811
+ checks.push({
812
+ id: 'astro-cms-host-origin',
813
+ label: 'Astro site rewrites',
814
+ status: isProductionTarget(input) ? 'fail' : 'warn',
815
+ message: `${siteDir}/vercel.json still rewrites /api/cms and the admin to the placeholder host CMS_HOST_ORIGIN, so on the public domain they go nowhere.`,
816
+ fix: `Replace CMS_HOST_ORIGIN in ${siteDir}/vercel.json with the deployed CMS host (for example cms-yourproject.vercel.app).`,
817
+ docs,
818
+ })
819
+ }
820
+
821
+ const siteEnv = files.siteEnv
822
+ if (!siteEnv) {
823
+ checks.push({
824
+ id: 'astro-site-env',
825
+ label: 'Astro site environment',
826
+ status: 'skip',
827
+ message: `No .env in ${siteDir}/, so its environment was not checked. On its Vercel project, set SITE, PRENTA_CMS_URL, PRENTA_WEBHOOK_SECRET and CDN purge credentials (CLOUDFLARE_ZONE_ID + CLOUDFLARE_API_TOKEN, or VERCEL_DEPLOY_HOOK_URL).`,
828
+ docs,
829
+ })
830
+ return checks
831
+ }
832
+
833
+ const missing = ['SITE', 'PRENTA_CMS_URL', 'PRENTA_WEBHOOK_SECRET'].filter(
834
+ (key) => !siteEnv[key]?.trim(),
835
+ )
836
+ const hasPurge = Boolean(
837
+ (siteEnv.CLOUDFLARE_ZONE_ID && siteEnv.CLOUDFLARE_API_TOKEN) || siteEnv.VERCEL_DEPLOY_HOOK_URL,
838
+ )
839
+ if (!hasPurge) {
840
+ missing.push('CLOUDFLARE_ZONE_ID + CLOUDFLARE_API_TOKEN (or VERCEL_DEPLOY_HOOK_URL)')
841
+ }
842
+ checks.push({
843
+ id: 'astro-site-env',
844
+ label: 'Astro site environment',
845
+ status: missing.length === 0 ? 'pass' : 'warn',
846
+ message:
847
+ missing.length === 0
848
+ ? `${siteDir}/.env sets SITE, PRENTA_CMS_URL, PRENTA_WEBHOOK_SECRET and CDN purge credentials.`
849
+ : `${siteDir}/.env is missing ${missing.join(', ')}. Without SITE the site falls back to the CMS origin; without the webhook secret or purge credentials, publishing does not refresh the site in production. Check the Astro project's Vercel environment too.`,
850
+ docs,
851
+ })
852
+
853
+ const site = siteEnv.SITE?.trim()
854
+ const cmsSiteUrl = input.env.NEXT_PUBLIC_SITE_URL?.trim()
855
+ if (
856
+ site &&
857
+ cmsSiteUrl &&
858
+ !productionOriginProblem(site) &&
859
+ !productionOriginProblem(cmsSiteUrl)
860
+ ) {
861
+ const same = sameOrigin(site, cmsSiteUrl)
862
+ checks.push({
863
+ id: 'astro-site-url-match',
864
+ label: 'Public origin agreement',
865
+ status: same ? 'pass' : 'warn',
866
+ message: same
867
+ ? 'The CMS NEXT_PUBLIC_SITE_URL and the Astro SITE name the same public origin.'
868
+ : `The CMS NEXT_PUBLIC_SITE_URL (${cmsSiteUrl}) and the Astro SITE (${site}) differ, so canonical URLs, sitemaps and purges disagree about which domain is live.`,
869
+ fix: same ? undefined : 'Set both to the public apex origin.',
870
+ docs: same ? undefined : docs,
871
+ })
872
+ }
873
+ return checks
874
+ }
875
+
454
876
  /** Off-platform database backups: encryption key + nightly workflow (spec 2026-09-18). */
455
877
  export function backupsCheck(hasKey: boolean, workflowPresent: boolean): DiagnosticCheck {
456
878
  const problems: string[] = []
@@ -480,6 +902,58 @@ export function backupsCheck(hasKey: boolean, workflowPresent: boolean): Diagnos
480
902
  }
481
903
  }
482
904
 
905
+ /**
906
+ * True when a 5-field cron expression can fire more than once a day, which a
907
+ * Vercel Hobby project refuses to deploy. Only a single-number minute and hour
908
+ * guarantee at most one run a day; anything else (`*`, a step, list or range)
909
+ * is treated as sub-daily, which can only over-warn.
910
+ */
911
+ export function cronRunsMoreThanDaily(schedule: string): boolean {
912
+ const fields = schedule.trim().split(/\s+/)
913
+ if (fields.length !== 5) return true
914
+ const single = /^\d+$/
915
+ return !single.test(fields[0]!) || !single.test(fields[1]!)
916
+ }
917
+
918
+ /**
919
+ * Warn about crons Vercel Hobby rejects (#1262). Hobby allows crons at most
920
+ * once a day and fails the whole deployment otherwise. The CLI cannot see the
921
+ * plan, so this is a warning; Pro and Enterprise run them fine.
922
+ */
923
+ function vercelCronPlanCheck(vercelJson: string): DiagnosticCheck | null {
924
+ let crons: unknown
925
+ try {
926
+ crons = (JSON.parse(vercelJson) as { crons?: unknown }).crons
927
+ } catch {
928
+ return null
929
+ }
930
+ if (!Array.isArray(crons) || crons.length === 0) return null
931
+ const subDaily = crons
932
+ .filter(
933
+ (c): c is { path: string; schedule: string } =>
934
+ typeof c?.path === 'string' && typeof c?.schedule === 'string',
935
+ )
936
+ .filter((c) => cronRunsMoreThanDaily(c.schedule))
937
+ if (subDaily.length === 0) {
938
+ return {
939
+ id: 'vercel-cron-plan',
940
+ label: 'Vercel cron schedules',
941
+ status: 'pass',
942
+ message: 'Every cron in vercel.json runs at most once a day, which Vercel Hobby allows.',
943
+ }
944
+ }
945
+ return {
946
+ id: 'vercel-cron-plan',
947
+ label: 'Vercel cron schedules',
948
+ status: 'warn',
949
+ message: `vercel.json has crons that run more than once a day: ${subDaily
950
+ .map((c) => `${c.path} (${c.schedule})`)
951
+ .join(', ')}. Vercel Hobby fails the deployment for these; Pro and Enterprise run them.`,
952
+ fix: 'On Hobby, give each a daily schedule (for example the publish cron "0 1 * * *"; scheduled publishes then run once a day). On Pro, nothing to do.',
953
+ docs: 'https://prentacms.dev/docs/deployment#vercel-hobby',
954
+ }
955
+ }
956
+
483
957
  export function buildDeploymentManifest() {
484
958
  return {
485
959
  schemaVersion: 1,
@@ -493,10 +967,10 @@ export function buildDeploymentManifest() {
493
967
  'CMS_ADMIN_PASSWORD',
494
968
  'CRON_SECRET',
495
969
  'BLOB_READ_WRITE_TOKEN',
496
- 'UPSTASH_REDIS_REST_URL',
497
- 'UPSTASH_REDIS_REST_TOKEN',
498
970
  'RESEND_API_KEY',
499
971
  ],
972
+ /** Required in production; either pair satisfies it. */
973
+ rateLimitEnv: RATE_LIMIT_ENV_PAIRS.map((pair) => [...pair]),
500
974
  routes: {
501
975
  apiHealth: '/api/cms/health',
502
976
  apiBase: '/api/cms',