@infuro/cms-core 1.0.5 → 1.0.7

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 CHANGED
@@ -1,34 +1,43 @@
1
1
  # @infuro/cms-core
2
2
 
3
- A headless CMS framework built on Next.js and TypeORM. Provides a ready-to-use admin panel, CRUD API layer, authentication, plugin system, and UI components — so you only write what's unique to your website.
3
+ A headless CMS framework built on Next.js and TypeORM. It provides a ready-to-use admin panel, CRUD API layer, authentication, plugin system, and UI components — so you only write what's unique to your website.
4
4
 
5
- ## Architecture
5
+ ## Overview
6
+
7
+ You don't set up or clone core in each website. Install the published package and run the init command to scaffold a new site.
8
+
9
+ **Typical workflow for a new site:**
10
+
11
+ 1. Create a Next.js app (TypeScript, Tailwind, App Router, `src` directory):
12
+ `npx create-next-app@latest my-site --typescript --tailwind --app --src-dir`
13
+ 2. From the project root, run:
14
+ `npx @infuro/cms-core init`
15
+ 3. Copy `.env.example` to `.env`, set `DATABASE_URL`, `NEXTAUTH_SECRET`, `NEXTAUTH_URL`, then run `npm run seed` (or migrations) and `npm run dev`.
16
+
17
+ Init creates all required files (data-source, auth-helpers, cms, API routes, admin layout and page, middleware, providers, seed, migration runner, default theme, basic home and contact pages), and can patch `next.config`, `tailwind.config`, layout, and `package.json` and install dependencies. Use `--force` to overwrite existing files, `--dry-run` to see what would be created, `--no-deps` to skip npm install, `--no-patch-config` to skip config changes.
18
+
19
+ **Manual setup (if you prefer not to use init):** Install from npm (`npm install @infuro/cms-core typeorm reflect-metadata bcryptjs next-auth next-themes sonner` and `npm install -D @types/node`), then follow the step-by-step setup below. For local development of core itself, use `"@infuro/cms-core": "file:../core"` in the site's package.json.
20
+
21
+ ## Project structure (your site after setup)
6
22
 
7
23
  ```
8
- core/ # This package
9
- ├── src/
10
- │ ├── entities/ # TypeORM entities (User, Blog, Form, etc.)
11
- │ ├── api/ # API handlers (CRUD, auth, CMS-specific)
12
- │ ├── auth/ # NextAuth config, middleware, helpers
13
- │ ├── admin/ # Admin panel (layout, pages, page resolver)
14
- │ ├── plugins/ # Plugin system (email, storage, analytics, ERP, etc.)
15
- │ ├── components/ # Shared UI (shadcn/ui + Admin components)
16
- │ ├── hooks/ # React hooks (analytics, mobile, plugin)
17
- │ └── lib/ # Utilities (cn, etc.)
18
-
19
- your-website/ # Your Next.js app
24
+ your-website/
20
25
  ├── src/
21
26
  │ ├── app/
22
- │ │ ├── admin/ # 2 files: layout.tsx + [[...slug]]/page.tsx
27
+ │ │ ├── admin/ # layout.tsx + [[...slug]]/page.tsx
23
28
  │ │ └── api/
24
29
  │ │ ├── auth/ # NextAuth route
25
- │ │ └── [[...path]]/ # Single catch-all mounting core's API
30
+ │ │ └── [[...path]]/ # Catch-all for CMS API
26
31
  │ ├── lib/
27
- │ │ ├── data-source.ts # TypeORM DataSource init
28
- │ │ ├── auth-helpers.ts # Wire core auth to NextResponse
29
- │ │ └── cms.ts # CmsApp init with plugins
30
- │ ├── middleware.ts # Wire core middleware to Next.js
31
- │ └── ... # Your custom pages, components, etc.
32
+ │ │ ├── data-source.ts
33
+ │ │ ├── auth-helpers.ts
34
+ │ │ ├── cms.ts
35
+ ├── theme-registry.ts
36
+ └── seed.ts
37
+ │ ├── themes/ # Optional: default theme from init
38
+ │ ├── migrations/
39
+ │ ├── middleware.ts
40
+ │ └── ... # Your pages, components, etc.
32
41
  ```
33
42
 
34
43
  ## Getting Started
@@ -40,28 +49,14 @@ npx create-next-app@latest my-website --typescript --tailwind --app --src-dir
40
49
  cd my-website
41
50
  ```
42
51
 
43
- ### 2. Install core
44
-
45
- Link the local package (or install from npm once published):
52
+ ### 2. Install the package
46
53
 
47
54
  ```bash
48
- # In your website's package.json, add:
49
- # "@infuro/cms-core": "file:../core"
50
- npm install
55
+ npm install @infuro/cms-core typeorm reflect-metadata bcryptjs next-auth next-themes sonner
56
+ npm install -D @types/node
51
57
  ```
52
58
 
53
- Required peer dependencies (should already be in a Next.js app):
54
-
55
- ```
56
- next >= 14, react >= 18, react-dom >= 18, next-auth ^4.24
57
- ```
58
-
59
- Additional dependencies you'll need:
60
-
61
- ```bash
62
- npm install typeorm reflect-metadata bcryptjs next-auth next-themes sonner
63
- npm install -D @types/node typescript
64
- ```
59
+ Peer dependencies (Next.js app usually has these): `next` ≥14, `react` ≥18, `react-dom` ≥18, `next-auth` ^4.24. For local development, use `"@infuro/cms-core": "file:../core"` in package.json and run `npm install`.
65
60
 
66
61
  ### 3. Configure `next.config.js`
67
62
 
@@ -306,8 +301,22 @@ export async function POST(req: Request) {
306
301
 
307
302
  Create `src/app/admin/layout.tsx`:
308
303
 
309
- ```ts
310
- export { default } from '@infuro/cms-core/admin';
304
+ ```tsx
305
+ 'use client';
306
+ import '@infuro/cms-core/admin.css';
307
+ import AdminLayout from '@infuro/cms-core/admin';
308
+
309
+ export default function AdminLayoutWrapper({ children }: { children: React.ReactNode }) {
310
+ return (
311
+ <AdminLayout
312
+ customNavItems={[]}
313
+ customNavSections={[]}
314
+ customCrudConfigs={{}}
315
+ >
316
+ {children}
317
+ </AdminLayout>
318
+ );
319
+ }
311
320
  ```
312
321
 
313
322
  Create `src/app/admin/[[...slug]]/page.tsx`:
@@ -321,20 +330,20 @@ export default async function AdminPage({ params }: { params: Promise<{ slug?: s
321
330
  }
322
331
  ```
323
332
 
324
- That's it — the admin panel at `/admin` is fully rendered by core (layout, sidebar, header, pages). Core injects its own CSS theme variables via `<style>` tag, so no additional CSS setup is needed for the admin panel.
333
+ The admin at `/admin` is rendered by the package (layout, sidebar, header, built-in pages). Pass `customNavSections` and `customCrudConfigs` to add your own sidebar links and CRUD list pages (see [Adding custom pages and admin nav](#adding-custom-pages-and-admin-nav)).
325
334
 
326
335
  ### 10. Configure Tailwind
327
336
 
328
- Core's admin components use Tailwind classes. Your `tailwind.config.js` must scan core's source so those classes aren't purged in production:
337
+ Core's admin components use Tailwind classes. Include the package in `content` so those classes aren't purged:
329
338
 
330
339
  ```js
331
- module.exports = {
332
- content: [
333
- "./src/**/*.{js,ts,jsx,tsx,mdx}",
334
- "../core/src/**/*.{js,ts,jsx,tsx}", // include core
335
- ],
336
- // ... rest of your config
337
- };
340
+ content: [
341
+ "./src/**/*.{js,ts,jsx,tsx,mdx}",
342
+ // When using from npm:
343
+ "./node_modules/@infuro/cms-core/dist/**/*.{js,cjs}",
344
+ // When using file:../core (local):
345
+ // "../core/src/**/*.{js,ts,jsx,tsx}",
346
+ ],
338
347
  ```
339
348
 
340
349
  You also need the shadcn/ui color mappings in `theme.extend.colors` — see the [Tailwind Config](#tailwind-config) section below.
@@ -348,7 +357,19 @@ import { NextResponse } from 'next/server';
348
357
  import type { NextRequest } from 'next/server';
349
358
  import { createCmsMiddleware } from '@infuro/cms-core/auth';
350
359
 
351
- const cmsMiddleware = createCmsMiddleware();
360
+ const cmsMiddleware = createCmsMiddleware({
361
+ // Optional: allow unauthenticated access to specific API paths/methods (e.g. public form submit)
362
+ publicApiMethods: {
363
+ '/api/contacts': ['POST'],
364
+ '/api/form-submissions': ['POST'],
365
+ '/api/blogs': ['GET'],
366
+ '/api/forms': ['GET'],
367
+ '/api/auth': ['GET', 'POST'],
368
+ '/api/users/forgot-password': ['POST'],
369
+ '/api/users/set-password': ['POST'],
370
+ '/api/users/invite': ['POST'],
371
+ },
372
+ });
352
373
 
353
374
  export function middleware(request: NextRequest) {
354
375
  const result = cmsMiddleware({
@@ -408,6 +429,16 @@ export default function RootLayout({ children }: { children: React.ReactNode })
408
429
  }
409
430
  ```
410
431
 
432
+ ## Adding custom pages and admin nav
433
+
434
+ **Custom sidebar links:** Pass `customNavItems` or `customNavSections` to `AdminLayout` in your `src/app/admin/layout.tsx`. Each item has `href`, `label`, and optional `icon`. Use `href` like `/admin/locations` so the link opens under the admin.
435
+
436
+ **Custom CRUD (list + optional add/edit):** Define a `CustomCrudConfig` (title, apiEndpoint, columns, addEditPageUrl, optional filters) and pass it as `customCrudConfigs={{ myResource: config }}` to `AdminLayout`. You must have a corresponding API (e.g. under your catch-all or a custom route) and entity. The first path segment (e.g. `locations`) is the key; add a nav item with `href: '/admin/locations'`.
437
+
438
+ **Custom full pages:** For a page that isn’t a CRUD list, add a Next.js route under admin, e.g. `src/app/admin/reports/page.tsx`, and render your component there. The admin layout wraps all `/admin/*` routes, so your page appears inside the same shell. Add a link in `customNavItems` or `customNavSections` with `href: '/admin/reports'`.
439
+
440
+ Types are exported from `@infuro/cms-core/admin`: `CustomNavItem`, `CustomNavSection`, `CustomCrudConfig`, `CustomCrudColumn`, etc.
441
+
411
442
  ## Database Setup
412
443
 
413
444
  ### First-time setup (quick)
@@ -586,13 +617,13 @@ createCmsMiddleware({
586
617
 
587
618
  ## Tailwind Config
588
619
 
589
- Core's admin panel and UI components use shadcn/ui which requires CSS variable-based color mappings. Your `tailwind.config.js` needs these in `theme.extend.colors`:
620
+ The admin panel and UI components use shadcn/ui and require CSS variable-based color mappings. Your `tailwind.config.js` needs these in `theme.extend.colors`:
590
621
 
591
622
  ```js
592
623
  module.exports = {
593
624
  content: [
594
625
  "./src/**/*.{js,ts,jsx,tsx,mdx}",
595
- "../core/src/**/*.{js,ts,jsx,tsx}",
626
+ "./node_modules/@infuro/cms-core/dist/**/*.{js,cjs}",
596
627
  ],
597
628
  darkMode: "class",
598
629
  theme: {
@@ -632,7 +663,7 @@ module.exports = {
632
663
  };
633
664
  ```
634
665
 
635
- The CSS variables themselves are injected by core's AdminLayout at runtime. Your website's own CSS can also define them in `:root` if your public pages use shadcn/ui components.
666
+ The CSS variables are injected by the admin layout at runtime. Your website's own CSS can also define them in `:root` if your public pages use shadcn/ui components.
636
667
 
637
668
  ## Environment Variables
638
669