create-lego-one 2.0.10 → 2.0.13
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/dist/index.cjs +179 -0
- package/dist/index.cjs.map +1 -1
- package/package.json +5 -3
- package/template/.cursor/rules/rules.mdc +639 -0
- package/template/.dockerignore +58 -0
- package/template/.env.example +18 -0
- package/template/.eslintignore +5 -0
- package/template/.eslintrc.js +28 -0
- package/template/.prettierignore +6 -0
- package/template/.prettierrc +11 -0
- package/template/CLAUDE.md +634 -0
- package/template/Dockerfile +67 -0
- package/template/PROMPT.md +457 -0
- package/template/README.md +325 -0
- package/template/docker-compose.yml +48 -0
- package/template/docker-entrypoint.sh +23 -0
- package/template/docs/checkpoints/.template.md +64 -0
- package/template/docs/checkpoints/framework/01-infrastructure-setup.md +132 -0
- package/template/docs/checkpoints/framework/02-pocketbase-setup.md +155 -0
- package/template/docs/checkpoints/framework/03-host-kernel.md +170 -0
- package/template/docs/checkpoints/framework/04-auth-system.md +163 -0
- package/template/docs/checkpoints/framework/phase-05-multitenancy-rbac.md +223 -0
- package/template/docs/checkpoints/framework/phase-06-ui-components.md +260 -0
- package/template/docs/checkpoints/framework/phase-07-communication-system.md +276 -0
- package/template/docs/checkpoints/framework/phase-08-plugin-system.md +91 -0
- package/template/docs/checkpoints/framework/phase-09-dashboard-plugin.md +111 -0
- package/template/docs/checkpoints/framework/phase-10-todo-plugin.md +169 -0
- package/template/docs/checkpoints/framework/phase-11-testing.md +264 -0
- package/template/docs/checkpoints/framework/phase-12-deployment.md +294 -0
- package/template/docs/checkpoints/framework/phase-13-documentation.md +312 -0
- package/template/docs/framework/plans/00-index.md +164 -0
- package/template/docs/framework/plans/01-infrastructure-setup.md +855 -0
- package/template/docs/framework/plans/02-pocketbase-setup.md +1374 -0
- package/template/docs/framework/plans/03-host-kernel.md +1518 -0
- package/template/docs/framework/plans/04-auth-system.md +1466 -0
- package/template/docs/framework/plans/05-multitenancy-rbac.md +1527 -0
- package/template/docs/framework/plans/06-ui-components.md +1478 -0
- package/template/docs/framework/plans/07-communication-system.md +1106 -0
- package/template/docs/framework/plans/08-plugin-system.md +1179 -0
- package/template/docs/framework/plans/09-dashboard-plugin.md +1137 -0
- package/template/docs/framework/plans/10-todo-plugin.md +1343 -0
- package/template/docs/framework/plans/11-testing.md +935 -0
- package/template/docs/framework/plans/12-deployment.md +896 -0
- package/template/docs/framework/prompts/0-boilerplate-modernjs.md +151 -0
- package/template/docs/framework/research/00-modernjs-audit.md +488 -0
- package/template/docs/framework/research/01-system-blueprint.md +721 -0
- package/template/docs/framework/research/02-data-migration-protocol.md +699 -0
- package/template/docs/framework/research/03-host-setup.md +714 -0
- package/template/docs/framework/research/04-plugin-architecture.md +645 -0
- package/template/docs/framework/research/05-slot-injection-pattern.md +671 -0
- package/template/docs/framework/research/06-cli-strategy.md +615 -0
- package/template/docs/framework/research/07-deployment.md +629 -0
- package/template/docs/framework/research/README.md +282 -0
- package/template/docs/framework/setup/00-index.md +210 -0
- package/template/docs/framework/setup/01-framework-structure.md +308 -0
- package/template/docs/framework/setup/02-development-workflow.md +405 -0
- package/template/docs/framework/setup/03-environment-setup.md +215 -0
- package/template/docs/framework/setup/04-kernel-architecture.md +499 -0
- package/template/docs/framework/setup/05-plugin-system.md +620 -0
- package/template/docs/framework/setup/06-communication-patterns.md +451 -0
- package/template/docs/framework/setup/07-plugin-development.md +582 -0
- package/template/docs/framework/setup/08-component-library.md +658 -0
- package/template/docs/framework/setup/09-data-integration.md +609 -0
- package/template/docs/framework/setup/10-auth-rbac.md +497 -0
- package/template/docs/framework/setup/11-hooks-api.md +393 -0
- package/template/docs/framework/setup/12-components-api.md +665 -0
- package/template/docs/framework/setup/13-deployment-guide.md +566 -0
- package/template/docs/framework/setup/README.md +548 -0
- package/template/host/e2e/auth.spec.ts +38 -0
- package/template/host/e2e/layout.spec.ts +38 -0
- package/template/host/modern.config.ts +19 -0
- package/template/host/package.json +71 -0
- package/template/host/playwright.config.ts +34 -0
- package/template/host/postcss.config.mjs +6 -0
- package/template/host/src/App.tsx +6 -0
- package/template/host/src/bootstrap.tsx +74 -0
- package/template/host/src/global.css +59 -0
- package/template/host/src/index.ts +2 -0
- package/template/host/src/kernel/__tests__/lib-utils.test.ts +32 -0
- package/template/host/src/kernel/__tests__/rbac-hooks.test.tsx +114 -0
- package/template/host/src/kernel/__tests__/rbac-utils.test.ts +108 -0
- package/template/host/src/kernel/auth/ProtectedRoute.tsx +41 -0
- package/template/host/src/kernel/auth/components/LoginForm.tsx +97 -0
- package/template/host/src/kernel/auth/components/LogoutButton.tsx +79 -0
- package/template/host/src/kernel/auth/hooks.ts +174 -0
- package/template/host/src/kernel/auth/index.ts +5 -0
- package/template/host/src/kernel/auth/schemas.ts +27 -0
- package/template/host/src/kernel/auth/service.ts +197 -0
- package/template/host/src/kernel/auth/types.ts +36 -0
- package/template/host/src/kernel/channels/ChannelBus.ts +181 -0
- package/template/host/src/kernel/channels/ChannelProvider.tsx +57 -0
- package/template/host/src/kernel/channels/events.ts +27 -0
- package/template/host/src/kernel/channels/hooks.ts +168 -0
- package/template/host/src/kernel/channels/index.ts +6 -0
- package/template/host/src/kernel/channels/integrations/ToastIntegration.tsx +60 -0
- package/template/host/src/kernel/channels/plugin-hooks.ts +72 -0
- package/template/host/src/kernel/channels/types.ts +112 -0
- package/template/host/src/kernel/components/__tests__/Badge.test.tsx +35 -0
- package/template/host/src/kernel/components/__tests__/Button.test.tsx +63 -0
- package/template/host/src/kernel/components/__tests__/Input.test.tsx +64 -0
- package/template/host/src/kernel/components/index.ts +32 -0
- package/template/host/src/kernel/components/ui/alert.tsx +58 -0
- package/template/host/src/kernel/components/ui/avatar.tsx +47 -0
- package/template/host/src/kernel/components/ui/badge.tsx +35 -0
- package/template/host/src/kernel/components/ui/button.tsx +50 -0
- package/template/host/src/kernel/components/ui/card.tsx +78 -0
- package/template/host/src/kernel/components/ui/dialog.tsx +116 -0
- package/template/host/src/kernel/components/ui/dropdown-menu.tsx +192 -0
- package/template/host/src/kernel/components/ui/index.ts +7 -0
- package/template/host/src/kernel/components/ui/input.tsx +24 -0
- package/template/host/src/kernel/components/ui/label.tsx +21 -0
- package/template/host/src/kernel/components/ui/popover.tsx +28 -0
- package/template/host/src/kernel/components/ui/progress.tsx +25 -0
- package/template/host/src/kernel/components/ui/scroll-area.tsx +45 -0
- package/template/host/src/kernel/components/ui/select.tsx +155 -0
- package/template/host/src/kernel/components/ui/separator.tsx +28 -0
- package/template/host/src/kernel/components/ui/skeleton.tsx +15 -0
- package/template/host/src/kernel/components/ui/switch.tsx +26 -0
- package/template/host/src/kernel/components/ui/table.tsx +116 -0
- package/template/host/src/kernel/components/ui/tabs.tsx +52 -0
- package/template/host/src/kernel/components/ui/toast.tsx +126 -0
- package/template/host/src/kernel/components/ui/toaster.tsx +34 -0
- package/template/host/src/kernel/components/ui/tooltip.tsx +27 -0
- package/template/host/src/kernel/components/ui/use-toast.ts +183 -0
- package/template/host/src/kernel/index.ts +48 -0
- package/template/host/src/kernel/lib/cn.ts +1 -0
- package/template/host/src/kernel/lib/utils.ts +36 -0
- package/template/host/src/kernel/plugins/Slot.tsx +41 -0
- package/template/host/src/kernel/plugins/SlotProvider.tsx +88 -0
- package/template/host/src/kernel/plugins/index.ts +23 -0
- package/template/host/src/kernel/plugins/loader.ts +122 -0
- package/template/host/src/kernel/plugins/schemas.ts +54 -0
- package/template/host/src/kernel/plugins/store.ts +185 -0
- package/template/host/src/kernel/plugins/types.ts +103 -0
- package/template/host/src/kernel/providers/PocketBaseProvider.tsx +70 -0
- package/template/host/src/kernel/providers/QueryProvider.tsx +28 -0
- package/template/host/src/kernel/providers/ThemeProvider.tsx +25 -0
- package/template/host/src/kernel/providers/index.ts +3 -0
- package/template/host/src/kernel/rbac/components/OrganizationSelector.tsx +69 -0
- package/template/host/src/kernel/rbac/components/PermissionGate.tsx +43 -0
- package/template/host/src/kernel/rbac/hooks.ts +379 -0
- package/template/host/src/kernel/rbac/index.ts +6 -0
- package/template/host/src/kernel/rbac/service.ts +504 -0
- package/template/host/src/kernel/rbac/types.ts +164 -0
- package/template/host/src/kernel/rbac/utils.ts +34 -0
- package/template/host/src/kernel/shared-state/bridge.ts +31 -0
- package/template/host/src/kernel/shared-state/index.ts +3 -0
- package/template/host/src/kernel/shared-state/store.ts +62 -0
- package/template/host/src/kernel/shared-state/types.ts +60 -0
- package/template/host/src/kernel/use-migrations.ts +72 -0
- package/template/host/src/layout/MobileMenu.tsx +61 -0
- package/template/host/src/layout/Shell.tsx +42 -0
- package/template/host/src/layout/Sidebar.tsx +178 -0
- package/template/host/src/layout/Topbar.tsx +50 -0
- package/template/host/src/layout/index.ts +4 -0
- package/template/host/src/lib/pocketbase/client.ts +38 -0
- package/template/host/src/lib/pocketbase/collections/audit_logs.ts +87 -0
- package/template/host/src/lib/pocketbase/collections/index.ts +19 -0
- package/template/host/src/lib/pocketbase/collections/organizations.ts +63 -0
- package/template/host/src/lib/pocketbase/collections/permissions.ts +57 -0
- package/template/host/src/lib/pocketbase/collections/roles.ts +55 -0
- package/template/host/src/lib/pocketbase/collections/todos.ts +74 -0
- package/template/host/src/lib/pocketbase/collections/user_roles.ts +57 -0
- package/template/host/src/lib/pocketbase/collections/users.ts +43 -0
- package/template/host/src/lib/pocketbase/index.ts +5 -0
- package/template/host/src/lib/pocketbase/migrations.ts +44 -0
- package/template/host/src/lib/pocketbase/seed/permissions.ts +8 -0
- package/template/host/src/lib/pocketbase/seed/roles.ts +22 -0
- package/template/host/src/lib/pocketbase/seed.ts +113 -0
- package/template/host/src/lib/pocketbase/types.ts +102 -0
- package/template/host/src/modern.runtime.ts +26 -0
- package/template/host/src/plugins.d.ts +9 -0
- package/template/host/src/providers/PocketBaseProvider.tsx +30 -0
- package/template/host/src/routes/_.tsx +6 -0
- package/template/host/src/routes/dashboard._.tsx +41 -0
- package/template/host/src/routes/index.tsx +93 -0
- package/template/host/src/routes/login.tsx +36 -0
- package/template/host/src/saas.config.ts +52 -0
- package/template/host/src/test/setup.ts +65 -0
- package/template/host/src/test/utils.tsx +69 -0
- package/template/host/src/test/vitest-globals.d.ts +19 -0
- package/template/host/src/vite-env.d.ts +16 -0
- package/template/host/tailwind.config.ts +77 -0
- package/template/host/tsconfig.json +19 -0
- package/template/host/vitest.config.ts +30 -0
- package/template/nginx.conf +72 -0
- package/template/package.json +44 -0
- package/template/packages/plugins/@lego/plugin-dashboard/modern.config.ts +19 -0
- package/template/packages/plugins/@lego/plugin-dashboard/package.json +35 -0
- package/template/packages/plugins/@lego/plugin-dashboard/postcss.config.mjs +6 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/App.tsx +27 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/ActivityFeed.tsx +63 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/QuickActionSlot.tsx +11 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/QuickActions.tsx +68 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/SidebarWidget.tsx +35 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/components/StatCard.tsx +47 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/global.css +24 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/useChannelIntegration.ts +43 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/useDashboardStats.ts +65 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/usePocketBase.ts +47 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/hooks/useRecentActivity.ts +55 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/lib/utils.ts +6 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/pages/DashboardPage.tsx +105 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/plugin.config.ts +121 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/plugin.ts +18 -0
- package/template/packages/plugins/@lego/plugin-dashboard/src/vite-env.d.ts +32 -0
- package/template/packages/plugins/@lego/plugin-dashboard/tailwind.config.ts +35 -0
- package/template/packages/plugins/@lego/plugin-dashboard/tsconfig.json +18 -0
- package/template/packages/plugins/@lego/plugin-todo/modern.config.ts +18 -0
- package/template/packages/plugins/@lego/plugin-todo/package.json +41 -0
- package/template/packages/plugins/@lego/plugin-todo/postcss.config.mjs +6 -0
- package/template/packages/plugins/@lego/plugin-todo/src/App.tsx +12 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/SidebarWidget.tsx +16 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoDialog.tsx +55 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoFilters.tsx +79 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoForm.tsx +94 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoItem.tsx +121 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/TodoList.tsx +41 -0
- package/template/packages/plugins/@lego/plugin-todo/src/components/index.ts +6 -0
- package/template/packages/plugins/@lego/plugin-todo/src/global.css +59 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useCreateTodo.ts +62 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useDeleteTodo.ts +46 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/usePocketBase.ts +38 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useTodos.ts +64 -0
- package/template/packages/plugins/@lego/plugin-todo/src/hooks/useUpdateTodo.ts +35 -0
- package/template/packages/plugins/@lego/plugin-todo/src/index.tsx +5 -0
- package/template/packages/plugins/@lego/plugin-todo/src/lib/utils.ts +20 -0
- package/template/packages/plugins/@lego/plugin-todo/src/pages/TodoPage.tsx +89 -0
- package/template/packages/plugins/@lego/plugin-todo/src/plugin.config.ts +104 -0
- package/template/packages/plugins/@lego/plugin-todo/src/plugin.ts +13 -0
- package/template/packages/plugins/@lego/plugin-todo/src/schemas.ts +37 -0
- package/template/packages/plugins/@lego/plugin-todo/src/types.ts +42 -0
- package/template/packages/plugins/@lego/plugin-todo/src/vite-env.d.ts +31 -0
- package/template/packages/plugins/@lego/plugin-todo/tailwind.config.ts +51 -0
- package/template/packages/plugins/@lego/plugin-todo/tsconfig.json +18 -0
- package/template/pnpm-workspace.yaml +4 -0
- package/template/pocketbase/CHANGELOG.md +911 -0
- package/template/pocketbase/LICENSE.md +17 -0
- package/template/scripts/create-plugin.js +221 -0
- package/template/scripts/deploy.sh +56 -0
- package/template/tsconfig.base.json +26 -0
- package/template/tsconfig.json +8 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
# Hooks API Reference
|
|
2
|
+
|
|
3
|
+
**All Kernel Hooks and Their Usage**
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
The Lego-One Kernel provides hooks for authentication, authorization, state management, and plugin communication.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Authentication Hooks
|
|
14
|
+
|
|
15
|
+
### useAuth()
|
|
16
|
+
|
|
17
|
+
Get current authentication state and auth methods.
|
|
18
|
+
|
|
19
|
+
**Location:** `host/src/kernel/hooks/useAuth.ts`
|
|
20
|
+
|
|
21
|
+
**Returns:**
|
|
22
|
+
```typescript
|
|
23
|
+
{
|
|
24
|
+
user: User | null;
|
|
25
|
+
token: string | null;
|
|
26
|
+
isAuthenticated: boolean;
|
|
27
|
+
isLoading: boolean;
|
|
28
|
+
login: (email: string, password: string) => Promise<void>;
|
|
29
|
+
register: (data: RegisterData) => Promise<void>;
|
|
30
|
+
logout: () => void;
|
|
31
|
+
updateProfile: (data: UpdateProfileData) => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Example:**
|
|
36
|
+
```typescript
|
|
37
|
+
function MyComponent() {
|
|
38
|
+
const { user, isAuthenticated, logout } = useAuth();
|
|
39
|
+
|
|
40
|
+
if (!isAuthenticated) {
|
|
41
|
+
return <div>Please log in</div>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div>
|
|
46
|
+
Welcome, {user.name}
|
|
47
|
+
<button onClick={logout}>Logout</button>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### useRequireAuth()
|
|
54
|
+
|
|
55
|
+
Hook that redirects to login if not authenticated.
|
|
56
|
+
|
|
57
|
+
**Location:** `host/src/kernel/hooks/useRequireAuth.ts`
|
|
58
|
+
|
|
59
|
+
**Example:**
|
|
60
|
+
```typescript
|
|
61
|
+
function ProtectedPage() {
|
|
62
|
+
useRequireAuth();
|
|
63
|
+
// User is guaranteed to be authenticated here
|
|
64
|
+
return <div>Protected content</div>;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Authorization Hooks
|
|
71
|
+
|
|
72
|
+
### useCurrentOrganization()
|
|
73
|
+
|
|
74
|
+
Get and set the current organization context.
|
|
75
|
+
|
|
76
|
+
**Location:** `host/src/kernel/hooks/useCurrentOrganization.ts`
|
|
77
|
+
|
|
78
|
+
**Returns:**
|
|
79
|
+
```typescript
|
|
80
|
+
{
|
|
81
|
+
organization: Organization | null;
|
|
82
|
+
setCurrentOrganization: (org: Organization | null) => void;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**Example:**
|
|
87
|
+
```typescript
|
|
88
|
+
function OrgSelector() {
|
|
89
|
+
const { organization, setCurrentOrganization } = useCurrentOrganization();
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<select
|
|
93
|
+
value={organization?.id}
|
|
94
|
+
onChange={(e) => setCurrentOrganization(/* find org by id */)}
|
|
95
|
+
>
|
|
96
|
+
{/* Org options */}
|
|
97
|
+
</select>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### useHasPermission()
|
|
103
|
+
|
|
104
|
+
Check if current user has a specific permission.
|
|
105
|
+
|
|
106
|
+
**Location:** `host/src/kernel/hooks/useHasPermission.ts`
|
|
107
|
+
|
|
108
|
+
**Parameters:**
|
|
109
|
+
- `resource` - The resource type (e.g., 'users', 'organizations')
|
|
110
|
+
- `action` - The action type (e.g., 'read', 'write', 'delete')
|
|
111
|
+
|
|
112
|
+
**Returns:**
|
|
113
|
+
```typescript
|
|
114
|
+
(resource: ResourceType, action: ActionType) => Promise<boolean>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Example:**
|
|
118
|
+
```typescript
|
|
119
|
+
function DeleteButton({ userId }) {
|
|
120
|
+
const checkPermission = useHasPermission();
|
|
121
|
+
const [hasPermission, setHasPermission] = useState(false);
|
|
122
|
+
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
checkPermission('users', 'delete').then(setHasPermission);
|
|
125
|
+
}, [checkPermission]);
|
|
126
|
+
|
|
127
|
+
if (!hasPermission) return null;
|
|
128
|
+
|
|
129
|
+
return <button>Delete User</button>;
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### useRequirePermission()
|
|
134
|
+
|
|
135
|
+
Hook that checks permission and returns loading state.
|
|
136
|
+
|
|
137
|
+
**Location:** `host/src/kernel/hooks/useRequirePermission.ts`
|
|
138
|
+
|
|
139
|
+
**Parameters:**
|
|
140
|
+
- `resource` - The resource to check
|
|
141
|
+
- `action` - The action to check
|
|
142
|
+
|
|
143
|
+
**Returns:**
|
|
144
|
+
```typescript
|
|
145
|
+
{
|
|
146
|
+
hasPermission: boolean;
|
|
147
|
+
isLoading: boolean;
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Example:**
|
|
152
|
+
```typescript
|
|
153
|
+
function AdminPanel() {
|
|
154
|
+
const { hasPermission, isLoading } = useRequirePermission('users', 'write');
|
|
155
|
+
|
|
156
|
+
if (isLoading) return <div>Loading...</div>;
|
|
157
|
+
if (!hasPermission) return <div>Access denied</div>;
|
|
158
|
+
|
|
159
|
+
return <div>Admin content</div>;
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### useUserPermissions()
|
|
164
|
+
|
|
165
|
+
Get all permissions for the current user in current organization.
|
|
166
|
+
|
|
167
|
+
**Location:** `host/src/kernel/hooks/useUserPermissions.ts`
|
|
168
|
+
|
|
169
|
+
**Returns:**
|
|
170
|
+
```typescript
|
|
171
|
+
UseQueryResult<Permission[]>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### useOrganizations()
|
|
175
|
+
|
|
176
|
+
Get all organizations for the current user.
|
|
177
|
+
|
|
178
|
+
**Location:** `host/src/kernel/hooks/useOrganizations.ts`
|
|
179
|
+
|
|
180
|
+
**Returns:**
|
|
181
|
+
```typescript
|
|
182
|
+
UseQueryResult<Organization[]>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## State Management Hooks
|
|
188
|
+
|
|
189
|
+
### useGlobalKernelState()
|
|
190
|
+
|
|
191
|
+
Access the global kernel Zustand store.
|
|
192
|
+
|
|
193
|
+
**Location:** `host/src/kernel/shared-state/store.ts`
|
|
194
|
+
|
|
195
|
+
**Returns:**
|
|
196
|
+
```typescript
|
|
197
|
+
{
|
|
198
|
+
user: User | null;
|
|
199
|
+
organization: Organization | null;
|
|
200
|
+
token: string | null;
|
|
201
|
+
isAuthenticated: boolean;
|
|
202
|
+
setUser: (user: User | null) => void;
|
|
203
|
+
setOrganization: (org: Organization | null) => void;
|
|
204
|
+
setToken: (token: string | null) => void;
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Example:**
|
|
209
|
+
```typescript
|
|
210
|
+
function MyComponent() {
|
|
211
|
+
const { user, organization, isAuthenticated } = useGlobalKernelState();
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<div>
|
|
215
|
+
{isAuthenticated && (
|
|
216
|
+
<p>{user?.name} - {organization?.name}</p>
|
|
217
|
+
)}
|
|
218
|
+
</div>
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Data Hooks
|
|
226
|
+
|
|
227
|
+
### usePocketBase()
|
|
228
|
+
|
|
229
|
+
Get the PocketBase client instance.
|
|
230
|
+
|
|
231
|
+
**Location:** `host/src/kernel/providers/PocketBaseProvider.tsx` or `packages/plugins/@lego/plugin-*/src/hooks/usePocketBase.ts`
|
|
232
|
+
|
|
233
|
+
**Returns:**
|
|
234
|
+
```typescript
|
|
235
|
+
PocketBase | null
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
**Example:**
|
|
239
|
+
```typescript
|
|
240
|
+
function MyComponent() {
|
|
241
|
+
const pb = usePocketBase();
|
|
242
|
+
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
if (pb) {
|
|
245
|
+
// Use PocketBase client
|
|
246
|
+
pb.collection('todos').getList(1, 20);
|
|
247
|
+
}
|
|
248
|
+
}, [pb]);
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Channel Hooks
|
|
255
|
+
|
|
256
|
+
### useToastChannel()
|
|
257
|
+
|
|
258
|
+
Show toast notifications via the channel bus.
|
|
259
|
+
|
|
260
|
+
**Location:** `host/src/kernel/channels/useToastChannel.ts`
|
|
261
|
+
|
|
262
|
+
**Returns:**
|
|
263
|
+
```typescript
|
|
264
|
+
(data: ToastData) => void
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Example:**
|
|
268
|
+
```typescript
|
|
269
|
+
function MyForm() {
|
|
270
|
+
const showToast = useToastChannel();
|
|
271
|
+
|
|
272
|
+
const handleSubmit = async () => {
|
|
273
|
+
await saveData();
|
|
274
|
+
showToast({
|
|
275
|
+
type: 'success',
|
|
276
|
+
title: 'Saved!',
|
|
277
|
+
description: 'Your data has been saved',
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### useChannelBus()
|
|
284
|
+
|
|
285
|
+
Access the channel bus for custom events.
|
|
286
|
+
|
|
287
|
+
**Location:** `host/src/kernel/channels/` or plugin-level implementation
|
|
288
|
+
|
|
289
|
+
**Returns:**
|
|
290
|
+
```typescript
|
|
291
|
+
{
|
|
292
|
+
publish: (channel: string, message: any) => void;
|
|
293
|
+
subscribe: (channel: string, callback: (data: any) => void) => () => void;
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**Example:**
|
|
298
|
+
```typescript
|
|
299
|
+
function MyComponent() {
|
|
300
|
+
const { publish, subscribe } = useChannelBus();
|
|
301
|
+
|
|
302
|
+
useEffect(() => {
|
|
303
|
+
const unsubscribe = subscribe('custom:event', (data) => {
|
|
304
|
+
console.log('Received:', data);
|
|
305
|
+
});
|
|
306
|
+
return unsubscribe;
|
|
307
|
+
}, [subscribe]);
|
|
308
|
+
|
|
309
|
+
const handleClick = () => {
|
|
310
|
+
publish('custom:event', { message: 'Hello!' });
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Plugin Hooks (Window Bridge)
|
|
318
|
+
|
|
319
|
+
### Accessing Kernel State from Plugins
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
// In plugin component
|
|
323
|
+
function MyPluginComponent() {
|
|
324
|
+
const kernelState = window.__LEGO_KERNEL_STATE__;
|
|
325
|
+
|
|
326
|
+
return (
|
|
327
|
+
<div>
|
|
328
|
+
<p>User: {kernelState?.user?.email}</p>
|
|
329
|
+
<p>Org: {kernelState?.organization?.name}</p>
|
|
330
|
+
</div>
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### Subscribing to Events from Plugins
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
// In plugin component
|
|
339
|
+
useEffect(() => {
|
|
340
|
+
const channelBus = window.__LEGO_CHANNEL_BUS__;
|
|
341
|
+
if (!channelBus) return;
|
|
342
|
+
|
|
343
|
+
const unsubscribe = channelBus.subscribe('lego:auth', (data) => {
|
|
344
|
+
console.log('Auth changed:', data);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
return unsubscribe;
|
|
348
|
+
}, []);
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Hook Parameters and Types
|
|
354
|
+
|
|
355
|
+
### User Type
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
interface User {
|
|
359
|
+
id: string;
|
|
360
|
+
email: string;
|
|
361
|
+
name?: string;
|
|
362
|
+
avatar?: string;
|
|
363
|
+
created: string;
|
|
364
|
+
updated: string;
|
|
365
|
+
}
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Organization Type
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
interface Organization {
|
|
372
|
+
id: string;
|
|
373
|
+
name: string;
|
|
374
|
+
slug: string;
|
|
375
|
+
created: string;
|
|
376
|
+
updated: string;
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
### Permission Type
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
interface Permission {
|
|
384
|
+
id: string;
|
|
385
|
+
resource: string;
|
|
386
|
+
action: string;
|
|
387
|
+
roleId: string;
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
**Next:** Read [`12-components-api.md`](./12-components-api.md) for UI component reference.
|