@ram_28/kf-ai-sdk 2.0.5 → 2.0.8
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/dist/workflow/Activity.d.ts +11 -9
- package/dist/workflow/Activity.d.ts.map +1 -1
- package/dist/workflow/client.d.ts +12 -10
- package/dist/workflow/client.d.ts.map +1 -1
- package/dist/workflow/types.d.ts +12 -11
- package/dist/workflow/types.d.ts.map +1 -1
- package/dist/workflow.cjs +1 -1
- package/dist/workflow.mjs +200 -212
- package/docs/workflow.md +38 -76
- package/package.json +1 -1
- package/sdk/workflow/Activity.ts +18 -26
- package/sdk/workflow/client.ts +25 -47
- package/sdk/workflow/types.ts +11 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ActivityInstanceType } from "./ActivityInstance";
|
|
2
2
|
import type { ActivityInstanceFieldsType, ActivityOperations } from "./types";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ListResponseType, MetricResponseType } from "../types/common";
|
|
4
4
|
import { BaseField } from "../bdo/fields/BaseField";
|
|
5
5
|
/**
|
|
6
6
|
* Abstract base class for workflow activities.
|
|
@@ -30,8 +30,8 @@ import { BaseField } from "../bdo/fields/BaseField";
|
|
|
30
30
|
* }
|
|
31
31
|
*
|
|
32
32
|
* const activity = new EmployeeInputActivity();
|
|
33
|
-
* const inProgress = await activity.getInProgressList(
|
|
34
|
-
* const completed = await activity.getCompletedList(
|
|
33
|
+
* const inProgress = await activity.getInProgressList();
|
|
34
|
+
* const completed = await activity.getCompletedList();
|
|
35
35
|
* const instance = await activity.getInstance("inst_123");
|
|
36
36
|
* instance.StartDate.get(); // typed value
|
|
37
37
|
* instance.StartDate.set("2026-03-01");
|
|
@@ -58,21 +58,23 @@ export declare abstract class Activity<TEntity extends Record<string, unknown>,
|
|
|
58
58
|
*/
|
|
59
59
|
private _discoverFields;
|
|
60
60
|
/**
|
|
61
|
-
* List in-progress activity instances
|
|
61
|
+
* List in-progress activity instances.
|
|
62
|
+
* Filtering and pagination are handled server-side.
|
|
62
63
|
*/
|
|
63
|
-
getInProgressList(
|
|
64
|
+
getInProgressList(): Promise<ListResponseType<ActivityInstanceFieldsType & TEntity>>;
|
|
64
65
|
/**
|
|
65
|
-
* List completed activity instances
|
|
66
|
+
* List completed activity instances.
|
|
67
|
+
* Filtering and pagination are handled server-side.
|
|
66
68
|
*/
|
|
67
|
-
getCompletedList(
|
|
69
|
+
getCompletedList(): Promise<ListResponseType<ActivityInstanceFieldsType & TEntity>>;
|
|
68
70
|
/**
|
|
69
71
|
* Get aggregated metrics for in-progress activity instances.
|
|
70
72
|
*/
|
|
71
|
-
inProgressMetrics(
|
|
73
|
+
inProgressMetrics(): Promise<MetricResponseType>;
|
|
72
74
|
/**
|
|
73
75
|
* Get aggregated metrics for completed activity instances.
|
|
74
76
|
*/
|
|
75
|
-
completedMetrics(
|
|
77
|
+
completedMetrics(): Promise<MetricResponseType>;
|
|
76
78
|
/**
|
|
77
79
|
* Get a typed ActivityInstance with field accessors and persistence methods.
|
|
78
80
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../sdk/workflow/Activity.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"Activity.d.ts","sourceRoot":"","sources":["../../sdk/workflow/Activity.ts"],"names":[],"mappings":"AAoBA,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,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,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|
* const wf = new Workflow<LeaveType>("SimpleLeaveProcess");
|
|
8
8
|
*
|
|
9
9
|
* // Start workflow
|
|
10
|
-
* const {
|
|
10
|
+
* const { BPInstanceId, ActivityId, _id } = await wf.start();
|
|
11
11
|
*
|
|
12
12
|
* // Get activity operations
|
|
13
13
|
* const act = wf.activity("EMPLOYEE_INPUT");
|
|
@@ -18,14 +18,14 @@ import type { ActivityOperations, ActivityProgressType, WorkflowStartResponseTyp
|
|
|
18
18
|
* await act.draftEnd("inst_123", data);
|
|
19
19
|
* await act.complete("inst_123");
|
|
20
20
|
*
|
|
21
|
-
* // List operations (by status)
|
|
22
|
-
* await act.inProgressList(
|
|
23
|
-
* await act.completedList(
|
|
24
|
-
* await act.inProgressMetric(
|
|
25
|
-
* await act.completedMetric(
|
|
21
|
+
* // List operations (by status — filtering/pagination handled server-side)
|
|
22
|
+
* await act.inProgressList();
|
|
23
|
+
* await act.completedList();
|
|
24
|
+
* await act.inProgressMetric();
|
|
25
|
+
* await act.completedMetric();
|
|
26
26
|
*
|
|
27
|
-
* //
|
|
28
|
-
* const progress = await wf.progress();
|
|
27
|
+
* // Process progress (requires instance_id)
|
|
28
|
+
* const progress = await wf.progress("bp_inst_123");
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
export declare class Workflow<T = any> {
|
|
@@ -36,10 +36,12 @@ export declare class Workflow<T = any> {
|
|
|
36
36
|
*/
|
|
37
37
|
start(): Promise<WorkflowStartResponseType>;
|
|
38
38
|
/**
|
|
39
|
-
* Get
|
|
39
|
+
* Get progress for a specific process instance.
|
|
40
40
|
* Returns a list of progress entries for each stage/activity.
|
|
41
|
+
*
|
|
42
|
+
* @param instance_id - The business process instance ID (from start().BPInstanceId)
|
|
41
43
|
*/
|
|
42
|
-
progress(): Promise<ActivityProgressType[]>;
|
|
44
|
+
progress(instance_id: string): Promise<ActivityProgressType[]>;
|
|
43
45
|
/**
|
|
44
46
|
* Get all operations for a specific activity
|
|
45
47
|
* @param activity_id - Activity identifier
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../sdk/workflow/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../sdk/workflow/client.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,kBAAkB,EAClB,oBAAoB,EACpB,yBAAyB,EAC1B,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,qBAAa,QAAQ,CAAC,CAAC,GAAG,GAAG;IAC3B,OAAO,CAAC,KAAK,CAAS;gBAEV,KAAK,EAAE,MAAM;IAIzB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,yBAAyB,CAAC;IAiBjD;;;;;OAKG;IACG,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAiBpE;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,kBAAkB,CAAC,CAAC,CAAC;CA+IrD"}
|
package/dist/workflow/types.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ListResponseType, MetricResponseType, DraftResponseType, CreateUpdateResponseType } from "../types/common";
|
|
2
2
|
import type { StringFieldType, SelectFieldType, DateTimeFieldType, ReferenceFieldType } from "../types/base-fields";
|
|
3
3
|
import type { UserRefType } from "../types/base-fields";
|
|
4
4
|
/**
|
|
5
5
|
* Response from Workflow.start()
|
|
6
6
|
*/
|
|
7
7
|
export interface WorkflowStartResponseType {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
BPInstanceId: string;
|
|
9
|
+
ActivityId: string;
|
|
10
|
+
_id: string;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* Response from the activity progress endpoint.
|
|
@@ -46,14 +47,14 @@ export type ActivityInstanceFieldsType = {
|
|
|
46
47
|
* Instance-level methods accept `instanceId` as their first parameter.
|
|
47
48
|
*/
|
|
48
49
|
export interface ActivityOperations<T> {
|
|
49
|
-
/** List in-progress activity instances (
|
|
50
|
-
inProgressList(
|
|
51
|
-
/** List completed activity instances (
|
|
52
|
-
completedList(
|
|
53
|
-
/** Get in-progress activity metrics (
|
|
54
|
-
inProgressMetric(
|
|
55
|
-
/** Get completed activity metrics (
|
|
56
|
-
completedMetric(
|
|
50
|
+
/** List in-progress activity instances (GET .../inprogress/list) */
|
|
51
|
+
inProgressList(): Promise<ListResponseType<ActivityInstanceFieldsType & T>>;
|
|
52
|
+
/** List completed activity instances (GET .../completed/list) */
|
|
53
|
+
completedList(): Promise<ListResponseType<ActivityInstanceFieldsType & T>>;
|
|
54
|
+
/** Get in-progress activity metrics (GET .../inprogress/metric) */
|
|
55
|
+
inProgressMetric(): Promise<MetricResponseType>;
|
|
56
|
+
/** Get completed activity metrics (GET .../completed/metric) */
|
|
57
|
+
completedMetric(): Promise<MetricResponseType>;
|
|
57
58
|
/** Read the activity instance data (GET .../read) */
|
|
58
59
|
read(instanceId: string): Promise<ActivityInstanceFieldsType & T>;
|
|
59
60
|
/** Update the activity instance (POST .../update) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../sdk/workflow/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../sdk/workflow/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,KAAK,EACV,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,Y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A0B,GAAG,CAAC,CAAC,CAAC;IAElE,qDAAqD;IACrD,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAEhF,mDAAmD;IACnD,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAE7E,2DAA2D;IAC3D,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAElF,4CAA4C;IAC5C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAEhE,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAAC;CAC/D"}
|
package/dist/workflow.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var F=Object.defineProperty;var R=(o,t,r)=>t in o?F(o,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):o[t]=r;var b=(o,t,r)=>R(o,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./client-DtPpfJc1.cjs"),U=require("./BaseField-Drp0-OxL.cjs"),f=require("react"),L=require("./index.esm-DuwT11sx.cjs"),A=require("./error-handling-CAoD0Kwb.cjs");class N{constructor(t){b(this,"bp_id");this.bp_id=t}async start(){const t=await fetch(`${l.getApiBaseUrl()}/api/app/process/${this.bp_id}/start`,{method:"POST",headers:l.getDefaultHeaders()});if(!t.ok)throw new Error(`Failed to start process: ${t.statusText}`);return t.json()}async progress(){const t=await fetch(`${l.getApiBaseUrl()}/api/app/process/${this.bp_id}/progress`,{method:"GET",headers:l.getDefaultHeaders()});if(!t.ok)throw new Error(`Failed to get process progress: ${t.statusText}`);return t.json()}activity(t){const r=`/api/app/process/${this.bp_id}/${t}`;return{async inProgressList(i){const s={Type:"List",...i},e=await fetch(`${l.getApiBaseUrl()}${r}/inprogress/list`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!e.ok)throw new Error(`Failed to list in-progress activities: ${e.statusText}`);return e.json()},async completedList(i){const s={Type:"List",...i},e=await fetch(`${l.getApiBaseUrl()}${r}/completed/list`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!e.ok)throw new Error(`Failed to list completed activities: ${e.statusText}`);return e.json()},async inProgressMetric(i){const s={Type:"Metric",...i},e=await fetch(`${l.getApiBaseUrl()}${r}/inprogress/metric`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!e.ok)throw new Error(`Failed to get in-progress activity metrics: ${e.statusText}`);return e.json()},async completedMetric(i){const s={Type:"Metric",...i},e=await fetch(`${l.getApiBaseUrl()}${r}/completed/metric`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!e.ok)throw new Error(`Failed to get completed activity metrics: ${e.statusText}`);return e.json()},async read(i){const s=await fetch(`${l.getApiBaseUrl()}${r}/${i}/read`,{method:"GET",headers:l.getDefaultHeaders()});if(!s.ok)throw new Error(`Failed to read activity: ${s.statusText}`);return(await s.json()).Data},async update(i,s){const e=await fetch(`${l.getApiBaseUrl()}${r}/${i}/update`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!e.ok)throw new Error(`Failed to update activity: ${e.statusText}`);return e.json()},async draftStart(i,s){const e=await fetch(`${l.getApiBaseUrl()}${r}/${i}/draft`,{method:"PATCH",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!e.ok)throw new Error(`Failed to start draft: ${e.statusText}`);return e.json()},async draftEnd(i,s){const e=await fetch(`${l.getApiBaseUrl()}${r}/${i}/draft`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!e.ok)throw new Error(`Failed to end draft: ${e.statusText}`);return e.json()},async complete(i){const s=await fetch(`${l.getApiBaseUrl()}${r}/${i}/done`,{method:"POST",headers:l.getDefaultHeaders()});if(!s.ok)throw new Error(`Failed to complete activity: ${s.statusText}`);return s.json()},async progress(i){const s=await fetch(`${l.getApiBaseUrl()}${r}/${i}/progress`,{method:"GET",headers:l.getDefaultHeaders()});if(!s.ok)throw new Error(`Failed to get activity progress: ${s.statusText}`);return s.json()}}}}class C{constructor(t,r,i,s){b(this,"_id");b(this,"_data");b(this,"_ops");b(this,"_fields");b(this,"_accessorCache",new Map);this._ops=t,this._id=r,this._data={...i},this._fields=s}toJSON(){return{...this._data}}validate(){const t=[];for(const[r,i]of Object.entries(this._fields)){const s=this._data[r],e=i.validate(s);e.valid||t.push(...e.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 r=this._fields[t],i=(r==null?void 0:r.meta)??{_id:t,Name:t,Type:"String"},s=(r==null?void 0:r.readOnly)??!1,e=()=>r?r.validate(this._data[t]):{valid:!0,errors:[]};let a;return s?a={label:(r==null?void 0:r.label)??t,required:(r==null?void 0:r.required)??!1,readOnly:!0,defaultValue:r==null?void 0:r.defaultValue,meta:i,get:()=>this._data[t],validate:e}:a={label:(r==null?void 0:r.label)??t,required:(r==null?void 0:r.required)??!1,readOnly:!1,defaultValue:r==null?void 0:r.defaultValue,meta:i,get:()=>this._data[t],set:g=>{this._data[t]=g},validate:e},this._accessorCache.set(t,a),a}}function G(o,t,r,i){const s=new C(o,t,r,i);return new Proxy(s,{get(e,a,g){return a==="validate"||a==="toJSON"||a==="update"||a==="save"||a==="complete"||a==="progress"||a==="_ops"||a==="_data"||a==="_fields"||a==="_accessorCache"||a==="_getAccessor"||typeof a=="symbol"?Reflect.get(e,a,g):a==="_id"?e._id:e._getAccessor(a)},has(e,a){return typeof a=="symbol"?!1:a==="validate"||a==="toJSON"||a==="update"||a==="save"||a==="complete"||a==="progress"||a==="_id"?!0:a in e._fields},ownKeys(e){return[...Object.keys(e._fields),"_id","validate","toJSON","update","save","complete","progress"]},getOwnPropertyDescriptor(e,a){if(typeof a!="symbol")return{configurable:!0,enumerable:a!=="validate"&&a!=="toJSON"&&a!=="update"&&a!=="save"&&a!=="complete"&&a!=="progress"}}})}class K{constructor(){b(this,"_fieldsCache",null)}_ops(){return new N(this.meta.businessProcessId).activity(this.meta.activityId)}_discoverFields(){if(this._fieldsCache)return this._fieldsCache;const t={};for(const r of Object.keys(this)){const i=this[r];i instanceof U.BaseField&&(t[r]=i)}return this._fieldsCache=t,t}async getInProgressList(t){return this._ops().inProgressList(t)}async getCompletedList(t){return this._ops().completedList(t)}async inProgressMetrics(t){return this._ops().inProgressMetric(t)}async completedMetrics(t){return this._ops().completedMetric(t)}async getInstance(t){const r=this._ops(),i=await r.read(t),s=this._discoverFields();return G(r,t,i,s)}_getFields(){return this._discoverFields()}_getOps(){return this._ops()}}function W(o){return async(t,r,i)=>{const s={},e=o._getFields(),a=(i==null?void 0:i.names)??Object.keys(e);for(const g of a){const w=e[g];if(!w||w.readOnly)continue;const $=t[g],O=w.validate($);!O.valid&&O.errors.length>0&&(s[g]={type:"validate",message:O.errors[0]||`${g} is invalid`})}return Object.keys(s).length===0?{values:t,errors:{}}:{values:{},errors:s}}}function z(o,t){const r=o._getFields();return new Proxy({},{get(i,s){if(typeof s=="symbol")return;if(s==="toJSON")return()=>t.getValues();if(s==="validate")return()=>t.trigger();const e=r[s],a=(e==null?void 0:e.meta)??{_id:s,Name:s,Type:"String"},g=(e==null?void 0:e.readOnly)??!1,w=()=>e?e.validate(t.getValues(s)):{valid:!0,errors:[]};return g?{label:(e==null?void 0:e.label)??s,required:(e==null?void 0:e.required)??!1,readOnly:!0,defaultValue:e==null?void 0:e.defaultValue,meta:a,get:()=>t.getValues(s),getOrDefault:O=>t.getValues(s)??O,validate:w}:{label:(e==null?void 0:e.label)??s,required:(e==null?void 0:e.required)??!1,readOnly:!1,defaultValue:e==null?void 0:e.defaultValue,meta:a,get:()=>t.getValues(s),getOrDefault:S=>t.getValues(s)??S,set:S=>{t.setValue(s,S,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:w}},has(i,s){return typeof s=="symbol"?!1:s==="toJSON"||s==="validate"?!0:s in r},ownKeys(i){return[...Object.keys(r),"toJSON","validate"]},getOwnPropertyDescriptor(i,s){if(typeof s!="symbol")return{configurable:!0,enumerable:s!=="toJSON"&&s!=="validate"}}})}function Q(o,t){const{activity_instance_id:r,defaultValues:i={},mode:s="onBlur",enabled:e=!0}=t,[a,g]=f.useState(!1),[w,$]=f.useState(null),[O,S]=f.useState(!1),V=f.useRef(!1),B=f.useRef(null),T=f.useMemo(()=>o._getFields(),[o]),p=f.useMemo(()=>Object.keys(T).filter(d=>T[d].readOnly),[T]),q=f.useMemo(()=>W(o),[o]),n=L.useForm({mode:s,defaultValues:i,resolver:q}),x=f.useMemo(()=>z(o,n),[o,n]),v=f.useMemo(()=>o._getOps(),[o]);f.useEffect(()=>{if(!e)return;let d=!0;return(async()=>{g(!0),$(null);try{const u=await v.read(r);if(!d)return;u&&typeof u=="object"&&n.reset({...i,...u})}catch(u){if(!d)return;console.error("Failed to read activity data:",u),$(A.toError(u))}finally{d&&g(!1)}})(),()=>{d=!1}},[e,v,r]);const P=f.useCallback(async d=>{p.length!==0&&(V.current||(B.current&&clearTimeout(B.current),B.current=setTimeout(async()=>{if(!V.current){V.current=!0;try{const c=n.getValues(),u={},h=new Set(p);Object.keys(c).forEach(m=>{h.has(m)||(u[m]=c[m])});const y=await v.draftStart(r,u);y&&typeof y=="object"&&Object.entries(y).forEach(([m,_])=>{h.has(m)&&n.getValues(m)!==_&&n.setValue(m,_,{shouldDirty:!1,shouldValidate:!1})})}catch(c){console.warn("Draft computation failed:",c)}finally{V.current=!1}}},300)))},[v,p,n]),J=f.useCallback((d,c)=>{const u=T[d],h=u?u.readOnly:!1,y=c==null?void 0:c.onBlur,m=async k=>{y&&await y(k);let j=!0;s==="onBlur"||s==="onTouched"||s==="all"?j=await n.trigger(d):j=!n.getFieldState(d,n.formState).error,j&&await P(d)},_=n.register(d,{...c,onBlur:m,...h?{disabled:!0}:{}});return h?{..._,disabled:!0}:_},[n,T,P,s]),M=f.useCallback((d,c)=>n.handleSubmit(async(u,h)=>{S(!0);try{const y={},m=new Set(p);Object.keys(u).forEach(_=>{!m.has(_)&&u[_]!==void 0&&(y[_]=u[_])}),await v.update(r,y),await v.draftEnd(r,y),await(d==null?void 0:d(u,h))}catch(y){c==null||c(A.toError(y),h)}finally{S(!1)}},(u,h)=>{c==null||c(u,h)}),[n,v,p]),D=f.useCallback((d,c)=>n.handleSubmit(async(u,h)=>{S(!0);try{await v.complete(r),await(d==null?void 0:d(u,h))}catch(y){c==null||c(A.toError(y),h)}finally{S(!1)}},(u,h)=>{c==null||c(u,h)}),[n,v]),H=f.useCallback(()=>{n.clearErrors()},[n]),E=!!w;return{item:x,activity:o,register:J,handleSubmit:M,handleComplete:D,watch:n.watch,setValue:n.setValue,getValues:n.getValues,reset:n.reset,trigger:n.trigger,control:n.control,errors:n.formState.errors,isValid:n.formState.isValid,isDirty:n.formState.isDirty,isSubmitting:n.formState.isSubmitting||O,isSubmitSuccessful:n.formState.isSubmitSuccessful,isLoading:a,loadError:w,hasError:E,clearErrors:H}}exports.Activity=K;exports.ActivityInstance=C;exports.Workflow=N;exports.useActivityForm=Q;
|
|
1
|
+
"use strict";var J=Object.defineProperty;var R=(o,t,e)=>t in o?J(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var O=(o,t,e)=>R(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./client-DtPpfJc1.cjs"),U=require("./BaseField-Drp0-OxL.cjs"),f=require("react"),L=require("./index.esm-DuwT11sx.cjs"),B=require("./error-handling-CAoD0Kwb.cjs");class C{constructor(t){O(this,"bp_id");this.bp_id=t}async start(){const t=await fetch(`${l.getApiBaseUrl()}/api/app/process/${this.bp_id}/start`,{method:"POST",headers:l.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(`${l.getApiBaseUrl()}/api/app/process/${this.bp_id}/${t}/progress`,{method:"GET",headers:l.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(){const r=await fetch(`${l.getApiBaseUrl()}${e}/inprogress/list`,{method:"GET",headers:l.getDefaultHeaders()});if(!r.ok)throw new Error(`Failed to list in-progress activities: ${r.statusText}`);return r.json()},async completedList(){const r=await fetch(`${l.getApiBaseUrl()}${e}/completed/list`,{method:"GET",headers:l.getDefaultHeaders()});if(!r.ok)throw new Error(`Failed to list completed activities: ${r.statusText}`);return r.json()},async inProgressMetric(){const r=await fetch(`${l.getApiBaseUrl()}${e}/inprogress/metric`,{method:"GET",headers:l.getDefaultHeaders()});if(!r.ok)throw new Error(`Failed to get in-progress activity metrics: ${r.statusText}`);return r.json()},async completedMetric(){const r=await fetch(`${l.getApiBaseUrl()}${e}/completed/metric`,{method:"GET",headers:l.getDefaultHeaders()});if(!r.ok)throw new Error(`Failed to get completed activity metrics: ${r.statusText}`);return r.json()},async read(r){const s=await fetch(`${l.getApiBaseUrl()}${e}/${r}/read`,{method:"GET",headers:l.getDefaultHeaders()});if(!s.ok)throw new Error(`Failed to read activity: ${s.statusText}`);return(await s.json()).Data},async update(r,s){const a=await fetch(`${l.getApiBaseUrl()}${e}/${r}/update`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!a.ok)throw new Error(`Failed to update activity: ${a.statusText}`);return a.json()},async draftStart(r,s){const a=await fetch(`${l.getApiBaseUrl()}${e}/${r}/draft`,{method:"PATCH",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!a.ok)throw new Error(`Failed to start draft: ${a.statusText}`);return a.json()},async draftEnd(r,s){const a=await fetch(`${l.getApiBaseUrl()}${e}/${r}/draft`,{method:"POST",headers:l.getDefaultHeaders(),body:JSON.stringify(s)});if(!a.ok)throw new Error(`Failed to end draft: ${a.statusText}`);return a.json()},async complete(r){const s=await fetch(`${l.getApiBaseUrl()}${e}/${r}/done`,{method:"POST",headers:l.getDefaultHeaders()});if(!s.ok)throw new Error(`Failed to complete activity: ${s.statusText}`);return s.json()},async progress(r){const s=await fetch(`${l.getApiBaseUrl()}${e}/${r}/progress`,{method:"GET",headers:l.getDefaultHeaders()});if(!s.ok)throw new Error(`Failed to get activity progress: ${s.statusText}`);return s.json()}}}}class P{constructor(t,e,r,s){O(this,"_id");O(this,"_data");O(this,"_ops");O(this,"_fields");O(this,"_accessorCache",new Map);this._ops=t,this._id=e,this._data={...r},this._fields=s}toJSON(){return{...this._data}}validate(){const t=[];for(const[e,r]of Object.entries(this._fields)){const s=this._data[e],a=r.validate(s);a.valid||t.push(...a.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],r=(e==null?void 0:e.meta)??{_id:t,Name:t,Type:"String"},s=(e==null?void 0:e.readOnly)??!1,a=()=>e?e.validate(this._data[t]):{valid:!0,errors:[]};let i;return s?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:r,get:()=>this._data[t],validate:a}: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:r,get:()=>this._data[t],set:g=>{this._data[t]=g},validate:a},this._accessorCache.set(t,i),i}}function G(o,t,e,r){const s=new P(o,t,e,r);return new Proxy(s,{get(a,i,g){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(a,i,g):i==="_id"?a._id:a._getAccessor(i)},has(a,i){return typeof i=="symbol"?!1:i==="validate"||i==="toJSON"||i==="update"||i==="save"||i==="complete"||i==="progress"||i==="_id"?!0:i in a._fields},ownKeys(a){return[...Object.keys(a._fields),"_id","validate","toJSON","update","save","complete","progress"]},getOwnPropertyDescriptor(a,i){if(typeof i!="symbol")return{configurable:!0,enumerable:i!=="validate"&&i!=="toJSON"&&i!=="update"&&i!=="save"&&i!=="complete"&&i!=="progress"}}})}class K{constructor(){O(this,"_fieldsCache",null)}_ops(){return new C(this.meta.businessProcessId).activity(this.meta.activityId)}_discoverFields(){if(this._fieldsCache)return this._fieldsCache;const t={};for(const e of Object.keys(this)){const r=this[e];r instanceof U.BaseField&&(t[e]=r)}return this._fieldsCache=t,t}async getInProgressList(){return this._ops().inProgressList()}async getCompletedList(){return this._ops().completedList()}async inProgressMetrics(){return this._ops().inProgressMetric()}async completedMetrics(){return this._ops().completedMetric()}async getInstance(t){const e=this._ops(),r=await e.read(t),s=this._discoverFields();return G(e,t,r,s)}_getFields(){return this._discoverFields()}_getOps(){return this._ops()}}function W(o){return async(t,e,r)=>{const s={},a=o._getFields(),i=(r==null?void 0:r.names)??Object.keys(a);for(const g of i){const w=a[g];if(!w||w.readOnly)continue;const S=t[g],$=w.validate(S);!$.valid&&$.errors.length>0&&(s[g]={type:"validate",message:$.errors[0]||`${g} is invalid`})}return Object.keys(s).length===0?{values:t,errors:{}}:{values:{},errors:s}}}function z(o,t){const e=o._getFields();return new Proxy({},{get(r,s){if(typeof s=="symbol")return;if(s==="toJSON")return()=>t.getValues();if(s==="validate")return()=>t.trigger();const a=e[s],i=(a==null?void 0:a.meta)??{_id:s,Name:s,Type:"String"},g=(a==null?void 0:a.readOnly)??!1,w=()=>a?a.validate(t.getValues(s)):{valid:!0,errors:[]};return g?{label:(a==null?void 0:a.label)??s,required:(a==null?void 0:a.required)??!1,readOnly:!0,defaultValue:a==null?void 0:a.defaultValue,meta:i,get:()=>t.getValues(s),getOrDefault:$=>t.getValues(s)??$,validate:w}:{label:(a==null?void 0:a.label)??s,required:(a==null?void 0:a.required)??!1,readOnly:!1,defaultValue:a==null?void 0:a.defaultValue,meta:i,get:()=>t.getValues(s),getOrDefault:b=>t.getValues(s)??b,set:b=>{t.setValue(s,b,{shouldDirty:!0,shouldTouch:!0,shouldValidate:!1})},validate:w}},has(r,s){return typeof s=="symbol"?!1:s==="toJSON"||s==="validate"?!0:s in e},ownKeys(r){return[...Object.keys(e),"toJSON","validate"]},getOwnPropertyDescriptor(r,s){if(typeof s!="symbol")return{configurable:!0,enumerable:s!=="toJSON"&&s!=="validate"}}})}function Q(o,t){const{activity_instance_id:e,defaultValues:r={},mode:s="onBlur",enabled:a=!0}=t,[i,g]=f.useState(!1),[w,S]=f.useState(null),[$,b]=f.useState(!1),V=f.useRef(!1),j=f.useRef(null),T=f.useMemo(()=>o._getFields(),[o]),p=f.useMemo(()=>Object.keys(T).filter(d=>T[d].readOnly),[T]),x=f.useMemo(()=>W(o),[o]),n=L.useForm({mode:s,defaultValues:r,resolver:x}),E=f.useMemo(()=>z(o,n),[o,n]),v=f.useMemo(()=>o._getOps(),[o]);f.useEffect(()=>{if(!a)return;let d=!0;return(async()=>{g(!0),S(null);try{const u=await v.read(e);if(!d)return;u&&typeof u=="object"&&n.reset({...r,...u})}catch(u){if(!d)return;console.error("Failed to read activity data:",u),S(B.toError(u))}finally{d&&g(!1)}})(),()=>{d=!1}},[a,v,e]);const k=f.useCallback(async d=>{p.length!==0&&(V.current||(j.current&&clearTimeout(j.current),j.current=setTimeout(async()=>{if(!V.current){V.current=!0;try{const c=n.getValues(),u={},h=new Set(p);Object.keys(c).forEach(m=>{h.has(m)||(u[m]=c[m])});const y=await v.draftStart(e,u);y&&typeof y=="object"&&Object.entries(y).forEach(([m,_])=>{h.has(m)&&n.getValues(m)!==_&&n.setValue(m,_,{shouldDirty:!1,shouldValidate:!1})})}catch(c){console.warn("Draft computation failed:",c)}finally{V.current=!1}}},300)))},[v,p,n]),N=f.useCallback((d,c)=>{const u=T[d],h=u?u.readOnly:!1,y=c==null?void 0:c.onBlur,m=async D=>{y&&await y(D);let A=!0;s==="onBlur"||s==="onTouched"||s==="all"?A=await n.trigger(d):A=!n.getFieldState(d,n.formState).error,A&&await k(d)},_=n.register(d,{...c,onBlur:m,...h?{disabled:!0}:{}});return h?{..._,disabled:!0}:_},[n,T,k,s]),H=f.useCallback((d,c)=>n.handleSubmit(async(u,h)=>{b(!0);try{const y={},m=new Set(p);Object.keys(u).forEach(_=>{!m.has(_)&&u[_]!==void 0&&(y[_]=u[_])}),await v.update(e,y),await v.draftEnd(e,y),await(d==null?void 0:d(u,h))}catch(y){c==null||c(B.toError(y),h)}finally{b(!1)}},(u,h)=>{c==null||c(u,h)}),[n,v,p]),M=f.useCallback((d,c)=>n.handleSubmit(async(u,h)=>{b(!0);try{await v.complete(e),await(d==null?void 0:d(u,h))}catch(y){c==null||c(B.toError(y),h)}finally{b(!1)}},(u,h)=>{c==null||c(u,h)}),[n,v]),q=f.useCallback(()=>{n.clearErrors()},[n]),F=!!w;return{item:E,activity:o,register:N,handleSubmit:H,handleComplete:M,watch:n.watch,setValue:n.setValue,getValues:n.getValues,reset:n.reset,trigger:n.trigger,control:n.control,errors:n.formState.errors,isValid:n.formState.isValid,isDirty:n.formState.isDirty,isSubmitting:n.formState.isSubmitting||$,isSubmitSuccessful:n.formState.isSubmitSuccessful,isLoading:i,loadError:w,hasError:F,clearErrors:q}}exports.Activity=K;exports.ActivityInstance=P;exports.Workflow=C;exports.useActivityForm=Q;
|