@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/api.md DELETED
@@ -1,95 +0,0 @@
1
- # API Types Reference
2
-
3
- Request and response types for BDO methods. For usage patterns, see [bdo.md](bdo.md).
4
-
5
- ## Imports
6
-
7
- ```typescript
8
- import { api } from "@ram_28/kf-ai-sdk/api";
9
- import type { ListOptionsType, CreateUpdateResponseType, DeleteResponseType, DraftResponseType, MetricOptionsType, MetricResponseType, PivotOptionsType, PivotResponseType } from "@ram_28/kf-ai-sdk/api/types";
10
- ```
11
-
12
- ---
13
-
14
- ## Common Mistakes (READ FIRST)
15
-
16
- ### 1. Calling `api` directly instead of as factory
17
-
18
- ```typescript
19
- // ❌ WRONG — api is a function, not a client
20
- api.get(id); api.delete(id);
21
-
22
- // ✅ CORRECT — call api(boId) first
23
- api(bdo.meta._id).get(id);
24
- api(bdo.meta._id).delete(id);
25
- ```
26
-
27
- ### 2. Using `api()` when BDO methods are available
28
-
29
- Prefer BDO methods when they're `public` on the role's class. Use `api()` only for `protected` methods.
30
-
31
- ```typescript
32
- // ✅ PREFERRED — BDO method
33
- const items = await bdo.list();
34
-
35
- // ✅ USE api() ONLY when BDO method is protected
36
- await api(bdo.meta._id).delete(id);
37
- ```
38
-
39
- ### 3. Wrong metric response key format
40
-
41
- Key pattern is `{lowercase_type}_{Field}` with single underscore.
42
-
43
- ```typescript
44
- // ❌ WRONG
45
- const count = result.Data[0].count;
46
-
47
- // ✅ CORRECT
48
- const count = result.Data?.[0]?.["count__id"] ?? 0; // Count of _id
49
- const total = result.Data?.[0]?.["sum_unit_price"] ?? 0; // Sum of unit_price
50
- ```
51
-
52
- ---
53
-
54
- ## Response Types
55
-
56
- ```typescript
57
- interface CreateUpdateResponseType { _id: string; }
58
- interface DeleteResponseType { status: "success"; }
59
- interface DraftResponseType { [fieldName: string]: any; }
60
-
61
- interface ListOptionsType {
62
- Field?: string[];
63
- Filter?: FilterType;
64
- Sort?: Record<string, "ASC" | "DESC">[];
65
- Page?: number; // 1-indexed
66
- PageSize?: number; // Default: 10
67
- }
68
-
69
- interface MetricOptionsType {
70
- GroupBy: string[];
71
- Metric: { Field: string; Type: AggregationType; }[];
72
- Filter?: FilterType;
73
- }
74
-
75
- interface MetricResponseType { Data: Record<string, any>[]; }
76
-
77
- interface PivotOptionsType {
78
- Row: string[];
79
- Column: string[];
80
- Metric: { Field: string; Type: AggregationType; }[];
81
- Filter?: FilterType;
82
- }
83
-
84
- interface PivotResponseType {
85
- Data: { RowHeader: { Key: string }[]; ColumnHeader: { Key: string }[]; Value: (number | string | null)[][]; };
86
- }
87
-
88
- type AggregationType = "Sum" | "Avg" | "Count" | "Max" | "Min" | "DistinctCount" | "BlankCount" | "NotBlankCount" | "Concat" | "DistinctConcat";
89
-
90
- // Filter type (for bdo.list() Filter parameter)
91
- interface FilterType { Operator: "And" | "Or" | "Not"; Condition: Array<ConditionType | ConditionGroupType>; }
92
- interface ConditionType { Operator: string; LHSField: string; RHSValue: any; RHSType?: "Constant" | "BDOField" | "AppVariable"; }
93
-
94
- type SortType = Record<string, "ASC" | "DESC">[];
95
- ```
package/docs/bdo.md DELETED
@@ -1,224 +0,0 @@
1
- # BDO SDK API
2
-
3
- Type-safe, role-based data access layer for business objects.
4
-
5
- ## Imports
6
-
7
- ```typescript
8
- // BDO class (from generated code)
9
- import { AdminProduct } from "@/bdo/admin/Product";
10
- import type { AdminProductEditableFieldType, AdminProductFieldType } from "@/bdo/admin/Product";
11
-
12
- // SDK types
13
- import type { ItemType, SystemFieldsType } from "@ram_28/kf-ai-sdk/bdo/types";
14
- import type { ListOptionsType, CreateUpdateResponseType, DeleteResponseType } from "@ram_28/kf-ai-sdk/api/types";
15
- ```
16
-
17
- ---
18
-
19
- ## Common Mistakes (READ FIRST)
20
-
21
- ### 1. Guessing field names instead of reading BDO files
22
-
23
- ALWAYS read `src/bdo/{role}/*.ts` BEFORE writing page code. Use EXACT field names from the class.
24
-
25
- ```typescript
26
- // ❌ WRONG — guessing
27
- bdo.productName bdo.isActive bdo.unitPrice
28
-
29
- // ✅ CORRECT — exact snake_case from BDO file
30
- bdo.product_name bdo.is_active bdo.unit_price
31
- ```
32
-
33
- ### 2. Rendering ItemType fields directly in JSX without `.get()`
34
-
35
- `bdo.list()`, `bdo.get()`, `bdo.create()` return `ItemType` — each field is an accessor object, NOT a value.
36
-
37
- ```tsx
38
- // ❌ WRONG — renders [object Object]
39
- const item = await bdo.get(id);
40
- <span>{item.product_name}</span>
41
-
42
- // ✅ CORRECT — call .get()
43
- <span>{item.product_name.get()}</span>
44
- <span>{item.product_name.get() ?? "—"}</span>
45
- ```
46
-
47
- **Key distinction:** `useTable().rows` are plain objects (access `row.field` directly). `bdo.get()`/`bdo.list()` return ItemType proxies (must call `item.field.get()`).
48
-
49
- ### 3. Rendering Image/File/Reference values in detail pages
50
-
51
- These field types return complex objects from `.get()` — NOT renderable as React children.
52
-
53
- ```tsx
54
- // ❌ WRONG — FileType/ImageFieldType are objects, not ReactNode
55
- <span>{item.product_image.get()}</span> // ImageFieldType = FileType | null
56
- <span>{item.attachments.get()}</span> // FileFieldType = FileType[]
57
- <span>{item.category.get()}</span> // Reference = { _id, _name, ... }
58
-
59
- // ✅ CORRECT — extract the renderable value
60
- // Image: use ImageThumbnail component (NEVER use src="#")
61
- import { ImageThumbnail } from "@/components/ui/image-thumbnail";
62
- <ImageThumbnail boId={bdo.meta._id} instanceId={item._id} fieldId={bdo.product_image.id} value={item.product_image.get()} imgClassName="w-24 h-24 object-cover rounded" />
63
-
64
- // Image: if you only need the filename as text
65
- const img = item.product_image.get();
66
- <span>{img ? (img as any).FileName : "No image"}</span>
67
-
68
- // File array: use FilePreview component
69
- import { FilePreview } from "@/components/ui/file-preview";
70
- <FilePreview boId={bdo.meta._id} instanceId={item._id} fieldId={bdo.attachments.id} value={item.attachments.get()} />
71
-
72
- // Reference: access _name
73
- const ref = item.category.get();
74
- <span>{ref ? (ref as any)._name : "—"}</span>
75
-
76
- // Number: format
77
- <span>{(item.unit_price.get() ?? 0).toFixed(2)}</span>
78
-
79
- // Boolean: display
80
- <span>{item.is_active.get() ? "Yes" : "No"}</span>
81
- ```
82
-
83
- ### 4. Calling protected methods
84
-
85
- Only methods the role has permission for are `public`. Check the BDO file.
86
-
87
- ```typescript
88
- // ❌ WRONG — if delete is not in the role's BDO class
89
- await bdo.delete(id); // TS2445: Property 'delete' is protected
90
-
91
- // ✅ CORRECT — use api() for methods not on the BDO class
92
- import { api } from "@ram_28/kf-ai-sdk/api";
93
- await api(bdo.meta._id).delete(id);
94
- ```
95
-
96
- ### 5. Not handling `.get()` return type (undefined)
97
-
98
- ```typescript
99
- // ❌ WRONG — might be undefined
100
- const title: string = item.product_name.get();
101
-
102
- // ✅ CORRECT — provide fallback
103
- const title = item.product_name.get() ?? "";
104
- const price = item.unit_price.get() ?? 0;
105
- ```
106
-
107
- ---
108
-
109
- ## BDO Meta & Fields
110
-
111
- ```typescript
112
- const product = new AdminProduct();
113
- product.meta._id; // "BDO_Product" — use as source in useTable, api()
114
- product.meta.name; // "Product"
115
-
116
- // Field getters (all field types)
117
- product.product_name.id // "product_name" — use in register(), watch(), setValue()
118
- product.product_name.label // "product_name" — display label
119
- product.product_name.required // boolean
120
- product.product_name.readOnly // boolean
121
- product.product_name.defaultValue // unknown
122
- ```
123
-
124
- ## Field Classes
125
-
126
- | Class | Extra Getters | Notes |
127
- |-------|--------------|-------|
128
- | `StringField` | `length` | May have `Constraint.Enum` — see useForm Mistake #3 |
129
- | `NumberField` | `integerPart`, `fractionPart` | |
130
- | `BooleanField` | — | |
131
- | `DateField` | — | Format: YYYY-MM-DD |
132
- | `DateTimeField` | `precision` | Format: YYYY-MM-DDTHH:MM:SS |
133
- | `SelectField` | **`options`**, `fetchOptions(instanceId)` | `.options` returns `{ value, label }[]` |
134
- | `ReferenceField` | `fetchOptions(instanceId)`, `referenceBdo` | Value is object `{ _id, _name, ... }` |
135
- | `TextField` | `format` | Long text |
136
- | `UserField` | `fetchOptions(instanceId)` | Value: `{ _id, _name }` |
137
- | `ImageField` | — | Value: `FileType \| null` |
138
- | `FileField` | — | Value: `FileType[]` |
139
-
140
- **CRITICAL**: Only `SelectField` has `.options` getter. `StringField` with `Constraint.Enum` does NOT.
141
-
142
- ---
143
-
144
- ## Methods
145
-
146
- All methods are `protected` on `BaseBdo`. Role BDOs selectively expose them as `public`.
147
-
148
- ```typescript
149
- // Read
150
- const item = await bdo.get(id); // ItemType — call .get() on fields
151
- const items = await bdo.list(options?); // ItemType[] — call .get() on fields
152
- const count = await bdo.count(options?); // number
153
-
154
- // Write
155
- const created = await bdo.create(data); // ItemType
156
- const result = await bdo.update(id, data); // { _id: string }
157
- const deleted = await bdo.delete(id); // { status: "success" }
158
-
159
- // Draft
160
- const draft = await bdo.draft(data); // { [field]: computed_value }
161
- const draftPatch = await bdo.draftPatch(id, data);
162
- const draftInt = await bdo.draftInteraction(data); // { _id, ...computed }
163
-
164
- // Analytics
165
- const metric = await bdo.metric({ GroupBy: [], Metric: [{ Field: "_id", Type: "Count" }] });
166
- // Access: metric.Data[0]["count__id"] (key pattern: {type}_{Field})
167
-
168
- const pivot = await bdo.pivot({ Row: ["category"], Column: ["status"], Metric: [{ Field: "_id", Type: "Count" }] });
169
- // Access: pivot.Data.RowHeader, pivot.Data.ColumnHeader, pivot.Data.Value[row][col]
170
- ```
171
-
172
- ### ListOptionsType
173
-
174
- ```typescript
175
- interface ListOptionsType {
176
- Field?: string[]; // Specific fields (omit for all)
177
- Filter?: FilterType; // See useFilter docs
178
- Sort?: Record<string, "ASC" | "DESC">[]; // [{ "field": "ASC" }]
179
- Page?: number; // 1-indexed
180
- PageSize?: number; // Default: 10
181
- }
182
- ```
183
-
184
- ---
185
-
186
- ## ItemType Accessor Pattern
187
-
188
- `get()`, `list()`, `create()` return `ItemType` with Proxy-wrapped field accessors.
189
-
190
- ```typescript
191
- const item = await bdo.get("id123");
192
-
193
- item._id; // "id123" — direct access (only _id)
194
- item.product_name.get(); // string | undefined
195
- item.product_name.set("New"); // editable fields only
196
- item.product_name.label; // "product_name"
197
- item.product_name.required; // boolean
198
- item.toJSON(); // plain object
199
- ```
200
-
201
- ## SystemFieldsType
202
-
203
- ```typescript
204
- type SystemFieldsType = {
205
- _id: string;
206
- _created_at: string; // "YYYY-MM-DDTHH:MM:SS"
207
- _modified_at: string;
208
- _created_by: { _id: string; _name: string };
209
- _modified_by: { _id: string; _name: string };
210
- _version: string;
211
- _m_version: string;
212
- };
213
- ```
214
-
215
- ## API Types
216
-
217
- ```typescript
218
- interface CreateUpdateResponseType { _id: string; }
219
- interface DeleteResponseType { status: "success"; }
220
- interface FileType { _id: string; _name: string; FileName: string; FileExtension: string; Size: number; ContentType: string; }
221
- type ImageFieldType = FileType | null;
222
- type FileFieldType = FileType[];
223
- type AggregationType = "Sum" | "Avg" | "Count" | "Max" | "Min" | "DistinctCount" | "BlankCount" | "NotBlankCount" | "Concat" | "DistinctConcat";
224
- ```