@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.
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/datetime.d.ts +59 -10
- package/dist/api/datetime.d.ts.map +1 -1
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api.cjs +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.mjs +43 -21
- package/dist/api.types.d.ts +2 -1
- package/dist/api.types.d.ts.map +1 -1
- package/dist/auth/AuthProvider.d.ts.map +1 -1
- package/dist/auth.cjs +1 -1
- package/dist/auth.mjs +34 -34
- package/dist/base-types.d.ts +1 -1
- package/dist/base-types.d.ts.map +1 -1
- package/dist/client-BIkaIr2y.js +217 -0
- package/dist/client-DxjRcEtN.cjs +1 -0
- package/dist/components/hooks/useForm/apiClient.d.ts +45 -4
- package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
- package/dist/components/hooks/useForm/types.d.ts +8 -0
- package/dist/components/hooks/useForm/types.d.ts.map +1 -1
- package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +1028 -1051
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/kanban.cjs +1 -1
- package/dist/kanban.mjs +1 -1
- package/dist/{metadata-0lZAfuTP.cjs → metadata-Bz8zJqC1.cjs} +1 -1
- package/dist/{metadata-B88D_pVS.js → metadata-VbQzyD2C.js} +1 -1
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +1 -1
- package/dist/types/base-fields.d.ts +71 -17
- package/dist/types/base-fields.d.ts.map +1 -1
- package/dist/types/common.d.ts +0 -12
- package/dist/types/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/sdk/api/client.ts +3 -41
- package/sdk/api/datetime.ts +98 -14
- package/sdk/api/index.ts +12 -6
- package/sdk/api.ts +6 -3
- package/sdk/api.types.ts +3 -4
- package/sdk/auth/AuthProvider.tsx +22 -24
- package/sdk/base-types.ts +2 -0
- package/sdk/components/hooks/useForm/apiClient.ts +118 -4
- package/sdk/components/hooks/useForm/types.ts +9 -0
- package/sdk/components/hooks/useForm/useForm.ts +79 -60
- package/sdk/index.ts +3 -0
- package/sdk/types/base-fields.ts +71 -17
- package/sdk/types/common.ts +2 -13
- package/dist/client-DgtkT50N.cjs +0 -1
- package/dist/client-V-WzUb8H.js +0 -237
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { AuthProvider, useAuth } from './auth';
|
|
|
10
10
|
export type { UseAuthReturnType, UserDetailsType, AuthStatusType, AuthProviderPropsType, } from './auth/types';
|
|
11
11
|
export { api, setApiBaseUrl, getApiBaseUrl, getBdoSchema } from './api';
|
|
12
12
|
export type { SortType, SortDirectionType, FilterType, ConditionType, ConditionGroupType, ConditionOperatorType, ConditionGroupOperatorType, ListResponseType, ListOptionsType, ColumnDefinitionType, } from './types/common';
|
|
13
|
-
export type { IdFieldType, StringFieldType, TextAreaFieldType, NumberFieldType, LongFieldType, BooleanFieldType, DateFieldType, DateTimeFieldType, CurrencyFieldType, SelectFieldType, LookupFieldType, ArrayFieldType, JSONFieldType, } from './types/base-fields';
|
|
13
|
+
export type { IdFieldType, StringFieldType, TextAreaFieldType, NumberFieldType, LongFieldType, BooleanFieldType, DateFieldType, DateTimeFieldType, CurrencyFieldType, SelectFieldType, LookupFieldType, ArrayFieldType, JSONFieldType, ReferenceFieldType, ExtractReferenceType, ExtractFetchFieldType, } from './types/base-fields';
|
|
14
14
|
export { formatCurrency, formatDate, formatDateTime, formatNumber, formatBoolean, formatArray, formatJSON, formatFieldValue, } from './utils/formatting';
|
|
15
15
|
export { cn } from './utils/cn';
|
|
16
16
|
export { toError, isError, getErrorMessage, isNetworkError, isTimeoutError, isAbortError, tryCatch, wrapError, } from './utils/error-handling';
|
package/dist/index.d.ts.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,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAO7B,OAAO,EACL,cAAc,EACd,UAAU,EACV,cAAc,EACd,YAAY,EACZ,aAAa,EACb,WAAW,EACX,UAAU,EACV,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAGhC,OAAO,EACL,OAAO,EACP,OAAO,EACP,eAAe,EACf,cAAc,EACd,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GACf,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,MAAM,EACN,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAOzB,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
|
package/dist/kanban.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),T=require("@tanstack/react-query"),F=require("./client-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),T=require("@tanstack/react-query"),F=require("./client-DxjRcEtN.cjs"),A=require("./error-handling-CAoD0Kwb.cjs"),Tt=require("./useFilter-DzpP_ag0.cjs"),ut=50,ct=5,lt=5;function dt({onCardMove:o,onError:l,columns:d,announceMove:a}){const[i,_]=c.useState({isDragging:!1,draggedCard:null,dragOverColumn:null,dragOverPosition:null,dragSourceColumn:null}),Q=c.useRef(null),D=c.useRef(null),S=c.useRef(null),w=c.useCallback(()=>{_({isDragging:!1,draggedCard:null,dragOverColumn:null,dragOverPosition:null,dragSourceColumn:null}),D.current&&(clearTimeout(D.current),D.current=null)},[]),h=c.useCallback(s=>d.find(u=>u._id===s)||null,[d]),$=c.useCallback(s=>{for(const u of d){const g=u.cards.find(f=>f._id===s);if(g)return{card:g,column:u}}return null},[d]),E=c.useCallback((s,u)=>{var g,f;try{const y=s.target,m=h(u.columnId);if(!m)throw new Error("Source column not found");(g=s.dataTransfer)==null||g.setData("text/plain",u._id),(f=s.dataTransfer)==null||f.setData("application/json",JSON.stringify(u));const k=y.cloneNode(!0);k.style.cssText=`
|
|
2
2
|
position: fixed;
|
|
3
3
|
top: -1000px;
|
|
4
4
|
left: -1000px;
|
package/dist/kanban.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState as G, useRef as q, useCallback as p, useEffect as V, useMemo as lt, createContext as Pt, useContext as Et } from "react";
|
|
2
2
|
import { useQueryClient as Ft, useQueries as $t, keepPreviousData as Lt, useQuery as It, useMutation as R } from "@tanstack/react-query";
|
|
3
|
-
import { a as F } from "./client-
|
|
3
|
+
import { a as F } from "./client-BIkaIr2y.js";
|
|
4
4
|
import { t as k } from "./error-handling-CrhTtD88.js";
|
|
5
5
|
import { u as Ht } from "./useFilter-H5bgAZQF.js";
|
|
6
6
|
const gt = 50, mt = 5, yt = 5;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("./client-
|
|
1
|
+
"use strict";const o=require("./client-DxjRcEtN.cjs");async function c(e){try{const r=o.getApiBaseUrl(),s=o.getDefaultHeaders(),a=await fetch(`${r}/api/app/meta/bdo/${e}`,{method:"GET",headers:s});if(!a.ok)throw new Error(`Failed to fetch schema for ${e}: ${a.statusText}`);const t=await a.json();if(!t||typeof t!="object")throw new Error(`Invalid BDO schema response for ${e}`);return t}catch(r){throw console.error(`Schema fetch error for ${e}:`,r),new Error(`Failed to load BDO schema: ${r instanceof Error?r.message:"Unknown error"}`)}}async function n(e){try{const r=o.getApiBaseUrl(),s=o.getDefaultHeaders(),a=e!=null&&e.Filter||e!=null&&e.Sort?"POST":"GET",t=await fetch(`${r}/api/app/metadata/list`,{method:a,headers:s,...a==="POST"&&e&&{body:JSON.stringify(e)}});if(!t.ok)throw new Error(`Failed to list metadata: ${t.statusText}`);return await t.json()}catch(r){throw console.error("Metadata list error:",r),new Error(`Failed to list metadata: ${r instanceof Error?r.message:"Unknown error"}`)}}exports.getBdoSchema=c;exports.listMetadata=n;
|
package/dist/table.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),O=require("@tanstack/react-query"),A=require("./client-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),O=require("@tanstack/react-query"),A=require("./client-DxjRcEtN.cjs"),h=require("./error-handling-CAoD0Kwb.cjs"),re=require("./useFilter-DzpP_ag0.cjs");function oe(o){var Q,z,M,P,F,w,R,x;const[s,b]=t.useState({query:"",debouncedQuery:""}),c=t.useRef(null),j=300,G=()=>{var r,y;const e=(r=o.initialState)==null?void 0:r.sort;if(e&&e.length>0){const D=e[0],L=Object.keys(D)[0],te=(y=D[L])==null?void 0:y.toLowerCase();return{field:L,direction:te}}return{field:null,direction:null}},[n,p]=t.useState(G),[a,i]=t.useState({pageNo:((z=(Q=o.initialState)==null?void 0:Q.pagination)==null?void 0:z.pageNo)||1,pageSize:((P=(M=o.initialState)==null?void 0:M.pagination)==null?void 0:P.pageSize)||10}),u=re.useFilter({conditions:(w=(F=o.initialState)==null?void 0:F.filter)==null?void 0:w.conditions,operator:((x=(R=o.initialState)==null?void 0:R.filter)==null?void 0:x.operator)||"And"}),l=t.useMemo(()=>{const e={};return s.debouncedQuery&&(e.Search=s.debouncedQuery),u.payload&&(e.Filter=u.payload),e},[s.debouncedQuery,u.payload]),N=t.useMemo(()=>{const e={...l};return n.field&&n.direction&&(e.Sort=[{[String(n.field)]:n.direction==="asc"?"ASC":"DESC"}]),e.Page=a.pageNo,e.PageSize=a.pageSize,e},[l,n,a]),{data:g,isLoading:H,isFetching:I,error:q,refetch:E}=O.useQuery({queryKey:["table",o.source,N],queryFn:async()=>{try{const e=await A.api(o.source).list(N);return o.onSuccess&&o.onSuccess(e.Data),e}catch(e){throw o.onError&&o.onError(h.toError(e)),e}},staleTime:0,gcTime:0}),{data:d,isLoading:K,isFetching:_,error:T,refetch:k}=O.useQuery({queryKey:["table-count",o.source,l],queryFn:async()=>{try{return await A.api(o.source).count(l)}catch(e){throw o.onError&&o.onError(h.toError(e)),e}},staleTime:0,gcTime:0}),B=t.useMemo(()=>(g==null?void 0:g.Data)||[],[g]),f=t.useMemo(()=>(d==null?void 0:d.Count)||0,[d]),S=t.useMemo(()=>Math.ceil(f/a.pageSize),[f,a.pageSize]),U=t.useCallback(e=>{p(r=>{if(r.field===e){if(r.direction==="asc")return{field:e,direction:"desc"};if(r.direction==="desc")return{field:null,direction:null}}return{field:e,direction:"asc"}})},[]),J=t.useCallback(()=>{p({field:null,direction:null})},[]),V=t.useCallback((e,r)=>{p({field:e,direction:r})},[]),W=t.useCallback(e=>{if(e.length>255){console.warn("Search query exceeds maximum length of 255 characters");return}b(r=>({...r,query:e})),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>{b(r=>({...r,debouncedQuery:e})),i(r=>({...r,pageNo:1}))},j)},[]),X=t.useCallback(()=>{c.current&&clearTimeout(c.current),b({query:"",debouncedQuery:""}),i(e=>({...e,pageNo:1}))},[]);t.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const m=a.pageNo<S,C=a.pageNo>1,Y=t.useCallback(()=>{m&&i(e=>({...e,pageNo:e.pageNo+1}))},[m]),Z=t.useCallback(()=>{C&&i(e=>({...e,pageNo:e.pageNo-1}))},[C]),$=t.useCallback(e=>{const r=Math.max(1,Math.min(e,S));i(y=>({...y,pageNo:r}))},[S]),v=t.useCallback(e=>{i(r=>({...r,pageSize:e,pageNo:1}))},[]),ee=t.useCallback(async()=>{const[e]=await Promise.all([E(),k()]);return e.data||{Data:[]}},[E,k]);return{rows:B,totalItems:f,isLoading:H||K,isFetching:I||_,error:q?h.toError(q):T?h.toError(T):null,search:{query:s.query,setQuery:W,clear:X},sort:{field:n.field,direction:n.direction,toggle:U,clear:J,set:V},filter:u,pagination:{pageNo:a.pageNo,pageSize:a.pageSize,totalPages:S,totalItems:f,canGoNext:m,canGoPrevious:C,goToNext:Y,goToPrevious:Z,goToPage:$,setPageSize:v},refetch:ee}}exports.useTable=oe;
|
package/dist/table.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState as q, useRef as ne, useMemo as s, useCallback as o, useEffect as ie } from "react";
|
|
2
2
|
import { useQuery as G } from "@tanstack/react-query";
|
|
3
|
-
import { a as I } from "./client-
|
|
3
|
+
import { a as I } from "./client-BIkaIr2y.js";
|
|
4
4
|
import { t as p } from "./error-handling-CrhTtD88.js";
|
|
5
5
|
import { u as ce } from "./useFilter-H5bgAZQF.js";
|
|
6
6
|
function de(r) {
|
|
@@ -57,26 +57,44 @@ export type LongFieldType = number;
|
|
|
57
57
|
* Use this for true/false values, flags, toggles
|
|
58
58
|
*/
|
|
59
59
|
export type BooleanFieldType = boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Encoded date format from API response
|
|
62
|
+
* API returns: { "$__d__": "YYYY-MM-DD" }
|
|
63
|
+
*/
|
|
64
|
+
export interface DateEncodedType {
|
|
65
|
+
$__d__: string;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Encoded datetime format from API response
|
|
69
|
+
* API returns: { "$__dt__": unix_timestamp_seconds }
|
|
70
|
+
*/
|
|
71
|
+
export interface DateTimeEncodedType {
|
|
72
|
+
$__dt__: number;
|
|
73
|
+
}
|
|
60
74
|
/**
|
|
61
75
|
* Date field (date only, no time)
|
|
62
|
-
*
|
|
76
|
+
* API Response Format: { "$__d__": "YYYY-MM-DD" }
|
|
77
|
+
* API Request Format: "YYYY-MM-DD"
|
|
63
78
|
* Storage: DATE in database
|
|
64
79
|
* Use this for birth dates, due dates, calendar events
|
|
65
80
|
*
|
|
66
81
|
* @example
|
|
67
|
-
*
|
|
82
|
+
* // Response from API:
|
|
83
|
+
* { "$__d__": "2025-03-15" }
|
|
68
84
|
*/
|
|
69
|
-
export type DateFieldType =
|
|
85
|
+
export type DateFieldType = DateEncodedType;
|
|
70
86
|
/**
|
|
71
87
|
* DateTime field (date and time)
|
|
72
|
-
*
|
|
88
|
+
* API Response Format: { "$__dt__": unix_timestamp_seconds }
|
|
89
|
+
* API Request Format: "YYYY-MM-DD HH:MM:SS"
|
|
73
90
|
* Storage: DATETIME/TIMESTAMP in database
|
|
74
91
|
* Use this for created_at, updated_at, event timestamps
|
|
75
92
|
*
|
|
76
93
|
* @example
|
|
77
|
-
*
|
|
94
|
+
* // Response from API:
|
|
95
|
+
* { "$__dt__": 1769110463 }
|
|
78
96
|
*/
|
|
79
|
-
export type DateTimeFieldType =
|
|
97
|
+
export type DateTimeFieldType = DateTimeEncodedType;
|
|
80
98
|
/**
|
|
81
99
|
* Currency field supporting multiple value formats
|
|
82
100
|
* Resolves to: CurrencyValueType
|
|
@@ -106,7 +124,49 @@ export type CurrencyValueType = {
|
|
|
106
124
|
* JSONFieldType<{settings: {theme: string}}> // => {settings: {theme: string}}
|
|
107
125
|
*/
|
|
108
126
|
export type JSONFieldType<T = JSONValueType> = T;
|
|
109
|
-
|
|
127
|
+
/**
|
|
128
|
+
* Reference/Lookup field for relationships to other Business Data Objects
|
|
129
|
+
*
|
|
130
|
+
* @template TReferencedType - The full type of the referenced BDO record
|
|
131
|
+
*
|
|
132
|
+
* Runtime behavior:
|
|
133
|
+
* - The field stores the full referenced record (e.g., full supplier object)
|
|
134
|
+
* - API returns the complete record from the referenced BDO
|
|
135
|
+
* - On save, the full object is sent in the payload
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* SupplierInfo: ReferenceFieldType<BaseSupplierType>;
|
|
139
|
+
* // At runtime: { _id: "...", SupplierId: "...", SupplierName: "...", ... }
|
|
140
|
+
*/
|
|
141
|
+
export type ReferenceFieldType<TReferencedType = unknown> = TReferencedType;
|
|
142
|
+
/**
|
|
143
|
+
* Extract the referenced type from a ReferenceFieldType
|
|
144
|
+
* Note: Since ReferenceFieldType<T> = T, this just returns T if it has _id
|
|
145
|
+
*/
|
|
146
|
+
export type ExtractReferenceType<T> = T extends {
|
|
147
|
+
_id: string;
|
|
148
|
+
} ? T : never;
|
|
149
|
+
/**
|
|
150
|
+
* Extract the type that fetchField should return for a given field type
|
|
151
|
+
* - For Reference fields (objects with _id) → the full referenced record type
|
|
152
|
+
* - For other field types → { Value: string; Label: string } (static dropdown)
|
|
153
|
+
*
|
|
154
|
+
* Detection: All BDO types have _id: string, so we check for that property
|
|
155
|
+
* to distinguish reference fields from primitive fields like StringFieldType.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* type SupplierOptions = ExtractFetchFieldType<BaseProductType["SupplierInfo"]>;
|
|
159
|
+
* // Result: BaseSupplierType (has _id)
|
|
160
|
+
*
|
|
161
|
+
* type CategoryOptions = ExtractFetchFieldType<BaseProductType["Category"]>;
|
|
162
|
+
* // Result: { Value: string; Label: string } (string has no _id)
|
|
163
|
+
*/
|
|
164
|
+
export type ExtractFetchFieldType<T> = T extends {
|
|
165
|
+
_id: string;
|
|
166
|
+
} ? T : {
|
|
167
|
+
Value: string;
|
|
168
|
+
Label: string;
|
|
169
|
+
};
|
|
110
170
|
/**
|
|
111
171
|
* Valid JSON value types
|
|
112
172
|
*/
|
|
@@ -128,17 +188,11 @@ export interface JSONArrayType extends Array<JSONValueType> {
|
|
|
128
188
|
*/
|
|
129
189
|
export type SelectFieldType<T extends string> = T;
|
|
130
190
|
/**
|
|
131
|
-
* Lookup
|
|
132
|
-
* @template
|
|
133
|
-
*
|
|
134
|
-
* Storage: VARCHAR in database (stores the ID)
|
|
135
|
-
* Use this for foreign keys, relationships, references
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* LookupFieldType // => string (referenced record ID)
|
|
139
|
-
* LookupFieldType<IdFieldType> // => string (typed as IdFieldType)
|
|
191
|
+
* Alias for ReferenceFieldType (Lookup = Reference in the backend)
|
|
192
|
+
* @template TReferencedType - The full type of the referenced BDO record
|
|
193
|
+
* @deprecated Use ReferenceFieldType instead
|
|
140
194
|
*/
|
|
141
|
-
export type LookupFieldType<
|
|
195
|
+
export type LookupFieldType<TReferencedType = unknown> = ReferenceFieldType<TReferencedType>;
|
|
142
196
|
/**
|
|
143
197
|
* Array field with MultiValue support
|
|
144
198
|
* @template T - Type of array elements
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-fields.d.ts","sourceRoot":"","sources":["../../sdk/types/base-fields.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,eAAe,CACzB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,UAAU,SAAS,MAAM,GAAG,KAAK,EACjC,UAAU,SAAS,MAAM,GAAG,KAAK,IAC/B,CAAC,CAAC;AAEN;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEvC;;;;;;;;;;GAUG;AACH,MAAM,MAAM,eAAe,CAAC,UAAU,SAAS,MAAM,GAAG,KAAK,IAAI,MAAM,CAAC;AAExE;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAEvC
|
|
1
|
+
{"version":3,"file":"base-fields.d.ts","sourceRoot":"","sources":["../../sdk/types/base-fields.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC;AAEjC;;;;;;;;;;;;GAYG;AACH,MAAM,MA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;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,IACjC,CAAC,SAAS;IAAE,GAAG,EAAE,MAAM,CAAA;CAAE,GACrB,CAAC,GACD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,cAAc,GACd,aAAa,CAAC;AAElB,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAAC;CAC9B;AAED,MAAM,WAAW,aAAc,SAAQ,KAAK,CAAC,aAAa,CAAC;CAAG;AAE9D;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,MAAM,eAAe,CAAC,eAAe,GAAG,OAAO,IAAI,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAM7F;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AAEpC;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;AAE/D;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC;AAMjD;;;GAGG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,SAAS,iBAAiB,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC"}
|
package/dist/types/common.d.ts
CHANGED
|
@@ -58,18 +58,6 @@ export interface ConditionGroupType<T = any> {
|
|
|
58
58
|
* @template T - Data type for type-safe field names (defaults to any)
|
|
59
59
|
*/
|
|
60
60
|
export type FilterType<T = any> = ConditionGroupType<T>;
|
|
61
|
-
/**
|
|
62
|
-
* DateTime encoding format used by the API
|
|
63
|
-
*/
|
|
64
|
-
export interface DateTimeEncodedType {
|
|
65
|
-
$__dt__: number;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Date encoding format used by the API
|
|
69
|
-
*/
|
|
70
|
-
export interface DateEncodedType {
|
|
71
|
-
$__d__: string;
|
|
72
|
-
}
|
|
73
61
|
/**
|
|
74
62
|
* Standard paginated list response
|
|
75
63
|
* @template T - Type of items in the list
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../sdk/types/common.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,CAAC;AAE/C;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;AAE/D;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,cAAc,EAAE,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,qBAAqB,GAC7B,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,GACzC,SAAS,GAAG,YAAY,GAAG,IAAI,GAAG,KAAK,GACvC,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,aAAa,GACjD,WAAW,GAAG,WAAW,CAAC;AAE9B;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG,KAAK,GAAG,IAAI,GAAG,KAAK,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,GAAG,SAAS,GAAG,aAAa,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,GAAG;IACpC,qEAAqE;IACrE,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,yBAAyB;IACzB,QAAQ,EAAE,qBAAqB,CAAC;IAChC,mEAAmE;IACnE,QAAQ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pD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,sCAAsC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;CACtD"}
|
package/package.json
CHANGED
package/sdk/api/client.ts
CHANGED
|
@@ -9,8 +9,6 @@ import type {
|
|
|
9
9
|
CreateUpdateResponseType,
|
|
10
10
|
DeleteResponseType,
|
|
11
11
|
CountResponseType,
|
|
12
|
-
DateTimeEncodedType,
|
|
13
|
-
DateEncodedType,
|
|
14
12
|
MetricOptionsType,
|
|
15
13
|
MetricResponseType,
|
|
16
14
|
PivotOptionsType,
|
|
@@ -157,40 +155,6 @@ export function getApiBaseUrl(): string {
|
|
|
157
155
|
return apiConfig.baseUrl || "";
|
|
158
156
|
}
|
|
159
157
|
|
|
160
|
-
/**
|
|
161
|
-
* Recursively process an object to decode datetime fields
|
|
162
|
-
*/
|
|
163
|
-
function decodeResponseData<T>(data: any): T {
|
|
164
|
-
if (data === null || data === undefined) {
|
|
165
|
-
return data;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (Array.isArray(data)) {
|
|
169
|
-
return data.map((item) => decodeResponseData(item)) as T;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (typeof data === "object") {
|
|
173
|
-
// Check for datetime encoding
|
|
174
|
-
if ("$__dt__" in data) {
|
|
175
|
-
return new Date((data as DateTimeEncodedType).$__dt__ * 1000) as T;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Check for date encoding
|
|
179
|
-
if ("$__d__" in data) {
|
|
180
|
-
return new Date((data as DateEncodedType).$__d__) as T;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Recursively process object properties
|
|
184
|
-
const result: any = {};
|
|
185
|
-
for (const [key, value] of Object.entries(data)) {
|
|
186
|
-
result[key] = decodeResponseData(value);
|
|
187
|
-
}
|
|
188
|
-
return result as T;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return data as T;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
158
|
/**
|
|
195
159
|
* Create a resource client for the specified Business Object
|
|
196
160
|
* @param bo_id - Business Object identifier (e.g., "user", "leave", "vendor")
|
|
@@ -212,7 +176,7 @@ export function api<T = any>(bo_id: string): ResourceClient<T> {
|
|
|
212
176
|
}
|
|
213
177
|
|
|
214
178
|
const responseData: ReadResponseType<T> = await response.json();
|
|
215
|
-
return
|
|
179
|
+
return responseData.Data;
|
|
216
180
|
},
|
|
217
181
|
|
|
218
182
|
async create(
|
|
@@ -278,10 +242,8 @@ export function api<T = any>(bo_id: string): ResourceClient<T> {
|
|
|
278
242
|
throw new Error(`Failed to list ${bo_id}: ${response.statusText}`);
|
|
279
243
|
}
|
|
280
244
|
|
|
281
|
-
const responseData: ListResponseType<
|
|
282
|
-
return
|
|
283
|
-
Data: responseData.Data.map((item) => decodeResponseData<T>(item)),
|
|
284
|
-
};
|
|
245
|
+
const responseData: ListResponseType<T> = await response.json();
|
|
246
|
+
return responseData;
|
|
285
247
|
},
|
|
286
248
|
|
|
287
249
|
async count(options?: ListOptionsType): Promise<CountResponseType> {
|
package/sdk/api/datetime.ts
CHANGED
|
@@ -1,33 +1,117 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DateEncodedType, DateTimeEncodedType } from "../types/base-fields";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Date format constants matching backend DatetimeFormat class
|
|
5
|
+
* Source: kf-ai-base/core/util/datetime_utils.py
|
|
5
6
|
*/
|
|
7
|
+
export const DatetimeFormat = {
|
|
8
|
+
/** Date format: "YYYY-MM-DD" */
|
|
9
|
+
DATE: "%Y-%m-%d",
|
|
10
|
+
/** Time format: "HH:MM:SS" */
|
|
11
|
+
TIME: "%H:%M:%S",
|
|
12
|
+
/** DateTime format: "YYYY-MM-DD HH:MM:SS" */
|
|
13
|
+
DATE_TIME: "%Y-%m-%d %H:%M:%S",
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
// ============================================================
|
|
17
|
+
// DECODING FUNCTIONS (API Response → Date object)
|
|
18
|
+
// Use these in components to convert API response to Date
|
|
19
|
+
// ============================================================
|
|
6
20
|
|
|
7
21
|
/**
|
|
8
|
-
*
|
|
22
|
+
* Decode API date response to Date object
|
|
23
|
+
* @param encoded - API response format { "$__d__": "YYYY-MM-DD" }
|
|
24
|
+
* @returns JavaScript Date object
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const apiResponse = { "$__d__": "2025-03-15" };
|
|
28
|
+
* const date = decodeDate(apiResponse); // => Date object
|
|
9
29
|
*/
|
|
10
|
-
export function
|
|
11
|
-
|
|
30
|
+
export function decodeDate(encoded: DateEncodedType): Date {
|
|
31
|
+
const [year, month, day] = encoded.$__d__.split("-").map(Number);
|
|
32
|
+
return new Date(year, month - 1, day);
|
|
12
33
|
}
|
|
13
34
|
|
|
14
35
|
/**
|
|
15
|
-
* Decode API datetime
|
|
36
|
+
* Decode API datetime response to Date object
|
|
37
|
+
* @param encoded - API response format { "$__dt__": unix_timestamp_seconds }
|
|
38
|
+
* @returns JavaScript Date object
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const apiResponse = { "$__dt__": 1769110463 };
|
|
42
|
+
* const date = decodeDateTime(apiResponse); // => Date object
|
|
16
43
|
*/
|
|
17
|
-
export function
|
|
44
|
+
export function decodeDateTime(encoded: DateTimeEncodedType): Date {
|
|
18
45
|
return new Date(encoded.$__dt__ * 1000);
|
|
19
46
|
}
|
|
20
47
|
|
|
48
|
+
// ============================================================
|
|
49
|
+
// FORMATTING FUNCTIONS (Date object → API Request string)
|
|
50
|
+
// Use these when creating/updating records
|
|
51
|
+
// ============================================================
|
|
52
|
+
|
|
21
53
|
/**
|
|
22
|
-
*
|
|
54
|
+
* Format a Date object to API request date string
|
|
55
|
+
* @param date - JavaScript Date object
|
|
56
|
+
* @returns "YYYY-MM-DD" formatted string for API requests
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* formatDate(new Date(2025, 2, 15)) // => "2025-03-15"
|
|
23
60
|
*/
|
|
24
|
-
export function
|
|
25
|
-
|
|
61
|
+
export function formatDate(date: Date): string {
|
|
62
|
+
const year = date.getFullYear();
|
|
63
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
64
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
65
|
+
return `${year}-${month}-${day}`;
|
|
26
66
|
}
|
|
27
67
|
|
|
28
68
|
/**
|
|
29
|
-
*
|
|
69
|
+
* Format a Date object to API request datetime string
|
|
70
|
+
* @param date - JavaScript Date object
|
|
71
|
+
* @returns "YYYY-MM-DD HH:MM:SS" formatted string for API requests
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* formatDateTime(new Date(2025, 2, 15, 10, 30, 45)) // => "2025-03-15 10:30:45"
|
|
30
75
|
*/
|
|
31
|
-
export function
|
|
32
|
-
|
|
33
|
-
|
|
76
|
+
export function formatDateTime(date: Date): string {
|
|
77
|
+
const year = date.getFullYear();
|
|
78
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
79
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
80
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
81
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
82
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
83
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ============================================================
|
|
87
|
+
// PARSING FUNCTIONS (String → Date object)
|
|
88
|
+
// Use these when you have a date string and need a Date object
|
|
89
|
+
// ============================================================
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Parse date string to Date object
|
|
93
|
+
* @param dateStr - "YYYY-MM-DD" formatted string
|
|
94
|
+
* @returns JavaScript Date object
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* parseDate("2025-03-15") // => Date object for March 15, 2025
|
|
98
|
+
*/
|
|
99
|
+
export function parseDate(dateStr: string): Date {
|
|
100
|
+
const [year, month, day] = dateStr.split("-").map(Number);
|
|
101
|
+
return new Date(year, month - 1, day);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Parse datetime string to Date object
|
|
106
|
+
* @param dateTimeStr - "YYYY-MM-DD HH:MM:SS" formatted string
|
|
107
|
+
* @returns JavaScript Date object
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* parseDateTime("2025-03-15 10:30:45") // => Date object
|
|
111
|
+
*/
|
|
112
|
+
export function parseDateTime(dateTimeStr: string): Date {
|
|
113
|
+
const [datePart, timePart] = dateTimeStr.split(" ");
|
|
114
|
+
const [year, month, day] = datePart.split("-").map(Number);
|
|
115
|
+
const [hours, minutes, seconds] = timePart.split(":").map(Number);
|
|
116
|
+
return new Date(year, month - 1, day, hours, minutes, seconds);
|
|
117
|
+
}
|
package/sdk/api/index.ts
CHANGED
|
@@ -10,10 +10,13 @@ export type { ResourceClient } from "./client";
|
|
|
10
10
|
|
|
11
11
|
// DateTime utilities
|
|
12
12
|
export {
|
|
13
|
-
|
|
14
|
-
decodeDatetime,
|
|
15
|
-
encodeDate,
|
|
13
|
+
DatetimeFormat,
|
|
16
14
|
decodeDate,
|
|
15
|
+
decodeDateTime,
|
|
16
|
+
formatDate,
|
|
17
|
+
formatDateTime,
|
|
18
|
+
parseDate,
|
|
19
|
+
parseDateTime,
|
|
17
20
|
} from "./datetime";
|
|
18
21
|
|
|
19
22
|
// Metadata API client
|
|
@@ -40,9 +43,6 @@ export type {
|
|
|
40
43
|
CreateUpdateResponseType,
|
|
41
44
|
DeleteResponseType,
|
|
42
45
|
CountResponseType,
|
|
43
|
-
// DateTime types
|
|
44
|
-
DateTimeEncodedType,
|
|
45
|
-
DateEncodedType,
|
|
46
46
|
// Metric types
|
|
47
47
|
MetricTypeType,
|
|
48
48
|
MetricFieldType,
|
|
@@ -58,3 +58,9 @@ export type {
|
|
|
58
58
|
// Fields types
|
|
59
59
|
FieldsResponseType,
|
|
60
60
|
} from "../types/common";
|
|
61
|
+
|
|
62
|
+
// Re-export date types from base-fields
|
|
63
|
+
export type {
|
|
64
|
+
DateEncodedType,
|
|
65
|
+
DateTimeEncodedType,
|
|
66
|
+
} from "../types/base-fields";
|
package/sdk/api.ts
CHANGED
|
@@ -14,10 +14,13 @@ export {
|
|
|
14
14
|
|
|
15
15
|
// DateTime utilities
|
|
16
16
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
formatDateTime,
|
|
18
|
+
decodeDateTime,
|
|
19
|
+
formatDate,
|
|
20
20
|
decodeDate,
|
|
21
|
+
parseDate,
|
|
22
|
+
parseDateTime,
|
|
23
|
+
DatetimeFormat,
|
|
21
24
|
} from './api/datetime';
|
|
22
25
|
|
|
23
26
|
// Metadata API client
|
package/sdk/api.types.ts
CHANGED
|
@@ -9,6 +9,9 @@ export type { ResourceClient } from './api/client';
|
|
|
9
9
|
// Metadata types
|
|
10
10
|
export type { BackendSchema, MetadataItem, FieldMetadata } from './api/metadata';
|
|
11
11
|
|
|
12
|
+
// DateTime types from base-fields
|
|
13
|
+
export type { DateTimeEncodedType, DateEncodedType } from './types/base-fields';
|
|
14
|
+
|
|
12
15
|
// Common API types
|
|
13
16
|
export type {
|
|
14
17
|
// Sort types
|
|
@@ -32,10 +35,6 @@ export type {
|
|
|
32
35
|
DeleteResponseType,
|
|
33
36
|
CountResponseType,
|
|
34
37
|
|
|
35
|
-
// DateTime types
|
|
36
|
-
DateTimeEncodedType,
|
|
37
|
-
DateEncodedType,
|
|
38
|
-
|
|
39
38
|
// Metric types
|
|
40
39
|
MetricTypeType,
|
|
41
40
|
MetricFieldType,
|
|
@@ -102,7 +102,8 @@ export function AuthProvider({
|
|
|
102
102
|
|
|
103
103
|
const status: AuthStatusType = useMemo(() => {
|
|
104
104
|
if (isLoading || isFetching) return "loading";
|
|
105
|
-
if (sessionData?.userDetails)
|
|
105
|
+
if (Object.keys(sessionData?.userDetails || {}).length > 0)
|
|
106
|
+
return "authenticated";
|
|
106
107
|
return "unauthenticated";
|
|
107
108
|
}, [isLoading, isFetching, sessionData]);
|
|
108
109
|
|
|
@@ -139,11 +140,7 @@ export function AuthProvider({
|
|
|
139
140
|
}, [queryError]);
|
|
140
141
|
|
|
141
142
|
useEffect(() => {
|
|
142
|
-
if (
|
|
143
|
-
status === "unauthenticated" &&
|
|
144
|
-
authConfig.autoRedirect &&
|
|
145
|
-
!isLoading
|
|
146
|
-
) {
|
|
143
|
+
if (status === "unauthenticated" && authConfig.autoRedirect && !isLoading) {
|
|
147
144
|
initiateLogin();
|
|
148
145
|
}
|
|
149
146
|
}, [status, isLoading, authConfig.autoRedirect]);
|
|
@@ -156,7 +153,7 @@ export function AuthProvider({
|
|
|
156
153
|
(provider?: AuthProviderNameType, options?: LoginOptionsType) => {
|
|
157
154
|
initiateLogin(provider, options);
|
|
158
155
|
},
|
|
159
|
-
[]
|
|
156
|
+
[],
|
|
160
157
|
);
|
|
161
158
|
|
|
162
159
|
const logout = useCallback(
|
|
@@ -164,36 +161,37 @@ export function AuthProvider({
|
|
|
164
161
|
queryClient.removeQueries({ queryKey: SESSION_QUERY_KEY });
|
|
165
162
|
await performLogout(options);
|
|
166
163
|
},
|
|
167
|
-
[queryClient]
|
|
164
|
+
[queryClient],
|
|
168
165
|
);
|
|
169
166
|
|
|
170
|
-
const refreshSession =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
const refreshSession =
|
|
168
|
+
useCallback(async (): Promise<SessionResponseType | null> => {
|
|
169
|
+
// Prevent concurrent refreshes - return existing data if already fetching
|
|
170
|
+
if (isFetching) {
|
|
171
|
+
return sessionData || null;
|
|
172
|
+
}
|
|
175
173
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
try {
|
|
175
|
+
const result = await refetch();
|
|
176
|
+
return result.data || null;
|
|
177
|
+
} catch (err) {
|
|
178
|
+
setError(err as Error);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}, [refetch, isFetching, sessionData]);
|
|
184
182
|
|
|
185
183
|
const hasRole = useCallback(
|
|
186
184
|
(role: string): boolean => {
|
|
187
185
|
return user?.Role === role;
|
|
188
186
|
},
|
|
189
|
-
[user]
|
|
187
|
+
[user],
|
|
190
188
|
);
|
|
191
189
|
|
|
192
190
|
const hasAnyRole = useCallback(
|
|
193
191
|
(roles: string[]): boolean => {
|
|
194
192
|
return roles.includes(user?.Role || "");
|
|
195
193
|
},
|
|
196
|
-
[user]
|
|
194
|
+
[user],
|
|
197
195
|
);
|
|
198
196
|
|
|
199
197
|
const clearError = useCallback(() => {
|
|
@@ -240,7 +238,7 @@ export function AuthProvider({
|
|
|
240
238
|
error,
|
|
241
239
|
clearError,
|
|
242
240
|
_forceCheck,
|
|
243
|
-
]
|
|
241
|
+
],
|
|
244
242
|
);
|
|
245
243
|
|
|
246
244
|
// ============================================================
|