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

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 (93) hide show
  1. package/README.md +8 -16
  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/Item.d.ts.map +1 -1
  10. package/dist/bdo.cjs +1 -1
  11. package/dist/bdo.mjs +32 -32
  12. package/dist/components/hooks/useActivityForm/types.d.ts +5 -4
  13. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  14. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  15. package/dist/components/hooks/useActivityTable/types.d.ts +4 -5
  16. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  17. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  18. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts +2 -2
  19. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -1
  20. package/dist/components/hooks/useBDOTable/types.d.ts +12 -20
  21. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  22. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
  23. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  24. package/dist/{constants-Cyi942Yr.js → constants-ConHc1oS.js} +5 -5
  25. package/dist/constants-QX2RX-wu.cjs +1 -0
  26. package/dist/filter.cjs +1 -1
  27. package/dist/filter.mjs +1 -1
  28. package/dist/form.cjs +1 -1
  29. package/dist/form.mjs +1 -1
  30. package/dist/table.cjs +1 -1
  31. package/dist/table.mjs +16 -15
  32. package/dist/table.types.d.ts +1 -1
  33. package/dist/table.types.d.ts.map +1 -1
  34. package/dist/types/constants.d.ts +1 -1
  35. package/dist/workflow/Activity.d.ts +5 -8
  36. package/dist/workflow/Activity.d.ts.map +1 -1
  37. package/dist/workflow.cjs +1 -1
  38. package/dist/workflow.mjs +476 -461
  39. package/docs/api.md +95 -0
  40. package/docs/bdo.md +224 -0
  41. package/docs/gaps.md +360 -0
  42. package/docs/useActivityForm.md +393 -0
  43. package/docs/useActivityTable.md +418 -0
  44. package/docs/useBDOForm.md +498 -0
  45. package/docs/useBDOTable.md +284 -0
  46. package/docs/useFilter.md +188 -0
  47. package/docs/workflow.md +560 -0
  48. package/package.json +14 -15
  49. package/sdk/auth/authConfig.ts +1 -1
  50. package/sdk/auth/types.ts +1 -1
  51. package/sdk/bdo/core/Item.ts +1 -2
  52. package/sdk/components/hooks/useActivityForm/types.ts +6 -4
  53. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +73 -10
  54. package/sdk/components/hooks/useActivityTable/types.ts +5 -4
  55. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +8 -10
  56. package/sdk/components/hooks/useBDOForm/createItemProxy.ts +5 -9
  57. package/sdk/components/hooks/useBDOTable/types.ts +10 -20
  58. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +8 -12
  59. package/sdk/table.types.ts +0 -2
  60. package/sdk/types/constants.ts +1 -1
  61. package/sdk/workflow/Activity.ts +7 -39
  62. package/dist/constants-DEmYwKfC.cjs +0 -1
  63. package/docs/README.md +0 -57
  64. package/docs/bdo/README.md +0 -161
  65. package/docs/bdo/api_reference.md +0 -281
  66. package/docs/examples/bdo/create-product.md +0 -69
  67. package/docs/examples/bdo/edit-product-dialog.md +0 -95
  68. package/docs/examples/bdo/filtered-product-table.md +0 -100
  69. package/docs/examples/bdo/product-listing.md +0 -73
  70. package/docs/examples/bdo/supplier-dropdown.md +0 -60
  71. package/docs/examples/fields/complex-fields.md +0 -248
  72. package/docs/examples/fields/primitive-fields.md +0 -217
  73. package/docs/examples/workflow/approve-leave-request.md +0 -76
  74. package/docs/examples/workflow/filtered-activity-table.md +0 -101
  75. package/docs/examples/workflow/my-pending-requests.md +0 -90
  76. package/docs/examples/workflow/start-new-workflow.md +0 -47
  77. package/docs/examples/workflow/submit-leave-request.md +0 -72
  78. package/docs/examples/workflow/workflow-progress.md +0 -49
  79. package/docs/fields/README.md +0 -141
  80. package/docs/fields/api_reference.md +0 -134
  81. package/docs/useActivityForm/README.md +0 -244
  82. package/docs/useActivityForm/api_reference.md +0 -279
  83. package/docs/useActivityTable/README.md +0 -263
  84. package/docs/useActivityTable/api_reference.md +0 -294
  85. package/docs/useBDOForm/README.md +0 -175
  86. package/docs/useBDOForm/api_reference.md +0 -244
  87. package/docs/useBDOTable/README.md +0 -242
  88. package/docs/useBDOTable/api_reference.md +0 -253
  89. package/docs/useFilter/README.md +0 -323
  90. package/docs/useFilter/api_reference.md +0 -228
  91. package/docs/workflow/README.md +0 -158
  92. package/docs/workflow/api_reference.md +0 -161
  93. /package/docs/{useAuth/README.md → useAuth.md} +0 -0
@@ -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,8 @@ 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
+ * In create mode (no _id), uses "draft" as the instanceId for attachment
25
+ * uploads and fetch operations no draftInteraction() call needed.
26
26
  *
27
27
  * @param bdo - The BDO instance for field metadata
28
28
  * @param form - The RHF useForm return object
@@ -36,8 +36,6 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
36
36
  const accessorCache = new Map<string, EditableFormFieldAccessorType<unknown> | ReadonlyFormFieldAccessorType<unknown>>();
37
37
 
38
38
  const boIdShared = bdo.getBoId();
39
-
40
- /** Returns the real _id in edit mode, or 'draft' in create mode */
41
39
  const getInstanceId = (): string =>
42
40
  (form.getValues("_id" as Path<FieldValues>) as string) || "draft";
43
41
 
@@ -150,16 +148,15 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
150
148
  validate,
151
149
  };
152
150
 
153
- // Enrich Image/File field accessors with attachment methods (draft-based upload)
151
+ // Enrich Image/File field accessors with attachment methods
154
152
  if (fieldMeta.Type === "Image" || fieldMeta.Type === "File") {
155
153
  const boId = boIdShared;
156
154
 
157
155
  if (fieldMeta.Type === "Image") {
158
- // Image: single file upload — always uploads immediately (draft in create mode)
156
+ // Image: single file upload
159
157
  (accessor as any).upload = async (file: File): Promise<FileType> => {
160
158
  validateFileExtension(file.name, "Image");
161
159
  const id = getInstanceId();
162
-
163
160
  const [uploadInfo] = await api(boId).getUploadUrl(id, prop, [
164
161
  { FileName: file.name, Size: file.size, FileExtension: extractFileExtension(file.name) },
165
162
  ]);
@@ -195,11 +192,10 @@ export function createItemProxy<B extends BaseBdo<any, any, any>>(
195
192
  return api(boId).getDownloadUrl(instanceId, prop, val._id, viewType);
196
193
  };
197
194
  } else {
198
- // File field — multi-file, always uploads immediately (draft in create mode)
195
+ // File field — multi-file
199
196
  (accessor as any).upload = async (files: File[]): Promise<FileType[]> => {
200
197
  for (const file of files) validateFileExtension(file.name, "File");
201
198
  const id = getInstanceId();
202
-
203
199
  const requests = files.map((file) => ({
204
200
  FileName: file.name,
205
201
  Size: file.size,
@@ -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.
@@ -1,161 +0,0 @@
1
- # BDO (Business Data Object)
2
-
3
- Type-safe, role-based data access layer. Each BDO class extends `BaseBdo<TEntity, TEditable, TReadonly>` and exposes CRUD methods filtered by role permissions.
4
-
5
- ## Imports
6
-
7
- ```typescript
8
- // Page component — import the generated role-specific BDO class
9
- import { AdminProduct } from "../bdo/admin/Product";
10
- ```
11
-
12
- ```typescript
13
- // BDO class definition — used by the js_sdk generator
14
- import { BaseBdo, StringField, NumberField, BooleanField, DateField, SelectField, ReferenceField } from "@ram_28/kf-ai-sdk/bdo";
15
- import type { StringFieldType, NumberFieldType, BooleanFieldType, DateFieldType, SelectFieldType, ReferenceFieldType, SystemFieldsType } from "@ram_28/kf-ai-sdk/types";
16
- import type { ListOptionsType } from "@ram_28/kf-ai-sdk/api/types";
17
- ```
18
-
19
- ## Common Mistakes (READ FIRST)
20
-
21
- 1. **`create()` returns `ItemType`, not `{ _id }`** — It returns a proxy-wrapped item with field accessors, not `CreateUpdateResponseType`. Use `item._id` to get the ID.
22
- 2. **Use `.get()` to read field values** — `item.Title` returns a field accessor object, not the value. Use `item.Title.get()`.
23
- 3. **Field names use `_name` not `name`** — System fields like `_created_by` return `{ _id, _name }`. Access the display name with `item._created_by.get()?._name`.
24
- 4. **Memoize BDO instances in React** — Wrap in `useMemo` to prevent re-creation on every render:
25
- ```typescript
26
- const product = useMemo(() => new AdminProduct(), []);
27
- ```
28
-
29
- ## Quick Start
30
-
31
- ```typescript
32
- const product = new AdminProduct();
33
-
34
- // Create — returns ItemType (proxy with field accessors)
35
- const item = await product.create({ Title: "Widget", Price: 29.99 });
36
- item._id; // "abc123"
37
- item.Title.get(); // "Widget"
38
- item.Price.get(); // 29.99
39
-
40
- // List
41
- const items = await product.list({ Page: 1, PageSize: 10 });
42
- items[0].Title.get();
43
-
44
- // Get single item
45
- const found = await product.get("abc123");
46
- found.Title.get(); // "Widget"
47
-
48
- // Update — returns { _id: string }
49
- await product.update("abc123", { Price: 39.99 });
50
-
51
- // Delete — returns { status: string }
52
- await product.delete("abc123");
53
- ```
54
-
55
- ## Usage Guide
56
-
57
- ### CRUD Operations
58
-
59
- ```typescript
60
- const product = new AdminProduct();
61
-
62
- // Create — returns ItemType with field accessors
63
- const item = await product.create({
64
- Title: "Widget",
65
- Price: 29.99,
66
- Category: "Electronics",
67
- });
68
- item._id; // direct string access
69
-
70
- // Get single item
71
- const item = await product.get("abc123");
72
-
73
- // Update — returns { _id: string }
74
- const { _id } = await product.update("abc123", { Price: 39.99 });
75
-
76
- // Delete — returns { status: string }
77
- const { status } = await product.delete("abc123");
78
-
79
- // Count
80
- const total = await product.count();
81
- const filtered = await product.count({
82
- Filter: {
83
- Operator: "And",
84
- Condition: [
85
- { Operator: "eq", LHSField: "Category", RHSValue: "Electronics" },
86
- ],
87
- },
88
- });
89
- ```
90
-
91
- ### ItemType Field Accessors
92
-
93
- Every `get()`, `list()`, and `create()` call returns `ItemType` — a proxy with typed field accessors.
94
-
95
- ```typescript
96
- const item = await product.get("abc123");
97
-
98
- // Read values
99
- item._id; // string (direct, not an accessor)
100
- item.Title.get(); // string | undefined
101
- item.Price.getOrDefault(0); // number (never undefined)
102
-
103
- // Write values (editable fields only)
104
- item.Title.set("New Title");
105
-
106
- // Field metadata
107
- item.Title.label; // "Product Title"
108
- item.Title.required; // true
109
- item.Title.readOnly; // false
110
- item.Title.defaultValue; // undefined
111
- item.Title.meta; // raw backend field meta
112
-
113
- // Validation
114
- item.Title.validate(); // { valid: boolean, errors: string[] }
115
- item.validate(); // validates all fields, returns { valid, errors }
116
-
117
- // Serialize
118
- item.toJSON(); // { Title: "New Title", Price: 29.99, ... }
119
- ```
120
-
121
- ### List with Filter, Sort, and Pagination
122
-
123
- ```typescript
124
- const items = await product.list({
125
- Filter: {
126
- Operator: "And",
127
- Condition: [
128
- { Operator: "eq", LHSField: "Category", RHSValue: "Electronics" },
129
- { Operator: "gte", LHSField: "Price", RHSValue: 10 },
130
- ],
131
- },
132
- Sort: [{ Price: "DESC" }],
133
- Page: 1,
134
- PageSize: 20,
135
- });
136
- ```
137
-
138
- ### Metric (Aggregation)
139
-
140
- ```typescript
141
- const result = await product.metric({
142
- GroupBy: ["Category"],
143
- Metric: [{ Field: "Price", Type: "Avg" }],
144
- });
145
- // result.Data = [{ Category: "Electronics", Price: 299.5 }, ...]
146
- ```
147
-
148
- ### Pivot (Cross-Tabulation)
149
-
150
- ```typescript
151
- const result = await product.pivot({
152
- Row: ["Category"],
153
- Column: ["IsActive"],
154
- Metric: [{ Field: "_id", Type: "Count" }],
155
- });
156
- // result.Data = { RowHeader: [...], ColumnHeader: [...], Value: [[...]] }
157
- ```
158
-
159
- ## Further Reading
160
-
161
- - [API Reference](./api_reference.md) — full method signatures, parameter types, and return types