openadminjs 0.1.7 → 0.1.9

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 (217) hide show
  1. package/README.md +114 -18
  2. package/dist/create-project.js +27 -4
  3. package/dist/create-project.test.js +57 -41
  4. package/dist/index.js +16 -5
  5. package/package.json +4 -2
  6. package/template/.env.example +2 -2
  7. package/template/README.md +24 -5
  8. package/template/apps/admin/app/api/auth/login/route.ts +51 -0
  9. package/template/apps/admin/app/api/auth/logout/route.ts +11 -0
  10. package/template/apps/admin/app/api/auth/refresh/route.ts +46 -0
  11. package/template/apps/admin/app/api-tokens/page.tsx +253 -0
  12. package/template/apps/admin/app/audit-logs/page.tsx +5 -0
  13. package/template/apps/admin/app/dashboard/page.tsx +392 -0
  14. package/template/apps/admin/app/files/page.tsx +5 -0
  15. package/template/apps/admin/app/globals.css +206 -0
  16. package/template/apps/admin/app/jobs/page.tsx +19 -0
  17. package/template/apps/admin/app/layout.tsx +57 -0
  18. package/template/apps/admin/app/login/page.test.tsx +18 -0
  19. package/template/apps/admin/app/login/page.tsx +161 -0
  20. package/template/apps/admin/app/login/safe-next-param.ts +4 -0
  21. package/template/apps/admin/app/notifications/page.tsx +146 -0
  22. package/template/apps/admin/app/page.tsx +5 -0
  23. package/template/apps/admin/app/plugins/page.tsx +407 -0
  24. package/template/apps/admin/app/profile/page.tsx +116 -0
  25. package/template/apps/admin/app/resources/[resource]/[id]/edit/page.tsx +45 -0
  26. package/template/apps/admin/app/resources/[resource]/[id]/page.tsx +449 -0
  27. package/template/apps/admin/app/resources/[resource]/create/page.tsx +34 -0
  28. package/template/apps/admin/app/resources/[resource]/page.tsx +100 -0
  29. package/template/apps/admin/app/settings/page.tsx +233 -0
  30. package/template/apps/admin/components/ai-assistant-widget.tsx +684 -0
  31. package/template/apps/admin/components/app-shell.tsx +305 -0
  32. package/template/apps/admin/components/auth-guard.test.tsx +55 -0
  33. package/template/apps/admin/components/auth-guard.tsx +39 -0
  34. package/template/apps/admin/components/jobs-panel.tsx +103 -0
  35. package/template/apps/admin/components/logo.tsx +30 -0
  36. package/template/apps/admin/components/resource-form.tsx +349 -0
  37. package/template/apps/admin/components/resource-table.tsx +277 -0
  38. package/template/apps/admin/lib/ai-events.ts +23 -0
  39. package/template/apps/admin/lib/api.test.ts +118 -0
  40. package/template/apps/admin/lib/api.ts +135 -0
  41. package/template/apps/admin/lib/auth-flow.e2e.test.ts +79 -0
  42. package/template/apps/admin/lib/brand.ts +14 -0
  43. package/template/apps/admin/lib/locale.ts +49 -0
  44. package/template/apps/admin/lib/tokens.ts +93 -0
  45. package/template/apps/admin/middleware.ts +58 -0
  46. package/template/apps/admin/next-env.d.ts +6 -0
  47. package/template/apps/admin/next.config.mjs +7 -0
  48. package/template/apps/admin/package.json +44 -0
  49. package/template/apps/admin/postcss.config.mjs +6 -0
  50. package/template/apps/admin/public/brand/apple-touch-icon.png +0 -0
  51. package/template/apps/admin/public/brand/favicon.svg +1 -0
  52. package/template/apps/admin/public/brand/og-image.png +0 -0
  53. package/template/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
  54. package/template/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
  55. package/template/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
  56. package/template/apps/admin/tailwind.config.ts +37 -0
  57. package/template/apps/admin/tsconfig.json +23 -0
  58. package/template/apps/admin/vitest.config.ts +7 -0
  59. package/template/apps/api/package.json +56 -0
  60. package/template/apps/api/plugins.manifest.example.json +34 -0
  61. package/template/apps/api/plugins.manifest.json +4 -0
  62. package/template/apps/api/src/access/catalog.ts +112 -0
  63. package/template/apps/api/src/access/derive-permissions.test.ts +26 -0
  64. package/template/apps/api/src/access/derive-permissions.ts +36 -0
  65. package/template/apps/api/src/access/public-catalog.ts +28 -0
  66. package/template/apps/api/src/admin/admin-ai.controller.ts +125 -0
  67. package/template/apps/api/src/admin/admin-ai.events.ts +23 -0
  68. package/template/apps/api/src/admin/admin-ai.service.ts +1271 -0
  69. package/template/apps/api/src/admin/admin-analytics.service.ts +164 -0
  70. package/template/apps/api/src/admin/admin-plugins.controller.ts +32 -0
  71. package/template/apps/api/src/admin/admin-plugins.service.ts +267 -0
  72. package/template/apps/api/src/admin/admin-resource.service.test.ts +118 -0
  73. package/template/apps/api/src/admin/admin-resource.service.ts +375 -0
  74. package/template/apps/api/src/admin/admin.controller.ts +72 -0
  75. package/template/apps/api/src/admin/admin.module.ts +30 -0
  76. package/template/apps/api/src/admin/dto/plugins.dto.ts +55 -0
  77. package/template/apps/api/src/admin/validate-resource-payload.test.ts +44 -0
  78. package/template/apps/api/src/admin/validate-resource-payload.ts +103 -0
  79. package/template/apps/api/src/app.module.ts +45 -0
  80. package/template/apps/api/src/auth/auth.controller.ts +70 -0
  81. package/template/apps/api/src/auth/auth.dto.ts +49 -0
  82. package/template/apps/api/src/auth/auth.module.ts +30 -0
  83. package/template/apps/api/src/auth/auth.service.test.ts +75 -0
  84. package/template/apps/api/src/auth/auth.service.ts +231 -0
  85. package/template/apps/api/src/common/auth-realm.decorator.ts +6 -0
  86. package/template/apps/api/src/common/auth.guard.test.ts +61 -0
  87. package/template/apps/api/src/common/auth.guard.ts +78 -0
  88. package/template/apps/api/src/common/casl-ability.factory.test.ts +33 -0
  89. package/template/apps/api/src/common/casl-ability.factory.ts +41 -0
  90. package/template/apps/api/src/common/current-user.decorator.ts +6 -0
  91. package/template/apps/api/src/common/permission.decorator.ts +7 -0
  92. package/template/apps/api/src/common/permissions.guard.ts +31 -0
  93. package/template/apps/api/src/common/prisma.service.ts +13 -0
  94. package/template/apps/api/src/health/health.controller.ts +25 -0
  95. package/template/apps/api/src/mail/mail.module.ts +9 -0
  96. package/template/apps/api/src/mail/mail.service.ts +115 -0
  97. package/template/apps/api/src/main.ts +37 -0
  98. package/template/apps/api/src/plugins/bootstrap.ts +4 -0
  99. package/template/apps/api/src/plugins/bundled/admin-widget.plugin.ts +25 -0
  100. package/template/apps/api/src/plugins/bundled/hello.plugin.ts +19 -0
  101. package/template/apps/api/src/plugins/bundled/image-optimizer.plugin.ts +22 -0
  102. package/template/apps/api/src/plugins/bundled/registry.ts +13 -0
  103. package/template/apps/api/src/plugins/bundled/seo.plugin.ts +25 -0
  104. package/template/apps/api/src/plugins/manifest-path.ts +35 -0
  105. package/template/apps/api/src/plugins/manifest.schema.test.ts +36 -0
  106. package/template/apps/api/src/plugins/manifest.schema.ts +58 -0
  107. package/template/apps/api/src/plugins/plugin-api.interceptor.ts +47 -0
  108. package/template/apps/api/src/plugins/plugin-loader.ts +134 -0
  109. package/template/apps/api/src/plugins/plugin-runtime.test.ts +24 -0
  110. package/template/apps/api/src/plugins/plugin-runtime.ts +85 -0
  111. package/template/apps/api/src/queue/queue.controller.ts +28 -0
  112. package/template/apps/api/src/queue/queue.module.ts +23 -0
  113. package/template/apps/api/src/queue/queue.processor.ts +47 -0
  114. package/template/apps/api/src/queue/queue.service.ts +50 -0
  115. package/template/apps/api/src/resources/categories.resource.ts +21 -0
  116. package/template/apps/api/src/resources/commerce.resource.ts +157 -0
  117. package/template/apps/api/src/resources/operations.resource.ts +111 -0
  118. package/template/apps/api/src/resources/posts.resource.ts +88 -0
  119. package/template/apps/api/src/resources/registry.ts +27 -0
  120. package/template/apps/api/src/resources/resource-hooks.install.ts +18 -0
  121. package/template/apps/api/src/resources/resource-hooks.registry.test.ts +72 -0
  122. package/template/apps/api/src/resources/resource-hooks.registry.ts +66 -0
  123. package/template/apps/api/src/resources/resource-hooks.runner.ts +93 -0
  124. package/template/apps/api/src/resources/system.resource.ts +51 -0
  125. package/template/apps/api/src/resources/users.resource.ts +19 -0
  126. package/template/apps/api/src/store/payment/payment.controller.ts +98 -0
  127. package/template/apps/api/src/store/payment/payment.module.ts +14 -0
  128. package/template/apps/api/src/store/payment/payment.provider.ts +38 -0
  129. package/template/apps/api/src/store/payment/payment.service.ts +235 -0
  130. package/template/apps/api/src/store/store.controller.ts +26 -0
  131. package/template/apps/api/src/store/store.module.ts +12 -0
  132. package/template/apps/api/src/test-setup.ts +1 -0
  133. package/template/apps/api/tsconfig.json +11 -0
  134. package/template/apps/api/vitest.config.ts +21 -0
  135. package/template/apps/web/lib/openadmin-client.ts +11 -0
  136. package/template/apps/web/lib/seo.test.ts +41 -0
  137. package/template/apps/web/lib/seo.ts +24 -13
  138. package/template/apps/web/next-env.d.ts +4 -0
  139. package/template/apps/web/package.json +2 -1
  140. package/template/apps/web/test/next-stub.ts +7 -0
  141. package/template/apps/web/vitest.config.ts +19 -0
  142. package/template/package.json +18 -11
  143. package/template/packages/auth/package.json +17 -0
  144. package/template/packages/auth/src/index.test.ts +10 -0
  145. package/template/packages/auth/src/index.ts +17 -0
  146. package/template/packages/auth/tsconfig.json +8 -0
  147. package/template/packages/brand/apps/admin/public/brand/apple-touch-icon.png +0 -0
  148. package/template/packages/brand/apps/admin/public/brand/favicon.svg +1 -0
  149. package/template/packages/brand/apps/admin/public/brand/og-image.png +0 -0
  150. package/template/packages/brand/apps/admin/public/brand/openadminjs-icon-new.png +0 -0
  151. package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-monochrome.png +0 -0
  152. package/template/packages/brand/apps/admin/public/brand/openadminjs-logo-new.png +0 -0
  153. package/template/packages/brand/apps/web/public/brand/apple-touch-icon.png +0 -0
  154. package/template/packages/brand/apps/web/public/brand/favicon.svg +1 -0
  155. package/template/packages/brand/apps/web/public/brand/og-image.png +0 -0
  156. package/template/packages/brand/apps/web/public/brand/openadminjs-icon-new.png +0 -0
  157. package/template/packages/brand/apps/web/public/brand/openadminjs-logo-monochrome.png +0 -0
  158. package/template/packages/brand/apps/web/public/brand/openadminjs-logo-new.png +0 -0
  159. package/template/packages/brand/package.json +19 -0
  160. package/template/packages/brand/site/assets/brand/favicon.svg +1 -0
  161. package/template/packages/brand/site/assets/brand/og-image.svg +1 -0
  162. package/template/packages/brand/site/assets/brand/openadminjs-icon.svg +1 -0
  163. package/template/packages/brand/site/assets/brand/openadminjs-logo-dark.svg +1 -0
  164. package/template/packages/brand/site/assets/brand/openadminjs-logo-horizontal.svg +1 -0
  165. package/template/packages/brand/site/assets/brand/openadminjs-logo-monochrome.svg +1 -0
  166. package/template/packages/brand/site/assets/brand/openadminjs-logo.svg +1 -0
  167. package/template/packages/brand/src/generate-assets.mjs +182 -0
  168. package/template/packages/brand/src/index.test.ts +9 -0
  169. package/template/packages/brand/src/index.ts +7 -0
  170. package/template/packages/brand/tsconfig.json +7 -0
  171. package/template/packages/core/package.json +20 -0
  172. package/template/packages/core/src/index.js +1 -0
  173. package/template/packages/core/src/index.test.ts +27 -0
  174. package/template/packages/core/src/index.ts +61 -0
  175. package/template/packages/core/tsconfig.json +8 -0
  176. package/template/packages/mail/package.json +18 -0
  177. package/template/packages/mail/src/index.test.ts +23 -0
  178. package/template/packages/mail/src/index.ts +246 -0
  179. package/template/packages/mail/tsconfig.json +5 -0
  180. package/template/packages/notifications/package.json +16 -0
  181. package/template/packages/notifications/src/index.test.ts +9 -0
  182. package/template/packages/notifications/src/index.ts +5 -0
  183. package/template/packages/notifications/tsconfig.json +5 -0
  184. package/template/packages/payments/package.json +15 -0
  185. package/template/packages/payments/src/index.ts +256 -0
  186. package/template/packages/payments/tsconfig.json +9 -0
  187. package/template/packages/permissions/package.json +17 -0
  188. package/template/packages/permissions/src/blueprints.js +57 -0
  189. package/template/packages/permissions/src/blueprints.test.ts +62 -0
  190. package/template/packages/permissions/src/blueprints.ts +89 -0
  191. package/template/packages/permissions/src/index.js +11 -0
  192. package/template/packages/permissions/src/index.test.ts +34 -0
  193. package/template/packages/permissions/src/index.ts +22 -0
  194. package/template/packages/permissions/tsconfig.json +8 -0
  195. package/template/packages/plugin-sdk/package.json +26 -0
  196. package/template/packages/plugin-sdk/src/hooks.ts +135 -0
  197. package/template/packages/plugin-sdk/src/index.ts +42 -0
  198. package/template/packages/plugin-sdk/src/sdk.test.ts +13 -0
  199. package/template/packages/plugin-sdk/tsconfig.json +8 -0
  200. package/template/packages/plugin-sdk/vitest.config.ts +5 -0
  201. package/template/packages/queue/package.json +16 -0
  202. package/template/packages/queue/src/index.test.ts +12 -0
  203. package/template/packages/queue/src/index.ts +6 -0
  204. package/template/packages/queue/tsconfig.json +5 -0
  205. package/template/packages/resource/package.json +17 -0
  206. package/template/packages/resource/src/index.js +177 -0
  207. package/template/packages/resource/src/index.test.ts +151 -0
  208. package/template/packages/resource/src/index.ts +344 -0
  209. package/template/packages/resource/tsconfig.json +8 -0
  210. package/template/packages/storage/package.json +16 -0
  211. package/template/packages/storage/src/index.test.ts +10 -0
  212. package/template/packages/storage/src/index.ts +23 -0
  213. package/template/packages/storage/tsconfig.json +5 -0
  214. package/template/prisma/migrations/20260505151751_baseline_init_all_tables/migration.sql +371 -0
  215. package/template/prisma/migrations/migration_lock.toml +3 -0
  216. package/template/prisma/schema.prisma +291 -0
  217. package/template/prisma/seed.ts +217 -0
package/README.md CHANGED
@@ -1,30 +1,126 @@
1
- # openadminjs CLI
1
+ # OpenAdminJS
2
2
 
3
- Official CLI for OpenAdminJS.
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.
4
4
 
5
- ## Quick start
5
+ ![OpenAdminJS logo](https://js-senpai.github.io/open-admin-js/assets/brand/openadminjs-logo-new.png)
6
+
7
+ ## Quick start (for package users)
8
+
9
+ Full documentation: [https://js-senpai.github.io/open-admin-js/docs.html](https://js-senpai.github.io/open-admin-js/docs.html)
10
+
11
+ ### 1. Create a new project
6
12
 
7
13
  ```bash
8
14
  npx openadminjs create my-app
9
15
  cd my-app
10
- pnpm db:migrate
11
- pnpm db:seed
16
+ ```
17
+
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.
20
+
21
+ ### 2. Configure environment
22
+
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`.
24
+ `ADMIN_ORIGIN` and `API_PORT` are prefilled with defaults (`http://localhost:3000` and `4000`) and can be changed manually if needed.
25
+ `.env.example` is left as a reference template.
26
+
27
+ Minimal `.env` example:
28
+
29
+ ```env
30
+ NODE_ENV=development
31
+ DATABASE_URL=postgresql://USER:PASSWORD@localhost:5432/openadminjs?schema=public
32
+ API_PORT=4000
33
+ JWT_SECRET=replace-with-a-long-random-string-at-least-32-chars
34
+ JWT_REFRESH_SECRET=another-long-random-string
35
+ ADMIN_ORIGIN=http://localhost:3000
36
+ ```
37
+
38
+ Optional:
39
+
40
+ ```env
41
+ REDIS_URL=redis://localhost:6379
42
+ OPENADMIN_PLUGIN_PNPM_INSTALL=0
43
+ ```
44
+
45
+ ### 3. Run project
46
+
47
+ ```bash
12
48
  pnpm dev
13
49
  ```
14
50
 
15
- ## Commands
51
+ Typical URLs:
52
+
53
+ | App | URL |
54
+ | ----------- | ------------------------------ |
55
+ | Admin | http://localhost:3000 |
56
+ | API | http://localhost:4000 |
57
+ | API Swagger | http://localhost:4000/api/docs |
58
+ | Web (demo) | http://localhost:3001 |
59
+
60
+ ### 4. Sign in
61
+
62
+ After project creation, migrations and seed are run automatically. Use the superadmin credentials you entered in the scaffold wizard:
63
+
64
+ - **Email:** your `Superadmin email`
65
+ - **Password:** your `Superadmin password`
66
+
67
+ ## MVP scope
68
+
69
+ - Resource-driven admin metadata with safe defaults.
70
+ - Auth, RBAC contracts, generic CRUD API, audit log and file/settings modules.
71
+ - Next.js admin shell with login, dashboard, resource screens and operational pages.
72
+ - Generated app `apps/web` for public frontend pages and SEO.
73
+ - CLI: `dev`, `build`, `db migrate`, `db seed`, `generate resource`, `doctor`, `security check`.
74
+
75
+ ## Plugin Platform
76
+
77
+ OpenAdminJS now uses a broad extension model (no legacy compatibility layer). Plugins can register multiple surfaces through `@openadminjs/plugin-sdk`:
78
+
79
+ - `resource` hooks (CRUD lifecycle)
80
+ - `api` hooks/routes
81
+ - `media` pipeline (upload transforms)
82
+ - `seo` metadata/sitemap contributors
83
+ - `jobs` handlers
84
+ - `adminUi` extensions (menus/pages/widgets/actions)
85
+
86
+ Plugins are controlled by manifest capabilities and trust mode (`trusted` / `sandboxed`) in `apps/api/plugins.manifest.json`.
87
+
88
+ ### Capability matrix
89
+
90
+ - `resource.hooks` — CRUD lifecycle hooks per resource.
91
+ - `api.hooks` / `api.routes` — request lifecycle hooks and custom API endpoints.
92
+ - `media.pipeline` — file/image transform pipeline.
93
+ - `seo.extend` — metadata + sitemap contributors.
94
+ - `jobs.run` — background job handlers.
95
+ - `admin.ui.extend` — admin menu/page/widget/action extensions.
96
+
97
+ `trusted` mode may run with broad access; `sandboxed` mode should explicitly declare only required capabilities.
98
+
99
+ Generate a starter plugin:
100
+
101
+ ```bash
102
+ pnpm exec openadminjs generate plugin com.example.my-plugin
103
+ ```
104
+
105
+ ### Optional queue setup
106
+
107
+ Set `REDIS_URL` in your environment to enable queue processing (example: `redis://localhost:6379`).
108
+
109
+ ## Partners
110
+
111
+ OpenAdminJS is community-powered and stays free thanks to partner support.
112
+
113
+ Want to become a partner and place your logo in the project materials?
114
+ Email us at `openadminjs@proton.me`.
16
115
 
17
- - `openadminjs create [projectName]`
18
- - `openadminjs dev`
19
- - `openadminjs build`
20
- - `openadminjs start`
21
- - `openadminjs db migrate|seed|studio`
22
- - `openadminjs generate resource <ModelName>`
23
- - `openadminjs generate plugin <pluginId>`
24
- - `openadminjs doctor`
25
- - `openadminjs security check`
116
+ ## Financial support
26
117
 
27
- ## Docs
118
+ If you want to support development, hosting and community tooling:
28
119
 
29
- - Full docs: [https://js-senpai.github.io/open-admin-js/docs.html](https://js-senpai.github.io/open-admin-js/docs.html)
30
- - Repository: [https://github.com/js-senpai/open-admin-js](https://github.com/js-senpai/open-admin-js)
120
+ - Open a sponsorship discussion in GitHub issues/discussions.
121
+ - Contribute with code, examples or QA.
122
+ - Contact maintainers for direct support options: `openadminjs@proton.me`.
123
+ - Crypto wallets:
124
+ - BTC (SegWit): `bc1qpcc4hd7w82jjvsdhvx6hgu2kfuz8jgfuvxurd7`
125
+ - ETH / USDC (ERC-20): `0xe5ac19c6f1f5070a7c713973fd25ee02eaf9eb48`
126
+ - USDT (TRC-20): `TWyzMehesWqJS7qs5LYL4QGmgTpohNy3gf`
@@ -1,5 +1,5 @@
1
- import { existsSync, readdirSync } from "node:fs";
2
- import { dirname, join, resolve } from "node:path";
1
+ import { existsSync, mkdirSync, readdirSync } from "node:fs";
2
+ import { dirname, extname, join, relative, resolve, sep } from "node:path";
3
3
  import { spawnSync } from "node:child_process";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { cancel, confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
@@ -7,6 +7,7 @@ import fsExtra from "fs-extra";
7
7
  import pc from "picocolors";
8
8
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
9
  const { copySync, ensureDirSync, readFileSync, writeFileSync } = fsExtra;
10
+ const BINARY_EXTENSIONS = new Set([".png", ".jpg", ".jpeg", ".gif", ".webp", ".svg", ".ico", ".woff", ".woff2", ".ttf", ".eot"]);
10
11
  const placeholderPattern = /__APP_NAME__|__PACKAGE_NAME__|__DATABASE_URL__|__DATABASE_PROVIDER__|__REDIS_URL__|__JWT_SECRET__|__JWT_REFRESH_SECRET__|__ADMIN_ORIGIN__|__API_PORT__/g;
11
12
  export function toPackageName(input) {
12
13
  return input
@@ -28,6 +29,8 @@ function databaseUrl(packageName, database) {
28
29
  return "file:./prisma/dev.db";
29
30
  }
30
31
  function renderFile(file, replacements) {
32
+ if (BINARY_EXTENSIONS.has(extname(file).toLowerCase()))
33
+ return;
31
34
  const content = readFileSync(file, "utf8");
32
35
  writeFileSync(file, content.replace(placeholderPattern, (key) => replacements[key] ?? key));
33
36
  }
@@ -60,7 +63,10 @@ export function createProject(options) {
60
63
  copySync(options.templateDir, targetDir, {
61
64
  overwrite: false,
62
65
  errorOnExist: true,
63
- filter: (source) => !source.includes("node_modules") && !source.includes(".next") && !source.includes("dist")
66
+ filter: (source) => {
67
+ const segments = relative(options.templateDir, source).split(sep);
68
+ return !segments.some((segment) => segment === "node_modules" || segment === ".next" || segment === "dist");
69
+ }
64
70
  });
65
71
  if (!existsSync(join(targetDir, "package.json"))) {
66
72
  throw new Error(`Template copy failed: package.json not found in ${targetDir}`);
@@ -76,6 +82,23 @@ export function createProject(options) {
76
82
  __ADMIN_ORIGIN__: options.adminOrigin,
77
83
  __API_PORT__: options.apiPort
78
84
  });
85
+ // Write the real .env for apps/api so the app starts and seed runs without
86
+ // manual intervention. Superadmin credentials are picked up by prisma/seed.ts
87
+ // via the SUPERADMIN_EMAIL / SUPERADMIN_PASSWORD env vars.
88
+ const apiEnvDir = join(targetDir, "apps", "api");
89
+ if (existsSync(apiEnvDir)) {
90
+ mkdirSync(apiEnvDir, { recursive: true });
91
+ writeFileSync(join(apiEnvDir, ".env"), [
92
+ `DATABASE_URL=${options.databaseUrl}`,
93
+ `REDIS_URL=${options.redisUrl}`,
94
+ `JWT_SECRET=${options.jwtSecret}`,
95
+ `JWT_REFRESH_SECRET=${options.jwtRefreshSecret}`,
96
+ `ADMIN_ORIGIN=${options.adminOrigin}`,
97
+ `API_PORT=${options.apiPort}`,
98
+ `SUPERADMIN_EMAIL=${options.superadminEmail}`,
99
+ `SUPERADMIN_PASSWORD=${options.superadminPassword}`
100
+ ].join("\n") + "\n");
101
+ }
79
102
  if (options.git) {
80
103
  const gitResult = spawnSync("git", ["init"], { cwd: targetDir, stdio: "ignore" });
81
104
  if (gitResult.status !== 0 || gitResult.error) {
@@ -103,7 +126,7 @@ export function createProject(options) {
103
126
  export function printNextSteps(result) {
104
127
  const pm = result.packageManager;
105
128
  const installStep = result.install ? "" : `\n ${pm} install`;
106
- outro(`${pc.green("Project created.")}\n\nNext steps:\n cd ${result.appName}${installStep}\n docker compose up -d\n ${pm} db:migrate\n ${pm} db:seed\n ${pm} dev\n\nAdmin: http://localhost:3000\nAPI: http://localhost:4000\nDocs: http://localhost:4000/api/docs\n\nSuperadmin: ${result.superadminEmail} / <your password>`);
129
+ outro(`${pc.green("Project created.")}\n\nNext steps:\n cd ${result.appName}${installStep}\n ${pm} db:migrate\n ${pm} db:seed\n ${pm} dev\n\nAdmin: http://localhost:3000\nAPI: http://localhost:4000\nSwagger: http://localhost:4000/api/docs\nWeb: http://localhost:3001\n\nSuperadmin: ${result.superadminEmail} / <your password>`);
107
130
  }
108
131
  export async function createProjectInteractive(options = {}) {
109
132
  intro(pc.green("Create OpenAdminJS"));
@@ -1,36 +1,33 @@
1
- import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1
+ import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { tmpdir } from "node:os";
4
4
  import { describe, expect, it } from "vitest";
5
5
  import { createProject, defaultTemplateDir } from "./create-project.js";
6
+ const BASE_OPTIONS = {
7
+ packageManager: "pnpm",
8
+ database: "postgresql",
9
+ superadminEmail: "admin@localhost.dev",
10
+ superadminPassword: "password1234",
11
+ databaseUrl: "postgresql://localhost:5432/my-app?schema=public",
12
+ redisUrl: "redis://localhost:6379",
13
+ jwtSecret: "test-jwt-secret",
14
+ jwtRefreshSecret: "test-jwt-refresh-secret",
15
+ adminOrigin: "http://localhost:3000",
16
+ apiPort: "4000",
17
+ git: false,
18
+ install: false
19
+ };
6
20
  describe("create project", () => {
7
- it("ships template env defaults for admin origin and api port", () => {
21
+ it("template .env.example contains placeholder keys for every secret", () => {
8
22
  const envExample = readFileSync(join(defaultTemplateDir(), ".env.example"), "utf8");
9
- expect(envExample).toContain("ADMIN_ORIGIN=http://localhost:3000");
10
- expect(envExample).toContain("API_PORT=4000");
11
- expect(envExample).not.toContain("__ADMIN_ORIGIN__");
12
- expect(envExample).not.toContain("__API_PORT__");
23
+ for (const key of ["__DATABASE_URL__", "__REDIS_URL__", "__JWT_SECRET__", "__JWT_REFRESH_SECRET__", "__ADMIN_ORIGIN__", "__API_PORT__"]) {
24
+ expect(envExample, `missing placeholder ${key}`).toContain(key);
25
+ }
13
26
  });
14
- it("creates project with rendered env values", () => {
27
+ it("creates project with rendered .env.example values", () => {
15
28
  const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
16
29
  try {
17
- const result = createProject({
18
- projectName: "my-app",
19
- cwd,
20
- packageManager: "pnpm",
21
- database: "postgresql",
22
- superadminEmail: "admin@localhost.dev",
23
- superadminPassword: "12345678",
24
- databaseUrl: "postgresql://localhost:5432/my-app?schema=public",
25
- redisUrl: "redis://localhost:6379",
26
- jwtSecret: "test-jwt-secret",
27
- jwtRefreshSecret: "test-jwt-refresh-secret",
28
- adminOrigin: "http://localhost:3000",
29
- apiPort: "4000",
30
- git: false,
31
- install: false,
32
- templateDir: defaultTemplateDir()
33
- });
30
+ const result = createProject({ ...BASE_OPTIONS, projectName: "my-app", cwd, templateDir: defaultTemplateDir() });
34
31
  const envExample = readFileSync(join(result.targetDir, ".env.example"), "utf8");
35
32
  expect(envExample).toContain("DATABASE_URL=postgresql://localhost:5432/my-app?schema=public");
36
33
  expect(envExample).toContain("REDIS_URL=redis://localhost:6379");
@@ -43,33 +40,52 @@ describe("create project", () => {
43
40
  rmSync(cwd, { recursive: true, force: true });
44
41
  }
45
42
  });
43
+ it("writes apps/api/.env with real secrets and superadmin credentials", () => {
44
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
45
+ try {
46
+ const result = createProject({ ...BASE_OPTIONS, projectName: "my-app", cwd, templateDir: defaultTemplateDir() });
47
+ const apiEnv = readFileSync(join(result.targetDir, "apps", "api", ".env"), "utf8");
48
+ expect(apiEnv).toContain("DATABASE_URL=postgresql://localhost:5432/my-app?schema=public");
49
+ expect(apiEnv).toContain("JWT_SECRET=test-jwt-secret");
50
+ expect(apiEnv).toContain("SUPERADMIN_EMAIL=admin@localhost.dev");
51
+ expect(apiEnv).toContain("SUPERADMIN_PASSWORD=password1234");
52
+ }
53
+ finally {
54
+ rmSync(cwd, { recursive: true, force: true });
55
+ }
56
+ });
46
57
  it("fails fast when template package.json is missing", () => {
47
58
  const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
48
59
  const badTemplate = mkdtempSync(join(tmpdir(), "openadminjs-cli-template-"));
49
60
  try {
50
61
  writeFileSync(join(badTemplate, ".env.example"), "DATABASE_URL=__DATABASE_URL__\n");
51
62
  mkdirSync(join(badTemplate, "apps"), { recursive: true });
52
- expect(() => createProject({
53
- projectName: "broken-app",
54
- cwd,
55
- packageManager: "pnpm",
56
- database: "postgresql",
57
- superadminEmail: "admin@localhost.dev",
58
- superadminPassword: "12345678",
59
- databaseUrl: "postgresql://localhost:5432/broken-app?schema=public",
60
- redisUrl: "redis://localhost:6379",
61
- jwtSecret: "test-jwt-secret",
62
- jwtRefreshSecret: "test-jwt-refresh-secret",
63
- adminOrigin: "http://localhost:3000",
64
- apiPort: "4000",
65
- git: false,
66
- install: false,
67
- templateDir: badTemplate
68
- })).toThrow(/package\.json not found/);
63
+ expect(() => createProject({ ...BASE_OPTIONS, projectName: "broken-app", cwd, templateDir: badTemplate })).toThrow(/package\.json not found/);
69
64
  }
70
65
  finally {
71
66
  rmSync(cwd, { recursive: true, force: true });
72
67
  rmSync(badTemplate, { recursive: true, force: true });
73
68
  }
74
69
  });
70
+ it("copies template when installed inside node_modules (npx scenario)", () => {
71
+ // The old filter `source.includes("node_modules")` matched the entire absolute path when the
72
+ // package was installed via npx (~/.npm/_npx/.../node_modules/openadminjs/template/...) and
73
+ // blocked every file, so package.json never landed in the target.
74
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
75
+ const fakeNpx = mkdtempSync(join(tmpdir(), "openadminjs-npx-"));
76
+ const templateDir = join(fakeNpx, "node_modules", "openadminjs", "template");
77
+ try {
78
+ mkdirSync(templateDir, { recursive: true });
79
+ writeFileSync(join(templateDir, "package.json"), JSON.stringify({ name: "__APP_NAME__", private: true }, null, 2) + "\n");
80
+ writeFileSync(join(templateDir, ".env.example"), "DATABASE_URL=__DATABASE_URL__\n");
81
+ const result = createProject({ ...BASE_OPTIONS, projectName: "npx-app", cwd, templateDir });
82
+ const packageJson = readFileSync(join(result.targetDir, "package.json"), "utf8");
83
+ expect(packageJson).toContain('"name": "npx-app"');
84
+ expect(existsSync(join(result.targetDir, "apps", "api", ".env"))).toBe(false);
85
+ }
86
+ finally {
87
+ rmSync(cwd, { recursive: true, force: true });
88
+ rmSync(fakeNpx, { recursive: true, force: true });
89
+ }
90
+ });
75
91
  });
package/dist/index.js CHANGED
@@ -1,18 +1,29 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
3
  import { join } from "node:path";
4
+ import { spawnSync } from "node:child_process";
4
5
  import { cac } from "cac";
5
6
  import pc from "picocolors";
6
7
  import { createProjectInteractive } from "./create-project.js";
7
8
  import { modelNameToResourceSlug } from "./resource-slug.js";
8
9
  const cli = cac("openadminjs");
9
10
  function runScript(name) {
10
- const scripts = {
11
- dev: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin dev",
12
- build: "pnpm -r build",
13
- start: "pnpm --parallel --filter @openadminjs/api --filter @openadminjs/admin start"
11
+ const commands = {
12
+ dev: ["pnpm", ["--parallel", "--filter", "@openadminjs/api", "--filter", "@openadminjs/admin", "dev"]],
13
+ build: ["pnpm", ["-r", "build"]],
14
+ start: ["pnpm", ["--parallel", "--filter", "@openadminjs/api", "--filter", "@openadminjs/admin", "start"]]
14
15
  };
15
- console.log(pc.cyan(`Run: ${scripts[name]}`));
16
+ const entry = commands[name];
17
+ if (!entry) {
18
+ console.error(pc.red(`Unknown script: ${name}`));
19
+ process.exitCode = 1;
20
+ return;
21
+ }
22
+ const [cmd, args] = entry;
23
+ const result = spawnSync(cmd, args, { stdio: "inherit", cwd: process.cwd() });
24
+ if (result.status !== 0 || result.error) {
25
+ process.exitCode = result.status ?? 1;
26
+ }
16
27
  }
17
28
  function doctor() {
18
29
  const required = ["package.json", "pnpm-workspace.yaml", ".env.example", "prisma/schema.prisma"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openadminjs",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "openadminjs": "dist/index.js"
@@ -26,7 +26,9 @@
26
26
  "README.md"
27
27
  ],
28
28
  "scripts": {
29
- "build": "tsc -p tsconfig.json && node ../../scripts/make-executable.mjs dist/index.js",
29
+ "sync-template": "node ../../scripts/sync-template.mjs",
30
+ "prepack": "node ../../scripts/sync-template.mjs",
31
+ "build": "node ../../scripts/sync-template.mjs && tsc -p tsconfig.json && node ../../scripts/make-executable.mjs dist/index.js",
30
32
  "lint": "tsc -p tsconfig.json --noEmit",
31
33
  "typecheck": "tsc -p tsconfig.json --noEmit",
32
34
  "test": "vitest run"
@@ -2,5 +2,5 @@ DATABASE_URL=__DATABASE_URL__
2
2
  REDIS_URL=__REDIS_URL__
3
3
  JWT_SECRET=__JWT_SECRET__
4
4
  JWT_REFRESH_SECRET=__JWT_REFRESH_SECRET__
5
- ADMIN_ORIGIN=http://localhost:3000
6
- API_PORT=4000
5
+ ADMIN_ORIGIN=__ADMIN_ORIGIN__
6
+ API_PORT=__API_PORT__
@@ -1,13 +1,32 @@
1
1
  # __APP_NAME__
2
2
 
3
- Generated by OpenAdminJS.
3
+ Generated by [OpenAdminJS](https://openadminjs.dev).
4
+
5
+ ## Stack
6
+
7
+ - **API** — Nest.js 10 + Prisma 6 (port 4000)
8
+ - **Admin** — Next.js 15 back-office (port 3000)
9
+ - **Web** — Next.js 15 public site (port 3001)
10
+
11
+ ## Getting started
4
12
 
5
13
  ```bash
6
14
  pnpm install
7
- docker compose up -d
8
- pnpm db:migrate
9
- pnpm db:seed
10
15
  pnpm dev
11
16
  ```
12
17
 
13
- Superadmin credentials are created during `pnpm db:seed`.
18
+ Admin panel → http://localhost:3000
19
+ API + Swagger → http://localhost:4000/api/docs
20
+ Public site → http://localhost:3001
21
+
22
+ ## Useful commands
23
+
24
+ | Command | Description |
25
+ |---|---|
26
+ | `pnpm dev` | Start API + admin in parallel |
27
+ | `pnpm db:migrate` | Run Prisma migrations |
28
+ | `pnpm db:seed` | Seed database (creates superadmin) |
29
+ | `pnpm db:studio` | Open Prisma Studio |
30
+ | `pnpm build` | Build all workspaces |
31
+ | `pnpm test` | Run all tests |
32
+ | `pnpm lint` | Type-check all workspaces |
@@ -0,0 +1,51 @@
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { TOKEN_COOKIE_AT, TOKEN_COOKIE_RT } from "../../../../lib/tokens";
3
+
4
+ const API_URL =
5
+ typeof process !== "undefined" && process.env.NEXT_PUBLIC_API_URL
6
+ ? process.env.NEXT_PUBLIC_API_URL
7
+ : "http://localhost:4000";
8
+
9
+ const COOKIE_OPTS = {
10
+ path: "/",
11
+ maxAge: 60 * 60 * 24 * 7,
12
+ sameSite: "lax" as const,
13
+ secure: process.env.NODE_ENV === "production",
14
+ httpOnly: false
15
+ } as const;
16
+
17
+ export async function POST(req: NextRequest) {
18
+ const body = await req.json().catch(() => null);
19
+ if (!body) return NextResponse.json({ message: "Invalid request body" }, { status: 400 });
20
+
21
+ const upstream = await fetch(`${API_URL}/auth/login`, {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify(body)
25
+ }).catch(() => null);
26
+
27
+ if (!upstream) {
28
+ return NextResponse.json(
29
+ { message: "Server error while signing in. Check that the API is running." },
30
+ { status: 502 }
31
+ );
32
+ }
33
+
34
+ const data = (await upstream.json().catch(() => ({}))) as {
35
+ accessToken?: string;
36
+ refreshToken?: string;
37
+ message?: string;
38
+ };
39
+
40
+ if (!upstream.ok || !data.accessToken || !data.refreshToken) {
41
+ return NextResponse.json(
42
+ { message: data.message ?? "Invalid credentials" },
43
+ { status: upstream.status }
44
+ );
45
+ }
46
+
47
+ const res = NextResponse.json({ ok: true });
48
+ res.cookies.set(TOKEN_COOKIE_AT, data.accessToken, COOKIE_OPTS);
49
+ res.cookies.set(TOKEN_COOKIE_RT, data.refreshToken, COOKIE_OPTS);
50
+ return res;
51
+ }
@@ -0,0 +1,11 @@
1
+ import { NextResponse } from "next/server";
2
+ import { TOKEN_COOKIE_AT, TOKEN_COOKIE_RT } from "../../../../lib/tokens";
3
+
4
+ const CLEAR_OPTS = { path: "/", maxAge: 0, sameSite: "lax" as const, httpOnly: false } as const;
5
+
6
+ export async function POST() {
7
+ const res = NextResponse.json({ ok: true });
8
+ res.cookies.set(TOKEN_COOKIE_AT, "", CLEAR_OPTS);
9
+ res.cookies.set(TOKEN_COOKIE_RT, "", CLEAR_OPTS);
10
+ return res;
11
+ }
@@ -0,0 +1,46 @@
1
+ import { NextRequest, NextResponse } from "next/server";
2
+ import { TOKEN_COOKIE_AT, TOKEN_COOKIE_RT } from "../../../../lib/tokens";
3
+
4
+ const API_URL =
5
+ typeof process !== "undefined" && process.env.NEXT_PUBLIC_API_URL
6
+ ? process.env.NEXT_PUBLIC_API_URL
7
+ : "http://localhost:4000";
8
+
9
+ const COOKIE_OPTS = {
10
+ path: "/",
11
+ maxAge: 60 * 60 * 24 * 7,
12
+ sameSite: "lax" as const,
13
+ secure: process.env.NODE_ENV === "production",
14
+ httpOnly: false
15
+ } as const;
16
+
17
+ export async function POST(req: NextRequest) {
18
+ const rt = req.cookies.get(TOKEN_COOKIE_RT)?.value;
19
+ if (!rt) return NextResponse.json({ message: "No refresh token" }, { status: 401 });
20
+
21
+ const upstream = await fetch(`${API_URL}/auth/refresh`, {
22
+ method: "POST",
23
+ headers: { "content-type": "application/json" },
24
+ body: JSON.stringify({ refreshToken: rt, realm: "admin" })
25
+ }).catch(() => null);
26
+
27
+ if (!upstream) return NextResponse.json({ message: "API unavailable" }, { status: 502 });
28
+
29
+ const data = (await upstream.json().catch(() => ({}))) as {
30
+ accessToken?: string;
31
+ refreshToken?: string;
32
+ message?: string;
33
+ };
34
+
35
+ if (!upstream.ok || !data.accessToken || !data.refreshToken) {
36
+ const res = NextResponse.json({ message: data.message ?? "Refresh failed" }, { status: 401 });
37
+ res.cookies.set(TOKEN_COOKIE_AT, "", { ...COOKIE_OPTS, maxAge: 0 });
38
+ res.cookies.set(TOKEN_COOKIE_RT, "", { ...COOKIE_OPTS, maxAge: 0 });
39
+ return res;
40
+ }
41
+
42
+ const res = NextResponse.json({ ok: true });
43
+ res.cookies.set(TOKEN_COOKIE_AT, data.accessToken, COOKIE_OPTS);
44
+ res.cookies.set(TOKEN_COOKIE_RT, data.refreshToken, COOKIE_OPTS);
45
+ return res;
46
+ }