@ram_28/kf-ai-sdk 2.0.19 → 2.0.20-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +8 -16
  2. package/dist/{FileField-CZjS2uLh.js → FileField-BWrSHNRq.js} +3 -3
  3. package/dist/{FileField-DU4UWo_t.cjs → FileField-eDeuzln8.cjs} +1 -1
  4. package/dist/api.cjs +1 -1
  5. package/dist/api.mjs +1 -1
  6. package/dist/auth/authConfig.d.ts +1 -1
  7. package/dist/auth/types.d.ts +1 -1
  8. package/dist/auth/types.d.ts.map +1 -1
  9. package/dist/auth.cjs +1 -1
  10. package/dist/auth.mjs +1 -1
  11. package/dist/bdo/core/Item.d.ts +4 -0
  12. package/dist/bdo/core/Item.d.ts.map +1 -1
  13. package/dist/bdo/fields/ReferenceField.d.ts +1 -1
  14. package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
  15. package/dist/bdo/fields/SelectField.d.ts +1 -1
  16. package/dist/bdo/fields/SelectField.d.ts.map +1 -1
  17. package/dist/bdo/fields/UserField.d.ts +1 -1
  18. package/dist/bdo/fields/UserField.d.ts.map +1 -1
  19. package/dist/bdo.cjs +1 -1
  20. package/dist/bdo.mjs +62 -53
  21. package/dist/components/hooks/useActivityForm/types.d.ts +5 -4
  22. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  23. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  24. package/dist/components/hooks/useActivityTable/types.d.ts +4 -5
  25. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  26. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  27. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts +3 -2
  28. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -1
  29. package/dist/components/hooks/useBDOTable/types.d.ts +12 -20
  30. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  31. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
  32. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  33. package/dist/{constants-Cyi942Yr.js → constants-ConHc1oS.js} +5 -5
  34. package/dist/constants-QX2RX-wu.cjs +1 -0
  35. package/dist/filter.cjs +1 -1
  36. package/dist/filter.mjs +1 -1
  37. package/dist/form.cjs +1 -1
  38. package/dist/form.mjs +243 -226
  39. package/dist/table.cjs +1 -1
  40. package/dist/table.mjs +16 -15
  41. package/dist/table.types.d.ts +1 -1
  42. package/dist/table.types.d.ts.map +1 -1
  43. package/dist/types/constants.d.ts +1 -1
  44. package/dist/workflow/Activity.d.ts +5 -8
  45. package/dist/workflow/Activity.d.ts.map +1 -1
  46. package/dist/workflow.cjs +1 -1
  47. package/dist/workflow.mjs +476 -461
  48. package/docs/api.md +95 -0
  49. package/docs/bdo.md +224 -0
  50. package/docs/gaps.md +360 -0
  51. package/docs/useActivityForm.md +393 -0
  52. package/docs/useActivityTable.md +418 -0
  53. package/docs/useBDOForm.md +498 -0
  54. package/docs/useBDOTable.md +284 -0
  55. package/docs/useFilter.md +188 -0
  56. package/docs/workflow.md +560 -0
  57. package/package.json +14 -15
  58. package/sdk/auth/authConfig.ts +1 -1
  59. package/sdk/auth/types.ts +1 -1
  60. package/sdk/bdo/core/Item.ts +10 -1
  61. package/sdk/bdo/fields/ReferenceField.ts +1 -1
  62. package/sdk/bdo/fields/SelectField.ts +1 -1
  63. package/sdk/bdo/fields/UserField.ts +1 -1
  64. package/sdk/components/hooks/useActivityForm/types.ts +6 -4
  65. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +73 -10
  66. package/sdk/components/hooks/useActivityTable/types.ts +5 -4
  67. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +8 -10
  68. package/sdk/components/hooks/useBDOForm/createItemProxy.ts +58 -17
  69. package/sdk/components/hooks/useBDOTable/types.ts +10 -20
  70. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +8 -12
  71. package/sdk/table.types.ts +0 -2
  72. package/sdk/types/constants.ts +1 -1
  73. package/sdk/workflow/Activity.ts +7 -39
  74. package/dist/constants-DEmYwKfC.cjs +0 -1
  75. package/docs/README.md +0 -57
  76. package/docs/bdo/README.md +0 -161
  77. package/docs/bdo/api_reference.md +0 -281
  78. package/docs/examples/bdo/create-product.md +0 -69
  79. package/docs/examples/bdo/edit-product-dialog.md +0 -95
  80. package/docs/examples/bdo/filtered-product-table.md +0 -100
  81. package/docs/examples/bdo/product-listing.md +0 -73
  82. package/docs/examples/bdo/supplier-dropdown.md +0 -60
  83. package/docs/examples/fields/complex-fields.md +0 -248
  84. package/docs/examples/fields/primitive-fields.md +0 -217
  85. package/docs/examples/workflow/approve-leave-request.md +0 -76
  86. package/docs/examples/workflow/filtered-activity-table.md +0 -101
  87. package/docs/examples/workflow/my-pending-requests.md +0 -90
  88. package/docs/examples/workflow/start-new-workflow.md +0 -47
  89. package/docs/examples/workflow/submit-leave-request.md +0 -72
  90. package/docs/examples/workflow/workflow-progress.md +0 -49
  91. package/docs/fields/README.md +0 -141
  92. package/docs/fields/api_reference.md +0 -134
  93. package/docs/useActivityForm/README.md +0 -244
  94. package/docs/useActivityForm/api_reference.md +0 -279
  95. package/docs/useActivityTable/README.md +0 -263
  96. package/docs/useActivityTable/api_reference.md +0 -294
  97. package/docs/useBDOForm/README.md +0 -175
  98. package/docs/useBDOForm/api_reference.md +0 -244
  99. package/docs/useBDOTable/README.md +0 -242
  100. package/docs/useBDOTable/api_reference.md +0 -253
  101. package/docs/useFilter/README.md +0 -323
  102. package/docs/useFilter/api_reference.md +0 -228
  103. package/docs/workflow/README.md +0 -158
  104. package/docs/workflow/api_reference.md +0 -161
  105. /package/docs/{useAuth/README.md → useAuth.md} +0 -0
@@ -15,7 +15,6 @@ import type {
15
15
  } from 'react-hook-form';
16
16
 
17
17
  import type { Activity } from '../../../workflow/Activity';
18
- import type { CreateUpdateResponseType } from '../../../types/common';
19
18
 
20
19
  // Reuse shared types from useBDOForm — identical interfaces, no duplication
21
20
  import type {
@@ -105,8 +104,11 @@ export interface UseActivityFormReturn<A extends Activity<any, any, any>> {
105
104
  ExtractActivityReadonly<A>
106
105
  >;
107
106
 
108
- /** Handle form submission — validates, updates dirty fields, then completes the activity */
109
- handleSubmit: HandleSubmitType<CreateUpdateResponseType>;
107
+ /** Handle form submission — calls activity.update() */
108
+ handleSubmit: HandleSubmitType<AllActivityFields<A>>;
109
+
110
+ /** Handle form completion — calls activity.update() + activity.complete() */
111
+ handleComplete: HandleSubmitType<AllActivityFields<A>>;
110
112
 
111
113
  /** Watch field values */
112
114
  watch: UseFormWatch<AllActivityFields<A>>;
@@ -139,7 +141,7 @@ export interface UseActivityFormReturn<A extends Activity<any, any, any>> {
139
141
  /** Form has been modified */
140
142
  isDirty: boolean;
141
143
 
142
- /** Form is currently submitting */
144
+ /** Form is currently submitting (save or complete) */
143
145
  isSubmitting: boolean;
144
146
 
145
147
  /** Form submission was successful */
@@ -10,9 +10,12 @@ import { useForm as useReactHookForm } from 'react-hook-form';
10
10
  import { useQuery } from '@tanstack/react-query';
11
11
 
12
12
  import type { Activity } from '../../../workflow/Activity';
13
- import type { UseActivityFormOptions, UseActivityFormReturn } from './types';
13
+ import type {
14
+ UseActivityFormOptions,
15
+ UseActivityFormReturn,
16
+ AllActivityFields,
17
+ } from './types';
14
18
 
15
- import type { CreateUpdateResponseType } from '../../../types/common';
16
19
  import { createActivityResolver } from './createActivityResolver';
17
20
  import { createActivityItemProxy } from './createActivityItemProxy';
18
21
  import {
@@ -297,13 +300,13 @@ export function useActivityForm<A extends Activity<any, any, any>>(
297
300
  );
298
301
 
299
302
  // ============================================================
300
- // HANDLE SUBMIT — activity.update() + activity.complete()
303
+ // HANDLE SUBMIT — activity.update()
301
304
  // ============================================================
302
305
 
303
306
  const handleSubmit = useCallback(
304
307
  (
305
308
  onSuccess?: (
306
- data: CreateUpdateResponseType,
309
+ data: AllActivityFields<A>,
307
310
  e?: React.BaseSyntheticEvent,
308
311
  ) => void | Promise<void>,
309
312
  onError?: (
@@ -316,7 +319,7 @@ export function useActivityForm<A extends Activity<any, any, any>>(
316
319
  setIsSubmitting(true);
317
320
 
318
321
  try {
319
- // Only send dirty (changed) fields — matches useBDOForm behavior
322
+ // Only send dirty (changed) fields — matches useBDOForm update behavior
320
323
  // Use getValues() to capture Image/File values set via setValue()
321
324
  // that RHF resolver doesn't include in `data`
322
325
  const cleanedData: Record<string, unknown> = {};
@@ -336,7 +339,7 @@ export function useActivityForm<A extends Activity<any, any, any>>(
336
339
  : value;
337
340
  }
338
341
 
339
- // Send remaining dirty fields via update
342
+ // Save via activity.update()
340
343
  if (Object.keys(cleanedData).length > 0) {
341
344
  await activityRef.update(
342
345
  activity_instance_id,
@@ -344,10 +347,7 @@ export function useActivityForm<A extends Activity<any, any, any>>(
344
347
  );
345
348
  }
346
349
 
347
- // Complete the activity — advances the workflow
348
- const result = await activityRef.complete(activity_instance_id);
349
-
350
- await onSuccess?.(result, event);
350
+ await onSuccess?.(data as AllActivityFields<A>, event);
351
351
  } catch (error) {
352
352
  onError?.(toError(error), event);
353
353
  } finally {
@@ -362,6 +362,68 @@ export function useActivityForm<A extends Activity<any, any, any>>(
362
362
  [rhf, activityRef, readonlyFieldNames, allFields, activity_instance_id],
363
363
  ) as UseActivityFormReturn<A>['handleSubmit'];
364
364
 
365
+ // ============================================================
366
+ // HANDLE COMPLETE — activity.update() + activity.complete()
367
+ // ============================================================
368
+
369
+ const handleComplete = useCallback(
370
+ (
371
+ onSuccess?: (
372
+ data: AllActivityFields<A>,
373
+ e?: React.BaseSyntheticEvent,
374
+ ) => void | Promise<void>,
375
+ onError?: (
376
+ error: any,
377
+ e?: React.BaseSyntheticEvent,
378
+ ) => void | Promise<void>,
379
+ ) => {
380
+ return rhf.handleSubmit(
381
+ async (data, event) => {
382
+ setIsSubmitting(true);
383
+
384
+ try {
385
+ // Only send dirty (changed) fields — matches useBDOForm update behavior
386
+ // Use getValues() to capture Image/File values set via setValue()
387
+ // that RHF resolver doesn't include in `data`
388
+ const cleanedData: Record<string, unknown> = {};
389
+ const readonlySet = new Set(readonlyFieldNames);
390
+ const dirtyFields = rhf.formState.dirtyFields;
391
+ const allValues = rhf.getValues() as Record<string, unknown>;
392
+
393
+ for (const key of Object.keys(allValues)) {
394
+ if (readonlySet.has(key) || !dirtyFields[key]) continue;
395
+ const value =
396
+ allValues[key] !== undefined
397
+ ? allValues[key]
398
+ : (data as Record<string, unknown>)[key];
399
+ const field = allFields[key];
400
+ cleanedData[key] = field
401
+ ? coerceFieldValue(field, value)
402
+ : value;
403
+ }
404
+
405
+ if (Object.keys(cleanedData).length > 0) {
406
+ await activityRef.update(
407
+ activity_instance_id,
408
+ cleanedData as any,
409
+ );
410
+ }
411
+ await activityRef.complete(activity_instance_id);
412
+ await onSuccess?.(data as AllActivityFields<A>, event);
413
+ } catch (error) {
414
+ onError?.(toError(error), event);
415
+ } finally {
416
+ setIsSubmitting(false);
417
+ }
418
+ },
419
+ (errors, event) => {
420
+ onError?.(errors, event);
421
+ },
422
+ );
423
+ },
424
+ [rhf, activityRef, readonlyFieldNames, allFields, activity_instance_id],
425
+ ) as UseActivityFormReturn<A>['handleComplete'];
426
+
365
427
  // ============================================================
366
428
  // CLEAR ERRORS
367
429
  // ============================================================
@@ -386,6 +448,7 @@ export function useActivityForm<A extends Activity<any, any, any>>(
386
448
  // Form methods
387
449
  register,
388
450
  handleSubmit,
451
+ handleComplete,
389
452
  watch: rhf.watch as any,
390
453
  setValue: rhf.setValue as any,
391
454
  getValues: rhf.getValues as any,
@@ -1,4 +1,5 @@
1
1
  import type { Activity } from '../../../workflow/Activity';
2
+ import type { ActivityInstanceFieldsType } from '../../../workflow/types';
2
3
  import type { UseTableReturnType, PaginationStateType } from '../useTable/types';
3
4
  import type { UseFilterOptionsType } from '../useFilter/types';
4
5
  import type { SortType } from '../../../types/common';
@@ -15,12 +16,12 @@ export type ActivityTableStatusType =
15
16
  (typeof ActivityTableStatus)[keyof typeof ActivityTableStatus];
16
17
 
17
18
  /**
18
- * Row type inferred from Activity's getInProgressList() return type.
19
- * Resolves to ActivityInstanceType (proxy with .get()/.set()).
19
+ * Row type for activity table data.
20
+ * System fields and entity fields are flat at the top level.
20
21
  */
21
22
  export type ActivityRowType<A extends Activity<any, any, any>> =
22
- A extends { getInProgressList(opts?: any): Promise<(infer R)[]> }
23
- ? R
23
+ A extends Activity<infer E, any, any>
24
+ ? ActivityInstanceFieldsType & E
24
25
  : never;
25
26
 
26
27
  export interface UseActivityTableOptionsType<
@@ -13,24 +13,22 @@ export function useActivityTable<A extends Activity<any, any, any>>(
13
13
  const { activity, status, ...rest } = options;
14
14
  const { businessProcessId, activityId } = activity.meta;
15
15
 
16
+ const ops = useMemo(() => activity._getOps(), [activity]);
17
+
16
18
  const listFn = useMemo(
17
19
  () =>
18
20
  status === 'inprogress'
19
- ? async (opts: any) => ({
20
- Data: (await activity.getInProgressList(opts)) as ActivityRowType<A>[],
21
- })
22
- : async (opts: any) => ({
23
- Data: (await activity.getCompletedList(opts)) as ActivityRowType<A>[],
24
- }),
25
- [activity, status],
21
+ ? (opts: any) => ops.inProgressList(opts)
22
+ : (opts: any) => ops.completedList(opts),
23
+ [ops, status],
26
24
  );
27
25
 
28
26
  const countFn = useMemo(
29
27
  () =>
30
28
  status === 'inprogress'
31
- ? async (opts: any) => ({ Count: await activity.inProgressCount(opts) })
32
- : async (opts: any) => ({ Count: await activity.completedCount(opts) }),
33
- [activity, status],
29
+ ? (opts: any) => ops.inProgressCount(opts)
30
+ : (opts: any) => ops.completedCount(opts),
31
+ [ops, status],
34
32
  );
35
33
 
36
34
  return useTable<ActivityRowType<A>>({
@@ -21,8 +21,9 @@ import type {
21
21
  * Key principle: Item has NO state. It's a view over RHF's state.
22
22
  * Editable fields get set(), readonly fields do not.
23
23
  *
24
- * In create mode (no _id), attachment and fetch operations use 'draft' as the
25
- * instanceId, which the backend accepts as a placeholder.
24
+ * Draft-based upload: In create mode (no _id), upload() automatically creates
25
+ * a draft record via draftInteraction() to get an _id, then uploads immediately.
26
+ * On form submit, if a draft _id exists, update() is used instead of create().
26
27
  *
27
28
  * @param bdo - The BDO instance for field metadata
28
29
  * @param form - The RHF useForm return object
@@ -35,11 +36,34 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
35
36
  const fields = bdo.getFields();
36
37
  const accessorCache = new Map<string, EditableFormFieldAccessorType<unknown> | ReadonlyFormFieldAccessorType<unknown>>();
37
38
 
39
+ // Draft tracking for create mode — shared across all attachment fields in this form
38
40
  const boIdShared = bdo.getBoId();
39
-
40
- /** Returns the real _id in edit mode, or 'draft' in create mode */
41
- const getInstanceId = (): string =>
42
- (form.getValues("_id" as Path<FieldValues>) as string) || "draft";
41
+ let draftId: string | null = null;
42
+ let draftPromise: Promise<string> | null = null;
43
+
44
+ /**
45
+ * Ensures a record _id exists for attachment uploads.
46
+ * In edit mode, returns the existing _id.
47
+ * In create mode, creates a draft record via draftInteraction() to get an _id.
48
+ * The draft _id is shared across all attachment fields and only created once.
49
+ */
50
+ async function ensureDraft(): Promise<string> {
51
+ // If form already has an _id (edit mode or previous draft), use it
52
+ const existing = form.getValues("_id" as Path<FieldValues>) as string | undefined;
53
+ if (existing) return existing;
54
+ if (draftId) return draftId;
55
+ if (!draftPromise) {
56
+ draftPromise = api(boIdShared).draftInteraction({}).then((d: any) => {
57
+ draftId = d._id;
58
+ form.setValue("_id" as Path<FieldValues>, draftId as any, { shouldDirty: false });
59
+ return draftId!;
60
+ }).catch((err: Error) => {
61
+ draftPromise = null;
62
+ throw err;
63
+ });
64
+ }
65
+ return draftPromise;
66
+ }
43
67
 
44
68
  return new Proxy({} as FormItemType<ExtractEditableType<B>, ExtractReadonlyType<B>>, {
45
69
  get(_, prop: string | symbol) {
@@ -63,6 +87,11 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
63
87
  return () => form.trigger();
64
88
  }
65
89
 
90
+ // Internal: check if a draft was created (used by handleSubmit)
91
+ if (prop === "_hasDraft") {
92
+ return () => !!draftId;
93
+ }
94
+
66
95
  // Return cached accessor if available
67
96
  if (accessorCache.has(prop)) {
68
97
  return accessorCache.get(prop);
@@ -153,12 +182,17 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
153
182
  // Enrich Image/File field accessors with attachment methods (draft-based upload)
154
183
  if (fieldMeta.Type === "Image" || fieldMeta.Type === "File") {
155
184
  const boId = boIdShared;
185
+ const requireInstanceId = (): string => {
186
+ const id = form.getValues("_id" as Path<FieldValues>) as string | undefined;
187
+ if (!id) throw new Error("Save the record before attachment operations");
188
+ return id;
189
+ };
156
190
 
157
191
  if (fieldMeta.Type === "Image") {
158
192
  // Image: single file upload — always uploads immediately (draft in create mode)
159
193
  (accessor as any).upload = async (file: File): Promise<FileType> => {
160
194
  validateFileExtension(file.name, "Image");
161
- const id = getInstanceId();
195
+ const id = await ensureDraft();
162
196
 
163
197
  const [uploadInfo] = await api(boId).getUploadUrl(id, prop, [
164
198
  { FileName: file.name, Size: file.size, FileExtension: extractFileExtension(file.name) },
@@ -182,7 +216,7 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
182
216
 
183
217
  (accessor as any).deleteAttachment = async (): Promise<void> => {
184
218
  const val = form.getValues(prop as Path<FieldValues>) as any;
185
- const instanceId = getInstanceId();
219
+ const instanceId = requireInstanceId();
186
220
  if (!(val?._id)) throw new Error(`${prop} has no image to delete`);
187
221
  await api(boId).deleteAttachment(instanceId, prop, val._id);
188
222
  form.setValue(prop as Path<FieldValues>, null as any, { shouldDirty: true });
@@ -190,7 +224,7 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
190
224
 
191
225
  (accessor as any).getDownloadUrl = async (viewType?: AttachmentViewType): Promise<FileDownloadResponseType> => {
192
226
  const val = form.getValues(prop as Path<FieldValues>) as any;
193
- const instanceId = getInstanceId();
227
+ const instanceId = requireInstanceId();
194
228
  if (!(val?._id)) throw new Error(`${prop} has no image`);
195
229
  return api(boId).getDownloadUrl(instanceId, prop, val._id, viewType);
196
230
  };
@@ -198,7 +232,7 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
198
232
  // File field — multi-file, always uploads immediately (draft in create mode)
199
233
  (accessor as any).upload = async (files: File[]): Promise<FileType[]> => {
200
234
  for (const file of files) validateFileExtension(file.name, "File");
201
- const id = getInstanceId();
235
+ const id = await ensureDraft();
202
236
 
203
237
  const requests = files.map((file) => ({
204
238
  FileName: file.name,
@@ -230,7 +264,7 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
230
264
 
231
265
  (accessor as any).deleteAttachment = async (attachmentId: string): Promise<void> => {
232
266
  const current = (form.getValues(prop as Path<FieldValues>) as any[]) ?? [];
233
- const instanceId = getInstanceId();
267
+ const instanceId = requireInstanceId();
234
268
  await api(boId).deleteAttachment(instanceId, prop, attachmentId);
235
269
  form.setValue(
236
270
  prop as Path<FieldValues>,
@@ -243,13 +277,13 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
243
277
  attachmentId: string,
244
278
  viewType?: AttachmentViewType,
245
279
  ): Promise<FileDownloadResponseType> => {
246
- const instanceId = getInstanceId();
280
+ const instanceId = requireInstanceId();
247
281
  return api(boId).getDownloadUrl(instanceId, prop, attachmentId, viewType);
248
282
  };
249
283
  (accessor as any).getDownloadUrls = async (
250
284
  viewType?: AttachmentViewType,
251
285
  ): Promise<FileDownloadResponseType[]> => {
252
- const instanceId = getInstanceId();
286
+ const instanceId = requireInstanceId();
253
287
  return api(boId).getDownloadUrls(instanceId, prop, viewType);
254
288
  };
255
289
  }
@@ -280,11 +314,16 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
280
314
  // Enrich readonly Image/File field accessors with download methods
281
315
  if (fieldMeta.Type === "Image" || fieldMeta.Type === "File") {
282
316
  const boId = boIdShared;
317
+ const requireInstanceId = (): string => {
318
+ const id = form.getValues("_id" as Path<FieldValues>) as string | undefined;
319
+ if (!id) throw new Error("Cannot perform attachment operation: item has no _id. Save the item first.");
320
+ return id;
321
+ };
283
322
 
284
323
  if (fieldMeta.Type === "Image") {
285
324
  (accessor as any).getDownloadUrl = async (viewType?: AttachmentViewType): Promise<FileDownloadResponseType> => {
286
325
  const val = form.getValues(prop as Path<FieldValues>) as any;
287
- const instanceId = getInstanceId();
326
+ const instanceId = requireInstanceId();
288
327
  if (!(val?._id)) throw new Error(`${prop} has no image to download`);
289
328
  return api(boId).getDownloadUrl(instanceId, prop, val._id, viewType);
290
329
  };
@@ -293,13 +332,13 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
293
332
  attachmentId: string,
294
333
  viewType?: AttachmentViewType,
295
334
  ): Promise<FileDownloadResponseType> => {
296
- const instanceId = getInstanceId();
335
+ const instanceId = requireInstanceId();
297
336
  return api(boId).getDownloadUrl(instanceId, prop, attachmentId, viewType);
298
337
  };
299
338
  (accessor as any).getDownloadUrls = async (
300
339
  viewType?: AttachmentViewType,
301
340
  ): Promise<FileDownloadResponseType[]> => {
302
- const instanceId = getInstanceId();
341
+ const instanceId = requireInstanceId();
303
342
  return api(boId).getDownloadUrls(instanceId, prop, viewType);
304
343
  };
305
344
  }
@@ -313,6 +352,8 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
313
352
  if (typeof prop === "symbol") return false;
314
353
  if (prop === "_id" || prop === "toJSON" || prop === "validate")
315
354
  return true;
355
+ if (prop === "_hasDraft")
356
+ return true;
316
357
  return prop in fields;
317
358
  },
318
359
 
@@ -324,7 +365,7 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
324
365
  if (typeof prop === "symbol") return undefined;
325
366
  return {
326
367
  configurable: true,
327
- enumerable: prop !== "toJSON" && prop !== "validate",
368
+ enumerable: prop !== "toJSON" && prop !== "validate" && prop !== "_hasDraft",
328
369
  };
329
370
  },
330
371
  });
@@ -1,32 +1,22 @@
1
- import type { ListOptionsType, SortType } from '../../../types/common';
2
1
  import type { UseTableReturnType, PaginationStateType } from '../useTable/types';
3
2
  import type { UseFilterOptionsType } from '../useFilter/types';
3
+ import type { SortType } from '../../../types/common';
4
4
 
5
- /** Structural constraint — any object with list() and count() */
6
- export interface BDOTableSourceType {
7
- meta: { readonly _id: string; readonly name: string };
8
- list(options?: ListOptionsType): Promise<any[]>;
9
- count(options?: ListOptionsType): Promise<number>;
10
- }
11
-
12
- /** Infer row type from BDO's list() return type */
13
- export type BDORowType<B extends BDOTableSourceType> =
14
- B extends { list(opts?: any): Promise<(infer R)[]> } ? R : never;
15
-
16
- export interface UseBDOTableOptionsType<B extends BDOTableSourceType> {
17
- /** BDO instance — list() and count() are called for data */
18
- bdo: B;
5
+ export interface UseBDOTableOptionsType<T> {
6
+ /** BDO instance — only meta._id is used (for API routing) */
7
+ bdo: {
8
+ meta: { readonly _id: string; readonly name: string };
9
+ };
19
10
  /** Initial state */
20
11
  initialState?: {
21
12
  sort?: SortType;
22
13
  pagination?: PaginationStateType;
23
- filter?: UseFilterOptionsType<BDORowType<B>>;
14
+ filter?: UseFilterOptionsType<T>;
24
15
  };
25
16
  /** Error callback */
26
17
  onError?: (error: Error) => void;
27
- /** Success callback — receives Item rows from current page */
28
- onSuccess?: (data: BDORowType<B>[]) => void;
18
+ /** Success callback — receives rows from current page */
19
+ onSuccess?: (data: T[]) => void;
29
20
  }
30
21
 
31
- export type UseBDOTableReturnType<B extends BDOTableSourceType> =
32
- UseTableReturnType<BDORowType<B>>;
22
+ export type UseBDOTableReturnType<T> = UseTableReturnType<T>;
@@ -1,20 +1,16 @@
1
+ import { api } from '../../../api/client';
1
2
  import { useTable } from '../useTable';
2
- import type {
3
- BDOTableSourceType,
4
- BDORowType,
5
- UseBDOTableOptionsType,
6
- UseBDOTableReturnType,
7
- } from './types';
3
+ import type { UseBDOTableOptionsType, UseBDOTableReturnType } from './types';
8
4
 
9
- export function useBDOTable<B extends BDOTableSourceType>(
10
- options: UseBDOTableOptionsType<B>,
11
- ): UseBDOTableReturnType<B> {
5
+ export function useBDOTable<T = any>(
6
+ options: UseBDOTableOptionsType<T>,
7
+ ): UseBDOTableReturnType<T> {
12
8
  const { bdo, ...rest } = options;
13
9
 
14
- return useTable<BDORowType<B>>({
10
+ return useTable<T>({
15
11
  queryKey: ['table', bdo.meta._id],
16
- listFn: async (opts) => ({ Data: await bdo.list(opts) }),
17
- countFn: async (opts) => ({ Count: await bdo.count(opts) }),
12
+ listFn: (opts) => api<T>(bdo.meta._id).list(opts),
13
+ countFn: (opts) => api<T>(bdo.meta._id).count(opts),
18
14
  ...rest,
19
15
  });
20
16
  }
@@ -14,8 +14,6 @@ export type {
14
14
 
15
15
  export type {
16
16
  // BDO wrapper types
17
- BDOTableSourceType,
18
- BDORowType,
19
17
  UseBDOTableOptionsType,
20
18
  UseBDOTableReturnType,
21
19
  } from './components/hooks/useBDOTable/types';
@@ -351,7 +351,7 @@ export const AuthStatus = {
351
351
  */
352
352
  export const AuthProviderName = {
353
353
  Google: "google",
354
- Azure: "azure",
354
+ Microsoft: "microsoft",
355
355
  GitHub: "github",
356
356
  Custom: "custom",
357
357
  } as const;
@@ -23,15 +23,13 @@ import { createActivityInstance } from "./ActivityInstance";
23
23
  import type { ActivityInstanceType } from "./ActivityInstance";
24
24
  import type { ActivityInstanceFieldsType, ActivityOperations } from "./types";
25
25
  import type {
26
+ ListResponseType,
26
27
  ListOptionsType,
27
28
  MetricOptionsType,
28
29
  MetricResponseType,
29
30
  } from "../types/common";
30
31
  import { BaseField } from "../bdo/fields/BaseField";
31
32
 
32
- /** Activity system fields treated as readonly on list results */
33
- type ActivitySystemReadonlyType = Omit<ActivityInstanceFieldsType, '_id'>;
34
-
35
33
  // ============================================================
36
34
  // ABSTRACT BASE CLASS
37
35
  // ============================================================
@@ -130,48 +128,18 @@ export abstract class Activity<
130
128
 
131
129
  /**
132
130
  * List in-progress activity instances.
133
- * Each row is wrapped in an ActivityInstance proxy with field accessors.
131
+ * Accepts optional filter/sort/pagination options.
134
132
  */
135
- async getInProgressList(
136
- options?: ListOptionsType,
137
- ): Promise<ActivityInstanceType<
138
- ActivityInstanceFieldsType & TEntity,
139
- TEditable,
140
- TReadonly & ActivitySystemReadonlyType
141
- >[]> {
142
- const ops = this._ops();
143
- const response = await ops.inProgressList(options);
144
- const fields = this._discoverFields();
145
- return response.Data.map((data) =>
146
- createActivityInstance<
147
- ActivityInstanceFieldsType & TEntity,
148
- TEditable,
149
- TReadonly & ActivitySystemReadonlyType
150
- >(ops, (data as any)._id, data as (ActivityInstanceFieldsType & TEntity), fields),
151
- );
133
+ async getInProgressList(options?: ListOptionsType): Promise<ListResponseType<ActivityInstanceFieldsType & TEntity>> {
134
+ return this._ops().inProgressList(options);
152
135
  }
153
136
 
154
137
  /**
155
138
  * List completed activity instances.
156
- * Each row is wrapped in an ActivityInstance proxy with field accessors.
139
+ * Accepts optional filter/sort/pagination options.
157
140
  */
158
- async getCompletedList(
159
- options?: ListOptionsType,
160
- ): Promise<ActivityInstanceType<
161
- ActivityInstanceFieldsType & TEntity,
162
- TEditable,
163
- TReadonly & ActivitySystemReadonlyType
164
- >[]> {
165
- const ops = this._ops();
166
- const response = await ops.completedList(options);
167
- const fields = this._discoverFields();
168
- return response.Data.map((data) =>
169
- createActivityInstance<
170
- ActivityInstanceFieldsType & TEntity,
171
- TEditable,
172
- TReadonly & ActivitySystemReadonlyType
173
- >(ops, (data as any)._id, data as (ActivityInstanceFieldsType & TEntity), fields),
174
- );
141
+ async getCompletedList(options?: ListOptionsType): Promise<ListResponseType<ActivityInstanceFieldsType & TEntity>> {
142
+ return this._ops().completedList(options);
175
143
  }
176
144
 
177
145
  /**
@@ -1 +0,0 @@
1
- "use strict";const t={EQ:"EQ",NE:"NE",GT:"GT",GTE:"GTE",LT:"LT",LTE:"LTE",Between:"Between",NotBetween:"NotBetween",IN:"IN",NIN:"NIN",Empty:"Empty",NotEmpty:"NotEmpty",Contains:"Contains",NotContains:"NotContains",MinLength:"MinLength",MaxLength:"MaxLength",Length:"Length"},e={And:"And",Or:"Or",Not:"Not"},n={Constant:"Constant",BDOField:"BDOField",AppVariable:"AppVariable"},o={ASC:"ASC",DESC:"DESC"},i={Sum:"Sum",Avg:"Avg",Count:"Count",Max:"Max",Min:"Min",DistinctCount:"DistinctCount",BlankCount:"BlankCount",NotBlankCount:"NotBlankCount",Concat:"Concat",DistinctConcat:"DistinctConcat"},a={List:"List",Metric:"Metric",Pivot:"Pivot"},r={Create:"create",Update:"update"},c={Interactive:"interactive",NonInteractive:"non-interactive"},s={OnBlur:"onBlur",OnChange:"onChange",OnSubmit:"onSubmit",OnTouched:"onTouched",All:"all"},d={Loading:"loading",Authenticated:"authenticated",Unauthenticated:"unauthenticated"},u={Google:"google",Azure:"azure",GitHub:"github",Custom:"custom"},C={Id:"_id",CreatedAt:"_created_at",ModifiedAt:"_modified_at",CreatedBy:"_created_by",ModifiedBy:"_modified_by",Version:"_version",MergeVersion:"_m_version"},E={GET:"GET",POST:"POST",PATCH:"PATCH",DELETE:"DELETE"},p={SEARCH_DEBOUNCE_MS:300,PAGE_SIZE:10,PAGE:1,SEARCH_MAX_LENGTH:255},T={Date:"$__d__",DateTime:"$__dt__"},l={Success:"success"};exports.AuthProviderName=u;exports.AuthStatus=d;exports.ConditionOperator=t;exports.DateEncodingKey=T;exports.Defaults=p;exports.DeleteStatus=l;exports.FormOperation=r;exports.GroupOperator=e;exports.HttpMethod=E;exports.InteractionMode=c;exports.MetricType=i;exports.QueryType=a;exports.RHSType=n;exports.SortDirection=o;exports.SystemField=C;exports.ValidationMode=s;
package/docs/README.md DELETED
@@ -1,57 +0,0 @@
1
- # @ram_28/kf-ai-sdk Documentation
2
-
3
- React SDK for building web applications with type-safe hooks for forms, tables, workflow, and authentication.
4
-
5
- ## Authentication
6
-
7
- **[`useAuth`](./useAuth/README.md)** — Cookie-based authentication with `AuthProvider`, login/logout, session management, and role checks. Wrap your app in `<AuthProvider>` and use `useAuth()` to access `user`, `isAuthenticated`, `login()`, `logout()`.
8
-
9
- ## BDO (Business Data Objects)
10
-
11
- BDO is the data access layer. See the [BDO module docs](./bdo/README.md) for field classes, Item proxy, and the three-generics pattern.
12
-
13
- ### When working with field types and metadata
14
-
15
- **See [Fields](./fields/README.md)** · [API Reference](./fields/api_reference.md)
16
-
17
- All 13 field classes (`StringField`, `NumberField`, `SelectField`, `ReferenceField`, `FileField`, etc.), the `BaseField<T>` contract, field-specific getters (`length`, `options`, `precision`, `format`), and pre-built UI components for attachments.
18
-
19
- ### When building a form for a BDO record
20
-
21
- **Use [`useBDOForm`](./useBDOForm/README.md)** · [API Reference](./useBDOForm/api_reference.md)
22
-
23
- Create, edit, or view a single BDO record. Automatic validation, per-field server sync, and `handleSubmit` to persist.
24
-
25
- ### When building a table of BDO records
26
-
27
- **Use [`useBDOTable`](./useBDOTable/README.md)** · [API Reference](./useBDOTable/api_reference.md)
28
-
29
- List BDO records with sorting, search, filtering, and pagination. Rows are proxies with `.get()` accessors.
30
-
31
- ### When building a CRUD page (table + form dialog)
32
-
33
- **Use `useBDOTable` + `useBDOForm` together.**
34
-
35
- The table lists records; clicking a row opens a form dialog to create or edit.
36
-
37
- ## Workflow
38
-
39
- Workflow orchestrates multi-step business processes (e.g., employee submits leave → manager approves). See the [Workflow module docs](./workflow/README.md) for `Workflow`, `Activity`, and instance management.
40
-
41
- ### When building a form for a workflow activity
42
-
43
- **Use [`useActivityForm`](./useActivityForm/README.md)** · [API Reference](./useActivityForm/api_reference.md)
44
-
45
- Fill in an activity's input fields. Same API shape as `useBDOForm` but operates on activity instances. Context-derived readonly fields from prior activities are discovered automatically from BP metadata.
46
-
47
- ### When building a table of workflow activities
48
-
49
- **Use [`useActivityTable`](./useActivityTable/README.md)** · [API Reference](./useActivityTable/api_reference.md)
50
-
51
- List in-progress or completed activity instances. Same API shape as `useBDOTable` with activity system fields (`Status`, `AssignedTo`, `CompletedAt`, `BPInstanceId`).
52
-
53
- ### When building a workflow page (table + form dialog)
54
-
55
- **Use `useActivityTable` + `useActivityForm` together.**
56
-
57
- The table lists activity instances; clicking a row opens a form dialog.