create-lego-one 2.0.12 → 2.0.14

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.
Files changed (78) hide show
  1. package/dist/index.cjs +150 -15
  2. package/dist/index.cjs.map +1 -1
  3. package/package.json +1 -1
  4. package/template/.cursor/rules/rules.mdc +639 -0
  5. package/template/.dockerignore +58 -0
  6. package/template/.env.example +18 -0
  7. package/template/.eslintignore +5 -0
  8. package/template/.eslintrc.js +28 -0
  9. package/template/.prettierignore +6 -0
  10. package/template/.prettierrc +11 -0
  11. package/template/CLAUDE.md +634 -0
  12. package/template/Dockerfile +67 -0
  13. package/template/PROMPT.md +457 -0
  14. package/template/README.md +325 -0
  15. package/template/docker-compose.yml +48 -0
  16. package/template/docker-entrypoint.sh +23 -0
  17. package/template/docs/checkpoints/.template.md +64 -0
  18. package/template/docs/checkpoints/framework/01-infrastructure-setup.md +132 -0
  19. package/template/docs/checkpoints/framework/02-pocketbase-setup.md +155 -0
  20. package/template/docs/checkpoints/framework/03-host-kernel.md +170 -0
  21. package/template/docs/checkpoints/framework/04-auth-system.md +163 -0
  22. package/template/docs/checkpoints/framework/phase-05-multitenancy-rbac.md +223 -0
  23. package/template/docs/checkpoints/framework/phase-06-ui-components.md +260 -0
  24. package/template/docs/checkpoints/framework/phase-07-communication-system.md +276 -0
  25. package/template/docs/checkpoints/framework/phase-08-plugin-system.md +91 -0
  26. package/template/docs/checkpoints/framework/phase-09-dashboard-plugin.md +111 -0
  27. package/template/docs/checkpoints/framework/phase-10-todo-plugin.md +169 -0
  28. package/template/docs/checkpoints/framework/phase-11-testing.md +264 -0
  29. package/template/docs/checkpoints/framework/phase-12-deployment.md +294 -0
  30. package/template/docs/checkpoints/framework/phase-13-documentation.md +312 -0
  31. package/template/docs/framework/plans/00-index.md +164 -0
  32. package/template/docs/framework/plans/01-infrastructure-setup.md +855 -0
  33. package/template/docs/framework/plans/02-pocketbase-setup.md +1374 -0
  34. package/template/docs/framework/plans/03-host-kernel.md +1518 -0
  35. package/template/docs/framework/plans/04-auth-system.md +1466 -0
  36. package/template/docs/framework/plans/05-multitenancy-rbac.md +1527 -0
  37. package/template/docs/framework/plans/06-ui-components.md +1478 -0
  38. package/template/docs/framework/plans/07-communication-system.md +1106 -0
  39. package/template/docs/framework/plans/08-plugin-system.md +1179 -0
  40. package/template/docs/framework/plans/09-dashboard-plugin.md +1137 -0
  41. package/template/docs/framework/plans/10-todo-plugin.md +1343 -0
  42. package/template/docs/framework/plans/11-testing.md +935 -0
  43. package/template/docs/framework/plans/12-deployment.md +896 -0
  44. package/template/docs/framework/prompts/0-boilerplate-modernjs.md +151 -0
  45. package/template/docs/framework/research/00-modernjs-audit.md +488 -0
  46. package/template/docs/framework/research/01-system-blueprint.md +721 -0
  47. package/template/docs/framework/research/02-data-migration-protocol.md +699 -0
  48. package/template/docs/framework/research/03-host-setup.md +714 -0
  49. package/template/docs/framework/research/04-plugin-architecture.md +645 -0
  50. package/template/docs/framework/research/05-slot-injection-pattern.md +671 -0
  51. package/template/docs/framework/research/06-cli-strategy.md +615 -0
  52. package/template/docs/framework/research/07-deployment.md +629 -0
  53. package/template/docs/framework/research/README.md +282 -0
  54. package/template/docs/framework/setup/00-index.md +210 -0
  55. package/template/docs/framework/setup/01-framework-structure.md +308 -0
  56. package/template/docs/framework/setup/02-development-workflow.md +405 -0
  57. package/template/docs/framework/setup/03-environment-setup.md +215 -0
  58. package/template/docs/framework/setup/04-kernel-architecture.md +499 -0
  59. package/template/docs/framework/setup/05-plugin-system.md +620 -0
  60. package/template/docs/framework/setup/06-communication-patterns.md +451 -0
  61. package/template/docs/framework/setup/07-plugin-development.md +582 -0
  62. package/template/docs/framework/setup/08-component-library.md +658 -0
  63. package/template/docs/framework/setup/09-data-integration.md +609 -0
  64. package/template/docs/framework/setup/10-auth-rbac.md +497 -0
  65. package/template/docs/framework/setup/11-hooks-api.md +393 -0
  66. package/template/docs/framework/setup/12-components-api.md +665 -0
  67. package/template/docs/framework/setup/13-deployment-guide.md +566 -0
  68. package/template/docs/framework/setup/README.md +548 -0
  69. package/template/host/package.json +1 -1
  70. package/template/nginx.conf +72 -0
  71. package/template/package.json +1 -1
  72. package/template/packages/plugins/@lego/plugin-dashboard/package.json +1 -1
  73. package/template/packages/plugins/@lego/plugin-todo/package.json +1 -1
  74. package/template/pocketbase/CHANGELOG.md +911 -0
  75. package/template/pocketbase/LICENSE.md +17 -0
  76. package/template/scripts/create-plugin.js +221 -0
  77. package/template/scripts/deploy.sh +56 -0
  78. package/template/tsconfig.base.json +26 -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.