@ram_28/kf-ai-sdk 1.0.18 → 1.0.20

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 (77) hide show
  1. package/README.md +45 -12
  2. package/dist/api/client.d.ts.map +1 -1
  3. package/dist/api.cjs +1 -1
  4. package/dist/api.mjs +2 -2
  5. package/dist/auth.cjs +1 -1
  6. package/dist/auth.mjs +1 -1
  7. package/dist/{client-C15j4O5B.cjs → client-DgtkT50N.cjs} +1 -1
  8. package/dist/{client-CfvLiGfP.js → client-V-WzUb8H.js} +9 -5
  9. package/dist/components/hooks/useFilter/types.d.ts +14 -11
  10. package/dist/components/hooks/useFilter/types.d.ts.map +1 -1
  11. package/dist/components/hooks/useFilter/useFilter.d.ts +1 -1
  12. package/dist/components/hooks/useFilter/useFilter.d.ts.map +1 -1
  13. package/dist/components/hooks/useForm/apiClient.d.ts.map +1 -1
  14. package/dist/components/hooks/useForm/useForm.d.ts.map +1 -1
  15. package/dist/components/hooks/useKanban/context.d.ts +1 -1
  16. package/dist/components/hooks/useKanban/context.d.ts.map +1 -1
  17. package/dist/components/hooks/useKanban/types.d.ts +5 -22
  18. package/dist/components/hooks/useKanban/types.d.ts.map +1 -1
  19. package/dist/components/hooks/useKanban/useKanban.d.ts.map +1 -1
  20. package/dist/components/hooks/useTable/types.d.ts +19 -31
  21. package/dist/components/hooks/useTable/types.d.ts.map +1 -1
  22. package/dist/components/hooks/useTable/useTable.d.ts.map +1 -1
  23. package/dist/error-handling-CAoD0Kwb.cjs +1 -0
  24. package/dist/error-handling-CrhTtD88.js +14 -0
  25. package/dist/filter.cjs +1 -1
  26. package/dist/filter.mjs +1 -1
  27. package/dist/form.cjs +1 -1
  28. package/dist/form.mjs +825 -814
  29. package/dist/index.d.ts +18 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/kanban.cjs +2 -2
  32. package/dist/kanban.mjs +335 -323
  33. package/dist/{metadata-2FLBsFcf.cjs → metadata-0lZAfuTP.cjs} +1 -1
  34. package/dist/{metadata-DBcoDth-.js → metadata-B88D_pVS.js} +1 -1
  35. package/dist/table.cjs +1 -1
  36. package/dist/table.mjs +113 -96
  37. package/dist/table.types.d.ts +1 -1
  38. package/dist/table.types.d.ts.map +1 -1
  39. package/dist/types/common.d.ts +26 -6
  40. package/dist/types/common.d.ts.map +1 -1
  41. package/dist/useFilter-DzpP_ag0.cjs +1 -0
  42. package/dist/useFilter-H5bgAZQF.js +120 -0
  43. package/dist/utils/api/buildListOptions.d.ts +43 -0
  44. package/dist/utils/api/buildListOptions.d.ts.map +1 -0
  45. package/dist/utils/api/index.d.ts +2 -0
  46. package/dist/utils/api/index.d.ts.map +1 -0
  47. package/dist/utils/error-handling.d.ts +41 -0
  48. package/dist/utils/error-handling.d.ts.map +1 -0
  49. package/dist/utils/index.d.ts +2 -0
  50. package/dist/utils/index.d.ts.map +1 -1
  51. package/docs/QUICK_REFERENCE.md +142 -420
  52. package/docs/useAuth.md +52 -340
  53. package/docs/useFilter.md +858 -162
  54. package/docs/useForm.md +712 -501
  55. package/docs/useKanban.md +534 -279
  56. package/docs/useTable.md +725 -214
  57. package/package.json +1 -1
  58. package/sdk/api/client.ts +7 -1
  59. package/sdk/components/hooks/useFilter/types.ts +14 -11
  60. package/sdk/components/hooks/useFilter/useFilter.ts +20 -18
  61. package/sdk/components/hooks/useForm/apiClient.ts +2 -1
  62. package/sdk/components/hooks/useForm/useForm.ts +47 -13
  63. package/sdk/components/hooks/useKanban/context.ts +5 -3
  64. package/sdk/components/hooks/useKanban/types.ts +7 -23
  65. package/sdk/components/hooks/useKanban/useKanban.ts +54 -18
  66. package/sdk/components/hooks/useTable/types.ts +26 -32
  67. package/sdk/components/hooks/useTable/useTable.llm.txt +8 -22
  68. package/sdk/components/hooks/useTable/useTable.ts +70 -25
  69. package/sdk/index.ts +154 -10
  70. package/sdk/table.types.ts +3 -0
  71. package/sdk/types/common.ts +31 -6
  72. package/sdk/utils/api/buildListOptions.ts +120 -0
  73. package/sdk/utils/api/index.ts +2 -0
  74. package/sdk/utils/error-handling.ts +150 -0
  75. package/sdk/utils/index.ts +6 -0
  76. package/dist/useFilter-Dofowpr_.cjs +0 -1
  77. package/dist/useFilter-Dv-mr9QW.js +0 -117
@@ -0,0 +1,120 @@
1
+ // ============================================================
2
+ // BUILD LIST OPTIONS UTILITY
3
+ // ============================================================
4
+ // Shared utility for building API list options across hooks
5
+
6
+ import type { ListOptionsType, FilterType, SortType } from "../../types/common";
7
+
8
+ /**
9
+ * Options for building list API request options
10
+ */
11
+ export interface BuildListOptionsParams<T = any> {
12
+ /** Search query string */
13
+ search?: string;
14
+ /** Filter payload */
15
+ filter?: FilterType<T>;
16
+ /** Sort configuration */
17
+ sort?: {
18
+ field: keyof T | null;
19
+ direction: "asc" | "desc" | null;
20
+ };
21
+ /** Sort array in API format */
22
+ sortArray?: SortType;
23
+ /** Pagination settings */
24
+ pagination?: {
25
+ pageNo: number;
26
+ pageSize: number;
27
+ };
28
+ }
29
+
30
+ /**
31
+ * Build list options for count queries
32
+ * Excludes pagination and sorting (they don't affect count)
33
+ */
34
+ export function buildCountOptions<T = any>(
35
+ params: Pick<BuildListOptionsParams<T>, "search" | "filter">
36
+ ): ListOptionsType {
37
+ const opts: ListOptionsType = {};
38
+
39
+ if (params.search) {
40
+ opts.Search = params.search;
41
+ }
42
+
43
+ if (params.filter) {
44
+ opts.Filter = params.filter;
45
+ }
46
+
47
+ return opts;
48
+ }
49
+
50
+ /**
51
+ * Build list options for data queries
52
+ * Includes all options: search, filter, sort, pagination
53
+ */
54
+ export function buildListOptions<T = any>(
55
+ params: BuildListOptionsParams<T>
56
+ ): ListOptionsType {
57
+ const opts: ListOptionsType = buildCountOptions({
58
+ search: params.search,
59
+ filter: params.filter,
60
+ });
61
+
62
+ // Add sorting - convert internal format to API format
63
+ if (params.sort?.field && params.sort?.direction) {
64
+ opts.Sort = [
65
+ {
66
+ [String(params.sort.field)]:
67
+ params.sort.direction === "asc" ? "ASC" : "DESC",
68
+ },
69
+ ];
70
+ } else if (params.sortArray) {
71
+ opts.Sort = params.sortArray;
72
+ }
73
+
74
+ // Add pagination
75
+ if (params.pagination) {
76
+ opts.Page = params.pagination.pageNo;
77
+ opts.PageSize = params.pagination.pageSize;
78
+ }
79
+
80
+ return opts;
81
+ }
82
+
83
+ /**
84
+ * Combine filter payload with additional column filter
85
+ * Used for kanban column-specific queries
86
+ */
87
+ export function combineFilters<T = any>(
88
+ baseFilter: FilterType<T> | undefined,
89
+ additionalCondition: {
90
+ LHSField: string;
91
+ Operator: string;
92
+ RHSValue: any;
93
+ RHSType?: string;
94
+ }
95
+ ): FilterType<T> {
96
+ const columnFilterObject = {
97
+ ...additionalCondition,
98
+ RHSType: additionalCondition.RHSType || "Constant",
99
+ };
100
+
101
+ if (!baseFilter) {
102
+ return {
103
+ Operator: "And",
104
+ Condition: [columnFilterObject],
105
+ } as FilterType<T>;
106
+ }
107
+
108
+ // If base is And, append. If base is Or/Not, wrap in new And.
109
+ if (baseFilter.Operator === "And") {
110
+ return {
111
+ ...baseFilter,
112
+ Condition: [...(baseFilter.Condition || []), columnFilterObject],
113
+ } as FilterType<T>;
114
+ }
115
+
116
+ return {
117
+ Operator: "And",
118
+ Condition: [baseFilter, columnFilterObject],
119
+ } as FilterType<T>;
120
+ }
@@ -0,0 +1,2 @@
1
+ // API utilities
2
+ export * from "./buildListOptions";
@@ -0,0 +1,150 @@
1
+ // ============================================================
2
+ // ERROR HANDLING UTILITIES
3
+ // ============================================================
4
+ // Type-safe error handling utilities for the SDK
5
+
6
+ /**
7
+ * Safely convert unknown error to Error object
8
+ * Handles all possible error types that could be thrown
9
+ */
10
+ export function toError(err: unknown): Error {
11
+ // Already an Error instance
12
+ if (err instanceof Error) {
13
+ return err;
14
+ }
15
+
16
+ // String error
17
+ if (typeof err === "string") {
18
+ return new Error(err);
19
+ }
20
+
21
+ // Object with message property
22
+ if (
23
+ err !== null &&
24
+ typeof err === "object" &&
25
+ "message" in err &&
26
+ typeof (err as { message: unknown }).message === "string"
27
+ ) {
28
+ const error = new Error((err as { message: string }).message);
29
+ // Preserve any additional properties
30
+ Object.assign(error, err);
31
+ return error;
32
+ }
33
+
34
+ // Fallback: convert to string
35
+ return new Error(String(err));
36
+ }
37
+
38
+ /**
39
+ * Type guard to check if a value is an Error
40
+ */
41
+ export function isError(value: unknown): value is Error {
42
+ return value instanceof Error;
43
+ }
44
+
45
+ /**
46
+ * Type guard to check if error has a specific code
47
+ */
48
+ export function hasErrorCode(
49
+ err: unknown,
50
+ code: string
51
+ ): err is Error & { code: string } {
52
+ return (
53
+ err instanceof Error &&
54
+ "code" in err &&
55
+ (err as Error & { code: unknown }).code === code
56
+ );
57
+ }
58
+
59
+ /**
60
+ * Type guard to check if error is a network error
61
+ */
62
+ export function isNetworkError(err: unknown): boolean {
63
+ if (!isError(err)) return false;
64
+
65
+ const message = err.message.toLowerCase();
66
+ return (
67
+ message.includes("network") ||
68
+ message.includes("fetch") ||
69
+ message.includes("connection") ||
70
+ hasErrorCode(err, "NETWORK_ERROR") ||
71
+ hasErrorCode(err, "ENOTFOUND") ||
72
+ hasErrorCode(err, "ECONNREFUSED")
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Type guard to check if error is a timeout error
78
+ */
79
+ export function isTimeoutError(err: unknown): boolean {
80
+ if (!isError(err)) return false;
81
+
82
+ return (
83
+ err.message.toLowerCase().includes("timeout") ||
84
+ hasErrorCode(err, "TIMEOUT") ||
85
+ hasErrorCode(err, "ETIMEDOUT")
86
+ );
87
+ }
88
+
89
+ /**
90
+ * Type guard to check if error is an abort error
91
+ */
92
+ export function isAbortError(err: unknown): boolean {
93
+ if (!isError(err)) return false;
94
+
95
+ return err.name === "AbortError" || hasErrorCode(err, "ABORT_ERR");
96
+ }
97
+
98
+ /**
99
+ * Extract error message from unknown error
100
+ */
101
+ export function getErrorMessage(err: unknown): string {
102
+ if (isError(err)) {
103
+ return err.message;
104
+ }
105
+
106
+ if (typeof err === "string") {
107
+ return err;
108
+ }
109
+
110
+ if (
111
+ err !== null &&
112
+ typeof err === "object" &&
113
+ "message" in err &&
114
+ typeof (err as { message: unknown }).message === "string"
115
+ ) {
116
+ return (err as { message: string }).message;
117
+ }
118
+
119
+ return String(err);
120
+ }
121
+
122
+ /**
123
+ * Safe error handler wrapper for async functions
124
+ * Returns a tuple of [result, error]
125
+ */
126
+ export async function tryCatch<T>(
127
+ fn: () => Promise<T>
128
+ ): Promise<[T, null] | [null, Error]> {
129
+ try {
130
+ const result = await fn();
131
+ return [result, null];
132
+ } catch (err) {
133
+ return [null, toError(err)];
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Create a wrapped error with original error as cause
139
+ */
140
+ export function wrapError(message: string, cause: unknown): Error {
141
+ const error = new Error(message);
142
+ // Use Object.defineProperty for broader compatibility
143
+ Object.defineProperty(error, 'cause', {
144
+ value: toError(cause),
145
+ writable: true,
146
+ enumerable: false,
147
+ configurable: true,
148
+ });
149
+ return error;
150
+ }
@@ -3,3 +3,9 @@ export * from "./formatting";
3
3
 
4
4
  // Class name utilities
5
5
  export * from "./cn";
6
+
7
+ // Error handling utilities
8
+ export * from "./error-handling";
9
+
10
+ // API utilities
11
+ export * from "./api";
@@ -1 +0,0 @@
1
- "use strict";const u=require("react"),d=r=>"Condition"in r,R=r=>"LHSField"in r;let _=0;const l=()=>`filter_${Date.now()}_${++_}`,$=r=>r.id?r:{...r,id:l()},k=r=>r.map(o=>{const n=$(o);return d(n)?{...n,Condition:k(n.Condition)}:n}),O=r=>r.map(o=>{if(d(o)){const{id:b,...C}=o;return{...C,Condition:O(o.Condition)}}const{id:n,...t}=o;return t}),h=(r,o)=>{for(const n of r){if(n.id===o)return n;if(d(n)){const t=h(n.Condition,o);if(t)return t}}},f=(r,o,n)=>r.map(t=>t.id===o?n(t):d(t)?{...t,Condition:f(t.Condition,o,n)}:t),G=(r,o)=>r.filter(n=>n.id!==o).map(n=>d(n)?{...n,Condition:G(n.Condition,o)}:n),p=(r,o,n)=>r.map(t=>t.id===o&&d(t)?{...t,Condition:[...t.Condition,n]}:d(t)?{...t,Condition:p(t.Condition,o,n)}:t);function q(r={}){const[o,n]=u.useState(()=>k(r.initialConditions||[])),[t,b]=u.useState(r.initialOperator||"And"),C=u.useMemo(()=>{if(o.length!==0)return{Operator:t,Condition:O(o)}},[o,t]),g=o.length>0,v=u.useCallback((i,s)=>{const c=l(),e={...i,id:c};return n(s?a=>p(a,s,e):a=>[...a,e]),c},[]),F=u.useCallback((i,s)=>{const c=l(),e={id:c,Operator:i,Condition:[]};return n(s?a=>p(a,s,e):a=>[...a,e]),c},[]),I=u.useCallback((i,s)=>{n(c=>f(c,i,e=>d(e)?e:{...e,...s}))},[]),S=u.useCallback((i,s)=>{n(c=>f(c,i,e=>d(e)?{...e,Operator:s}:e))},[]),w=u.useCallback(i=>{n(s=>G(s,i))},[]),T=u.useCallback(i=>h(o,i),[o]),y=u.useCallback(()=>{n([])},[]),A=u.useCallback(i=>{b(i)},[]);return{operator:t,items:o,payload:C,hasConditions:g,addCondition:v,addConditionGroup:F,updateCondition:I,updateGroupOperator:S,removeCondition:w,getCondition:T,clearAllConditions:y,setRootOperator:A}}exports.isCondition=R;exports.isConditionGroup=d;exports.useFilter=q;
@@ -1,117 +0,0 @@
1
- import { useState as h, useMemo as k, useCallback as c } from "react";
2
- const u = (t) => "Condition" in t, H = (t) => "LHSField" in t;
3
- let x = 0;
4
- const f = () => `filter_${Date.now()}_${++x}`, B = (t) => t.id ? t : { ...t, id: f() }, g = (t) => t.map((o) => {
5
- const n = B(o);
6
- return u(n) ? {
7
- ...n,
8
- Condition: g(n.Condition)
9
- } : n;
10
- }), v = (t) => t.map((o) => {
11
- if (u(o)) {
12
- const { id: O, ...C } = o;
13
- return {
14
- ...C,
15
- Condition: v(o.Condition)
16
- };
17
- }
18
- const { id: n, ...r } = o;
19
- return r;
20
- }), G = (t, o) => {
21
- for (const n of t) {
22
- if (n.id === o)
23
- return n;
24
- if (u(n)) {
25
- const r = G(n.Condition, o);
26
- if (r) return r;
27
- }
28
- }
29
- }, p = (t, o, n) => t.map((r) => r.id === o ? n(r) : u(r) ? {
30
- ...r,
31
- Condition: p(r.Condition, o, n)
32
- } : r), I = (t, o) => t.filter((n) => n.id !== o).map((n) => u(n) ? {
33
- ...n,
34
- Condition: I(n.Condition, o)
35
- } : n), l = (t, o, n) => t.map((r) => r.id === o && u(r) ? {
36
- ...r,
37
- Condition: [...r.Condition, n]
38
- } : u(r) ? {
39
- ...r,
40
- Condition: l(r.Condition, o, n)
41
- } : r);
42
- function L(t = {}) {
43
- const [o, n] = h(
44
- () => g(t.initialConditions || [])
45
- ), [r, O] = h(
46
- t.initialOperator || "And"
47
- ), C = k(() => {
48
- if (o.length !== 0)
49
- return {
50
- Operator: r,
51
- Condition: v(o)
52
- };
53
- }, [o, r]), w = o.length > 0, F = c(
54
- (i, s) => {
55
- const d = f(), e = { ...i, id: d };
56
- return n(s ? (a) => l(a, s, e) : (a) => [...a, e]), d;
57
- },
58
- []
59
- ), S = c(
60
- (i, s) => {
61
- const d = f(), e = {
62
- id: d,
63
- Operator: i,
64
- Condition: []
65
- };
66
- return n(s ? (a) => l(a, s, e) : (a) => [...a, e]), d;
67
- },
68
- []
69
- ), T = c(
70
- (i, s) => {
71
- n(
72
- (d) => p(d, i, (e) => u(e) ? e : { ...e, ...s })
73
- );
74
- },
75
- []
76
- ), y = c(
77
- (i, s) => {
78
- n(
79
- (d) => p(d, i, (e) => u(e) ? { ...e, Operator: s } : e)
80
- );
81
- },
82
- []
83
- ), A = c((i) => {
84
- n((s) => I(s, i));
85
- }, []), _ = c(
86
- (i) => G(o, i),
87
- [o]
88
- ), $ = c(() => {
89
- n([]);
90
- }, []), b = c((i) => {
91
- O(i);
92
- }, []);
93
- return {
94
- // State
95
- operator: r,
96
- items: o,
97
- payload: C,
98
- hasConditions: w,
99
- // Add operations
100
- addCondition: F,
101
- addConditionGroup: S,
102
- // Update operations
103
- updateCondition: T,
104
- updateGroupOperator: y,
105
- // Remove & access
106
- removeCondition: A,
107
- getCondition: _,
108
- // Utility
109
- clearAllConditions: $,
110
- setRootOperator: b
111
- };
112
- }
113
- export {
114
- u as a,
115
- H as i,
116
- L as u
117
- };