@ram_28/kf-ai-sdk 2.0.4 → 2.0.5
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.mjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/Item.d.ts.map +1 -1
- package/dist/bdo/core/types.d.ts +1 -0
- package/dist/bdo/core/types.d.ts.map +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +91 -86
- package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useForm/index.d.ts +1 -1
- package/dist/components/hooks/useForm/index.d.ts.map +1 -1
- package/dist/components/hooks/useForm/types.d.ts +6 -16
- package/dist/components/hooks/useForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useForm/useForm.d.ts +0 -1
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
- package/dist/components/hooks/useTable/types.d.ts +2 -2
- package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
- package/dist/{constants-BQrBcCON.js → constants-CYJih7y4.js} +2 -2
- package/dist/filter.mjs +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +158 -283
- package/dist/form.types.d.ts +1 -1
- package/dist/form.types.d.ts.map +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +65 -65
- package/dist/types/constants.d.ts +11 -11
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/utils/api/buildListOptions.d.ts +1 -1
- package/dist/utils/api/buildListOptions.d.ts.map +1 -1
- package/dist/workflow/Activity.d.ts +14 -5
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/ActivityInstance.d.ts +1 -1
- package/dist/workflow/ActivityInstance.d.ts.map +1 -1
- package/dist/workflow/client.d.ts +14 -4
- package/dist/workflow/client.d.ts.map +1 -1
- package/dist/workflow/components/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
- package/dist/workflow/types.d.ts +26 -9
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +296 -240
- package/docs/bdo.md +63 -0
- package/docs/useAuth.md +27 -0
- package/docs/useFilter.md +67 -0
- package/docs/useForm.md +59 -0
- package/docs/useTable.md +106 -13
- package/docs/workflow.md +93 -49
- package/package.json +2 -2
- package/sdk/bdo/core/Item.ts +8 -0
- package/sdk/bdo/core/types.ts +1 -0
- package/sdk/components/hooks/useForm/createItemProxy.ts +8 -0
- package/sdk/components/hooks/useForm/index.ts +0 -1
- package/sdk/components/hooks/useForm/types.ts +7 -18
- package/sdk/components/hooks/useForm/useForm.ts +23 -109
- package/sdk/components/hooks/useTable/types.ts +2 -2
- package/sdk/components/hooks/useTable/useTable.llm.txt +7 -7
- package/sdk/components/hooks/useTable/useTable.ts +9 -8
- package/sdk/form.types.ts +0 -1
- package/sdk/types/constants.ts +11 -11
- package/sdk/utils/api/buildListOptions.ts +2 -3
- package/sdk/workflow/Activity.ts +31 -10
- package/sdk/workflow/ActivityInstance.ts +1 -1
- package/sdk/workflow/client.ts +73 -10
- package/sdk/workflow/components/useActivityForm/createActivityItemProxy.ts +4 -0
- package/sdk/workflow/types.ts +22 -9
- package/dist/components/hooks/useForm/useDraftInteraction.d.ts +0 -26
- package/dist/components/hooks/useForm/useDraftInteraction.d.ts.map +0 -1
- package/sdk/components/hooks/useForm/useDraftInteraction.ts +0 -251
package/docs/bdo.md
CHANGED
|
@@ -740,3 +740,66 @@ suppliers.forEach((sup) => {
|
|
|
740
740
|
console.log(`${sup._id}: ${sup.SupplierName}`);
|
|
741
741
|
});
|
|
742
742
|
```
|
|
743
|
+
|
|
744
|
+
---
|
|
745
|
+
|
|
746
|
+
## Common Mistakes
|
|
747
|
+
|
|
748
|
+
### 1. Guessing field names instead of reading BDO files
|
|
749
|
+
|
|
750
|
+
ALWAYS read the BDO `.ts` files (`src/bdo/{role}/*.ts`) BEFORE writing page code. Use the exact field names from the class — NEVER guess or invent field names.
|
|
751
|
+
|
|
752
|
+
```typescript
|
|
753
|
+
// ❌ WRONG — guessing field names that don't exist
|
|
754
|
+
bdo.used // TS2339: Property 'used' does not exist
|
|
755
|
+
bdo.remaining // TS2339: Property 'remaining' does not exist
|
|
756
|
+
bdo.meta_title // TS2339: actual field might be 'seo_title'
|
|
757
|
+
bdo.tags // TS2339: no such field exists
|
|
758
|
+
|
|
759
|
+
// ✅ CORRECT — read the BDO file first, use exact names
|
|
760
|
+
// Check src/bdo/employee/LeaveBalance.ts for actual fields
|
|
761
|
+
bdo.UsedLeaves // matches the actual field in the BDO class
|
|
762
|
+
bdo.RemainingDays // matches the actual field in the BDO class
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
### 2. Inventing BDO classes that don't exist
|
|
766
|
+
|
|
767
|
+
Check `src/bdo/{role}/index.ts` to see which BDO classes actually exist before importing.
|
|
768
|
+
|
|
769
|
+
```typescript
|
|
770
|
+
// ❌ WRONG — ShippingAddress BDO doesn't exist
|
|
771
|
+
import { customerShippingAddress } from "@/bdo/customer/ShippingAddress";
|
|
772
|
+
|
|
773
|
+
// ✅ CORRECT — check index.ts first. shipping_address might just be a StringField on Order
|
|
774
|
+
import { customerOrder } from "@/bdo/customer/Order";
|
|
775
|
+
```
|
|
776
|
+
|
|
777
|
+
### 3. Calling protected methods
|
|
778
|
+
|
|
779
|
+
All `BaseBdo` methods are `protected` by default. Only the methods the role has permission for are re-exposed as `public` in the generated class. Read the BDO file to see which methods are available.
|
|
780
|
+
|
|
781
|
+
```typescript
|
|
782
|
+
// ❌ WRONG — if delete is not in the role's BDO class
|
|
783
|
+
await bdo.delete(id); // TS2445: Property 'delete' is protected
|
|
784
|
+
|
|
785
|
+
// ✅ CORRECT — use api() for methods not exposed on the BDO class
|
|
786
|
+
import { api } from "@ram_28/kf-ai-sdk/api";
|
|
787
|
+
await api(bdo.meta._id).delete(id);
|
|
788
|
+
|
|
789
|
+
// ✅ CORRECT — for create/update, prefer useForm
|
|
790
|
+
const { handleSubmit } = useForm({ bdo });
|
|
791
|
+
```
|
|
792
|
+
|
|
793
|
+
### 4. Not handling `.get()` return type
|
|
794
|
+
|
|
795
|
+
`ItemType` field `.get()` returns `T | undefined`. Always handle the undefined case.
|
|
796
|
+
|
|
797
|
+
```typescript
|
|
798
|
+
// ❌ WRONG — might be undefined
|
|
799
|
+
const title: string = item.Title.get();
|
|
800
|
+
|
|
801
|
+
// ✅ CORRECT — provide fallback
|
|
802
|
+
const title = item.Title.get() ?? "";
|
|
803
|
+
const price = item.Price.get() ?? 0;
|
|
804
|
+
const active = item.IsActive.get() ?? false;
|
|
805
|
+
```
|
package/docs/useAuth.md
CHANGED
|
@@ -121,3 +121,30 @@ function AppContent() {
|
|
|
121
121
|
| `hasAnyRole` | `(roles: string[]) => boolean` | Check if user has any of the roles |
|
|
122
122
|
| `refreshSession` | `() => Promise<SessionResponseType \| null>` | Manually refresh session |
|
|
123
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
|
+
```
|
package/docs/useFilter.md
CHANGED
|
@@ -1320,3 +1320,70 @@ Produces:
|
|
|
1320
1320
|
```
|
|
1321
1321
|
|
|
1322
1322
|
> **Note:** The `RHSType` field defaults to `"Constant"` and is automatically added to the payload. Other possible values are `"BOField"` (reference another field) and `"AppVariable"` (reference an application variable).
|
|
1323
|
+
|
|
1324
|
+
---
|
|
1325
|
+
|
|
1326
|
+
## Common Mistakes
|
|
1327
|
+
|
|
1328
|
+
### 1. Inventing RHSType values
|
|
1329
|
+
|
|
1330
|
+
Only three RHSType values exist. Any other string causes TS2322.
|
|
1331
|
+
|
|
1332
|
+
```typescript
|
|
1333
|
+
// ❌ WRONG — these values don't exist
|
|
1334
|
+
{ RHSType: "Value" }
|
|
1335
|
+
{ RHSType: "Literal" }
|
|
1336
|
+
{ RHSType: "Field" }
|
|
1337
|
+
|
|
1338
|
+
// ✅ CORRECT — only these three values
|
|
1339
|
+
{ RHSType: RHSType.Constant } // "Constant"
|
|
1340
|
+
{ RHSType: RHSType.BOField } // "BOField"
|
|
1341
|
+
{ RHSType: RHSType.AppVariable } // "AppVariable"
|
|
1342
|
+
```
|
|
1343
|
+
|
|
1344
|
+
### 2. Accessing `filter.conditions` instead of `filter.items`
|
|
1345
|
+
|
|
1346
|
+
`UseFilterReturnType` does NOT have a `conditions` property. The conditions array is called `items`.
|
|
1347
|
+
|
|
1348
|
+
```typescript
|
|
1349
|
+
// ❌ WRONG — conditions does NOT exist on UseFilterReturnType
|
|
1350
|
+
filter.conditions
|
|
1351
|
+
filter.conditions.length
|
|
1352
|
+
|
|
1353
|
+
// ✅ CORRECT — use items
|
|
1354
|
+
filter.items
|
|
1355
|
+
filter.items.length
|
|
1356
|
+
filter.hasConditions // boolean shortcut
|
|
1357
|
+
```
|
|
1358
|
+
|
|
1359
|
+
### 3. Mixing hook init format with API format
|
|
1360
|
+
|
|
1361
|
+
`UseFilterOptionsType` (for hook initialization) uses lowercase. `FilterType` (for API calls) uses uppercase. NEVER mix them.
|
|
1362
|
+
|
|
1363
|
+
```typescript
|
|
1364
|
+
// Hook initialization (UseFilterOptionsType) — lowercase, plural
|
|
1365
|
+
useTable({
|
|
1366
|
+
initialState: {
|
|
1367
|
+
filter: { conditions: [...], operator: "And" }
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
|
|
1371
|
+
// API calls (FilterType) — uppercase, singular
|
|
1372
|
+
bdo.list({
|
|
1373
|
+
Filter: { Operator: "And", Condition: [...] }
|
|
1374
|
+
});
|
|
1375
|
+
```
|
|
1376
|
+
|
|
1377
|
+
### 4. Using `as const` on Operator values
|
|
1378
|
+
|
|
1379
|
+
```typescript
|
|
1380
|
+
// ❌ WRONG — as const causes TypeScript narrowing errors in arrays
|
|
1381
|
+
const conditions = [
|
|
1382
|
+
{ Operator: ConditionOperator.EQ as const, ... }
|
|
1383
|
+
];
|
|
1384
|
+
|
|
1385
|
+
// ✅ CORRECT — type the array instead
|
|
1386
|
+
const conditions: Omit<ConditionType, "id">[] = [
|
|
1387
|
+
{ Operator: ConditionOperator.EQ, ... }
|
|
1388
|
+
];
|
|
1389
|
+
```
|
package/docs/useForm.md
CHANGED
|
@@ -736,3 +736,62 @@ ValidationMode.All // "all"
|
|
|
736
736
|
FormOperation.Create // "create"
|
|
737
737
|
FormOperation.Update // "update"
|
|
738
738
|
```
|
|
739
|
+
|
|
740
|
+
---
|
|
741
|
+
|
|
742
|
+
## Common Mistakes
|
|
743
|
+
|
|
744
|
+
### 1. Passing FieldType instead of BDO instance
|
|
745
|
+
|
|
746
|
+
`useForm` takes a BDO class **instance**, NOT a FieldType. The hook infers all types from the BDO class.
|
|
747
|
+
|
|
748
|
+
```typescript
|
|
749
|
+
// ❌ WRONG — FieldType as generic causes register/watch to return `never`
|
|
750
|
+
useForm<ProductFieldType>({ ... });
|
|
751
|
+
|
|
752
|
+
// ❌ WRONG — passing FieldType as bdo
|
|
753
|
+
useForm({ bdo: ProductFieldType });
|
|
754
|
+
|
|
755
|
+
// ✅ CORRECT — pass a BDO class instance
|
|
756
|
+
const product = useMemo(() => new SellerProduct(), []);
|
|
757
|
+
useForm({ bdo: product, mode: ValidationMode.OnBlur });
|
|
758
|
+
```
|
|
759
|
+
|
|
760
|
+
### 2. Wrong handleSubmit onSuccess type
|
|
761
|
+
|
|
762
|
+
```typescript
|
|
763
|
+
// ❌ WRONG — these types cause errors
|
|
764
|
+
const onSuccess = (data: unknown) => { ... };
|
|
765
|
+
const onSuccess = (data: Partial<EditableFieldType>) => { ... };
|
|
766
|
+
|
|
767
|
+
// ✅ CORRECT — CreateUpdateResponseType = { _id: string }
|
|
768
|
+
import type { CreateUpdateResponseType } from "@ram_28/kf-ai-sdk/api/types";
|
|
769
|
+
const onSuccess = (data: CreateUpdateResponseType): void => {
|
|
770
|
+
console.log("Saved:", data._id);
|
|
771
|
+
};
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
### 3. Using register() for boolean fields
|
|
775
|
+
|
|
776
|
+
Boolean fields need watch/setValue pattern because HTML checkboxes don't work with register().
|
|
777
|
+
|
|
778
|
+
```typescript
|
|
779
|
+
// ❌ WRONG — register doesn't work correctly with checkboxes
|
|
780
|
+
<input type="checkbox" {...register(bdo.IsActive.id)} />
|
|
781
|
+
|
|
782
|
+
// ✅ CORRECT — use watch + setValue
|
|
783
|
+
<Checkbox
|
|
784
|
+
checked={Boolean(watch(bdo.IsActive.id))}
|
|
785
|
+
onCheckedChange={(v) => setValue(bdo.IsActive.id, v as boolean)}
|
|
786
|
+
/>
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
### 4. Wrong default values for date fields
|
|
790
|
+
|
|
791
|
+
```typescript
|
|
792
|
+
// ❌ WRONG — empty string causes type errors
|
|
793
|
+
defaultValues: { StartDate: "" }
|
|
794
|
+
|
|
795
|
+
// ✅ CORRECT — use undefined for date fields
|
|
796
|
+
defaultValues: { StartDate: undefined }
|
|
797
|
+
```
|
package/docs/useTable.md
CHANGED
|
@@ -142,17 +142,17 @@ interface UseTableReturnType<T> {
|
|
|
142
142
|
field: keyof T | null;
|
|
143
143
|
|
|
144
144
|
// Current sort direction, null if no sort active
|
|
145
|
-
direction: "
|
|
145
|
+
direction: "ASC" | "DESC" | null;
|
|
146
146
|
|
|
147
147
|
// Toggle sort on a field (triggers API call)
|
|
148
|
-
// Cycles: none →
|
|
148
|
+
// Cycles: none → ASC → DESC → none
|
|
149
149
|
toggle: (field: keyof T) => void;
|
|
150
150
|
|
|
151
151
|
// Clear sorting (triggers API call)
|
|
152
152
|
clear: () => void;
|
|
153
153
|
|
|
154
154
|
// Set explicit sort field and direction (triggers API call)
|
|
155
|
-
set: (field: keyof T, direction: "
|
|
155
|
+
set: (field: keyof T, direction: "ASC" | "DESC") => void;
|
|
156
156
|
};
|
|
157
157
|
|
|
158
158
|
// ============================================================
|
|
@@ -345,7 +345,7 @@ function MyItemsTable() {
|
|
|
345
345
|
>
|
|
346
346
|
{col.label}
|
|
347
347
|
{table.sort.field === col.fieldId && (
|
|
348
|
-
<span>{table.sort.direction === "
|
|
348
|
+
<span>{table.sort.direction === "ASC" ? " ↑" : " ↓"}</span>
|
|
349
349
|
)}
|
|
350
350
|
</th>
|
|
351
351
|
))}
|
|
@@ -591,7 +591,7 @@ function SortableTable() {
|
|
|
591
591
|
>
|
|
592
592
|
{col.label}
|
|
593
593
|
{table.sort.field === col.fieldId && (
|
|
594
|
-
<span>{table.sort.direction === "
|
|
594
|
+
<span>{table.sort.direction === "ASC" ? " ↑" : " ↓"}</span>
|
|
595
595
|
)}
|
|
596
596
|
</th>
|
|
597
597
|
))}
|
|
@@ -636,17 +636,17 @@ function TableWithSortDropdown() {
|
|
|
636
636
|
setSelectedSort(value);
|
|
637
637
|
switch (value) {
|
|
638
638
|
case "price-asc":
|
|
639
|
-
table.sort.set(product.Price.id, "
|
|
639
|
+
table.sort.set(product.Price.id, "ASC");
|
|
640
640
|
break;
|
|
641
641
|
case "price-desc":
|
|
642
|
-
table.sort.set(product.Price.id, "
|
|
642
|
+
table.sort.set(product.Price.id, "DESC");
|
|
643
643
|
break;
|
|
644
644
|
case "newest":
|
|
645
|
-
table.sort.set("_created_at", "
|
|
645
|
+
table.sort.set("_created_at", "DESC"); // System field
|
|
646
646
|
break;
|
|
647
647
|
case "featured":
|
|
648
648
|
default:
|
|
649
|
-
table.sort.set(product.Title.id, "
|
|
649
|
+
table.sort.set(product.Title.id, "ASC");
|
|
650
650
|
break;
|
|
651
651
|
}
|
|
652
652
|
};
|
|
@@ -1005,16 +1005,16 @@ function ProductListPage() {
|
|
|
1005
1005
|
setSelectedSort(value);
|
|
1006
1006
|
switch (value) {
|
|
1007
1007
|
case "price-asc":
|
|
1008
|
-
table.sort.set(product.Price.id, "
|
|
1008
|
+
table.sort.set(product.Price.id, "ASC");
|
|
1009
1009
|
break;
|
|
1010
1010
|
case "price-desc":
|
|
1011
|
-
table.sort.set(product.Price.id, "
|
|
1011
|
+
table.sort.set(product.Price.id, "DESC");
|
|
1012
1012
|
break;
|
|
1013
1013
|
case "newest":
|
|
1014
|
-
table.sort.set("_created_at", "
|
|
1014
|
+
table.sort.set("_created_at", "DESC"); // System field
|
|
1015
1015
|
break;
|
|
1016
1016
|
default:
|
|
1017
|
-
table.sort.set(product.Title.id, "
|
|
1017
|
+
table.sort.set(product.Title.id, "ASC");
|
|
1018
1018
|
break;
|
|
1019
1019
|
}
|
|
1020
1020
|
};
|
|
@@ -1115,3 +1115,96 @@ function ProductListPage() {
|
|
|
1115
1115
|
);
|
|
1116
1116
|
}
|
|
1117
1117
|
```
|
|
1118
|
+
|
|
1119
|
+
---
|
|
1120
|
+
|
|
1121
|
+
## Common Mistakes
|
|
1122
|
+
|
|
1123
|
+
### 1. Passing `bdo` instead of `source`
|
|
1124
|
+
|
|
1125
|
+
`useTable` takes `source` (a BO_ID string), NOT `bdo` (a BDO instance). Don't confuse with `useForm({ bdo })`.
|
|
1126
|
+
|
|
1127
|
+
```typescript
|
|
1128
|
+
// ❌ WRONG — bdo is NOT a valid property
|
|
1129
|
+
useTable({ bdo, columns });
|
|
1130
|
+
useTable({ bdo: product, columns });
|
|
1131
|
+
|
|
1132
|
+
// ✅ CORRECT — pass the BO_ID string via source
|
|
1133
|
+
useTable({ source: product.meta._id, columns });
|
|
1134
|
+
```
|
|
1135
|
+
|
|
1136
|
+
### 2. Wrong initialState property names
|
|
1137
|
+
|
|
1138
|
+
This is NOT react-table. Don't use react-table naming conventions.
|
|
1139
|
+
|
|
1140
|
+
```typescript
|
|
1141
|
+
// ❌ WRONG — sorting and pageIndex don't exist
|
|
1142
|
+
initialState: { sorting: [...], pagination: { pageIndex: 0, pageSize: 10 } }
|
|
1143
|
+
|
|
1144
|
+
// ✅ CORRECT — use sort and pageNo
|
|
1145
|
+
initialState: { sort: [{ [bdo.Title.id]: "ASC" }], pagination: { pageNo: 1, pageSize: 10 } }
|
|
1146
|
+
```
|
|
1147
|
+
|
|
1148
|
+
### 3. Wrong sort direction type
|
|
1149
|
+
|
|
1150
|
+
Sort direction must be the string literal `"ASC"` or `"DESC"` — nothing else.
|
|
1151
|
+
|
|
1152
|
+
```typescript
|
|
1153
|
+
// ❌ WRONG — booleans, lowercase, or arbitrary strings
|
|
1154
|
+
sort.set(bdo.Title.id, true);
|
|
1155
|
+
sort.set(bdo.Title.id, "asc");
|
|
1156
|
+
sort.set(bdo.Title.id, "ascending");
|
|
1157
|
+
|
|
1158
|
+
// ✅ CORRECT — uppercase string literals only
|
|
1159
|
+
sort.set(bdo.Title.id, "ASC");
|
|
1160
|
+
sort.set(bdo.Title.id, "DESC");
|
|
1161
|
+
```
|
|
1162
|
+
|
|
1163
|
+
### 4. Calling `.get()` on table rows
|
|
1164
|
+
|
|
1165
|
+
Table `rows` are **plain objects**, NOT `ItemType`. `.get()` is only for `ItemType` returned by `bdo.get()`, `bdo.create()`, or `useForm` item proxy.
|
|
1166
|
+
|
|
1167
|
+
```typescript
|
|
1168
|
+
// ❌ WRONG — rows are plain objects, not ItemType
|
|
1169
|
+
table.rows.map(row => row.Title.get());
|
|
1170
|
+
|
|
1171
|
+
// ✅ CORRECT — access properties directly
|
|
1172
|
+
table.rows.map(row => row.Title);
|
|
1173
|
+
table.rows.map(row => row[bdo.Title.id]);
|
|
1174
|
+
```
|
|
1175
|
+
|
|
1176
|
+
### 5. Using entity-level FieldType as generic
|
|
1177
|
+
|
|
1178
|
+
Entity-level types (from `@/bdo/entities/`) exclude `SystemFieldsType`, so `row._id` won't work.
|
|
1179
|
+
|
|
1180
|
+
```typescript
|
|
1181
|
+
// ❌ WRONG — ProductFieldType excludes _id, _created_at, etc.
|
|
1182
|
+
import type { ProductFieldType } from "@/bdo/entities/Product";
|
|
1183
|
+
useTable<ProductFieldType>({ ... });
|
|
1184
|
+
|
|
1185
|
+
// ✅ CORRECT — role-specific type includes SystemFieldsType
|
|
1186
|
+
import type { BuyerProductFieldType } from "@/bdo/buyer/Product";
|
|
1187
|
+
useTable<BuyerProductFieldType>({ ... });
|
|
1188
|
+
```
|
|
1189
|
+
|
|
1190
|
+
### 6. Using `header` instead of `label` in columns
|
|
1191
|
+
|
|
1192
|
+
```typescript
|
|
1193
|
+
// ❌ WRONG
|
|
1194
|
+
{ fieldId: bdo.Title.id, header: "Title" }
|
|
1195
|
+
|
|
1196
|
+
// ✅ CORRECT
|
|
1197
|
+
{ fieldId: bdo.Title.id, label: "Title" }
|
|
1198
|
+
```
|
|
1199
|
+
|
|
1200
|
+
### 7. Accessing `data` or `columns` on the return type
|
|
1201
|
+
|
|
1202
|
+
```typescript
|
|
1203
|
+
// ❌ WRONG — these properties don't exist
|
|
1204
|
+
table.data
|
|
1205
|
+
table.columns
|
|
1206
|
+
|
|
1207
|
+
// ✅ CORRECT
|
|
1208
|
+
table.rows // current page data
|
|
1209
|
+
table.totalItems // total matching records
|
|
1210
|
+
```
|
package/docs/workflow.md
CHANGED
|
@@ -61,15 +61,20 @@ interface WorkflowStartResponseType {
|
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
63
|
interface ActivityProgressType {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
ActivityId: string;
|
|
65
|
+
ActivityInstanceId: string;
|
|
66
|
+
ActivityType: string;
|
|
67
|
+
AssignedTo: { Type: string; _id: string }[];
|
|
68
|
+
CompletedAt: string | null;
|
|
69
|
+
CompletedBy: { _id: string; _name: string } | null;
|
|
70
|
+
Status: "COMPLETED" | "IN_PROGRESS";
|
|
71
|
+
_name: string;
|
|
67
72
|
}
|
|
68
73
|
```
|
|
69
74
|
|
|
70
75
|
### ActivityInstanceFieldsType
|
|
71
76
|
|
|
72
|
-
System fields present on every activity instance. Returned alongside activity-specific fields from `
|
|
77
|
+
System fields present on every activity instance. Returned alongside activity-specific fields from `getInProgressList()` and `getCompletedList()`.
|
|
73
78
|
|
|
74
79
|
```typescript
|
|
75
80
|
type ActivityInstanceFieldsType = {
|
|
@@ -84,7 +89,7 @@ type ActivityInstanceFieldsType = {
|
|
|
84
89
|
|
|
85
90
|
```typescript
|
|
86
91
|
interface UseActivityFormOptions<A extends Activity<any, any, any>> {
|
|
87
|
-
/** Activity instance identifier (from wf.start() or
|
|
92
|
+
/** Activity instance identifier (from wf.start() or getInProgressList()) */
|
|
88
93
|
activity_instance_id: string;
|
|
89
94
|
|
|
90
95
|
/** Default form values */
|
|
@@ -209,28 +214,50 @@ export class SimpleLeaveProcess {
|
|
|
209
214
|
|
|
210
215
|
---
|
|
211
216
|
|
|
217
|
+
## Workflow Class
|
|
218
|
+
|
|
219
|
+
### start()
|
|
220
|
+
|
|
221
|
+
Start a new workflow instance.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const wf = new SimpleLeaveProcess();
|
|
225
|
+
const { activityId, activityInstanceId } = await wf.start();
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### progress()
|
|
229
|
+
|
|
230
|
+
Get global progress across the entire business process. Returns a list of progress entries for each stage/activity.
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
const wf = new SimpleLeaveProcess();
|
|
234
|
+
const progressList = await wf.progress();
|
|
235
|
+
// progressList: ActivityProgressType[]
|
|
236
|
+
for (const entry of progressList) {
|
|
237
|
+
console.log(entry._name, entry.Status, entry.CompletedAt);
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Endpoint:** `GET /api/app/process/{bp_id}/progress`
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
212
245
|
## Activity Class
|
|
213
246
|
|
|
214
|
-
Each Activity class provides methods to query and access activity instances.
|
|
247
|
+
Each Activity class provides methods to query and access activity instances. List and metric operations are split by status (`inprogress` / `completed`).
|
|
215
248
|
|
|
216
249
|
```typescript
|
|
217
250
|
const activity = wf.employeeInputActivity();
|
|
218
251
|
```
|
|
219
252
|
|
|
220
|
-
###
|
|
253
|
+
### getInProgressList(options?)
|
|
221
254
|
|
|
222
|
-
List activity instances with optional filtering and pagination.
|
|
255
|
+
List in-progress activity instances with optional filtering and pagination.
|
|
223
256
|
|
|
224
257
|
```typescript
|
|
225
|
-
const result = await activity.
|
|
258
|
+
const result = await activity.getInProgressList({
|
|
226
259
|
Page: 1,
|
|
227
260
|
PageSize: 20,
|
|
228
|
-
Filter: {
|
|
229
|
-
Operator: "And",
|
|
230
|
-
Condition: [
|
|
231
|
-
{ LHSField: "Status", Operator: "EQ", RHSValue: "InProgress", RHSType: "Constant" },
|
|
232
|
-
],
|
|
233
|
-
},
|
|
234
261
|
});
|
|
235
262
|
|
|
236
263
|
for (const item of result.Data) {
|
|
@@ -238,12 +265,37 @@ for (const item of result.Data) {
|
|
|
238
265
|
}
|
|
239
266
|
```
|
|
240
267
|
|
|
241
|
-
###
|
|
268
|
+
### getCompletedList(options?)
|
|
269
|
+
|
|
270
|
+
List completed activity instances with optional filtering and pagination.
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
const result = await activity.getCompletedList({
|
|
274
|
+
Page: 1,
|
|
275
|
+
PageSize: 20,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
for (const item of result.Data) {
|
|
279
|
+
console.log(item._id, item.CompletedAt, item.StartDate);
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### inProgressMetrics(options)
|
|
284
|
+
|
|
285
|
+
Get aggregated metrics for in-progress activity instances.
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
const metrics = await activity.inProgressMetrics({
|
|
289
|
+
Metric: [{ Field: "Status", Function: "Count" }],
|
|
290
|
+
});
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
### completedMetrics(options)
|
|
242
294
|
|
|
243
|
-
Get aggregated metrics for activity instances.
|
|
295
|
+
Get aggregated metrics for completed activity instances.
|
|
244
296
|
|
|
245
297
|
```typescript
|
|
246
|
-
const metrics = await activity.
|
|
298
|
+
const metrics = await activity.completedMetrics({
|
|
247
299
|
Metric: [{ Field: "Status", Function: "Count" }],
|
|
248
300
|
});
|
|
249
301
|
```
|
|
@@ -271,7 +323,7 @@ instance.validate(); // validate all fields
|
|
|
271
323
|
await instance.update({ StartDate: "2026-03-01" }); // update fields
|
|
272
324
|
await instance.save({ StartDate: "2026-03-01" }); // save and commit
|
|
273
325
|
await instance.complete(); // complete the activity
|
|
274
|
-
const progress = await instance.progress(); // get progress
|
|
326
|
+
const progress = await instance.progress(); // get progress (ActivityProgressType[])
|
|
275
327
|
```
|
|
276
328
|
|
|
277
329
|
---
|
|
@@ -284,7 +336,7 @@ React hook for building forms bound to workflow activity input fields. Integrate
|
|
|
284
336
|
|
|
285
337
|
| Property | Type | Default | Description |
|
|
286
338
|
|----------|------|---------|-------------|
|
|
287
|
-
| `activity_instance_id` | `string` | *required* | Activity instance ID (from `wf.start()` or `
|
|
339
|
+
| `activity_instance_id` | `string` | *required* | Activity instance ID (from `wf.start()` or `getInProgressList()`) |
|
|
288
340
|
| `defaultValues` | `Partial<Editable>` | `{}` | Initial form values |
|
|
289
341
|
| `mode` | `"onBlur" \| "onChange" \| "onSubmit" \| "onTouched" \| "all"` | `"onBlur"` | Validation timing |
|
|
290
342
|
| `enabled` | `boolean` | `true` | Whether to load activity data on mount |
|
|
@@ -350,6 +402,9 @@ import type { WorkflowStartResponseType } from "@ram_28/kf-ai-sdk/workflow";
|
|
|
350
402
|
|
|
351
403
|
const wf = new SimpleLeaveProcess();
|
|
352
404
|
const { activityId, activityInstanceId }: WorkflowStartResponseType = await wf.start();
|
|
405
|
+
|
|
406
|
+
// Check global progress at any time
|
|
407
|
+
const progress = await wf.progress();
|
|
353
408
|
```
|
|
354
409
|
|
|
355
410
|
### Step 2 — React component with useActivityForm
|
|
@@ -505,13 +560,7 @@ import { SimpleLeaveProcess } from "@/bdo/workflows/SimpleLeaveProcess";
|
|
|
505
560
|
const wf = new SimpleLeaveProcess();
|
|
506
561
|
const activity = wf.managerApprovalActivity();
|
|
507
562
|
|
|
508
|
-
const result = await activity.
|
|
509
|
-
Filter: {
|
|
510
|
-
Operator: "And",
|
|
511
|
-
Condition: [
|
|
512
|
-
{ LHSField: "Status", Operator: "EQ", RHSValue: "InProgress", RHSType: "Constant" },
|
|
513
|
-
],
|
|
514
|
-
},
|
|
563
|
+
const result = await activity.getInProgressList({
|
|
515
564
|
Page: 1,
|
|
516
565
|
PageSize: 20,
|
|
517
566
|
});
|
|
@@ -628,7 +677,7 @@ await instance.save({ StartDate: "2026-03-01", EndDate: "2026-03-05" });
|
|
|
628
677
|
// Complete activity
|
|
629
678
|
await instance.complete();
|
|
630
679
|
|
|
631
|
-
// Check progress
|
|
680
|
+
// Check progress (returns ActivityProgressType[])
|
|
632
681
|
const progress = await instance.progress();
|
|
633
682
|
```
|
|
634
683
|
|
|
@@ -636,36 +685,24 @@ const progress = await instance.progress();
|
|
|
636
685
|
|
|
637
686
|
## Filtering Reference
|
|
638
687
|
|
|
688
|
+
Status filtering is built into the method names (`getInProgressList` / `getCompletedList`), so you no longer need a Status filter condition.
|
|
689
|
+
|
|
639
690
|
### In-progress items
|
|
640
691
|
|
|
641
692
|
```typescript
|
|
642
|
-
const result = await activity.
|
|
643
|
-
Filter: {
|
|
644
|
-
Operator: "And",
|
|
645
|
-
Condition: [
|
|
646
|
-
{ LHSField: "Status", Operator: "EQ", RHSValue: "InProgress", RHSType: "Constant" },
|
|
647
|
-
],
|
|
648
|
-
},
|
|
649
|
-
});
|
|
693
|
+
const result = await activity.getInProgressList();
|
|
650
694
|
```
|
|
651
695
|
|
|
652
696
|
### Completed items
|
|
653
697
|
|
|
654
698
|
```typescript
|
|
655
|
-
const result = await activity.
|
|
656
|
-
Filter: {
|
|
657
|
-
Operator: "And",
|
|
658
|
-
Condition: [
|
|
659
|
-
{ LHSField: "Status", Operator: "EQ", RHSValue: "Completed", RHSType: "Constant" },
|
|
660
|
-
],
|
|
661
|
-
},
|
|
662
|
-
});
|
|
699
|
+
const result = await activity.getCompletedList();
|
|
663
700
|
```
|
|
664
701
|
|
|
665
|
-
### Assigned to a specific user
|
|
702
|
+
### Assigned to a specific user (in-progress)
|
|
666
703
|
|
|
667
704
|
```typescript
|
|
668
|
-
const result = await activity.
|
|
705
|
+
const result = await activity.getInProgressList({
|
|
669
706
|
Filter: {
|
|
670
707
|
Operator: "And",
|
|
671
708
|
Condition: [
|
|
@@ -675,20 +712,27 @@ const result = await activity.getInstanceList({
|
|
|
675
712
|
});
|
|
676
713
|
```
|
|
677
714
|
|
|
678
|
-
###
|
|
715
|
+
### Assigned to a specific user (completed)
|
|
679
716
|
|
|
680
717
|
```typescript
|
|
681
|
-
const result = await activity.
|
|
718
|
+
const result = await activity.getCompletedList({
|
|
682
719
|
Filter: {
|
|
683
720
|
Operator: "And",
|
|
684
721
|
Condition: [
|
|
685
|
-
{ LHSField: "Status", Operator: "EQ", RHSValue: "InProgress", RHSType: "Constant" },
|
|
686
722
|
{ LHSField: "AssignedTo._id", Operator: "EQ", RHSValue: userId, RHSType: "Constant" },
|
|
687
723
|
],
|
|
688
724
|
},
|
|
689
725
|
});
|
|
690
726
|
```
|
|
691
727
|
|
|
728
|
+
### Global process progress
|
|
729
|
+
|
|
730
|
+
```typescript
|
|
731
|
+
const wf = new SimpleLeaveProcess();
|
|
732
|
+
const progressList = await wf.progress();
|
|
733
|
+
// Returns ActivityProgressType[] — one entry per activity in the process
|
|
734
|
+
```
|
|
735
|
+
|
|
692
736
|
---
|
|
693
737
|
|
|
694
738
|
## ActivityInstance System Fields Reference
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ram_28/kf-ai-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "Type-safe, AI-driven SDK for building modern web applications with role-based access control",
|
|
5
5
|
"author": "Ramprasad",
|
|
6
6
|
"license": "MIT",
|
|
@@ -211,7 +211,7 @@
|
|
|
211
211
|
"test": "vitest",
|
|
212
212
|
"test:watch": "vitest --watch",
|
|
213
213
|
"typecheck": "tsc --noEmit",
|
|
214
|
-
"prepublishOnly": "
|
|
214
|
+
"prepublishOnly": "pnpm run build"
|
|
215
215
|
},
|
|
216
216
|
"dependencies": {
|
|
217
217
|
"@tanstack/react-virtual": "^3.0.0-beta.68",
|