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
package/README.md CHANGED
@@ -1,127 +1,163 @@
1
- # OpenAdminJS
1
+ # OpenAdminJS CLI
2
2
 
3
- OpenAdminJS is an open-source, resource-driven admin platform for the Node.js ecosystem, built with Nest.js, Prisma, PostgreSQL, Next.js, TailwindCSS and shadcn/ui.
3
+ **`openadminjs` is a CLI scaffold generator**, not a runtime library you import into React/Next/Nest apps. It creates a full monorepo (NestJS API, Next.js admin/web, shared packages).
4
4
 
5
- ![OpenAdminJS logo](https://js-senpai.github.io/open-admin-js/assets/brand/openadminjs-logo-new.png)
5
+ Full documentation: [https://js-senpai.github.io/open-admin-js/docs.html](https://js-senpai.github.io/open-admin-js/docs.html)
6
6
 
7
- ## Quick start (for package users)
7
+ ## Requirements
8
8
 
9
- Full documentation: [https://js-senpai.github.io/open-admin-js/docs.html](https://js-senpai.github.io/open-admin-js/docs.html)
9
+ - **Node.js 20+**
10
+ - **One of:** pnpm 9+ (recommended), npm 9+, or yarn 1.x / Berry
11
+ - **Database:** PostgreSQL 14+, MySQL 8+, or **SQLite 3** (local file, zero external DB)
12
+ - **Redis:** optional — background job queues are disabled when `REDIS_URL` is blank
13
+ - **Network:** Prisma downloads engine binaries on first install/generate (corporate proxies may need configuration)
14
+
15
+ The CLI verifies Node.js before writing files and detects which package managers are installed.
10
16
 
11
- ### 1. Create a new project
17
+ ## Quick start (interactive)
12
18
 
13
19
  ```bash
14
20
  npx openadminjs create my-app
15
21
  cd my-app
22
+ pnpm dev # or: npm run dev / yarn dev
16
23
  ```
17
24
 
18
- `npx` runs the single `openadminjs` package and scaffolds the project with dependencies installed automatically.
19
- During scaffolding, you can choose the database driver from a list (PostgreSQL, MySQL, or SQLite), and the CLI fills `DATABASE_URL` for you.
25
+ If you skipped install during create:
20
26
 
21
- ### 2. Configure environment
27
+ ```bash
28
+ pnpm install && pnpm db:migrate && pnpm db:seed
29
+ ```
22
30
 
23
- The scaffold wizard asks for database access and key env values (`DATABASE_URL`, `REDIS_URL`, JWT secrets) and writes ready-to-use values into `apps/api/.env` (including `SUPERADMIN_EMAIL` / `SUPERADMIN_PASSWORD` for non-interactive seed).
24
- `ADMIN_ORIGIN` and `API_PORT` are prefilled with defaults (`http://localhost:3000` and `4000`) and can be changed manually if needed.
25
- New projects do **not** include a root `.env.example` or root `.env`—use `apps/api/.env` as the source of truth (you can add your own `.env.example` for your team if you want).
31
+ During create, choosing **install** runs dependency install, schema apply, and seed automatically.
26
32
 
27
- Typical `apps/api/.env` keys (after create, edit as needed):
33
+ ### What `dev` starts
28
34
 
29
- ```env
30
- DATABASE_URL=postgresql://USER:PASSWORD@localhost:5432/openadminjs?schema=public
31
- REDIS_URL=redis://localhost:6379
32
- JWT_SECRET=replace-with-a-long-random-string-at-least-32-chars
33
- JWT_REFRESH_SECRET=another-long-random-string
34
- ADMIN_ORIGIN=http://localhost:3000
35
- API_PORT=4000
36
- SUPERADMIN_EMAIL=admin@localhost.dev
37
- SUPERADMIN_PASSWORD=your-secure-password
38
- ```
35
+ The root **`dev` script starts the admin UI and the API only** (not the public web app):
36
+
37
+ | Service | URL |
38
+ | ----------- | ------------------------------ |
39
+ | Admin | http://localhost:3000 |
40
+ | API | http://localhost:4000 |
41
+ | API Swagger | http://localhost:4000/api/docs |
39
42
 
40
- Optional (elsewhere / advanced):
43
+ Optional public web app (port 3001):
41
44
 
42
- ```env
43
- OPENADMIN_PLUGIN_PNPM_INSTALL=0
45
+ ```bash
46
+ pnpm --filter @openadminjs/web dev # npm: npm run dev --workspace=@openadminjs/web
44
47
  ```
45
48
 
46
- ### 3. Run project
49
+ ## Non-interactive / CI
50
+
51
+ When stdin is not a TTY (or you pass `--yes` / `--non-interactive`), the CLI uses flags and safe defaults — no prompts.
47
52
 
48
53
  ```bash
49
- pnpm dev
50
- ```
54
+ export OPENADMIN_ADMIN_PASSWORD="$(openssl rand -base64 24)"
51
55
 
52
- Typical URLs:
56
+ npx openadminjs create my-app \
57
+ --yes \
58
+ --package-manager npm \
59
+ --database sqlite \
60
+ --admin-email admin@example.com \
61
+ --admin-password-env OPENADMIN_ADMIN_PASSWORD \
62
+ --skip-redis
53
63
 
54
- | App | URL |
55
- | ----------- | ------------------------------ |
56
- | Admin | http://localhost:3000 |
57
- | API | http://localhost:4000 |
58
- | API Swagger | http://localhost:4000/api/docs |
59
- | Web (demo) | http://localhost:3001 |
64
+ cd my-app && npm run dev
65
+ ```
60
66
 
61
- ### 4. Sign in
67
+ Prefer **`--admin-password-env`** over `--admin-password` so secrets are not stored in shell history.
62
68
 
63
- After project creation, migrations and seed are run automatically. Use the superadmin credentials you entered in the scaffold wizard:
69
+ | Flag | Description |
70
+ | --- | --- |
71
+ | `--package-manager`, `--pm` | `pnpm`, `npm`, or `yarn` |
72
+ | `--database`, `--db` | `postgresql`, `mysql`, or `sqlite` |
73
+ | `--admin-email` | Superadmin email |
74
+ | `--admin-password-env <VAR>` | Read password from environment (recommended) |
75
+ | `--admin-password <value>` | Password on CLI (discouraged) |
76
+ | `--db-url <url>` | Override `DATABASE_URL` |
77
+ | `--redis-url <url>` | Redis URL (blank disables queues) |
78
+ | `--skip-redis` | Disable background job queues |
79
+ | `--no-install` | Skip install / DB setup |
80
+ | `--no-git` | Skip `git init` |
81
+ | `-y`, `--yes` | Non-interactive with defaults |
64
82
 
65
- - **Email:** your `Superadmin email`
66
- - **Password:** your `Superadmin password`
83
+ ## Package managers
67
84
 
68
- ## MVP scope
85
+ | Manager | Notes |
86
+ | --- | --- |
87
+ | **pnpm** | Default; ships `pnpm-workspace.yaml` and `workspace:*` deps |
88
+ | **npm** | Adds npm `workspaces`; rewrites `workspace:*` → `*` for local linking |
89
+ | **yarn** | Adds `workspaces`; rewrites `workspace:*` → `*` |
69
90
 
70
- - Resource-driven admin metadata with safe defaults.
71
- - Auth, RBAC contracts, generic CRUD API, audit log and file/settings modules.
72
- - Next.js admin shell with login, dashboard, resource screens and operational pages.
73
- - Generated app `apps/web` for public frontend pages and SEO.
74
- - CLI: `dev`, `build`, `db migrate`, `db seed`, `generate resource`, `doctor`, `security check`.
91
+ If your preferred manager is missing, the interactive wizard offers installed alternatives or Corepack hints for pnpm.
75
92
 
76
- ## Plugin Platform
93
+ ## SQLite zero-setup
77
94
 
78
- OpenAdminJS now uses a broad extension model (no legacy compatibility layer). Plugins can register multiple surfaces through `@openadminjs/plugin-sdk`:
95
+ SQLite uses a local `file:./dev.db` — no PostgreSQL/MySQL server required. **Redis is optional** for SQLite: leave the Redis prompt blank or pass `--skip-redis`. The API starts without Redis; queue endpoints return a clear `503` until `REDIS_URL` is set.
79
96
 
80
- - `resource` hooks (CRUD lifecycle)
81
- - `api` hooks/routes
82
- - `media` pipeline (upload transforms)
83
- - `seo` metadata/sitemap contributors
84
- - `jobs` handlers
85
- - `adminUi` extensions (menus/pages/widgets/actions)
97
+ Prisma Client is generated automatically before `dev`, `build`, and `db:seed` via lifecycle scripts.
86
98
 
87
- Plugins are controlled by manifest capabilities and trust mode (`trusted` / `sandboxed`) in `apps/api/plugins.manifest.json`.
99
+ ## Environment
88
100
 
89
- ### Capability matrix
101
+ Secrets are written to **`apps/api/.env`** (git-ignored). JWT keys are generated with `crypto.randomBytes`. A tracked **`.env.example`** contains placeholders only — the CLI never prints secret values.
90
102
 
91
- - `resource.hooks` — CRUD lifecycle hooks per resource.
92
- - `api.hooks` / `api.routes` — request lifecycle hooks and custom API endpoints.
93
- - `media.pipeline` — file/image transform pipeline.
94
- - `seo.extend` — metadata + sitemap contributors.
95
- - `jobs.run` — background job handlers.
96
- - `admin.ui.extend` — admin menu/page/widget/action extensions.
103
+ ```env
104
+ DATABASE_URL=file:./dev.db # or postgres/mysql URL
105
+ REDIS_URL= # blank = queues disabled
106
+ JWT_SECRET=<generated>
107
+ JWT_REFRESH_SECRET=<generated>
108
+ ADMIN_ORIGIN=http://localhost:3000
109
+ API_PORT=4000
110
+ SUPERADMIN_EMAIL=admin@localhost.dev
111
+ SUPERADMIN_PASSWORD=<your password>
112
+ ```
113
+
114
+ ## Sign in
97
115
 
98
- `trusted` mode may run with broad access; `sandboxed` mode should explicitly declare only required capabilities.
116
+ After create (with install), use the superadmin email and password from the wizard or `apps/api/.env`.
99
117
 
100
- Generate a starter plugin:
118
+ ## Health & troubleshooting
101
119
 
102
120
  ```bash
103
- pnpm exec openadminjs generate plugin com.example.my-plugin
121
+ openadminjs doctor # verify install, env, Prisma client, scripts
122
+ openadminjs doctor --skip-network # offline-friendly
123
+ openadminjs security check
104
124
  ```
105
125
 
106
- ### Queue setup
126
+ **Prisma Client not initialized:** run `pnpm db:migrate` (or `npm run db:migrate`) from the project root, or `prisma generate` from `apps/api`.
107
127
 
108
- Set `REDIS_URL` in your environment to run queue processing (example: `redis://localhost:6379`).
128
+ **Prisma engine download failed:** check network/proxy; retry install from the project root.
109
129
 
110
- ## Partners
130
+ **Setup failed mid-create:** the project directory is preserved with a resume command in the error message.
111
131
 
112
- OpenAdminJS is community-powered and stays free thanks to partner support.
132
+ **npm `EUNSUPPORTEDPROTOCOL workspace:*`:** upgrade to the latest `openadminjs` CLI — npm projects must use `*` not `workspace:*`.
113
133
 
114
- Want to become a partner and place your logo in the project materials?
115
- Email us at `openadminjs@proton.me`.
134
+ ## Commands
116
135
 
117
- ## Financial support
118
-
119
- If you want to support development, hosting and community tooling:
136
+ ```bash
137
+ openadminjs create [name] [options]
138
+ openadminjs db migrate [dev|deploy] | seed | studio | reset
139
+ openadminjs generate resource <Model> | field <resource> <field> | plugin <id>
140
+ openadminjs doctor [--json] [--skip-network]
141
+ openadminjs security check [--json]
142
+ ```
120
143
 
121
- - Open a sponsorship discussion in GitHub issues/discussions.
122
- - Contribute with code, examples or QA.
123
- - Contact maintainers for direct support options: `openadminjs@proton.me`.
124
- - Crypto wallets:
125
- - BTC (SegWit): `bc1qpcc4hd7w82jjvsdhvx6hgu2kfuz8jgfuvxurd7`
126
- - ETH / USDC (ERC-20): `0xe5ac19c6f1f5070a7c713973fd25ee02eaf9eb48`
127
- - USDT (TRC-20): `TWyzMehesWqJS7qs5LYL4QGmgTpohNy3gf`
144
+ ## Programmatic API
145
+
146
+ ```ts
147
+ import { createProject, databaseUrl, generateSecret } from "openadminjs";
148
+
149
+ createProject({
150
+ projectName: "my-app",
151
+ packageManager: "npm",
152
+ database: "sqlite",
153
+ databaseUrl: "file:./dev.db",
154
+ redisUrl: "", // optional — blank disables queues
155
+ superadminEmail: "admin@localhost.dev",
156
+ superadminPassword: process.env.ADMIN_PASSWORD!,
157
+ jwtSecret: generateSecret(),
158
+ jwtRefreshSecret: generateSecret(),
159
+ adminOrigin: "http://localhost:3000",
160
+ apiPort: "4000",
161
+ install: true
162
+ });
163
+ ```
@@ -0,0 +1,3 @@
1
+ export type PackageManager = "pnpm" | "npm" | "yarn";
2
+ /** Rewrites a scaffolded monorepo for npm or yarn (template ships pnpm-first). */
3
+ export declare function adaptProjectForPackageManager(targetDir: string, packageManager: PackageManager): void;
@@ -0,0 +1,118 @@
1
+ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ const WORKSPACE_GLOBS = ["apps/*", "packages/*"];
4
+ const ROOT_SCRIPTS = {
5
+ pnpm: {
6
+ dev: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin dev",
7
+ build: "pnpm -r build",
8
+ start: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin start",
9
+ lint: "pnpm -r lint",
10
+ typecheck: "pnpm -r typecheck",
11
+ test: "pnpm -r test",
12
+ "db:migrate": "pnpm --filter @openadminjs/api db:migrate",
13
+ "db:migrate:deploy": "pnpm --filter @openadminjs/api db:migrate:deploy",
14
+ "db:seed": "pnpm --filter @openadminjs/api db:seed",
15
+ "db:studio": "pnpm --filter @openadminjs/api db:studio",
16
+ "db:reset": "pnpm --filter @openadminjs/api db:reset",
17
+ generate: "pnpm --filter @openadminjs/api generate"
18
+ },
19
+ npm: {
20
+ dev: "npm run dev --workspace=@openadminjs/api --workspace=@openadminjs/admin --if-present",
21
+ build: "npm run build --workspaces --if-present",
22
+ start: "npm run start --workspace=@openadminjs/api --workspace=@openadminjs/admin --if-present",
23
+ lint: "npm run lint --workspaces --if-present",
24
+ typecheck: "npm run typecheck --workspaces --if-present",
25
+ test: "npm run test --workspaces --if-present",
26
+ "db:migrate": "npm run db:migrate --workspace=@openadminjs/api",
27
+ "db:migrate:deploy": "npm run db:migrate:deploy --workspace=@openadminjs/api",
28
+ "db:seed": "npm run db:seed --workspace=@openadminjs/api",
29
+ "db:studio": "npm run db:studio --workspace=@openadminjs/api",
30
+ "db:reset": "npm run db:reset --workspace=@openadminjs/api",
31
+ generate: "npm run generate --workspace=@openadminjs/api"
32
+ },
33
+ yarn: {
34
+ dev: "yarn workspace @openadminjs/api dev & yarn workspace @openadminjs/admin dev",
35
+ build: "yarn workspaces run build",
36
+ start: "yarn workspace @openadminjs/api start & yarn workspace @openadminjs/admin start",
37
+ lint: "yarn workspaces run lint",
38
+ typecheck: "yarn workspaces run typecheck",
39
+ test: "yarn workspaces run test",
40
+ "db:migrate": "yarn workspace @openadminjs/api db:migrate",
41
+ "db:migrate:deploy": "yarn workspace @openadminjs/api db:migrate:deploy",
42
+ "db:seed": "yarn workspace @openadminjs/api db:seed",
43
+ "db:studio": "yarn workspace @openadminjs/api db:studio",
44
+ "db:reset": "yarn workspace @openadminjs/api db:reset",
45
+ generate: "yarn workspace @openadminjs/api generate"
46
+ }
47
+ };
48
+ function findPackageJsonFiles(dir) {
49
+ const files = [];
50
+ const stack = [dir];
51
+ while (stack.length) {
52
+ const current = stack.pop();
53
+ if (!current)
54
+ continue;
55
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
56
+ if (entry.name === "node_modules" || entry.name === ".next" || entry.name === "dist" || entry.name === ".turbo") {
57
+ continue;
58
+ }
59
+ const path = join(current, entry.name);
60
+ if (entry.isDirectory())
61
+ stack.push(path);
62
+ else if (entry.name === "package.json")
63
+ files.push(path);
64
+ }
65
+ }
66
+ return files;
67
+ }
68
+ function replaceWorkspaceProtocol(pkg, replacement) {
69
+ for (const section of ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]) {
70
+ const deps = pkg[section];
71
+ if (!deps)
72
+ continue;
73
+ for (const [name, version] of Object.entries(deps)) {
74
+ if (version.startsWith("workspace:")) {
75
+ deps[name] = replacement;
76
+ }
77
+ }
78
+ }
79
+ }
80
+ function readPackageJson(path) {
81
+ return JSON.parse(readFileSync(path, "utf8"));
82
+ }
83
+ function writePackageJson(path, pkg) {
84
+ writeFileSync(path, `${JSON.stringify(pkg, null, 2)}\n`);
85
+ }
86
+ /** Rewrites a scaffolded monorepo for npm or yarn (template ships pnpm-first). */
87
+ export function adaptProjectForPackageManager(targetDir, packageManager) {
88
+ if (packageManager === "pnpm")
89
+ return;
90
+ const rootPath = join(targetDir, "package.json");
91
+ if (!existsSync(rootPath))
92
+ return;
93
+ const root = readPackageJson(rootPath);
94
+ const pnpmOverrides = typeof root.pnpm === "object" && root.pnpm !== null && "overrides" in root.pnpm
95
+ ? root.pnpm.overrides
96
+ : undefined;
97
+ root.workspaces = WORKSPACE_GLOBS;
98
+ root.scripts = { ...root.scripts, ...ROOT_SCRIPTS[packageManager] };
99
+ delete root.packageManager;
100
+ delete root.pnpm;
101
+ if (packageManager === "npm" && pnpmOverrides) {
102
+ root.overrides = pnpmOverrides;
103
+ }
104
+ writePackageJson(rootPath, root);
105
+ const pnpmWorkspaceFile = join(targetDir, "pnpm-workspace.yaml");
106
+ if (existsSync(pnpmWorkspaceFile)) {
107
+ rmSync(pnpmWorkspaceFile);
108
+ }
109
+ // Neither npm nor Yarn Classic understand pnpm's `workspace:` protocol
110
+ // (npm throws EUNSUPPORTEDPROTOCOL). Both resolve `"*"` to the local
111
+ // workspace package by name, so rewrite every `workspace:<range>` to `"*"`.
112
+ const workspaceReplacement = "*";
113
+ for (const file of findPackageJsonFiles(targetDir)) {
114
+ const pkg = readPackageJson(file);
115
+ replaceWorkspaceProtocol(pkg, workspaceReplacement);
116
+ writePackageJson(file, pkg);
117
+ }
118
+ }
@@ -1,4 +1,7 @@
1
- export type PackageManager = "pnpm" | "npm" | "yarn";
1
+ import { type PackageManager } from "./adapt-package-manager.js";
2
+ /** Minimum supported Node.js major version (kept in sync with package.json engines). */
3
+ export declare const MIN_NODE_MAJOR = 20;
4
+ export type { PackageManager } from "./adapt-package-manager.js";
2
5
  export type DatabaseDriver = "postgresql" | "mysql" | "sqlite";
3
6
  export type CreateProjectOptions = {
4
7
  projectName?: string;
@@ -8,7 +11,10 @@ export type CreateProjectOptions = {
8
11
  superadminEmail?: string;
9
12
  superadminPassword?: string;
10
13
  databaseUrl?: string;
14
+ /** Empty string disables Redis-backed queues (see `skipRedis`). */
11
15
  redisUrl?: string;
16
+ /** When true, force Redis (and background job queues) off. */
17
+ skipRedis?: boolean;
12
18
  jwtSecret?: string;
13
19
  jwtRefreshSecret?: string;
14
20
  adminOrigin?: string;
@@ -16,6 +22,13 @@ export type CreateProjectOptions = {
16
22
  git?: boolean;
17
23
  install?: boolean;
18
24
  templateDir?: string;
25
+ runtimeMode?: "source" | "registry";
26
+ /**
27
+ * Skip all interactive prompts. Missing optional values fall back to safe
28
+ * defaults; a missing superadmin password is generated (CSPRNG). Used for
29
+ * CI / scripting and auto-enabled when stdin is not a TTY.
30
+ */
31
+ nonInteractive?: boolean;
19
32
  };
20
33
  export type CreateProjectResult = {
21
34
  appName: string;
@@ -27,9 +40,71 @@ export type CreateProjectResult = {
27
40
  git: boolean;
28
41
  install: boolean;
29
42
  dbInitialized: boolean;
43
+ /** True when a REDIS_URL was configured (background job queues enabled). */
44
+ redisEnabled: boolean;
45
+ /** True when the superadmin password was generated (non-interactive). */
46
+ passwordGenerated: boolean;
30
47
  };
31
48
  export declare function toPackageName(input: string): string;
32
49
  export declare function defaultTemplateDir(): string;
33
- export declare function createProject(options: Required<CreateProjectOptions>): CreateProjectResult;
50
+ /** Returns the current Node.js major version. */
51
+ export declare function currentNodeMajor(): number;
52
+ /** Throws if the running Node.js is older than the supported minimum. */
53
+ export declare function assertSupportedNode(): void;
54
+ /** Returns true when the given package manager is on PATH. */
55
+ export declare function isPackageManagerAvailable(packageManager: PackageManager): boolean;
56
+ /** Throws with an actionable message when pnpm is not installed. */
57
+ export declare function assertPnpmAvailable(): void;
58
+ export declare const DEFAULT_SUPERADMIN_EMAIL = "admin@localhost.dev";
59
+ /** Resolves the final email, applying the default when the user pressed Enter. */
60
+ export declare function resolveSuperadminEmail(value: string, fallback?: string): string;
61
+ /**
62
+ * Validates the superadmin email against the FINAL value (after default
63
+ * resolution), so pressing Enter to accept the default is always valid.
64
+ */
65
+ export declare function validateSuperadminEmailInput(value: string, fallback?: string): string | undefined;
66
+ export declare const DEFAULT_REDIS_URL = "redis://localhost:6379";
67
+ export declare const PACKAGE_MANAGERS: readonly PackageManager[];
68
+ /** Returns the first package manager that is installed on PATH, or undefined. */
69
+ export declare function firstAvailablePackageManager(preference?: readonly PackageManager[]): PackageManager | undefined;
70
+ /**
71
+ * Validates a Redis URL. An empty value is VALID — it disables background job
72
+ * queues. A non-empty value must be a parseable redis:// (or rediss://) URL so
73
+ * pressing Enter on the shown default is always accepted.
74
+ */
75
+ export declare function validateRedisUrlInput(value: string): string | undefined;
76
+ export declare function databaseUrl(packageName: string, database: DatabaseDriver): string;
77
+ /**
78
+ * Generates the scaffold into a sibling staging directory and atomically renames
79
+ * it into place only after generation succeeds. On failure the staging directory
80
+ * is removed and an existing target directory is never touched.
81
+ */
82
+ export declare function createProject(options: CreateProjectOptions & {
83
+ projectName: string;
84
+ }): CreateProjectResult;
85
+ /**
86
+ * Thrown when the scaffold was generated successfully but a later step
87
+ * (install, migrate, seed) failed. Carries the exact command to resume so the
88
+ * user never has to guess, and signals that the directory was intentionally
89
+ * preserved (never auto-deleted).
90
+ */
91
+ export declare class SetupIncompleteError extends Error {
92
+ readonly targetDir: string;
93
+ readonly resumeCommand: string;
94
+ constructor(message: string, meta: {
95
+ targetDir: string;
96
+ appName: string;
97
+ packageManager: PackageManager;
98
+ });
99
+ }
34
100
  export declare function printNextSteps(result: CreateProjectResult): void;
101
+ /** Warns where secrets live and that they must never be committed. Never prints secret values. */
102
+ export declare function printSecurityNotice(result: CreateProjectResult): void;
103
+ /** Generates a strong, human-usable password (used in non-interactive mode). */
104
+ export declare function generatePassword(): string;
35
105
  export declare function createProjectInteractive(options?: CreateProjectOptions): Promise<CreateProjectResult | undefined>;
106
+ /**
107
+ * Validates a DATABASE_URL against the FINAL resolved value so pressing Enter to
108
+ * accept the shown default is always valid.
109
+ */
110
+ export declare function validateDatabaseUrlInput(database: DatabaseDriver, value: string, fallback: string): string | undefined;