@ram_28/kf-ai-sdk 2.0.12 → 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/api/client.d.ts.map +1 -1
- package/dist/api.cjs +1 -1
- package/dist/api.mjs +2 -2
- package/dist/attachment-constants-B5jlqoKI.cjs +1 -0
- package/dist/attachment-constants-C2UHWxmp.js +63 -0
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/types.d.ts +4 -0
- package/dist/bdo/core/types.d.ts.map +1 -1
- package/dist/bdo/fields/NumberField.d.ts.map +1 -1
- package/dist/bdo/fields/ReferenceField.d.ts +3 -2
- package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
- package/dist/bdo/fields/SelectField.d.ts +1 -1
- package/dist/bdo/fields/SelectField.d.ts.map +1 -1
- package/dist/bdo/fields/UserField.d.ts +5 -0
- package/dist/bdo/fields/UserField.d.ts.map +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +107 -153
- package/dist/client-DnO2KKrw.cjs +1 -0
- package/dist/{client-CMERmrC-.js → client-iQTqFDNI.js} +34 -30
- package/dist/components/hooks/useForm/createItemProxy.d.ts +4 -0
- package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useForm/createResolver.d.ts.map +1 -1
- package/dist/components/hooks/useForm/useForm.d.ts +1 -0
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +368 -203
- package/dist/{metadata-BfJtHz84.cjs → metadata-DgLSJkF5.cjs} +1 -1
- package/dist/{metadata-CwAo6a8e.js → metadata-DpfI3zRN.js} +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +1 -1
- package/dist/workflow/types.d.ts +3 -2
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.d.ts +0 -2
- package/dist/workflow.d.ts.map +1 -1
- package/dist/workflow.mjs +204 -274
- package/dist/workflow.types.d.ts +0 -1
- package/dist/workflow.types.d.ts.map +1 -1
- package/docs/api.md +45 -253
- package/docs/bdo.md +130 -711
- package/docs/useAuth.md +42 -104
- package/docs/useFilter.md +117 -1591
- package/docs/useForm.md +263 -861
- package/docs/useTable.md +255 -1096
- package/docs/workflow.md +10 -155
- package/package.json +1 -1
- package/sdk/api/client.ts +18 -4
- package/sdk/bdo/core/types.ts +1 -0
- package/sdk/bdo/fields/NumberField.ts +2 -1
- package/sdk/bdo/fields/ReferenceField.ts +4 -3
- package/sdk/bdo/fields/SelectField.ts +2 -2
- package/sdk/bdo/fields/UserField.ts +14 -0
- package/sdk/components/hooks/useForm/createItemProxy.ts +221 -4
- package/sdk/components/hooks/useForm/createResolver.ts +16 -1
- package/sdk/components/hooks/useForm/useForm.ts +151 -50
- package/sdk/workflow/types.ts +3 -2
- package/sdk/workflow.ts +0 -7
- package/sdk/workflow.types.ts +0 -7
- package/dist/client-BnVxSHAm.cjs +0 -1
- package/dist/workflow/components/useActivityTable/index.d.ts +0 -4
- package/dist/workflow/components/useActivityTable/index.d.ts.map +0 -1
- package/dist/workflow/components/useActivityTable/types.d.ts +0 -53
- package/dist/workflow/components/useActivityTable/types.d.ts.map +0 -1
- package/dist/workflow/components/useActivityTable/useActivityTable.d.ts +0 -4
- package/dist/workflow/components/useActivityTable/useActivityTable.d.ts.map +0 -1
- package/sdk/workflow/components/useActivityTable/index.ts +0 -8
- package/sdk/workflow/components/useActivityTable/types.ts +0 -67
- package/sdk/workflow/components/useActivityTable/useActivityTable.ts +0 -145
package/docs/useAuth.md
CHANGED
|
@@ -1,150 +1,88 @@
|
|
|
1
1
|
# Auth SDK API
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
authentication and state management with session handling.
|
|
5
|
-
|
|
6
|
-
Here is the example how to use this API:
|
|
3
|
+
React hook for authentication and session management.
|
|
7
4
|
|
|
8
5
|
## Imports
|
|
9
6
|
|
|
10
7
|
```typescript
|
|
11
8
|
import { useAuth, AuthProvider } from "@ram_28/kf-ai-sdk/auth";
|
|
12
|
-
import type {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
import type { UseAuthReturnType, UserDetailsType, AuthStatusType } from "@ram_28/kf-ai-sdk/auth/types";
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Common Mistakes (READ FIRST)
|
|
15
|
+
|
|
16
|
+
### 1. Wrong user name property
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// ❌ WRONG — `name` does not exist
|
|
20
|
+
user?.name
|
|
21
|
+
|
|
22
|
+
// ✅ CORRECT — underscore prefix
|
|
23
|
+
user?._name
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2. Not casting unknown properties
|
|
27
|
+
|
|
28
|
+
All properties except `_id`, `_name`, and `Role` are typed as `unknown`.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
// ❌ WRONG — Email is unknown, can't render in JSX
|
|
32
|
+
<p>{user?.Email}</p>
|
|
33
|
+
|
|
34
|
+
// ✅ CORRECT
|
|
35
|
+
<p>{String(user?.Email ?? "")}</p>
|
|
17
36
|
```
|
|
18
37
|
|
|
38
|
+
---
|
|
39
|
+
|
|
19
40
|
## Type Definitions
|
|
20
41
|
|
|
21
42
|
```typescript
|
|
22
|
-
// User details from session
|
|
23
43
|
interface UserDetailsType {
|
|
24
44
|
_id: string;
|
|
25
45
|
_name: string;
|
|
26
46
|
Role: string;
|
|
27
|
-
[key: string]: unknown;
|
|
47
|
+
[key: string]: unknown; // Other properties are unknown — cast when rendering
|
|
28
48
|
}
|
|
29
49
|
|
|
30
|
-
// Authentication status
|
|
31
50
|
type AuthStatusType = "loading" | "authenticated" | "unauthenticated";
|
|
32
51
|
|
|
33
|
-
// Hook return type
|
|
34
52
|
interface UseAuthReturnType {
|
|
35
|
-
// User state
|
|
36
53
|
user: UserDetailsType | null;
|
|
37
|
-
staticBaseUrl: string | null;
|
|
38
|
-
buildId: string | null;
|
|
39
|
-
|
|
40
|
-
// Auth status
|
|
41
54
|
status: AuthStatusType;
|
|
42
55
|
isAuthenticated: boolean;
|
|
43
56
|
isLoading: boolean;
|
|
44
57
|
error: Error | null;
|
|
45
|
-
|
|
46
|
-
// Auth actions
|
|
47
58
|
login: (provider?: string, options?: { callbackUrl?: string }) => void;
|
|
48
59
|
logout: (options?: { redirectUrl?: string }) => Promise<void>;
|
|
49
|
-
refreshSession: () => Promise<SessionResponseType | null>;
|
|
50
|
-
|
|
51
|
-
// Role checks
|
|
52
60
|
hasRole: (role: string) => boolean;
|
|
53
61
|
hasAnyRole: (roles: string[]) => boolean;
|
|
54
|
-
|
|
55
|
-
// Error handling
|
|
62
|
+
refreshSession: () => Promise<any>;
|
|
56
63
|
clearError: () => void;
|
|
64
|
+
staticBaseUrl: string | null;
|
|
65
|
+
buildId: string | null;
|
|
57
66
|
}
|
|
58
67
|
```
|
|
59
68
|
|
|
60
|
-
## Usage
|
|
61
|
-
|
|
62
|
-
Wrap your app with `AuthProvider` and use `useAuth` in components.
|
|
69
|
+
## Usage
|
|
63
70
|
|
|
64
71
|
```tsx
|
|
65
|
-
import { useAuth
|
|
66
|
-
|
|
67
|
-
// 1. Wrap app with AuthProvider inside QueryClientProvider
|
|
68
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
69
|
-
|
|
70
|
-
const queryClient = new QueryClient();
|
|
71
|
-
|
|
72
|
-
function App() {
|
|
73
|
-
return (
|
|
74
|
-
<QueryClientProvider client={queryClient}>
|
|
75
|
-
<AuthProvider>
|
|
76
|
-
<AppContent />
|
|
77
|
-
</AuthProvider>
|
|
78
|
-
</QueryClientProvider>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
72
|
+
import { useAuth } from "@ram_28/kf-ai-sdk/auth";
|
|
81
73
|
|
|
82
|
-
// 2. Use useAuth in components
|
|
83
74
|
function AppContent() {
|
|
84
|
-
const
|
|
75
|
+
const { user, isAuthenticated, isLoading, login, logout } = useAuth();
|
|
85
76
|
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
if (!auth.isAuthenticated) {
|
|
89
|
-
return (
|
|
90
|
-
<div>
|
|
91
|
-
<h1>Welcome</h1>
|
|
92
|
-
<button onClick={() => auth.login()}>Login with Google</button>
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
77
|
+
if (isLoading) return <div>Loading...</div>;
|
|
78
|
+
if (!isAuthenticated) return <button onClick={() => login()}>Login</button>;
|
|
96
79
|
|
|
97
80
|
return (
|
|
98
81
|
<div>
|
|
99
|
-
<h1>Hello, {
|
|
100
|
-
<p>Role: {
|
|
101
|
-
<button onClick={() =>
|
|
82
|
+
<h1>Hello, {user?._name}</h1>
|
|
83
|
+
<p>Role: {user?.Role}</p>
|
|
84
|
+
<button onClick={() => logout()}>Sign Out</button>
|
|
102
85
|
</div>
|
|
103
86
|
);
|
|
104
87
|
}
|
|
105
88
|
```
|
|
106
|
-
|
|
107
|
-
## useAuth Properties
|
|
108
|
-
|
|
109
|
-
| Property | Type | Description |
|
|
110
|
-
| ----------------- | -------------------------------------------- | ---------------------------------------------------------------- |
|
|
111
|
-
| `user` | `UserDetailsType \| null` | Current authenticated user details |
|
|
112
|
-
| `isAuthenticated` | `boolean` | Whether user is logged in |
|
|
113
|
-
| `isLoading` | `boolean` | Whether auth state is being determined |
|
|
114
|
-
| `status` | `AuthStatusType` | Full status: `"loading"`, `"authenticated"`, `"unauthenticated"` |
|
|
115
|
-
| `error` | `Error \| null` | Last authentication error |
|
|
116
|
-
| `staticBaseUrl` | `string \| null` | Base URL for static assets from session |
|
|
117
|
-
| `buildId` | `string \| null` | Current build identifier from session |
|
|
118
|
-
| `login` | `(provider?, options?) => void` | Start login flow |
|
|
119
|
-
| `logout` | `(options?) => Promise<void>` | Sign out user |
|
|
120
|
-
| `hasRole` | `(role: string) => boolean` | Check if user has specific role |
|
|
121
|
-
| `hasAnyRole` | `(roles: string[]) => boolean` | Check if user has any of the roles |
|
|
122
|
-
| `refreshSession` | `() => Promise<SessionResponseType \| null>` | Manually refresh session |
|
|
123
|
-
| `clearError` | `() => void` | Clear the current error state |
|
|
124
|
-
|
|
125
|
-
---
|
|
126
|
-
|
|
127
|
-
## Common Mistakes
|
|
128
|
-
|
|
129
|
-
### 1. Wrong user name property
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
// ❌ WRONG — `name` does not exist on UserDetailsType
|
|
133
|
-
user?.name
|
|
134
|
-
|
|
135
|
-
// ✅ CORRECT — use _name (underscore prefix)
|
|
136
|
-
user?._name
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### 2. Not casting unknown properties
|
|
140
|
-
|
|
141
|
-
All properties except `_id`, `_name`, and `Role` are typed as `unknown` via the index signature.
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
// ❌ WRONG — Email is typed as unknown, can't render directly in JSX
|
|
145
|
-
<p>{user?.Email}</p>
|
|
146
|
-
|
|
147
|
-
// ✅ CORRECT — cast to string when rendering
|
|
148
|
-
<p>{String(user?.Email)}</p>
|
|
149
|
-
<p>{user?.Email as string}</p>
|
|
150
|
-
```
|