@prenta/cli 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
@@ -83,6 +89,17 @@ export interface DiagnosticInput {
83
89
  schemaPath: string
84
90
  mode?: 'doctor' | 'deploy'
85
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 }>
86
103
  }
87
104
 
88
105
  /** Optional on-disk project signals for site-launch checks. */
@@ -104,6 +121,14 @@ export interface ProjectFileSignals {
104
121
  astroConfigPresent?: boolean
105
122
  /** True when `.github/workflows/db-backup.yml` exists (nightly `prenta db:backup`). */
106
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>
107
132
  }
108
133
 
109
134
  export const RECOMMENDED_PRODUCTION_PLUGINS = [
@@ -294,31 +319,48 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
294
319
  checks.push(rateLimitBackendCheck(input))
295
320
 
296
321
  const blobState = detectBlobLinkState(input.env, input.configContent)
297
- checks.push({
298
- id: 'blob-storage',
299
- label: 'Vercel Blob storage',
300
- status: blobState === 'partial' ? 'fail' : blobState === 'token-format' ? 'warn' : 'pass',
301
- message:
302
- blobState === 'partial'
303
- ? '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.'
304
- : blobState === 'token-format'
305
- ? 'BLOB_READ_WRITE_TOKEN does not start with `vercel_blob_` — verify it is a real Vercel Blob read-write token.'
306
- : blobState === 'ok'
307
- ? input.env.BLOB_READ_WRITE_TOKEN
308
- ? 'BLOB_READ_WRITE_TOKEN is configured.'
309
- : 'Vercel Marketplace Blob is linked (BLOB_STORE_ID). Uploads use OIDC on Vercel; no read-write token required.'
310
- : 'No Vercel Blob storage configured (skipped).',
311
- fix:
312
- blobState === 'partial'
313
- ? 'Connect a Vercel Blob store to the project from the Storage tab, then `vercel env pull`. Validate with `prenta vercel:blob-link`.'
314
- : blobState === 'token-format'
315
- ? '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'
316
357
  : undefined,
317
- docs:
318
- blobState === 'partial' || blobState === 'token-format'
319
- ? 'https://prentacms.dev/docs/deployment'
320
- : undefined,
321
- })
358
+ })
359
+
360
+ checks.push(envShapeCheck(input))
361
+ checks.push(cronSecretCheck(input))
362
+ const emailCheck = emailProviderCheck(input)
363
+ if (emailCheck) checks.push(emailCheck)
322
364
 
323
365
  checks.push({
324
366
  id: 'package-manager',
@@ -364,30 +406,44 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
364
406
  })
365
407
 
366
408
  const seoSiteUrlOk = detectSeoSiteUrl(input.configContent, input.env)
367
- checks.push({
368
- id: 'seo-site-url',
369
- label: 'SEO site URL',
370
- status: seoSiteUrlOk ? 'pass' : 'warn',
371
- message: seoSiteUrlOk
372
- ? 'Production site URL is configured via NEXT_PUBLIC_SITE_URL and/or prenta.config.ts seo.siteUrl.'
373
- : 'Neither NEXT_PUBLIC_SITE_URL nor prenta.config.ts seo.siteUrl appears configured — canonical URLs, sitemaps, and JSON-LD may be wrong.',
374
- fix: seoSiteUrlOk
375
- ? undefined
376
- : 'Set NEXT_PUBLIC_SITE_URL to your production origin (no trailing slash) and align prenta.config.ts seo.siteUrl.',
377
- docs: seoSiteUrlOk ? undefined : 'https://prentacms.dev/docs/environment-variables',
378
- })
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
+ })
379
434
 
380
435
  if (input.projectFiles) {
381
436
  const astroSplit = detectsAstroSplitSite(input.projectFiles)
437
+ const siteDir = input.projectFiles.siteLabel ?? 'site'
382
438
  if (astroSplit) {
383
439
  checks.push({
384
440
  id: 'astro-split-site',
385
441
  label: 'Astro public site (split)',
386
442
  status: 'pass',
387
- message:
388
- '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.`,
389
444
  docs: 'https://prentacms.dev/docs/astro-public-site',
390
445
  })
446
+ checks.push(...astroSiteChecks(input, siteDir))
391
447
 
392
448
  const astroCmsOk = detectsAstroCmsHelpers(input.projectFiles)
393
449
  checks.push({
@@ -396,10 +452,10 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
396
452
  status: astroCmsOk ? 'pass' : 'warn',
397
453
  message: astroCmsOk
398
454
  ? 'Astro site uses createAstroSiteHelpers / PRENTA_CMS_URL.'
399
- : '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.`,
400
456
  fix: astroCmsOk
401
457
  ? undefined
402
- : '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.`,
403
459
  docs: 'https://prentacms.dev/docs/astro-public-site',
404
460
  })
405
461
  }
@@ -422,66 +478,104 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
422
478
  docs: seoOk ? undefined : 'https://prentacms.dev/docs/prototype-to-production',
423
479
  })
424
480
 
425
- const uncachedResolve = !astroSplit && detectsUncachedResolvePattern(input.projectFiles)
426
- checks.push({
427
- id: 'cached-resolve',
428
- label: 'Cached /resolve for ISR',
429
- status: uncachedResolve ? 'warn' : 'pass',
430
- message: uncachedResolve
431
- ? '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.'
432
- : astroSplit
433
- ? '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.'
434
514
  : 'Published pages use cached /resolve helpers suitable for ISR.',
435
- fix: uncachedResolve
436
- ? '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).'
437
- : undefined,
438
- docs: uncachedResolve ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
439
- })
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
+ })
440
520
 
441
- const clientSections = !astroSplit && detectsClientWrappedPublicSections(input.projectFiles)
442
- checks.push({
443
- id: 'public-sections-ssr',
444
- label: 'Public sections SSR',
445
- status: clientSections ? 'warn' : 'pass',
446
- message: clientSections
447
- ? "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."
448
- : astroSplit
449
- ? '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."
450
529
  : 'Public page sections render from a Server Component catch-all.',
451
- fix: clientSections
452
- ? "Remove 'use client' from the catch-all and any PageSections wrapper; register section renderers via a side-effect import in the site layout instead."
453
- : undefined,
454
- docs: clientSections ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
455
- })
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
+ })
456
535
 
457
536
  const missingJsonLd =
458
537
  !astroSplit && detectsMissingJsonLdInCatchAll(input.projectFiles.catchAllPage)
459
- checks.push({
460
- id: 'structured-data-html',
461
- label: 'JSON-LD in page HTML',
462
- status: missingJsonLd ? 'warn' : 'pass',
463
- message: missingJsonLd
464
- ? 'The public catch-all does not render JSON-LD from /resolve — Rich Results and some AI crawlers expect structured data in the HTML body.'
465
- : 'Published pages inject JSON-LD from cms-core into the server-rendered HTML.',
466
- fix: missingJsonLd
467
- ? 'Render result.jsonLd as a <script type="application/ld+json"> in the catch-all (see create-prenta scaffold).'
468
- : undefined,
469
- docs: missingJsonLd ? 'https://prentacms.dev/docs/prototype-to-production' : undefined,
470
- })
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
+ })
471
551
 
472
552
  const missingApiCache = detectsMissingApiCacheWiring(input.projectFiles.apiRoute)
473
- checks.push({
474
- id: 'api-cache-invalidation',
475
- label: 'CMS API cache + invalidation',
476
- status: missingApiCache ? 'warn' : 'pass',
477
- message: missingApiCache
478
- ? '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.'
479
- : 'CMS public reads are CDN-cacheable and writes drain Next ISR via onInvalidate.',
480
- fix: missingApiCache
481
- ? 'Adopt the cache block from create-prenta app/api/cms/[[...cms]]/route.ts (publicReads + onInvalidate with revalidateTag).'
482
- : undefined,
483
- docs: missingApiCache ? 'https://prentacms.dev/docs/caching' : undefined,
484
- })
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
+ }
485
579
 
486
580
  if (input.projectFiles.backupWorkflowPresent !== undefined) {
487
581
  checks.push(
@@ -544,6 +638,241 @@ export function createDiagnosticReport(input: DiagnosticInput): DiagnosticReport
544
638
  return { status, checks }
545
639
  }
546
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
+
547
876
  /** Off-platform database backups: encryption key + nightly workflow (spec 2026-09-18). */
548
877
  export function backupsCheck(hasKey: boolean, workflowPresent: boolean): DiagnosticCheck {
549
878
  const problems: string[] = []
@@ -573,6 +902,58 @@ export function backupsCheck(hasKey: boolean, workflowPresent: boolean): Diagnos
573
902
  }
574
903
  }
575
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
+
576
957
  export function buildDeploymentManifest() {
577
958
  return {
578
959
  schemaVersion: 1,