@prenta/cli 0.14.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.
- package/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +353 -0
- package/CHANGELOG.md +404 -0
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/__tests__/db-init.test.d.ts +2 -0
- package/dist/__tests__/db-init.test.d.ts.map +1 -0
- package/dist/__tests__/db-init.test.js +127 -0
- package/dist/__tests__/db-init.test.js.map +1 -0
- package/dist/__tests__/db-sync-resolver.test.d.ts +2 -0
- package/dist/__tests__/db-sync-resolver.test.d.ts.map +1 -0
- package/dist/__tests__/db-sync-resolver.test.js +25 -0
- package/dist/__tests__/db-sync-resolver.test.js.map +1 -0
- package/dist/__tests__/db-sync.test.d.ts +2 -0
- package/dist/__tests__/db-sync.test.d.ts.map +1 -0
- package/dist/__tests__/db-sync.test.js +167 -0
- package/dist/__tests__/db-sync.test.js.map +1 -0
- package/dist/__tests__/deployment-diagnostics.test.d.ts +2 -0
- package/dist/__tests__/deployment-diagnostics.test.d.ts.map +1 -0
- package/dist/__tests__/deployment-diagnostics.test.js +401 -0
- package/dist/__tests__/deployment-diagnostics.test.js.map +1 -0
- package/dist/__tests__/form-seed.test.d.ts +2 -0
- package/dist/__tests__/form-seed.test.d.ts.map +1 -0
- package/dist/__tests__/form-seed.test.js +79 -0
- package/dist/__tests__/form-seed.test.js.map +1 -0
- package/dist/__tests__/init.test.d.ts +2 -0
- package/dist/__tests__/init.test.d.ts.map +1 -0
- package/dist/__tests__/init.test.js +25 -0
- package/dist/__tests__/init.test.js.map +1 -0
- package/dist/__tests__/load-dotenv.test.d.ts +2 -0
- package/dist/__tests__/load-dotenv.test.d.ts.map +1 -0
- package/dist/__tests__/load-dotenv.test.js +40 -0
- package/dist/__tests__/load-dotenv.test.js.map +1 -0
- package/dist/__tests__/mcp-init.test.d.ts +2 -0
- package/dist/__tests__/mcp-init.test.d.ts.map +1 -0
- package/dist/__tests__/mcp-init.test.js +100 -0
- package/dist/__tests__/mcp-init.test.js.map +1 -0
- package/dist/__tests__/prisma-client-path.test.d.ts +2 -0
- package/dist/__tests__/prisma-client-path.test.d.ts.map +1 -0
- package/dist/__tests__/prisma-client-path.test.js +66 -0
- package/dist/__tests__/prisma-client-path.test.js.map +1 -0
- package/dist/__tests__/schema-fragment.test.d.ts +2 -0
- package/dist/__tests__/schema-fragment.test.d.ts.map +1 -0
- package/dist/__tests__/schema-fragment.test.js +40 -0
- package/dist/__tests__/schema-fragment.test.js.map +1 -0
- package/dist/__tests__/seed.test.d.ts +2 -0
- package/dist/__tests__/seed.test.d.ts.map +1 -0
- package/dist/__tests__/seed.test.js +207 -0
- package/dist/__tests__/seed.test.js.map +1 -0
- package/dist/__tests__/upgrade.test.d.ts +2 -0
- package/dist/__tests__/upgrade.test.d.ts.map +1 -0
- package/dist/__tests__/upgrade.test.js +41 -0
- package/dist/__tests__/upgrade.test.js.map +1 -0
- package/dist/__tests__/vercel-env-matrix.test.d.ts +2 -0
- package/dist/__tests__/vercel-env-matrix.test.d.ts.map +1 -0
- package/dist/__tests__/vercel-env-matrix.test.js +56 -0
- package/dist/__tests__/vercel-env-matrix.test.js.map +1 -0
- package/dist/commands/db-init.d.ts +24 -0
- package/dist/commands/db-init.d.ts.map +1 -0
- package/dist/commands/db-init.js +195 -0
- package/dist/commands/db-init.js.map +1 -0
- package/dist/commands/db-status.d.ts +3 -0
- package/dist/commands/db-status.d.ts.map +1 -0
- package/dist/commands/db-status.js +108 -0
- package/dist/commands/db-status.js.map +1 -0
- package/dist/commands/db-sync.d.ts +66 -0
- package/dist/commands/db-sync.d.ts.map +1 -0
- package/dist/commands/db-sync.js +310 -0
- package/dist/commands/db-sync.js.map +1 -0
- package/dist/commands/doctor.d.ts +5 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +282 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/export.d.ts +3 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +99 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/generate.d.ts +3 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +24 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/import.d.ts +3 -0
- package/dist/commands/import.d.ts.map +1 -0
- package/dist/commands/import.js +201 -0
- package/dist/commands/import.js.map +1 -0
- package/dist/commands/init.d.ts +4 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +31 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +3 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +126 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/migrate-media-usage.d.ts +3 -0
- package/dist/commands/migrate-media-usage.d.ts.map +1 -0
- package/dist/commands/migrate-media-usage.js +52 -0
- package/dist/commands/migrate-media-usage.js.map +1 -0
- package/dist/commands/migrate-meta.d.ts +3 -0
- package/dist/commands/migrate-meta.d.ts.map +1 -0
- package/dist/commands/migrate-meta.js +81 -0
- package/dist/commands/migrate-meta.js.map +1 -0
- package/dist/commands/migrate-schema.d.ts +3 -0
- package/dist/commands/migrate-schema.d.ts.map +1 -0
- package/dist/commands/migrate-schema.js +84 -0
- package/dist/commands/migrate-schema.js.map +1 -0
- package/dist/commands/migrate-sections.d.ts +3 -0
- package/dist/commands/migrate-sections.d.ts.map +1 -0
- package/dist/commands/migrate-sections.js +56 -0
- package/dist/commands/migrate-sections.js.map +1 -0
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +51 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/seed.d.ts +60 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +585 -0
- package/dist/commands/seed.js.map +1 -0
- package/dist/commands/update-check.d.ts +3 -0
- package/dist/commands/update-check.d.ts.map +1 -0
- package/dist/commands/update-check.js +132 -0
- package/dist/commands/update-check.js.map +1 -0
- package/dist/commands/upgrade.d.ts +4 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +175 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/commands/vercel-blob-link.d.ts +3 -0
- package/dist/commands/vercel-blob-link.d.ts.map +1 -0
- package/dist/commands/vercel-blob-link.js +83 -0
- package/dist/commands/vercel-blob-link.js.map +1 -0
- package/dist/deployment/diagnostics.d.ts +136 -0
- package/dist/deployment/diagnostics.d.ts.map +1 -0
- package/dist/deployment/diagnostics.js +575 -0
- package/dist/deployment/diagnostics.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/database.d.ts +21 -0
- package/dist/utils/database.d.ts.map +1 -0
- package/dist/utils/database.js +98 -0
- package/dist/utils/database.js.map +1 -0
- package/dist/utils/form-seed.d.ts +15 -0
- package/dist/utils/form-seed.d.ts.map +1 -0
- package/dist/utils/form-seed.js +97 -0
- package/dist/utils/form-seed.js.map +1 -0
- package/dist/utils/load-dotenv.d.ts +11 -0
- package/dist/utils/load-dotenv.d.ts.map +1 -0
- package/dist/utils/load-dotenv.js +47 -0
- package/dist/utils/load-dotenv.js.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +16 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/prisma-client-path.d.ts +20 -0
- package/dist/utils/prisma-client-path.d.ts.map +1 -0
- package/dist/utils/prisma-client-path.js +77 -0
- package/dist/utils/prisma-client-path.js.map +1 -0
- package/dist/vercel/client.d.ts +32 -0
- package/dist/vercel/client.d.ts.map +1 -0
- package/dist/vercel/client.js +74 -0
- package/dist/vercel/client.js.map +1 -0
- package/dist/vercel/env-matrix.d.ts +35 -0
- package/dist/vercel/env-matrix.d.ts.map +1 -0
- package/dist/vercel/env-matrix.js +66 -0
- package/dist/vercel/env-matrix.js.map +1 -0
- package/package.json +41 -0
- package/src/__tests__/db-init.test.ts +155 -0
- package/src/__tests__/db-sync-resolver.test.ts +29 -0
- package/src/__tests__/db-sync.test.ts +221 -0
- package/src/__tests__/deployment-diagnostics.test.ts +474 -0
- package/src/__tests__/form-seed.test.ts +91 -0
- package/src/__tests__/init.test.ts +30 -0
- package/src/__tests__/load-dotenv.test.ts +53 -0
- package/src/__tests__/mcp-init.test.ts +125 -0
- package/src/__tests__/prisma-client-path.test.ts +87 -0
- package/src/__tests__/schema-fragment.test.ts +51 -0
- package/src/__tests__/seed.test.ts +249 -0
- package/src/__tests__/upgrade.test.ts +44 -0
- package/src/__tests__/vercel-env-matrix.test.ts +65 -0
- package/src/commands/db-init.ts +211 -0
- package/src/commands/db-status.ts +122 -0
- package/src/commands/db-sync.ts +367 -0
- package/src/commands/doctor.ts +354 -0
- package/src/commands/export.ts +118 -0
- package/src/commands/generate.ts +26 -0
- package/src/commands/import.ts +228 -0
- package/src/commands/init.ts +36 -0
- package/src/commands/mcp.ts +181 -0
- package/src/commands/migrate-media-usage.ts +68 -0
- package/src/commands/migrate-meta.ts +107 -0
- package/src/commands/migrate-schema.ts +110 -0
- package/src/commands/migrate-sections.ts +73 -0
- package/src/commands/migrate.ts +56 -0
- package/src/commands/seed.ts +693 -0
- package/src/commands/update-check.ts +152 -0
- package/src/commands/upgrade.ts +202 -0
- package/src/commands/vercel-blob-link.ts +116 -0
- package/src/deployment/diagnostics.ts +735 -0
- package/src/index.ts +54 -0
- package/src/utils/database.ts +126 -0
- package/src/utils/form-seed.ts +137 -0
- package/src/utils/load-dotenv.ts +52 -0
- package/src/utils/logger.ts +26 -0
- package/src/utils/prisma-client-path.ts +81 -0
- package/src/vercel/client.ts +112 -0
- package/src/vercel/env-matrix.ts +112 -0
- package/tsconfig.json +9 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander'
|
|
3
|
+
import { registerMigrateCommand } from './commands/migrate.js'
|
|
4
|
+
import { registerMigrateSectionsCommand } from './commands/migrate-sections.js'
|
|
5
|
+
import { registerMigrateSchemaCommand } from './commands/migrate-schema.js'
|
|
6
|
+
import { registerMigrateMetaCommand } from './commands/migrate-meta.js'
|
|
7
|
+
import { registerMigrateMediaUsageCommand } from './commands/migrate-media-usage.js'
|
|
8
|
+
import { registerGenerateCommand } from './commands/generate.js'
|
|
9
|
+
import { registerSeedCommand } from './commands/seed.js'
|
|
10
|
+
import { registerImportCommand } from './commands/import.js'
|
|
11
|
+
import { registerExportCommand } from './commands/export.js'
|
|
12
|
+
import { registerUpgradeCommand } from './commands/upgrade.js'
|
|
13
|
+
import { registerUpdateCheckCommand } from './commands/update-check.js'
|
|
14
|
+
import { registerDbInitCommand } from './commands/db-init.js'
|
|
15
|
+
import { registerDbSyncCommand } from './commands/db-sync.js'
|
|
16
|
+
import { registerDbStatusCommand } from './commands/db-status.js'
|
|
17
|
+
import { registerInitCommand } from './commands/init.js'
|
|
18
|
+
import {
|
|
19
|
+
registerDeployCheckCommand,
|
|
20
|
+
registerDoctorCommand,
|
|
21
|
+
registerVerifyCommand,
|
|
22
|
+
} from './commands/doctor.js'
|
|
23
|
+
import { registerVercelBlobLinkCommand } from './commands/vercel-blob-link.js'
|
|
24
|
+
import { registerMcpCommand } from './commands/mcp.js'
|
|
25
|
+
|
|
26
|
+
const program = new Command()
|
|
27
|
+
|
|
28
|
+
program
|
|
29
|
+
.name('prenta')
|
|
30
|
+
.description('Prenta CMS — CLI toolkit for migrations, codegen, and more')
|
|
31
|
+
.version('0.1.0')
|
|
32
|
+
|
|
33
|
+
registerMigrateCommand(program)
|
|
34
|
+
registerMigrateSectionsCommand(program)
|
|
35
|
+
registerMigrateSchemaCommand(program)
|
|
36
|
+
registerMigrateMetaCommand(program)
|
|
37
|
+
registerMigrateMediaUsageCommand(program)
|
|
38
|
+
registerGenerateCommand(program)
|
|
39
|
+
registerSeedCommand(program)
|
|
40
|
+
registerImportCommand(program)
|
|
41
|
+
registerExportCommand(program)
|
|
42
|
+
registerUpgradeCommand(program)
|
|
43
|
+
registerUpdateCheckCommand(program)
|
|
44
|
+
registerDbInitCommand(program)
|
|
45
|
+
registerDbSyncCommand(program)
|
|
46
|
+
registerDbStatusCommand(program)
|
|
47
|
+
registerInitCommand(program)
|
|
48
|
+
registerDoctorCommand(program)
|
|
49
|
+
registerDeployCheckCommand(program)
|
|
50
|
+
registerVerifyCommand(program)
|
|
51
|
+
registerVercelBlobLinkCommand(program)
|
|
52
|
+
registerMcpCommand(program)
|
|
53
|
+
|
|
54
|
+
program.parse()
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createRequire } from 'node:module'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { pathToFileURL } from 'node:url'
|
|
4
|
+
|
|
5
|
+
import { findLibPrismaHelper, resolveProjectPrismaClientModule } from './prisma-client-path.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Shared helper for CLI commands that need a live connection to the consumer
|
|
9
|
+
* project's database (seed, populate, data migrations…).
|
|
10
|
+
*
|
|
11
|
+
* Resolution order mirrors how a scaffolded Prenta project exposes Prisma:
|
|
12
|
+
* 1. If `cms-core` already has an initialized client (e.g. set up by the host
|
|
13
|
+
* app in-process), reuse it.
|
|
14
|
+
* 2. Otherwise call `getPrisma()` from `lib/prisma.ts` when the project ships
|
|
15
|
+
* one (Prisma 7 + pg adapter / Accelerate — same path Next.js uses).
|
|
16
|
+
* 3. Otherwise build a client from the schema's `output` path (custom or
|
|
17
|
+
* default `generated/prisma/client.ts`) via tsx + pg driver adapter.
|
|
18
|
+
* 4. Fall back to a plain `@prisma/client` resolved from the project.
|
|
19
|
+
*
|
|
20
|
+
* The returned `disconnect()` only tears down clients this helper created — a
|
|
21
|
+
* pre-initialized in-process client is left untouched.
|
|
22
|
+
*/
|
|
23
|
+
export async function connectProjectDatabase(): Promise<{
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Prisma client shape varies by project; callers treat it structurally.
|
|
25
|
+
db: any
|
|
26
|
+
disconnect: () => Promise<void>
|
|
27
|
+
}> {
|
|
28
|
+
const { getDB, initDB, isDBInitialized } = await import('@prenta/core')
|
|
29
|
+
|
|
30
|
+
if (isDBInitialized()) {
|
|
31
|
+
return { db: getDB<any>(), disconnect: async () => {} }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const db = await createProjectPrismaClient()
|
|
35
|
+
initDB(db)
|
|
36
|
+
return {
|
|
37
|
+
db,
|
|
38
|
+
disconnect: async () => {
|
|
39
|
+
if (typeof db.$disconnect === 'function') {
|
|
40
|
+
await db.$disconnect()
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const ACCELERATED_DB_URL_PREFIXES = ['prisma://', 'prisma+postgres://'] as const
|
|
47
|
+
|
|
48
|
+
function isAcceleratedDbUrl(url: string | undefined): boolean {
|
|
49
|
+
const trimmed = url?.trim()
|
|
50
|
+
if (!trimmed) return false
|
|
51
|
+
return ACCELERATED_DB_URL_PREFIXES.some((prefix) => trimmed.startsWith(prefix))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function importModule(specifier: string, requireFromProject: NodeRequire): Promise<unknown> {
|
|
55
|
+
const href = pathToFileURL(requireFromProject.resolve(specifier)).href
|
|
56
|
+
return import(href)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function tryLibPrismaClient(): Promise<any | null> {
|
|
60
|
+
const helperPath = findLibPrismaHelper()
|
|
61
|
+
if (!helperPath) return null
|
|
62
|
+
|
|
63
|
+
const { tsImport } = await import('tsx/esm/api')
|
|
64
|
+
const mod = (await tsImport(pathToFileURL(helperPath).href, import.meta.url)) as {
|
|
65
|
+
getPrisma?: () => unknown
|
|
66
|
+
default?: { getPrisma?: () => unknown }
|
|
67
|
+
}
|
|
68
|
+
const getPrisma = mod.getPrisma ?? mod.default?.getPrisma
|
|
69
|
+
if (typeof getPrisma !== 'function') return null
|
|
70
|
+
return getPrisma()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above.
|
|
74
|
+
async function createProjectPrismaClient(): Promise<any> {
|
|
75
|
+
if (!process.env.DATABASE_URL) {
|
|
76
|
+
throw new Error('DATABASE_URL is required to connect to the project database.')
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const fromLib = await tryLibPrismaClient()
|
|
80
|
+
if (fromLib) return fromLib
|
|
81
|
+
|
|
82
|
+
const requireFromProject = createRequire(path.join(process.cwd(), 'package.json'))
|
|
83
|
+
const generatedClient = resolveProjectPrismaClientModule()
|
|
84
|
+
|
|
85
|
+
if (generatedClient) {
|
|
86
|
+
const url = process.env.DATABASE_URL
|
|
87
|
+
const [{ tsImport }, adapterModule, pgModule] = await Promise.all([
|
|
88
|
+
import('tsx/esm/api'),
|
|
89
|
+
importModule('@prisma/adapter-pg', requireFromProject),
|
|
90
|
+
importModule('pg', requireFromProject),
|
|
91
|
+
])
|
|
92
|
+
const { PrismaClient } = (await tsImport(
|
|
93
|
+
pathToFileURL(generatedClient).href,
|
|
94
|
+
import.meta.url,
|
|
95
|
+
)) as {
|
|
96
|
+
PrismaClient: new (options?: unknown) => any
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (isAcceleratedDbUrl(url)) {
|
|
100
|
+
let withAccelerate: () => unknown
|
|
101
|
+
try {
|
|
102
|
+
const ext = (await importModule('@prisma/extension-accelerate', requireFromProject)) as {
|
|
103
|
+
withAccelerate: () => unknown
|
|
104
|
+
}
|
|
105
|
+
withAccelerate = ext.withAccelerate
|
|
106
|
+
} catch {
|
|
107
|
+
throw new Error(
|
|
108
|
+
'DATABASE_URL uses Prisma Accelerate but @prisma/extension-accelerate is not installed. Run `lib/prisma.ts` via adding it, or install the extension.',
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
const client = new PrismaClient({ accelerateUrl: url } as never).$extends(withAccelerate())
|
|
112
|
+
return client
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const { PrismaPg } = adapterModule as { PrismaPg: new (pool: unknown) => unknown }
|
|
116
|
+
const pg = (pgModule as { default?: typeof pgModule }).default ?? pgModule
|
|
117
|
+
const pool = new (pg as any).Pool({ connectionString: url })
|
|
118
|
+
const adapter = new PrismaPg(pool)
|
|
119
|
+
return new PrismaClient({ adapter } as any)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const clientModule = (await importModule('@prisma/client', requireFromProject)) as {
|
|
123
|
+
PrismaClient: new () => any
|
|
124
|
+
}
|
|
125
|
+
return new clientModule.PrismaClient()
|
|
126
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation for `forms`-collection seed entries.
|
|
3
|
+
*
|
|
4
|
+
* The form definition lives in `document.data` and has its own lifecycle
|
|
5
|
+
* `data.status` (`active` | `draft` | `archived`) that gates the public
|
|
6
|
+
* endpoints — a separate axis from the *document envelope* status
|
|
7
|
+
* (`DRAFT` | `PUBLISHED`). Seeding a form with the wrong shape used to fail
|
|
8
|
+
* silently: the document row was created, but `/api/cms/public/forms/:slug`
|
|
9
|
+
* 404'd (not `active`) or rendered nothing (fields missing `key`/`label`).
|
|
10
|
+
* This validator turns those mistakes into actionable errors at seed time.
|
|
11
|
+
*
|
|
12
|
+
* Type-only imports keep cms-core a runtime peer dependency (the CLI loads it
|
|
13
|
+
* lazily); the literal lists below are typed against the cms-core contracts so
|
|
14
|
+
* a typo here fails the build.
|
|
15
|
+
*/
|
|
16
|
+
import type { FormFieldType, FormStatus } from '@prenta/core'
|
|
17
|
+
|
|
18
|
+
const VALID_FIELD_TYPES: readonly FormFieldType[] = [
|
|
19
|
+
'text',
|
|
20
|
+
'email',
|
|
21
|
+
'phone',
|
|
22
|
+
'textarea',
|
|
23
|
+
'select',
|
|
24
|
+
'multiselect',
|
|
25
|
+
'radio',
|
|
26
|
+
'checkbox',
|
|
27
|
+
'date',
|
|
28
|
+
'number',
|
|
29
|
+
'url',
|
|
30
|
+
'hidden',
|
|
31
|
+
'file',
|
|
32
|
+
'consent',
|
|
33
|
+
'richtext',
|
|
34
|
+
'divider',
|
|
35
|
+
'honeypot',
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
const VALID_FORM_STATUSES: readonly FormStatus[] = ['active', 'draft', 'archived']
|
|
39
|
+
|
|
40
|
+
/** Document-envelope statuses people mistakenly put in `data.status`. */
|
|
41
|
+
const ENVELOPE_STATUSES = new Set(['DRAFT', 'PUBLISHED', 'SCHEDULED', 'ARCHIVED'])
|
|
42
|
+
|
|
43
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
44
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Validate one form's `data` payload. Returns human-readable errors —
|
|
49
|
+
* empty array means the form will work with the public endpoints
|
|
50
|
+
* (`GET /api/cms/public/forms/:slug` + `/submit`) and `<PrentaForm>`.
|
|
51
|
+
*/
|
|
52
|
+
export function validateFormSeedData(data: unknown, label = 'form'): string[] {
|
|
53
|
+
const errors: string[] = []
|
|
54
|
+
if (!isRecord(data)) {
|
|
55
|
+
return [`${label}: form data must be an object.`]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (typeof data.slug !== 'string' || data.slug.trim() === '') {
|
|
59
|
+
errors.push(
|
|
60
|
+
`${label}: missing "slug" (string). The public endpoints look forms up by slug — e.g. /api/cms/public/forms/contact.`,
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const name = data.name ?? data.title
|
|
65
|
+
if (typeof name !== 'string' || name.trim() === '') {
|
|
66
|
+
errors.push(`${label}: missing "name" (string) — shown in the admin Forms list and inbox.`)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const status = data.status
|
|
70
|
+
if (status === undefined || status === null) {
|
|
71
|
+
errors.push(
|
|
72
|
+
`${label}: missing "status". Set data.status to "active" to enable the public form endpoints. ` +
|
|
73
|
+
`Note: this is the FORM's lifecycle status inside data — separate from the document envelope status ` +
|
|
74
|
+
`(DRAFT/PUBLISHED) set next to data.`,
|
|
75
|
+
)
|
|
76
|
+
} else if (typeof status === 'string' && ENVELOPE_STATUSES.has(status)) {
|
|
77
|
+
errors.push(
|
|
78
|
+
`${label}: data.status "${status}" looks like a document envelope status. The form definition's ` +
|
|
79
|
+
`data.status must be one of ${VALID_FORM_STATUSES.map((s) => `"${s}"`).join(' | ')} — use "active" ` +
|
|
80
|
+
`to enable the public endpoints. Put DRAFT/PUBLISHED on the document's top-level "status" key instead.`,
|
|
81
|
+
)
|
|
82
|
+
} else if (!VALID_FORM_STATUSES.includes(status as FormStatus)) {
|
|
83
|
+
errors.push(
|
|
84
|
+
`${label}: invalid data.status ${JSON.stringify(status)} — must be one of ` +
|
|
85
|
+
`${VALID_FORM_STATUSES.map((s) => `"${s}"`).join(' | ')}.`,
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const fields = data.fields
|
|
90
|
+
if (!Array.isArray(fields) || fields.length === 0) {
|
|
91
|
+
errors.push(
|
|
92
|
+
`${label}: missing "fields" (non-empty array). Each field needs at least { key, label, type }.`,
|
|
93
|
+
)
|
|
94
|
+
return errors
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fields.forEach((field, i) => {
|
|
98
|
+
const fieldLabel = `${label}: fields[${i}]`
|
|
99
|
+
if (!isRecord(field)) {
|
|
100
|
+
errors.push(`${fieldLabel}: must be an object with at least { key, label, type }.`)
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
if (typeof field.key !== 'string' || field.key.trim() === '') {
|
|
104
|
+
errors.push(
|
|
105
|
+
typeof field.name === 'string'
|
|
106
|
+
? `${fieldLabel}: uses "name" — the form schema calls this "key". Rename name → key (and add a human-readable "label").`
|
|
107
|
+
: `${fieldLabel}: missing "key" (string) — the submission payload is keyed by it.`,
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
if (typeof field.label !== 'string' || field.label.trim() === '') {
|
|
111
|
+
errors.push(`${fieldLabel}: missing "label" (string) — shown to visitors and in the inbox.`)
|
|
112
|
+
}
|
|
113
|
+
if (!VALID_FIELD_TYPES.includes(field.type as FormFieldType)) {
|
|
114
|
+
errors.push(
|
|
115
|
+
`${fieldLabel}: invalid type ${JSON.stringify(field.type)} — must be one of ${VALID_FIELD_TYPES.join(', ')}.`,
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
return errors
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Validate every `forms`-collection document in a normalized seed payload.
|
|
125
|
+
* Returns all errors across all forms (so one run surfaces everything).
|
|
126
|
+
*/
|
|
127
|
+
export function validateFormSeeds(
|
|
128
|
+
documents: ReadonlyArray<{ collection: string; data: Record<string, unknown> }>,
|
|
129
|
+
): string[] {
|
|
130
|
+
const errors: string[] = []
|
|
131
|
+
documents.forEach((doc, i) => {
|
|
132
|
+
if (doc.collection !== 'forms') return
|
|
133
|
+
const slug = typeof doc.data.slug === 'string' ? doc.data.slug : `#${i + 1}`
|
|
134
|
+
errors.push(...validateFormSeedData(doc.data, `forms "${slug}"`))
|
|
135
|
+
})
|
|
136
|
+
return errors
|
|
137
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { resolve } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/** Parse a minimal `.env` file (KEY=VALUE, # comments, optional quotes). */
|
|
5
|
+
export function parseDotenv(content: string): Record<string, string> {
|
|
6
|
+
const out: Record<string, string> = {}
|
|
7
|
+
for (const line of content.split(/\r?\n/)) {
|
|
8
|
+
const trimmed = line.trim()
|
|
9
|
+
if (!trimmed || trimmed.startsWith('#')) continue
|
|
10
|
+
const eq = trimmed.indexOf('=')
|
|
11
|
+
if (eq <= 0) continue
|
|
12
|
+
const key = trimmed.slice(0, eq).trim()
|
|
13
|
+
let value = trimmed.slice(eq + 1).trim()
|
|
14
|
+
if (
|
|
15
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
16
|
+
(value.startsWith("'") && value.endsWith("'"))
|
|
17
|
+
) {
|
|
18
|
+
value = value.slice(1, -1)
|
|
19
|
+
}
|
|
20
|
+
out[key] = value
|
|
21
|
+
}
|
|
22
|
+
return out
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Merge project `.env` files into a copy of `process.env`.
|
|
27
|
+
*
|
|
28
|
+
* Matches the common Next.js local-dev order: `.env` first, then `.env.local`
|
|
29
|
+
* overrides. Never overwrites keys already set in the parent environment
|
|
30
|
+
* (CI secrets, inline exports).
|
|
31
|
+
*/
|
|
32
|
+
export async function loadProjectEnv(
|
|
33
|
+
cwd: string,
|
|
34
|
+
baseEnv: Record<string, string | undefined> = process.env,
|
|
35
|
+
): Promise<Record<string, string | undefined>> {
|
|
36
|
+
const merged: Record<string, string | undefined> = { ...baseEnv }
|
|
37
|
+
|
|
38
|
+
for (const file of ['.env', '.env.local'] as const) {
|
|
39
|
+
try {
|
|
40
|
+
const content = await readFile(resolve(cwd, file), 'utf-8')
|
|
41
|
+
for (const [key, value] of Object.entries(parseDotenv(content))) {
|
|
42
|
+
if (merged[key] === undefined || merged[key] === '') {
|
|
43
|
+
merged[key] = value
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} catch {
|
|
47
|
+
// Missing env file is normal.
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return merged
|
|
52
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
|
|
3
|
+
export interface Logger {
|
|
4
|
+
info(message: string): void
|
|
5
|
+
success(message: string): void
|
|
6
|
+
warn(message: string): void
|
|
7
|
+
error(message: string): void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const logger: Logger = {
|
|
11
|
+
info(message: string): void {
|
|
12
|
+
console.log(chalk.blue('ℹ'), message)
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
success(message: string): void {
|
|
16
|
+
console.log(chalk.green('✔'), message)
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
warn(message: string): void {
|
|
20
|
+
console.warn(chalk.yellow('⚠'), message)
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
error(message: string): void {
|
|
24
|
+
console.error(chalk.red('✖'), message)
|
|
25
|
+
},
|
|
26
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
const SCHEMA_CANDIDATES = ['prisma/schema.prisma', 'schema.prisma'] as const
|
|
5
|
+
|
|
6
|
+
const CLIENT_ENTRY_NAMES = ['client.ts', 'client.js', 'client.mjs', 'index.ts', 'index.js'] as const
|
|
7
|
+
|
|
8
|
+
const OUTPUT_DIR_FALLBACKS = [['generated', 'prisma'], ['src', 'generated'], ['generated']] as const
|
|
9
|
+
|
|
10
|
+
/** Locate the consumer project's Prisma schema file. */
|
|
11
|
+
export function findPrismaSchemaFile(cwd = process.cwd()): string | null {
|
|
12
|
+
for (const rel of SCHEMA_CANDIDATES) {
|
|
13
|
+
const candidate = path.join(cwd, rel)
|
|
14
|
+
if (existsSync(candidate)) return candidate
|
|
15
|
+
}
|
|
16
|
+
return null
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Parse `generator client { output = "..." }` and return the absolute output
|
|
21
|
+
* directory. Relative paths resolve from the schema file's directory (Prisma
|
|
22
|
+
* convention), including `../generated/prisma` layouts.
|
|
23
|
+
*/
|
|
24
|
+
export function parsePrismaGeneratorOutputDir(schemaPath: string): string | null {
|
|
25
|
+
let content: string
|
|
26
|
+
try {
|
|
27
|
+
content = readFileSync(schemaPath, 'utf8')
|
|
28
|
+
} catch {
|
|
29
|
+
return null
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const match = content.match(/output\s*=\s*"([^"]+)"/)
|
|
33
|
+
if (!match?.[1]) return null
|
|
34
|
+
|
|
35
|
+
const raw = match[1].replace(/\//g, path.sep)
|
|
36
|
+
if (path.isAbsolute(raw)) return raw
|
|
37
|
+
return path.resolve(path.dirname(schemaPath), raw)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** First existing Prisma client entry file inside `dir`. */
|
|
41
|
+
export function resolveClientEntryInDir(dir: string): string | null {
|
|
42
|
+
for (const name of CLIENT_ENTRY_NAMES) {
|
|
43
|
+
const candidate = path.join(dir, name)
|
|
44
|
+
if (existsSync(candidate)) return candidate
|
|
45
|
+
}
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Resolve the generated Prisma client module path for CLI database commands.
|
|
51
|
+
* Reads the schema's custom `output` path before falling back to common
|
|
52
|
+
* scaffold locations (`generated/prisma`, `src/generated`, …).
|
|
53
|
+
*/
|
|
54
|
+
export function resolveProjectPrismaClientModule(cwd = process.cwd()): string | null {
|
|
55
|
+
const schemaPath = findPrismaSchemaFile(cwd)
|
|
56
|
+
if (schemaPath) {
|
|
57
|
+
const outputDir = parsePrismaGeneratorOutputDir(schemaPath)
|
|
58
|
+
if (outputDir) {
|
|
59
|
+
const entry = resolveClientEntryInDir(outputDir)
|
|
60
|
+
if (entry) return entry
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
for (const parts of OUTPUT_DIR_FALLBACKS) {
|
|
65
|
+
const entry = resolveClientEntryInDir(path.resolve(cwd, ...parts))
|
|
66
|
+
if (entry) return entry
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return null
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Project helpers that wrap Prisma 7 + driver adapters (preferred when present). */
|
|
73
|
+
export const LIB_PRISMA_HELPERS = ['lib/prisma.ts', 'lib/prisma.js', 'lib/prisma.mjs'] as const
|
|
74
|
+
|
|
75
|
+
export function findLibPrismaHelper(cwd = process.cwd()): string | null {
|
|
76
|
+
for (const rel of LIB_PRISMA_HELPERS) {
|
|
77
|
+
const candidate = path.join(cwd, rel)
|
|
78
|
+
if (existsSync(candidate)) return candidate
|
|
79
|
+
}
|
|
80
|
+
return null
|
|
81
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Minimal Vercel REST client for the CLI. Scope is deliberately small: read a
|
|
6
|
+
* project's environment variables so we can validate Blob wiring and print a
|
|
7
|
+
* per-environment readiness matrix. No write operations.
|
|
8
|
+
*
|
|
9
|
+
* Auth: a Vercel access token via `--token`, `VERCEL_TOKEN`, or
|
|
10
|
+
* `VERCEL_API_TOKEN`. Project/team identity from `.vercel/project.json` (written
|
|
11
|
+
* by `vercel link`) or explicit overrides. The client is fetch-injectable so the
|
|
12
|
+
* evaluation logic can be unit-tested without network access.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const DEFAULT_BASE_URL = 'https://api.vercel.com'
|
|
16
|
+
|
|
17
|
+
export const VERCEL_TARGETS = ['production', 'preview', 'development'] as const
|
|
18
|
+
export type VercelTarget = (typeof VERCEL_TARGETS)[number]
|
|
19
|
+
|
|
20
|
+
export interface VercelLink {
|
|
21
|
+
projectId: string
|
|
22
|
+
orgId?: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface VercelEnvVar {
|
|
26
|
+
key: string
|
|
27
|
+
/** Targets this var applies to, e.g. ['production', 'preview']. */
|
|
28
|
+
target: VercelTarget[]
|
|
29
|
+
type?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class VercelApiError extends Error {
|
|
33
|
+
readonly status: number
|
|
34
|
+
|
|
35
|
+
constructor(message: string, status: number) {
|
|
36
|
+
super(message)
|
|
37
|
+
this.name = 'VercelApiError'
|
|
38
|
+
this.status = status
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Read `.vercel/project.json` (written by `vercel link`). Returns null if absent. */
|
|
43
|
+
export async function readVercelLink(cwd: string): Promise<VercelLink | null> {
|
|
44
|
+
try {
|
|
45
|
+
const raw = await readFile(join(cwd, '.vercel', 'project.json'), 'utf-8')
|
|
46
|
+
const parsed = JSON.parse(raw) as { projectId?: string; orgId?: string }
|
|
47
|
+
if (!parsed.projectId) return null
|
|
48
|
+
return { projectId: parsed.projectId, orgId: parsed.orgId }
|
|
49
|
+
} catch {
|
|
50
|
+
return null
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Resolve a Vercel token from an explicit flag or the standard env vars. */
|
|
55
|
+
export function resolveVercelToken(explicit?: string): string | undefined {
|
|
56
|
+
return explicit ?? process.env.VERCEL_TOKEN ?? process.env.VERCEL_API_TOKEN ?? undefined
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface VercelClientOptions {
|
|
60
|
+
token: string
|
|
61
|
+
/** Team / org id, appended as `teamId` when the project belongs to a team. */
|
|
62
|
+
teamId?: string
|
|
63
|
+
fetchImpl?: typeof fetch
|
|
64
|
+
baseUrl?: string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface VercelClient {
|
|
68
|
+
listProjectEnv(projectId: string): Promise<VercelEnvVar[]>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function createVercelClient(options: VercelClientOptions): VercelClient {
|
|
72
|
+
const fetchImpl = options.fetchImpl ?? fetch
|
|
73
|
+
const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL
|
|
74
|
+
|
|
75
|
+
async function request<T>(path: string): Promise<T> {
|
|
76
|
+
const url = new URL(path, baseUrl)
|
|
77
|
+
if (options.teamId) url.searchParams.set('teamId', options.teamId)
|
|
78
|
+
|
|
79
|
+
const response = await fetchImpl(url.toString(), {
|
|
80
|
+
headers: { Authorization: `Bearer ${options.token}` },
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
let detail = ''
|
|
85
|
+
try {
|
|
86
|
+
const body = (await response.json()) as { error?: { message?: string } }
|
|
87
|
+
detail = body?.error?.message ? `: ${body.error.message}` : ''
|
|
88
|
+
} catch {
|
|
89
|
+
// non-JSON error body — status alone is enough context
|
|
90
|
+
}
|
|
91
|
+
throw new VercelApiError(
|
|
92
|
+
`Vercel API request failed (HTTP ${response.status})${detail}`,
|
|
93
|
+
response.status,
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return (await response.json()) as T
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
async listProjectEnv(projectId: string): Promise<VercelEnvVar[]> {
|
|
102
|
+
const data = await request<{ envs?: VercelEnvVar[] }>(
|
|
103
|
+
`/v9/projects/${encodeURIComponent(projectId)}/env`,
|
|
104
|
+
)
|
|
105
|
+
return (data.envs ?? []).map((env) => ({
|
|
106
|
+
key: env.key,
|
|
107
|
+
target: Array.isArray(env.target) ? env.target : [],
|
|
108
|
+
type: env.type,
|
|
109
|
+
}))
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
}
|