@ram_28/kf-ai-sdk 1.0.19 → 1.0.20

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 (64) hide show
  1. package/README.md +45 -12
  2. package/dist/components/hooks/useFilter/types.d.ts +14 -11
  3. package/dist/components/hooks/useFilter/types.d.ts.map +1 -1
  4. package/dist/components/hooks/useFilter/useFilter.d.ts +1 -1
  5. package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
  6. package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
  7. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  8. package/dist/components/hooks/useKanban/types.d.ts +5 -22
  9. package/dist/components/hooks/useKanban/types.d.ts.map +1 -1
  10. package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -1
  11. package/dist/components/hooks/useTable/types.d.ts +19 -31
  12. package/dist/components/hooks/useTable/types.d.ts.map +1 -1
  13. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  14. package/dist/error-handling-CAoD0Kwb.cjs +1 -0
  15. package/dist/error-handling-CrhTtD88.js +14 -0
  16. package/dist/filter.cjs +1 -1
  17. package/dist/filter.mjs +1 -1
  18. package/dist/form.cjs +1 -1
  19. package/dist/form.mjs +338 -327
  20. package/dist/index.d.ts +18 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/kanban.cjs +2 -2
  23. package/dist/kanban.mjs +332 -322
  24. package/dist/table.cjs +1 -1
  25. package/dist/table.mjs +113 -96
  26. package/dist/table.types.d.ts +1 -1
  27. package/dist/table.types.d.ts.map +1 -1
  28. package/dist/types/common.d.ts +26 -6
  29. package/dist/types/common.d.ts.map +1 -1
  30. package/dist/useFilter-DzpP_ag0.cjs +1 -0
  31. package/dist/useFilter-H5bgAZQF.js +120 -0
  32. package/dist/utils/api/buildListOptions.d.ts +43 -0
  33. package/dist/utils/api/buildListOptions.d.ts.map +1 -0
  34. package/dist/utils/api/index.d.ts +2 -0
  35. package/dist/utils/api/index.d.ts.map +1 -0
  36. package/dist/utils/error-handling.d.ts +41 -0
  37. package/dist/utils/error-handling.d.ts.map +1 -0
  38. package/dist/utils/index.d.ts +2 -0
  39. package/dist/utils/index.d.ts.map +1 -1
  40. package/docs/QUICK_REFERENCE.md +142 -420
  41. package/docs/useAuth.md +52 -340
  42. package/docs/useFilter.md +858 -162
  43. package/docs/useForm.md +712 -501
  44. package/docs/useKanban.md +534 -279
  45. package/docs/useTable.md +725 -214
  46. package/package.json +1 -1
  47. package/sdk/components/hooks/useFilter/types.ts +14 -11
  48. package/sdk/components/hooks/useFilter/useFilter.ts +20 -18
  49. package/sdk/components/hooks/useForm/apiClient.ts +2 -1
  50. package/sdk/components/hooks/useForm/useForm.ts +35 -11
  51. package/sdk/components/hooks/useKanban/types.ts +7 -23
  52. package/sdk/components/hooks/useKanban/useKanban.ts +54 -18
  53. package/sdk/components/hooks/useTable/types.ts +26 -32
  54. package/sdk/components/hooks/useTable/useTable.llm.txt +8 -22
  55. package/sdk/components/hooks/useTable/useTable.ts +70 -25
  56. package/sdk/index.ts +154 -10
  57. package/sdk/table.types.ts +3 -0
  58. package/sdk/types/common.ts +31 -6
  59. package/sdk/utils/api/buildListOptions.ts +120 -0
  60. package/sdk/utils/api/index.ts +2 -0
  61. package/sdk/utils/error-handling.ts +150 -0
  62. package/sdk/utils/index.ts +6 -0
  63. package/dist/useFilter-Dofowpr_.cjs +0 -1
  64. package/dist/useFilter-Dv-mr9QW.js +0 -117
package/docs/useAuth.md CHANGED
@@ -1,13 +1,8 @@
1
1
  # useAuth
2
2
 
3
- ## Brief Description
3
+ Authentication state management with session handling.
4
4
 
5
- - Provides authentication state management with support for multiple OAuth providers (Google, Microsoft, GitHub, custom)
6
- - Handles session checking, login flow initiation, and logout operations with automatic session refresh
7
- - Includes role-based access control helpers (`hasRole`, `hasAnyRole`) for permission checking
8
- - Must be used within an `AuthProvider` component that manages the authentication context
9
-
10
- ## Type Reference
5
+ ## Imports
11
6
 
12
7
  ```typescript
13
8
  import { useAuth, AuthProvider } from "@ram_28/kf-ai-sdk/auth";
@@ -15,15 +10,12 @@ import type {
15
10
  UseAuthReturnType,
16
11
  UserDetailsType,
17
12
  AuthStatusType,
18
- AuthProviderPropsType,
19
- AuthProviderNameType,
20
- AuthConfigType,
21
- AuthEndpointConfigType,
22
- LoginOptionsType,
23
- LogoutOptionsType,
24
- SessionResponseType,
25
13
  } from "@ram_28/kf-ai-sdk/auth/types";
14
+ ```
15
+
16
+ ## Type Definitions
26
17
 
18
+ ```typescript
27
19
  // User details from session
28
20
  interface UserDetailsType {
29
21
  _id: string;
@@ -32,371 +24,91 @@ interface UserDetailsType {
32
24
  [key: string]: unknown;
33
25
  }
34
26
 
35
- // Session response from API
36
- interface SessionResponseType {
37
- userDetails: UserDetailsType;
38
- staticBaseUrl: string;
39
- buildId: string;
40
- }
41
-
42
27
  // Authentication status
43
28
  type AuthStatusType = "loading" | "authenticated" | "unauthenticated";
44
29
 
45
- // Supported auth providers
46
- type AuthProviderNameType = "google" | "microsoft" | "github" | "custom";
47
-
48
- // Auth endpoint configuration for a provider
49
- interface AuthEndpointConfigType {
50
- loginPath: string;
51
- logoutPath?: string;
52
- callbackPath?: string;
53
- }
54
-
55
- // Global auth configuration
56
- interface AuthConfigType {
57
- baseUrl?: string;
58
- sessionEndpoint: string;
59
- providers: Partial<Record<AuthProviderNameType, AuthEndpointConfigType>>;
60
- defaultProvider: AuthProviderNameType;
61
- autoRedirect: boolean;
62
- loginRedirectUrl?: string;
63
- callbackUrl?: string;
64
- sessionCheckInterval: number;
65
- retry: { count: number; delay: number };
66
- staleTime: number;
67
- refetchOnWindowFocus?: boolean;
68
- refetchOnReconnect?: boolean;
69
- }
70
-
71
- // AuthProvider component props
72
- interface AuthProviderPropsType {
73
- children: React.ReactNode;
74
- config?: Partial<AuthConfigType>;
75
- onAuthChange?: (status: AuthStatusType, user: UserDetailsType | null) => void;
76
- onError?: (error: Error) => void;
77
- loadingComponent?: React.ReactNode;
78
- unauthenticatedComponent?: React.ReactNode;
79
- skipInitialCheck?: boolean;
80
- }
81
-
82
- // Login options
83
- interface LoginOptionsType {
84
- callbackUrl?: string;
85
- params?: Record<string, string>;
86
- }
87
-
88
- // Logout options
89
- interface LogoutOptionsType {
90
- redirectUrl?: string;
91
- callLogoutEndpoint?: boolean;
92
- }
93
-
94
30
  // Hook return type
95
31
  interface UseAuthReturnType {
96
32
  // User state
97
33
  user: UserDetailsType | null;
98
34
  staticBaseUrl: string | null;
99
35
  buildId: string | null;
36
+
37
+ // Auth status
100
38
  status: AuthStatusType;
101
39
  isAuthenticated: boolean;
102
40
  isLoading: boolean;
41
+ error: Error | null;
103
42
 
104
- // Auth operations
105
- login: (provider?: AuthProviderNameType, options?: LoginOptionsType) => void;
106
- logout: (options?: LogoutOptionsType) => Promise<void>;
43
+ // Auth actions
44
+ login: (provider?: string, options?: { callbackUrl?: string }) => void;
45
+ logout: (options?: { redirectUrl?: string }) => Promise<void>;
107
46
  refreshSession: () => Promise<SessionResponseType | null>;
47
+
48
+ // Role checks
108
49
  hasRole: (role: string) => boolean;
109
50
  hasAnyRole: (roles: string[]) => boolean;
110
51
 
111
- // Error state
112
- error: Error | null;
52
+ // Error handling
113
53
  clearError: () => void;
114
54
  }
115
55
  ```
116
56
 
117
57
  ## Usage Example
118
58
 
59
+ Wrap your app with `AuthProvider` and use `useAuth` in components.
60
+
119
61
  ```tsx
120
62
  import { useAuth, AuthProvider } from "@ram_28/kf-ai-sdk/auth";
121
- import type {
122
- UseAuthReturnType,
123
- UserDetailsType,
124
- AuthStatusType,
125
- AuthProviderPropsType,
126
- AuthProviderNameType,
127
- AuthConfigType,
128
- AuthEndpointConfigType,
129
- LoginOptionsType,
130
- LogoutOptionsType,
131
- SessionResponseType,
132
- } from "@ram_28/kf-ai-sdk/auth/types";
133
-
134
- // Define available roles
135
- type Role = "Admin" | "Buyer" | "Seller" | "InventoryManager";
136
63
 
137
- // Auth configuration
138
- const authConfig: Partial<AuthConfigType> = {
139
- sessionEndpoint: "/api/id",
140
- defaultProvider: "google",
141
- autoRedirect: false,
142
- sessionCheckInterval: 5 * 60 * 1000, // 5 minutes
143
- providers: {
144
- google: {
145
- loginPath: "/api/auth/google/login",
146
- logoutPath: "/api/auth/logout",
147
- },
148
- microsoft: {
149
- loginPath: "/api/auth/microsoft/login",
150
- logoutPath: "/api/auth/logout",
151
- },
152
- },
153
- refetchOnWindowFocus: true,
154
- refetchOnReconnect: true,
155
- };
156
-
157
- // App wrapper with AuthProvider
64
+ // 1. Wrap app with AuthProvider
158
65
  function App() {
159
- // Auth status change handler
160
- const handleAuthChange = (status: AuthStatusType, user: UserDetailsType | null) => {
161
- console.log("Auth status:", status, "User:", user?._name);
162
- };
163
-
164
- // Auth error handler
165
- const handleAuthError = (error: Error) => {
166
- console.error("Auth error:", error.message);
167
- };
168
-
169
- // AuthProviderPropsType configuration
170
- const providerProps: AuthProviderPropsType = {
171
- children: <AppRoutes />,
172
- config: authConfig,
173
- onAuthChange: handleAuthChange,
174
- onError: handleAuthError,
175
- loadingComponent: <div>Checking authentication...</div>,
176
- unauthenticatedComponent: <LoginPage />,
177
- skipInitialCheck: false,
178
- };
179
-
180
- return <AuthProvider {...providerProps} />;
181
- }
182
-
183
- // Login page component
184
- function LoginPage() {
185
- const auth: UseAuthReturnType = useAuth();
186
-
187
- // Login with Google
188
- const handleGoogleLogin = () => {
189
- const options: LoginOptionsType = {
190
- callbackUrl: "/dashboard",
191
- };
192
- auth.login("google", options);
193
- };
194
-
195
- // Login with Microsoft
196
- const handleMicrosoftLogin = () => {
197
- const options: LoginOptionsType = {
198
- callbackUrl: "/dashboard",
199
- params: { prompt: "select_account" },
200
- };
201
- auth.login("microsoft", options);
202
- };
203
-
204
- // Login with default provider
205
- const handleDefaultLogin = () => {
206
- auth.login(); // Uses defaultProvider from config
207
- };
208
-
209
- // Access auth status
210
- const status: AuthStatusType = auth.status;
211
-
212
66
  return (
213
- <div className="login-page">
214
- <h1>Welcome</h1>
215
- <p>Please sign in to continue</p>
216
-
217
- {/* Error display */}
218
- {auth.error && (
219
- <div className="error">
220
- {auth.error.message}
221
- <button onClick={auth.clearError}>Dismiss</button>
222
- </div>
223
- )}
224
-
225
- {/* Login buttons */}
226
- <div className="login-buttons">
227
- <button onClick={handleGoogleLogin} disabled={auth.isLoading}>
228
- Sign in with Google
229
- </button>
230
- <button onClick={handleMicrosoftLogin} disabled={auth.isLoading}>
231
- Sign in with Microsoft
232
- </button>
233
- <button onClick={handleDefaultLogin} disabled={auth.isLoading}>
234
- Sign in (Default)
235
- </button>
236
- </div>
237
-
238
- {/* Loading state */}
239
- {auth.isLoading && <span>Loading...</span>}
240
-
241
- {/* Status display */}
242
- <p>Current status: {status}</p>
243
- </div>
67
+ <AuthProvider>
68
+ <AppContent />
69
+ </AuthProvider>
244
70
  );
245
71
  }
246
72
 
247
- // Dashboard component (authenticated users)
248
- function Dashboard() {
249
- const auth: UseAuthReturnType = useAuth();
250
-
251
- // Logout handler
252
- const handleLogout = async () => {
253
- const options: LogoutOptionsType = {
254
- redirectUrl: "/login",
255
- callLogoutEndpoint: true,
256
- };
257
- await auth.logout(options);
258
- };
259
-
260
- // Refresh session handler
261
- const handleRefreshSession = async () => {
262
- const session: SessionResponseType | null = await auth.refreshSession();
263
- if (session) {
264
- console.log("Session refreshed:", session.userDetails._name);
265
- console.log("Static URL:", session.staticBaseUrl);
266
- console.log("Build ID:", session.buildId);
267
- }
268
- };
73
+ // 2. Use useAuth in components
74
+ function AppContent() {
75
+ const auth = useAuth();
269
76
 
270
- // Access user details
271
- const user: UserDetailsType | null = auth.user;
77
+ if (auth.isLoading) return <div>Loading...</div>;
272
78
 
273
- // Role-based access control
274
- const isAdmin: boolean = auth.hasRole("Admin");
275
- const canManageProducts: boolean = auth.hasAnyRole(["Admin", "Seller"]);
276
- const canViewReports: boolean = auth.hasAnyRole(["Admin", "InventoryManager"]);
277
-
278
- // Guard against unauthenticated access
279
79
  if (!auth.isAuthenticated) {
280
- return <div>Please log in to access the dashboard</div>;
281
- }
282
-
283
- return (
284
- <div className="dashboard">
285
- {/* Header */}
286
- <header>
287
- <h1>Dashboard</h1>
288
- <div className="user-info">
289
- <span>Welcome, {user?._name}</span>
290
- <span>Role: {user?.Role}</span>
291
- <button onClick={handleRefreshSession}>Refresh Session</button>
292
- <button onClick={handleLogout}>Logout</button>
293
- </div>
294
- </header>
295
-
296
- {/* Main content */}
297
- <main>
298
- {/* User info section */}
299
- <section className="user-section">
300
- <h2>User Information</h2>
301
- <p>User ID: {user?._id}</p>
302
- <p>Name: {user?._name}</p>
303
- <p>Role: {user?.Role}</p>
304
- <p>Static Base URL: {auth.staticBaseUrl}</p>
305
- <p>Build ID: {auth.buildId}</p>
306
- <p>Status: {auth.status}</p>
307
- <p>Authenticated: {auth.isAuthenticated ? "Yes" : "No"}</p>
308
- </section>
309
-
310
- {/* Role-based sections */}
311
- {canManageProducts && (
312
- <section className="products-section">
313
- <h2>Product Management</h2>
314
- <p>You have access to manage products.</p>
315
- </section>
316
- )}
317
-
318
- {canViewReports && (
319
- <section className="reports-section">
320
- <h2>Reports</h2>
321
- <p>You have access to view reports.</p>
322
- </section>
323
- )}
324
-
325
- {isAdmin && (
326
- <section className="admin-section">
327
- <h2>Admin Panel</h2>
328
- <p>Full administrative access.</p>
329
- </section>
330
- )}
331
-
332
- {!isAdmin && (
333
- <section className="restricted-section">
334
- <p>Admin panel is restricted to administrators.</p>
335
- </section>
336
- )}
337
- </main>
338
-
339
- {/* Error banner */}
340
- {auth.error && (
341
- <div className="error-banner">
342
- Error: {auth.error.message}
343
- <button onClick={auth.clearError}>Dismiss</button>
344
- </div>
345
- )}
346
- </div>
347
- );
348
- }
349
-
350
- // Protected route component
351
- function ProtectedRoute({
352
- children,
353
- requiredRoles,
354
- }: {
355
- children: React.ReactNode;
356
- requiredRoles?: string[];
357
- }) {
358
- const auth: UseAuthReturnType = useAuth();
359
-
360
- // Show loading while checking auth
361
- if (auth.isLoading) {
362
- return <div>Loading...</div>;
363
- }
364
-
365
- // Redirect if not authenticated
366
- if (!auth.isAuthenticated) {
367
- return <div>Access denied. Please log in.</div>;
368
- }
369
-
370
- // Check role requirements
371
- if (requiredRoles && !auth.hasAnyRole(requiredRoles)) {
372
- return <div>Access denied. Insufficient permissions.</div>;
80
+ return (
81
+ <div>
82
+ <h1>Welcome</h1>
83
+ <button onClick={() => auth.login()}>Login with Google</button>
84
+ </div>
85
+ );
373
86
  }
374
87
 
375
- return <>{children}</>;
376
- }
377
-
378
- // App routes with protected routes
379
- function AppRoutes() {
380
88
  return (
381
89
  <div>
382
- {/* Public route */}
383
- <LoginPage />
384
-
385
- {/* Protected route - any authenticated user */}
386
- <ProtectedRoute>
387
- <Dashboard />
388
- </ProtectedRoute>
389
-
390
- {/* Protected route - admin only */}
391
- <ProtectedRoute requiredRoles={["Admin"]}>
392
- <div>Admin Only Content</div>
393
- </ProtectedRoute>
394
-
395
- {/* Protected route - multiple roles */}
396
- <ProtectedRoute requiredRoles={["Admin", "Seller", "InventoryManager"]}>
397
- <div>Staff Only Content</div>
398
- </ProtectedRoute>
90
+ <h1>Hello, {auth.user?._name}</h1>
91
+ <p>Role: {auth.user?.Role}</p>
92
+ <button onClick={() => auth.logout()}>Sign Out</button>
399
93
  </div>
400
94
  );
401
95
  }
402
96
  ```
97
+
98
+ ## useAuth Properties
99
+
100
+ | Property | Type | Description |
101
+ | ----------------- | -------------------------------------------- | ---------------------------------------------------------------- |
102
+ | `user` | `UserDetailsType \| null` | Current authenticated user details |
103
+ | `isAuthenticated` | `boolean` | Whether user is logged in |
104
+ | `isLoading` | `boolean` | Whether auth state is being determined |
105
+ | `status` | `AuthStatusType` | Full status: `"loading"`, `"authenticated"`, `"unauthenticated"` |
106
+ | `error` | `Error \| null` | Last authentication error |
107
+ | `staticBaseUrl` | `string \| null` | Base URL for static assets from session |
108
+ | `buildId` | `string \| null` | Current build identifier from session |
109
+ | `login` | `(provider?, options?) => void` | Start login flow |
110
+ | `logout` | `(options?) => Promise<void>` | Sign out user |
111
+ | `hasRole` | `(role: string) => boolean` | Check if user has specific role |
112
+ | `hasAnyRole` | `(roles: string[]) => boolean` | Check if user has any of the roles |
113
+ | `refreshSession` | `() => Promise<SessionResponseType \| null>` | Manually refresh session |
114
+ | `clearError` | `() => void` | Clear the current error state |