@ram_28/kf-ai-sdk 2.0.15 → 2.0.17

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 (130) hide show
  1. package/README.md +22 -14
  2. package/dist/api.cjs +1 -1
  3. package/dist/api.mjs +1 -1
  4. package/dist/auth/authConfig.d.ts +1 -1
  5. package/dist/auth/types.d.ts +1 -1
  6. package/dist/auth/types.d.ts.map +1 -1
  7. package/dist/auth.cjs +1 -1
  8. package/dist/auth.mjs +1 -1
  9. package/dist/bdo/core/BaseBdo.d.ts +1 -1
  10. package/dist/bdo.cjs +1 -1
  11. package/dist/bdo.mjs +3 -3
  12. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts +1 -1
  13. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
  14. package/dist/components/hooks/useActivityForm/types.d.ts +6 -7
  15. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  16. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  17. package/dist/components/hooks/useActivityTable/types.d.ts +7 -6
  18. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  19. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +1 -1
  20. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  21. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
  22. package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
  23. package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
  24. package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
  25. package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
  26. package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
  27. package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
  28. package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
  29. package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
  30. package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
  31. package/dist/components/hooks/useBDOTable/types.d.ts +20 -14
  32. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  33. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
  34. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  35. package/dist/{constants-ConHc1oS.js → constants-Cyi942Yr.js} +5 -5
  36. package/dist/constants-DEmYwKfC.cjs +1 -0
  37. package/dist/filter.cjs +1 -1
  38. package/dist/filter.mjs +1 -1
  39. package/dist/form.cjs +1 -1
  40. package/dist/form.d.ts +1 -1
  41. package/dist/form.d.ts.map +1 -1
  42. package/dist/form.mjs +250 -253
  43. package/dist/form.types.d.ts +1 -1
  44. package/dist/form.types.d.ts.map +1 -1
  45. package/dist/shared-5a7UkED1.js +1180 -0
  46. package/dist/shared-nnmlRVs7.cjs +1 -0
  47. package/dist/table.cjs +1 -1
  48. package/dist/table.mjs +14 -14
  49. package/dist/table.types.d.ts +1 -1
  50. package/dist/table.types.d.ts.map +1 -1
  51. package/dist/types/constants.d.ts +4 -4
  52. package/dist/workflow/Activity.d.ts +22 -7
  53. package/dist/workflow/Activity.d.ts.map +1 -1
  54. package/dist/workflow/client.d.ts +2 -2
  55. package/dist/workflow/client.d.ts.map +1 -1
  56. package/dist/workflow/types.d.ts +7 -3
  57. package/dist/workflow/types.d.ts.map +1 -1
  58. package/dist/workflow.cjs +1 -1
  59. package/dist/workflow.mjs +518 -576
  60. package/docs/README.md +51 -0
  61. package/docs/bdo/README.md +161 -0
  62. package/docs/bdo/api_reference.md +281 -0
  63. package/docs/examples/bdo/create-product.md +69 -0
  64. package/docs/examples/bdo/edit-product-dialog.md +95 -0
  65. package/docs/examples/bdo/filtered-product-table.md +100 -0
  66. package/docs/examples/bdo/product-listing.md +73 -0
  67. package/docs/examples/bdo/supplier-dropdown.md +60 -0
  68. package/docs/examples/workflow/approve-leave-request.md +76 -0
  69. package/docs/examples/workflow/filtered-activity-table.md +101 -0
  70. package/docs/examples/workflow/my-pending-requests.md +90 -0
  71. package/docs/examples/workflow/start-new-workflow.md +47 -0
  72. package/docs/examples/workflow/submit-leave-request.md +72 -0
  73. package/docs/examples/workflow/workflow-progress.md +49 -0
  74. package/docs/useActivityForm/README.md +241 -0
  75. package/docs/useActivityForm/api_reference.md +279 -0
  76. package/docs/useActivityTable/README.md +263 -0
  77. package/docs/useActivityTable/api_reference.md +294 -0
  78. package/docs/useBDOForm/README.md +172 -0
  79. package/docs/useBDOForm/api_reference.md +244 -0
  80. package/docs/useBDOTable/README.md +242 -0
  81. package/docs/useBDOTable/api_reference.md +253 -0
  82. package/docs/useFilter/README.md +323 -0
  83. package/docs/useFilter/api_reference.md +228 -0
  84. package/docs/workflow/README.md +158 -0
  85. package/docs/workflow/api_reference.md +161 -0
  86. package/package.json +2 -2
  87. package/sdk/auth/authConfig.ts +1 -1
  88. package/sdk/auth/types.ts +1 -1
  89. package/sdk/bdo/core/BaseBdo.ts +2 -2
  90. package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +1 -1
  91. package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +1 -1
  92. package/sdk/components/hooks/useActivityForm/types.ts +8 -10
  93. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +52 -265
  94. package/sdk/components/hooks/useActivityTable/types.ts +6 -5
  95. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +14 -43
  96. package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
  97. package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
  98. package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
  99. package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
  100. package/sdk/components/hooks/useBDOTable/types.ts +20 -12
  101. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +12 -7
  102. package/sdk/form.ts +2 -2
  103. package/sdk/form.types.ts +4 -4
  104. package/sdk/table.types.ts +2 -0
  105. package/sdk/types/constants.ts +4 -4
  106. package/sdk/workflow/Activity.ts +68 -13
  107. package/sdk/workflow/client.ts +65 -25
  108. package/sdk/workflow/types.ts +10 -2
  109. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
  110. package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
  111. package/dist/components/hooks/useForm/index.d.ts +0 -5
  112. package/dist/components/hooks/useForm/index.d.ts.map +0 -1
  113. package/dist/components/hooks/useForm/types.d.ts.map +0 -1
  114. package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
  115. package/dist/constants-QX2RX-wu.cjs +0 -1
  116. package/dist/createResolver-AIgUwoS6.cjs +0 -1
  117. package/dist/createResolver-ZHXQ7QMa.js +0 -1078
  118. package/docs/api.md +0 -95
  119. package/docs/bdo.md +0 -224
  120. package/docs/gaps.md +0 -410
  121. package/docs/useActivityTable.md +0 -481
  122. package/docs/useBDOTable.md +0 -317
  123. package/docs/useFilter.md +0 -188
  124. package/docs/useForm.md +0 -376
  125. package/docs/workflow.md +0 -818
  126. /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
  127. /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
  128. /package/docs/{useAuth.md → useAuth/README.md} +0 -0
  129. /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
  130. /package/sdk/components/hooks/{useForm → useBDOForm}/createResolver.ts +0 -0
package/docs/workflow.md DELETED
@@ -1,818 +0,0 @@
1
- # Workflow SDK API
2
-
3
- The Workflow SDK provides a type-safe client for orchestrating business processes (workflows). Each workflow has typed Activity classes with field definitions, and a React hook (`useActivityForm`) for building forms bound to activity input fields.
4
-
5
- ## Imports
6
-
7
- ```typescript
8
- // Runtime exports
9
- import {
10
- Workflow,
11
- Activity,
12
- ActivityInstance,
13
- useActivityForm,
14
- useActivityTable,
15
- ActivityTableStatus,
16
- } from "@ram_28/kf-ai-sdk/workflow";
17
-
18
- // Type-only exports
19
- import type {
20
- ActivityInstanceFieldsType,
21
- ActivityProgressType,
22
- WorkflowStartResponseType,
23
- UseActivityFormOptions,
24
- UseActivityFormReturn,
25
- UseActivityTableOptionsType,
26
- UseActivityTableReturnType,
27
- ActivityTableStatusType,
28
- ActivityRowType,
29
- } from "@ram_28/kf-ai-sdk/workflow";
30
-
31
- // Field classes (for defining Activity fields)
32
- import {
33
- StringField,
34
- NumberField,
35
- BooleanField,
36
- DateField,
37
- DateTimeField,
38
- SelectField,
39
- ReferenceField,
40
- } from '@ram_28/kf-ai-sdk/bdo/fields';
41
-
42
- // Field types (for entity type definitions)
43
- import type {
44
- StringFieldType,
45
- NumberFieldType,
46
- BooleanFieldType,
47
- DateFieldType,
48
- DateTimeFieldType,
49
- SelectFieldType,
50
- ReferenceFieldType,
51
- } from '@ram_28/kf-ai-sdk/types';
52
- ```
53
-
54
- ---
55
-
56
- ## Type Definitions
57
-
58
- ### WorkflowStartResponseType
59
-
60
- ```typescript
61
- interface WorkflowStartResponseType {
62
- BPInstanceId: string; // Business process instance ID
63
- ActivityId: string; // First activity ID in the workflow
64
- _id: string; // Activity instance ID
65
- }
66
- ```
67
-
68
- ### ActivityProgressType
69
-
70
- ```typescript
71
- interface ActivityProgressType {
72
- ActivityId: string;
73
- ActivityInstanceId: string;
74
- ActivityType: string;
75
- AssignedTo: { Type: string; _id: string }[];
76
- CompletedAt: string | null;
77
- CompletedBy: { _id: string; _name: string } | null;
78
- Status: "COMPLETED" | "IN_PROGRESS";
79
- _name: string;
80
- }
81
- ```
82
-
83
- ### ActivityInstanceFieldsType
84
-
85
- System fields present on every activity instance. Returned alongside activity-specific fields from `getInProgressList()` and `getCompletedList()`.
86
-
87
- ```typescript
88
- type ActivityInstanceFieldsType = {
89
- _id: StringFieldType;
90
- Status: SelectFieldType<"InProgress" | "Completed">;
91
- AssignedTo: UserFieldType[];
92
- CompletedAt: DateTimeFieldType;
93
- };
94
- ```
95
-
96
- ### Activity Table Types
97
-
98
- See the dedicated [useActivityTable documentation](./useActivityTable.md) for `ActivityTableStatus`, `ActivityRowType`, `UseActivityTableOptionsType`, and `UseActivityTableReturnType`.
99
-
100
- **Key change:** Entity fields are now nested under `ADO` instead of being flattened at the top level. Access entity fields as `row.ADO.FieldName`.
101
-
102
-
103
- ### UseActivityFormOptions\<A\>
104
-
105
- ```typescript
106
- interface UseActivityFormOptions<A extends Activity<any, any, any>> {
107
- /** Activity instance identifier (from wf.start() or getInProgressList()) */
108
- activity_instance_id: string;
109
-
110
- /** Default form values */
111
- defaultValues?: Partial<ExtractActivityEditable<A>>;
112
-
113
- /** Validation mode (default: "onBlur") */
114
- mode?: "onBlur" | "onChange" | "onSubmit" | "onTouched" | "all";
115
-
116
- /** Whether to load activity data on mount (default: true) */
117
- enabled?: boolean;
118
- }
119
- ```
120
-
121
- ### UseActivityFormReturn\<A\>
122
-
123
- ```typescript
124
- interface UseActivityFormReturn<A extends Activity<any, any, any>> {
125
- // Core
126
- item: FormItemType<EditableFields, ReadonlyFields>;
127
- activity: A;
128
- register: FormRegisterType<EditableFields, ReadonlyFields>;
129
- handleSubmit: HandleSubmitType; // Save the activity form
130
- handleComplete: HandleSubmitType; // Complete the activity
131
-
132
- // RHF methods
133
- watch: UseFormWatch;
134
- setValue: UseFormSetValue;
135
- getValues: UseFormGetValues;
136
- reset: UseFormReset;
137
- trigger: UseFormTrigger;
138
- control: Control;
139
-
140
- // Form state
141
- errors: FieldErrors;
142
- isValid: boolean;
143
- isDirty: boolean;
144
- isSubmitting: boolean;
145
- isSubmitSuccessful: boolean;
146
-
147
- // Loading
148
- isLoading: boolean;
149
- loadError: Error | null;
150
- hasError: boolean;
151
-
152
- // Operations
153
- clearErrors: () => void;
154
- }
155
- ```
156
-
157
- ### File & Image Types
158
-
159
- Image accessor: `item.field.get()` returns `FileType | null`. Has `upload(file: File)`, `deleteAttachment()`, `getDownloadUrl()`.
160
- File accessor: `item.field.get()` returns `FileType[]`. Has `upload(files: File[])`, `deleteAttachment(id)`, `getDownloadUrl(id)`.
161
-
162
- Activity forms always have an instance ID, so attachment operations work immediately — no draft creation is needed.
163
-
164
- ---
165
-
166
- ## Generated Workflow SDK
167
-
168
- Each workflow generates a TypeScript SDK with typed Activity classes and a Workflow class. These are defined in `src/bdo/workflows/` and should never be created manually.
169
-
170
- ### Example: SimpleLeaveProcess SDK
171
-
172
- ```typescript
173
- // --- Activity classes ---
174
-
175
- export type EmployeeInputEntityType = {
176
- StartDate: DateFieldType;
177
- EndDate: DateFieldType;
178
- LeaveType: SelectFieldType<"PTO" | "Sick" | "Parental">;
179
- LeaveDays: NumberFieldType;
180
- };
181
-
182
- export type EmployeeInputEditable = Omit<EmployeeInputEntityType, "LeaveDays">;
183
- export type EmployeeInputReadonly = Pick<EmployeeInputEntityType, "LeaveDays">;
184
-
185
- export class EmployeeInputActivity extends Activity<
186
- EmployeeInputEntityType,
187
- EmployeeInputEditable,
188
- EmployeeInputReadonly
189
- > {
190
- readonly meta = {
191
- businessProcessId: "SimpleLeaveProcess",
192
- activityId: "EMPLOYEE_INPUT",
193
- };
194
-
195
- readonly StartDate = new DateField({ "_id": "StartDate", "Name": "Start Date", "Type": "Date" });
196
- readonly EndDate = new DateField({ "_id": "EndDate", "Name": "End Date", "Type": "Date" });
197
- readonly LeaveType = new SelectField<"PTO" | "Sick" | "Parental">({
198
- "_id": "LeaveType", "Name": "Leave Type", "Type": "String",
199
- "Constraint": { "Enum": ["PTO", "Sick", "Parental"] },
200
- });
201
- readonly LeaveDays = new NumberField({ "_id": "LeaveDays", "Name": "Leave Days", "Type": "Number", "ReadOnly": true });
202
- }
203
-
204
- export type ManagerApprovalEntityType = {
205
- ManagerApproved: BooleanFieldType;
206
- ManagerReason: StringFieldType;
207
- };
208
-
209
- export class ManagerApprovalActivity extends Activity<
210
- ManagerApprovalEntityType,
211
- ManagerApprovalEntityType,
212
- {}
213
- > {
214
- readonly meta = {
215
- businessProcessId: "SimpleLeaveProcess",
216
- activityId: "MANAGER_APPROVAL",
217
- };
218
-
219
- readonly ManagerApproved = new BooleanField({ "_id": "ManagerApproved", "Name": "Manager Approved", "Type": "Boolean" });
220
- readonly ManagerReason = new StringField({ "_id": "ManagerReason", "Name": "Manager's Reason", "Type": "String" });
221
- }
222
-
223
- // --- Workflow class ---
224
-
225
- export class SimpleLeaveProcess {
226
- async start(): Promise<WorkflowStartResponseType>;
227
- async progress(instance_id: string): Promise<ActivityProgressType[]>;
228
-
229
- employeeInputActivity(): EmployeeInputActivity;
230
- managerApprovalActivity(): ManagerApprovalActivity;
231
- }
232
- ```
233
-
234
- ---
235
-
236
- ## Workflow Class
237
-
238
- ### start()
239
-
240
- Start a new workflow instance.
241
-
242
- ```typescript
243
- const wf = new SimpleLeaveProcess();
244
- const { BPInstanceId, ActivityId, _id } = await wf.start();
245
- ```
246
-
247
- ### progress(instance_id)
248
-
249
- Get progress for a specific process instance. Returns a list of progress entries for each stage/activity.
250
-
251
- ```typescript
252
- const wf = new SimpleLeaveProcess();
253
- const { BPInstanceId } = await wf.start();
254
- const progressList = await wf.progress(BPInstanceId);
255
- // progressList: ActivityProgressType[]
256
- for (const entry of progressList) {
257
- console.log(entry._name, entry.Status, entry.CompletedAt);
258
- }
259
- ```
260
-
261
- **Endpoint:** `GET /api/app/process/{bp_id}/{instance_id}/progress`
262
-
263
- ---
264
-
265
- ## Activity Class
266
-
267
- Each Activity class provides methods to query and access activity instances. List and metric operations are split by status (`inprogress` / `completed`).
268
-
269
- ```typescript
270
- const activity = wf.employeeInputActivity();
271
- ```
272
-
273
- ### getInProgressList(options?)
274
-
275
- List in-progress activity instances. Accepts optional `ListOptionsType` payload for server-side filtering, sorting, and pagination.
276
-
277
- ```typescript
278
- // No options — returns all in-progress items (default pagination)
279
- const result = await activity.getInProgressList();
280
-
281
- for (const item of result.Data) {
282
- console.log(item._id, item.Status, item.StartDate);
283
- }
284
-
285
- // With options — server-side filter, sort, and pagination
286
- const filtered = await activity.getInProgressList({
287
- Filter: { Operator: 'And', Condition: [{ LHSField: 'Status', Operator: 'EQ', RHSValue: 'InProgress', RHSType: 'Constant' }] },
288
- Sort: [{ '_created_at': 'DESC' }],
289
- Page: 1,
290
- PageSize: 10,
291
- });
292
- ```
293
-
294
- ### getCompletedList(options?)
295
-
296
- List completed activity instances. Same options as `getInProgressList`.
297
-
298
- ```typescript
299
- const result = await activity.getCompletedList();
300
-
301
- for (const item of result.Data) {
302
- console.log(item._id, item.CompletedAt, item.StartDate);
303
- }
304
- ```
305
-
306
- ### inProgressMetrics(options?)
307
-
308
- Get count of in-progress activity instances. Returns `CountResponseType` (`{ Count: number }`).
309
-
310
- ```typescript
311
- const { Count } = await activity.inProgressMetrics();
312
- console.log('In-progress count:', Count);
313
- ```
314
-
315
- ### completedMetrics(options?)
316
-
317
- Get count of completed activity instances. Returns `CountResponseType` (`{ Count: number }`).
318
-
319
- ```typescript
320
- const { Count } = await activity.completedMetrics();
321
- console.log('Completed count:', Count);
322
- ```
323
-
324
- ### getInstance(instanceId)
325
-
326
- Get a typed ActivityInstance with field accessors and persistence methods.
327
-
328
- ```typescript
329
- const instance = await activity.getInstance("inst_abc123");
330
-
331
- // Field accessors (BDO Item pattern)
332
- instance._id; // "inst_abc123"
333
- instance.StartDate.get(); // read value (typed)
334
- instance.StartDate.set("2026-03-01"); // set value (editable fields only)
335
- instance.StartDate.meta; // { _id: "StartDate", Name: "Start Date", Type: "Date" }
336
- instance.LeaveDays.get(); // read computed/readonly field
337
- // instance.LeaveDays.set(...) // NOT available — readonly, no set()
338
-
339
- // Utility methods
340
- instance.toJSON(); // convert to plain object
341
- instance.validate(); // validate all fields
342
-
343
- // Persistence methods
344
- await instance.update({ StartDate: "2026-03-01" }); // update fields
345
- await instance.save({ StartDate: "2026-03-01" }); // save and commit
346
- await instance.complete(); // complete the activity
347
- const progress = await instance.progress(); // get progress (ActivityProgressType[])
348
- ```
349
-
350
- ---
351
-
352
- ## useActivityForm Hook
353
-
354
- React hook for building forms bound to workflow activity input fields. Integrates with `react-hook-form`.
355
-
356
- ### Options
357
-
358
- | Property | Type | Default | Description |
359
- |----------|------|---------|-------------|
360
- | `activity_instance_id` | `string` | *required* | Activity instance ID (from `wf.start()` or `getInProgressList()`) |
361
- | `defaultValues` | `Partial<Editable>` | `{}` | Initial form values |
362
- | `mode` | `"onBlur" \| "onChange" \| "onSubmit" \| "onTouched" \| "all"` | `"onBlur"` | Validation timing |
363
- | `enabled` | `boolean` | `true` | Whether to load activity data on mount |
364
-
365
- ### Lifecycle
366
-
367
- ```
368
- Mount
369
- |
370
- |-> Load activity instance data -> populate form
371
- |
372
- v
373
- User edits field -> blurs
374
- |
375
- |-> Field validation (BaseField.validate)
376
- |-> If valid + readonly fields exist -> update computed fields
377
- |
378
- v
379
- User clicks Save
380
- |
381
- |-> handleSubmit -> save activity data
382
- |
383
- v
384
- User clicks Complete
385
- |
386
- |-> handleComplete -> complete activity
387
- ```
388
-
389
- ### Return Value
390
-
391
- | Property | Type | Description |
392
- |----------|------|-------------|
393
- | `item` | `FormItemType` | Proxy with typed field accessors (`.get()`, `.set()`, `.meta`) |
394
- | `activity` | `A` | The Activity instance |
395
- | `register` | `FormRegisterType` | Smart register (auto-disables readonly fields) |
396
- | `handleSubmit` | `HandleSubmitType` | Save activity data |
397
- | `handleComplete` | `HandleSubmitType` | Complete the activity |
398
- | `watch` | `UseFormWatch` | Watch field values |
399
- | `setValue` | `UseFormSetValue` | Set field value programmatically |
400
- | `getValues` | `UseFormGetValues` | Get current field values |
401
- | `reset` | `UseFormReset` | Reset form to default values |
402
- | `trigger` | `UseFormTrigger` | Trigger validation |
403
- | `control` | `Control` | RHF control (for Controller components) |
404
- | `errors` | `FieldErrors` | Validation errors |
405
- | `isValid` | `boolean` | Form is valid |
406
- | `isDirty` | `boolean` | Form has been modified |
407
- | `isSubmitting` | `boolean` | Currently submitting |
408
- | `isSubmitSuccessful` | `boolean` | Last submission succeeded |
409
- | `isLoading` | `boolean` | Loading activity data |
410
- | `loadError` | `Error \| null` | Load error |
411
- | `hasError` | `boolean` | Any error active |
412
- | `clearErrors` | `() => void` | Clear all form errors |
413
-
414
- ---
415
-
416
- ## useActivityTable Hook
417
-
418
- See the dedicated [useActivityTable documentation](./useActivityTable.md) for the full API reference, type definitions, and examples.
419
-
420
- `useActivityTable` now wraps the base `useTable` hook, providing the same search, sort, filter, and pagination capabilities as BDO tables. Entity fields are accessed via `row.ADO.FieldName`.
421
-
422
- ---
423
-
424
-
425
- ## Use Case: Employee Creating Leave
426
-
427
- ### Step 1 — Start the workflow
428
-
429
- ```typescript
430
- import { SimpleLeaveProcess } from "@/bdo/workflows/SimpleLeaveProcess";
431
- import type { WorkflowStartResponseType } from "@ram_28/kf-ai-sdk/workflow";
432
-
433
- const wf = new SimpleLeaveProcess();
434
- const { BPInstanceId, ActivityId, _id }: WorkflowStartResponseType = await wf.start();
435
-
436
- // Check progress at any time
437
- const progress = await wf.progress(BPInstanceId);
438
- ```
439
-
440
- ### Step 2 — React component with useActivityForm
441
-
442
- ```tsx
443
- import { useMemo } from "react";
444
- import { useActivityForm } from "@ram_28/kf-ai-sdk/workflow";
445
- import type { UseActivityFormOptions } from "@ram_28/kf-ai-sdk/workflow";
446
- import type { FieldErrors } from "react-hook-form";
447
- import { SimpleLeaveProcess, EmployeeInputActivity } from "@/bdo/workflows/SimpleLeaveProcess";
448
-
449
- interface LeaveRequestFormProps {
450
- activityInstanceId: string;
451
- onComplete: () => void;
452
- }
453
-
454
- function LeaveRequestForm({ activityInstanceId, onComplete }: LeaveRequestFormProps) {
455
- // 1. Get the typed activity from the workflow
456
- const activity = useMemo(() => new SimpleLeaveProcess().employeeInputActivity(), []);
457
-
458
- // 2. Hook options
459
- const options: UseActivityFormOptions<EmployeeInputActivity> = {
460
- activity_instance_id: activityInstanceId,
461
- defaultValues: {
462
- StartDate: undefined,
463
- EndDate: undefined,
464
- LeaveType: undefined,
465
- },
466
- mode: "onBlur",
467
- };
468
-
469
- // 3. Initialize hook
470
- const {
471
- register,
472
- handleSubmit,
473
- handleComplete,
474
- item,
475
- errors,
476
- isLoading,
477
- isSubmitting,
478
- loadError,
479
- } = useActivityForm(activity, options);
480
-
481
- if (isLoading) return <div>Loading...</div>;
482
- if (loadError) return <div>Error: {loadError.message}</div>;
483
-
484
- // 4. Handlers
485
- const onSaveSuccess = (): void => {
486
- console.log("Saved!");
487
- };
488
-
489
- const onCompleteSuccess = (): void => {
490
- console.log("Leave request submitted!");
491
- onComplete();
492
- };
493
-
494
- const onError = (error: FieldErrors | Error): void => {
495
- if (error instanceof Error) {
496
- console.error("API Error:", error.message);
497
- } else {
498
- console.error("Validation errors:", error);
499
- }
500
- };
501
-
502
- return (
503
- <form>
504
- <h2>Leave Request</h2>
505
-
506
- {/* Start Date */}
507
- <div>
508
- <label>{activity.StartDate.label}</label>
509
- <input type="date" {...register(activity.StartDate.id)} />
510
- {errors.StartDate && <span>{errors.StartDate.message}</span>}
511
- </div>
512
-
513
- {/* End Date */}
514
- <div>
515
- <label>{activity.EndDate.label}</label>
516
- <input type="date" {...register(activity.EndDate.id)} />
517
- {errors.EndDate && <span>{errors.EndDate.message}</span>}
518
- </div>
519
-
520
- {/* Leave Type */}
521
- <div>
522
- <label>{activity.LeaveType.label}</label>
523
- <select {...register(activity.LeaveType.id)}>
524
- <option value="">Select type</option>
525
- <option value="PTO">PTO</option>
526
- <option value="Sick">Sick</option>
527
- <option value="Parental">Parental</option>
528
- </select>
529
- {errors.LeaveType && <span>{errors.LeaveType.message}</span>}
530
- </div>
531
-
532
- {/* Leave Days (readonly — auto-disabled, computed by server) */}
533
- <div>
534
- <label>{activity.LeaveDays.label}</label>
535
- <input type="number" {...register(activity.LeaveDays.id)} />
536
- </div>
537
-
538
- {/* Actions */}
539
- <div>
540
- <button type="button" onClick={handleSubmit(onSaveSuccess, onError)}>
541
- {isSubmitting ? "Saving..." : "Save Draft"}
542
- </button>
543
- <button type="button" onClick={handleComplete(onCompleteSuccess, onError)}>
544
- {isSubmitting ? "Submitting..." : "Submit Leave Request"}
545
- </button>
546
- </div>
547
- </form>
548
- );
549
- }
550
- ```
551
-
552
- ### Full flow orchestration
553
-
554
- ```tsx
555
- import { useState } from "react";
556
- import { SimpleLeaveProcess } from "@/bdo/workflows/SimpleLeaveProcess";
557
- import type { WorkflowStartResponseType } from "@ram_28/kf-ai-sdk/workflow";
558
-
559
- function LeaveRequestPage() {
560
- const [instanceId, setInstanceId] = useState<string | null>(null);
561
-
562
- const startLeaveRequest = async () => {
563
- const wf = new SimpleLeaveProcess();
564
- const result: WorkflowStartResponseType = await wf.start();
565
- setInstanceId(result._id);
566
- };
567
-
568
- if (!instanceId) {
569
- return <button onClick={startLeaveRequest}>New Leave Request</button>;
570
- }
571
-
572
- return (
573
- <LeaveRequestForm
574
- activityInstanceId={instanceId}
575
- onComplete={() => setInstanceId(null)}
576
- />
577
- );
578
- }
579
- ```
580
-
581
- ---
582
-
583
- ## Use Case: Manager Approving Leave
584
-
585
- ### Step 1 — List in-progress items
586
-
587
- ```tsx
588
- import { useMemo, useState } from "react";
589
- import { useActivityTable, ActivityTableStatus } from "@ram_28/kf-ai-sdk/workflow";
590
- import { SimpleLeaveProcess, ManagerApprovalActivity } from "@/bdo/workflows/SimpleLeaveProcess";
591
-
592
- const wf = new SimpleLeaveProcess();
593
- const activity = wf.managerApprovalActivity();
594
-
595
- const { rows, totalItems, isLoading, error, pagination, refetch } = useActivityTable(activity, {
596
- status: ActivityTableStatus.InProgress,
597
- initialState: {
598
- pagination: { pageNo: 1, pageSize: 10 },
599
- },
600
- });
601
-
602
- if (isLoading) return <div>Loading...</div>;
603
- if (error) return <div>Error: {error.message}</div>;
604
-
605
- if (selectedId) {
606
- return (
607
- <ApprovalForm
608
- activityInstanceId={selectedId}
609
- onComplete={() => {
610
- setSelectedId(null);
611
- refetch();
612
- }}
613
- />
614
- );
615
- }
616
-
617
- return (
618
- <div>
619
- <h2>Pending Approvals ({totalItems})</h2>
620
- <table>
621
- <thead>
622
- <tr>
623
- <th>ID</th>
624
- <th>Status</th>
625
- <th>Assigned To</th>
626
- <th>Approved</th>
627
- <th>Reason</th>
628
- <th>Action</th>
629
- </tr>
630
- </thead>
631
- <tbody>
632
- {rows.map((row) => (
633
- <tr key={row._id}>
634
- <td>{row._id}</td>
635
- <td>{row.Status}</td>
636
- <td>{row.AssignedTo.map((u) => u._name).join(", ")}</td>
637
- <td>{row.ADO.ManagerApproved ? "Yes" : "No"}</td>
638
- <td>{row.ADO.ManagerReason}</td>
639
- <td>
640
- <button onClick={() => setSelectedId(row._id)}>Review</button>
641
- </td>
642
- </tr>
643
- ))}
644
- </tbody>
645
- </table>
646
- <div>
647
- <button onClick={pagination.goToPrevious} disabled={!pagination.canGoPrevious}>Previous</button>
648
- <span>Page {pagination.pageNo} of {pagination.totalPages}</span>
649
- <button onClick={pagination.goToNext} disabled={!pagination.canGoNext}>Next</button>
650
- </div>
651
- </div>
652
- );
653
- }
654
- ```
655
-
656
- ### Step 2 — Approval form component
657
-
658
- ```tsx
659
- import { useMemo } from "react";
660
- import { useActivityForm } from "@ram_28/kf-ai-sdk/workflow";
661
- import type { UseActivityFormOptions } from "@ram_28/kf-ai-sdk/workflow";
662
- import type { FieldErrors } from "react-hook-form";
663
- import { SimpleLeaveProcess, ManagerApprovalActivity } from "@/bdo/workflows/SimpleLeaveProcess";
664
-
665
- interface ApprovalFormProps {
666
- activityInstanceId: string;
667
- onComplete: () => void;
668
- }
669
-
670
- function ApprovalForm({ activityInstanceId, onComplete }: ApprovalFormProps) {
671
- const activity = useMemo(() => new SimpleLeaveProcess().managerApprovalActivity(), []);
672
-
673
- const options: UseActivityFormOptions<ManagerApprovalActivity> = {
674
- activity_instance_id: activityInstanceId,
675
- defaultValues: {
676
- ManagerApproved: false,
677
- ManagerReason: "",
678
- },
679
- mode: "onBlur",
680
- };
681
-
682
- const {
683
- register,
684
- handleComplete,
685
- errors,
686
- isLoading,
687
- isSubmitting,
688
- loadError,
689
- } = useActivityForm(activity, options);
690
-
691
- if (isLoading) return <div>Loading...</div>;
692
- if (loadError) return <div>Error: {loadError.message}</div>;
693
-
694
- const onSuccess = (): void => {
695
- console.log("Approval submitted!");
696
- onComplete();
697
- };
698
-
699
- const onError = (error: FieldErrors | Error): void => {
700
- if (error instanceof Error) console.error("API Error:", error.message);
701
- };
702
-
703
- return (
704
- <form>
705
- <h2>Leave Approval</h2>
706
-
707
- <div>
708
- <label>
709
- <input type="checkbox" {...register(activity.ManagerApproved.id)} />
710
- {activity.ManagerApproved.label}
711
- </label>
712
- </div>
713
-
714
- <div>
715
- <label>{activity.ManagerReason.label}</label>
716
- <textarea {...register(activity.ManagerReason.id)} rows={4} />
717
- </div>
718
-
719
- <button type="button" onClick={handleComplete(onSuccess, onError)}>
720
- {isSubmitting ? "Submitting..." : "Submit Decision"}
721
- </button>
722
- </form>
723
- );
724
- }
725
- ```
726
-
727
- ---
728
-
729
- ## Use Case: Programmatic ActivityInstance
730
-
731
- For non-form scenarios (scripts, server-side, batch processing):
732
-
733
- ```typescript
734
- import { SimpleLeaveProcess } from "@/bdo/workflows/SimpleLeaveProcess";
735
-
736
- const wf = new SimpleLeaveProcess();
737
- const activity = wf.employeeInputActivity();
738
-
739
- // Get a typed instance
740
- const instance = await activity.getInstance("inst_abc123");
741
-
742
- // Read fields
743
- console.log(instance.StartDate.get()); // "2026-02-01"
744
- console.log(instance.LeaveType.get()); // "PTO"
745
- console.log(instance.LeaveDays.get()); // 5 (computed)
746
-
747
- // Write editable fields
748
- instance.StartDate.set("2026-03-01");
749
- instance.EndDate.set("2026-03-05");
750
-
751
- // Field metadata
752
- console.log(instance.StartDate.label); // "Start Date"
753
-
754
- // Persist changes
755
- await instance.update({ StartDate: "2026-03-01", EndDate: "2026-03-05" });
756
-
757
- // Save and commit
758
- await instance.save({ StartDate: "2026-03-01", EndDate: "2026-03-05" });
759
-
760
- // Complete activity
761
- await instance.complete();
762
-
763
- // Check progress (returns ActivityProgressType[])
764
- const progress = await instance.progress();
765
- ```
766
-
767
- ---
768
-
769
- ## Filtering Reference
770
-
771
- Status filtering is built into the method names (`getInProgressList` / `getCompletedList`). Internal filters (ActivityId, Status, AssignedTo) are **always applied** by the backend. Frontend filters passed via `ListOptionsType` are AND-merged with the internal filters.
772
-
773
- All four list/metric endpoints now use **POST** with an optional `ListOptionsType` body (same shape as BDO list API: `{ Filter, Sort, Page, PageSize }`).
774
-
775
- ### In-progress items
776
-
777
- ```typescript
778
- // No options — returns all (default pagination)
779
- const result = await activity.getInProgressList();
780
-
781
- // With filter + pagination
782
- const result = await activity.getInProgressList({
783
- Sort: [{ '_created_at': 'DESC' }],
784
- Page: 1,
785
- PageSize: 25,
786
- });
787
- ```
788
-
789
- ### Completed items
790
-
791
- ```typescript
792
- const result = await activity.getCompletedList({
793
- Page: 1,
794
- PageSize: 25,
795
- });
796
- ```
797
-
798
- ### Process progress
799
-
800
- ```typescript
801
- const wf = new SimpleLeaveProcess();
802
- const { BPInstanceId } = await wf.start();
803
- const progressList = await wf.progress(BPInstanceId);
804
- // Returns ActivityProgressType[] — one entry per activity in the process
805
- ```
806
-
807
- ---
808
-
809
- ## ActivityInstance System Fields Reference
810
-
811
- | Field | Type | Description |
812
- |-------|------|-------------|
813
- | `_id` | `StringFieldType` | Unique activity instance identifier |
814
- | `Status` | `SelectFieldType<"InProgress" \| "Completed">` | Current status |
815
- | `AssignedTo` | `UserFieldType[]` | Assigned users (each has `._id` and `._name`) |
816
- | `CompletedAt` | `DateTimeFieldType` | Completion timestamp (`"YYYY-MM-DDTHH:MM:SS"`) |
817
-
818
- ---