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.
- package/README.md +117 -81
- package/dist/adapt-package-manager.d.ts +3 -0
- package/dist/adapt-package-manager.js +118 -0
- package/dist/create-project.d.ts +77 -2
- package/dist/create-project.js +685 -224
- package/dist/db-commands.d.ts +20 -0
- package/dist/db-commands.js +75 -0
- package/dist/detect-package-manager.d.ts +8 -0
- package/dist/detect-package-manager.js +37 -0
- package/dist/doctor.d.ts +26 -0
- package/dist/doctor.js +232 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +476 -166
- package/dist/render-schema.d.ts +3 -0
- package/dist/render-schema.js +33 -0
- package/dist/resource-slug.d.ts +1 -0
- package/dist/resource-slug.js +7 -0
- package/dist/runtime-mode.d.ts +16 -0
- package/dist/runtime-mode.js +138 -0
- package/dist/secrets.d.ts +24 -0
- package/dist/secrets.js +93 -0
- package/dist/security.d.ts +13 -0
- package/dist/security.js +168 -0
- package/dist/upgrade.d.ts +10 -0
- package/dist/upgrade.js +133 -0
- package/dist/validate-name.d.ts +33 -0
- package/dist/validate-name.js +206 -0
- package/package.json +39 -11
- package/template/.dockerignore +15 -0
- package/template/.env.production.example +5 -0
- package/template/Dockerfile +12 -0
- package/template/README.md +23 -3
- package/template/apps/admin/app/api/auth/login/route.ts +9 -9
- package/template/apps/admin/app/api/auth/logout/route.ts +11 -3
- package/template/apps/admin/app/api/auth/oidc/callback/route.ts +19 -0
- package/template/apps/admin/app/api/auth/oidc/start/route.ts +11 -0
- package/template/apps/admin/app/api/auth/oidc/status/route.ts +6 -0
- package/template/apps/admin/app/api/auth/refresh/route.ts +18 -11
- package/template/apps/admin/app/api/backend/[...path]/route.ts +48 -0
- package/template/apps/admin/app/api-tokens/page.tsx +39 -39
- package/template/apps/admin/app/assistant/page.tsx +11 -0
- package/template/apps/admin/app/dashboard/page.tsx +45 -462
- package/template/apps/admin/app/globals.css +52 -16
- package/template/apps/admin/app/layout.tsx +1 -1
- package/template/apps/admin/app/login/page.tsx +13 -145
- package/template/apps/admin/app/plugins/page.tsx +16 -402
- package/template/apps/admin/app/profile/page.tsx +5 -2
- package/template/apps/admin/app/settings/page.tsx +14 -265
- package/template/apps/admin/components/ai-assistant-widget.tsx +3 -6
- package/template/apps/admin/components/app-shell.tsx +25 -373
- package/template/apps/admin/components/auth-guard.tsx +8 -28
- package/template/apps/admin/components/logo.tsx +1 -30
- package/template/apps/admin/components/resource-form.tsx +3 -3
- package/template/apps/admin/components/resource-table.tsx +12 -8
- package/template/apps/admin/lib/api.ts +45 -107
- package/template/apps/admin/lib/resource-table-prefs.ts +1 -57
- package/template/apps/admin/lib/server-api.ts +7 -0
- package/template/apps/admin/lib/tokens.ts +9 -81
- package/template/apps/admin/middleware.ts +9 -50
- package/template/apps/admin/next.config.mjs +4 -0
- package/template/apps/admin/package.json +2 -1
- package/template/apps/admin/public/brand/favicon.svg +4 -1
- package/template/apps/admin/tailwind.config.ts +9 -8
- package/template/apps/api/package.json +13 -6
- package/template/apps/api/src/access/catalog.ts +4 -0
- package/template/apps/api/src/admin/admin-ai.controller.ts +15 -125
- package/template/apps/api/src/admin/admin-analytics.service.ts +16 -148
- package/template/apps/api/src/admin/admin-logs.controller.ts +4 -1
- package/template/apps/api/src/admin/admin-plugins.controller.ts +8 -8
- package/template/apps/api/src/admin/admin-plugins.service.ts +15 -259
- package/template/apps/api/src/admin/admin-resource.service.ts +105 -254
- package/template/apps/api/src/admin/admin.controller.ts +17 -4
- package/template/apps/api/src/admin/admin.module.ts +2 -2
- package/template/apps/api/src/admin/resource-policy.ts +1 -0
- package/template/apps/api/src/admin/resource-query.ts +1 -0
- package/template/apps/api/src/admin/safe-ai.service.ts +43 -0
- package/template/apps/api/src/admin/validate-resource-payload.ts +2 -0
- package/template/apps/api/src/auth/auth.controller.ts +4 -2
- package/template/apps/api/src/auth/auth.service.ts +68 -83
- package/template/apps/api/src/auth/sso-oidc.controller.ts +12 -74
- package/template/apps/api/src/auth/sso-oidc.service.ts +51 -268
- package/template/apps/api/src/common/api-exception.filter.ts +1 -0
- package/template/apps/api/src/common/auth.guard.ts +66 -39
- package/template/apps/api/src/common/json-field-codec.ts +138 -0
- package/template/apps/api/src/common/prisma.service.ts +12 -7
- package/template/apps/api/src/common/request-logging.interceptor.ts +8 -3
- package/template/apps/api/src/graphql/graphql.module.ts +14 -1
- package/template/apps/api/src/health/health.controller.ts +6 -0
- package/template/apps/api/src/main.ts +11 -2
- package/template/apps/api/src/plugins/plugin-loader.ts +5 -3
- package/template/apps/api/src/resources/commerce.resource.ts +3 -34
- package/template/apps/api/src/resources/operations.resource.ts +1 -0
- package/template/apps/api/src/store/payment/payment.controller.ts +15 -92
- package/template/apps/api/src/store/payment/payment.module.ts +2 -3
- package/template/apps/api/src/store/payment/payment.service.ts +121 -227
- package/template/apps/api/webpack.config.cjs +2 -1
- package/template/apps/web/next.config.mjs +4 -0
- package/template/apps/web/public/brand/favicon.svg +4 -1
- package/template/compose.yaml +56 -0
- package/template/examples/crm-admin/README.md +31 -0
- package/template/examples/crm-admin/package.json +17 -0
- package/template/examples/crm-admin/prisma/models.fragment.prisma +50 -0
- package/template/examples/crm-admin/src/index.ts +7 -0
- package/template/examples/crm-admin/src/resources/activities.resource.ts +29 -0
- package/template/examples/crm-admin/src/resources/companies.resource.ts +21 -0
- package/template/examples/crm-admin/src/resources/contacts.resource.ts +24 -0
- package/template/examples/crm-admin/src/resources/deals.resource.ts +30 -0
- package/template/examples/crm-admin/tsconfig.json +7 -0
- package/template/package.json +8 -1
- package/template/packages/admin-client/package.json +18 -0
- package/template/packages/admin-client/src/contracts.ts +29 -0
- package/template/packages/admin-client/src/index.ts +2 -0
- package/template/packages/admin-client/src/preferences.ts +57 -0
- package/template/packages/admin-client/tsconfig.json +12 -0
- package/template/packages/auth/package.json +1 -1
- package/template/packages/brand/site/assets/brand/favicon.svg +4 -1
- package/template/packages/brand/src/generate-assets.mjs +17 -186
- package/template/packages/core/package.json +1 -1
- package/template/packages/mail/package.json +1 -1
- package/template/packages/nest/package.json +22 -0
- package/template/packages/nest/src/api-exception.filter.ts +23 -0
- package/template/packages/nest/src/index.ts +3 -0
- package/template/packages/nest/src/resource-policy.ts +64 -0
- package/template/packages/nest/src/resource-query.ts +103 -0
- package/template/packages/nest/tsconfig.json +12 -0
- package/template/packages/notifications/package.json +1 -1
- package/template/packages/payments/package.json +1 -1
- package/template/packages/permissions/package.json +1 -1
- package/template/packages/permissions/src/index.ts +2 -2
- package/template/packages/plugin-sdk/package.json +1 -1
- package/template/packages/plugin-sdk/src/index.ts +2 -2
- package/template/packages/prisma/package.json +21 -0
- package/template/packages/prisma/schema/ai.prisma +36 -0
- package/template/packages/prisma/schema/audit.prisma +13 -0
- package/template/packages/prisma/schema/commerce.prisma +79 -0
- package/template/packages/prisma/schema/content.prisma +27 -0
- package/template/packages/prisma/schema/core.prisma +106 -0
- package/template/packages/prisma/schema/header.prisma +8 -0
- package/template/packages/prisma/schema/jobs.prisma +9 -0
- package/template/packages/prisma/schema/media.prisma +9 -0
- package/template/packages/prisma/schema/modules.json +47 -0
- package/template/packages/prisma/schema/notifications.prisma +9 -0
- package/template/packages/prisma/schema/settings.prisma +8 -0
- package/template/packages/prisma/schema/tokens.prisma +10 -0
- package/template/packages/prisma/src/index.d.ts +12 -0
- package/template/packages/prisma/src/index.mjs +138 -0
- package/template/packages/queue/package.json +1 -1
- package/template/packages/resource/package.json +1 -1
- package/template/packages/resource/src/index.ts +1 -0
- package/template/packages/storage/package.json +1 -1
- package/template/packages/storage/src/index.ts +37 -0
- package/template/prisma/migrations/20260713120000_add_user_oidc_key_and_category_order/migration.sql +11 -0
- package/template/prisma/migrations/20261126130000_add_sessions/migration.sql +26 -0
- package/template/prisma/migrations/20261126140000_api_token_hash/migration.sql +3 -0
- package/template/prisma/migrations/20261126150000_payment_idempotency/migration.sql +6 -0
- package/template/prisma/schema.prisma +82 -54
- package/template/prisma/seed.ts +14 -38
- package/template/runtime-versions.json +15 -0
- package/template/scripts/db-init.mjs +33 -0
- package/template/scripts/install-crm.mjs +50 -0
- package/template/scripts/migrate-existing.mjs +65 -0
- package/template/scripts/schema.mjs +48 -0
- package/template/tsconfig.base.json +23 -5
- package/LICENSE +0 -21
- package/dist/create-project.test.d.ts +0 -1
- package/dist/create-project.test.js +0 -99
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -7
- package/dist/resource-slug.test.d.ts +0 -1
- package/dist/resource-slug.test.js +0 -9
- package/template/apps/admin/.storybook/main.ts +0 -12
- package/template/apps/admin/.storybook/preview.ts +0 -10
- package/template/apps/admin/app/login/page.test.tsx +0 -18
- package/template/apps/admin/components/auth-guard.test.tsx +0 -55
- package/template/apps/admin/components/logo.stories.tsx +0 -24
- package/template/apps/admin/lib/api.test.ts +0 -118
- package/template/apps/admin/lib/auth-flow.e2e.test.ts +0 -79
- package/template/apps/admin/vitest.config.ts +0 -7
- package/template/apps/api/src/access/derive-permissions.test.ts +0 -26
- package/template/apps/api/src/admin/admin-resource.service.test.ts +0 -118
- package/template/apps/api/src/admin/validate-resource-payload.test.ts +0 -44
- package/template/apps/api/src/app.module.test.ts +0 -12
- package/template/apps/api/src/auth/auth.service.test.ts +0 -78
- package/template/apps/api/src/auth/sso-oidc.service.test.ts +0 -84
- package/template/apps/api/src/common/auth.guard.test.ts +0 -62
- package/template/apps/api/src/common/casl-ability.factory.test.ts +0 -33
- package/template/apps/api/src/common/request-logging.interceptor.test.ts +0 -39
- package/template/apps/api/src/graphql/admin-resources.resolver.test.ts +0 -45
- package/template/apps/api/src/graphql/ensure-gql-paramtypes.test.ts +0 -44
- package/template/apps/api/src/graphql/graphql-schema.test.ts +0 -26
- package/template/apps/api/src/plugins/manifest.schema.test.ts +0 -36
- package/template/apps/api/src/plugins/plugin-runtime.test.ts +0 -24
- package/template/apps/api/src/queue/queue.service.test.ts +0 -33
- package/template/apps/api/src/resources/resource-hooks.registry.test.ts +0 -72
- package/template/apps/api/vitest.config.ts +0 -21
- package/template/apps/web/lib/seo.test.ts +0 -41
- package/template/apps/web/vitest.config.ts +0 -19
- package/template/packages/auth/src/index.test.ts +0 -10
- package/template/packages/brand/src/index.test.ts +0 -9
- package/template/packages/core/src/index.test.ts +0 -27
- package/template/packages/core/vitest.config.ts +0 -9
- package/template/packages/mail/src/index.test.ts +0 -23
- package/template/packages/notifications/src/index.test.ts +0 -9
- package/template/packages/permissions/src/blueprints.test.ts +0 -62
- package/template/packages/permissions/src/index.test.ts +0 -34
- package/template/packages/plugin-sdk/src/sdk.test.ts +0 -13
- package/template/packages/plugin-sdk/vitest.config.ts +0 -5
- package/template/packages/queue/src/index.test.ts +0 -12
- package/template/packages/resource/src/index.test.ts +0 -196
- 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
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
7
|
+
## Requirements
|
|
8
8
|
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
27
|
+
```bash
|
|
28
|
+
pnpm install && pnpm db:migrate && pnpm db:seed
|
|
29
|
+
```
|
|
22
30
|
|
|
23
|
-
|
|
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
|
-
|
|
33
|
+
### What `dev` starts
|
|
28
34
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 (
|
|
43
|
+
Optional public web app (port 3001):
|
|
41
44
|
|
|
42
|
-
```
|
|
43
|
-
|
|
45
|
+
```bash
|
|
46
|
+
pnpm --filter @openadminjs/web dev # npm: npm run dev --workspace=@openadminjs/web
|
|
44
47
|
```
|
|
45
48
|
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
```
|
|
54
|
+
export OPENADMIN_ADMIN_PASSWORD="$(openssl rand -base64 24)"
|
|
51
55
|
|
|
52
|
-
|
|
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
|
-
|
|
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
|
-
|
|
67
|
+
Prefer **`--admin-password-env`** over `--admin-password` so secrets are not stored in shell history.
|
|
62
68
|
|
|
63
|
-
|
|
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
|
-
|
|
66
|
-
- **Password:** your `Superadmin password`
|
|
83
|
+
## Package managers
|
|
67
84
|
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
93
|
+
## SQLite zero-setup
|
|
77
94
|
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
99
|
+
## Environment
|
|
88
100
|
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
116
|
+
After create (with install), use the superadmin email and password from the wizard or `apps/api/.env`.
|
|
99
117
|
|
|
100
|
-
|
|
118
|
+
## Health & troubleshooting
|
|
101
119
|
|
|
102
120
|
```bash
|
|
103
|
-
|
|
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
|
-
|
|
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
|
-
|
|
128
|
+
**Prisma engine download failed:** check network/proxy; retry install from the project root.
|
|
109
129
|
|
|
110
|
-
|
|
130
|
+
**Setup failed mid-create:** the project directory is preserved with a resume command in the error message.
|
|
111
131
|
|
|
112
|
-
|
|
132
|
+
**npm `EUNSUPPORTEDPROTOCOL workspace:*`:** upgrade to the latest `openadminjs` CLI — npm projects must use `*` not `workspace:*`.
|
|
113
133
|
|
|
114
|
-
|
|
115
|
-
Email us at `openadminjs@proton.me`.
|
|
134
|
+
## Commands
|
|
116
135
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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,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
|
+
}
|
package/dist/create-project.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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;
|