@cfast/admin 0.0.1 → 0.2.0

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
@@ -23,7 +23,7 @@ This means:
23
23
  - **Permission-aware by default.** The admin panel uses `@cfast/db` under the hood. Admins see everything. Moderators see what moderators see. The admin UI doesn't bypass your permission system — it uses it.
24
24
  - **User management built in.** View users, assign roles, revoke roles, impersonate users. Integrated with `@cfast/auth`.
25
25
  - **Customizable, not locked in.** Override any view, any field, any action. But the default is good enough to ship.
26
- - **UI delegated to `@cfast/ui`.** Admin generates configuration. `@cfast/ui/joy` renders it.
26
+ - **UI delegated to `@cfast/ui`.** Admin generates configuration. `@cfast/joy` renders it.
27
27
 
28
28
  ## API
29
29
 
package/dist/index.js CHANGED
@@ -1432,7 +1432,7 @@ import Input2 from "@mui/joy/Input";
1432
1432
  import Table3 from "@mui/joy/Table";
1433
1433
  import Sheet4 from "@mui/joy/Sheet";
1434
1434
  import Stack4 from "@mui/joy/Stack";
1435
- import { RoleBadge } from "@cfast/ui/joy";
1435
+ import { RoleBadge } from "@cfast/joy";
1436
1436
  import { jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1437
1437
  function UserList({
1438
1438
  items,
@@ -1570,7 +1570,7 @@ import Chip2 from "@mui/joy/Chip";
1570
1570
  import Select from "@mui/joy/Select";
1571
1571
  import Option from "@mui/joy/Option";
1572
1572
  import Divider2 from "@mui/joy/Divider";
1573
- import { RoleBadge as RoleBadge2, AvatarWithInitials } from "@cfast/ui/joy";
1573
+ import { RoleBadge as RoleBadge2, AvatarWithInitials } from "@cfast/joy";
1574
1574
  import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
1575
1575
  function UserDetail({
1576
1576
  targetUser,
package/llms.txt ADDED
@@ -0,0 +1,167 @@
1
+ # @cfast/admin
2
+
3
+ > A complete admin panel generated from your Drizzle schema, with role management and user impersonation.
4
+
5
+ ## When to use
6
+
7
+ Use `@cfast/admin` when you need an admin panel for a cfast app. It reads your Drizzle schema, generates list/detail/create/edit views, and provides user management with role assignment and impersonation. Mount it on a single React Router route.
8
+
9
+ ## Key concepts
10
+
11
+ - **Schema introspection**: `introspectSchema()` reads Drizzle tables, infers column types/labels/relations, and produces `AdminTableMeta[]` config.
12
+ - **Thin layer**: Admin generates configuration. Rendering is delegated to `@cfast/ui` components (`ListView`, `DetailView`, `DataTable`, etc.) and `@cfast/forms` (`AutoForm`).
13
+ - **Permission-aware**: All CRUD operations go through `@cfast/db` with the user's grants. The admin UI respects your permission system -- an editor sees what editors see.
14
+ - **Auth adapter pattern**: Admin does not depend on `@cfast/auth` directly. You provide an `AdminAuthConfig` with callbacks for authentication, role management, and impersonation.
15
+
16
+ ## API Reference
17
+
18
+ ### Main entry point
19
+
20
+ ```typescript
21
+ import { createAdmin } from "@cfast/admin";
22
+
23
+ createAdmin(config: AdminConfig): { loader, action, Component }
24
+ ```
25
+
26
+ Returns a `{ loader, action, Component }` triple to mount on a React Router route.
27
+
28
+ ### AdminConfig
29
+
30
+ ```typescript
31
+ type AdminConfig = {
32
+ db: CreateDbFn; // (grants, user) => Db
33
+ auth: AdminAuthConfig; // auth adapter (see below)
34
+ schema: Record<string, SQLiteTable>; // your Drizzle schema object
35
+ tables?: Record<string, TableOverrides>; // per-table customization
36
+ users?: UserManagementConfig; // { assignableRoles?: string[] }
37
+ dashboard?: DashboardConfig; // { widgets?: DashboardWidget[] }
38
+ requiredRole?: string; // default: "admin"
39
+ };
40
+ ```
41
+
42
+ ### AdminAuthConfig
43
+
44
+ ```typescript
45
+ type AdminAuthConfig = {
46
+ requireUser: (request: Request) => Promise<{ user: AdminUser; grants: Grant[] }>;
47
+ hasRole: (user: AdminUser, role: string) => boolean;
48
+ getRoles: (userId: string) => Promise<string[]>;
49
+ setRole: (userId: string, role: string) => Promise<void>;
50
+ removeRole: (userId: string, role: string) => Promise<void>;
51
+ setRoles: (userId: string, roles: string[]) => Promise<void>;
52
+ impersonate?: (adminId: string, targetId: string, request: Request) => Promise<Response>;
53
+ stopImpersonation?: (request: Request) => Promise<Response>;
54
+ };
55
+ ```
56
+
57
+ ### TableOverrides
58
+
59
+ ```typescript
60
+ type TableOverrides = {
61
+ label?: string;
62
+ listColumns?: string[];
63
+ searchable?: string[];
64
+ defaultSort?: { column: string; direction: "asc" | "desc" };
65
+ fields?: Record<string, FieldConfig>; // from @cfast/forms
66
+ actions?: { row?: RowAction[]; table?: TableAction[] };
67
+ exclude?: boolean;
68
+ };
69
+ ```
70
+
71
+ ### Server/client splitting
72
+
73
+ For apps where server code must not leak into client bundles:
74
+
75
+ ```typescript
76
+ import { createAdminLoader, createAdminAction, introspectSchema } from "@cfast/admin";
77
+ import { createAdminComponent } from "@cfast/admin";
78
+
79
+ const tableMetas = introspectSchema(schema, tableOverrides?);
80
+ const loader = createAdminLoader(config, tableMetas);
81
+ const action = createAdminAction(config, tableMetas);
82
+ const Component = createAdminComponent(tableMetas);
83
+ ```
84
+
85
+ ### Schema introspection
86
+
87
+ ```typescript
88
+ introspectSchema(
89
+ schema: Record<string, SQLiteTable>,
90
+ tableOverrides?: Record<string, TableOverrides>,
91
+ ): AdminTableMeta[]
92
+ ```
93
+
94
+ Auto-excludes auth-internal tables (`session`, `account`, `verification`, `passkey`) unless explicitly configured.
95
+
96
+ ## Usage Examples
97
+
98
+ ### Minimal setup
99
+
100
+ ```typescript
101
+ // app/routes/admin.tsx
102
+ import { createAdmin } from "@cfast/admin";
103
+ import * as schema from "~/schema";
104
+
105
+ const admin = createAdmin({
106
+ db: (grants, user) => createDb({ d1: env.DB, schema, grants, user }),
107
+ auth: {
108
+ requireUser: async (request) => {
109
+ const session = await getSession(request);
110
+ return { user: session.user, grants: session.grants };
111
+ },
112
+ hasRole: (user, role) => user.roles.includes(role),
113
+ getRoles: (userId) => authInstance.getRoles(userId),
114
+ setRole: (userId, role) => authInstance.setRole(userId, role),
115
+ removeRole: (userId, role) => authInstance.removeRole(userId, role),
116
+ setRoles: (userId, roles) => authInstance.setRoles(userId, roles),
117
+ },
118
+ schema,
119
+ });
120
+
121
+ export const loader = admin.loader;
122
+ export const action = admin.action;
123
+ export default admin.Component;
124
+ ```
125
+
126
+ ### With table overrides and dashboard
127
+
128
+ ```typescript
129
+ const admin = createAdmin({
130
+ db, auth, schema,
131
+ tables: {
132
+ posts: {
133
+ label: "Blog Posts",
134
+ listColumns: ["title", "author", "published", "createdAt"],
135
+ searchable: ["title", "content"],
136
+ defaultSort: { column: "createdAt", direction: "desc" },
137
+ fields: { content: { component: RichTextEditor } },
138
+ actions: {
139
+ row: [{ label: "Publish", action: async (id, formData) => { /* ... */ } }],
140
+ },
141
+ },
142
+ },
143
+ users: { assignableRoles: ["user", "editor", "moderator", "admin"] },
144
+ dashboard: {
145
+ widgets: [
146
+ { type: "count", table: "users", label: "Total Users" },
147
+ { type: "recent", table: "posts", label: "Recent Posts", limit: 5 },
148
+ ],
149
+ },
150
+ });
151
+ ```
152
+
153
+ ## Integration
154
+
155
+ - **@cfast/ui** -- All rendering. Admin generates config, UI renders pixels (`ListView`, `DetailView`, `DataTable`, `AppShell`, `RoleBadge`, `AvatarWithInitials`).
156
+ - **@cfast/db** -- All data access via permission-checked Operations.
157
+ - **@cfast/auth** -- User management, role assignment, impersonation (via auth adapter callbacks).
158
+ - **@cfast/forms** -- Create/edit forms via `AutoForm`.
159
+ - **@cfast/permissions** -- Permission grants flow through to `@cfast/db` operations.
160
+ - **@cfast/pagination** -- List views paginate via pagination hooks.
161
+
162
+ ## Common Mistakes
163
+
164
+ - Forgetting to provide `requireUser` that returns `grants` -- the admin needs grants to create a permission-scoped DB instance.
165
+ - Not providing `impersonate`/`stopImpersonation` callbacks and expecting impersonation to work -- these are optional but required for that feature.
166
+ - Trying to customize rendering by passing JSX to `createAdmin` -- instead, override fields via `TableOverrides.fields` (for forms) or use `@cfast/ui` components directly in custom routes.
167
+ - Expecting auth-internal tables (`session`, `account`, `verification`, `passkey`) to show up -- they are auto-excluded. Set `exclude: false` in table overrides to show them.
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@cfast/admin",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Auto-generated admin UI from your Drizzle schema with role management and impersonation",
5
+ "keywords": [
6
+ "cfast",
7
+ "cloudflare-workers",
8
+ "admin",
9
+ "drizzle",
10
+ "auto-generated"
11
+ ],
5
12
  "license": "MIT",
6
13
  "repository": {
7
14
  "type": "git",
@@ -18,12 +25,20 @@
18
25
  }
19
26
  },
20
27
  "files": [
21
- "dist"
28
+ "dist",
29
+ "llms.txt"
22
30
  ],
23
31
  "sideEffects": false,
24
32
  "publishConfig": {
25
33
  "access": "public"
26
34
  },
35
+ "scripts": {
36
+ "build": "tsup src/index.ts --format esm --dts",
37
+ "dev": "tsup src/index.ts --format esm --dts --watch",
38
+ "typecheck": "tsc --noEmit",
39
+ "lint": "eslint src/",
40
+ "test": "vitest run"
41
+ },
27
42
  "peerDependencies": {
28
43
  "@mui/joy": ">=5.0.0-beta.0",
29
44
  "react": ">=19",
@@ -37,10 +52,11 @@
37
52
  }
38
53
  },
39
54
  "dependencies": {
40
- "@cfast/db": "0.0.1",
41
- "@cfast/forms": "0.0.1",
42
- "@cfast/ui": "0.0.1",
43
- "@cfast/permissions": "0.0.1"
55
+ "@cfast/db": "workspace:*",
56
+ "@cfast/forms": "workspace:*",
57
+ "@cfast/permissions": "workspace:*",
58
+ "@cfast/joy": "workspace:*",
59
+ "@cfast/ui": "workspace:*"
44
60
  },
45
61
  "devDependencies": {
46
62
  "@emotion/react": "^11.14.0",
@@ -55,12 +71,5 @@
55
71
  "tsup": "^8",
56
72
  "typescript": "^5.7",
57
73
  "vitest": "^4.1.0"
58
- },
59
- "scripts": {
60
- "build": "tsup src/index.ts --format esm --dts",
61
- "dev": "tsup src/index.ts --format esm --dts --watch",
62
- "typecheck": "tsc --noEmit",
63
- "lint": "eslint src/",
64
- "test": "vitest run"
65
74
  }
66
- }
75
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Daniel Schmidt
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.