@ram_28/kf-ai-sdk 1.0.20 → 1.0.22

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 (53) hide show
  1. package/dist/api/client.d.ts.map +1 -1
  2. package/dist/api/datetime.d.ts +59 -10
  3. package/dist/api/datetime.d.ts.map +1 -1
  4. package/dist/api/index.d.ts +3 -2
  5. package/dist/api/index.d.ts.map +1 -1
  6. package/dist/api.cjs +1 -1
  7. package/dist/api.d.ts +1 -1
  8. package/dist/api.d.ts.map +1 -1
  9. package/dist/api.mjs +43 -21
  10. package/dist/api.types.d.ts +2 -1
  11. package/dist/api.types.d.ts.map +1 -1
  12. package/dist/auth/AuthProvider.d.ts.map +1 -1
  13. package/dist/auth.cjs +1 -1
  14. package/dist/auth.mjs +34 -34
  15. package/dist/base-types.d.ts +1 -1
  16. package/dist/base-types.d.ts.map +1 -1
  17. package/dist/client-BIkaIr2y.js +217 -0
  18. package/dist/client-DxjRcEtN.cjs +1 -0
  19. package/dist/components/hooks/useForm/apiClient.d.ts +45 -4
  20. package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
  21. package/dist/components/hooks/useForm/types.d.ts +8 -0
  22. package/dist/components/hooks/useForm/types.d.ts.map +1 -1
  23. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  24. package/dist/form.cjs +1 -1
  25. package/dist/form.mjs +1028 -1051
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/kanban.cjs +1 -1
  29. package/dist/kanban.mjs +1 -1
  30. package/dist/{metadata-0lZAfuTP.cjs → metadata-Bz8zJqC1.cjs} +1 -1
  31. package/dist/{metadata-B88D_pVS.js → metadata-VbQzyD2C.js} +1 -1
  32. package/dist/table.cjs +1 -1
  33. package/dist/table.mjs +1 -1
  34. package/dist/types/base-fields.d.ts +71 -17
  35. package/dist/types/base-fields.d.ts.map +1 -1
  36. package/dist/types/common.d.ts +0 -12
  37. package/dist/types/common.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/sdk/api/client.ts +3 -41
  40. package/sdk/api/datetime.ts +98 -14
  41. package/sdk/api/index.ts +12 -6
  42. package/sdk/api.ts +6 -3
  43. package/sdk/api.types.ts +3 -4
  44. package/sdk/auth/AuthProvider.tsx +22 -24
  45. package/sdk/base-types.ts +2 -0
  46. package/sdk/components/hooks/useForm/apiClient.ts +118 -4
  47. package/sdk/components/hooks/useForm/types.ts +9 -0
  48. package/sdk/components/hooks/useForm/useForm.ts +79 -60
  49. package/sdk/index.ts +3 -0
  50. package/sdk/types/base-fields.ts +71 -17
  51. package/sdk/types/common.ts +2 -13
  52. package/dist/client-DgtkT50N.cjs +0 -1
  53. package/dist/client-V-WzUb8H.js +0 -237
@@ -67,27 +67,47 @@ export type LongFieldType = number;
67
67
  */
68
68
  export type BooleanFieldType = boolean;
69
69
 
70
+ /**
71
+ * Encoded date format from API response
72
+ * API returns: { "$__d__": "YYYY-MM-DD" }
73
+ */
74
+ export interface DateEncodedType {
75
+ $__d__: string;
76
+ }
77
+
78
+ /**
79
+ * Encoded datetime format from API response
80
+ * API returns: { "$__dt__": unix_timestamp_seconds }
81
+ */
82
+ export interface DateTimeEncodedType {
83
+ $__dt__: number;
84
+ }
85
+
70
86
  /**
71
87
  * Date field (date only, no time)
72
- * Resolves to: Date
88
+ * API Response Format: { "$__d__": "YYYY-MM-DD" }
89
+ * API Request Format: "YYYY-MM-DD"
73
90
  * Storage: DATE in database
74
91
  * Use this for birth dates, due dates, calendar events
75
92
  *
76
93
  * @example
77
- * DateFieldType // => Date (date only)
94
+ * // Response from API:
95
+ * { "$__d__": "2025-03-15" }
78
96
  */
79
- export type DateFieldType = Date;
97
+ export type DateFieldType = DateEncodedType;
80
98
 
81
99
  /**
82
100
  * DateTime field (date and time)
83
- * Resolves to: Date
101
+ * API Response Format: { "$__dt__": unix_timestamp_seconds }
102
+ * API Request Format: "YYYY-MM-DD HH:MM:SS"
84
103
  * Storage: DATETIME/TIMESTAMP in database
85
104
  * Use this for created_at, updated_at, event timestamps
86
105
  *
87
106
  * @example
88
- * DateTimeFieldType // => Date (with time)
107
+ * // Response from API:
108
+ * { "$__dt__": 1769110463 }
89
109
  */
90
- export type DateTimeFieldType = Date;
110
+ export type DateTimeFieldType = DateTimeEncodedType;
91
111
 
92
112
  // ============================================================
93
113
  // COMPLEX FIELD TYPES
@@ -124,7 +144,47 @@ export type CurrencyValueType =
124
144
  */
125
145
  export type JSONFieldType<T = JSONValueType> = T;
126
146
 
127
- export type ReferenceFieldType = string;
147
+ /**
148
+ * Reference/Lookup field for relationships to other Business Data Objects
149
+ *
150
+ * @template TReferencedType - The full type of the referenced BDO record
151
+ *
152
+ * Runtime behavior:
153
+ * - The field stores the full referenced record (e.g., full supplier object)
154
+ * - API returns the complete record from the referenced BDO
155
+ * - On save, the full object is sent in the payload
156
+ *
157
+ * @example
158
+ * SupplierInfo: ReferenceFieldType<BaseSupplierType>;
159
+ * // At runtime: { _id: "...", SupplierId: "...", SupplierName: "...", ... }
160
+ */
161
+ export type ReferenceFieldType<TReferencedType = unknown> = TReferencedType;
162
+
163
+ /**
164
+ * Extract the referenced type from a ReferenceFieldType
165
+ * Note: Since ReferenceFieldType<T> = T, this just returns T if it has _id
166
+ */
167
+ export type ExtractReferenceType<T> = T extends { _id: string } ? T : never;
168
+
169
+ /**
170
+ * Extract the type that fetchField should return for a given field type
171
+ * - For Reference fields (objects with _id) → the full referenced record type
172
+ * - For other field types → { Value: string; Label: string } (static dropdown)
173
+ *
174
+ * Detection: All BDO types have _id: string, so we check for that property
175
+ * to distinguish reference fields from primitive fields like StringFieldType.
176
+ *
177
+ * @example
178
+ * type SupplierOptions = ExtractFetchFieldType<BaseProductType["SupplierInfo"]>;
179
+ * // Result: BaseSupplierType (has _id)
180
+ *
181
+ * type CategoryOptions = ExtractFetchFieldType<BaseProductType["Category"]>;
182
+ * // Result: { Value: string; Label: string } (string has no _id)
183
+ */
184
+ export type ExtractFetchFieldType<T> =
185
+ T extends { _id: string }
186
+ ? T
187
+ : { Value: string; Label: string };
128
188
 
129
189
  /**
130
190
  * Valid JSON value types
@@ -156,17 +216,11 @@ export interface JSONArrayType extends Array<JSONValueType> {}
156
216
  export type SelectFieldType<T extends string> = T;
157
217
 
158
218
  /**
159
- * Lookup field for references to other records
160
- * @template T - Type of the referenced record ID (defaults to string)
161
- * Resolves to: T
162
- * Storage: VARCHAR in database (stores the ID)
163
- * Use this for foreign keys, relationships, references
164
- *
165
- * @example
166
- * LookupFieldType // => string (referenced record ID)
167
- * LookupFieldType<IdFieldType> // => string (typed as IdFieldType)
219
+ * Alias for ReferenceFieldType (Lookup = Reference in the backend)
220
+ * @template TReferencedType - The full type of the referenced BDO record
221
+ * @deprecated Use ReferenceFieldType instead
168
222
  */
169
- export type LookupFieldType<T extends string = string> = T;
223
+ export type LookupFieldType<TReferencedType = unknown> = ReferenceFieldType<TReferencedType>;
170
224
 
171
225
  // ============================================================
172
226
  // CONTAINER AND UTILITY TYPES
@@ -71,19 +71,8 @@ export interface ConditionGroupType<T = any> {
71
71
  */
72
72
  export type FilterType<T = any> = ConditionGroupType<T>;
73
73
 
74
- /**
75
- * DateTime encoding format used by the API
76
- */
77
- export interface DateTimeEncodedType {
78
- $__dt__: number;
79
- }
80
-
81
- /**
82
- * Date encoding format used by the API
83
- */
84
- export interface DateEncodedType {
85
- $__d__: string;
86
- }
74
+ // Note: DateTimeEncodedType and DateEncodedType are now defined in base-fields.ts
75
+ // They are re-exported from api/index.ts for convenience
87
76
 
88
77
  /**
89
78
  * Standard paginated list response
@@ -1 +0,0 @@
1
- "use strict";let o={baseUrl:"",headers:{"Content-Type":"application/json"}};function u(e){o.baseUrl=e}function h(e){o.headers={...o.headers,...e}}function d(){return{...o.headers}}function l(){return o.baseUrl||""}function i(e){if(e==null)return e;if(Array.isArray(e))return e.map(s=>i(s));if(typeof e=="object"){if("$__dt__"in e)return new Date(e.$__dt__*1e3);if("$__d__"in e)return new Date(e.$__d__);const s={};for(const[n,t]of Object.entries(e))s[n]=i(t);return s}return e}function w(e){const s=o.baseUrl,n=o.headers;return{async get(t){const r=await fetch(`${s}/api/app/${e}/${t}/read`,{method:"GET",headers:n});if(!r.ok)throw new Error(`Failed to get ${e} ${t}: ${r.statusText}`);const a=await r.json();return i(a.Data)},async create(t){const r=await fetch(`${s}/api/app/${e}/create`,{method:"POST",headers:n,body:JSON.stringify(t)});if(!r.ok)throw new Error(`Failed to create ${e}: ${r.statusText}`);return r.json()},async update(t,r){const a=await fetch(`${s}/api/app/${e}/${t}/update`,{method:"POST",headers:n,body:JSON.stringify(r)});if(!a.ok)throw new Error(`Failed to update ${e} ${t}: ${a.statusText}`);return a.json()},async delete(t){const r=await fetch(`${s}/api/app/${e}/${t}/delete`,{method:"DELETE",headers:n});if(!r.ok)throw new Error(`Failed to delete ${e} ${t}: ${r.statusText}`);return r.json()},async list(t){const r={Type:"List",...t},a=await fetch(`${s}/api/app/${e}/list`,{method:"POST",headers:n,body:JSON.stringify(r)});if(!a.ok)throw new Error(`Failed to list ${e}: ${a.statusText}`);return{Data:(await a.json()).Data.map(f=>i(f))}},async count(t){var p,$;const r={Type:"Metric",GroupBy:[],Metric:[{Field:"_id",Type:"Count"}],...(t==null?void 0:t.Filter)&&{Filter:t.Filter}},a=await fetch(`${s}/api/app/${e}/metric`,{method:"POST",headers:n,body:JSON.stringify(r)});if(!a.ok)throw new Error(`Failed to count ${e}: ${a.statusText}`);return{Count:(($=(p=(await a.json()).Data)==null?void 0:p[0])==null?void 0:$.count__id)??0}},async draft(t){const r=await fetch(`${s}/api/app/${e}/draft`,{method:"POST",headers:n,body:JSON.stringify(t)});if(!r.ok)throw new Error(`Failed to create draft for ${e}: ${r.statusText}`);return r.json()},async draftUpdate(t,r){const a=await fetch(`${s}/api/app/${e}/${t}/draft`,{method:"POST",headers:n,body:JSON.stringify(r)});if(!a.ok)throw new Error(`Failed to update draft for ${e} ${t}: ${a.statusText}`);return a.json()},async draftPatch(t,r){const a=await fetch(`${s}/api/app/${e}/${t}/draft`,{method:"PATCH",headers:n,body:JSON.stringify(r)});if(!a.ok)throw new Error(`Failed to patch draft for ${e} ${t}: ${a.statusText}`);return a.json()},async draftInteraction(t){const r=await fetch(`${s}/api/app/${e}/draft`,{method:"PATCH",headers:n,body:JSON.stringify(t)});if(!r.ok)throw new Error(`Failed to create interactive draft for ${e}: ${r.statusText}`);const a=await r.json();return{...a.Data,_id:a.Data._id}},async metric(t){const r={Type:"Metric",...t},a=await fetch(`${s}/api/app/${e}/metric`,{method:"POST",headers:n,body:JSON.stringify(r)});if(!a.ok)throw new Error(`Failed to get metrics for ${e}: ${a.statusText}`);return a.json()},async pivot(t){const r={Type:"Pivot",...t},a=await fetch(`${s}/api/app/${e}/pivot`,{method:"POST",headers:n,body:JSON.stringify(r)});if(!a.ok)throw new Error(`Failed to get pivot data for ${e}: ${a.statusText}`);return a.json()},async fields(){const t=await fetch(`${s}/api/app/${e}/fields`,{method:"GET",headers:n});if(!t.ok)throw new Error(`Failed to get fields for ${e}: ${t.statusText}`);return t.json()},async fetchField(t,r){const a=await fetch(`${s}/api/app/${e}/${t}/field/${r}/fetch`,{method:"GET",headers:n});if(!a.ok)throw new Error(`Failed to fetch field ${r} for ${e}: ${a.statusText}`);return(await a.json()).Data}}}exports.api=w;exports.getApiBaseUrl=l;exports.getDefaultHeaders=d;exports.setApiBaseUrl=u;exports.setDefaultHeaders=h;
@@ -1,237 +0,0 @@
1
- let o = {
2
- baseUrl: "",
3
- headers: {
4
- "Content-Type": "application/json"
5
- }
6
- };
7
- function u(e) {
8
- o.baseUrl = e;
9
- }
10
- function h(e) {
11
- o.headers = { ...o.headers, ...e };
12
- }
13
- function d() {
14
- return { ...o.headers };
15
- }
16
- function w() {
17
- return o.baseUrl || "";
18
- }
19
- function i(e) {
20
- if (e == null)
21
- return e;
22
- if (Array.isArray(e))
23
- return e.map((s) => i(s));
24
- if (typeof e == "object") {
25
- if ("$__dt__" in e)
26
- return new Date(e.$__dt__ * 1e3);
27
- if ("$__d__" in e)
28
- return new Date(e.$__d__);
29
- const s = {};
30
- for (const [n, t] of Object.entries(e))
31
- s[n] = i(t);
32
- return s;
33
- }
34
- return e;
35
- }
36
- function y(e) {
37
- const s = o.baseUrl, n = o.headers;
38
- return {
39
- async get(t) {
40
- const r = await fetch(`${s}/api/app/${e}/${t}/read`, {
41
- method: "GET",
42
- headers: n
43
- });
44
- if (!r.ok)
45
- throw new Error(`Failed to get ${e} ${t}: ${r.statusText}`);
46
- const a = await r.json();
47
- return i(a.Data);
48
- },
49
- async create(t) {
50
- const r = await fetch(`${s}/api/app/${e}/create`, {
51
- method: "POST",
52
- headers: n,
53
- body: JSON.stringify(t)
54
- });
55
- if (!r.ok)
56
- throw new Error(`Failed to create ${e}: ${r.statusText}`);
57
- return r.json();
58
- },
59
- async update(t, r) {
60
- const a = await fetch(`${s}/api/app/${e}/${t}/update`, {
61
- method: "POST",
62
- headers: n,
63
- body: JSON.stringify(r)
64
- });
65
- if (!a.ok)
66
- throw new Error(
67
- `Failed to update ${e} ${t}: ${a.statusText}`
68
- );
69
- return a.json();
70
- },
71
- async delete(t) {
72
- const r = await fetch(`${s}/api/app/${e}/${t}/delete`, {
73
- method: "DELETE",
74
- headers: n
75
- });
76
- if (!r.ok)
77
- throw new Error(
78
- `Failed to delete ${e} ${t}: ${r.statusText}`
79
- );
80
- return r.json();
81
- },
82
- async list(t) {
83
- const r = {
84
- Type: "List",
85
- ...t
86
- }, a = await fetch(`${s}/api/app/${e}/list`, {
87
- method: "POST",
88
- headers: n,
89
- body: JSON.stringify(r)
90
- });
91
- if (!a.ok)
92
- throw new Error(`Failed to list ${e}: ${a.statusText}`);
93
- return {
94
- Data: (await a.json()).Data.map((f) => i(f))
95
- };
96
- },
97
- async count(t) {
98
- var p, $;
99
- const r = {
100
- Type: "Metric",
101
- GroupBy: [],
102
- Metric: [{ Field: "_id", Type: "Count" }],
103
- ...(t == null ? void 0 : t.Filter) && { Filter: t.Filter }
104
- }, a = await fetch(`${s}/api/app/${e}/metric`, {
105
- method: "POST",
106
- headers: n,
107
- body: JSON.stringify(r)
108
- });
109
- if (!a.ok)
110
- throw new Error(`Failed to count ${e}: ${a.statusText}`);
111
- return { Count: (($ = (p = (await a.json()).Data) == null ? void 0 : p[0]) == null ? void 0 : $.count__id) ?? 0 };
112
- },
113
- // ============================================================
114
- // DRAFT/INTERACTIVE OPERATIONS
115
- // ============================================================
116
- async draft(t) {
117
- const r = await fetch(`${s}/api/app/${e}/draft`, {
118
- method: "POST",
119
- headers: n,
120
- body: JSON.stringify(t)
121
- });
122
- if (!r.ok)
123
- throw new Error(
124
- `Failed to create draft for ${e}: ${r.statusText}`
125
- );
126
- return r.json();
127
- },
128
- async draftUpdate(t, r) {
129
- const a = await fetch(`${s}/api/app/${e}/${t}/draft`, {
130
- method: "POST",
131
- headers: n,
132
- body: JSON.stringify(r)
133
- });
134
- if (!a.ok)
135
- throw new Error(
136
- `Failed to update draft for ${e} ${t}: ${a.statusText}`
137
- );
138
- return a.json();
139
- },
140
- async draftPatch(t, r) {
141
- const a = await fetch(`${s}/api/app/${e}/${t}/draft`, {
142
- method: "PATCH",
143
- headers: n,
144
- body: JSON.stringify(r)
145
- });
146
- if (!a.ok)
147
- throw new Error(
148
- `Failed to patch draft for ${e} ${t}: ${a.statusText}`
149
- );
150
- return a.json();
151
- },
152
- async draftInteraction(t) {
153
- const r = await fetch(`${s}/api/app/${e}/draft`, {
154
- method: "PATCH",
155
- headers: n,
156
- body: JSON.stringify(t)
157
- });
158
- if (!r.ok)
159
- throw new Error(
160
- `Failed to create interactive draft for ${e}: ${r.statusText}`
161
- );
162
- const a = await r.json();
163
- return {
164
- ...a.Data,
165
- _id: a.Data._id
166
- };
167
- },
168
- // ============================================================
169
- // QUERY OPERATIONS
170
- // ============================================================
171
- async metric(t) {
172
- const r = {
173
- Type: "Metric",
174
- ...t
175
- }, a = await fetch(`${s}/api/app/${e}/metric`, {
176
- method: "POST",
177
- headers: n,
178
- body: JSON.stringify(r)
179
- });
180
- if (!a.ok)
181
- throw new Error(
182
- `Failed to get metrics for ${e}: ${a.statusText}`
183
- );
184
- return a.json();
185
- },
186
- async pivot(t) {
187
- const r = {
188
- Type: "Pivot",
189
- ...t
190
- }, a = await fetch(`${s}/api/app/${e}/pivot`, {
191
- method: "POST",
192
- headers: n,
193
- body: JSON.stringify(r)
194
- });
195
- if (!a.ok)
196
- throw new Error(
197
- `Failed to get pivot data for ${e}: ${a.statusText}`
198
- );
199
- return a.json();
200
- },
201
- // ============================================================
202
- // METADATA OPERATIONS
203
- // ============================================================
204
- async fields() {
205
- const t = await fetch(`${s}/api/app/${e}/fields`, {
206
- method: "GET",
207
- headers: n
208
- });
209
- if (!t.ok)
210
- throw new Error(
211
- `Failed to get fields for ${e}: ${t.statusText}`
212
- );
213
- return t.json();
214
- },
215
- async fetchField(t, r) {
216
- const a = await fetch(
217
- `${s}/api/app/${e}/${t}/field/${r}/fetch`,
218
- {
219
- method: "GET",
220
- headers: n
221
- }
222
- );
223
- if (!a.ok)
224
- throw new Error(
225
- `Failed to fetch field ${r} for ${e}: ${a.statusText}`
226
- );
227
- return (await a.json()).Data;
228
- }
229
- };
230
- }
231
- export {
232
- y as a,
233
- h as b,
234
- w as c,
235
- d as g,
236
- u as s
237
- };