@fluxbase/sdk-react 2026.2.8 → 2026.3.2-rc.3

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/index.js DELETED
@@ -1,1637 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- FluxbaseProvider: () => FluxbaseProvider,
24
- isCaptchaRequiredForEndpoint: () => isCaptchaRequiredForEndpoint,
25
- useAPIKeys: () => useAPIKeys,
26
- useAdminAuth: () => useAdminAuth,
27
- useAppSettings: () => useAppSettings,
28
- useAuth: () => useAuth,
29
- useAuthConfig: () => useAuthConfig,
30
- useCaptcha: () => useCaptcha,
31
- useCaptchaConfig: () => useCaptchaConfig,
32
- useClientKeys: () => useClientKeys,
33
- useCreateBucket: () => useCreateBucket,
34
- useCreateTableExportSync: () => useCreateTableExportSync,
35
- useDelete: () => useDelete,
36
- useDeleteBucket: () => useDeleteBucket,
37
- useDeleteTableExportSync: () => useDeleteTableExportSync,
38
- useExportTable: () => useExportTable,
39
- useFluxbaseClient: () => useFluxbaseClient,
40
- useFluxbaseQuery: () => useFluxbaseQuery,
41
- useGetSAMLLoginUrl: () => useGetSAMLLoginUrl,
42
- useGraphQL: () => useGraphQL,
43
- useGraphQLIntrospection: () => useGraphQLIntrospection,
44
- useGraphQLMutation: () => useGraphQLMutation,
45
- useGraphQLQuery: () => useGraphQLQuery,
46
- useHandleSAMLCallback: () => useHandleSAMLCallback,
47
- useInsert: () => useInsert,
48
- useRealtime: () => useRealtime,
49
- useSAMLMetadataUrl: () => useSAMLMetadataUrl,
50
- useSAMLProviders: () => useSAMLProviders,
51
- useSession: () => useSession,
52
- useSignIn: () => useSignIn,
53
- useSignInWithSAML: () => useSignInWithSAML,
54
- useSignOut: () => useSignOut,
55
- useSignUp: () => useSignUp,
56
- useStorageBuckets: () => useStorageBuckets,
57
- useStorageCopy: () => useStorageCopy,
58
- useStorageDelete: () => useStorageDelete,
59
- useStorageDownload: () => useStorageDownload,
60
- useStorageList: () => useStorageList,
61
- useStorageMove: () => useStorageMove,
62
- useStoragePublicUrl: () => useStoragePublicUrl,
63
- useStorageSignedUrl: () => useStorageSignedUrl,
64
- useStorageSignedUrlWithOptions: () => useStorageSignedUrlWithOptions,
65
- useStorageTransformUrl: () => useStorageTransformUrl,
66
- useStorageUpload: () => useStorageUpload,
67
- useStorageUploadWithProgress: () => useStorageUploadWithProgress,
68
- useSystemSettings: () => useSystemSettings,
69
- useTable: () => useTable,
70
- useTableDeletes: () => useTableDeletes,
71
- useTableDetails: () => useTableDetails,
72
- useTableExportSyncs: () => useTableExportSyncs,
73
- useTableInserts: () => useTableInserts,
74
- useTableSubscription: () => useTableSubscription,
75
- useTableUpdates: () => useTableUpdates,
76
- useTriggerTableExportSync: () => useTriggerTableExportSync,
77
- useUpdate: () => useUpdate,
78
- useUpdateTableExportSync: () => useUpdateTableExportSync,
79
- useUpdateUser: () => useUpdateUser,
80
- useUpsert: () => useUpsert,
81
- useUser: () => useUser,
82
- useUsers: () => useUsers,
83
- useWebhooks: () => useWebhooks
84
- });
85
- module.exports = __toCommonJS(index_exports);
86
-
87
- // src/context.tsx
88
- var import_react = require("react");
89
- var import_jsx_runtime = require("react/jsx-runtime");
90
- var FluxbaseContext = (0, import_react.createContext)(null);
91
- function FluxbaseProvider({ client, children }) {
92
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FluxbaseContext.Provider, { value: client, children });
93
- }
94
- function useFluxbaseClient() {
95
- const client = (0, import_react.useContext)(FluxbaseContext);
96
- if (!client) {
97
- throw new Error("useFluxbaseClient must be used within a FluxbaseProvider");
98
- }
99
- return client;
100
- }
101
-
102
- // src/use-auth.ts
103
- var import_react_query = require("@tanstack/react-query");
104
- function useUser() {
105
- const client = useFluxbaseClient();
106
- return (0, import_react_query.useQuery)({
107
- queryKey: ["fluxbase", "auth", "user"],
108
- queryFn: async () => {
109
- const { data } = await client.auth.getSession();
110
- if (!data?.session) {
111
- return null;
112
- }
113
- try {
114
- const result = await client.auth.getCurrentUser();
115
- return result.data?.user ?? null;
116
- } catch {
117
- return null;
118
- }
119
- },
120
- staleTime: 1e3 * 60 * 5
121
- // 5 minutes
122
- });
123
- }
124
- function useSession() {
125
- const client = useFluxbaseClient();
126
- return (0, import_react_query.useQuery)({
127
- queryKey: ["fluxbase", "auth", "session"],
128
- queryFn: async () => {
129
- const { data } = await client.auth.getSession();
130
- return data?.session ?? null;
131
- },
132
- staleTime: 1e3 * 60 * 5
133
- // 5 minutes
134
- });
135
- }
136
- function useSignIn() {
137
- const client = useFluxbaseClient();
138
- const queryClient = (0, import_react_query.useQueryClient)();
139
- return (0, import_react_query.useMutation)({
140
- mutationFn: async (credentials) => {
141
- return await client.auth.signIn(credentials);
142
- },
143
- onSuccess: (session) => {
144
- queryClient.setQueryData(["fluxbase", "auth", "session"], session);
145
- if (session && "user" in session && session.user) {
146
- queryClient.setQueryData(["fluxbase", "auth", "user"], session.user);
147
- }
148
- }
149
- });
150
- }
151
- function useSignUp() {
152
- const client = useFluxbaseClient();
153
- const queryClient = (0, import_react_query.useQueryClient)();
154
- return (0, import_react_query.useMutation)({
155
- mutationFn: async (credentials) => {
156
- return await client.auth.signUp(credentials);
157
- },
158
- onSuccess: (response) => {
159
- if (response.data) {
160
- queryClient.setQueryData(
161
- ["fluxbase", "auth", "session"],
162
- response.data.session
163
- );
164
- queryClient.setQueryData(
165
- ["fluxbase", "auth", "user"],
166
- response.data.user
167
- );
168
- }
169
- }
170
- });
171
- }
172
- function useSignOut() {
173
- const client = useFluxbaseClient();
174
- const queryClient = (0, import_react_query.useQueryClient)();
175
- return (0, import_react_query.useMutation)({
176
- mutationFn: async () => {
177
- await client.auth.signOut();
178
- },
179
- onSuccess: () => {
180
- queryClient.setQueryData(["fluxbase", "auth", "session"], null);
181
- queryClient.setQueryData(["fluxbase", "auth", "user"], null);
182
- queryClient.invalidateQueries({ queryKey: ["fluxbase"] });
183
- }
184
- });
185
- }
186
- function useUpdateUser() {
187
- const client = useFluxbaseClient();
188
- const queryClient = (0, import_react_query.useQueryClient)();
189
- return (0, import_react_query.useMutation)({
190
- mutationFn: async (data) => {
191
- return await client.auth.updateUser(data);
192
- },
193
- onSuccess: (user) => {
194
- queryClient.setQueryData(["fluxbase", "auth", "user"], user);
195
- }
196
- });
197
- }
198
- function useAuth() {
199
- const { data: user, isLoading: isLoadingUser } = useUser();
200
- const { data: session, isLoading: isLoadingSession } = useSession();
201
- const signIn = useSignIn();
202
- const signUp = useSignUp();
203
- const signOut = useSignOut();
204
- const updateUser = useUpdateUser();
205
- return {
206
- user,
207
- session,
208
- isLoading: isLoadingUser || isLoadingSession,
209
- isAuthenticated: !!session,
210
- signIn: signIn.mutateAsync,
211
- signUp: signUp.mutateAsync,
212
- signOut: signOut.mutateAsync,
213
- updateUser: updateUser.mutateAsync,
214
- isSigningIn: signIn.isPending,
215
- isSigningUp: signUp.isPending,
216
- isSigningOut: signOut.isPending,
217
- isUpdating: updateUser.isPending
218
- };
219
- }
220
-
221
- // src/use-captcha.ts
222
- var import_react_query2 = require("@tanstack/react-query");
223
- var import_react2 = require("react");
224
- function useCaptchaConfig() {
225
- const client = useFluxbaseClient();
226
- return (0, import_react_query2.useQuery)({
227
- queryKey: ["fluxbase", "auth", "captcha", "config"],
228
- queryFn: async () => {
229
- const { data, error } = await client.auth.getCaptchaConfig();
230
- if (error) {
231
- throw error;
232
- }
233
- return data;
234
- },
235
- staleTime: 1e3 * 60 * 60,
236
- // Cache for 1 hour (config rarely changes)
237
- gcTime: 1e3 * 60 * 60 * 24
238
- // Keep in cache for 24 hours
239
- });
240
- }
241
- function useCaptcha(provider) {
242
- const [token, setToken] = (0, import_react2.useState)(null);
243
- const [isReady, setIsReady] = (0, import_react2.useState)(false);
244
- const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
245
- const [error, setError] = (0, import_react2.useState)(null);
246
- const executeResolverRef = (0, import_react2.useRef)(null);
247
- const executeRejecterRef = (0, import_react2.useRef)(null);
248
- const onVerify = (0, import_react2.useCallback)((newToken) => {
249
- setToken(newToken);
250
- setIsLoading(false);
251
- setError(null);
252
- setIsReady(true);
253
- if (executeResolverRef.current) {
254
- executeResolverRef.current(newToken);
255
- executeResolverRef.current = null;
256
- executeRejecterRef.current = null;
257
- }
258
- }, []);
259
- const onExpire = (0, import_react2.useCallback)(() => {
260
- setToken(null);
261
- setIsReady(true);
262
- }, []);
263
- const onError = (0, import_react2.useCallback)((err) => {
264
- setError(err);
265
- setIsLoading(false);
266
- setToken(null);
267
- if (executeRejecterRef.current) {
268
- executeRejecterRef.current(err);
269
- executeResolverRef.current = null;
270
- executeRejecterRef.current = null;
271
- }
272
- }, []);
273
- const reset = (0, import_react2.useCallback)(() => {
274
- setToken(null);
275
- setError(null);
276
- setIsLoading(false);
277
- }, []);
278
- const execute = (0, import_react2.useCallback)(async () => {
279
- if (token) {
280
- return token;
281
- }
282
- if (!provider) {
283
- return "";
284
- }
285
- setIsLoading(true);
286
- setError(null);
287
- return new Promise((resolve, reject) => {
288
- executeResolverRef.current = resolve;
289
- executeRejecterRef.current = reject;
290
- });
291
- }, [token, provider]);
292
- (0, import_react2.useEffect)(() => {
293
- if (provider) {
294
- setIsReady(true);
295
- }
296
- }, [provider]);
297
- return {
298
- token,
299
- isReady,
300
- isLoading,
301
- error,
302
- reset,
303
- execute,
304
- onVerify,
305
- onExpire,
306
- onError
307
- };
308
- }
309
- function isCaptchaRequiredForEndpoint(config, endpoint) {
310
- if (!config?.enabled) {
311
- return false;
312
- }
313
- return config.endpoints?.includes(endpoint) ?? false;
314
- }
315
-
316
- // src/use-auth-config.ts
317
- var import_react_query3 = require("@tanstack/react-query");
318
- function useAuthConfig() {
319
- const client = useFluxbaseClient();
320
- return (0, import_react_query3.useQuery)({
321
- queryKey: ["fluxbase", "auth", "config"],
322
- queryFn: async () => {
323
- const { data, error } = await client.auth.getAuthConfig();
324
- if (error) {
325
- throw error;
326
- }
327
- return data;
328
- },
329
- staleTime: 1e3 * 60 * 5,
330
- // Cache for 5 minutes (config changes infrequently)
331
- gcTime: 1e3 * 60 * 60
332
- // Keep in cache for 1 hour
333
- });
334
- }
335
-
336
- // src/use-saml.ts
337
- var import_react_query4 = require("@tanstack/react-query");
338
- function useSAMLProviders() {
339
- const client = useFluxbaseClient();
340
- return (0, import_react_query4.useQuery)({
341
- queryKey: ["fluxbase", "auth", "saml", "providers"],
342
- queryFn: async () => {
343
- const { data, error } = await client.auth.getSAMLProviders();
344
- if (error) throw error;
345
- return data.providers;
346
- },
347
- staleTime: 1e3 * 60 * 5
348
- // 5 minutes - providers don't change often
349
- });
350
- }
351
- function useGetSAMLLoginUrl() {
352
- const client = useFluxbaseClient();
353
- return (0, import_react_query4.useMutation)({
354
- mutationFn: async ({
355
- provider,
356
- options
357
- }) => {
358
- return await client.auth.getSAMLLoginUrl(provider, options);
359
- }
360
- });
361
- }
362
- function useSignInWithSAML() {
363
- const client = useFluxbaseClient();
364
- return (0, import_react_query4.useMutation)({
365
- mutationFn: async ({
366
- provider,
367
- options
368
- }) => {
369
- return await client.auth.signInWithSAML(provider, options);
370
- }
371
- });
372
- }
373
- function useHandleSAMLCallback() {
374
- const client = useFluxbaseClient();
375
- const queryClient = (0, import_react_query4.useQueryClient)();
376
- return (0, import_react_query4.useMutation)({
377
- mutationFn: async ({
378
- samlResponse,
379
- provider
380
- }) => {
381
- return await client.auth.handleSAMLCallback(samlResponse, provider);
382
- },
383
- onSuccess: (result) => {
384
- if (result.data) {
385
- queryClient.setQueryData(
386
- ["fluxbase", "auth", "session"],
387
- result.data.session
388
- );
389
- queryClient.setQueryData(
390
- ["fluxbase", "auth", "user"],
391
- result.data.user
392
- );
393
- queryClient.invalidateQueries({ queryKey: ["fluxbase"] });
394
- }
395
- }
396
- });
397
- }
398
- function useSAMLMetadataUrl() {
399
- const client = useFluxbaseClient();
400
- return (provider) => {
401
- return client.auth.getSAMLMetadataUrl(provider);
402
- };
403
- }
404
-
405
- // src/use-graphql.ts
406
- var import_react_query5 = require("@tanstack/react-query");
407
- function useGraphQLQuery(queryKey, query, options) {
408
- const client = useFluxbaseClient();
409
- const normalizedKey = Array.isArray(queryKey) ? ["fluxbase", "graphql", ...queryKey] : ["fluxbase", "graphql", queryKey];
410
- return (0, import_react_query5.useQuery)({
411
- queryKey: normalizedKey,
412
- queryFn: async () => {
413
- const response = await client.graphql.execute(
414
- query,
415
- options?.variables,
416
- options?.operationName,
417
- options?.requestOptions
418
- );
419
- if (response.errors && response.errors.length > 0) {
420
- throw response.errors[0];
421
- }
422
- return response.data;
423
- },
424
- enabled: options?.enabled ?? true,
425
- staleTime: options?.staleTime ?? 0,
426
- gcTime: options?.gcTime,
427
- refetchOnWindowFocus: options?.refetchOnWindowFocus ?? true,
428
- select: options?.select
429
- });
430
- }
431
- function useGraphQLMutation(mutation, options) {
432
- const client = useFluxbaseClient();
433
- const queryClient = (0, import_react_query5.useQueryClient)();
434
- return (0, import_react_query5.useMutation)({
435
- mutationFn: async (variables) => {
436
- const response = await client.graphql.execute(
437
- mutation,
438
- variables,
439
- options?.operationName,
440
- options?.requestOptions
441
- );
442
- if (response.errors && response.errors.length > 0) {
443
- throw response.errors[0];
444
- }
445
- return response.data;
446
- },
447
- onSuccess: (data, variables) => {
448
- if (options?.invalidateQueries) {
449
- for (const key of options.invalidateQueries) {
450
- queryClient.invalidateQueries({
451
- queryKey: ["fluxbase", "graphql", key]
452
- });
453
- }
454
- }
455
- if (options?.onSuccess && data !== void 0) {
456
- options.onSuccess(data, variables);
457
- }
458
- },
459
- onError: (error, variables) => {
460
- if (options?.onError) {
461
- options.onError(error, variables);
462
- }
463
- }
464
- });
465
- }
466
- function useGraphQLIntrospection(options) {
467
- const client = useFluxbaseClient();
468
- return (0, import_react_query5.useQuery)({
469
- queryKey: ["fluxbase", "graphql", "__introspection"],
470
- queryFn: async () => {
471
- const response = await client.graphql.introspect(options?.requestOptions);
472
- if (response.errors && response.errors.length > 0) {
473
- throw response.errors[0];
474
- }
475
- return response.data;
476
- },
477
- enabled: options?.enabled ?? true,
478
- staleTime: options?.staleTime ?? 1e3 * 60 * 5
479
- // 5 minutes - schema doesn't change often
480
- });
481
- }
482
- function useGraphQL() {
483
- const client = useFluxbaseClient();
484
- return {
485
- /**
486
- * Execute a GraphQL query
487
- */
488
- executeQuery: (query, variables, options) => {
489
- return client.graphql.query(query, variables, options);
490
- },
491
- /**
492
- * Execute a GraphQL mutation
493
- */
494
- executeMutation: (mutation, variables, options) => {
495
- return client.graphql.mutation(mutation, variables, options);
496
- },
497
- /**
498
- * Execute a GraphQL operation with an explicit operation name
499
- */
500
- execute: (document, variables, operationName, options) => {
501
- return client.graphql.execute(document, variables, operationName, options);
502
- },
503
- /**
504
- * Fetch the GraphQL schema via introspection
505
- */
506
- introspect: (options) => {
507
- return client.graphql.introspect(options);
508
- }
509
- };
510
- }
511
-
512
- // src/use-query.ts
513
- var import_react_query6 = require("@tanstack/react-query");
514
- function useFluxbaseQuery(buildQuery, options) {
515
- const client = useFluxbaseClient();
516
- if (!options?.queryKey) {
517
- console.warn(
518
- "[useFluxbaseQuery] No queryKey provided. This may cause cache misses. Please provide a stable queryKey in options."
519
- );
520
- }
521
- const queryKey = options?.queryKey || ["fluxbase", "query", "unstable"];
522
- return (0, import_react_query6.useQuery)({
523
- queryKey,
524
- queryFn: async () => {
525
- const query = buildQuery(client);
526
- const { data, error } = await query.execute();
527
- if (error) {
528
- throw error;
529
- }
530
- return Array.isArray(data) ? data : data ? [data] : [];
531
- },
532
- ...options
533
- });
534
- }
535
- function useTable(table, buildQuery, options) {
536
- const client = useFluxbaseClient();
537
- if (buildQuery && !options?.queryKey) {
538
- console.warn(
539
- `[useTable] Using buildQuery without a custom queryKey for table "${table}". This may cause cache misses. Provide a queryKey that includes your filter values.`
540
- );
541
- }
542
- return useFluxbaseQuery(
543
- (client2) => {
544
- const query = client2.from(table);
545
- return buildQuery ? buildQuery(query) : query;
546
- },
547
- {
548
- ...options,
549
- // Use table name as base key, or custom key if provided
550
- queryKey: options?.queryKey || ["fluxbase", "table", table]
551
- }
552
- );
553
- }
554
- function useInsert(table) {
555
- const client = useFluxbaseClient();
556
- const queryClient = (0, import_react_query6.useQueryClient)();
557
- return (0, import_react_query6.useMutation)({
558
- mutationFn: async (data) => {
559
- const query = client.from(table);
560
- const { data: result, error } = await query.insert(data);
561
- if (error) {
562
- throw error;
563
- }
564
- return result;
565
- },
566
- onSuccess: () => {
567
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
568
- }
569
- });
570
- }
571
- function useUpdate(table) {
572
- const client = useFluxbaseClient();
573
- const queryClient = (0, import_react_query6.useQueryClient)();
574
- return (0, import_react_query6.useMutation)({
575
- mutationFn: async (params) => {
576
- const query = client.from(table);
577
- const builtQuery = params.buildQuery(query);
578
- const { data: result, error } = await builtQuery.update(params.data);
579
- if (error) {
580
- throw error;
581
- }
582
- return result;
583
- },
584
- onSuccess: () => {
585
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
586
- }
587
- });
588
- }
589
- function useUpsert(table) {
590
- const client = useFluxbaseClient();
591
- const queryClient = (0, import_react_query6.useQueryClient)();
592
- return (0, import_react_query6.useMutation)({
593
- mutationFn: async (data) => {
594
- const query = client.from(table);
595
- const { data: result, error } = await query.upsert(data);
596
- if (error) {
597
- throw error;
598
- }
599
- return result;
600
- },
601
- onSuccess: () => {
602
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
603
- }
604
- });
605
- }
606
- function useDelete(table) {
607
- const client = useFluxbaseClient();
608
- const queryClient = (0, import_react_query6.useQueryClient)();
609
- return (0, import_react_query6.useMutation)({
610
- mutationFn: async (buildQuery) => {
611
- const query = client.from(table);
612
- const builtQuery = buildQuery(query);
613
- const { error } = await builtQuery.delete();
614
- if (error) {
615
- throw error;
616
- }
617
- },
618
- onSuccess: () => {
619
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
620
- }
621
- });
622
- }
623
-
624
- // src/use-realtime.ts
625
- var import_react3 = require("react");
626
- var import_react_query7 = require("@tanstack/react-query");
627
- function useRealtime(options) {
628
- const client = useFluxbaseClient();
629
- const queryClient = (0, import_react_query7.useQueryClient)();
630
- const channelRef = (0, import_react3.useRef)(
631
- null
632
- );
633
- const {
634
- channel: channelName,
635
- event = "*",
636
- callback,
637
- autoInvalidate = true,
638
- invalidateKey,
639
- enabled = true
640
- } = options;
641
- const callbackRef = (0, import_react3.useRef)(callback);
642
- const invalidateKeyRef = (0, import_react3.useRef)(invalidateKey);
643
- const autoInvalidateRef = (0, import_react3.useRef)(autoInvalidate);
644
- callbackRef.current = callback;
645
- invalidateKeyRef.current = invalidateKey;
646
- autoInvalidateRef.current = autoInvalidate;
647
- (0, import_react3.useEffect)(() => {
648
- if (!enabled) {
649
- return;
650
- }
651
- const channel = client.realtime.channel(channelName);
652
- channelRef.current = channel;
653
- const handleChange = (payload) => {
654
- if (callbackRef.current) {
655
- callbackRef.current(payload);
656
- }
657
- if (autoInvalidateRef.current) {
658
- const tableName = channelName.replace(/^table:/, "");
659
- const key = invalidateKeyRef.current || ["fluxbase", "table", tableName];
660
- queryClient.invalidateQueries({ queryKey: key });
661
- }
662
- };
663
- channel.on(event, handleChange).subscribe();
664
- return () => {
665
- channel.unsubscribe();
666
- channelRef.current = null;
667
- };
668
- }, [client, channelName, event, queryClient, enabled]);
669
- return {
670
- channel: channelRef.current
671
- };
672
- }
673
- function useTableSubscription(table, options) {
674
- return useRealtime({
675
- ...options,
676
- channel: `table:${table}`
677
- });
678
- }
679
- function useTableInserts(table, callback, options) {
680
- return useRealtime({
681
- ...options,
682
- channel: `table:${table}`,
683
- event: "INSERT",
684
- callback
685
- });
686
- }
687
- function useTableUpdates(table, callback, options) {
688
- return useRealtime({
689
- ...options,
690
- channel: `table:${table}`,
691
- event: "UPDATE",
692
- callback
693
- });
694
- }
695
- function useTableDeletes(table, callback, options) {
696
- return useRealtime({
697
- ...options,
698
- channel: `table:${table}`,
699
- event: "DELETE",
700
- callback
701
- });
702
- }
703
-
704
- // src/use-storage.ts
705
- var import_react4 = require("react");
706
- var import_react_query8 = require("@tanstack/react-query");
707
- function useStorageList(bucket, options) {
708
- const client = useFluxbaseClient();
709
- const { prefix, limit, offset, ...queryOptions } = options || {};
710
- return (0, import_react_query8.useQuery)({
711
- queryKey: [
712
- "fluxbase",
713
- "storage",
714
- bucket,
715
- "list",
716
- { prefix, limit, offset }
717
- ],
718
- queryFn: async () => {
719
- const { data, error } = await client.storage.from(bucket).list({ prefix, limit, offset });
720
- if (error) {
721
- throw error;
722
- }
723
- return data || [];
724
- },
725
- ...queryOptions
726
- });
727
- }
728
- function useStorageUpload(bucket) {
729
- const client = useFluxbaseClient();
730
- const queryClient = (0, import_react_query8.useQueryClient)();
731
- return (0, import_react_query8.useMutation)({
732
- mutationFn: async (params) => {
733
- const { path, file, options } = params;
734
- const { data, error } = await client.storage.from(bucket).upload(path, file, options);
735
- if (error) {
736
- throw error;
737
- }
738
- return data;
739
- },
740
- onSuccess: () => {
741
- queryClient.invalidateQueries({
742
- queryKey: ["fluxbase", "storage", bucket, "list"]
743
- });
744
- }
745
- });
746
- }
747
- function useStorageUploadWithProgress(bucket) {
748
- const client = useFluxbaseClient();
749
- const queryClient = (0, import_react_query8.useQueryClient)();
750
- const [progress, setProgress] = (0, import_react4.useState)(null);
751
- const mutation = (0, import_react_query8.useMutation)({
752
- mutationFn: async (params) => {
753
- const { path, file, options } = params;
754
- setProgress({ loaded: 0, total: 0, percentage: 0 });
755
- const { data, error } = await client.storage.from(bucket).upload(path, file, {
756
- ...options,
757
- onUploadProgress: (p) => {
758
- setProgress(p);
759
- }
760
- });
761
- if (error) {
762
- throw error;
763
- }
764
- return data;
765
- },
766
- onSuccess: () => {
767
- queryClient.invalidateQueries({
768
- queryKey: ["fluxbase", "storage", bucket, "list"]
769
- });
770
- },
771
- onError: () => {
772
- setProgress(null);
773
- }
774
- });
775
- return {
776
- upload: mutation,
777
- progress,
778
- reset: () => setProgress(null)
779
- };
780
- }
781
- function useStorageDownload(bucket, path, enabled = true) {
782
- const client = useFluxbaseClient();
783
- return (0, import_react_query8.useQuery)({
784
- queryKey: ["fluxbase", "storage", bucket, "download", path],
785
- queryFn: async () => {
786
- if (!path) {
787
- return null;
788
- }
789
- const { data, error } = await client.storage.from(bucket).download(path);
790
- if (error) {
791
- throw error;
792
- }
793
- return data;
794
- },
795
- enabled: enabled && !!path
796
- });
797
- }
798
- function useStorageDelete(bucket) {
799
- const client = useFluxbaseClient();
800
- const queryClient = (0, import_react_query8.useQueryClient)();
801
- return (0, import_react_query8.useMutation)({
802
- mutationFn: async (paths) => {
803
- const { error } = await client.storage.from(bucket).remove(paths);
804
- if (error) {
805
- throw error;
806
- }
807
- },
808
- onSuccess: () => {
809
- queryClient.invalidateQueries({
810
- queryKey: ["fluxbase", "storage", bucket, "list"]
811
- });
812
- }
813
- });
814
- }
815
- function useStoragePublicUrl(bucket, path) {
816
- const client = useFluxbaseClient();
817
- if (!path) {
818
- return null;
819
- }
820
- const { data } = client.storage.from(bucket).getPublicUrl(path);
821
- return data.publicUrl;
822
- }
823
- function useStorageTransformUrl(bucket, path, transform) {
824
- const client = useFluxbaseClient();
825
- if (!path) {
826
- return null;
827
- }
828
- return client.storage.from(bucket).getTransformUrl(path, transform);
829
- }
830
- function useStorageSignedUrl(bucket, path, expiresIn) {
831
- const client = useFluxbaseClient();
832
- return (0, import_react_query8.useQuery)({
833
- queryKey: ["fluxbase", "storage", bucket, "signed-url", path, expiresIn],
834
- queryFn: async () => {
835
- if (!path) {
836
- return null;
837
- }
838
- const { data, error } = await client.storage.from(bucket).createSignedUrl(path, { expiresIn });
839
- if (error) {
840
- throw error;
841
- }
842
- return data?.signedUrl || null;
843
- },
844
- enabled: !!path,
845
- // Refresh 1 minute before expiry, but ensure staleTime is never negative
846
- // For very short expirations (<60s), use half the expiration time
847
- staleTime: expiresIn ? Math.max(expiresIn * 500, expiresIn * 1e3 - 6e4) : 1e3 * 60 * 50
848
- // 50 minutes default
849
- });
850
- }
851
- function useStorageSignedUrlWithOptions(bucket, path, options) {
852
- const client = useFluxbaseClient();
853
- const expiresIn = options?.expiresIn;
854
- const transformKey = options?.transform ? JSON.stringify(options.transform) : null;
855
- return (0, import_react_query8.useQuery)({
856
- queryKey: [
857
- "fluxbase",
858
- "storage",
859
- bucket,
860
- "signed-url",
861
- path,
862
- expiresIn,
863
- transformKey
864
- ],
865
- queryFn: async () => {
866
- if (!path) {
867
- return null;
868
- }
869
- const { data, error } = await client.storage.from(bucket).createSignedUrl(path, options);
870
- if (error) {
871
- throw error;
872
- }
873
- return data?.signedUrl || null;
874
- },
875
- enabled: !!path,
876
- // Refresh 1 minute before expiry, but ensure staleTime is never negative
877
- // For very short expirations (<60s), use half the expiration time
878
- staleTime: expiresIn ? Math.max(expiresIn * 500, expiresIn * 1e3 - 6e4) : 1e3 * 60 * 50
879
- // 50 minutes default
880
- });
881
- }
882
- function useStorageMove(bucket) {
883
- const client = useFluxbaseClient();
884
- const queryClient = (0, import_react_query8.useQueryClient)();
885
- return (0, import_react_query8.useMutation)({
886
- mutationFn: async (params) => {
887
- const { fromPath, toPath } = params;
888
- const { data, error } = await client.storage.from(bucket).move(fromPath, toPath);
889
- if (error) {
890
- throw error;
891
- }
892
- return data;
893
- },
894
- onSuccess: () => {
895
- queryClient.invalidateQueries({
896
- queryKey: ["fluxbase", "storage", bucket, "list"]
897
- });
898
- }
899
- });
900
- }
901
- function useStorageCopy(bucket) {
902
- const client = useFluxbaseClient();
903
- const queryClient = (0, import_react_query8.useQueryClient)();
904
- return (0, import_react_query8.useMutation)({
905
- mutationFn: async (params) => {
906
- const { fromPath, toPath } = params;
907
- const { data, error } = await client.storage.from(bucket).copy(fromPath, toPath);
908
- if (error) {
909
- throw error;
910
- }
911
- return data;
912
- },
913
- onSuccess: () => {
914
- queryClient.invalidateQueries({
915
- queryKey: ["fluxbase", "storage", bucket, "list"]
916
- });
917
- }
918
- });
919
- }
920
- function useStorageBuckets() {
921
- const client = useFluxbaseClient();
922
- return (0, import_react_query8.useQuery)({
923
- queryKey: ["fluxbase", "storage", "buckets"],
924
- queryFn: async () => {
925
- const { data, error } = await client.storage.listBuckets();
926
- if (error) {
927
- throw error;
928
- }
929
- return data || [];
930
- }
931
- });
932
- }
933
- function useCreateBucket() {
934
- const client = useFluxbaseClient();
935
- const queryClient = (0, import_react_query8.useQueryClient)();
936
- return (0, import_react_query8.useMutation)({
937
- mutationFn: async (bucketName) => {
938
- const { error } = await client.storage.createBucket(bucketName);
939
- if (error) {
940
- throw error;
941
- }
942
- },
943
- onSuccess: () => {
944
- queryClient.invalidateQueries({
945
- queryKey: ["fluxbase", "storage", "buckets"]
946
- });
947
- }
948
- });
949
- }
950
- function useDeleteBucket() {
951
- const client = useFluxbaseClient();
952
- const queryClient = (0, import_react_query8.useQueryClient)();
953
- return (0, import_react_query8.useMutation)({
954
- mutationFn: async (bucketName) => {
955
- const { error } = await client.storage.deleteBucket(bucketName);
956
- if (error) {
957
- throw error;
958
- }
959
- },
960
- onSuccess: () => {
961
- queryClient.invalidateQueries({
962
- queryKey: ["fluxbase", "storage", "buckets"]
963
- });
964
- }
965
- });
966
- }
967
-
968
- // src/use-admin-auth.ts
969
- var import_react5 = require("react");
970
- function useAdminAuth(options = {}) {
971
- const { autoCheck = true } = options;
972
- const client = useFluxbaseClient();
973
- const [user, setUser] = (0, import_react5.useState)(null);
974
- const [isLoading, setIsLoading] = (0, import_react5.useState)(autoCheck);
975
- const [error, setError] = (0, import_react5.useState)(null);
976
- const checkAuth = (0, import_react5.useCallback)(async () => {
977
- try {
978
- setIsLoading(true);
979
- setError(null);
980
- const { data, error: apiError } = await client.admin.me();
981
- if (apiError) {
982
- throw apiError;
983
- }
984
- setUser(data.user);
985
- } catch (err) {
986
- setUser(null);
987
- setError(err);
988
- } finally {
989
- setIsLoading(false);
990
- }
991
- }, [client]);
992
- const login = (0, import_react5.useCallback)(
993
- async (email, password) => {
994
- try {
995
- setIsLoading(true);
996
- setError(null);
997
- const { data, error: apiError } = await client.admin.login({
998
- email,
999
- password
1000
- });
1001
- if (apiError) {
1002
- throw apiError;
1003
- }
1004
- setUser(data.user);
1005
- return data;
1006
- } catch (err) {
1007
- setError(err);
1008
- throw err;
1009
- } finally {
1010
- setIsLoading(false);
1011
- }
1012
- },
1013
- [client]
1014
- );
1015
- const logout = (0, import_react5.useCallback)(async () => {
1016
- try {
1017
- setIsLoading(true);
1018
- setError(null);
1019
- setUser(null);
1020
- } catch (err) {
1021
- setError(err);
1022
- throw err;
1023
- } finally {
1024
- setIsLoading(false);
1025
- }
1026
- }, []);
1027
- const refresh = (0, import_react5.useCallback)(async () => {
1028
- await checkAuth();
1029
- }, [checkAuth]);
1030
- (0, import_react5.useEffect)(() => {
1031
- if (autoCheck) {
1032
- checkAuth();
1033
- }
1034
- }, [autoCheck, checkAuth]);
1035
- return {
1036
- user,
1037
- isAuthenticated: user !== null,
1038
- isLoading,
1039
- error,
1040
- login,
1041
- logout,
1042
- refresh
1043
- };
1044
- }
1045
-
1046
- // src/use-users.ts
1047
- var import_react6 = require("react");
1048
- function useUsers(options = {}) {
1049
- const { autoFetch = true, refetchInterval = 0, ...listOptions } = options;
1050
- const client = useFluxbaseClient();
1051
- const [users, setUsers] = (0, import_react6.useState)([]);
1052
- const [total, setTotal] = (0, import_react6.useState)(0);
1053
- const [isLoading, setIsLoading] = (0, import_react6.useState)(autoFetch);
1054
- const [error, setError] = (0, import_react6.useState)(null);
1055
- const fetchUsers = (0, import_react6.useCallback)(async () => {
1056
- try {
1057
- setIsLoading(true);
1058
- setError(null);
1059
- const { data, error: apiError } = await client.admin.listUsers(listOptions);
1060
- if (apiError) {
1061
- throw apiError;
1062
- }
1063
- setUsers(data.users);
1064
- setTotal(data.total);
1065
- } catch (err) {
1066
- setError(err);
1067
- } finally {
1068
- setIsLoading(false);
1069
- }
1070
- }, [client, JSON.stringify(listOptions)]);
1071
- const inviteUser = (0, import_react6.useCallback)(
1072
- async (email, role) => {
1073
- await client.admin.inviteUser({ email, role });
1074
- await fetchUsers();
1075
- },
1076
- [client, fetchUsers]
1077
- );
1078
- const updateUserRole = (0, import_react6.useCallback)(
1079
- async (userId, role) => {
1080
- await client.admin.updateUserRole(userId, role);
1081
- await fetchUsers();
1082
- },
1083
- [client, fetchUsers]
1084
- );
1085
- const deleteUser = (0, import_react6.useCallback)(
1086
- async (userId) => {
1087
- await client.admin.deleteUser(userId);
1088
- await fetchUsers();
1089
- },
1090
- [client, fetchUsers]
1091
- );
1092
- const resetPassword = (0, import_react6.useCallback)(
1093
- async (userId) => {
1094
- const { data, error: error2 } = await client.admin.resetUserPassword(userId);
1095
- if (error2) {
1096
- throw error2;
1097
- }
1098
- return data;
1099
- },
1100
- [client]
1101
- );
1102
- (0, import_react6.useEffect)(() => {
1103
- if (autoFetch) {
1104
- fetchUsers();
1105
- }
1106
- }, [autoFetch, fetchUsers]);
1107
- (0, import_react6.useEffect)(() => {
1108
- if (refetchInterval > 0) {
1109
- const interval = setInterval(fetchUsers, refetchInterval);
1110
- return () => clearInterval(interval);
1111
- }
1112
- }, [refetchInterval, fetchUsers]);
1113
- return {
1114
- users,
1115
- total,
1116
- isLoading,
1117
- error,
1118
- refetch: fetchUsers,
1119
- inviteUser,
1120
- updateUserRole,
1121
- deleteUser,
1122
- resetPassword
1123
- };
1124
- }
1125
-
1126
- // src/use-client-keys.ts
1127
- var import_react7 = require("react");
1128
- function useClientKeys(options = {}) {
1129
- const { autoFetch = true } = options;
1130
- const client = useFluxbaseClient();
1131
- const [keys, setKeys] = (0, import_react7.useState)([]);
1132
- const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
1133
- const [error, setError] = (0, import_react7.useState)(null);
1134
- const fetchKeys = (0, import_react7.useCallback)(async () => {
1135
- try {
1136
- setIsLoading(true);
1137
- setError(null);
1138
- const response = await client.admin.management.clientKeys.list();
1139
- setKeys(response.client_keys);
1140
- } catch (err) {
1141
- setError(err);
1142
- } finally {
1143
- setIsLoading(false);
1144
- }
1145
- }, [client]);
1146
- const createKey = (0, import_react7.useCallback)(
1147
- async (request) => {
1148
- const response = await client.admin.management.clientKeys.create(request);
1149
- await fetchKeys();
1150
- return { key: response.key, keyData: response.client_key };
1151
- },
1152
- [client, fetchKeys]
1153
- );
1154
- const updateKey = (0, import_react7.useCallback)(
1155
- async (keyId, update) => {
1156
- await client.admin.management.clientKeys.update(keyId, update);
1157
- await fetchKeys();
1158
- },
1159
- [client, fetchKeys]
1160
- );
1161
- const revokeKey = (0, import_react7.useCallback)(
1162
- async (keyId) => {
1163
- await client.admin.management.clientKeys.revoke(keyId);
1164
- await fetchKeys();
1165
- },
1166
- [client, fetchKeys]
1167
- );
1168
- const deleteKey = (0, import_react7.useCallback)(
1169
- async (keyId) => {
1170
- await client.admin.management.clientKeys.delete(keyId);
1171
- await fetchKeys();
1172
- },
1173
- [client, fetchKeys]
1174
- );
1175
- (0, import_react7.useEffect)(() => {
1176
- if (autoFetch) {
1177
- fetchKeys();
1178
- }
1179
- }, [autoFetch, fetchKeys]);
1180
- return {
1181
- keys,
1182
- isLoading,
1183
- error,
1184
- refetch: fetchKeys,
1185
- createKey,
1186
- updateKey,
1187
- revokeKey,
1188
- deleteKey
1189
- };
1190
- }
1191
- var useAPIKeys = useClientKeys;
1192
-
1193
- // src/use-admin-hooks.ts
1194
- var import_react8 = require("react");
1195
- function useAppSettings(options = {}) {
1196
- const { autoFetch = true } = options;
1197
- const client = useFluxbaseClient();
1198
- const [settings, setSettings] = (0, import_react8.useState)(null);
1199
- const [isLoading, setIsLoading] = (0, import_react8.useState)(autoFetch);
1200
- const [error, setError] = (0, import_react8.useState)(null);
1201
- const fetchSettings = (0, import_react8.useCallback)(async () => {
1202
- try {
1203
- setIsLoading(true);
1204
- setError(null);
1205
- const appSettings = await client.admin.settings.app.get();
1206
- setSettings(appSettings);
1207
- } catch (err) {
1208
- setError(err);
1209
- } finally {
1210
- setIsLoading(false);
1211
- }
1212
- }, [client]);
1213
- const updateSettings = (0, import_react8.useCallback)(
1214
- async (update) => {
1215
- await client.admin.settings.app.update(update);
1216
- await fetchSettings();
1217
- },
1218
- [client, fetchSettings]
1219
- );
1220
- (0, import_react8.useEffect)(() => {
1221
- if (autoFetch) {
1222
- fetchSettings();
1223
- }
1224
- }, [autoFetch, fetchSettings]);
1225
- return {
1226
- settings,
1227
- isLoading,
1228
- error,
1229
- refetch: fetchSettings,
1230
- updateSettings
1231
- };
1232
- }
1233
- function useSystemSettings(options = {}) {
1234
- const { autoFetch = true } = options;
1235
- const client = useFluxbaseClient();
1236
- const [settings, setSettings] = (0, import_react8.useState)([]);
1237
- const [isLoading, setIsLoading] = (0, import_react8.useState)(autoFetch);
1238
- const [error, setError] = (0, import_react8.useState)(null);
1239
- const fetchSettings = (0, import_react8.useCallback)(async () => {
1240
- try {
1241
- setIsLoading(true);
1242
- setError(null);
1243
- const response = await client.admin.settings.system.list();
1244
- setSettings(response.settings);
1245
- } catch (err) {
1246
- setError(err);
1247
- } finally {
1248
- setIsLoading(false);
1249
- }
1250
- }, [client]);
1251
- const getSetting = (0, import_react8.useCallback)(
1252
- (key) => {
1253
- return settings.find((s) => s.key === key);
1254
- },
1255
- [settings]
1256
- );
1257
- const updateSetting = (0, import_react8.useCallback)(
1258
- async (key, update) => {
1259
- await client.admin.settings.system.update(key, update);
1260
- await fetchSettings();
1261
- },
1262
- [client, fetchSettings]
1263
- );
1264
- const deleteSetting = (0, import_react8.useCallback)(
1265
- async (key) => {
1266
- await client.admin.settings.system.delete(key);
1267
- await fetchSettings();
1268
- },
1269
- [client, fetchSettings]
1270
- );
1271
- (0, import_react8.useEffect)(() => {
1272
- if (autoFetch) {
1273
- fetchSettings();
1274
- }
1275
- }, [autoFetch, fetchSettings]);
1276
- return {
1277
- settings,
1278
- isLoading,
1279
- error,
1280
- refetch: fetchSettings,
1281
- getSetting,
1282
- updateSetting,
1283
- deleteSetting
1284
- };
1285
- }
1286
- function useWebhooks(options = {}) {
1287
- const { autoFetch = true, refetchInterval = 0 } = options;
1288
- const client = useFluxbaseClient();
1289
- const [webhooks, setWebhooks] = (0, import_react8.useState)([]);
1290
- const [isLoading, setIsLoading] = (0, import_react8.useState)(autoFetch);
1291
- const [error, setError] = (0, import_react8.useState)(null);
1292
- const fetchWebhooks = (0, import_react8.useCallback)(async () => {
1293
- try {
1294
- setIsLoading(true);
1295
- setError(null);
1296
- const response = await client.admin.management.webhooks.list();
1297
- setWebhooks(response.webhooks);
1298
- } catch (err) {
1299
- setError(err);
1300
- } finally {
1301
- setIsLoading(false);
1302
- }
1303
- }, [client]);
1304
- const createWebhook = (0, import_react8.useCallback)(
1305
- async (webhook) => {
1306
- const created = await client.admin.management.webhooks.create(webhook);
1307
- await fetchWebhooks();
1308
- return created;
1309
- },
1310
- [client, fetchWebhooks]
1311
- );
1312
- const updateWebhook = (0, import_react8.useCallback)(
1313
- async (id, update) => {
1314
- const updated = await client.admin.management.webhooks.update(id, update);
1315
- await fetchWebhooks();
1316
- return updated;
1317
- },
1318
- [client, fetchWebhooks]
1319
- );
1320
- const deleteWebhook = (0, import_react8.useCallback)(
1321
- async (id) => {
1322
- await client.admin.management.webhooks.delete(id);
1323
- await fetchWebhooks();
1324
- },
1325
- [client, fetchWebhooks]
1326
- );
1327
- const testWebhook = (0, import_react8.useCallback)(
1328
- async (id) => {
1329
- await client.admin.management.webhooks.test(id);
1330
- },
1331
- [client]
1332
- );
1333
- (0, import_react8.useEffect)(() => {
1334
- if (autoFetch) {
1335
- fetchWebhooks();
1336
- }
1337
- if (refetchInterval > 0) {
1338
- const interval = setInterval(fetchWebhooks, refetchInterval);
1339
- return () => clearInterval(interval);
1340
- }
1341
- }, [autoFetch, refetchInterval, fetchWebhooks]);
1342
- return {
1343
- webhooks,
1344
- isLoading,
1345
- error,
1346
- refetch: fetchWebhooks,
1347
- createWebhook,
1348
- updateWebhook,
1349
- deleteWebhook,
1350
- testWebhook
1351
- };
1352
- }
1353
-
1354
- // src/use-table-export.ts
1355
- var import_react9 = require("react");
1356
- function useTableDetails(options) {
1357
- const { schema, table, autoFetch = true } = options;
1358
- const client = useFluxbaseClient();
1359
- const [data, setData] = (0, import_react9.useState)(null);
1360
- const [isLoading, setIsLoading] = (0, import_react9.useState)(autoFetch && !!schema && !!table);
1361
- const [error, setError] = (0, import_react9.useState)(null);
1362
- const fetchData = (0, import_react9.useCallback)(async () => {
1363
- if (!schema || !table) return;
1364
- try {
1365
- setIsLoading(true);
1366
- setError(null);
1367
- const result = await client.admin.ai.getTableDetails(schema, table);
1368
- if (result.error) {
1369
- throw result.error;
1370
- }
1371
- setData(result.data);
1372
- } catch (err) {
1373
- setError(err);
1374
- } finally {
1375
- setIsLoading(false);
1376
- }
1377
- }, [client, schema, table]);
1378
- (0, import_react9.useEffect)(() => {
1379
- if (autoFetch && schema && table) {
1380
- fetchData();
1381
- }
1382
- }, [autoFetch, fetchData, schema, table]);
1383
- return {
1384
- data,
1385
- isLoading,
1386
- error,
1387
- refetch: fetchData
1388
- };
1389
- }
1390
- function useExportTable(knowledgeBaseId) {
1391
- const client = useFluxbaseClient();
1392
- const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
1393
- const [error, setError] = (0, import_react9.useState)(null);
1394
- const exportTable = (0, import_react9.useCallback)(
1395
- async (options) => {
1396
- try {
1397
- setIsLoading(true);
1398
- setError(null);
1399
- const result = await client.admin.ai.exportTable(knowledgeBaseId, options);
1400
- if (result.error) {
1401
- throw result.error;
1402
- }
1403
- return result.data;
1404
- } catch (err) {
1405
- setError(err);
1406
- return null;
1407
- } finally {
1408
- setIsLoading(false);
1409
- }
1410
- },
1411
- [client, knowledgeBaseId]
1412
- );
1413
- const reset = (0, import_react9.useCallback)(() => {
1414
- setError(null);
1415
- setIsLoading(false);
1416
- }, []);
1417
- return {
1418
- exportTable,
1419
- isLoading,
1420
- error,
1421
- reset
1422
- };
1423
- }
1424
- function useTableExportSyncs(knowledgeBaseId, options = {}) {
1425
- const { autoFetch = true } = options;
1426
- const client = useFluxbaseClient();
1427
- const [configs, setConfigs] = (0, import_react9.useState)([]);
1428
- const [isLoading, setIsLoading] = (0, import_react9.useState)(autoFetch);
1429
- const [error, setError] = (0, import_react9.useState)(null);
1430
- const fetchData = (0, import_react9.useCallback)(async () => {
1431
- try {
1432
- setIsLoading(true);
1433
- setError(null);
1434
- const result = await client.admin.ai.listTableExportSyncs(knowledgeBaseId);
1435
- if (result.error) {
1436
- throw result.error;
1437
- }
1438
- setConfigs(result.data || []);
1439
- } catch (err) {
1440
- setError(err);
1441
- } finally {
1442
- setIsLoading(false);
1443
- }
1444
- }, [client, knowledgeBaseId]);
1445
- (0, import_react9.useEffect)(() => {
1446
- if (autoFetch) {
1447
- fetchData();
1448
- }
1449
- }, [autoFetch, fetchData]);
1450
- return {
1451
- configs,
1452
- isLoading,
1453
- error,
1454
- refetch: fetchData
1455
- };
1456
- }
1457
- function useCreateTableExportSync(knowledgeBaseId) {
1458
- const client = useFluxbaseClient();
1459
- const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
1460
- const [error, setError] = (0, import_react9.useState)(null);
1461
- const createSync = (0, import_react9.useCallback)(
1462
- async (config) => {
1463
- try {
1464
- setIsLoading(true);
1465
- setError(null);
1466
- const result = await client.admin.ai.createTableExportSync(knowledgeBaseId, config);
1467
- if (result.error) {
1468
- throw result.error;
1469
- }
1470
- return result.data;
1471
- } catch (err) {
1472
- setError(err);
1473
- return null;
1474
- } finally {
1475
- setIsLoading(false);
1476
- }
1477
- },
1478
- [client, knowledgeBaseId]
1479
- );
1480
- return {
1481
- createSync,
1482
- isLoading,
1483
- error
1484
- };
1485
- }
1486
- function useUpdateTableExportSync(knowledgeBaseId) {
1487
- const client = useFluxbaseClient();
1488
- const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
1489
- const [error, setError] = (0, import_react9.useState)(null);
1490
- const updateSync = (0, import_react9.useCallback)(
1491
- async (syncId, updates) => {
1492
- try {
1493
- setIsLoading(true);
1494
- setError(null);
1495
- const result = await client.admin.ai.updateTableExportSync(knowledgeBaseId, syncId, updates);
1496
- if (result.error) {
1497
- throw result.error;
1498
- }
1499
- return result.data;
1500
- } catch (err) {
1501
- setError(err);
1502
- return null;
1503
- } finally {
1504
- setIsLoading(false);
1505
- }
1506
- },
1507
- [client, knowledgeBaseId]
1508
- );
1509
- return {
1510
- updateSync,
1511
- isLoading,
1512
- error
1513
- };
1514
- }
1515
- function useDeleteTableExportSync(knowledgeBaseId) {
1516
- const client = useFluxbaseClient();
1517
- const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
1518
- const [error, setError] = (0, import_react9.useState)(null);
1519
- const deleteSync = (0, import_react9.useCallback)(
1520
- async (syncId) => {
1521
- try {
1522
- setIsLoading(true);
1523
- setError(null);
1524
- const result = await client.admin.ai.deleteTableExportSync(knowledgeBaseId, syncId);
1525
- if (result.error) {
1526
- throw result.error;
1527
- }
1528
- return true;
1529
- } catch (err) {
1530
- setError(err);
1531
- return false;
1532
- } finally {
1533
- setIsLoading(false);
1534
- }
1535
- },
1536
- [client, knowledgeBaseId]
1537
- );
1538
- return {
1539
- deleteSync,
1540
- isLoading,
1541
- error
1542
- };
1543
- }
1544
- function useTriggerTableExportSync(knowledgeBaseId) {
1545
- const client = useFluxbaseClient();
1546
- const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
1547
- const [error, setError] = (0, import_react9.useState)(null);
1548
- const triggerSync = (0, import_react9.useCallback)(
1549
- async (syncId) => {
1550
- try {
1551
- setIsLoading(true);
1552
- setError(null);
1553
- const result = await client.admin.ai.triggerTableExportSync(knowledgeBaseId, syncId);
1554
- if (result.error) {
1555
- throw result.error;
1556
- }
1557
- return result.data;
1558
- } catch (err) {
1559
- setError(err);
1560
- return null;
1561
- } finally {
1562
- setIsLoading(false);
1563
- }
1564
- },
1565
- [client, knowledgeBaseId]
1566
- );
1567
- return {
1568
- triggerSync,
1569
- isLoading,
1570
- error
1571
- };
1572
- }
1573
- // Annotate the CommonJS export names for ESM import in node:
1574
- 0 && (module.exports = {
1575
- FluxbaseProvider,
1576
- isCaptchaRequiredForEndpoint,
1577
- useAPIKeys,
1578
- useAdminAuth,
1579
- useAppSettings,
1580
- useAuth,
1581
- useAuthConfig,
1582
- useCaptcha,
1583
- useCaptchaConfig,
1584
- useClientKeys,
1585
- useCreateBucket,
1586
- useCreateTableExportSync,
1587
- useDelete,
1588
- useDeleteBucket,
1589
- useDeleteTableExportSync,
1590
- useExportTable,
1591
- useFluxbaseClient,
1592
- useFluxbaseQuery,
1593
- useGetSAMLLoginUrl,
1594
- useGraphQL,
1595
- useGraphQLIntrospection,
1596
- useGraphQLMutation,
1597
- useGraphQLQuery,
1598
- useHandleSAMLCallback,
1599
- useInsert,
1600
- useRealtime,
1601
- useSAMLMetadataUrl,
1602
- useSAMLProviders,
1603
- useSession,
1604
- useSignIn,
1605
- useSignInWithSAML,
1606
- useSignOut,
1607
- useSignUp,
1608
- useStorageBuckets,
1609
- useStorageCopy,
1610
- useStorageDelete,
1611
- useStorageDownload,
1612
- useStorageList,
1613
- useStorageMove,
1614
- useStoragePublicUrl,
1615
- useStorageSignedUrl,
1616
- useStorageSignedUrlWithOptions,
1617
- useStorageTransformUrl,
1618
- useStorageUpload,
1619
- useStorageUploadWithProgress,
1620
- useSystemSettings,
1621
- useTable,
1622
- useTableDeletes,
1623
- useTableDetails,
1624
- useTableExportSyncs,
1625
- useTableInserts,
1626
- useTableSubscription,
1627
- useTableUpdates,
1628
- useTriggerTableExportSync,
1629
- useUpdate,
1630
- useUpdateTableExportSync,
1631
- useUpdateUser,
1632
- useUpsert,
1633
- useUser,
1634
- useUsers,
1635
- useWebhooks
1636
- });
1637
- //# sourceMappingURL=index.js.map