@ram_28/kf-ai-sdk 2.0.12 → 2.0.14

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 (69) hide show
  1. package/dist/api/client.d.ts.map +1 -1
  2. package/dist/api.cjs +1 -1
  3. package/dist/api.mjs +2 -2
  4. package/dist/attachment-constants-B5jlqoKI.cjs +1 -0
  5. package/dist/attachment-constants-C2UHWxmp.js +63 -0
  6. package/dist/auth.cjs +1 -1
  7. package/dist/auth.mjs +1 -1
  8. package/dist/bdo/core/types.d.ts +4 -0
  9. package/dist/bdo/core/types.d.ts.map +1 -1
  10. package/dist/bdo/fields/NumberField.d.ts.map +1 -1
  11. package/dist/bdo/fields/ReferenceField.d.ts +3 -2
  12. package/dist/bdo/fields/ReferenceField.d.ts.map +1 -1
  13. package/dist/bdo/fields/SelectField.d.ts +1 -1
  14. package/dist/bdo/fields/SelectField.d.ts.map +1 -1
  15. package/dist/bdo/fields/UserField.d.ts +5 -0
  16. package/dist/bdo/fields/UserField.d.ts.map +1 -1
  17. package/dist/bdo.cjs +1 -1
  18. package/dist/bdo.mjs +107 -153
  19. package/dist/client-DnO2KKrw.cjs +1 -0
  20. package/dist/{client-CMERmrC-.js → client-iQTqFDNI.js} +34 -30
  21. package/dist/components/hooks/useForm/createItemProxy.d.ts +4 -0
  22. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +1 -1
  23. package/dist/components/hooks/useForm/createResolver.d.ts.map +1 -1
  24. package/dist/components/hooks/useForm/useForm.d.ts +1 -0
  25. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  26. package/dist/form.cjs +1 -1
  27. package/dist/form.mjs +368 -203
  28. package/dist/{metadata-BfJtHz84.cjs → metadata-DgLSJkF5.cjs} +1 -1
  29. package/dist/{metadata-CwAo6a8e.js → metadata-DpfI3zRN.js} +1 -1
  30. package/dist/table.cjs +1 -1
  31. package/dist/table.mjs +1 -1
  32. package/dist/workflow/types.d.ts +3 -2
  33. package/dist/workflow/types.d.ts.map +1 -1
  34. package/dist/workflow.cjs +1 -1
  35. package/dist/workflow.d.ts +0 -2
  36. package/dist/workflow.d.ts.map +1 -1
  37. package/dist/workflow.mjs +204 -274
  38. package/dist/workflow.types.d.ts +0 -1
  39. package/dist/workflow.types.d.ts.map +1 -1
  40. package/docs/api.md +45 -253
  41. package/docs/bdo.md +130 -711
  42. package/docs/useAuth.md +42 -104
  43. package/docs/useFilter.md +117 -1591
  44. package/docs/useForm.md +266 -861
  45. package/docs/useTable.md +255 -1096
  46. package/docs/workflow.md +10 -155
  47. package/package.json +1 -1
  48. package/sdk/api/client.ts +18 -4
  49. package/sdk/bdo/core/types.ts +1 -0
  50. package/sdk/bdo/fields/NumberField.ts +2 -1
  51. package/sdk/bdo/fields/ReferenceField.ts +4 -3
  52. package/sdk/bdo/fields/SelectField.ts +2 -2
  53. package/sdk/bdo/fields/UserField.ts +14 -0
  54. package/sdk/components/hooks/useForm/createItemProxy.ts +221 -4
  55. package/sdk/components/hooks/useForm/createResolver.ts +16 -1
  56. package/sdk/components/hooks/useForm/useForm.ts +151 -50
  57. package/sdk/workflow/types.ts +3 -2
  58. package/sdk/workflow.ts +0 -7
  59. package/sdk/workflow.types.ts +0 -7
  60. package/dist/client-BnVxSHAm.cjs +0 -1
  61. package/dist/workflow/components/useActivityTable/index.d.ts +0 -4
  62. package/dist/workflow/components/useActivityTable/index.d.ts.map +0 -1
  63. package/dist/workflow/components/useActivityTable/types.d.ts +0 -53
  64. package/dist/workflow/components/useActivityTable/types.d.ts.map +0 -1
  65. package/dist/workflow/components/useActivityTable/useActivityTable.d.ts +0 -4
  66. package/dist/workflow/components/useActivityTable/useActivityTable.d.ts.map +0 -1
  67. package/sdk/workflow/components/useActivityTable/index.ts +0 -8
  68. package/sdk/workflow/components/useActivityTable/types.ts +0 -67
  69. package/sdk/workflow/components/useActivityTable/useActivityTable.ts +0 -145
@@ -88,7 +88,22 @@ export function createResolver<B extends BaseBdo<any, any, any>>(
88
88
  const field = fields[fieldName];
89
89
  if (!field) continue;
90
90
 
91
- const value = values[fieldName];
91
+ let value = values[fieldName];
92
+
93
+ // Coerce string → number for NumberField (HTML inputs always send strings)
94
+ if ("integerPart" in field && typeof value === "string" && value !== "") {
95
+ const num = Number(value);
96
+ if (!isNaN(num)) {
97
+ value = num;
98
+ values[fieldName] = num;
99
+ }
100
+ }
101
+
102
+ // Match backend BDO core: skip ALL validation for non-required empty fields
103
+ // (backend get_value(None) returns immediately without calling validate())
104
+ if (!field.required && (value == null || value === "" || (Array.isArray(value) && value.length === 0))) {
105
+ continue;
106
+ }
92
107
 
93
108
  // 1. Type validation (existing)
94
109
  const typeResult: ValidationResultType = (
@@ -1,4 +1,4 @@
1
- import { useMemo, useCallback, useEffect } from "react";
1
+ import { useMemo, useCallback, useEffect, useRef } from "react";
2
2
  import {
3
3
  useForm as useRHF,
4
4
  type FieldValues,
@@ -11,17 +11,54 @@ import { useQuery } from "@tanstack/react-query";
11
11
  import { createResolver } from "./createResolver";
12
12
  import { createItemProxy } from "./createItemProxy";
13
13
  import { getBdoSchema } from "../../../api/metadata";
14
+ import { api } from "../../../api/client";
14
15
  import type { BaseBdo } from "../../../bdo";
15
16
  import type { CreateUpdateResponseType } from "../../../types/common";
17
+ import type { BaseField } from "../../../bdo/fields/BaseField";
16
18
  import type {
17
19
  UseFormOptionsType,
18
20
  UseFormReturnType,
19
21
  HandleSubmitType,
20
22
  AllFieldsType,
21
- CreatableBdo,
22
23
  UpdatableBdo,
23
24
  } from "./types";
24
25
 
26
+ /** Coerce form value to match field's expected type (HTML inputs return strings) */
27
+ function coerceFieldValue(field: BaseField<unknown>, value: unknown): unknown {
28
+ const type = field.meta.Type;
29
+ if (typeof value === "string" && type === "Number") {
30
+ return value === "" ? undefined : Number(value);
31
+ }
32
+ // Date/DateTime: empty string → undefined (don't send to backend)
33
+ if (typeof value === "string" && value === "" && (type === "Date" || type === "DateTime")) {
34
+ return undefined;
35
+ }
36
+ // DateTime: normalize to HH:MM:SS and ensure Z suffix for API request format
37
+ if (typeof value === "string" && value !== "" && type === "DateTime") {
38
+ let normalized = value;
39
+ if (normalized.endsWith("Z")) normalized = normalized.slice(0, -1);
40
+ // HTML datetime-local may omit seconds (e.g. "2026-02-18T15:12")
41
+ const timePart = normalized.split("T")[1] || "";
42
+ if ((timePart.match(/:/g) || []).length === 1) {
43
+ normalized += ":00";
44
+ }
45
+ return normalized + "Z";
46
+ }
47
+ return value;
48
+ }
49
+
50
+ /** Strip trailing Z from DateTime response values for HTML datetime-local inputs */
51
+ function coerceRecordForForm(bdo: BaseBdo<any, any, any>, data: Record<string, unknown>): Record<string, unknown> {
52
+ const fields = bdo.getFields();
53
+ const result = { ...data };
54
+ for (const [key, value] of Object.entries(result)) {
55
+ if (typeof value === "string" && fields[key]?.meta.Type === "DateTime" && value.endsWith("Z")) {
56
+ result[key] = value.slice(0, -1);
57
+ }
58
+ }
59
+ return result;
60
+ }
61
+
25
62
  /**
26
63
  * A form hook that integrates with React Hook Form.
27
64
  *
@@ -34,6 +71,7 @@ import type {
34
71
  * - Smart register: auto-disables readonly fields
35
72
  * - Payload filtering: handleSubmit auto-filters to editable fields only
36
73
  * - Constraint validation: auto-validates required, length, etc. from field meta
74
+ * - Draft auto-save: creates draft on form open, patches on field changes
37
75
  */
38
76
  export function useForm<B extends BaseBdo<any, any, any>>(
39
77
  options: UseFormOptionsType<B>,
@@ -73,13 +111,30 @@ export function useForm<B extends BaseBdo<any, any, any>>(
73
111
  } = useQuery({
74
112
  queryKey: ["form-record", bdo.meta._id, recordId],
75
113
  queryFn: async () => {
76
- // bdo.get returns ItemWithData - extract raw data via toJSON
77
- // Safe: update operation requires UpdatableBdo (enforced by UseFormOptionsType)
78
114
  const item = await (bdo as unknown as UpdatableBdo).get(recordId!);
79
- return item.toJSON();
115
+ return coerceRecordForForm(bdo, item.toJSON() as Record<string, unknown>);
80
116
  },
81
117
  enabled: operation === "update" && !!recordId,
82
- staleTime: 0, // Always fetch fresh data for forms
118
+ staleTime: 0,
119
+ });
120
+
121
+ // ============================================================
122
+ // DRAFT CREATION (Create Mode - Interactive)
123
+ // ============================================================
124
+
125
+ const {
126
+ data: draftData,
127
+ isLoading: isCreatingDraft,
128
+ error: draftError,
129
+ } = useQuery({
130
+ queryKey: ["form-draft", bdo.meta._id],
131
+ queryFn: async () => {
132
+ return api(bdo.meta._id).draftInteraction({});
133
+ },
134
+ enabled: operation === "create",
135
+ staleTime: Infinity,
136
+ gcTime: 0,
137
+ retry: 1,
83
138
  });
84
139
 
85
140
  // ============================================================
@@ -89,8 +144,8 @@ export function useForm<B extends BaseBdo<any, any, any>>(
89
144
  const { data: schema } = useQuery({
90
145
  queryKey: ["form-schema", bdo.meta._id],
91
146
  queryFn: () => getBdoSchema(bdo.meta._id),
92
- staleTime: 30 * 60 * 1000, // Cache for 30 minutes
93
- gcTime: 60 * 60 * 1000, // Keep in cache for 1 hour
147
+ staleTime: 30 * 60 * 1000,
148
+ gcTime: 60 * 60 * 1000,
94
149
  enabled: enableExpressionValidation !== false,
95
150
  });
96
151
 
@@ -109,14 +164,31 @@ export function useForm<B extends BaseBdo<any, any, any>>(
109
164
 
110
165
  const form = useRHF<FieldValues>({
111
166
  mode,
112
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
- resolver: resolver as any, // Validation integrated here!
167
+ resolver: resolver as any,
114
168
  defaultValues: defaultValues as any,
115
- // `values` prop reactively updates form when record loads
116
- values:
117
- operation === "update" && record ? (record as FieldValues) : undefined,
169
+ // NOTE: Don't use `values` prop it continuously syncs and overrides
170
+ // setValue() calls for unregistered fields (Image/File attachments).
171
+ // Instead, we reset once when record arrives (see useEffect below).
118
172
  });
119
173
 
174
+ // Reset form whenever record data changes (edit mode)
175
+ // Track the record object reference — React Query returns a new object on each fetch,
176
+ // so this resets the form both on initial load AND when navigating between records.
177
+ const lastResetDataRef = useRef<Record<string, unknown> | null>(null);
178
+ useEffect(() => {
179
+ if (operation === "update" && record && record !== lastResetDataRef.current) {
180
+ form.reset(record as FieldValues);
181
+ lastResetDataRef.current = record;
182
+ }
183
+ }, [record, operation, form]);
184
+
185
+ // Set draft _id into form values when it arrives
186
+ useEffect(() => {
187
+ if (draftData?._id) {
188
+ form.setValue("_id" as any, draftData._id);
189
+ }
190
+ }, [draftData, form]);
191
+
120
192
  // ============================================================
121
193
  // ITEM PROXY
122
194
  // ============================================================
@@ -135,17 +207,59 @@ export function useForm<B extends BaseBdo<any, any, any>>(
135
207
  const smartRegister = useCallback(
136
208
  (name: string, registerOptions?: RegisterOptions) => {
137
209
  const rhfResult = form.register(name as any, registerOptions);
138
-
139
- // If field is readonly, add disabled: true
140
210
  if (fields[name]?.readOnly) {
141
211
  return { ...rhfResult, disabled: true };
142
212
  }
143
-
144
213
  return rhfResult;
145
214
  },
146
215
  [form, fields],
147
216
  );
148
217
 
218
+ // ============================================================
219
+ // DRAFT AUTO-SAVE (Create Mode - patch dirty fields on change)
220
+ // ============================================================
221
+
222
+ const draftPatchTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
223
+
224
+ useEffect(() => {
225
+ if (operation !== "create" || !draftData?._id) return;
226
+
227
+ const subscription = form.watch((_values, { type }) => {
228
+ if (type !== "change") return;
229
+
230
+ if (draftPatchTimeoutRef.current) {
231
+ clearTimeout(draftPatchTimeoutRef.current);
232
+ }
233
+
234
+ draftPatchTimeoutRef.current = setTimeout(async () => {
235
+ const currentValues = form.getValues();
236
+ const dirtyFields = form.formState.dirtyFields;
237
+ const dirtyData: Record<string, unknown> = {};
238
+
239
+ for (const [key, value] of Object.entries(currentValues)) {
240
+ if (fields[key] && !fields[key].readOnly && dirtyFields[key]) {
241
+ dirtyData[key] = coerceFieldValue(fields[key], value);
242
+ }
243
+ }
244
+
245
+ if (Object.keys(dirtyData).length > 0) {
246
+ try {
247
+ await api(bdo.meta._id).draftInteraction({ _id: draftData._id, ...dirtyData });
248
+ } catch {
249
+ // Draft auto-save is best-effort — don't block user interaction
250
+ }
251
+ }
252
+ }, 800);
253
+ });
254
+
255
+ return () => {
256
+ subscription.unsubscribe();
257
+ if (draftPatchTimeoutRef.current) {
258
+ clearTimeout(draftPatchTimeoutRef.current);
259
+ }
260
+ };
261
+ }, [form, operation, draftData, fields, bdo]);
262
+
149
263
  // ============================================================
150
264
  // CUSTOM HANDLE SUBMIT (with API call + payload filtering)
151
265
  // ============================================================
@@ -153,57 +267,50 @@ export function useForm<B extends BaseBdo<any, any, any>>(
153
267
  const handleSubmit: HandleSubmitType<CreateUpdateResponseType> = useCallback(
154
268
  (onSuccess, onError) => {
155
269
  return form.handleSubmit(
156
- // onValid - validation passed, make API call
157
270
  async (data, e) => {
158
271
  try {
159
272
  const filteredData: Record<string, unknown> = {};
160
273
 
274
+ // Get ALL form values at once (includes setValue values for Image/File fields)
275
+ const allValues = form.getValues() as Record<string, unknown>;
161
276
  if (operation === "create") {
162
- // Create mode - send all known, non-readonly fields
163
- for (const [key, value] of Object.entries(data)) {
164
- if (fields[key] && !fields[key].readOnly) {
165
- filteredData[key] = value;
277
+ for (const [key, field] of Object.entries(fields)) {
278
+ if (field.readOnly) continue;
279
+ // Check both allValues and RHF resolved data for the value
280
+ const value = allValues[key] !== undefined ? allValues[key] : data[key];
281
+ if (value !== undefined) {
282
+ filteredData[key] = coerceFieldValue(field, value);
166
283
  }
167
284
  }
168
285
  } else {
169
- // Update mode - send only known, non-readonly, dirty fields
170
286
  const dirtyFields = form.formState.dirtyFields;
171
- for (const [key, value] of Object.entries(data)) {
172
- if (fields[key] && !fields[key].readOnly && dirtyFields[key]) {
173
- filteredData[key] = value;
174
- }
287
+ for (const [key, field] of Object.entries(fields)) {
288
+ if (field.readOnly || !dirtyFields[key]) continue;
289
+ const value = allValues[key] !== undefined ? allValues[key] : data[key];
290
+ filteredData[key] = coerceFieldValue(field, value);
175
291
  }
176
292
  }
177
293
 
178
294
  let result: unknown;
179
295
 
180
296
  if (operation === "create") {
181
- // Safe: create operation requires CreatableBdo (enforced by UseFormOptionsType)
182
- result = await (bdo as unknown as CreatableBdo).create(
183
- filteredData,
184
- );
297
+ filteredData._id = draftData?._id;
298
+ result = await api(bdo.meta._id).draft(filteredData);
185
299
  } else {
186
- // Safe: update operation requires UpdatableBdo (enforced by UseFormOptionsType)
187
- result = await (bdo as unknown as UpdatableBdo).update(
188
- recordId!,
189
- filteredData,
190
- );
300
+ result = await api(bdo.meta._id).update(recordId!, filteredData);
191
301
  }
192
302
 
193
- // Success callback
194
303
  onSuccess?.(result as any, e);
195
304
  } catch (error) {
196
- // API error
197
305
  onError?.(error as Error, e);
198
306
  }
199
307
  },
200
- // onInvalid - validation failed
201
308
  (errors, e) => {
202
309
  onError?.(errors as FieldErrors, e);
203
310
  },
204
311
  );
205
312
  },
206
- [form, bdo, operation, recordId, fields],
313
+ [form, bdo, operation, recordId, fields, draftData],
207
314
  );
208
315
 
209
316
  // ============================================================
@@ -211,21 +318,15 @@ export function useForm<B extends BaseBdo<any, any, any>>(
211
318
  // ============================================================
212
319
 
213
320
  return {
214
- // Item - synced with form
215
321
  item,
216
322
 
217
- // BDO reference
218
323
  bdo,
219
324
  operation,
220
325
  recordId,
221
326
 
222
- // Smart register (auto-disables readonly fields)
223
327
  register: smartRegister as any,
224
-
225
- // Custom handleSubmit (handles API call + filters payload)
226
328
  handleSubmit,
227
329
 
228
- // RHF methods (spread, but handleSubmit is overridden above)
229
330
  watch: form.watch as any,
230
331
  setValue: form.setValue as any,
231
332
  getValues: form.getValues as any,
@@ -234,7 +335,6 @@ export function useForm<B extends BaseBdo<any, any, any>>(
234
335
  control: form.control as unknown as Control<AllFieldsType<B>>,
235
336
  formState: form.formState as any,
236
337
 
237
- // Flattened state for convenience
238
338
  errors: form.formState.errors as any,
239
339
  isDirty: form.formState.isDirty,
240
340
  isValid: form.formState.isValid,
@@ -242,11 +342,12 @@ export function useForm<B extends BaseBdo<any, any, any>>(
242
342
  isSubmitSuccessful: form.formState.isSubmitSuccessful,
243
343
  dirtyFields: form.formState.dirtyFields as any,
244
344
 
245
- // Loading states
246
- isLoading: isLoadingRecord,
345
+ isLoading: isLoadingRecord || isCreatingDraft,
247
346
  isFetching: isFetchingRecord,
248
347
 
249
- // Error
250
- loadError: recordError as Error | null,
348
+ loadError: (recordError ?? draftError) as Error | null,
349
+
350
+ draftId: draftData?._id,
351
+ isCreatingDraft,
251
352
  };
252
353
  }
@@ -13,8 +13,9 @@ import type {
13
13
  StringFieldType,
14
14
  SelectFieldType,
15
15
  DateTimeFieldType,
16
- UserFieldType,
16
+ ReferenceFieldType,
17
17
  } from "../types/base-fields";
18
+ import type { UserRefType } from "../types/base-fields";
18
19
 
19
20
  /**
20
21
  * Response from Workflow.start()
@@ -48,7 +49,7 @@ export interface ActivityProgressType {
48
49
  export type ActivityInstanceFieldsType = {
49
50
  _id: StringFieldType;
50
51
  Status: SelectFieldType<"InProgress" | "Completed">;
51
- AssignedTo: UserFieldType;
52
+ AssignedTo: ReferenceFieldType<UserRefType>;
52
53
  CompletedAt: DateTimeFieldType;
53
54
  };
54
55
 
package/sdk/workflow.ts CHANGED
@@ -23,10 +23,3 @@ export type {
23
23
  UseActivityFormOptions,
24
24
  UseActivityFormReturn,
25
25
  } from './workflow/components/useActivityForm';
26
-
27
- export { useActivityTable, ActivityTableStatus } from './workflow/components/useActivityTable';
28
- export type {
29
- UseActivityTableOptionsType,
30
- UseActivityTableReturnType,
31
- ActivityRowType,
32
- } from './workflow/components/useActivityTable';
@@ -9,10 +9,3 @@ export type {
9
9
  ActivityProgressType,
10
10
  WorkflowStartResponseType,
11
11
  } from './workflow/types';
12
-
13
- export type {
14
- UseActivityTableOptionsType,
15
- UseActivityTableReturnType,
16
- ActivityTableStatusType,
17
- ActivityRowType,
18
- } from './workflow/components/useActivityTable/types';
@@ -1 +0,0 @@
1
- "use strict";let c={baseUrl:"",headers:{"Content-Type":"application/json"}};function f(o){c.baseUrl=o}function u(o){c.headers={...c.headers,...o}}function s(){return{...c.headers}}function l(){return c.baseUrl||""}function w(o){const n=c.baseUrl;return{async get(r){const t=await fetch(`${n}${o}/${r}/read`,{method:"GET",headers:s()});if(!t.ok)throw new Error(`Failed to get ${o} ${r}: ${t.statusText}`);return(await t.json()).Data},async create(r){const t=await fetch(`${n}${o}/create`,{method:"POST",headers:s(),body:JSON.stringify(r)});if(!t.ok)throw new Error(`Failed to create ${o}: ${t.statusText}`);return t.json()},async update(r,t){const e=await fetch(`${n}${o}/${r}/update`,{method:"POST",headers:s(),body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to update ${o} ${r}: ${e.statusText}`);return e.json()},async delete(r){const t=await fetch(`${n}${o}/${r}/delete`,{method:"DELETE",headers:s()});if(!t.ok)throw new Error(`Failed to delete ${o} ${r}: ${t.statusText}`);return t.json()},async list(r){const t={Type:"List",...r},e=await fetch(`${n}${o}/list`,{method:"POST",headers:s(),body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to list ${o}: ${e.statusText}`);return await e.json()},async count(r){var d,$;const t={Type:"Metric",GroupBy:[],Metric:[{Field:"_id",Type:"Count"}],...(r==null?void 0:r.Filter)&&{Filter:r.Filter}},e=await fetch(`${n}${o}/metric`,{method:"POST",headers:s(),body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to count ${o}: ${e.statusText}`);return{Count:(($=(d=(await e.json()).Data)==null?void 0:d[0])==null?void 0:$.count__id)??0}},async draft(r){const t=await fetch(`${n}${o}/draft`,{method:"POST",headers:s(),body:JSON.stringify(r)});if(!t.ok)throw new Error(`Failed to create draft for ${o}: ${t.statusText}`);return t.json()},async draftUpdate(r,t){const e=await fetch(`${n}${o}/${r}/draft`,{method:"POST",headers:s(),body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to update draft for ${o} ${r}: ${e.statusText}`);return e.json()},async draftPatch(r,t){const e=await fetch(`${n}${o}/${r}/draft`,{method:"PATCH",headers:s(),body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to patch draft for ${o} ${r}: ${e.statusText}`);return e.json()},async draftInteraction(r){const t=await fetch(`${n}${o}/draft`,{method:"PATCH",headers:s(),body:JSON.stringify(r)});if(!t.ok)throw new Error(`Failed to create interactive draft for ${o}: ${t.statusText}`);const e=await t.json();return{...e.Data,_id:e.Data._id}},async metric(r){const t={Type:"Metric",...r},e=await fetch(`${n}${o}/metric`,{method:"POST",headers:s(),body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to get metrics for ${o}: ${e.statusText}`);return e.json()},async pivot(r){const t={Type:"Pivot",...r},e=await fetch(`${n}${o}/pivot`,{method:"POST",headers:s(),body:JSON.stringify(t)});if(!e.ok)throw new Error(`Failed to get pivot data for ${o}: ${e.statusText}`);return e.json()},async fields(){const r=await fetch(`${n}${o}/fields`,{method:"GET",headers:s()});if(!r.ok)throw new Error(`Failed to get fields for ${o}: ${r.statusText}`);return r.json()},async fetchField(r,t){const e=await fetch(`${n}${o}/${r}/field/${t}/fetch`,{method:"GET",headers:s()});if(!e.ok)throw new Error(`Failed to fetch field ${t} for ${o}: ${e.statusText}`);return(await e.json()).Data},async getUploadUrl(r,t,e){const a=await fetch(`${n}${o}/${r}/field/${t}/attachment/upload`,{method:"POST",headers:s(),body:JSON.stringify(e)});if(!a.ok)throw new Error(`Failed to get upload URL for ${o}/${t}: ${a.statusText}`);return(await a.json()).Data},async getDownloadUrl(r,t,e,a){let i=`${n}${o}/${r}/field/${t}/attachment/${e}/read`;a&&(i+=`?view_type=${a}`);const d=await fetch(i,{method:"GET",headers:s()});if(!d.ok)throw new Error(`Failed to get download URL for ${o}/${t}/${e}: ${d.statusText}`);return(await d.json()).Data},async getDownloadUrls(r,t,e){let a=`${n}${o}/${r}/field/${t}/attachment/read`;e&&(a+=`?view_type=${e}`);const i=await fetch(a,{method:"GET",headers:s()});if(!i.ok)throw new Error(`Failed to get download URLs for ${o}/${t}: ${i.statusText}`);return(await i.json()).Data},async deleteAttachment(r,t,e){const a=await fetch(`${n}${o}/${r}/field/${t}/attachment/${e}/delete`,{method:"DELETE",headers:s()});if(!a.ok)throw new Error(`Failed to delete attachment ${e} for ${o}/${t}: ${a.statusText}`)}}}function p(o){return w(`/api/app/${o}`)}exports.api=p;exports.getApiBaseUrl=l;exports.getDefaultHeaders=s;exports.setApiBaseUrl=f;exports.setDefaultHeaders=u;
@@ -1,4 +0,0 @@
1
- export { useActivityTable } from './useActivityTable';
2
- export { ActivityTableStatus } from './types';
3
- export type { UseActivityTableOptionsType, UseActivityTableReturnType, ActivityTableStatusType, ActivityRowType, } from './types';
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityTable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAC9C,YAAY,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,uBAAuB,EACvB,eAAe,GAChB,MAAM,SAAS,CAAC"}
@@ -1,53 +0,0 @@
1
- import type { Activity } from '../../Activity';
2
- import type { ActivityInstanceFieldsType } from '../../types';
3
- import type { ExtractActivityEntity } from '../useActivityForm/types';
4
- import type { ListResponseType } from '../../../types/common';
5
- /**
6
- * Activity table status — determines which API to call
7
- */
8
- export declare const ActivityTableStatus: {
9
- readonly InProgress: "inprogress";
10
- readonly Completed: "completed";
11
- };
12
- export type ActivityTableStatusType = (typeof ActivityTableStatus)[keyof typeof ActivityTableStatus];
13
- /**
14
- * Row type for activity table data.
15
- * Combines activity instance system fields with entity-specific fields.
16
- *
17
- * For a ManagerApprovalActivity with { ManagerApproved, ManagerReason }:
18
- * ActivityRowType resolves to:
19
- * {
20
- * // System fields (ActivityInstanceFieldsType)
21
- * _id: string;
22
- * Status: "InProgress" | "Completed";
23
- * AssignedTo: UserRefType;
24
- * CompletedAt: string;
25
- * // Entity fields
26
- * ManagerApproved: boolean;
27
- * ManagerReason: string;
28
- * }
29
- */
30
- export type ActivityRowType<A extends Activity<any, any, any>> = ActivityInstanceFieldsType & ExtractActivityEntity<A>;
31
- export interface UseActivityTableOptionsType<A extends Activity<any, any, any>> {
32
- /** Which activity instances to fetch */
33
- status: ActivityTableStatusType;
34
- /** Error callback */
35
- onError?: (error: Error) => void;
36
- /** Success callback with row data */
37
- onSuccess?: (data: ActivityRowType<A>[]) => void;
38
- }
39
- export interface UseActivityTableReturnType<A extends Activity<any, any, any>> {
40
- /** Activity instance records (system fields + entity fields) */
41
- rows: ActivityRowType<A>[];
42
- /** Total count from metrics endpoint */
43
- totalItems: number;
44
- /** Initial load in progress */
45
- isLoading: boolean;
46
- /** Any fetch in progress (including refetch) */
47
- isFetching: boolean;
48
- /** Fetch error */
49
- error: Error | null;
50
- /** Refetch both list and metrics */
51
- refetch: () => Promise<ListResponseType<ActivityRowType<A>>>;
52
- }
53
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityTable/types.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;CAGtB,CAAC;AAEX,MAAM,MAAM,uBAAuB,GACjC,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAEjE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAC3D,0BAA0B,GAAG,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAExD,MAAM,WAAW,2BAA2B,CAC1C,CAAC,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAEjC,wCAAwC;IACxC,MAAM,EAAE,uBAAuB,CAAC;IAChC,qBAAqB;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,qCAAqC;IACrC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,0BAA0B,CACzC,CAAC,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAEjC,gEAAgE;IAChE,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;IAC3B,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,UAAU,EAAE,OAAO,CAAC;IACpB,kBAAkB;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IACpB,oCAAoC;IACpC,OAAO,EAAE,MAAM,OAAO,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9D"}
@@ -1,4 +0,0 @@
1
- import type { Activity } from '../../Activity';
2
- import { type UseActivityTableOptionsType, type UseActivityTableReturnType } from './types';
3
- export declare function useActivityTable<A extends Activity<any, any, any>>(activity: A, options: UseActivityTableOptionsType<A>): UseActivityTableReturnType<A>;
4
- //# sourceMappingURL=useActivityTable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useActivityTable.d.ts","sourceRoot":"","sources":["../../../../sdk/workflow/components/useActivityTable/useActivityTable.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,0BAA0B,EAEhC,MAAM,SAAS,CAAC;AAMjB,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAChE,QAAQ,EAAE,CAAC,EACX,OAAO,EAAE,2BAA2B,CAAC,CAAC,CAAC,GACtC,0BAA0B,CAAC,CAAC,CAAC,CAoH/B"}
@@ -1,8 +0,0 @@
1
- export { useActivityTable } from './useActivityTable';
2
- export { ActivityTableStatus } from './types';
3
- export type {
4
- UseActivityTableOptionsType,
5
- UseActivityTableReturnType,
6
- ActivityTableStatusType,
7
- ActivityRowType,
8
- } from './types';
@@ -1,67 +0,0 @@
1
- // ============================================================
2
- // TYPE DEFINITIONS FOR useActivityTable HOOK
3
- // ============================================================
4
-
5
- import type { Activity } from '../../Activity';
6
- import type { ActivityInstanceFieldsType } from '../../types';
7
- import type { ExtractActivityEntity } from '../useActivityForm/types';
8
- import type { ListResponseType } from '../../../types/common';
9
-
10
- /**
11
- * Activity table status — determines which API to call
12
- */
13
- export const ActivityTableStatus = {
14
- InProgress: 'inprogress',
15
- Completed: 'completed',
16
- } as const;
17
-
18
- export type ActivityTableStatusType =
19
- (typeof ActivityTableStatus)[keyof typeof ActivityTableStatus];
20
-
21
- /**
22
- * Row type for activity table data.
23
- * Combines activity instance system fields with entity-specific fields.
24
- *
25
- * For a ManagerApprovalActivity with { ManagerApproved, ManagerReason }:
26
- * ActivityRowType resolves to:
27
- * {
28
- * // System fields (ActivityInstanceFieldsType)
29
- * _id: string;
30
- * Status: "InProgress" | "Completed";
31
- * AssignedTo: UserRefType;
32
- * CompletedAt: string;
33
- * // Entity fields
34
- * ManagerApproved: boolean;
35
- * ManagerReason: string;
36
- * }
37
- */
38
- export type ActivityRowType<A extends Activity<any, any, any>> =
39
- ActivityInstanceFieldsType & ExtractActivityEntity<A>;
40
-
41
- export interface UseActivityTableOptionsType<
42
- A extends Activity<any, any, any>,
43
- > {
44
- /** Which activity instances to fetch */
45
- status: ActivityTableStatusType;
46
- /** Error callback */
47
- onError?: (error: Error) => void;
48
- /** Success callback with row data */
49
- onSuccess?: (data: ActivityRowType<A>[]) => void;
50
- }
51
-
52
- export interface UseActivityTableReturnType<
53
- A extends Activity<any, any, any>,
54
- > {
55
- /** Activity instance records (system fields + entity fields) */
56
- rows: ActivityRowType<A>[];
57
- /** Total count from metrics endpoint */
58
- totalItems: number;
59
- /** Initial load in progress */
60
- isLoading: boolean;
61
- /** Any fetch in progress (including refetch) */
62
- isFetching: boolean;
63
- /** Fetch error */
64
- error: Error | null;
65
- /** Refetch both list and metrics */
66
- refetch: () => Promise<ListResponseType<ActivityRowType<A>>>;
67
- }