openadminjs 0.1.24 → 0.3.0-rc.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.
Files changed (210) hide show
  1. package/README.md +117 -81
  2. package/dist/adapt-package-manager.d.ts +3 -0
  3. package/dist/adapt-package-manager.js +118 -0
  4. package/dist/create-project.d.ts +77 -2
  5. package/dist/create-project.js +685 -224
  6. package/dist/db-commands.d.ts +20 -0
  7. package/dist/db-commands.js +75 -0
  8. package/dist/detect-package-manager.d.ts +8 -0
  9. package/dist/detect-package-manager.js +37 -0
  10. package/dist/doctor.d.ts +26 -0
  11. package/dist/doctor.js +232 -0
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +476 -166
  14. package/dist/render-schema.d.ts +3 -0
  15. package/dist/render-schema.js +33 -0
  16. package/dist/resource-slug.d.ts +1 -0
  17. package/dist/resource-slug.js +7 -0
  18. package/dist/runtime-mode.d.ts +16 -0
  19. package/dist/runtime-mode.js +138 -0
  20. package/dist/secrets.d.ts +24 -0
  21. package/dist/secrets.js +93 -0
  22. package/dist/security.d.ts +13 -0
  23. package/dist/security.js +168 -0
  24. package/dist/upgrade.d.ts +10 -0
  25. package/dist/upgrade.js +133 -0
  26. package/dist/validate-name.d.ts +33 -0
  27. package/dist/validate-name.js +206 -0
  28. package/package.json +39 -11
  29. package/template/.dockerignore +15 -0
  30. package/template/.env.production.example +5 -0
  31. package/template/Dockerfile +12 -0
  32. package/template/README.md +23 -3
  33. package/template/apps/admin/app/api/auth/login/route.ts +9 -9
  34. package/template/apps/admin/app/api/auth/logout/route.ts +11 -3
  35. package/template/apps/admin/app/api/auth/oidc/callback/route.ts +19 -0
  36. package/template/apps/admin/app/api/auth/oidc/start/route.ts +11 -0
  37. package/template/apps/admin/app/api/auth/oidc/status/route.ts +6 -0
  38. package/template/apps/admin/app/api/auth/refresh/route.ts +18 -11
  39. package/template/apps/admin/app/api/backend/[...path]/route.ts +48 -0
  40. package/template/apps/admin/app/api-tokens/page.tsx +39 -39
  41. package/template/apps/admin/app/assistant/page.tsx +11 -0
  42. package/template/apps/admin/app/dashboard/page.tsx +45 -462
  43. package/template/apps/admin/app/globals.css +52 -16
  44. package/template/apps/admin/app/layout.tsx +1 -1
  45. package/template/apps/admin/app/login/page.tsx +13 -145
  46. package/template/apps/admin/app/plugins/page.tsx +16 -402
  47. package/template/apps/admin/app/profile/page.tsx +5 -2
  48. package/template/apps/admin/app/settings/page.tsx +14 -265
  49. package/template/apps/admin/components/ai-assistant-widget.tsx +3 -6
  50. package/template/apps/admin/components/app-shell.tsx +25 -373
  51. package/template/apps/admin/components/auth-guard.tsx +8 -28
  52. package/template/apps/admin/components/logo.tsx +1 -30
  53. package/template/apps/admin/components/resource-form.tsx +3 -3
  54. package/template/apps/admin/components/resource-table.tsx +12 -8
  55. package/template/apps/admin/lib/api.ts +45 -107
  56. package/template/apps/admin/lib/resource-table-prefs.ts +1 -57
  57. package/template/apps/admin/lib/server-api.ts +7 -0
  58. package/template/apps/admin/lib/tokens.ts +9 -81
  59. package/template/apps/admin/middleware.ts +9 -50
  60. package/template/apps/admin/next.config.mjs +4 -0
  61. package/template/apps/admin/package.json +2 -1
  62. package/template/apps/admin/public/brand/favicon.svg +4 -1
  63. package/template/apps/admin/tailwind.config.ts +9 -8
  64. package/template/apps/api/package.json +13 -6
  65. package/template/apps/api/src/access/catalog.ts +4 -0
  66. package/template/apps/api/src/admin/admin-ai.controller.ts +15 -125
  67. package/template/apps/api/src/admin/admin-analytics.service.ts +16 -148
  68. package/template/apps/api/src/admin/admin-logs.controller.ts +4 -1
  69. package/template/apps/api/src/admin/admin-plugins.controller.ts +8 -8
  70. package/template/apps/api/src/admin/admin-plugins.service.ts +15 -259
  71. package/template/apps/api/src/admin/admin-resource.service.ts +105 -254
  72. package/template/apps/api/src/admin/admin.controller.ts +17 -4
  73. package/template/apps/api/src/admin/admin.module.ts +2 -2
  74. package/template/apps/api/src/admin/resource-policy.ts +1 -0
  75. package/template/apps/api/src/admin/resource-query.ts +1 -0
  76. package/template/apps/api/src/admin/safe-ai.service.ts +43 -0
  77. package/template/apps/api/src/admin/validate-resource-payload.ts +2 -0
  78. package/template/apps/api/src/auth/auth.controller.ts +4 -2
  79. package/template/apps/api/src/auth/auth.service.ts +68 -83
  80. package/template/apps/api/src/auth/sso-oidc.controller.ts +12 -74
  81. package/template/apps/api/src/auth/sso-oidc.service.ts +51 -268
  82. package/template/apps/api/src/common/api-exception.filter.ts +1 -0
  83. package/template/apps/api/src/common/auth.guard.ts +66 -39
  84. package/template/apps/api/src/common/json-field-codec.ts +138 -0
  85. package/template/apps/api/src/common/prisma.service.ts +12 -7
  86. package/template/apps/api/src/common/request-logging.interceptor.ts +8 -3
  87. package/template/apps/api/src/graphql/graphql.module.ts +14 -1
  88. package/template/apps/api/src/health/health.controller.ts +6 -0
  89. package/template/apps/api/src/main.ts +11 -2
  90. package/template/apps/api/src/plugins/plugin-loader.ts +5 -3
  91. package/template/apps/api/src/resources/commerce.resource.ts +3 -34
  92. package/template/apps/api/src/resources/operations.resource.ts +1 -0
  93. package/template/apps/api/src/store/payment/payment.controller.ts +15 -92
  94. package/template/apps/api/src/store/payment/payment.module.ts +2 -3
  95. package/template/apps/api/src/store/payment/payment.service.ts +121 -227
  96. package/template/apps/api/webpack.config.cjs +2 -1
  97. package/template/apps/web/next.config.mjs +4 -0
  98. package/template/apps/web/public/brand/favicon.svg +4 -1
  99. package/template/compose.yaml +56 -0
  100. package/template/examples/crm-admin/README.md +31 -0
  101. package/template/examples/crm-admin/package.json +17 -0
  102. package/template/examples/crm-admin/prisma/models.fragment.prisma +50 -0
  103. package/template/examples/crm-admin/src/index.ts +7 -0
  104. package/template/examples/crm-admin/src/resources/activities.resource.ts +29 -0
  105. package/template/examples/crm-admin/src/resources/companies.resource.ts +21 -0
  106. package/template/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
  107. package/template/examples/crm-admin/src/resources/deals.resource.ts +30 -0
  108. package/template/examples/crm-admin/tsconfig.json +7 -0
  109. package/template/package.json +8 -1
  110. package/template/packages/admin-client/package.json +18 -0
  111. package/template/packages/admin-client/src/contracts.ts +29 -0
  112. package/template/packages/admin-client/src/index.ts +2 -0
  113. package/template/packages/admin-client/src/preferences.ts +57 -0
  114. package/template/packages/admin-client/tsconfig.json +12 -0
  115. package/template/packages/auth/package.json +1 -1
  116. package/template/packages/brand/site/assets/brand/favicon.svg +4 -1
  117. package/template/packages/brand/src/generate-assets.mjs +17 -186
  118. package/template/packages/core/package.json +1 -1
  119. package/template/packages/mail/package.json +1 -1
  120. package/template/packages/nest/package.json +22 -0
  121. package/template/packages/nest/src/api-exception.filter.ts +23 -0
  122. package/template/packages/nest/src/index.ts +3 -0
  123. package/template/packages/nest/src/resource-policy.ts +64 -0
  124. package/template/packages/nest/src/resource-query.ts +103 -0
  125. package/template/packages/nest/tsconfig.json +12 -0
  126. package/template/packages/notifications/package.json +1 -1
  127. package/template/packages/payments/package.json +1 -1
  128. package/template/packages/permissions/package.json +1 -1
  129. package/template/packages/permissions/src/index.ts +2 -2
  130. package/template/packages/plugin-sdk/package.json +1 -1
  131. package/template/packages/plugin-sdk/src/index.ts +2 -2
  132. package/template/packages/prisma/package.json +21 -0
  133. package/template/packages/prisma/schema/ai.prisma +36 -0
  134. package/template/packages/prisma/schema/audit.prisma +13 -0
  135. package/template/packages/prisma/schema/commerce.prisma +79 -0
  136. package/template/packages/prisma/schema/content.prisma +27 -0
  137. package/template/packages/prisma/schema/core.prisma +106 -0
  138. package/template/packages/prisma/schema/header.prisma +8 -0
  139. package/template/packages/prisma/schema/jobs.prisma +9 -0
  140. package/template/packages/prisma/schema/media.prisma +9 -0
  141. package/template/packages/prisma/schema/modules.json +47 -0
  142. package/template/packages/prisma/schema/notifications.prisma +9 -0
  143. package/template/packages/prisma/schema/settings.prisma +8 -0
  144. package/template/packages/prisma/schema/tokens.prisma +10 -0
  145. package/template/packages/prisma/src/index.d.ts +12 -0
  146. package/template/packages/prisma/src/index.mjs +138 -0
  147. package/template/packages/queue/package.json +1 -1
  148. package/template/packages/resource/package.json +1 -1
  149. package/template/packages/resource/src/index.ts +1 -0
  150. package/template/packages/storage/package.json +1 -1
  151. package/template/packages/storage/src/index.ts +37 -0
  152. package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
  153. package/template/prisma/migrations/20261126130000_add_sessions/migration.sql +26 -0
  154. package/template/prisma/migrations/20261126140000_api_token_hash/migration.sql +3 -0
  155. package/template/prisma/migrations/20261126150000_payment_idempotency/migration.sql +6 -0
  156. package/template/prisma/schema.prisma +82 -54
  157. package/template/prisma/seed.ts +14 -38
  158. package/template/runtime-versions.json +15 -0
  159. package/template/scripts/db-init.mjs +33 -0
  160. package/template/scripts/install-crm.mjs +50 -0
  161. package/template/scripts/migrate-existing.mjs +65 -0
  162. package/template/scripts/schema.mjs +48 -0
  163. package/template/tsconfig.base.json +23 -5
  164. package/LICENSE +0 -21
  165. package/dist/create-project.test.d.ts +0 -1
  166. package/dist/create-project.test.js +0 -99
  167. package/dist/index.test.d.ts +0 -1
  168. package/dist/index.test.js +0 -7
  169. package/dist/resource-slug.test.d.ts +0 -1
  170. package/dist/resource-slug.test.js +0 -9
  171. package/template/apps/admin/.storybook/main.ts +0 -12
  172. package/template/apps/admin/.storybook/preview.ts +0 -10
  173. package/template/apps/admin/app/login/page.test.tsx +0 -18
  174. package/template/apps/admin/components/auth-guard.test.tsx +0 -55
  175. package/template/apps/admin/components/logo.stories.tsx +0 -24
  176. package/template/apps/admin/lib/api.test.ts +0 -118
  177. package/template/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
  178. package/template/apps/admin/vitest.config.ts +0 -7
  179. package/template/apps/api/src/access/derive-permissions.test.ts +0 -26
  180. package/template/apps/api/src/admin/admin-resource.service.test.ts +0 -118
  181. package/template/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
  182. package/template/apps/api/src/app.module.test.ts +0 -12
  183. package/template/apps/api/src/auth/auth.service.test.ts +0 -78
  184. package/template/apps/api/src/auth/sso-oidc.service.test.ts +0 -84
  185. package/template/apps/api/src/common/auth.guard.test.ts +0 -62
  186. package/template/apps/api/src/common/casl-ability.factory.test.ts +0 -33
  187. package/template/apps/api/src/common/request-logging.interceptor.test.ts +0 -39
  188. package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +0 -45
  189. package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +0 -44
  190. package/template/apps/api/src/graphql/graphql-schema.test.ts +0 -26
  191. package/template/apps/api/src/plugins/manifest.schema.test.ts +0 -36
  192. package/template/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
  193. package/template/apps/api/src/queue/queue.service.test.ts +0 -33
  194. package/template/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
  195. package/template/apps/api/vitest.config.ts +0 -21
  196. package/template/apps/web/lib/seo.test.ts +0 -41
  197. package/template/apps/web/vitest.config.ts +0 -19
  198. package/template/packages/auth/src/index.test.ts +0 -10
  199. package/template/packages/brand/src/index.test.ts +0 -9
  200. package/template/packages/core/src/index.test.ts +0 -27
  201. package/template/packages/core/vitest.config.ts +0 -9
  202. package/template/packages/mail/src/index.test.ts +0 -23
  203. package/template/packages/notifications/src/index.test.ts +0 -9
  204. package/template/packages/permissions/src/blueprints.test.ts +0 -62
  205. package/template/packages/permissions/src/index.test.ts +0 -34
  206. package/template/packages/plugin-sdk/src/sdk.test.ts +0 -13
  207. package/template/packages/plugin-sdk/vitest.config.ts +0 -5
  208. package/template/packages/queue/src/index.test.ts +0 -12
  209. package/template/packages/resource/src/index.test.ts +0 -196
  210. package/template/packages/storage/src/index.test.ts +0 -10
@@ -0,0 +1,20 @@
1
+ import type { PackageManager } from "./adapt-package-manager.js";
2
+ export type DbAction = "migrate" | "seed" | "studio" | "reset";
3
+ export type DbCommand = {
4
+ cmd: string;
5
+ args: string[];
6
+ /** Human-readable form for --dry-run / logging. */
7
+ label: string;
8
+ /** True for destructive commands that require explicit confirmation. */
9
+ destructive: boolean;
10
+ };
11
+ /**
12
+ * Builds the process invocation for a db command using an argument array (never
13
+ * an interpolated shell string), so user input cannot inject shell commands.
14
+ */
15
+ export declare function buildDbCommand(action: DbAction, mode: string | undefined, pm: PackageManager): DbCommand;
16
+ /**
17
+ * Spawns a command inheriting stdio, forwarding SIGINT/SIGTERM to the child, and
18
+ * resolving with the child's exit code.
19
+ */
20
+ export declare function runInherit(cmd: string, args: string[], cwd: string): Promise<number>;
@@ -0,0 +1,75 @@
1
+ import { spawn } from "node:child_process";
2
+ import { runScriptPrefix } from "./detect-package-manager.js";
3
+ const DB_SCRIPTS = {
4
+ "migrate:dev": "db:migrate",
5
+ "migrate:deploy": "db:migrate:deploy",
6
+ seed: "db:seed",
7
+ studio: "db:studio",
8
+ reset: "db:reset"
9
+ };
10
+ /**
11
+ * Builds the process invocation for a db command using an argument array (never
12
+ * an interpolated shell string), so user input cannot inject shell commands.
13
+ */
14
+ export function buildDbCommand(action, mode, pm) {
15
+ let key;
16
+ let destructive = false;
17
+ switch (action) {
18
+ case "migrate": {
19
+ const m = (mode ?? "dev").toLowerCase();
20
+ if (m !== "dev" && m !== "deploy") {
21
+ throw new Error(`Unknown migrate mode "${mode}". Use "dev" or "deploy".`);
22
+ }
23
+ key = `migrate:${m}`;
24
+ break;
25
+ }
26
+ case "seed":
27
+ key = "seed";
28
+ break;
29
+ case "studio":
30
+ key = "studio";
31
+ break;
32
+ case "reset":
33
+ key = "reset";
34
+ destructive = true;
35
+ break;
36
+ default:
37
+ throw new Error(`Unknown db action "${action}". Use: migrate, seed, studio, reset.`);
38
+ }
39
+ const script = DB_SCRIPTS[key];
40
+ if (!script)
41
+ throw new Error(`No script mapping for "${key}".`);
42
+ const [cmd, args] = runScriptPrefix(pm, script);
43
+ return { cmd, args, label: `${cmd} ${args.join(" ")}`, destructive };
44
+ }
45
+ /**
46
+ * Spawns a command inheriting stdio, forwarding SIGINT/SIGTERM to the child, and
47
+ * resolving with the child's exit code.
48
+ */
49
+ export function runInherit(cmd, args, cwd) {
50
+ return new Promise((resolve, reject) => {
51
+ const child = spawn(cmd, args, { cwd, stdio: "inherit" });
52
+ const forward = (signal) => {
53
+ if (!child.killed)
54
+ child.kill(signal);
55
+ };
56
+ process.on("SIGINT", forward);
57
+ process.on("SIGTERM", forward);
58
+ const cleanup = () => {
59
+ process.off("SIGINT", forward);
60
+ process.off("SIGTERM", forward);
61
+ };
62
+ child.on("error", (err) => {
63
+ cleanup();
64
+ reject(err);
65
+ });
66
+ child.on("close", (code, signal) => {
67
+ cleanup();
68
+ if (signal) {
69
+ resolve(1);
70
+ return;
71
+ }
72
+ resolve(code ?? 0);
73
+ });
74
+ });
75
+ }
@@ -0,0 +1,8 @@
1
+ import type { PackageManager } from "./adapt-package-manager.js";
2
+ /**
3
+ * Detects the package manager a generated project uses, preferring an explicit
4
+ * `packageManager` field, then lockfiles, then workspace config. Defaults to pnpm.
5
+ */
6
+ export declare function detectPackageManager(cwd: string): PackageManager;
7
+ /** Returns [command, prefixArgs] to run an npm-style script with the given PM. */
8
+ export declare function runScriptPrefix(pm: PackageManager, script: string): [string, string[]];
@@ -0,0 +1,37 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ /**
4
+ * Detects the package manager a generated project uses, preferring an explicit
5
+ * `packageManager` field, then lockfiles, then workspace config. Defaults to pnpm.
6
+ */
7
+ export function detectPackageManager(cwd) {
8
+ const pkgPath = join(cwd, "package.json");
9
+ if (existsSync(pkgPath)) {
10
+ try {
11
+ const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
12
+ const pm = pkg.packageManager ?? "";
13
+ if (pm.startsWith("pnpm"))
14
+ return "pnpm";
15
+ if (pm.startsWith("yarn"))
16
+ return "yarn";
17
+ if (pm.startsWith("npm"))
18
+ return "npm";
19
+ }
20
+ catch {
21
+ // fall through to lockfile detection
22
+ }
23
+ }
24
+ if (existsSync(join(cwd, "pnpm-lock.yaml")) || existsSync(join(cwd, "pnpm-workspace.yaml")))
25
+ return "pnpm";
26
+ if (existsSync(join(cwd, "yarn.lock")))
27
+ return "yarn";
28
+ if (existsSync(join(cwd, "package-lock.json")))
29
+ return "npm";
30
+ return "pnpm";
31
+ }
32
+ /** Returns [command, prefixArgs] to run an npm-style script with the given PM. */
33
+ export function runScriptPrefix(pm, script) {
34
+ if (pm === "npm")
35
+ return ["npm", ["run", script]];
36
+ return [pm, [script]];
37
+ }
@@ -0,0 +1,26 @@
1
+ export type CheckStatus = "pass" | "warn" | "fail";
2
+ export type CheckResult = {
3
+ name: string;
4
+ status: CheckStatus;
5
+ message: string;
6
+ };
7
+ export type DoctorReport = {
8
+ results: CheckResult[];
9
+ ok: boolean;
10
+ };
11
+ /**
12
+ * Verifies the Prisma Client is genuinely usable — not just that the
13
+ * `@prisma/client` package exists on disk. The un-generated package ships a
14
+ * stub that throws "did not initialize yet" at require time, so we actually
15
+ * load it in a child process. This distinguishes:
16
+ * - fail: package missing (deps not installed)
17
+ * - warn: package present but not generated (recoverable: run prisma generate)
18
+ * - pass: generated client loads and exposes PrismaClient
19
+ */
20
+ export declare function checkPrismaClientUsable(cwd: string, pm: string): {
21
+ status: CheckStatus;
22
+ message: string;
23
+ };
24
+ export declare function runDoctorChecks(cwd: string, opts?: {
25
+ skipNetwork?: boolean;
26
+ }): Promise<DoctorReport>;
package/dist/doctor.js ADDED
@@ -0,0 +1,232 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import net from "node:net";
4
+ import { spawnSync } from "node:child_process";
5
+ import { detectPackageManager } from "./detect-package-manager.js";
6
+ import { isPackageManagerAvailable, MIN_NODE_MAJOR } from "./create-project.js";
7
+ import { inspectPassword, inspectSecret } from "./secrets.js";
8
+ function parseEnv(content) {
9
+ const env = {};
10
+ for (const line of content.split(/\r?\n/)) {
11
+ const trimmed = line.trim();
12
+ if (!trimmed || trimmed.startsWith("#"))
13
+ continue;
14
+ const eq = trimmed.indexOf("=");
15
+ if (eq < 0)
16
+ continue;
17
+ const key = trimmed.slice(0, eq).trim();
18
+ let value = trimmed.slice(eq + 1).trim();
19
+ if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
20
+ value = value.slice(1, -1);
21
+ }
22
+ env[key] = value;
23
+ }
24
+ return env;
25
+ }
26
+ function readFileSafe(path) {
27
+ try {
28
+ return readFileSync(path, "utf8");
29
+ }
30
+ catch {
31
+ return undefined;
32
+ }
33
+ }
34
+ async function tcpReachable(host, port, timeoutMs = 1200) {
35
+ return new Promise((resolve) => {
36
+ const socket = net.createConnection({ host, port });
37
+ const done = (ok) => {
38
+ socket.destroy();
39
+ resolve(ok);
40
+ };
41
+ socket.setTimeout(timeoutMs, () => done(false));
42
+ socket.once("error", () => done(false));
43
+ socket.once("connect", () => done(true));
44
+ });
45
+ }
46
+ /**
47
+ * Verifies the Prisma Client is genuinely usable — not just that the
48
+ * `@prisma/client` package exists on disk. The un-generated package ships a
49
+ * stub that throws "did not initialize yet" at require time, so we actually
50
+ * load it in a child process. This distinguishes:
51
+ * - fail: package missing (deps not installed)
52
+ * - warn: package present but not generated (recoverable: run prisma generate)
53
+ * - pass: generated client loads and exposes PrismaClient
54
+ */
55
+ export function checkPrismaClientUsable(cwd, pm) {
56
+ const pkgDir = join(cwd, "node_modules", "@prisma", "client");
57
+ if (!existsSync(pkgDir)) {
58
+ // Recoverable and already surfaced by the node-modules check; keep as warn.
59
+ return { status: "warn", message: `@prisma/client is not installed — run "${pm} install".` };
60
+ }
61
+ const probe = spawnSync(process.execPath, ["-e", "const m=require('@prisma/client'); if(typeof m.PrismaClient!=='function'){process.exit(3);}"], { cwd, encoding: "utf8", timeout: 20000 });
62
+ if (probe.status === 0) {
63
+ return { status: "pass", message: "Prisma Client is generated and loads successfully." };
64
+ }
65
+ const stderr = (probe.stderr || "").trim();
66
+ const notGenerated = /did not initialize yet|prisma generate/i.test(stderr) || probe.status === 3;
67
+ if (notGenerated) {
68
+ return {
69
+ status: "warn",
70
+ message: `Prisma Client is not generated — run "${pm} db:migrate" or "prisma generate".`
71
+ };
72
+ }
73
+ // Present, generated, but genuinely fails to load — a blocking error.
74
+ return {
75
+ status: "fail",
76
+ message: `Prisma Client failed to load: ${stderr.split("\n").pop() ?? "unknown error"}`
77
+ };
78
+ }
79
+ export async function runDoctorChecks(cwd, opts = {}) {
80
+ const results = [];
81
+ const add = (name, status, message) => results.push({ name, status, message });
82
+ const nodeMajor = Number(process.versions.node.split(".")[0]);
83
+ if (nodeMajor >= MIN_NODE_MAJOR)
84
+ add("node-version", "pass", `Node.js ${process.versions.node}`);
85
+ else
86
+ add("node-version", "fail", `Node.js ${process.versions.node} is below the required ${MIN_NODE_MAJOR}.`);
87
+ const pm = detectPackageManager(cwd);
88
+ if (opts.skipNetwork) {
89
+ add("package-manager", "pass", `Detected ${pm} (availability check skipped).`);
90
+ }
91
+ else if (isPackageManagerAvailable(pm)) {
92
+ add("package-manager", "pass", `${pm} is installed.`);
93
+ }
94
+ else {
95
+ add("package-manager", "fail", `${pm} is not installed or not on PATH.`);
96
+ }
97
+ const hasNodeModules = existsSync(join(cwd, "node_modules"));
98
+ if (hasNodeModules)
99
+ add("node-modules", "pass", "Dependencies are installed.");
100
+ else
101
+ add("node-modules", "fail", `node_modules missing — run "${pm} install".`);
102
+ const schemaPath = join(cwd, "prisma", "schema.prisma");
103
+ const schema = readFileSafe(schemaPath);
104
+ if (schema)
105
+ add("prisma-schema", "pass", "prisma/schema.prisma present.");
106
+ else
107
+ add("prisma-schema", "fail", "prisma/schema.prisma is missing.");
108
+ const envPath = join(cwd, "apps", "api", ".env");
109
+ const envRaw = readFileSafe(envPath);
110
+ const env = envRaw ? parseEnv(envRaw) : {};
111
+ if (envRaw)
112
+ add("env-file", "pass", "apps/api/.env present.");
113
+ else
114
+ add("env-file", "fail", "apps/api/.env is missing.");
115
+ const requiredEnv = ["DATABASE_URL", "REDIS_URL", "JWT_SECRET", "JWT_REFRESH_SECRET"];
116
+ const missingEnv = requiredEnv.filter((k) => !env[k]);
117
+ if (envRaw) {
118
+ if (missingEnv.length === 0)
119
+ add("env-vars", "pass", "Required environment variables are set.");
120
+ else
121
+ add("env-vars", "fail", `Missing env vars: ${missingEnv.join(", ")}.`);
122
+ }
123
+ const clientCheck = checkPrismaClientUsable(cwd, pm);
124
+ add("prisma-client", clientCheck.status, clientCheck.message);
125
+ // prisma validate (best-effort; only when deps + a local prisma binary exist)
126
+ const prismaBin = join(cwd, "node_modules", ".bin", process.platform === "win32" ? "prisma.cmd" : "prisma");
127
+ if (schema && existsSync(prismaBin)) {
128
+ const res = spawnSync(prismaBin, ["validate", "--schema", schemaPath], { cwd, encoding: "utf8" });
129
+ if (res.status === 0)
130
+ add("prisma-validate", "pass", "prisma validate succeeded.");
131
+ else
132
+ add("prisma-validate", "fail", `prisma validate failed: ${(res.stderr || res.stdout || "").trim().split("\n").pop() ?? "error"}`);
133
+ }
134
+ else {
135
+ add("prisma-validate", "warn", "Skipped prisma validate (install dependencies first).");
136
+ }
137
+ // migration provider consistency
138
+ const lockPath = join(cwd, "prisma", "migrations", "migration_lock.toml");
139
+ const lockRaw = readFileSafe(lockPath);
140
+ // Read the provider from the `datasource` block, not the `generator` block.
141
+ const schemaProvider = schema
142
+ ?.match(/datasource\s+\w+\s*\{[^}]*?provider\s*=\s*"([^"]+)"/m)?.[1];
143
+ const lockProvider = lockRaw?.match(/provider\s*=\s*"([^"]+)"/)?.[1];
144
+ if (lockRaw && schemaProvider && lockProvider) {
145
+ if (schemaProvider === lockProvider) {
146
+ add("migration-provider", "pass", `Migration provider matches schema (${schemaProvider}).`);
147
+ }
148
+ else {
149
+ add("migration-provider", "fail", `Schema provider "${schemaProvider}" does not match migration_lock.toml "${lockProvider}".`);
150
+ }
151
+ }
152
+ // incompatible migration SQL for non-postgres providers
153
+ if (schemaProvider && schemaProvider !== "postgresql" && lockProvider === "postgresql") {
154
+ add("migration-compat", "fail", "Migrations were generated for PostgreSQL but the schema uses a different provider.");
155
+ }
156
+ const pkgRaw = readFileSafe(join(cwd, "package.json"));
157
+ if (pkgRaw) {
158
+ try {
159
+ const scripts = JSON.parse(pkgRaw).scripts ?? {};
160
+ const requiredScripts = ["dev", "build", "test", "db:migrate", "db:seed"];
161
+ const missingScripts = requiredScripts.filter((s) => !scripts[s]);
162
+ if (missingScripts.length === 0)
163
+ add("root-scripts", "pass", "Required root scripts are present.");
164
+ else
165
+ add("root-scripts", "fail", `Missing root scripts: ${missingScripts.join(", ")}.`);
166
+ }
167
+ catch {
168
+ add("root-scripts", "fail", "Root package.json is not valid JSON.");
169
+ }
170
+ }
171
+ const lockfiles = ["pnpm-lock.yaml", "package-lock.json", "yarn.lock"].filter((f) => existsSync(join(cwd, f)));
172
+ if (lockfiles.length <= 1)
173
+ add("lockfiles", "pass", lockfiles.length ? `Single lockfile (${lockfiles[0]}).` : "No lockfile yet.");
174
+ else
175
+ add("lockfiles", "fail", `Conflicting lockfiles: ${lockfiles.join(", ")}.`);
176
+ if (!existsSync(join(cwd, ".gitignore")))
177
+ add("gitignore", "fail", ".gitignore is missing.");
178
+ else
179
+ add("gitignore", "pass", ".gitignore present.");
180
+ // .env tracked by git?
181
+ if (existsSync(join(cwd, ".git"))) {
182
+ const tracked = spawnSync("git", ["ls-files", "--error-unmatch", "apps/api/.env"], { cwd, stdio: "ignore" });
183
+ if (tracked.status === 0)
184
+ add("env-tracked", "fail", "apps/api/.env is tracked by Git — remove it and rotate secrets.");
185
+ else
186
+ add("env-tracked", "pass", "apps/api/.env is not tracked by Git.");
187
+ }
188
+ // weak secrets
189
+ if (envRaw) {
190
+ const weak = [];
191
+ const jwt = inspectSecret(env.JWT_SECRET, "JWT_SECRET");
192
+ const jwtR = inspectSecret(env.JWT_REFRESH_SECRET, "JWT_REFRESH_SECRET");
193
+ if (jwt.weak)
194
+ weak.push(jwt.reason);
195
+ if (jwtR.weak)
196
+ weak.push(jwtR.reason);
197
+ if (env.JWT_SECRET && env.JWT_SECRET === env.JWT_REFRESH_SECRET)
198
+ weak.push("JWT_SECRET equals JWT_REFRESH_SECRET");
199
+ const pw = inspectPassword(env.SUPERADMIN_PASSWORD);
200
+ if (env.SUPERADMIN_PASSWORD && pw.weak)
201
+ weak.push(pw.reason);
202
+ if (weak.length === 0)
203
+ add("secrets", "pass", "Secrets look strong.");
204
+ else
205
+ add("secrets", "fail", weak.join("; ") + ".");
206
+ }
207
+ // redis connectivity (only meaningful when configured)
208
+ if (env.REDIS_URL && !opts.skipNetwork) {
209
+ try {
210
+ const url = new URL(env.REDIS_URL);
211
+ const ok = await tcpReachable(url.hostname, Number(url.port) || 6379);
212
+ add("redis", ok ? "pass" : "warn", ok ? "Redis is reachable." : "Redis is not reachable (start it before running queues).");
213
+ }
214
+ catch {
215
+ add("redis", "warn", "REDIS_URL is not a valid URL.");
216
+ }
217
+ }
218
+ // database connectivity (skip for SQLite file URLs — no server to ping)
219
+ if (env.DATABASE_URL && !opts.skipNetwork && !env.DATABASE_URL.trim().toLowerCase().startsWith("file:")) {
220
+ try {
221
+ const url = new URL(env.DATABASE_URL);
222
+ const port = Number(url.port) || (schemaProvider === "mysql" ? 3306 : 5432);
223
+ const ok = await tcpReachable(url.hostname, port);
224
+ add("database", ok ? "pass" : "warn", ok ? "Database is reachable." : "Database is not reachable (is it running?).");
225
+ }
226
+ catch {
227
+ add("database", "warn", "DATABASE_URL is not a valid URL.");
228
+ }
229
+ }
230
+ const ok = !results.some((r) => r.status === "fail");
231
+ return { results, ok };
232
+ }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  #!/usr/bin/env node
2
- export {};
2
+ export { createProject, createProjectInteractive, databaseUrl, defaultTemplateDir, printNextSteps, printSecurityNotice, toPackageName, type CreateProjectOptions, type CreateProjectResult, type DatabaseDriver, type PackageManager } from "./create-project.js";
3
+ export { modelNameToResourceSlug } from "./resource-slug.js";
4
+ export declare function insertResourceField(content: string, name: string, snippet: string, force?: boolean): string;