@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
package/dist/form.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("./constants-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const K=require("./constants-QX2RX-wu.cjs"),m=require("react"),w=require("./shared-nnmlRVs7.cjs"),J=require("@tanstack/react-query"),y=require("./client-D5k4SYuw.cjs"),P=require("./attachment-constants-B5jlqoKI.cjs"),W=require("./metadata-DWXQPDav.cjs");function X(T,n){const f=T.getFields(),D=new Map,C=T.getBoId(),c=()=>n.getValues("_id")||"draft";return new Proxy({},{get(q,e){if(typeof e=="symbol")return;if(e==="_id")return n.getValues("_id");if(e==="toJSON")return()=>n.getValues();if(e==="validate")return()=>n.trigger();if(D.has(e))return D.get(e);const s=f[e],o=(s==null?void 0:s.meta)??{_id:e,Name:e,Type:"String"},A=(s==null?void 0:s.readOnly)??!1,S=()=>{if(!s)return{valid:!0,errors:[]};let i=n.getValues(e);if("integerPart"in s&&typeof i=="string"&&i!==""){const a=Number(i);isNaN(a)||(i=a,n.setValue(e,a,{shouldDirty:!1}))}if(!s.required&&(i==null||i===""||Array.isArray(i)&&i.length===0))return{valid:!0,errors:[]};const l=s.validate(i);if(!l.valid)return l;const r=w.validateConstraints(s,i);if(!r.valid)return r;if(T.hasMetadata()){const a=T.validateFieldExpression(e,i,n.getValues());if(!a.valid)return a}return{valid:!0,errors:[]}},x=i=>{const l=n.getValues(e);return l??i};if(!A){const i=()=>{const r=n.getValues(e);return o.Type==="File"?r??[]:r},l={label:(s==null?void 0:s.label)??e,required:(s==null?void 0:s.required)??!1,readOnly:!1,defaultValue:s==null?void 0:s.defaultValue,meta:o,get:i,getOrDefault:x,set:r=>{n.setValue(e,r,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:S};if(o.Type==="Image"||o.Type==="File"){const r=C;o.Type==="Image"?(l.upload=async a=>{P.validateFileExtension(a.name,"Image");const t=c(),[u]=await y.api(r).getUploadUrl(t,e,[{FileName:a.name,Size:a.size,FileExtension:P.extractFileExtension(a.name)}]);await fetch(u.UploadUrl.URL,{method:"PUT",headers:{"Content-Type":u.ContentType},body:a});const d={_id:u._id,_name:u._name,FileName:u.FileName,FileExtension:u.FileExtension,Size:u.Size,ContentType:u.ContentType};return n.setValue(e,d,{shouldDirty:!0}),d},l.deleteAttachment=async()=>{const a=n.getValues(e),t=c();if(!(a!=null&&a._id))throw new Error(`${e} has no image to delete`);await y.api(r).deleteAttachment(t,e,a._id),n.setValue(e,null,{shouldDirty:!0})},l.getDownloadUrl=async a=>{const t=n.getValues(e),u=c();if(!(t!=null&&t._id))throw new Error(`${e} has no image`);return y.api(r).getDownloadUrl(u,e,t._id,a)}):(l.upload=async a=>{for(const _ of a)P.validateFileExtension(_.name,"File");const t=c(),u=a.map(_=>({FileName:_.name,Size:_.size,FileExtension:P.extractFileExtension(_.name)})),d=await y.api(r).getUploadUrl(t,e,u),g=await Promise.all(a.map(async(_,h)=>(await fetch(d[h].UploadUrl.URL,{method:"PUT",headers:{"Content-Type":d[h].ContentType},body:_}),{_id:d[h]._id,_name:d[h]._name,FileName:d[h].FileName,FileExtension:d[h].FileExtension,Size:d[h].Size,ContentType:d[h].ContentType}))),L=n.getValues(e)??[];return n.setValue(e,[...L,...g],{shouldDirty:!0}),g},l.deleteAttachment=async a=>{const t=n.getValues(e)??[],u=c();await y.api(r).deleteAttachment(u,e,a),n.setValue(e,t.filter(d=>d._id!==a),{shouldDirty:!0})},l.getDownloadUrl=async(a,t)=>{const u=c();return y.api(r).getDownloadUrl(u,e,a,t)},l.getDownloadUrls=async a=>{const t=c();return y.api(r).getDownloadUrls(t,e,a)})}return D.set(e,l),l}const k=()=>{const i=n.getValues(e);return o.Type==="File"?i??[]:i},O={label:(s==null?void 0:s.label)??e,required:(s==null?void 0:s.required)??!1,readOnly:!0,defaultValue:s==null?void 0:s.defaultValue,meta:o,get:k,getOrDefault:x,validate:S};if(o.Type==="Image"||o.Type==="File"){const i=C;o.Type==="Image"?O.getDownloadUrl=async l=>{const r=n.getValues(e),a=c();if(!(r!=null&&r._id))throw new Error(`${e} has no image to download`);return y.api(i).getDownloadUrl(a,e,r._id,l)}:(O.getDownloadUrl=async(l,r)=>{const a=c();return y.api(i).getDownloadUrl(a,e,l,r)},O.getDownloadUrls=async l=>{const r=c();return y.api(i).getDownloadUrls(r,e,l)})}return D.set(e,O),O},has(q,e){return typeof e=="symbol"?!1:e==="_id"||e==="toJSON"||e==="validate"?!0:e in f},ownKeys(q){return[...Object.keys(f),"_id","toJSON","validate"]},getOwnPropertyDescriptor(q,e){if(typeof e!="symbol")return{configurable:!0,enumerable:e!=="toJSON"&&e!=="validate"}}})}function Y(T){const{bdo:n,recordId:f,operation:D,defaultValues:C,mode:c="onBlur",enableDraft:q=!1,enableConstraintValidation:e,enableExpressionValidation:s}=T,o=D??(f?"update":"create"),A=m.useMemo(()=>w.createResolver(n,{enableConstraintValidation:e}),[n,e]),{data:S,isLoading:x,isFetching:k,error:O}=J.useQuery({queryKey:["form-record",n.meta._id,f],queryFn:async()=>{const V=await n.get(f);return w.coerceRecordForForm(n.getFields(),V.toJSON())},enabled:o==="update"&&!!f,staleTime:0}),{data:i,isLoading:l,error:r}=J.useQuery({queryKey:["form-draft",n.meta._id],queryFn:async()=>y.api(n.meta._id).draftInteraction({}),enabled:o==="create",staleTime:1/0,gcTime:0,retry:1}),{data:a}=J.useQuery({queryKey:["form-schema",n.meta._id],queryFn:()=>W.getBdoSchema(n.meta._id),staleTime:30*60*1e3,gcTime:60*60*1e3,enabled:s!==!1});m.useEffect(()=>{a!=null&&a.BDOBlob?n.loadMetadata(a.BDOBlob):a!=null&&a.MetaBlob&&n.loadMetadata(a.MetaBlob)},[a,n]);const t=w.useForm({mode:c,resolver:A,defaultValues:C}),u=m.useRef(null);m.useEffect(()=>{o==="update"&&S&&S!==u.current&&(t.reset(S),u.current=S)},[S,o,t]),m.useEffect(()=>{i!=null&&i._id&&t.setValue("_id",i._id)},[i,t]);const d=m.useMemo(()=>X(n,t),[n,t]),g=n.getFields(),L=m.useRef(!1),_=m.useMemo(()=>Object.keys(g).filter(V=>g[V].readOnly),[g]),h=m.useCallback(async(V,F)=>{if(o==="create"&&(i!=null&&i._id))return y.api(n.meta._id).draftInteraction({_id:i._id,[V]:F});if(o==="update"&&f)return y.api(n.meta._id).update(f,{[V]:F})},[o,i,f,n]),M=m.useMemo(()=>w.createSyncField({apiFn:h,allFields:g,readonlyFieldNames:_,rhf:t,isComputingRef:L}),[h,g,_,t]),R=c==="onChange"||c==="all",N=c==="onBlur"||c==="onTouched"||c==="all",Q=m.useMemo(()=>w.createEnhancedRegister({rhf:t,allFields:g,syncField:M,syncOnBlur:N,syncOnChange:R}),[t,g,M,N,R]),$=m.useMemo(()=>w.createEnhancedControl({control:t.control,syncField:M,syncOnBlur:N,syncOnChange:R}),[t.control,M,N,R]),G=m.useCallback((V,F)=>t.handleSubmit(async(E,B)=>{try{const v={},z=t.getValues();if(o==="create")for(const[U,I]of Object.entries(g)){if(I.readOnly)continue;const b=z[U]!==void 0?z[U]:E[U];b!==void 0&&(v[U]=w.coerceFieldValue(I,b))}else{const U=t.formState.dirtyFields;for(const[I,b]of Object.entries(g)){if(b.readOnly||!U[I])continue;const H=z[I]!==void 0?z[I]:E[I];v[I]=w.coerceFieldValue(b,H)}}let j;o==="create"?(v._id=i==null?void 0:i._id,j=await y.api(n.meta._id).draft(v)):j=await y.api(n.meta._id).update(f,v),V==null||V(j,B)}catch(v){F==null||F(v,B)}},(E,B)=>{F==null||F(E,B)}),[t,n,o,f,g,i]);return{item:d,bdo:n,operation:o,recordId:f,register:Q,handleSubmit:G,watch:t.watch,setValue:t.setValue,getValues:t.getValues,reset:t.reset,trigger:t.trigger,control:$,formState:t.formState,errors:t.formState.errors,isDirty:t.formState.isDirty,isValid:t.formState.isValid,isSubmitting:t.formState.isSubmitting,isSubmitSuccessful:t.formState.isSubmitSuccessful,dirtyFields:t.formState.dirtyFields,isLoading:x||l,isFetching:k,loadError:O??r,draftId:i==null?void 0:i._id,isCreatingDraft:l}}exports.FormOperation=K.FormOperation;exports.InteractionMode=K.InteractionMode;exports.ValidationMode=K.ValidationMode;exports.useBDOForm=Y;
|
package/dist/form.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as he, I as _e, V as Ve } from "./constants-
|
|
1
|
+
import { F as he, I as _e, V as Ve } from "./constants-ConHc1oS.js";
|
|
2
2
|
import { useMemo as U, useEffect as k, useRef as j, useCallback as K } from "react";
|
|
3
3
|
import { v as Z, c as p, a as ee, u as te, b as ae, d as ne, e as se, f as $ } from "./shared-5a7UkED1.js";
|
|
4
4
|
import { useQuery as J } from "@tanstack/react-query";
|
package/dist/table.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./useTable-CeRklbdT.cjs"),o=require("./client-D5k4SYuw.cjs"),e=require("./constants-QX2RX-wu.cjs");function u(a){const{bdo:t,...n}=a;return i.useTable({queryKey:["table",t.meta._id],listFn:r=>o.api(t.meta._id).list(r),countFn:r=>o.api(t.meta._id).count(r),...n})}exports.useTable=i.useTable;exports.ConditionOperator=e.ConditionOperator;exports.GroupOperator=e.GroupOperator;exports.RHSType=e.RHSType;exports.SortDirection=e.SortDirection;exports.TableDefaults=e.Defaults;exports.useBDOTable=u;
|
package/dist/table.mjs
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import { u as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { u as s } from "./useTable-DS0-WInw.js";
|
|
2
|
+
import { a } from "./client-_ayziI1d.js";
|
|
3
|
+
import { C as l, G as b, R as c, S as d, D as f } from "./constants-ConHc1oS.js";
|
|
4
|
+
function u(o) {
|
|
5
|
+
const { bdo: t, ...r } = o;
|
|
6
|
+
return s({
|
|
6
7
|
queryKey: ["table", t.meta._id],
|
|
7
|
-
listFn:
|
|
8
|
-
countFn:
|
|
9
|
-
...
|
|
8
|
+
listFn: (e) => a(t.meta._id).list(e),
|
|
9
|
+
countFn: (e) => a(t.meta._id).count(e),
|
|
10
|
+
...r
|
|
10
11
|
});
|
|
11
12
|
}
|
|
12
13
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
l as ConditionOperator,
|
|
15
|
+
b as GroupOperator,
|
|
16
|
+
c as RHSType,
|
|
17
|
+
d as SortDirection,
|
|
18
|
+
f as TableDefaults,
|
|
19
|
+
u as useBDOTable,
|
|
20
|
+
s as useTable
|
|
20
21
|
};
|
package/dist/table.types.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export type { UseTableOptionsType, UseTableReturnType, PaginationStateType, } from './components/hooks/useTable/types';
|
|
2
|
-
export type {
|
|
2
|
+
export type { UseBDOTableOptionsType, UseBDOTableReturnType, } from './components/hooks/useBDOTable/types';
|
|
3
3
|
//# sourceMappingURL=table.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.types.d.ts","sourceRoot":"","sources":["../sdk/table.types.ts"],"names":[],"mappings":"AAKA,YAAY,EAEV,mBAAmB,EACnB,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,mCAAmC,CAAC;AAE3C,YAAY,EAEV,
|
|
1
|
+
{"version":3,"file":"table.types.d.ts","sourceRoot":"","sources":["../sdk/table.types.ts"],"names":[],"mappings":"AAKA,YAAY,EAEV,mBAAmB,EACnB,kBAAkB,EAGlB,mBAAmB,GACpB,MAAM,mCAAmC,CAAC;AAE3C,YAAY,EAEV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,sCAAsC,CAAC"}
|
|
@@ -305,7 +305,7 @@ export declare const AuthStatus: {
|
|
|
305
305
|
*/
|
|
306
306
|
export declare const AuthProviderName: {
|
|
307
307
|
readonly Google: "google";
|
|
308
|
-
readonly
|
|
308
|
+
readonly Microsoft: "microsoft";
|
|
309
309
|
readonly GitHub: "github";
|
|
310
310
|
readonly Custom: "custom";
|
|
311
311
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { ActivityInstanceType } from "./ActivityInstance";
|
|
2
2
|
import type { ActivityInstanceFieldsType, ActivityOperations } from "./types";
|
|
3
|
-
import type { ListOptionsType, MetricOptionsType, MetricResponseType } from "../types/common";
|
|
3
|
+
import type { ListResponseType, ListOptionsType, MetricOptionsType, MetricResponseType } from "../types/common";
|
|
4
4
|
import { BaseField } from "../bdo/fields/BaseField";
|
|
5
|
-
/** Activity system fields treated as readonly on list results */
|
|
6
|
-
type ActivitySystemReadonlyType = Omit<ActivityInstanceFieldsType, '_id'>;
|
|
7
5
|
/**
|
|
8
6
|
* Abstract base class for workflow activities.
|
|
9
7
|
*
|
|
@@ -61,14 +59,14 @@ export declare abstract class Activity<TEntity extends Record<string, unknown>,
|
|
|
61
59
|
private _discoverFields;
|
|
62
60
|
/**
|
|
63
61
|
* List in-progress activity instances.
|
|
64
|
-
*
|
|
62
|
+
* Accepts optional filter/sort/pagination options.
|
|
65
63
|
*/
|
|
66
|
-
getInProgressList(options?: ListOptionsType): Promise<
|
|
64
|
+
getInProgressList(options?: ListOptionsType): Promise<ListResponseType<ActivityInstanceFieldsType & TEntity>>;
|
|
67
65
|
/**
|
|
68
66
|
* List completed activity instances.
|
|
69
|
-
*
|
|
67
|
+
* Accepts optional filter/sort/pagination options.
|
|
70
68
|
*/
|
|
71
|
-
getCompletedList(options?: ListOptionsType): Promise<
|
|
69
|
+
getCompletedList(options?: ListOptionsType): Promise<ListResponseType<ActivityInstanceFieldsType & TEntity>>;
|
|
72
70
|
/**
|
|
73
71
|
* Get count of in-progress activity instances.
|
|
74
72
|
* Returns a number (same as BDO count()).
|
|
@@ -107,5 +105,4 @@ export declare abstract class Activity<TEntity extends Record<string, unknown>,
|
|
|
107
105
|
*/
|
|
108
106
|
_getOps(): ActivityOperations<TEntity>;
|
|
109
107
|
}
|
|
110
|
-
export {};
|
|
111
108
|
//# sourceMappingURL=Activity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../sdk/workflow/Activity.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../sdk/workflow/Activity.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAMpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,8BAAsB,QAAQ,CAC5B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACvC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAEnD,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,EAAE;IAE9C;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE;QACtB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;QACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,CAAC;IAMF;;;OAGG;IACH,OAAO,CAAC,IAAI;IASZ,OAAO,CAAC,YAAY,CAAmD;IAEvE;;;OAGG;IACH,OAAO,CAAC,eAAe;IAmBvB;;;OAGG;IACG,iBAAiB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,0BAA0B,GAAG,OAAO,CAAC,CAAC;IAInH;;;OAGG;IACG,gBAAgB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,0BAA0B,GAAG,OAAO,CAAC,CAAC;IAIlH;;;OAGG;IACG,eAAe,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAKjE;;;OAGG;IACG,cAAc,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC;IAKhE;;;OAGG;IACG,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI7F;;;OAGG;IACG,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAI5F;;;;;OAKG;IACG,WAAW,CACf,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;IAgB/D;;;OAGG;IACH,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAIhD;;;OAGG;IACH,OAAO,IAAI,kBAAkB,CAAC,OAAO,CAAC;CAGvC"}
|
package/dist/workflow.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ie=Object.defineProperty;var oe=(o,t,e)=>t in o?ie(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var A=(o,t,e)=>oe(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("./client-D5k4SYuw.cjs"),$=require("./FileField-DU4UWo_t.cjs"),_=require("react"),E=require("./shared-nnmlRVs7.cjs"),ce=require("@tanstack/react-query"),L=require("./attachment-constants-B5jlqoKI.cjs"),G=require("./useTable-CeRklbdT.cjs"),le=require("./metadata-DWXQPDav.cjs");class Y{constructor(t){A(this,"bp_id");this.bp_id=t}async start(){const t=await fetch(`${d.getApiBaseUrl()}/api/app/process/${this.bp_id}/start`,{method:"POST",headers:d.getDefaultHeaders()});if(!t.ok)throw new Error(`Failed to start process: ${t.statusText}`);return(await t.json()).Data}async progress(t){const e=await fetch(`${d.getApiBaseUrl()}/api/app/process/${this.bp_id}/${t}/progress`,{method:"GET",headers:d.getDefaultHeaders()});if(!e.ok)throw new Error(`Failed to get process progress: ${e.statusText}`);return(await e.json()).Data}activity(t){const e=`/api/app/process/${this.bp_id}/${t}`;return{async inProgressList(s){const a=await fetch(`${d.getApiBaseUrl()}${e}/inprogress/list`,{method:"POST",headers:d.getDefaultHeaders(),body:s?JSON.stringify(s):void 0});if(!a.ok)throw new Error(`Failed to list in-progress activities: ${a.statusText}`);return a.json()},async completedList(s){const a=await fetch(`${d.getApiBaseUrl()}${e}/completed/list`,{method:"POST",headers:d.getDefaultHeaders(),body:s?JSON.stringify(s):void 0});if(!a.ok)throw new Error(`Failed to list completed activities: ${a.statusText}`);return a.json()},async inProgressCount(s){var f,r;const a={Type:"Metric",GroupBy:[],Metric:[{Field:"_id",Type:"Count"}],...(s==null?void 0:s.Filter)&&{Filter:s.Filter}},n=await fetch(`${d.getApiBaseUrl()}${e}/inprogress/metric`,{method:"POST",headers:d.getDefaultHeaders(),body:JSON.stringify(a)});if(!n.ok)throw new Error(`Failed to get in-progress count: ${n.statusText}`);return{Count:((r=(f=(await n.json()).Data)==null?void 0:f[0])==null?void 0:r.count__id)??0}},async completedCount(s){var f,r;const a={Type:"Metric",GroupBy:[],Metric:[{Field:"_id",Type:"Count"}],...(s==null?void 0:s.Filter)&&{Filter:s.Filter}},n=await fetch(`${d.getApiBaseUrl()}${e}/completed/metric`,{method:"POST",headers:d.getDefaultHeaders(),body:JSON.stringify(a)});if(!n.ok)throw new Error(`Failed to get completed count: ${n.statusText}`);return{Count:((r=(f=(await n.json()).Data)==null?void 0:f[0])==null?void 0:r.count__id)??0}},async inProgressMetric(s){const a={Type:"Metric",...s},n=await fetch(`${d.getApiBaseUrl()}${e}/inprogress/metric`,{method:"POST",headers:d.getDefaultHeaders(),body:JSON.stringify(a)});if(!n.ok)throw new Error(`Failed to get in-progress metrics: ${n.statusText}`);return n.json()},async completedMetric(s){const a={Type:"Metric",...s},n=await fetch(`${d.getApiBaseUrl()}${e}/completed/metric`,{method:"POST",headers:d.getDefaultHeaders(),body:JSON.stringify(a)});if(!n.ok)throw new Error(`Failed to get completed metrics: ${n.statusText}`);return n.json()},async read(s){const a=await fetch(`${d.getApiBaseUrl()}${e}/${s}/read`,{method:"GET",headers:d.getDefaultHeaders()});if(!a.ok)throw new Error(`Failed to read activity: ${a.statusText}`);return(await a.json()).Data},async update(s,a){const n=await fetch(`${d.getApiBaseUrl()}${e}/${s}/update`,{method:"POST",headers:d.getDefaultHeaders(),body:JSON.stringify(a)});if(!n.ok)throw new Error(`Failed to update activity: ${n.statusText}`);return n.json()},async draftStart(s,a){const n=await fetch(`${d.getApiBaseUrl()}${e}/${s}/draft`,{method:"PATCH",headers:d.getDefaultHeaders(),body:JSON.stringify(a)});if(!n.ok)throw new Error(`Failed to start draft: ${n.statusText}`);return n.json()},async draftEnd(s,a){const n=await fetch(`${d.getApiBaseUrl()}${e}/${s}/draft`,{method:"POST",headers:d.getDefaultHeaders(),body:JSON.stringify(a)});if(!n.ok)throw new Error(`Failed to end draft: ${n.statusText}`);return n.json()},async complete(s){const a=await fetch(`${d.getApiBaseUrl()}${e}/${s}/done`,{method:"POST",headers:d.getDefaultHeaders()});if(!a.ok)throw new Error(`Failed to complete activity: ${a.statusText}`);return a.json()},async progress(s){const a=await fetch(`${d.getApiBaseUrl()}${e}/${s}/progress`,{method:"GET",headers:d.getDefaultHeaders()});if(!a.ok)throw new Error(`Failed to get activity progress: ${a.statusText}`);return a.json()}}}}class Z{constructor(t,e,s,a){A(this,"_id");A(this,"_data");A(this,"_ops");A(this,"_fields");A(this,"_accessorCache",new Map);this._ops=t,this._id=e,this._data={...s},this._fields=a}toJSON(){return{...this._data}}validate(){const t=[];for(const[e,s]of Object.entries(this._fields)){const a=this._data[e],n=s.validate(a);n.valid||t.push(...n.errors)}return{valid:t.length===0,errors:t}}async update(t){return this._ops.update(this._id,t)}async save(t){return this._ops.draftEnd(this._id,t)}async complete(){return this._ops.complete(this._id)}async progress(){return this._ops.progress(this._id)}_getAccessor(t){if(this._accessorCache.has(t))return this._accessorCache.get(t);const e=this._fields[t],s=(e==null?void 0:e.meta)??{_id:t,Name:t,Type:"String"},a=(e==null?void 0:e.readOnly)??!1,n=()=>e?e.validate(this._data[t]):{valid:!0,errors:[]};let i;return a?i={label:(e==null?void 0:e.label)??t,required:(e==null?void 0:e.required)??!1,readOnly:!0,defaultValue:e==null?void 0:e.defaultValue,meta:s,get:()=>this._data[t],validate:n}:i={label:(e==null?void 0:e.label)??t,required:(e==null?void 0:e.required)??!1,readOnly:!1,defaultValue:e==null?void 0:e.defaultValue,meta:s,get:()=>this._data[t],set:y=>{this._data[t]=y},validate:n},this._accessorCache.set(t,i),i}}function z(o,t,e,s){const a=new Z(o,t,e,s);return new Proxy(a,{get(n,i,y){return i==="validate"||i==="toJSON"||i==="update"||i==="save"||i==="complete"||i==="progress"||i==="_ops"||i==="_data"||i==="_fields"||i==="_accessorCache"||i==="_getAccessor"||typeof i=="symbol"?Reflect.get(n,i,y):i==="_id"?n._id:n._getAccessor(i)},has(n,i){return typeof i=="symbol"?!1:i==="validate"||i==="toJSON"||i==="update"||i==="save"||i==="complete"||i==="progress"||i==="_id"?!0:i in n._fields},ownKeys(n){return[...Object.keys(n._fields),"_id","validate","toJSON","update","save","complete","progress"]},getOwnPropertyDescriptor(n,i){if(typeof i!="symbol")return{configurable:!0,enumerable:i!=="validate"&&i!=="toJSON"&&i!=="update"&&i!=="save"&&i!=="complete"&&i!=="progress"}}})}class ue{constructor(){A(this,"_fieldsCache",null)}_ops(){return new Y(this.meta.businessProcessId).activity(this.meta.activityId)}_discoverFields(){if(this._fieldsCache)return this._fieldsCache;const t={};for(const e of Object.keys(this)){const s=this[e];s instanceof $.BaseField&&(t[e]=s)}return this._fieldsCache=t,t}async getInProgressList(t){const e=this._ops(),s=await e.inProgressList(t),a=this._discoverFields();return s.Data.map(n=>z(e,n._id,n,a))}async getCompletedList(t){const e=this._ops(),s=await e.completedList(t),a=this._discoverFields();return s.Data.map(n=>z(e,n._id,n,a))}async inProgressCount(t){return(await this._ops().inProgressCount(t)).Count}async completedCount(t){return(await this._ops().completedCount(t)).Count}async inProgressMetric(t){return this._ops().inProgressMetric(t)}async completedMetric(t){return this._ops().completedMetric(t)}async getInstance(t){const e=this._ops(),s=await e.read(t),a=this._discoverFields();return z(e,t,s,a)}_getFields(){return this._discoverFields()}_getOps(){return this._ops()}}function K(o,t){var a;const e={_id:o,...t},s=t.Type;if(s==="String"&&((a=t.Constraint)!=null&&a.Enum))return new $.SelectField(e);switch(s){case"String":return new $.StringField(e);case"Number":return new $.NumberField(e);case"Boolean":return new $.BooleanField(e);case"Date":return new $.DateField(e);case"DateTime":return new $.DateTimeField(e);case"Text":return new $.TextField(e);case"Reference":return new $.ReferenceField(e);case"User":return new $.UserField(e);case"File":return new $.FileField(e);default:return new $.StringField(e)}}function ee(o){const t={};for(const[e,s]of Object.entries(o))t[e]=K(e,s);return t}function de(o,t,e){var n;const s=t==null?void 0:t.BDOBlob;if(!(s!=null&&s.Activity))return null;const a=o==null?void 0:o.Id;for(const i of s.Activity)if(i.Id!==a&&(n=i.Input)!=null&&n[e])return i.Input[e];return null}function ye(o){return async(t,e,s)=>{const a={},n="_getFields"in o?o._getFields():o,i=(s==null?void 0:s.names)??Object.keys(n);for(const y of i){const f=n[y];if(!f||f.readOnly)continue;let r=t[y];typeof r=="string"&&f.meta.Type==="Number"&&(r=r===""?void 0:Number(r));const l=f.validate(r);if(!l.valid&&l.errors.length>0){a[y]={type:"validate",message:l.errors[0]||`${y} is invalid`};continue}const F=E.validateConstraints(f,r);!F.valid&&F.errors.length>0&&(a[y]={type:"constraint",message:F.errors[0]})}return Object.keys(a).length===0?{values:t,errors:{}}:{values:{},errors:a}}}function ge(o,t,e){const s=o._getFields(),a=new Map,n=`/api/app/process/${o.meta.businessProcessId}/${o.meta.activityId}`,i=d.createResourceClient(n);function y(){if(!e)throw new Error("Cannot perform attachment operation: no activity instance ID");return e}return new Proxy({},{get(f,r){if(typeof r=="symbol")return;if(r==="_id")return e;if(r==="toJSON")return()=>t.getValues();if(r==="validate")return()=>t.trigger();if(a.has(r))return a.get(r);const l=s[r],F=(l==null?void 0:l.meta)??{_id:r,Name:r,Type:"String"},M=(l==null?void 0:l.readOnly)??!1,k=()=>l?l.validate(t.getValues(r)):{valid:!0,errors:[]},N=S=>{const u=t.getValues(r);return u??S};if(!M){const S=()=>{const c=t.getValues(r);return F.Type==="File"?c??[]:c},u={label:(l==null?void 0:l.label)??r,required:(l==null?void 0:l.required)??!1,readOnly:!1,defaultValue:l==null?void 0:l.defaultValue,meta:F,get:S,getOrDefault:N,set:c=>{t.setValue(r,c,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:k};return(F.Type==="Image"||F.Type==="File")&&(F.Type==="Image"?(u.upload=async c=>{L.validateFileExtension(c.name,"Image");const m=y(),[h]=await i.getUploadUrl(m,r,[{FileName:c.name,Size:c.size,FileExtension:L.extractFileExtension(c.name)}]);await fetch(h.UploadUrl.URL,{method:"PUT",headers:{"Content-Type":h.ContentType},body:c});const w={_id:h._id,_name:h._name,FileName:h.FileName,FileExtension:h.FileExtension,Size:h.Size,ContentType:h.ContentType};return t.setValue(r,w,{shouldDirty:!0}),w},u.deleteAttachment=async()=>{const c=t.getValues(r),m=y();if(!(c!=null&&c._id))throw new Error(`${r} has no image to delete`);await i.deleteAttachment(m,r,c._id),t.setValue(r,null,{shouldDirty:!0})},u.getDownloadUrl=async c=>{const m=t.getValues(r),h=y();if(!(m!=null&&m._id))throw new Error(`${r} has no image`);return i.getDownloadUrl(h,r,m._id,c)}):(u.upload=async c=>{for(const T of c)L.validateFileExtension(T.name,"File");const m=y(),h=c.map(T=>({FileName:T.name,Size:T.size,FileExtension:L.extractFileExtension(T.name)})),w=await i.getUploadUrl(m,r,h),I=await Promise.all(c.map(async(T,C)=>(await fetch(w[C].UploadUrl.URL,{method:"PUT",headers:{"Content-Type":w[C].ContentType},body:T}),{_id:w[C]._id,_name:w[C]._name,FileName:w[C].FileName,FileExtension:w[C].FileExtension,Size:w[C].Size,ContentType:w[C].ContentType}))),g=t.getValues(r)??[];return t.setValue(r,[...g,...I],{shouldDirty:!0}),I},u.deleteAttachment=async c=>{const m=t.getValues(r)??[],h=y();await i.deleteAttachment(h,r,c),t.setValue(r,m.filter(w=>w._id!==c),{shouldDirty:!0})},u.getDownloadUrl=async(c,m)=>{const h=y();return i.getDownloadUrl(h,r,c,m)},u.getDownloadUrls=async c=>{const m=y();return i.getDownloadUrls(m,r,c)})),a.set(r,u),u}const B=()=>{const S=t.getValues(r);return F.Type==="File"?S??[]:S},O={label:(l==null?void 0:l.label)??r,required:(l==null?void 0:l.required)??!1,readOnly:!0,defaultValue:l==null?void 0:l.defaultValue,meta:F,get:B,getOrDefault:N,validate:k};return(F.Type==="Image"||F.Type==="File")&&(F.Type==="Image"?O.getDownloadUrl=async S=>{const u=t.getValues(r),c=y();if(!(u!=null&&u._id))throw new Error(`${r} has no image to download`);return i.getDownloadUrl(c,r,u._id,S)}:(O.getDownloadUrl=async(S,u)=>{const c=y();return i.getDownloadUrl(c,r,S,u)},O.getDownloadUrls=async S=>{const u=y();return i.getDownloadUrls(u,r,S)})),a.set(r,O),O},has(f,r){return typeof r=="symbol"?!1:r==="_id"||r==="toJSON"||r==="validate"?!0:r in s},ownKeys(f){return[...Object.keys(s),"_id","toJSON","validate"]},getOwnPropertyDescriptor(f,r){if(typeof r!="symbol")return{configurable:!0,enumerable:r!=="toJSON"&&r!=="validate"}}})}function fe(o,t){const{activity_instance_id:e,defaultValues:s={},mode:a="onBlur",enabled:n=!0}=t,[i,y]=_.useState(!1),[f,r]=_.useState(null),[l,F]=_.useState(!1),[M,k]=_.useState({}),N=_.useRef(!1),B=_.useRef(null),{data:O,isLoading:S}=ce.useQuery({queryKey:["bp-metadata",o.meta.businessProcessId],queryFn:()=>le.getBdoSchema(o.meta.businessProcessId),staleTime:30*60*1e3}),u=_.useMemo(()=>{const v=O==null?void 0:O.BDOBlob;return v!=null&&v.Activity?v.Activity.find(p=>p.Id===o.meta.activityId)??null:null},[O,o.meta.activityId]),c=S,m=_.useMemo(()=>u!=null&&u.Input?ee(u.Input):o._getFields(),[u,o]),h=_.useMemo(()=>({...M,...m}),[M,m]),w=_.useMemo(()=>Object.keys(h).filter(v=>h[v].readOnly),[h]),I=_.useMemo(()=>ye(m),[m]),g=E.useForm({mode:a,defaultValues:s,resolver:I}),T=_.useMemo(()=>o._getOps(),[o]),C=_.useMemo(()=>ge(o,g,e),[o,g,e]);_.useEffect(()=>{if(!n||c)return;let v=!0;return(async()=>{y(!0),r(null);try{const b=await T.read(e);if(!v)return;if(b&&typeof b=="object"){const x=E.coerceRecordForForm(m,b),U={...s,...x};(B.current===null||b!==B.current)&&(g.reset(U),B.current=b);const H=new Set(["_id","BPInstanceId","Status","AssignedTo","CompletedAt","_created_at","_modified_at","_created_by","_modified_by","_v","_m_v"]),V={};for(const D of Object.keys(b))if(!m[D]&&!H.has(D)){const J=de(u,O,D);J&&(V[D]=K(D,{...J,ReadOnly:!0}))}Object.keys(V).length>0&&k(V)}}catch(b){if(!v)return;console.error("Failed to read activity data:",b),r(G.toError(b))}finally{v&&y(!1)}})(),()=>{v=!1}},[n,c,T,e]);const Q=_.useCallback((v,p)=>T.update(e,{[v]:p}),[T,e]),j=_.useMemo(()=>E.createSyncField({apiFn:Q,allFields:h,readonlyFieldNames:w,rhf:g,isComputingRef:N}),[Q,h,w,g]),q=a==="onChange"||a==="all",R=a==="onBlur"||a==="onTouched"||a==="all",te=_.useMemo(()=>E.createEnhancedRegister({rhf:g,allFields:h,syncField:j,syncOnBlur:R,syncOnChange:q}),[g,h,j,R,q]),se=_.useMemo(()=>E.createEnhancedControl({control:g.control,syncField:j,syncOnBlur:R,syncOnChange:q}),[g.control,j,R,q]),ae=_.useCallback((v,p)=>g.handleSubmit(async(b,x)=>{F(!0);try{const U={},H=new Set(w),V=g.formState.dirtyFields,D=g.getValues();for(const P of Object.keys(D)){if(H.has(P)||!V[P])continue;const W=D[P]!==void 0?D[P]:b[P],X=h[P];U[P]=X?E.coerceFieldValue(X,W):W}Object.keys(U).length>0&&await T.update(e,U);const J=await T.complete(e);await(v==null?void 0:v(J,x))}catch(U){p==null||p(G.toError(U),x)}finally{F(!1)}},(b,x)=>{p==null||p(b,x)}),[g,T,w,h,e]),re=_.useCallback(()=>{g.clearErrors()},[g]),ne=!!f;return{item:C,activity:o,register:te,handleSubmit:ae,watch:g.watch,setValue:g.setValue,getValues:g.getValues,reset:g.reset,trigger:g.trigger,control:se,errors:g.formState.errors,isValid:g.formState.isValid,isDirty:g.formState.isDirty,isSubmitting:g.formState.isSubmitting||l,isSubmitSuccessful:g.formState.isSubmitSuccessful,isLoading:i||c,isMetadataLoading:c,loadError:f,hasError:ne,bpMetadata:O??null,clearErrors:re}}function he(o){const{activity:t,status:e,...s}=o,{businessProcessId:a,activityId:n}=t.meta,i=_.useMemo(()=>e==="inprogress"?async f=>({Data:await t.getInProgressList(f)}):async f=>({Data:await t.getCompletedList(f)}),[t,e]),y=_.useMemo(()=>e==="inprogress"?async f=>({Count:await t.inProgressCount(f)}):async f=>({Count:await t.completedCount(f)}),[t,e]);return G.useTable({queryKey:["activity-table",a,n,e],listFn:i,countFn:y,...s})}const me={InProgress:"inprogress",Completed:"completed"};exports.Activity=ue;exports.ActivityInstance=Z;exports.ActivityTableStatus=me;exports.Workflow=Y;exports.buildFieldsFromInput=ee;exports.createFieldFromMeta=K;exports.useActivityForm=fe;exports.useActivityTable=he;
|
|
1
|
+
"use strict";var ne=Object.defineProperty;var ie=(o,t,e)=>t in o?ne(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var V=(o,t,e)=>ie(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./client-D5k4SYuw.cjs"),A=require("./FileField-DU4UWo_t.cjs"),h=require("react"),k=require("./shared-nnmlRVs7.cjs"),oe=require("@tanstack/react-query"),z=require("./attachment-constants-B5jlqoKI.cjs"),G=require("./useTable-CeRklbdT.cjs"),ce=require("./metadata-DWXQPDav.cjs");class W{constructor(t){V(this,"bp_id");this.bp_id=t}async start(){const t=await fetch(`${y.getApiBaseUrl()}/api/app/process/${this.bp_id}/start`,{method:"POST",headers:y.getDefaultHeaders()});if(!t.ok)throw new Error(`Failed to start process: ${t.statusText}`);return(await t.json()).Data}async progress(t){const e=await fetch(`${y.getApiBaseUrl()}/api/app/process/${this.bp_id}/${t}/progress`,{method:"GET",headers:y.getDefaultHeaders()});if(!e.ok)throw new Error(`Failed to get process progress: ${e.statusText}`);return(await e.json()).Data}activity(t){const e=`/api/app/process/${this.bp_id}/${t}`;return{async inProgressList(a){const r=await fetch(`${y.getApiBaseUrl()}${e}/inprogress/list`,{method:"POST",headers:y.getDefaultHeaders(),body:a?JSON.stringify(a):void 0});if(!r.ok)throw new Error(`Failed to list in-progress activities: ${r.statusText}`);return r.json()},async completedList(a){const r=await fetch(`${y.getApiBaseUrl()}${e}/completed/list`,{method:"POST",headers:y.getDefaultHeaders(),body:a?JSON.stringify(a):void 0});if(!r.ok)throw new Error(`Failed to list completed activities: ${r.statusText}`);return r.json()},async inProgressCount(a){var w,s;const r={Type:"Metric",GroupBy:[],Metric:[{Field:"_id",Type:"Count"}],...(a==null?void 0:a.Filter)&&{Filter:a.Filter}},i=await fetch(`${y.getApiBaseUrl()}${e}/inprogress/metric`,{method:"POST",headers:y.getDefaultHeaders(),body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to get in-progress count: ${i.statusText}`);return{Count:((s=(w=(await i.json()).Data)==null?void 0:w[0])==null?void 0:s.count__id)??0}},async completedCount(a){var w,s;const r={Type:"Metric",GroupBy:[],Metric:[{Field:"_id",Type:"Count"}],...(a==null?void 0:a.Filter)&&{Filter:a.Filter}},i=await fetch(`${y.getApiBaseUrl()}${e}/completed/metric`,{method:"POST",headers:y.getDefaultHeaders(),body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to get completed count: ${i.statusText}`);return{Count:((s=(w=(await i.json()).Data)==null?void 0:w[0])==null?void 0:s.count__id)??0}},async inProgressMetric(a){const r={Type:"Metric",...a},i=await fetch(`${y.getApiBaseUrl()}${e}/inprogress/metric`,{method:"POST",headers:y.getDefaultHeaders(),body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to get in-progress metrics: ${i.statusText}`);return i.json()},async completedMetric(a){const r={Type:"Metric",...a},i=await fetch(`${y.getApiBaseUrl()}${e}/completed/metric`,{method:"POST",headers:y.getDefaultHeaders(),body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to get completed metrics: ${i.statusText}`);return i.json()},async read(a){const r=await fetch(`${y.getApiBaseUrl()}${e}/${a}/read`,{method:"GET",headers:y.getDefaultHeaders()});if(!r.ok)throw new Error(`Failed to read activity: ${r.statusText}`);return(await r.json()).Data},async update(a,r){const i=await fetch(`${y.getApiBaseUrl()}${e}/${a}/update`,{method:"POST",headers:y.getDefaultHeaders(),body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to update activity: ${i.statusText}`);return i.json()},async draftStart(a,r){const i=await fetch(`${y.getApiBaseUrl()}${e}/${a}/draft`,{method:"PATCH",headers:y.getDefaultHeaders(),body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to start draft: ${i.statusText}`);return i.json()},async draftEnd(a,r){const i=await fetch(`${y.getApiBaseUrl()}${e}/${a}/draft`,{method:"POST",headers:y.getDefaultHeaders(),body:JSON.stringify(r)});if(!i.ok)throw new Error(`Failed to end draft: ${i.statusText}`);return i.json()},async complete(a){const r=await fetch(`${y.getApiBaseUrl()}${e}/${a}/done`,{method:"POST",headers:y.getDefaultHeaders()});if(!r.ok)throw new Error(`Failed to complete activity: ${r.statusText}`);return r.json()},async progress(a){const r=await fetch(`${y.getApiBaseUrl()}${e}/${a}/progress`,{method:"GET",headers:y.getDefaultHeaders()});if(!r.ok)throw new Error(`Failed to get activity progress: ${r.statusText}`);return r.json()}}}}class X{constructor(t,e,a,r){V(this,"_id");V(this,"_data");V(this,"_ops");V(this,"_fields");V(this,"_accessorCache",new Map);this._ops=t,this._id=e,this._data={...a},this._fields=r}toJSON(){return{...this._data}}validate(){const t=[];for(const[e,a]of Object.entries(this._fields)){const r=this._data[e],i=a.validate(r);i.valid||t.push(...i.errors)}return{valid:t.length===0,errors:t}}async update(t){return this._ops.update(this._id,t)}async save(t){return this._ops.draftEnd(this._id,t)}async complete(){return this._ops.complete(this._id)}async progress(){return this._ops.progress(this._id)}_getAccessor(t){if(this._accessorCache.has(t))return this._accessorCache.get(t);const e=this._fields[t],a=(e==null?void 0:e.meta)??{_id:t,Name:t,Type:"String"},r=(e==null?void 0:e.readOnly)??!1,i=()=>e?e.validate(this._data[t]):{valid:!0,errors:[]};let n;return r?n={label:(e==null?void 0:e.label)??t,required:(e==null?void 0:e.required)??!1,readOnly:!0,defaultValue:e==null?void 0:e.defaultValue,meta:a,get:()=>this._data[t],validate:i}:n={label:(e==null?void 0:e.label)??t,required:(e==null?void 0:e.required)??!1,readOnly:!1,defaultValue:e==null?void 0:e.defaultValue,meta:a,get:()=>this._data[t],set:f=>{this._data[t]=f},validate:i},this._accessorCache.set(t,n),n}}function le(o,t,e,a){const r=new X(o,t,e,a);return new Proxy(r,{get(i,n,f){return n==="validate"||n==="toJSON"||n==="update"||n==="save"||n==="complete"||n==="progress"||n==="_ops"||n==="_data"||n==="_fields"||n==="_accessorCache"||n==="_getAccessor"||typeof n=="symbol"?Reflect.get(i,n,f):n==="_id"?i._id:i._getAccessor(n)},has(i,n){return typeof n=="symbol"?!1:n==="validate"||n==="toJSON"||n==="update"||n==="save"||n==="complete"||n==="progress"||n==="_id"?!0:n in i._fields},ownKeys(i){return[...Object.keys(i._fields),"_id","validate","toJSON","update","save","complete","progress"]},getOwnPropertyDescriptor(i,n){if(typeof n!="symbol")return{configurable:!0,enumerable:n!=="validate"&&n!=="toJSON"&&n!=="update"&&n!=="save"&&n!=="complete"&&n!=="progress"}}})}class ue{constructor(){V(this,"_fieldsCache",null)}_ops(){return new W(this.meta.businessProcessId).activity(this.meta.activityId)}_discoverFields(){if(this._fieldsCache)return this._fieldsCache;const t={};for(const e of Object.keys(this)){const a=this[e];a instanceof A.BaseField&&(t[e]=a)}return this._fieldsCache=t,t}async getInProgressList(t){return this._ops().inProgressList(t)}async getCompletedList(t){return this._ops().completedList(t)}async inProgressCount(t){return(await this._ops().inProgressCount(t)).Count}async completedCount(t){return(await this._ops().completedCount(t)).Count}async inProgressMetric(t){return this._ops().inProgressMetric(t)}async completedMetric(t){return this._ops().completedMetric(t)}async getInstance(t){const e=this._ops(),a=await e.read(t),r=this._discoverFields();return le(e,t,a,r)}_getFields(){return this._discoverFields()}_getOps(){return this._ops()}}function K(o,t){var r;const e={_id:o,...t},a=t.Type;if(a==="String"&&((r=t.Constraint)!=null&&r.Enum))return new A.SelectField(e);switch(a){case"String":return new A.StringField(e);case"Number":return new A.NumberField(e);case"Boolean":return new A.BooleanField(e);case"Date":return new A.DateField(e);case"DateTime":return new A.DateTimeField(e);case"Text":return new A.TextField(e);case"Reference":return new A.ReferenceField(e);case"User":return new A.UserField(e);case"File":return new A.FileField(e);default:return new A.StringField(e)}}function Y(o){const t={};for(const[e,a]of Object.entries(o))t[e]=K(e,a);return t}function de(o,t,e){var i;const a=t==null?void 0:t.BDOBlob;if(!(a!=null&&a.Activity))return null;const r=o==null?void 0:o.Id;for(const n of a.Activity)if(n.Id!==r&&(i=n.Input)!=null&&i[e])return n.Input[e];return null}function ye(o){return async(t,e,a)=>{const r={},i="_getFields"in o?o._getFields():o,n=(a==null?void 0:a.names)??Object.keys(i);for(const f of n){const w=i[f];if(!w||w.readOnly)continue;let s=t[f];typeof s=="string"&&w.meta.Type==="Number"&&(s=s===""?void 0:Number(s));const l=w.validate(s);if(!l.valid&&l.errors.length>0){r[f]={type:"validate",message:l.errors[0]||`${f} is invalid`};continue}const v=k.validateConstraints(w,s);!v.valid&&v.errors.length>0&&(r[f]={type:"constraint",message:v.errors[0]})}return Object.keys(r).length===0?{values:t,errors:{}}:{values:{},errors:r}}}function fe(o,t,e){const a=o._getFields(),r=new Map,i=`/api/app/process/${o.meta.businessProcessId}/${o.meta.activityId}`,n=y.createResourceClient(i);function f(){if(!e)throw new Error("Cannot perform attachment operation: no activity instance ID");return e}return new Proxy({},{get(w,s){if(typeof s=="symbol")return;if(s==="_id")return e;if(s==="toJSON")return()=>t.getValues();if(s==="validate")return()=>t.trigger();if(r.has(s))return r.get(s);const l=a[s],v=(l==null?void 0:l.meta)??{_id:s,Name:s,Type:"String"},E=(l==null?void 0:l.readOnly)??!1,I=()=>l?l.validate(t.getValues(s)):{valid:!0,errors:[]},q=$=>{const d=t.getValues(s);return d??$};if(!E){const $=()=>{const c=t.getValues(s);return v.Type==="File"?c??[]:c},d={label:(l==null?void 0:l.label)??s,required:(l==null?void 0:l.required)??!1,readOnly:!1,defaultValue:l==null?void 0:l.defaultValue,meta:v,get:$,getOrDefault:q,set:c=>{t.setValue(s,c,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:I};return(v.Type==="Image"||v.Type==="File")&&(v.Type==="Image"?(d.upload=async c=>{z.validateFileExtension(c.name,"Image");const m=f(),[g]=await n.getUploadUrl(m,s,[{FileName:c.name,Size:c.size,FileExtension:z.extractFileExtension(c.name)}]);await fetch(g.UploadUrl.URL,{method:"PUT",headers:{"Content-Type":g.ContentType},body:c});const F={_id:g._id,_name:g._name,FileName:g.FileName,FileExtension:g.FileExtension,Size:g.Size,ContentType:g.ContentType};return t.setValue(s,F,{shouldDirty:!0}),F},d.deleteAttachment=async()=>{const c=t.getValues(s),m=f();if(!(c!=null&&c._id))throw new Error(`${s} has no image to delete`);await n.deleteAttachment(m,s,c._id),t.setValue(s,null,{shouldDirty:!0})},d.getDownloadUrl=async c=>{const m=t.getValues(s),g=f();if(!(m!=null&&m._id))throw new Error(`${s} has no image`);return n.getDownloadUrl(g,s,m._id,c)}):(d.upload=async c=>{for(const O of c)z.validateFileExtension(O.name,"File");const m=f(),g=c.map(O=>({FileName:O.name,Size:O.size,FileExtension:z.extractFileExtension(O.name)})),F=await n.getUploadUrl(m,s,g),R=await Promise.all(c.map(async(O,P)=>(await fetch(F[P].UploadUrl.URL,{method:"PUT",headers:{"Content-Type":F[P].ContentType},body:O}),{_id:F[P]._id,_name:F[P]._name,FileName:F[P].FileName,FileExtension:F[P].FileExtension,Size:F[P].Size,ContentType:F[P].ContentType}))),u=t.getValues(s)??[];return t.setValue(s,[...u,...R],{shouldDirty:!0}),R},d.deleteAttachment=async c=>{const m=t.getValues(s)??[],g=f();await n.deleteAttachment(g,s,c),t.setValue(s,m.filter(F=>F._id!==c),{shouldDirty:!0})},d.getDownloadUrl=async(c,m)=>{const g=f();return n.getDownloadUrl(g,s,c,m)},d.getDownloadUrls=async c=>{const m=f();return n.getDownloadUrls(m,s,c)})),r.set(s,d),d}const B=()=>{const $=t.getValues(s);return v.Type==="File"?$??[]:$},D={label:(l==null?void 0:l.label)??s,required:(l==null?void 0:l.required)??!1,readOnly:!0,defaultValue:l==null?void 0:l.defaultValue,meta:v,get:B,getOrDefault:q,validate:I};return(v.Type==="Image"||v.Type==="File")&&(v.Type==="Image"?D.getDownloadUrl=async $=>{const d=t.getValues(s),c=f();if(!(d!=null&&d._id))throw new Error(`${s} has no image to download`);return n.getDownloadUrl(c,s,d._id,$)}:(D.getDownloadUrl=async($,d)=>{const c=f();return n.getDownloadUrl(c,s,$,d)},D.getDownloadUrls=async $=>{const d=f();return n.getDownloadUrls(d,s,$)})),r.set(s,D),D},has(w,s){return typeof s=="symbol"?!1:s==="_id"||s==="toJSON"||s==="validate"?!0:s in a},ownKeys(w){return[...Object.keys(a),"_id","toJSON","validate"]},getOwnPropertyDescriptor(w,s){if(typeof s!="symbol")return{configurable:!0,enumerable:s!=="toJSON"&&s!=="validate"}}})}function ge(o,t){const{activity_instance_id:e,defaultValues:a={},mode:r="onBlur",enabled:i=!0}=t,[n,f]=h.useState(!1),[w,s]=h.useState(null),[l,v]=h.useState(!1),[E,I]=h.useState({}),q=h.useRef(!1),B=h.useRef(null),{data:D,isLoading:$}=oe.useQuery({queryKey:["bp-metadata",o.meta.businessProcessId],queryFn:()=>ce.getBdoSchema(o.meta.businessProcessId),staleTime:30*60*1e3}),d=h.useMemo(()=>{const _=D==null?void 0:D.BDOBlob;return _!=null&&_.Activity?_.Activity.find(b=>b.Id===o.meta.activityId)??null:null},[D,o.meta.activityId]),c=$,m=h.useMemo(()=>d!=null&&d.Input?Y(d.Input):o._getFields(),[d,o]),g=h.useMemo(()=>({...E,...m}),[E,m]),F=h.useMemo(()=>Object.keys(g).filter(_=>g[_].readOnly),[g]),R=h.useMemo(()=>ye(m),[m]),u=k.useForm({mode:r,defaultValues:a,resolver:R}),O=h.useMemo(()=>o._getOps(),[o]),P=h.useMemo(()=>fe(o,u,e),[o,u,e]);h.useEffect(()=>{if(!i||c)return;let _=!0;return(async()=>{f(!0),s(null);try{const T=await O.read(e);if(!_)return;if(T&&typeof T=="object"){const U=k.coerceRecordForForm(m,T),p={...a,...U};(B.current===null||T!==B.current)&&(u.reset(p),B.current=T);const M=new Set(["_id","BPInstanceId","Status","AssignedTo","CompletedAt","_created_at","_modified_at","_created_by","_modified_by","_v","_m_v"]),x={};for(const C of Object.keys(T))if(!m[C]&&!M.has(C)){const S=de(d,D,C);S&&(x[C]=K(C,{...S,ReadOnly:!0}))}Object.keys(x).length>0&&I(x)}}catch(T){if(!_)return;console.error("Failed to read activity data:",T),s(G.toError(T))}finally{_&&f(!1)}})(),()=>{_=!1}},[i,c,O,e]);const Q=h.useCallback((_,b)=>O.update(e,{[_]:b}),[O,e]),J=h.useMemo(()=>k.createSyncField({apiFn:Q,allFields:g,readonlyFieldNames:F,rhf:u,isComputingRef:q}),[Q,g,F,u]),L=r==="onChange"||r==="all",H=r==="onBlur"||r==="onTouched"||r==="all",Z=h.useMemo(()=>k.createEnhancedRegister({rhf:u,allFields:g,syncField:J,syncOnBlur:H,syncOnChange:L}),[u,g,J,H,L]),ee=h.useMemo(()=>k.createEnhancedControl({control:u.control,syncField:J,syncOnBlur:H,syncOnChange:L}),[u.control,J,H,L]),te=h.useCallback((_,b)=>u.handleSubmit(async(T,U)=>{v(!0);try{const p={},M=new Set(F),x=u.formState.dirtyFields,C=u.getValues();for(const S of Object.keys(C)){if(M.has(S)||!x[S])continue;const N=C[S]!==void 0?C[S]:T[S],j=g[S];p[S]=j?k.coerceFieldValue(j,N):N}Object.keys(p).length>0&&await O.update(e,p),await(_==null?void 0:_(T,U))}catch(p){b==null||b(G.toError(p),U)}finally{v(!1)}},(T,U)=>{b==null||b(T,U)}),[u,O,F,g,e]),se=h.useCallback((_,b)=>u.handleSubmit(async(T,U)=>{v(!0);try{const p={},M=new Set(F),x=u.formState.dirtyFields,C=u.getValues();for(const S of Object.keys(C)){if(M.has(S)||!x[S])continue;const N=C[S]!==void 0?C[S]:T[S],j=g[S];p[S]=j?k.coerceFieldValue(j,N):N}Object.keys(p).length>0&&await O.update(e,p),await O.complete(e),await(_==null?void 0:_(T,U))}catch(p){b==null||b(G.toError(p),U)}finally{v(!1)}},(T,U)=>{b==null||b(T,U)}),[u,O,F,g,e]),ae=h.useCallback(()=>{u.clearErrors()},[u]),re=!!w;return{item:P,activity:o,register:Z,handleSubmit:te,handleComplete:se,watch:u.watch,setValue:u.setValue,getValues:u.getValues,reset:u.reset,trigger:u.trigger,control:ee,errors:u.formState.errors,isValid:u.formState.isValid,isDirty:u.formState.isDirty,isSubmitting:u.formState.isSubmitting||l,isSubmitSuccessful:u.formState.isSubmitSuccessful,isLoading:n||c,isMetadataLoading:c,loadError:w,hasError:re,bpMetadata:D??null,clearErrors:ae}}function he(o){const{activity:t,status:e,...a}=o,{businessProcessId:r,activityId:i}=t.meta,n=h.useMemo(()=>t._getOps(),[t]),f=h.useMemo(()=>e==="inprogress"?s=>n.inProgressList(s):s=>n.completedList(s),[n,e]),w=h.useMemo(()=>e==="inprogress"?s=>n.inProgressCount(s):s=>n.completedCount(s),[n,e]);return G.useTable({queryKey:["activity-table",r,i,e],listFn:f,countFn:w,...a})}const me={InProgress:"inprogress",Completed:"completed"};exports.Activity=ue;exports.ActivityInstance=X;exports.ActivityTableStatus=me;exports.Workflow=W;exports.buildFieldsFromInput=Y;exports.createFieldFromMeta=K;exports.useActivityForm=ge;exports.useActivityTable=he;
|