@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.
- package/README.md +16 -8
- package/dist/{FileField-BWrSHNRq.js → FileField-CZjS2uLh.js} +3 -3
- package/dist/{FileField-eDeuzln8.cjs → FileField-DU4UWo_t.cjs} +1 -1
- package/dist/api.cjs +1 -1
- package/dist/api.mjs +1 -1
- package/dist/auth/authConfig.d.ts +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/Item.d.ts +0 -4
- package/dist/bdo/core/Item.d.ts.map +1 -1
- package/dist/bdo/fields/ReferenceField.d.ts +1 -1
- 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 +1 -1
- package/dist/bdo/fields/UserField.d.ts.map +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +53 -62
- package/dist/components/hooks/useActivityForm/types.d.ts +4 -5
- package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/types.d.ts +5 -4
- package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
- package/dist/components/hooks/useBDOForm/createItemProxy.d.ts +2 -3
- package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useBDOTable/types.d.ts +20 -12
- package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
- package/dist/{constants-ConHc1oS.js → constants-Cyi942Yr.js} +5 -5
- package/dist/constants-DEmYwKfC.cjs +1 -0
- package/dist/filter.cjs +1 -1
- package/dist/filter.mjs +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +226 -243
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +15 -16
- package/dist/table.types.d.ts +1 -1
- package/dist/table.types.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/workflow/Activity.d.ts +8 -5
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +461 -476
- package/docs/README.md +57 -0
- package/docs/bdo/README.md +161 -0
- package/docs/bdo/api_reference.md +281 -0
- package/docs/examples/bdo/create-product.md +69 -0
- package/docs/examples/bdo/edit-product-dialog.md +95 -0
- package/docs/examples/bdo/filtered-product-table.md +100 -0
- package/docs/examples/bdo/product-listing.md +73 -0
- package/docs/examples/bdo/supplier-dropdown.md +60 -0
- package/docs/examples/fields/complex-fields.md +248 -0
- package/docs/examples/fields/primitive-fields.md +217 -0
- package/docs/examples/workflow/approve-leave-request.md +76 -0
- package/docs/examples/workflow/filtered-activity-table.md +101 -0
- package/docs/examples/workflow/my-pending-requests.md +90 -0
- package/docs/examples/workflow/start-new-workflow.md +47 -0
- package/docs/examples/workflow/submit-leave-request.md +72 -0
- package/docs/examples/workflow/workflow-progress.md +49 -0
- package/docs/fields/README.md +141 -0
- package/docs/fields/api_reference.md +134 -0
- package/docs/useActivityForm/README.md +244 -0
- package/docs/useActivityForm/api_reference.md +279 -0
- package/docs/useActivityTable/README.md +263 -0
- package/docs/useActivityTable/api_reference.md +294 -0
- package/docs/useBDOForm/README.md +175 -0
- package/docs/useBDOForm/api_reference.md +244 -0
- package/docs/useBDOTable/README.md +242 -0
- package/docs/useBDOTable/api_reference.md +253 -0
- package/docs/useFilter/README.md +323 -0
- package/docs/useFilter/api_reference.md +228 -0
- package/docs/workflow/README.md +158 -0
- package/docs/workflow/api_reference.md +161 -0
- package/package.json +1 -1
- package/sdk/auth/authConfig.ts +1 -1
- package/sdk/auth/types.ts +1 -1
- package/sdk/bdo/core/Item.ts +1 -10
- package/sdk/bdo/fields/ReferenceField.ts +1 -1
- package/sdk/bdo/fields/SelectField.ts +1 -1
- package/sdk/bdo/fields/UserField.ts +1 -1
- package/sdk/components/hooks/useActivityForm/types.ts +4 -6
- package/sdk/components/hooks/useActivityForm/useActivityForm.ts +10 -73
- package/sdk/components/hooks/useActivityTable/types.ts +4 -5
- package/sdk/components/hooks/useActivityTable/useActivityTable.ts +10 -8
- package/sdk/components/hooks/useBDOForm/createItemProxy.ts +17 -58
- package/sdk/components/hooks/useBDOTable/types.ts +20 -10
- package/sdk/components/hooks/useBDOTable/useBDOTable.ts +12 -8
- package/sdk/table.types.ts +2 -0
- package/sdk/types/constants.ts +1 -1
- package/sdk/workflow/Activity.ts +39 -7
- package/dist/constants-QX2RX-wu.cjs +0 -1
- package/docs/api.md +0 -95
- package/docs/bdo.md +0 -224
- package/docs/gaps.md +0 -360
- package/docs/useActivityForm.md +0 -393
- package/docs/useActivityTable.md +0 -418
- package/docs/useBDOForm.md +0 -376
- package/docs/useBDOTable.md +0 -284
- package/docs/useFilter.md +0 -188
- package/docs/workflow.md +0 -560
- /package/docs/{useAuth.md → useAuth/README.md} +0 -0
package/docs/workflow.md
DELETED
|
@@ -1,560 +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
|
-
Entity fields and system fields are flat at the top level, same as BDO tables. Access entity fields as `row.FieldName`.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
### UseActivityFormOptions\<A\> / UseActivityFormReturn\<A\>
|
|
104
|
-
|
|
105
|
-
See the dedicated [useActivityForm documentation](./useActivityForm.md) for the full type definitions.
|
|
106
|
-
|
|
107
|
-
### File & Image Types
|
|
108
|
-
|
|
109
|
-
Image accessor: `item.field.get()` returns `FileType | null`. Has `upload(file: File)`, `deleteAttachment()`, `getDownloadUrl()`.
|
|
110
|
-
File accessor: `item.field.get()` returns `FileType[]`. Has `upload(files: File[])`, `deleteAttachment(id)`, `getDownloadUrl(id)`.
|
|
111
|
-
|
|
112
|
-
Activity forms always have an instance ID, so attachment operations work immediately — no draft creation is needed.
|
|
113
|
-
|
|
114
|
-
---
|
|
115
|
-
|
|
116
|
-
## Generated Workflow SDK
|
|
117
|
-
|
|
118
|
-
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.
|
|
119
|
-
|
|
120
|
-
### Example: SimpleLeaveProcess SDK
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
// --- Activity classes ---
|
|
124
|
-
|
|
125
|
-
export type EmployeeInputEntityType = {
|
|
126
|
-
StartDate: DateFieldType;
|
|
127
|
-
EndDate: DateFieldType;
|
|
128
|
-
LeaveType: SelectFieldType<"PTO" | "Sick" | "Parental">;
|
|
129
|
-
LeaveDays: NumberFieldType;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export type EmployeeInputEditable = Omit<EmployeeInputEntityType, "LeaveDays">;
|
|
133
|
-
export type EmployeeInputReadonly = Pick<EmployeeInputEntityType, "LeaveDays">;
|
|
134
|
-
|
|
135
|
-
export class EmployeeInputActivity extends Activity<
|
|
136
|
-
EmployeeInputEntityType,
|
|
137
|
-
EmployeeInputEditable,
|
|
138
|
-
EmployeeInputReadonly
|
|
139
|
-
> {
|
|
140
|
-
readonly meta = {
|
|
141
|
-
businessProcessId: "SimpleLeaveProcess",
|
|
142
|
-
activityId: "EMPLOYEE_INPUT",
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
readonly StartDate = new DateField({ "_id": "StartDate", "Name": "Start Date", "Type": "Date" });
|
|
146
|
-
readonly EndDate = new DateField({ "_id": "EndDate", "Name": "End Date", "Type": "Date" });
|
|
147
|
-
readonly LeaveType = new SelectField<"PTO" | "Sick" | "Parental">({
|
|
148
|
-
"_id": "LeaveType", "Name": "Leave Type", "Type": "String",
|
|
149
|
-
"Constraint": { "Enum": ["PTO", "Sick", "Parental"] },
|
|
150
|
-
});
|
|
151
|
-
readonly LeaveDays = new NumberField({ "_id": "LeaveDays", "Name": "Leave Days", "Type": "Number", "ReadOnly": true });
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export type ManagerApprovalEntityType = {
|
|
155
|
-
ManagerApproved: BooleanFieldType;
|
|
156
|
-
ManagerReason: StringFieldType;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export class ManagerApprovalActivity extends Activity<
|
|
160
|
-
ManagerApprovalEntityType,
|
|
161
|
-
ManagerApprovalEntityType,
|
|
162
|
-
{}
|
|
163
|
-
> {
|
|
164
|
-
readonly meta = {
|
|
165
|
-
businessProcessId: "SimpleLeaveProcess",
|
|
166
|
-
activityId: "MANAGER_APPROVAL",
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
readonly ManagerApproved = new BooleanField({ "_id": "ManagerApproved", "Name": "Manager Approved", "Type": "Boolean" });
|
|
170
|
-
readonly ManagerReason = new StringField({ "_id": "ManagerReason", "Name": "Manager's Reason", "Type": "String" });
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
// --- Workflow class ---
|
|
174
|
-
|
|
175
|
-
export class SimpleLeaveProcess {
|
|
176
|
-
async start(): Promise<WorkflowStartResponseType>;
|
|
177
|
-
async progress(instance_id: string): Promise<ActivityProgressType[]>;
|
|
178
|
-
|
|
179
|
-
employeeInputActivity(): EmployeeInputActivity;
|
|
180
|
-
managerApprovalActivity(): ManagerApprovalActivity;
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
---
|
|
185
|
-
|
|
186
|
-
## Workflow Class
|
|
187
|
-
|
|
188
|
-
### start()
|
|
189
|
-
|
|
190
|
-
Start a new workflow instance.
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
const wf = new SimpleLeaveProcess();
|
|
194
|
-
const { BPInstanceId, ActivityId, _id } = await wf.start();
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### progress(instance_id)
|
|
198
|
-
|
|
199
|
-
Get progress for a specific process instance. Returns a list of progress entries for each stage/activity.
|
|
200
|
-
|
|
201
|
-
```typescript
|
|
202
|
-
const wf = new SimpleLeaveProcess();
|
|
203
|
-
const { BPInstanceId } = await wf.start();
|
|
204
|
-
const progressList = await wf.progress(BPInstanceId);
|
|
205
|
-
// progressList: ActivityProgressType[]
|
|
206
|
-
for (const entry of progressList) {
|
|
207
|
-
console.log(entry._name, entry.Status, entry.CompletedAt);
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
**Endpoint:** `GET /api/app/process/{bp_id}/{instance_id}/progress`
|
|
212
|
-
|
|
213
|
-
---
|
|
214
|
-
|
|
215
|
-
## Activity Class
|
|
216
|
-
|
|
217
|
-
Each Activity class provides methods to query and access activity instances. List and metric operations are split by status (`inprogress` / `completed`).
|
|
218
|
-
|
|
219
|
-
```typescript
|
|
220
|
-
const activity = wf.employeeInputActivity();
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
### getInProgressList(options?)
|
|
224
|
-
|
|
225
|
-
List in-progress activity instances. Accepts optional `ListOptionsType` payload for server-side filtering, sorting, and pagination.
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
// No options — returns all in-progress items (default pagination)
|
|
229
|
-
const result = await activity.getInProgressList();
|
|
230
|
-
|
|
231
|
-
for (const item of result.Data) {
|
|
232
|
-
console.log(item._id, item.Status, item.StartDate);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// With options — server-side filter, sort, and pagination
|
|
236
|
-
const filtered = await activity.getInProgressList({
|
|
237
|
-
Filter: { Operator: 'And', Condition: [{ LHSField: 'Status', Operator: 'EQ', RHSValue: 'InProgress', RHSType: 'Constant' }] },
|
|
238
|
-
Sort: [{ '_created_at': 'DESC' }],
|
|
239
|
-
Page: 1,
|
|
240
|
-
PageSize: 10,
|
|
241
|
-
});
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
### getCompletedList(options?)
|
|
245
|
-
|
|
246
|
-
List completed activity instances. Same options as `getInProgressList`.
|
|
247
|
-
|
|
248
|
-
```typescript
|
|
249
|
-
const result = await activity.getCompletedList();
|
|
250
|
-
|
|
251
|
-
for (const item of result.Data) {
|
|
252
|
-
console.log(item._id, item.CompletedAt, item.StartDate);
|
|
253
|
-
}
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
### inProgressCount(options?)
|
|
257
|
-
|
|
258
|
-
Get count of in-progress activity instances. Returns `number`.
|
|
259
|
-
|
|
260
|
-
```typescript
|
|
261
|
-
const count = await activity.inProgressCount();
|
|
262
|
-
console.log('In-progress count:', count);
|
|
263
|
-
```
|
|
264
|
-
|
|
265
|
-
### completedCount(options?)
|
|
266
|
-
|
|
267
|
-
Get count of completed activity instances. Returns `number`.
|
|
268
|
-
|
|
269
|
-
```typescript
|
|
270
|
-
const count = await activity.completedCount();
|
|
271
|
-
console.log('Completed count:', count);
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### inProgressMetric(options)
|
|
275
|
-
|
|
276
|
-
Get aggregated metrics for in-progress activity instances. Accepts `Omit<MetricOptionsType, 'Type'>` for custom aggregations (Sum, Avg, Count, etc.). Returns `MetricResponseType` (`{ Data: Record<string, any>[] }`).
|
|
277
|
-
|
|
278
|
-
```typescript
|
|
279
|
-
const result = await activity.inProgressMetric({
|
|
280
|
-
GroupBy: ['Status'],
|
|
281
|
-
Metric: [{ Field: '_id', Type: 'Count' }],
|
|
282
|
-
});
|
|
283
|
-
console.log(result.Data);
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
### completedMetric(options)
|
|
287
|
-
|
|
288
|
-
Get aggregated metrics for completed activity instances. Same signature as `inProgressMetric`.
|
|
289
|
-
|
|
290
|
-
```typescript
|
|
291
|
-
const result = await activity.completedMetric({
|
|
292
|
-
GroupBy: [],
|
|
293
|
-
Metric: [{ Field: 'LeaveDays', Type: 'Sum' }],
|
|
294
|
-
});
|
|
295
|
-
console.log('Total leave days:', result.Data[0]?.sum_LeaveDays);
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### getInstance(instanceId)
|
|
299
|
-
|
|
300
|
-
Get a typed ActivityInstance with field accessors and persistence methods.
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
const instance = await activity.getInstance("inst_abc123");
|
|
304
|
-
|
|
305
|
-
// Field accessors (BDO Item pattern)
|
|
306
|
-
instance._id; // "inst_abc123"
|
|
307
|
-
instance.StartDate.get(); // read value (typed)
|
|
308
|
-
instance.StartDate.set("2026-03-01"); // set value (editable fields only)
|
|
309
|
-
instance.StartDate.meta; // { _id: "StartDate", Name: "Start Date", Type: "Date" }
|
|
310
|
-
instance.LeaveDays.get(); // read computed/readonly field
|
|
311
|
-
// instance.LeaveDays.set(...) // NOT available — readonly, no set()
|
|
312
|
-
|
|
313
|
-
// Utility methods
|
|
314
|
-
instance.toJSON(); // convert to plain object
|
|
315
|
-
instance.validate(); // validate all fields
|
|
316
|
-
|
|
317
|
-
// Persistence methods
|
|
318
|
-
await instance.update({ StartDate: "2026-03-01" }); // update fields
|
|
319
|
-
await instance.save({ StartDate: "2026-03-01" }); // save and commit
|
|
320
|
-
await instance.complete(); // complete the activity
|
|
321
|
-
const progress = await instance.progress(); // get progress (ActivityProgressType[])
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
---
|
|
325
|
-
|
|
326
|
-
## useActivityForm Hook
|
|
327
|
-
|
|
328
|
-
See the dedicated [useActivityForm documentation](./useActivityForm.md) for the full API reference, type definitions, and examples.
|
|
329
|
-
|
|
330
|
-
---
|
|
331
|
-
|
|
332
|
-
## useActivityTable Hook
|
|
333
|
-
|
|
334
|
-
See the dedicated [useActivityTable documentation](./useActivityTable.md) for the full API reference, type definitions, and examples.
|
|
335
|
-
|
|
336
|
-
`useActivityTable` provides search, sort, filter, and pagination capabilities, same as `useBDOTable`. Entity fields are accessed at the top level (e.g., `row.FieldName`).
|
|
337
|
-
|
|
338
|
-
---
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
## Use Case: Employee Creating Leave
|
|
342
|
-
|
|
343
|
-
### Step 1 — Start the workflow
|
|
344
|
-
|
|
345
|
-
```typescript
|
|
346
|
-
import { SimpleLeaveProcess } from "@/bdo/workflows/SimpleLeaveProcess";
|
|
347
|
-
import type { WorkflowStartResponseType } from "@ram_28/kf-ai-sdk/workflow";
|
|
348
|
-
|
|
349
|
-
const wf = new SimpleLeaveProcess();
|
|
350
|
-
const { BPInstanceId, ActivityId, _id }: WorkflowStartResponseType = await wf.start();
|
|
351
|
-
|
|
352
|
-
// Check progress at any time
|
|
353
|
-
const progress = await wf.progress(BPInstanceId);
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
### Step 2 — React component with useActivityForm
|
|
357
|
-
|
|
358
|
-
See [useActivityForm](./useActivityForm.md) for the full form component example.
|
|
359
|
-
|
|
360
|
-
### Full flow orchestration
|
|
361
|
-
|
|
362
|
-
```tsx
|
|
363
|
-
import { useState } from "react";
|
|
364
|
-
import { SimpleLeaveProcess } from "@/bdo/workflows/SimpleLeaveProcess";
|
|
365
|
-
import type { WorkflowStartResponseType } from "@ram_28/kf-ai-sdk/workflow";
|
|
366
|
-
|
|
367
|
-
function LeaveRequestPage() {
|
|
368
|
-
const [instanceId, setInstanceId] = useState<string | null>(null);
|
|
369
|
-
|
|
370
|
-
const startLeaveRequest = async () => {
|
|
371
|
-
const wf = new SimpleLeaveProcess();
|
|
372
|
-
const result: WorkflowStartResponseType = await wf.start();
|
|
373
|
-
setInstanceId(result._id);
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
if (!instanceId) {
|
|
377
|
-
return <button onClick={startLeaveRequest}>New Leave Request</button>;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
return (
|
|
381
|
-
<LeaveRequestForm
|
|
382
|
-
activityInstanceId={instanceId}
|
|
383
|
-
onComplete={() => setInstanceId(null)}
|
|
384
|
-
/>
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
---
|
|
390
|
-
|
|
391
|
-
## Use Case: Manager Approving Leave
|
|
392
|
-
|
|
393
|
-
### Step 1 — List in-progress items
|
|
394
|
-
|
|
395
|
-
```tsx
|
|
396
|
-
import { useMemo, useState } from "react";
|
|
397
|
-
import { useActivityTable, ActivityTableStatus } from "@ram_28/kf-ai-sdk/workflow";
|
|
398
|
-
import { SimpleLeaveProcess, ManagerApprovalActivity } from "@/bdo/workflows/SimpleLeaveProcess";
|
|
399
|
-
|
|
400
|
-
const wf = new SimpleLeaveProcess();
|
|
401
|
-
const activity = wf.managerApprovalActivity();
|
|
402
|
-
|
|
403
|
-
const { rows, totalItems, isLoading, error, pagination, refetch } = useActivityTable({
|
|
404
|
-
activity,
|
|
405
|
-
status: ActivityTableStatus.InProgress,
|
|
406
|
-
initialState: {
|
|
407
|
-
pagination: { pageNo: 1, pageSize: 10 },
|
|
408
|
-
},
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
if (isLoading) return <div>Loading...</div>;
|
|
412
|
-
if (error) return <div>Error: {error.message}</div>;
|
|
413
|
-
|
|
414
|
-
if (selectedId) {
|
|
415
|
-
return (
|
|
416
|
-
<ApprovalForm
|
|
417
|
-
activityInstanceId={selectedId}
|
|
418
|
-
onComplete={() => {
|
|
419
|
-
setSelectedId(null);
|
|
420
|
-
refetch();
|
|
421
|
-
}}
|
|
422
|
-
/>
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return (
|
|
427
|
-
<div>
|
|
428
|
-
<h2>Pending Approvals ({totalItems})</h2>
|
|
429
|
-
<table>
|
|
430
|
-
<thead>
|
|
431
|
-
<tr>
|
|
432
|
-
<th>ID</th>
|
|
433
|
-
<th>Status</th>
|
|
434
|
-
<th>Assigned To</th>
|
|
435
|
-
<th>Approved</th>
|
|
436
|
-
<th>Reason</th>
|
|
437
|
-
<th>Action</th>
|
|
438
|
-
</tr>
|
|
439
|
-
</thead>
|
|
440
|
-
<tbody>
|
|
441
|
-
{rows.map((row) => (
|
|
442
|
-
<tr key={row._id}>
|
|
443
|
-
<td>{row._id}</td>
|
|
444
|
-
<td>{row.Status}</td>
|
|
445
|
-
<td>{row.AssignedTo.map((u) => u._name).join(", ")}</td>
|
|
446
|
-
<td>{row.ManagerApproved ? "Yes" : "No"}</td>
|
|
447
|
-
<td>{row.ManagerReason}</td>
|
|
448
|
-
<td>
|
|
449
|
-
<button onClick={() => setSelectedId(row._id)}>Review</button>
|
|
450
|
-
</td>
|
|
451
|
-
</tr>
|
|
452
|
-
))}
|
|
453
|
-
</tbody>
|
|
454
|
-
</table>
|
|
455
|
-
<div>
|
|
456
|
-
<button onClick={pagination.goToPrevious} disabled={!pagination.canGoPrevious}>Previous</button>
|
|
457
|
-
<span>Page {pagination.pageNo} of {pagination.totalPages}</span>
|
|
458
|
-
<button onClick={pagination.goToNext} disabled={!pagination.canGoNext}>Next</button>
|
|
459
|
-
</div>
|
|
460
|
-
</div>
|
|
461
|
-
);
|
|
462
|
-
}
|
|
463
|
-
```
|
|
464
|
-
|
|
465
|
-
### Step 2 — Approval form component
|
|
466
|
-
|
|
467
|
-
See [useActivityForm](./useActivityForm.md) for the full approval form component example.
|
|
468
|
-
|
|
469
|
-
---
|
|
470
|
-
|
|
471
|
-
## Use Case: Programmatic ActivityInstance
|
|
472
|
-
|
|
473
|
-
For non-form scenarios (scripts, server-side, batch processing):
|
|
474
|
-
|
|
475
|
-
```typescript
|
|
476
|
-
import { SimpleLeaveProcess } from "@/bdo/workflows/SimpleLeaveProcess";
|
|
477
|
-
|
|
478
|
-
const wf = new SimpleLeaveProcess();
|
|
479
|
-
const activity = wf.employeeInputActivity();
|
|
480
|
-
|
|
481
|
-
// Get a typed instance
|
|
482
|
-
const instance = await activity.getInstance("inst_abc123");
|
|
483
|
-
|
|
484
|
-
// Read fields
|
|
485
|
-
console.log(instance.StartDate.get()); // "2026-02-01"
|
|
486
|
-
console.log(instance.LeaveType.get()); // "PTO"
|
|
487
|
-
console.log(instance.LeaveDays.get()); // 5 (computed)
|
|
488
|
-
|
|
489
|
-
// Write editable fields
|
|
490
|
-
instance.StartDate.set("2026-03-01");
|
|
491
|
-
instance.EndDate.set("2026-03-05");
|
|
492
|
-
|
|
493
|
-
// Field metadata
|
|
494
|
-
console.log(instance.StartDate.label); // "Start Date"
|
|
495
|
-
|
|
496
|
-
// Persist changes
|
|
497
|
-
await instance.update({ StartDate: "2026-03-01", EndDate: "2026-03-05" });
|
|
498
|
-
|
|
499
|
-
// Save and commit
|
|
500
|
-
await instance.save({ StartDate: "2026-03-01", EndDate: "2026-03-05" });
|
|
501
|
-
|
|
502
|
-
// Complete activity
|
|
503
|
-
await instance.complete();
|
|
504
|
-
|
|
505
|
-
// Check progress (returns ActivityProgressType[])
|
|
506
|
-
const progress = await instance.progress();
|
|
507
|
-
```
|
|
508
|
-
|
|
509
|
-
---
|
|
510
|
-
|
|
511
|
-
## Filtering Reference
|
|
512
|
-
|
|
513
|
-
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.
|
|
514
|
-
|
|
515
|
-
All four list/metric endpoints now use **POST** with an optional `ListOptionsType` body (same shape as BDO list API: `{ Filter, Sort, Page, PageSize }`).
|
|
516
|
-
|
|
517
|
-
### In-progress items
|
|
518
|
-
|
|
519
|
-
```typescript
|
|
520
|
-
// No options — returns all (default pagination)
|
|
521
|
-
const result = await activity.getInProgressList();
|
|
522
|
-
|
|
523
|
-
// With filter + pagination
|
|
524
|
-
const result = await activity.getInProgressList({
|
|
525
|
-
Sort: [{ '_created_at': 'DESC' }],
|
|
526
|
-
Page: 1,
|
|
527
|
-
PageSize: 25,
|
|
528
|
-
});
|
|
529
|
-
```
|
|
530
|
-
|
|
531
|
-
### Completed items
|
|
532
|
-
|
|
533
|
-
```typescript
|
|
534
|
-
const result = await activity.getCompletedList({
|
|
535
|
-
Page: 1,
|
|
536
|
-
PageSize: 25,
|
|
537
|
-
});
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
### Process progress
|
|
541
|
-
|
|
542
|
-
```typescript
|
|
543
|
-
const wf = new SimpleLeaveProcess();
|
|
544
|
-
const { BPInstanceId } = await wf.start();
|
|
545
|
-
const progressList = await wf.progress(BPInstanceId);
|
|
546
|
-
// Returns ActivityProgressType[] — one entry per activity in the process
|
|
547
|
-
```
|
|
548
|
-
|
|
549
|
-
---
|
|
550
|
-
|
|
551
|
-
## ActivityInstance System Fields Reference
|
|
552
|
-
|
|
553
|
-
| Field | Type | Description |
|
|
554
|
-
|-------|------|-------------|
|
|
555
|
-
| `_id` | `StringFieldType` | Unique activity instance identifier |
|
|
556
|
-
| `Status` | `SelectFieldType<"InProgress" \| "Completed">` | Current status |
|
|
557
|
-
| `AssignedTo` | `UserFieldType[]` | Assigned users (each has `._id` and `._name`) |
|
|
558
|
-
| `CompletedAt` | `DateTimeFieldType` | Completion timestamp (`"YYYY-MM-DDTHH:MM:SS"`) |
|
|
559
|
-
|
|
560
|
-
---
|
|
File without changes
|