@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.
- package/README.md +8 -16
- package/dist/api.cjs +1 -1
- package/dist/api.mjs +1 -1
- package/dist/auth/authConfig.d.ts +1 -1
- package/dist/auth/types.d.ts +1 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +1 -1
- package/dist/bdo/core/Item.d.ts.map +1 -1
- package/dist/bdo.cjs +1 -1
- package/dist/bdo.mjs +32 -32
- package/dist/components/hooks/useActivityForm/types.d.ts +5 -4
- package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/types.d.ts +4 -5
- package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
- package/dist/components/hooks/useBDOForm/createItemProxy.d.ts +2 -2
- package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -1
- package/dist/components/hooks/useBDOTable/types.d.ts +12 -20
- package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
- package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
- package/dist/{constants-Cyi942Yr.js → constants-ConHc1oS.js} +5 -5
- package/dist/constants-QX2RX-wu.cjs +1 -0
- package/dist/filter.cjs +1 -1
- package/dist/filter.mjs +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +16 -15
- package/dist/table.types.d.ts +1 -1
- package/dist/table.types.d.ts.map +1 -1
- package/dist/types/constants.d.ts +1 -1
- package/dist/workflow/Activity.d.ts +5 -8
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +476 -461
- package/docs/api.md +95 -0
- package/docs/bdo.md +224 -0
- package/docs/gaps.md +360 -0
- package/docs/useActivityForm.md +393 -0
- package/docs/useActivityTable.md +418 -0
- package/docs/useBDOForm.md +498 -0
- package/docs/useBDOTable.md +284 -0
- package/docs/useFilter.md +188 -0
- package/docs/workflow.md +560 -0
- package/package.json +14 -15
- package/sdk/auth/authConfig.ts +1 -1
- package/sdk/auth/types.ts +1 -1
- package/sdk/bdo/core/Item.ts +1 -2
- package/sdk/components/hooks/useActivityForm/types.ts +6 -4
- package/sdk/components/hooks/useActivityForm/useActivityForm.ts +73 -10
- package/sdk/components/hooks/useActivityTable/types.ts +5 -4
- package/sdk/components/hooks/useActivityTable/useActivityTable.ts +8 -10
- package/sdk/components/hooks/useBDOForm/createItemProxy.ts +5 -9
- package/sdk/components/hooks/useBDOTable/types.ts +10 -20
- package/sdk/components/hooks/useBDOTable/useBDOTable.ts +8 -12
- package/sdk/table.types.ts +0 -2
- package/sdk/types/constants.ts +1 -1
- package/sdk/workflow/Activity.ts +7 -39
- package/dist/constants-DEmYwKfC.cjs +0 -1
- package/docs/README.md +0 -57
- package/docs/bdo/README.md +0 -161
- package/docs/bdo/api_reference.md +0 -281
- package/docs/examples/bdo/create-product.md +0 -69
- package/docs/examples/bdo/edit-product-dialog.md +0 -95
- package/docs/examples/bdo/filtered-product-table.md +0 -100
- package/docs/examples/bdo/product-listing.md +0 -73
- package/docs/examples/bdo/supplier-dropdown.md +0 -60
- package/docs/examples/fields/complex-fields.md +0 -248
- package/docs/examples/fields/primitive-fields.md +0 -217
- package/docs/examples/workflow/approve-leave-request.md +0 -76
- package/docs/examples/workflow/filtered-activity-table.md +0 -101
- package/docs/examples/workflow/my-pending-requests.md +0 -90
- package/docs/examples/workflow/start-new-workflow.md +0 -47
- package/docs/examples/workflow/submit-leave-request.md +0 -72
- package/docs/examples/workflow/workflow-progress.md +0 -49
- package/docs/fields/README.md +0 -141
- package/docs/fields/api_reference.md +0 -134
- package/docs/useActivityForm/README.md +0 -244
- package/docs/useActivityForm/api_reference.md +0 -279
- package/docs/useActivityTable/README.md +0 -263
- package/docs/useActivityTable/api_reference.md +0 -294
- package/docs/useBDOForm/README.md +0 -175
- package/docs/useBDOForm/api_reference.md +0 -244
- package/docs/useBDOTable/README.md +0 -242
- package/docs/useBDOTable/api_reference.md +0 -253
- package/docs/useFilter/README.md +0 -323
- package/docs/useFilter/api_reference.md +0 -228
- package/docs/workflow/README.md +0 -158
- package/docs/workflow/api_reference.md +0 -161
- /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 {
|
|
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()
|
|
303
|
+
// HANDLE SUBMIT — activity.update()
|
|
301
304
|
// ============================================================
|
|
302
305
|
|
|
303
306
|
const handleSubmit = useCallback(
|
|
304
307
|
(
|
|
305
308
|
onSuccess?: (
|
|
306
|
-
data:
|
|
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
|
-
//
|
|
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
|
-
|
|
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
|
|
19
|
-
*
|
|
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
|
|
23
|
-
?
|
|
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
|
-
?
|
|
20
|
-
|
|
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
|
-
?
|
|
32
|
-
:
|
|
33
|
-
[
|
|
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),
|
|
25
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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<
|
|
14
|
+
filter?: UseFilterOptionsType<T>;
|
|
24
15
|
};
|
|
25
16
|
/** Error callback */
|
|
26
17
|
onError?: (error: Error) => void;
|
|
27
|
-
/** Success callback — receives
|
|
28
|
-
onSuccess?: (data:
|
|
18
|
+
/** Success callback — receives rows from current page */
|
|
19
|
+
onSuccess?: (data: T[]) => void;
|
|
29
20
|
}
|
|
30
21
|
|
|
31
|
-
export type UseBDOTableReturnType<
|
|
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<
|
|
10
|
-
options: UseBDOTableOptionsType<
|
|
11
|
-
): UseBDOTableReturnType<
|
|
5
|
+
export function useBDOTable<T = any>(
|
|
6
|
+
options: UseBDOTableOptionsType<T>,
|
|
7
|
+
): UseBDOTableReturnType<T> {
|
|
12
8
|
const { bdo, ...rest } = options;
|
|
13
9
|
|
|
14
|
-
return useTable<
|
|
10
|
+
return useTable<T>({
|
|
15
11
|
queryKey: ['table', bdo.meta._id],
|
|
16
|
-
listFn:
|
|
17
|
-
countFn:
|
|
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
|
}
|
package/sdk/table.types.ts
CHANGED
package/sdk/types/constants.ts
CHANGED
package/sdk/workflow/Activity.ts
CHANGED
|
@@ -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
|
-
*
|
|
131
|
+
* Accepts optional filter/sort/pagination options.
|
|
134
132
|
*/
|
|
135
|
-
async getInProgressList(
|
|
136
|
-
options
|
|
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
|
-
*
|
|
139
|
+
* Accepts optional filter/sort/pagination options.
|
|
157
140
|
*/
|
|
158
|
-
async getCompletedList(
|
|
159
|
-
options
|
|
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.
|
package/docs/bdo/README.md
DELETED
|
@@ -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
|