@logickernel/bridge 0.8.2 → 0.8.3

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
@@ -6,17 +6,13 @@ Framework-agnostic micro-frontend authentication library for AuthJS/NextAuth JWT
6
6
 
7
7
  ```bash
8
8
  npm install @logickernel/bridge
9
- # or
10
- pnpm add @logickernel/bridge
11
- # or
12
- yarn add @logickernel/bridge
13
9
  ```
14
10
 
15
11
  ## Quick Start (Next.js)
16
12
 
17
13
  ### 1. Environment Variables
18
14
 
19
- Add these to your `.env` file:
15
+ Add these to the `.env` file of your application:
20
16
 
21
17
  ```bash
22
18
  AUTH_SECRET=your-nextauth-secret # Required: Same secret used by your kernel/auth server
@@ -39,16 +35,56 @@ const nextConfig: NextConfig = {
39
35
  export default nextConfig
40
36
  ```
41
37
 
38
+ **Why `transpilePackages`?** This tells Next.js to transpile the bridge library's TypeScript/ES modules during the build process. This is necessary because the library uses modern JavaScript features and needs to be processed by Next.js's bundler (Turbopack or webpack) to work correctly with your application.
39
+
42
40
  ### 3. Use the Layout Component
43
41
 
44
- The library provides a ready-to-use layout component with sidebar navigation. Import `AppLayoutWrapper` directly from the library:
42
+ The library provides a ready-to-use layout component with sidebar navigation. You need a thin wrapper component in your app to establish the client/server boundary.
43
+
44
+ **Step 1: Create a wrapper component**
45
+
46
+ Create `src/components/app-layout-wrapper.tsx`:
47
+
48
+ ```typescript
49
+ "use client"
50
+
51
+ /**
52
+ * Client boundary wrapper for AppLayout.
53
+ *
54
+ * This wrapper is required because "use client" directives are not preserved
55
+ * in bundled library code. Next.js needs this directive in your source code
56
+ * to properly handle the client/server boundary.
57
+ */
58
+ import { AppLayout } from "@logickernel/bridge/next-components"
59
+
60
+ export function AppLayoutWrapper({
61
+ children,
62
+ organizationId,
63
+ apiBaseUrl,
64
+ }: {
65
+ children: React.ReactNode
66
+ organizationId?: string
67
+ apiBaseUrl?: string
68
+ }) {
69
+ return (
70
+ <AppLayout
71
+ organizationId={organizationId}
72
+ apiBaseUrl={apiBaseUrl}
73
+ >
74
+ {children}
75
+ </AppLayout>
76
+ )
77
+ }
78
+ ```
79
+
80
+ **Step 2: Use in your layout**
45
81
 
46
82
  In your `app/app/layout.tsx` (or wherever your app layout is):
47
83
 
48
84
  ```typescript
49
85
  import { redirect } from "next/navigation"
50
86
  import { auth } from "@/lib/next-auth" // or your auth setup
51
- import { AppLayoutWrapper } from "@logickernel/bridge/next-components"
87
+ import { AppLayoutWrapper } from "@/components/app-layout-wrapper"
52
88
 
53
89
  export default async function Layout({
54
90
  children,
@@ -69,17 +105,6 @@ export default async function Layout({
69
105
  }
70
106
  ```
71
107
 
72
- **Optional: Pass organization ID and API base URL**
73
-
74
- ```typescript
75
- <AppLayoutWrapper
76
- organizationId={organizationId}
77
- apiBaseUrl={apiBaseUrl}
78
- >
79
- {children}
80
- </AppLayoutWrapper>
81
- ```
82
-
83
108
  The `user` prop is **not needed** - the layout automatically fetches user information from the navigation API endpoint.
84
109
 
85
110
  ### 4. Navigation API Endpoint
@@ -285,8 +310,7 @@ import { AppLayout, type User } from "@logickernel/bridge/next-components"
285
310
 
286
311
  | Export | Description |
287
312
  |--------|-------------|
288
- | `AppLayout` | Main layout component with sidebar navigation (use `AppLayoutWrapper` in server components) |
289
- | `AppLayoutWrapper` | Wrapper component for use in server components (recommended) |
313
+ | `AppLayout` | Main layout component with sidebar navigation (wrap in a local component with `"use client"` for server components) |
290
314
  | `useNavigation` | Hook to fetch navigation items from API |
291
315
  | `getIconComponent` | Utility to get icon component from icon name |
292
316
 
@@ -301,16 +325,6 @@ interface AppLayoutProps {
301
325
  }
302
326
  ```
303
327
 
304
- ## Why AppLayoutWrapper?
305
-
306
- The library provides `AppLayoutWrapper` as a convenience wrapper for `AppLayout` because:
307
-
308
- 1. **React Context Requirement**: `AppLayout` uses React Context internally (for sidebar state)
309
- 2. **SSR Build Compatibility**: Next.js requires a clean client/server boundary when client components with Context are used in server components
310
- 3. **Simplified Usage**: Using `AppLayoutWrapper` directly avoids React resolution issues during build-time analysis
311
-
312
- You can use `AppLayoutWrapper` directly in server components without creating your own wrapper.
313
-
314
328
  ## TypeScript Types
315
329
 
316
330
  ```typescript
@@ -1335,23 +1335,8 @@ function AppLayout({
1335
1335
  ] })
1336
1336
  ] });
1337
1337
  }
1338
- function AppLayoutWrapper({
1339
- organizationId,
1340
- apiBaseUrl,
1341
- children
1342
- }) {
1343
- return /* @__PURE__ */ jsxRuntime.jsx(
1344
- AppLayout,
1345
- {
1346
- organizationId,
1347
- apiBaseUrl,
1348
- children
1349
- }
1350
- );
1351
- }
1352
1338
 
1353
1339
  exports.AppLayout = AppLayout;
1354
- exports.AppLayoutWrapper = AppLayoutWrapper;
1355
1340
  exports.AppSidebar = AppSidebar;
1356
1341
  exports.NavMain = NavMain;
1357
1342
  exports.NavUser = NavUser;