@nimbleflux/fluxbase-sdk-react 2026.3.6 → 2026.3.7-rc.10

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.
@@ -16,7 +16,7 @@ import type {
16
16
  UploadProgress,
17
17
  TransformOptions,
18
18
  SignedUrlOptions,
19
- } from "@fluxbase/sdk";
19
+ } from "@nimbleflux/fluxbase-sdk";
20
20
 
21
21
  /**
22
22
  * Hook to list files in a bucket
@@ -141,7 +141,9 @@ export function useStorageUploadWithProgress(bucket: string) {
141
141
  .from(bucket)
142
142
  .upload(path, file, {
143
143
  ...options,
144
- onUploadProgress: (p: import("@fluxbase/sdk").UploadProgress) => {
144
+ onUploadProgress: (
145
+ p: import("@nimbleflux/fluxbase-sdk").UploadProgress,
146
+ ) => {
145
147
  setProgress(p);
146
148
  },
147
149
  });
@@ -385,62 +387,6 @@ export function useStorageSignedUrlWithOptions(
385
387
  });
386
388
  }
387
389
 
388
- /**
389
- * Hook to move a file
390
- */
391
- export function useStorageMove(bucket: string) {
392
- const client = useFluxbaseClient();
393
- const queryClient = useQueryClient();
394
-
395
- return useMutation({
396
- mutationFn: async (params: { fromPath: string; toPath: string }) => {
397
- const { fromPath, toPath } = params;
398
- const { data, error } = await client.storage
399
- .from(bucket)
400
- .move(fromPath, toPath);
401
-
402
- if (error) {
403
- throw error;
404
- }
405
-
406
- return data;
407
- },
408
- onSuccess: () => {
409
- queryClient.invalidateQueries({
410
- queryKey: ["fluxbase", "storage", bucket, "list"],
411
- });
412
- },
413
- });
414
- }
415
-
416
- /**
417
- * Hook to copy a file
418
- */
419
- export function useStorageCopy(bucket: string) {
420
- const client = useFluxbaseClient();
421
- const queryClient = useQueryClient();
422
-
423
- return useMutation({
424
- mutationFn: async (params: { fromPath: string; toPath: string }) => {
425
- const { fromPath, toPath } = params;
426
- const { data, error } = await client.storage
427
- .from(bucket)
428
- .copy(fromPath, toPath);
429
-
430
- if (error) {
431
- throw error;
432
- }
433
-
434
- return data;
435
- },
436
- onSuccess: () => {
437
- queryClient.invalidateQueries({
438
- queryKey: ["fluxbase", "storage", bucket, "list"],
439
- });
440
- },
441
- });
442
- }
443
-
444
390
  /**
445
391
  * Hook to manage buckets
446
392
  */
@@ -1,35 +1,28 @@
1
1
  /**
2
2
  * Table Export Hooks
3
3
  *
4
- * React hooks for exporting database tables to knowledge bases and managing sync configurations.
4
+ * React hooks for exporting database tables to knowledge bases.
5
5
  */
6
6
 
7
- import { useState, useEffect, useCallback } from 'react'
8
- import { useFluxbaseClient } from './context'
9
- import type {
10
- ExportTableOptions,
11
- ExportTableResult,
12
- TableDetails,
13
- TableExportSyncConfig,
14
- CreateTableExportSyncConfig,
15
- UpdateTableExportSyncConfig,
16
- } from '@fluxbase/sdk'
7
+ import { useState, useEffect, useCallback } from "react";
8
+ import { useFluxbaseClient } from "./context";
9
+ import type { TableDetails } from "@nimbleflux/fluxbase-sdk";
17
10
 
18
11
  // ============================================================================
19
12
  // useTableDetails Hook
20
13
  // ============================================================================
21
14
 
22
15
  export interface UseTableDetailsOptions {
23
- schema?: string
24
- table?: string
25
- autoFetch?: boolean
16
+ schema?: string;
17
+ table?: string;
18
+ autoFetch?: boolean;
26
19
  }
27
20
 
28
21
  export interface UseTableDetailsReturn {
29
- data: TableDetails | null
30
- isLoading: boolean
31
- error: Error | null
32
- refetch: () => Promise<void>
22
+ data: TableDetails | null;
23
+ isLoading: boolean;
24
+ error: Error | null;
25
+ refetch: () => Promise<void>;
33
26
  }
34
27
 
35
28
  /**
@@ -56,426 +49,44 @@ export interface UseTableDetailsReturn {
56
49
  * }
57
50
  * ```
58
51
  */
59
- export function useTableDetails(options: UseTableDetailsOptions): UseTableDetailsReturn {
60
- const { schema, table, autoFetch = true } = options
61
- const client = useFluxbaseClient()
52
+ export function useTableDetails(
53
+ options: UseTableDetailsOptions,
54
+ ): UseTableDetailsReturn {
55
+ const { schema, table, autoFetch = true } = options;
56
+ const client = useFluxbaseClient();
62
57
 
63
- const [data, setData] = useState<TableDetails | null>(null)
64
- const [isLoading, setIsLoading] = useState(autoFetch && !!schema && !!table)
65
- const [error, setError] = useState<Error | null>(null)
58
+ const [data, setData] = useState<TableDetails | null>(null);
59
+ const [isLoading, setIsLoading] = useState(autoFetch && !!schema && !!table);
60
+ const [error, setError] = useState<Error | null>(null);
66
61
 
67
62
  const fetchData = useCallback(async () => {
68
- if (!schema || !table) return
63
+ if (!schema || !table) return;
69
64
 
70
65
  try {
71
- setIsLoading(true)
72
- setError(null)
73
- const result = await client.admin.ai.getTableDetails(schema, table)
66
+ setIsLoading(true);
67
+ setError(null);
68
+ const result = await client.admin.ai.getTableDetails(schema, table);
74
69
  if (result.error) {
75
- throw result.error
70
+ throw result.error;
76
71
  }
77
- setData(result.data)
72
+ setData(result.data);
78
73
  } catch (err) {
79
- setError(err as Error)
74
+ setError(err as Error);
80
75
  } finally {
81
- setIsLoading(false)
76
+ setIsLoading(false);
82
77
  }
83
- }, [client, schema, table])
78
+ }, [client, schema, table]);
84
79
 
85
80
  useEffect(() => {
86
81
  if (autoFetch && schema && table) {
87
- fetchData()
82
+ fetchData();
88
83
  }
89
- }, [autoFetch, fetchData, schema, table])
84
+ }, [autoFetch, fetchData, schema, table]);
90
85
 
91
86
  return {
92
87
  data,
93
88
  isLoading,
94
89
  error,
95
90
  refetch: fetchData,
96
- }
97
- }
98
-
99
- // ============================================================================
100
- // useExportTable Hook
101
- // ============================================================================
102
-
103
- export interface UseExportTableReturn {
104
- exportTable: (options: ExportTableOptions) => Promise<ExportTableResult | null>
105
- isLoading: boolean
106
- error: Error | null
107
- reset: () => void
108
- }
109
-
110
- /**
111
- * Hook for exporting a table to a knowledge base
112
- *
113
- * @example
114
- * ```tsx
115
- * function ExportTableButton({ kbId, schema, table }: Props) {
116
- * const { exportTable, isLoading, error } = useExportTable(kbId)
117
- *
118
- * const handleExport = async () => {
119
- * const result = await exportTable({
120
- * schema,
121
- * table,
122
- * columns: ['id', 'name', 'email'],
123
- * include_foreign_keys: true,
124
- * })
125
- * if (result) {
126
- * console.log('Exported document:', result.document_id)
127
- * }
128
- * }
129
- *
130
- * return (
131
- * <button onClick={handleExport} disabled={isLoading}>
132
- * {isLoading ? 'Exporting...' : 'Export Table'}
133
- * </button>
134
- * )
135
- * }
136
- * ```
137
- */
138
- export function useExportTable(knowledgeBaseId: string): UseExportTableReturn {
139
- const client = useFluxbaseClient()
140
-
141
- const [isLoading, setIsLoading] = useState(false)
142
- const [error, setError] = useState<Error | null>(null)
143
-
144
- const exportTable = useCallback(
145
- async (options: ExportTableOptions): Promise<ExportTableResult | null> => {
146
- try {
147
- setIsLoading(true)
148
- setError(null)
149
- const result = await client.admin.ai.exportTable(knowledgeBaseId, options)
150
- if (result.error) {
151
- throw result.error
152
- }
153
- return result.data
154
- } catch (err) {
155
- setError(err as Error)
156
- return null
157
- } finally {
158
- setIsLoading(false)
159
- }
160
- },
161
- [client, knowledgeBaseId],
162
- )
163
-
164
- const reset = useCallback(() => {
165
- setError(null)
166
- setIsLoading(false)
167
- }, [])
168
-
169
- return {
170
- exportTable,
171
- isLoading,
172
- error,
173
- reset,
174
- }
175
- }
176
-
177
- // ============================================================================
178
- // useTableExportSyncs Hook
179
- // ============================================================================
180
-
181
- export interface UseTableExportSyncsOptions {
182
- autoFetch?: boolean
183
- }
184
-
185
- export interface UseTableExportSyncsReturn {
186
- configs: TableExportSyncConfig[]
187
- isLoading: boolean
188
- error: Error | null
189
- refetch: () => Promise<void>
190
- }
191
-
192
- /**
193
- * Hook for listing table export sync configurations
194
- *
195
- * @example
196
- * ```tsx
197
- * function SyncConfigsList({ kbId }: { kbId: string }) {
198
- * const { configs, isLoading, error } = useTableExportSyncs(kbId)
199
- *
200
- * if (isLoading) return <div>Loading...</div>
201
- *
202
- * return (
203
- * <ul>
204
- * {configs.map(config => (
205
- * <li key={config.id}>
206
- * {config.schema_name}.{config.table_name} ({config.sync_mode})
207
- * </li>
208
- * ))}
209
- * </ul>
210
- * )
211
- * }
212
- * ```
213
- */
214
- export function useTableExportSyncs(
215
- knowledgeBaseId: string,
216
- options: UseTableExportSyncsOptions = {},
217
- ): UseTableExportSyncsReturn {
218
- const { autoFetch = true } = options
219
- const client = useFluxbaseClient()
220
-
221
- const [configs, setConfigs] = useState<TableExportSyncConfig[]>([])
222
- const [isLoading, setIsLoading] = useState(autoFetch)
223
- const [error, setError] = useState<Error | null>(null)
224
-
225
- const fetchData = useCallback(async () => {
226
- try {
227
- setIsLoading(true)
228
- setError(null)
229
- const result = await client.admin.ai.listTableExportSyncs(knowledgeBaseId)
230
- if (result.error) {
231
- throw result.error
232
- }
233
- setConfigs(result.data || [])
234
- } catch (err) {
235
- setError(err as Error)
236
- } finally {
237
- setIsLoading(false)
238
- }
239
- }, [client, knowledgeBaseId])
240
-
241
- useEffect(() => {
242
- if (autoFetch) {
243
- fetchData()
244
- }
245
- }, [autoFetch, fetchData])
246
-
247
- return {
248
- configs,
249
- isLoading,
250
- error,
251
- refetch: fetchData,
252
- }
253
- }
254
-
255
- // ============================================================================
256
- // useCreateTableExportSync Hook
257
- // ============================================================================
258
-
259
- export interface UseCreateTableExportSyncReturn {
260
- createSync: (config: CreateTableExportSyncConfig) => Promise<TableExportSyncConfig | null>
261
- isLoading: boolean
262
- error: Error | null
263
- }
264
-
265
- /**
266
- * Hook for creating a table export sync configuration
267
- *
268
- * @example
269
- * ```tsx
270
- * function CreateSyncForm({ kbId }: { kbId: string }) {
271
- * const { createSync, isLoading, error } = useCreateTableExportSync(kbId)
272
- *
273
- * const handleSubmit = async (e: React.FormEvent) => {
274
- * e.preventDefault()
275
- * const config = await createSync({
276
- * schema_name: 'public',
277
- * table_name: 'users',
278
- * columns: ['id', 'name', 'email'],
279
- * sync_mode: 'automatic',
280
- * sync_on_insert: true,
281
- * sync_on_update: true,
282
- * })
283
- * if (config) {
284
- * console.log('Created sync config:', config.id)
285
- * }
286
- * }
287
- *
288
- * return <form onSubmit={handleSubmit}>...</form>
289
- * }
290
- * ```
291
- */
292
- export function useCreateTableExportSync(knowledgeBaseId: string): UseCreateTableExportSyncReturn {
293
- const client = useFluxbaseClient()
294
-
295
- const [isLoading, setIsLoading] = useState(false)
296
- const [error, setError] = useState<Error | null>(null)
297
-
298
- const createSync = useCallback(
299
- async (config: CreateTableExportSyncConfig): Promise<TableExportSyncConfig | null> => {
300
- try {
301
- setIsLoading(true)
302
- setError(null)
303
- const result = await client.admin.ai.createTableExportSync(knowledgeBaseId, config)
304
- if (result.error) {
305
- throw result.error
306
- }
307
- return result.data
308
- } catch (err) {
309
- setError(err as Error)
310
- return null
311
- } finally {
312
- setIsLoading(false)
313
- }
314
- },
315
- [client, knowledgeBaseId],
316
- )
317
-
318
- return {
319
- createSync,
320
- isLoading,
321
- error,
322
- }
323
- }
324
-
325
- // ============================================================================
326
- // useUpdateTableExportSync Hook
327
- // ============================================================================
328
-
329
- export interface UseUpdateTableExportSyncReturn {
330
- updateSync: (syncId: string, updates: UpdateTableExportSyncConfig) => Promise<TableExportSyncConfig | null>
331
- isLoading: boolean
332
- error: Error | null
333
- }
334
-
335
- /**
336
- * Hook for updating a table export sync configuration
337
- */
338
- export function useUpdateTableExportSync(knowledgeBaseId: string): UseUpdateTableExportSyncReturn {
339
- const client = useFluxbaseClient()
340
-
341
- const [isLoading, setIsLoading] = useState(false)
342
- const [error, setError] = useState<Error | null>(null)
343
-
344
- const updateSync = useCallback(
345
- async (syncId: string, updates: UpdateTableExportSyncConfig): Promise<TableExportSyncConfig | null> => {
346
- try {
347
- setIsLoading(true)
348
- setError(null)
349
- const result = await client.admin.ai.updateTableExportSync(knowledgeBaseId, syncId, updates)
350
- if (result.error) {
351
- throw result.error
352
- }
353
- return result.data
354
- } catch (err) {
355
- setError(err as Error)
356
- return null
357
- } finally {
358
- setIsLoading(false)
359
- }
360
- },
361
- [client, knowledgeBaseId],
362
- )
363
-
364
- return {
365
- updateSync,
366
- isLoading,
367
- error,
368
- }
369
- }
370
-
371
- // ============================================================================
372
- // useDeleteTableExportSync Hook
373
- // ============================================================================
374
-
375
- export interface UseDeleteTableExportSyncReturn {
376
- deleteSync: (syncId: string) => Promise<boolean>
377
- isLoading: boolean
378
- error: Error | null
379
- }
380
-
381
- /**
382
- * Hook for deleting a table export sync configuration
383
- */
384
- export function useDeleteTableExportSync(knowledgeBaseId: string): UseDeleteTableExportSyncReturn {
385
- const client = useFluxbaseClient()
386
-
387
- const [isLoading, setIsLoading] = useState(false)
388
- const [error, setError] = useState<Error | null>(null)
389
-
390
- const deleteSync = useCallback(
391
- async (syncId: string): Promise<boolean> => {
392
- try {
393
- setIsLoading(true)
394
- setError(null)
395
- const result = await client.admin.ai.deleteTableExportSync(knowledgeBaseId, syncId)
396
- if (result.error) {
397
- throw result.error
398
- }
399
- return true
400
- } catch (err) {
401
- setError(err as Error)
402
- return false
403
- } finally {
404
- setIsLoading(false)
405
- }
406
- },
407
- [client, knowledgeBaseId],
408
- )
409
-
410
- return {
411
- deleteSync,
412
- isLoading,
413
- error,
414
- }
415
- }
416
-
417
- // ============================================================================
418
- // useTriggerTableExportSync Hook
419
- // ============================================================================
420
-
421
- export interface UseTriggerTableExportSyncReturn {
422
- triggerSync: (syncId: string) => Promise<ExportTableResult | null>
423
- isLoading: boolean
424
- error: Error | null
425
- }
426
-
427
- /**
428
- * Hook for manually triggering a table export sync
429
- *
430
- * @example
431
- * ```tsx
432
- * function TriggerSyncButton({ kbId, syncId }: Props) {
433
- * const { triggerSync, isLoading, error } = useTriggerTableExportSync(kbId)
434
- *
435
- * const handleTrigger = async () => {
436
- * const result = await triggerSync(syncId)
437
- * if (result) {
438
- * console.log('Sync completed:', result.document_id)
439
- * }
440
- * }
441
- *
442
- * return (
443
- * <button onClick={handleTrigger} disabled={isLoading}>
444
- * {isLoading ? 'Syncing...' : 'Sync Now'}
445
- * </button>
446
- * )
447
- * }
448
- * ```
449
- */
450
- export function useTriggerTableExportSync(knowledgeBaseId: string): UseTriggerTableExportSyncReturn {
451
- const client = useFluxbaseClient()
452
-
453
- const [isLoading, setIsLoading] = useState(false)
454
- const [error, setError] = useState<Error | null>(null)
455
-
456
- const triggerSync = useCallback(
457
- async (syncId: string): Promise<ExportTableResult | null> => {
458
- try {
459
- setIsLoading(true)
460
- setError(null)
461
- const result = await client.admin.ai.triggerTableExportSync(knowledgeBaseId, syncId)
462
- if (result.error) {
463
- throw result.error
464
- }
465
- return result.data
466
- } catch (err) {
467
- setError(err as Error)
468
- return null
469
- } finally {
470
- setIsLoading(false)
471
- }
472
- },
473
- [client, knowledgeBaseId],
474
- )
475
-
476
- return {
477
- triggerSync,
478
- isLoading,
479
- error,
480
- }
91
+ };
481
92
  }