@ram_28/kf-ai-sdk 2.0.16 → 2.0.18

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 (105) hide show
  1. package/README.md +16 -8
  2. package/dist/{FileField-BWrSHNRq.js → FileField-CZjS2uLh.js} +3 -3
  3. package/dist/{FileField-eDeuzln8.cjs → FileField-DU4UWo_t.cjs} +1 -1
  4. package/dist/api.cjs +1 -1
  5. package/dist/api.mjs +1 -1
  6. package/dist/auth/authConfig.d.ts +1 -1
  7. package/dist/auth/types.d.ts +1 -1
  8. package/dist/auth/types.d.ts.map +1 -1
  9. package/dist/auth.cjs +1 -1
  10. package/dist/auth.mjs +1 -1
  11. package/dist/bdo/core/Item.d.ts +0 -4
  12. package/dist/bdo/core/Item.d.ts.map +1 -1
  13. package/dist/bdo/fields/ReferenceField.d.ts +1 -1
  14. package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
  15. package/dist/bdo/fields/SelectField.d.ts +1 -1
  16. package/dist/bdo/fields/SelectField.d.ts.map +1 -1
  17. package/dist/bdo/fields/UserField.d.ts +1 -1
  18. package/dist/bdo/fields/UserField.d.ts.map +1 -1
  19. package/dist/bdo.cjs +1 -1
  20. package/dist/bdo.mjs +53 -62
  21. package/dist/components/hooks/useActivityForm/types.d.ts +4 -5
  22. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  23. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  24. package/dist/components/hooks/useActivityTable/types.d.ts +5 -4
  25. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  26. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  27. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts +2 -3
  28. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -1
  29. package/dist/components/hooks/useBDOTable/types.d.ts +20 -12
  30. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  31. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
  32. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  33. package/dist/{constants-ConHc1oS.js → constants-Cyi942Yr.js} +5 -5
  34. package/dist/constants-DEmYwKfC.cjs +1 -0
  35. package/dist/filter.cjs +1 -1
  36. package/dist/filter.mjs +1 -1
  37. package/dist/form.cjs +1 -1
  38. package/dist/form.mjs +226 -243
  39. package/dist/table.cjs +1 -1
  40. package/dist/table.mjs +15 -16
  41. package/dist/table.types.d.ts +1 -1
  42. package/dist/table.types.d.ts.map +1 -1
  43. package/dist/types/constants.d.ts +1 -1
  44. package/dist/workflow/Activity.d.ts +8 -5
  45. package/dist/workflow/Activity.d.ts.map +1 -1
  46. package/dist/workflow.cjs +1 -1
  47. package/dist/workflow.mjs +461 -476
  48. package/docs/README.md +57 -0
  49. package/docs/bdo/README.md +161 -0
  50. package/docs/bdo/api_reference.md +281 -0
  51. package/docs/examples/bdo/create-product.md +69 -0
  52. package/docs/examples/bdo/edit-product-dialog.md +95 -0
  53. package/docs/examples/bdo/filtered-product-table.md +100 -0
  54. package/docs/examples/bdo/product-listing.md +73 -0
  55. package/docs/examples/bdo/supplier-dropdown.md +60 -0
  56. package/docs/examples/fields/complex-fields.md +248 -0
  57. package/docs/examples/fields/primitive-fields.md +217 -0
  58. package/docs/examples/workflow/approve-leave-request.md +76 -0
  59. package/docs/examples/workflow/filtered-activity-table.md +101 -0
  60. package/docs/examples/workflow/my-pending-requests.md +90 -0
  61. package/docs/examples/workflow/start-new-workflow.md +47 -0
  62. package/docs/examples/workflow/submit-leave-request.md +72 -0
  63. package/docs/examples/workflow/workflow-progress.md +49 -0
  64. package/docs/fields/README.md +141 -0
  65. package/docs/fields/api_reference.md +134 -0
  66. package/docs/useActivityForm/README.md +244 -0
  67. package/docs/useActivityForm/api_reference.md +279 -0
  68. package/docs/useActivityTable/README.md +263 -0
  69. package/docs/useActivityTable/api_reference.md +294 -0
  70. package/docs/useBDOForm/README.md +175 -0
  71. package/docs/useBDOForm/api_reference.md +244 -0
  72. package/docs/useBDOTable/README.md +242 -0
  73. package/docs/useBDOTable/api_reference.md +253 -0
  74. package/docs/useFilter/README.md +323 -0
  75. package/docs/useFilter/api_reference.md +228 -0
  76. package/docs/workflow/README.md +158 -0
  77. package/docs/workflow/api_reference.md +161 -0
  78. package/package.json +1 -1
  79. package/sdk/auth/authConfig.ts +1 -1
  80. package/sdk/auth/types.ts +1 -1
  81. package/sdk/bdo/core/Item.ts +1 -10
  82. package/sdk/bdo/fields/ReferenceField.ts +1 -1
  83. package/sdk/bdo/fields/SelectField.ts +1 -1
  84. package/sdk/bdo/fields/UserField.ts +1 -1
  85. package/sdk/components/hooks/useActivityForm/types.ts +4 -6
  86. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +10 -73
  87. package/sdk/components/hooks/useActivityTable/types.ts +4 -5
  88. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +10 -8
  89. package/sdk/components/hooks/useBDOForm/createItemProxy.ts +17 -58
  90. package/sdk/components/hooks/useBDOTable/types.ts +20 -10
  91. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +12 -8
  92. package/sdk/table.types.ts +2 -0
  93. package/sdk/types/constants.ts +1 -1
  94. package/sdk/workflow/Activity.ts +39 -7
  95. package/dist/constants-QX2RX-wu.cjs +0 -1
  96. package/docs/api.md +0 -95
  97. package/docs/bdo.md +0 -224
  98. package/docs/gaps.md +0 -360
  99. package/docs/useActivityForm.md +0 -393
  100. package/docs/useActivityTable.md +0 -418
  101. package/docs/useBDOForm.md +0 -376
  102. package/docs/useBDOTable.md +0 -284
  103. package/docs/useFilter.md +0 -188
  104. package/docs/workflow.md +0 -560
  105. /package/docs/{useAuth.md → useAuth/README.md} +0 -0
@@ -1,393 +0,0 @@
1
- # useActivityForm
2
-
3
- React hook for building forms bound to workflow activity input fields. Integrates with `react-hook-form`.
4
-
5
- ## Imports
6
-
7
- ```typescript
8
- import { useActivityForm } from "@ram_28/kf-ai-sdk/workflow";
9
- import type {
10
- UseActivityFormOptions,
11
- UseActivityFormReturn,
12
- } from "@ram_28/kf-ai-sdk/workflow";
13
- import type { FieldErrors } from "react-hook-form";
14
- ```
15
-
16
- ---
17
-
18
- ## Common Mistakes (READ FIRST)
19
-
20
- ### 1. Passing a Workflow instead of an Activity
21
-
22
- `useActivityForm` takes an **Activity** instance, not a Workflow.
23
-
24
- ```typescript
25
- // ❌ WRONG — passing a workflow
26
- const wf = new SimpleLeaveProcess();
27
- useActivityForm(wf, options);
28
-
29
- // ✅ CORRECT — get the typed activity from the workflow
30
- const activity = useMemo(() => new SimpleLeaveProcess().employeeInputActivity(), []);
31
- useActivityForm(activity, options);
32
- ```
33
-
34
- ### 2. Forgetting to memoize the activity instance
35
-
36
- Activity instances must be stable across renders, or the hook will re-fetch metadata on every render.
37
-
38
- ```typescript
39
- // ❌ WRONG — new instance on every render
40
- const activity = new SimpleLeaveProcess().employeeInputActivity();
41
- useActivityForm(activity, options);
42
-
43
- // ✅ CORRECT — memoize with useMemo
44
- const activity = useMemo(() => new SimpleLeaveProcess().employeeInputActivity(), []);
45
- useActivityForm(activity, options);
46
- ```
47
-
48
- ### 3. Using handleSubmit instead of handleComplete to finish an activity
49
-
50
- `handleSubmit` saves the form data but does NOT complete the activity. Use `handleComplete` to save AND complete.
51
-
52
- ```typescript
53
- // ❌ WRONG — only saves, does not complete
54
- <button onClick={handleSubmit(onSuccess, onError)}>Submit Leave Request</button>
55
-
56
- // ✅ CORRECT — saves AND completes the activity
57
- <button onClick={handleComplete(onSuccess, onError)}>Submit Leave Request</button>
58
-
59
- // ✅ ALSO CORRECT — save as draft (intentionally not completing)
60
- <button onClick={handleSubmit(onSaveSuccess, onError)}>Save Draft</button>
61
- ```
62
-
63
- ### 4. Calling `.get()` on form item fields
64
-
65
- Form item fields from `useActivityForm` follow the same accessor pattern as `useBDOForm`. Use `.get()` to read values programmatically, but prefer `watch()` for rendering.
66
-
67
- ```tsx
68
- // ❌ WRONG — renders [object Object]
69
- <span>{item.StartDate}</span>
70
-
71
- // ✅ CORRECT — use .get() for programmatic access
72
- const startDate = item.StartDate.get();
73
-
74
- // ✅ CORRECT — use watch() for reactive rendering in JSX
75
- <span>{watch(activity.StartDate.id)}</span>
76
- ```
77
-
78
- ---
79
-
80
- ## Type Definitions
81
-
82
- ### UseActivityFormOptions\<A\>
83
-
84
- ```typescript
85
- interface UseActivityFormOptions<A extends Activity<any, any, any>> {
86
- /** Activity instance identifier (from wf.start() or getInProgressList()) */
87
- activity_instance_id: string;
88
-
89
- /** Default form values */
90
- defaultValues?: Partial<ExtractActivityEditable<A>>;
91
-
92
- /** Validation mode (default: "onBlur") */
93
- mode?: "onBlur" | "onChange" | "onSubmit" | "onTouched" | "all";
94
-
95
- /** Whether to load activity data on mount (default: true) */
96
- enabled?: boolean;
97
- }
98
- ```
99
-
100
- ### UseActivityFormReturn\<A\>
101
-
102
- ```typescript
103
- interface UseActivityFormReturn<A extends Activity<any, any, any>> {
104
- // Core
105
- item: FormItemType<EditableFields, ReadonlyFields>;
106
- activity: A;
107
- register: FormRegisterType<EditableFields, ReadonlyFields>;
108
- handleSubmit: HandleSubmitType; // Save the activity form
109
- handleComplete: HandleSubmitType; // Complete the activity
110
-
111
- // RHF methods
112
- watch: UseFormWatch;
113
- setValue: UseFormSetValue;
114
- getValues: UseFormGetValues;
115
- reset: UseFormReset;
116
- trigger: UseFormTrigger;
117
- control: Control;
118
-
119
- // Form state
120
- errors: FieldErrors;
121
- isValid: boolean;
122
- isDirty: boolean;
123
- isSubmitting: boolean;
124
- isSubmitSuccessful: boolean;
125
-
126
- // Loading
127
- isLoading: boolean;
128
- loadError: Error | null;
129
- hasError: boolean;
130
-
131
- // Operations
132
- clearErrors: () => void;
133
- }
134
- ```
135
-
136
- ---
137
-
138
- ## handleSubmit vs handleComplete
139
-
140
- | | `handleSubmit` | `handleComplete` |
141
- |---|---|---|
142
- | **Saves dirty fields** | Yes | Yes |
143
- | **Completes the activity** | No | Yes |
144
- | **Use case** | Save draft / intermediate save | Final submission |
145
-
146
- Both validate the form before executing. Both only send dirty (changed) fields to the API.
147
-
148
- ---
149
-
150
- ## Options
151
-
152
- | Property | Type | Default | Description |
153
- |----------|------|---------|-------------|
154
- | `activity_instance_id` | `string` | *required* | Activity instance ID (from `wf.start()` or `getInProgressList()`) |
155
- | `defaultValues` | `Partial<Editable>` | `{}` | Initial form values |
156
- | `mode` | `"onBlur" \| "onChange" \| "onSubmit" \| "onTouched" \| "all"` | `"onBlur"` | Validation timing |
157
- | `enabled` | `boolean` | `true` | Whether to load activity data on mount |
158
-
159
- ## Lifecycle
160
-
161
- ```
162
- Mount
163
- |
164
- |-> Load activity instance data -> populate form
165
- |
166
- v
167
- User edits field -> blurs
168
- |
169
- |-> Field validation (BaseField.validate)
170
- |-> If valid + readonly fields exist -> update computed fields
171
- |
172
- v
173
- User clicks Save
174
- |
175
- |-> handleSubmit -> save activity data
176
- |
177
- v
178
- User clicks Complete
179
- |
180
- |-> handleComplete -> complete activity
181
- ```
182
-
183
- ## Return Value
184
-
185
- | Property | Type | Description |
186
- |----------|------|-------------|
187
- | `item` | `FormItemType` | Proxy with typed field accessors (`.get()`, `.set()`, `.meta`) |
188
- | `activity` | `A` | The Activity instance |
189
- | `register` | `FormRegisterType` | Smart register (auto-disables readonly fields) |
190
- | `handleSubmit` | `HandleSubmitType` | Save activity data |
191
- | `handleComplete` | `HandleSubmitType` | Complete the activity |
192
- | `watch` | `UseFormWatch` | Watch field values |
193
- | `setValue` | `UseFormSetValue` | Set field value programmatically |
194
- | `getValues` | `UseFormGetValues` | Get current field values |
195
- | `reset` | `UseFormReset` | Reset form to default values |
196
- | `trigger` | `UseFormTrigger` | Trigger validation |
197
- | `control` | `Control` | RHF control (for Controller components) |
198
- | `errors` | `FieldErrors` | Validation errors |
199
- | `isValid` | `boolean` | Form is valid |
200
- | `isDirty` | `boolean` | Form has been modified |
201
- | `isSubmitting` | `boolean` | Currently submitting |
202
- | `isSubmitSuccessful` | `boolean` | Last submission succeeded |
203
- | `isLoading` | `boolean` | Loading activity data |
204
- | `loadError` | `Error \| null` | Load error |
205
- | `hasError` | `boolean` | Any error active |
206
- | `clearErrors` | `() => void` | Clear all form errors |
207
-
208
- ---
209
-
210
- ## Example: Employee Leave Request Form
211
-
212
- ```tsx
213
- import { useMemo } from "react";
214
- import { useActivityForm } from "@ram_28/kf-ai-sdk/workflow";
215
- import type { UseActivityFormOptions } from "@ram_28/kf-ai-sdk/workflow";
216
- import type { FieldErrors } from "react-hook-form";
217
- import { SimpleLeaveProcess, EmployeeInputActivity } from "@/bdo/workflows/SimpleLeaveProcess";
218
-
219
- interface LeaveRequestFormProps {
220
- activityInstanceId: string;
221
- onComplete: () => void;
222
- }
223
-
224
- function LeaveRequestForm({ activityInstanceId, onComplete }: LeaveRequestFormProps) {
225
- // 1. Get the typed activity from the workflow
226
- const activity = useMemo(() => new SimpleLeaveProcess().employeeInputActivity(), []);
227
-
228
- // 2. Hook options
229
- const options: UseActivityFormOptions<EmployeeInputActivity> = {
230
- activity_instance_id: activityInstanceId,
231
- defaultValues: {
232
- StartDate: undefined,
233
- EndDate: undefined,
234
- LeaveType: undefined,
235
- },
236
- mode: "onBlur",
237
- };
238
-
239
- // 3. Initialize hook
240
- const {
241
- register,
242
- handleSubmit,
243
- handleComplete,
244
- item,
245
- errors,
246
- isLoading,
247
- isSubmitting,
248
- loadError,
249
- } = useActivityForm(activity, options);
250
-
251
- if (isLoading) return <div>Loading...</div>;
252
- if (loadError) return <div>Error: {loadError.message}</div>;
253
-
254
- // 4. Handlers
255
- const onSaveSuccess = (): void => {
256
- console.log("Saved!");
257
- };
258
-
259
- const onCompleteSuccess = (): void => {
260
- console.log("Leave request submitted!");
261
- onComplete();
262
- };
263
-
264
- const onError = (error: FieldErrors | Error): void => {
265
- if (error instanceof Error) {
266
- console.error("API Error:", error.message);
267
- } else {
268
- console.error("Validation errors:", error);
269
- }
270
- };
271
-
272
- return (
273
- <form>
274
- <h2>Leave Request</h2>
275
-
276
- {/* Start Date */}
277
- <div>
278
- <label>{activity.StartDate.label}</label>
279
- <input type="date" {...register(activity.StartDate.id)} />
280
- {errors.StartDate && <span>{errors.StartDate.message}</span>}
281
- </div>
282
-
283
- {/* End Date */}
284
- <div>
285
- <label>{activity.EndDate.label}</label>
286
- <input type="date" {...register(activity.EndDate.id)} />
287
- {errors.EndDate && <span>{errors.EndDate.message}</span>}
288
- </div>
289
-
290
- {/* Leave Type */}
291
- <div>
292
- <label>{activity.LeaveType.label}</label>
293
- <select {...register(activity.LeaveType.id)}>
294
- <option value="">Select type</option>
295
- <option value="PTO">PTO</option>
296
- <option value="Sick">Sick</option>
297
- <option value="Parental">Parental</option>
298
- </select>
299
- {errors.LeaveType && <span>{errors.LeaveType.message}</span>}
300
- </div>
301
-
302
- {/* Leave Days (readonly — auto-disabled, computed by server) */}
303
- <div>
304
- <label>{activity.LeaveDays.label}</label>
305
- <input type="number" {...register(activity.LeaveDays.id)} />
306
- </div>
307
-
308
- {/* Actions */}
309
- <div>
310
- <button type="button" onClick={handleSubmit(onSaveSuccess, onError)}>
311
- {isSubmitting ? "Saving..." : "Save Draft"}
312
- </button>
313
- <button type="button" onClick={handleComplete(onCompleteSuccess, onError)}>
314
- {isSubmitting ? "Submitting..." : "Submit Leave Request"}
315
- </button>
316
- </div>
317
- </form>
318
- );
319
- }
320
- ```
321
-
322
- ---
323
-
324
- ## Example: Manager Approval Form
325
-
326
- ```tsx
327
- import { useMemo } from "react";
328
- import { useActivityForm } from "@ram_28/kf-ai-sdk/workflow";
329
- import type { UseActivityFormOptions } from "@ram_28/kf-ai-sdk/workflow";
330
- import type { FieldErrors } from "react-hook-form";
331
- import { SimpleLeaveProcess, ManagerApprovalActivity } from "@/bdo/workflows/SimpleLeaveProcess";
332
-
333
- interface ApprovalFormProps {
334
- activityInstanceId: string;
335
- onComplete: () => void;
336
- }
337
-
338
- function ApprovalForm({ activityInstanceId, onComplete }: ApprovalFormProps) {
339
- const activity = useMemo(() => new SimpleLeaveProcess().managerApprovalActivity(), []);
340
-
341
- const options: UseActivityFormOptions<ManagerApprovalActivity> = {
342
- activity_instance_id: activityInstanceId,
343
- defaultValues: {
344
- ManagerApproved: false,
345
- ManagerReason: "",
346
- },
347
- mode: "onBlur",
348
- };
349
-
350
- const {
351
- register,
352
- handleComplete,
353
- errors,
354
- isLoading,
355
- isSubmitting,
356
- loadError,
357
- } = useActivityForm(activity, options);
358
-
359
- if (isLoading) return <div>Loading...</div>;
360
- if (loadError) return <div>Error: {loadError.message}</div>;
361
-
362
- const onSuccess = (): void => {
363
- console.log("Approval submitted!");
364
- onComplete();
365
- };
366
-
367
- const onError = (error: FieldErrors | Error): void => {
368
- if (error instanceof Error) console.error("API Error:", error.message);
369
- };
370
-
371
- return (
372
- <form>
373
- <h2>Leave Approval</h2>
374
-
375
- <div>
376
- <label>
377
- <input type="checkbox" {...register(activity.ManagerApproved.id)} />
378
- {activity.ManagerApproved.label}
379
- </label>
380
- </div>
381
-
382
- <div>
383
- <label>{activity.ManagerReason.label}</label>
384
- <textarea {...register(activity.ManagerReason.id)} rows={4} />
385
- </div>
386
-
387
- <button type="button" onClick={handleComplete(onSuccess, onError)}>
388
- {isSubmitting ? "Submitting..." : "Submit Decision"}
389
- </button>
390
- </form>
391
- );
392
- }
393
- ```