@infuro/cms-core 1.0.4 → 1.0.6

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,6 +1,31 @@
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
+
5
+ ## Overview
6
+
7
+ **What you need to set up a new site:**
8
+
9
+ - Next.js 14+ app with TypeScript and Tailwind
10
+ - PostgreSQL and env vars: `DATABASE_URL`, `NEXTAUTH_SECRET`, `NEXTAUTH_URL`
11
+ - A few files in your app: **data-source** (TypeORM), **auth-helpers**, **cms** (plugins), **API catch-all route**, **NextAuth route**, **admin layout + catch-all page**, **middleware**, **providers** (Session + Theme + Toaster)
12
+ - Tailwind config that includes the package in `content` and extends theme (shadcn-style colors)
13
+ - Optional: custom admin nav, custom CRUD configs, custom admin pages, plugins
14
+
15
+ **Install from npm:**
16
+
17
+ ```bash
18
+ npm install @infuro/cms-core typeorm reflect-metadata bcryptjs next-auth next-themes sonner
19
+ npm install -D @types/node
20
+ ```
21
+
22
+ For local development with the core package in a sibling folder:
23
+
24
+ ```json
25
+ "@infuro/cms-core": "file:../core"
26
+ ```
27
+
28
+ Then follow the setup steps below.
4
29
 
5
30
  ## Architecture
6
31
 
@@ -42,26 +67,12 @@ cd my-website
42
67
 
43
68
  ### 2. Install core
44
69
 
45
- Link the local package (or install from npm once published):
46
-
47
70
  ```bash
48
- # In your website's package.json, add:
49
- # "@infuro/cms-core": "file:../core"
50
- npm install
51
- ```
52
-
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
71
+ npm install @infuro/cms-core typeorm reflect-metadata bcryptjs next-auth next-themes sonner
72
+ npm install -D @types/node
57
73
  ```
58
74
 
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
- ```
75
+ 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
76
 
66
77
  ### 3. Configure `next.config.js`
67
78
 
@@ -306,8 +317,22 @@ export async function POST(req: Request) {
306
317
 
307
318
  Create `src/app/admin/layout.tsx`:
308
319
 
309
- ```ts
310
- export { default } from '@infuro/cms-core/admin';
320
+ ```tsx
321
+ 'use client';
322
+ import '@infuro/cms-core/admin.css';
323
+ import AdminLayout from '@infuro/cms-core/admin';
324
+
325
+ export default function AdminLayoutWrapper({ children }: { children: React.ReactNode }) {
326
+ return (
327
+ <AdminLayout
328
+ customNavItems={[]}
329
+ customNavSections={[]}
330
+ customCrudConfigs={{}}
331
+ >
332
+ {children}
333
+ </AdminLayout>
334
+ );
335
+ }
311
336
  ```
312
337
 
313
338
  Create `src/app/admin/[[...slug]]/page.tsx`:
@@ -321,20 +346,20 @@ export default async function AdminPage({ params }: { params: Promise<{ slug?: s
321
346
  }
322
347
  ```
323
348
 
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.
349
+ The admin at `/admin` is rendered by core (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
350
 
326
351
  ### 10. Configure Tailwind
327
352
 
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:
353
+ Core's admin components use Tailwind classes. Include the package in `content` so those classes aren't purged:
329
354
 
330
355
  ```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
- };
356
+ content: [
357
+ "./src/**/*.{js,ts,jsx,tsx,mdx}",
358
+ // When using from npm:
359
+ "./node_modules/@infuro/cms-core/dist/**/*.{js,cjs}",
360
+ // When using file:../core (local):
361
+ // "../core/src/**/*.{js,ts,jsx,tsx}",
362
+ ],
338
363
  ```
339
364
 
340
365
  You also need the shadcn/ui color mappings in `theme.extend.colors` — see the [Tailwind Config](#tailwind-config) section below.
@@ -348,7 +373,19 @@ import { NextResponse } from 'next/server';
348
373
  import type { NextRequest } from 'next/server';
349
374
  import { createCmsMiddleware } from '@infuro/cms-core/auth';
350
375
 
351
- const cmsMiddleware = createCmsMiddleware();
376
+ const cmsMiddleware = createCmsMiddleware({
377
+ // Optional: allow unauthenticated access to specific API paths/methods (e.g. public form submit)
378
+ publicApiMethods: {
379
+ '/api/contacts': ['POST'],
380
+ '/api/form-submissions': ['POST'],
381
+ '/api/blogs': ['GET'],
382
+ '/api/forms': ['GET'],
383
+ '/api/auth': ['GET', 'POST'],
384
+ '/api/users/forgot-password': ['POST'],
385
+ '/api/users/set-password': ['POST'],
386
+ '/api/users/invite': ['POST'],
387
+ },
388
+ });
352
389
 
353
390
  export function middleware(request: NextRequest) {
354
391
  const result = cmsMiddleware({
@@ -408,6 +445,16 @@ export default function RootLayout({ children }: { children: React.ReactNode })
408
445
  }
409
446
  ```
410
447
 
448
+ ## Adding custom pages and admin nav
449
+
450
+ **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.
451
+
452
+ **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'`.
453
+
454
+ **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'`.
455
+
456
+ Types are exported from `@infuro/cms-core/admin`: `CustomNavItem`, `CustomNavSection`, `CustomCrudConfig`, `CustomCrudColumn`, etc.
457
+
411
458
  ## Database Setup
412
459
 
413
460
  ### First-time setup (quick)