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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/README.md +8 -16
  2. package/dist/{FileField-CZjS2uLh.js → FileField-BWrSHNRq.js} +3 -3
  3. package/dist/{FileField-DU4UWo_t.cjs → FileField-eDeuzln8.cjs} +1 -1
  4. package/dist/api.cjs +1 -1
  5. package/dist/api.mjs +1 -1
  6. package/dist/auth/authClient.d.ts.map +1 -1
  7. package/dist/auth/authConfig.d.ts +1 -1
  8. package/dist/auth/types.d.ts +1 -1
  9. package/dist/auth/types.d.ts.map +1 -1
  10. package/dist/auth.cjs +1 -1
  11. package/dist/auth.mjs +102 -106
  12. package/dist/bdo/core/Item.d.ts +4 -0
  13. package/dist/bdo/core/Item.d.ts.map +1 -1
  14. package/dist/bdo/fields/ReferenceField.d.ts +1 -1
  15. package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
  16. package/dist/bdo/fields/SelectField.d.ts +1 -1
  17. package/dist/bdo/fields/SelectField.d.ts.map +1 -1
  18. package/dist/bdo/fields/UserField.d.ts +1 -1
  19. package/dist/bdo/fields/UserField.d.ts.map +1 -1
  20. package/dist/bdo.cjs +1 -1
  21. package/dist/bdo.mjs +62 -53
  22. package/dist/components/hooks/useActivityForm/types.d.ts +5 -4
  23. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  24. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  25. package/dist/components/hooks/useActivityTable/types.d.ts +4 -5
  26. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  27. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  28. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts +3 -2
  29. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -1
  30. package/dist/components/hooks/useBDOTable/types.d.ts +12 -20
  31. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  32. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts +2 -2
  33. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  34. package/dist/{constants-Cyi942Yr.js → constants-ConHc1oS.js} +5 -5
  35. package/dist/constants-QX2RX-wu.cjs +1 -0
  36. package/dist/filter.cjs +1 -1
  37. package/dist/filter.mjs +1 -1
  38. package/dist/form.cjs +1 -1
  39. package/dist/form.mjs +243 -226
  40. package/dist/table.cjs +1 -1
  41. package/dist/table.mjs +16 -15
  42. package/dist/table.types.d.ts +1 -1
  43. package/dist/table.types.d.ts.map +1 -1
  44. package/dist/types/constants.d.ts +1 -1
  45. package/dist/workflow/Activity.d.ts +5 -8
  46. package/dist/workflow/Activity.d.ts.map +1 -1
  47. package/dist/workflow.cjs +1 -1
  48. package/dist/workflow.mjs +476 -461
  49. package/docs/api.md +95 -0
  50. package/docs/bdo.md +224 -0
  51. package/docs/gaps.md +360 -0
  52. package/docs/useActivityForm.md +393 -0
  53. package/docs/useActivityTable.md +418 -0
  54. package/docs/useBDOForm.md +498 -0
  55. package/docs/useBDOTable.md +284 -0
  56. package/docs/useFilter.md +188 -0
  57. package/docs/workflow.md +560 -0
  58. package/package.json +14 -15
  59. package/sdk/auth/authClient.ts +15 -21
  60. package/sdk/auth/authConfig.ts +1 -1
  61. package/sdk/auth/types.ts +1 -1
  62. package/sdk/bdo/core/Item.ts +10 -1
  63. package/sdk/bdo/fields/ReferenceField.ts +1 -1
  64. package/sdk/bdo/fields/SelectField.ts +1 -1
  65. package/sdk/bdo/fields/UserField.ts +1 -1
  66. package/sdk/components/hooks/useActivityForm/types.ts +6 -4
  67. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +73 -10
  68. package/sdk/components/hooks/useActivityTable/types.ts +5 -4
  69. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +8 -10
  70. package/sdk/components/hooks/useBDOForm/createItemProxy.ts +58 -17
  71. package/sdk/components/hooks/useBDOTable/types.ts +10 -20
  72. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +8 -12
  73. package/sdk/table.types.ts +0 -2
  74. package/sdk/types/constants.ts +1 -1
  75. package/sdk/workflow/Activity.ts +7 -39
  76. package/dist/constants-DEmYwKfC.cjs +0 -1
  77. package/docs/README.md +0 -57
  78. package/docs/bdo/README.md +0 -161
  79. package/docs/bdo/api_reference.md +0 -281
  80. package/docs/examples/bdo/create-product.md +0 -69
  81. package/docs/examples/bdo/edit-product-dialog.md +0 -95
  82. package/docs/examples/bdo/filtered-product-table.md +0 -100
  83. package/docs/examples/bdo/product-listing.md +0 -73
  84. package/docs/examples/bdo/supplier-dropdown.md +0 -60
  85. package/docs/examples/fields/complex-fields.md +0 -248
  86. package/docs/examples/fields/primitive-fields.md +0 -217
  87. package/docs/examples/workflow/approve-leave-request.md +0 -76
  88. package/docs/examples/workflow/filtered-activity-table.md +0 -101
  89. package/docs/examples/workflow/my-pending-requests.md +0 -90
  90. package/docs/examples/workflow/start-new-workflow.md +0 -47
  91. package/docs/examples/workflow/submit-leave-request.md +0 -72
  92. package/docs/examples/workflow/workflow-progress.md +0 -49
  93. package/docs/fields/README.md +0 -141
  94. package/docs/fields/api_reference.md +0 -134
  95. package/docs/useActivityForm/README.md +0 -244
  96. package/docs/useActivityForm/api_reference.md +0 -279
  97. package/docs/useActivityTable/README.md +0 -263
  98. package/docs/useActivityTable/api_reference.md +0 -294
  99. package/docs/useBDOForm/README.md +0 -175
  100. package/docs/useBDOForm/api_reference.md +0 -244
  101. package/docs/useBDOTable/README.md +0 -242
  102. package/docs/useBDOTable/api_reference.md +0 -253
  103. package/docs/useFilter/README.md +0 -323
  104. package/docs/useFilter/api_reference.md +0 -228
  105. package/docs/workflow/README.md +0 -158
  106. package/docs/workflow/api_reference.md +0 -161
  107. /package/docs/{useAuth/README.md → useAuth.md} +0 -0
@@ -305,7 +305,7 @@ export declare const AuthStatus: {
305
305
  */
306
306
  export declare const AuthProviderName: {
307
307
  readonly Google: "google";
308
- readonly Azure: "azure";
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
- * Each row is wrapped in an ActivityInstance proxy with field accessors.
62
+ * Accepts optional filter/sort/pagination options.
65
63
  */
66
- getInProgressList(options?: ListOptionsType): Promise<ActivityInstanceType<ActivityInstanceFieldsType & TEntity, TEditable, TReadonly & ActivitySystemReadonlyType>[]>;
64
+ getInProgressList(options?: ListOptionsType): Promise<ListResponseType<ActivityInstanceFieldsType & TEntity>>;
67
65
  /**
68
66
  * List completed activity instances.
69
- * Each row is wrapped in an ActivityInstance proxy with field accessors.
67
+ * Accepts optional filter/sort/pagination options.
70
68
  */
71
- getCompletedList(options?: ListOptionsType): Promise<ActivityInstanceType<ActivityInstanceFieldsType & TEntity, TEditable, TReadonly & ActivitySystemReadonlyType>[]>;
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;AAEpD,iEAAiE;AACjE,KAAK,0BAA0B,GAAG,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AAM1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CACrB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,oBAAoB,CAC7B,0BAA0B,GAAG,OAAO,EACpC,SAAS,EACT,SAAS,GAAG,0BAA0B,CACvC,EAAE,CAAC;IAaJ;;;OAGG;IACG,gBAAgB,CACpB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,oBAAoB,CAC7B,0BAA0B,GAAG,OAAO,EACpC,SAAS,EACT,SAAS,GAAG,0BAA0B,CACvC,EAAE,CAAC;IAaJ;;;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"}
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-eDeuzln8.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;