@logickernel/bridge 0.5.0 → 0.6.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 +199 -1
- package/dist/next/components.cjs +1348 -0
- package/dist/next/components.cjs.map +1 -0
- package/dist/next/components.d.cts +104 -0
- package/dist/next/components.d.ts +104 -0
- package/dist/next/components.js +1313 -0
- package/dist/next/components.js.map +1 -0
- package/dist/next/index.cjs +1341 -0
- package/dist/next/index.cjs.map +1 -1
- package/dist/next/index.d.cts +4 -0
- package/dist/next/index.d.ts +4 -0
- package/dist/next/index.js +1308 -1
- package/dist/next/index.js.map +1 -1
- package/package.json +42 -3
package/README.md
CHANGED
|
@@ -180,6 +180,168 @@ export const middlewareConfig = {
|
|
|
180
180
|
}
|
|
181
181
|
```
|
|
182
182
|
|
|
183
|
+
#### Layout Components
|
|
184
|
+
|
|
185
|
+
The bridge library provides ready-to-use layout components with built-in navigation connected to the Core of the Kernel.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
// app/app/layout.tsx (or your app layout)
|
|
189
|
+
"use client"
|
|
190
|
+
|
|
191
|
+
import { AppLayout, type User } from "@logickernel/bridge/next/components"
|
|
192
|
+
import { useSession } from "next-auth/react"
|
|
193
|
+
|
|
194
|
+
export default function Layout({ children }: { children: React.ReactNode }) {
|
|
195
|
+
const { data: session } = useSession()
|
|
196
|
+
|
|
197
|
+
if (!session?.user) {
|
|
198
|
+
return <>{children}</>
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const user: User = {
|
|
202
|
+
name: session.user.name || null,
|
|
203
|
+
email: session.user.email || "",
|
|
204
|
+
image: session.user.image || null,
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<AppLayout
|
|
209
|
+
user={user}
|
|
210
|
+
organizationId={organizationId} // Optional: Current organization ID
|
|
211
|
+
apiBaseUrl={apiBaseUrl} // Optional: API base URL for navigation
|
|
212
|
+
>
|
|
213
|
+
{children}
|
|
214
|
+
</AppLayout>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**For Server Components:**
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// app/app/layout.tsx
|
|
223
|
+
import { AppLayout, type User } from "@logickernel/bridge/next/components"
|
|
224
|
+
import { redirect } from "next/navigation"
|
|
225
|
+
import { auth } from "@/lib/next-auth" // or your NextAuth setup
|
|
226
|
+
|
|
227
|
+
export default async function Layout({
|
|
228
|
+
children,
|
|
229
|
+
params,
|
|
230
|
+
}: {
|
|
231
|
+
children: React.ReactNode
|
|
232
|
+
params: Promise<{ organization_id?: string }>
|
|
233
|
+
}) {
|
|
234
|
+
const session = await auth()
|
|
235
|
+
|
|
236
|
+
if (!session?.user) {
|
|
237
|
+
redirect("/auth/signin")
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const { organization_id } = await params
|
|
241
|
+
|
|
242
|
+
const user: User = {
|
|
243
|
+
name: session.user.name || null,
|
|
244
|
+
email: session.user.email || "",
|
|
245
|
+
image: session.user.image || null,
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return (
|
|
249
|
+
<AppLayout
|
|
250
|
+
user={user}
|
|
251
|
+
organizationId={organization_id}
|
|
252
|
+
apiBaseUrl={process.env.AUTH_URL}
|
|
253
|
+
>
|
|
254
|
+
{children}
|
|
255
|
+
</AppLayout>
|
|
256
|
+
)
|
|
257
|
+
}
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Note:** You can also use `getSession()` from `@logickernel/bridge/next` instead of NextAuth's `auth()` function. Both will work, but NextAuth's `auth()` is recommended if you're using NextAuth v5.
|
|
261
|
+
|
|
262
|
+
**Features:**
|
|
263
|
+
- ✅ Built-in sidebar navigation with organization switcher
|
|
264
|
+
- ✅ User menu with sign-out
|
|
265
|
+
- ✅ Responsive design (mobile/desktop)
|
|
266
|
+
- ✅ Automatic navigation loading from your API
|
|
267
|
+
- ✅ No component passing required - UI components are included in the library
|
|
268
|
+
- ✅ Consistent UI across all microfrontends using the bridge
|
|
269
|
+
|
|
270
|
+
The `AppLayout` component automatically:
|
|
271
|
+
- Loads navigation items from `/api/navigation/[organization_id]` endpoint
|
|
272
|
+
- Displays organizations the user belongs to
|
|
273
|
+
- Handles organization switching
|
|
274
|
+
- Provides user profile menu with sign-out
|
|
275
|
+
|
|
276
|
+
**Required API Endpoint:**
|
|
277
|
+
|
|
278
|
+
The navigation requires an endpoint at `/api/navigation/[organization_id]` that returns:
|
|
279
|
+
```typescript
|
|
280
|
+
{
|
|
281
|
+
items: NavigationItem[],
|
|
282
|
+
organizations: NavigationOrganization[]
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
**Type Definitions:**
|
|
287
|
+
```typescript
|
|
288
|
+
interface NavigationItem {
|
|
289
|
+
title: string
|
|
290
|
+
url?: string // If missing, item is treated as a section label
|
|
291
|
+
icon?: string // Icon name (mapped using getIconComponent)
|
|
292
|
+
isActive?: boolean // Whether the item should be highlighted
|
|
293
|
+
items?: { // Sub-items for collapsible navigation
|
|
294
|
+
title: string
|
|
295
|
+
url: string
|
|
296
|
+
}[]
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
interface NavigationOrganization {
|
|
300
|
+
id: string
|
|
301
|
+
name: string
|
|
302
|
+
logo?: string // Icon name for the organization logo
|
|
303
|
+
plan?: string // Optional plan/badge text
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**Example Response:**
|
|
308
|
+
```json
|
|
309
|
+
{
|
|
310
|
+
"items": [
|
|
311
|
+
{
|
|
312
|
+
"title": "Dashboard",
|
|
313
|
+
"url": "/app/{organizationId}/home",
|
|
314
|
+
"icon": "LayoutDashboard"
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
"title": "Team",
|
|
318
|
+
"icon": "Users" // Section label (no URL)
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
"title": "Members",
|
|
322
|
+
"url": "/app/{organizationId}/members",
|
|
323
|
+
"icon": "User",
|
|
324
|
+
"items": [
|
|
325
|
+
{
|
|
326
|
+
"title": "All Members",
|
|
327
|
+
"url": "/app/{organizationId}/members"
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
"organizations": [
|
|
333
|
+
{
|
|
334
|
+
"id": "org-123",
|
|
335
|
+
"name": "Acme Corp",
|
|
336
|
+
"logo": "Building",
|
|
337
|
+
"plan": "Pro"
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**Note:** The `{organizationId}` placeholder in URLs will be automatically replaced with the current organization ID. The endpoint should be protected and only return data the current user has access to.
|
|
344
|
+
|
|
183
345
|
## API Reference
|
|
184
346
|
|
|
185
347
|
### Core Exports (`@logickernel/bridge`)
|
|
@@ -210,6 +372,28 @@ export const middlewareConfig = {
|
|
|
210
372
|
| `hasRequiredRole(orgId, roles)` | Check if user has required roles (user ID determined from session token) |
|
|
211
373
|
| `createProxyHandler(options)` | Create a middleware/proxy handler |
|
|
212
374
|
|
|
375
|
+
### Layout Components (`@logickernel/bridge/next/components`)
|
|
376
|
+
|
|
377
|
+
| Export | Description |
|
|
378
|
+
|--------|-------------|
|
|
379
|
+
| `AppLayout` | Main layout component with sidebar navigation |
|
|
380
|
+
| `AppSidebar` | Sidebar component (used internally by AppLayout) |
|
|
381
|
+
| `NavMain` | Main navigation component (used internally) |
|
|
382
|
+
| `NavUser` | User menu component (used internally) |
|
|
383
|
+
| `TeamSwitcher` | Organization switcher component (used internally) |
|
|
384
|
+
| `useNavigation` | Hook to fetch navigation items from API |
|
|
385
|
+
| `getIconComponent` | Utility to get icon component from icon name |
|
|
386
|
+
|
|
387
|
+
**AppLayout Props:**
|
|
388
|
+
```typescript
|
|
389
|
+
interface AppLayoutProps {
|
|
390
|
+
user: User // User information (name, email, image)
|
|
391
|
+
organizationId?: string // Optional: Current organization ID
|
|
392
|
+
apiBaseUrl?: string // Optional: API base URL for navigation
|
|
393
|
+
children: React.ReactNode // Page content
|
|
394
|
+
}
|
|
395
|
+
```
|
|
396
|
+
|
|
213
397
|
### Types
|
|
214
398
|
|
|
215
399
|
```typescript
|
|
@@ -231,6 +415,12 @@ import type {
|
|
|
231
415
|
PageAuthOptions,
|
|
232
416
|
PageAuthResult,
|
|
233
417
|
} from "@logickernel/bridge/next"
|
|
418
|
+
|
|
419
|
+
import type {
|
|
420
|
+
User,
|
|
421
|
+
NavigationItem,
|
|
422
|
+
NavigationOrganization,
|
|
423
|
+
} from "@logickernel/bridge/next/components"
|
|
234
424
|
```
|
|
235
425
|
|
|
236
426
|
## Architecture
|
|
@@ -249,7 +439,15 @@ bridge/
|
|
|
249
439
|
│ ├── session.ts # Session utilities
|
|
250
440
|
│ ├── api.ts # API route utilities
|
|
251
441
|
│ ├── page.ts # Page utilities
|
|
252
|
-
│
|
|
442
|
+
│ ├── proxy.ts # Middleware/proxy utilities
|
|
443
|
+
│ └── components/
|
|
444
|
+
│ ├── app-layout.tsx # Main layout component
|
|
445
|
+
│ ├── app-sidebar.tsx # Sidebar component
|
|
446
|
+
│ ├── nav-main.tsx # Navigation component
|
|
447
|
+
│ ├── nav-user.tsx # User menu component
|
|
448
|
+
│ ├── team-switcher.tsx # Organization switcher
|
|
449
|
+
│ ├── use-navigation.ts # Navigation hook
|
|
450
|
+
│ └── ui/ # Internal UI components (shadcn)
|
|
253
451
|
```
|
|
254
452
|
|
|
255
453
|
## Development
|