@fluxbase/sdk-react 0.0.1-rc.6 → 0.0.1-rc.60

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.mjs CHANGED
@@ -20,12 +20,13 @@ function useUser() {
20
20
  return useQuery({
21
21
  queryKey: ["fluxbase", "auth", "user"],
22
22
  queryFn: async () => {
23
- const session = client.auth.getSession();
24
- if (!session) {
23
+ const { data } = await client.auth.getSession();
24
+ if (!data?.session) {
25
25
  return null;
26
26
  }
27
27
  try {
28
- return await client.auth.getCurrentUser();
28
+ const result = await client.auth.getCurrentUser();
29
+ return result.data?.user ?? null;
29
30
  } catch {
30
31
  return null;
31
32
  }
@@ -38,7 +39,10 @@ function useSession() {
38
39
  const client = useFluxbaseClient();
39
40
  return useQuery({
40
41
  queryKey: ["fluxbase", "auth", "session"],
41
- queryFn: () => client.auth.getSession(),
42
+ queryFn: async () => {
43
+ const { data } = await client.auth.getSession();
44
+ return data?.session ?? null;
45
+ },
42
46
  staleTime: 1e3 * 60 * 5
43
47
  // 5 minutes
44
48
  });
@@ -65,9 +69,17 @@ function useSignUp() {
65
69
  mutationFn: async (credentials) => {
66
70
  return await client.auth.signUp(credentials);
67
71
  },
68
- onSuccess: (session) => {
69
- queryClient.setQueryData(["fluxbase", "auth", "session"], session);
70
- queryClient.setQueryData(["fluxbase", "auth", "user"], session.user);
72
+ onSuccess: (response) => {
73
+ if (response.data) {
74
+ queryClient.setQueryData(
75
+ ["fluxbase", "auth", "session"],
76
+ response.data.session
77
+ );
78
+ queryClient.setQueryData(
79
+ ["fluxbase", "auth", "user"],
80
+ response.data.user
81
+ );
82
+ }
71
83
  }
72
84
  });
73
85
  }
@@ -227,7 +239,9 @@ import { useQueryClient as useQueryClient3 } from "@tanstack/react-query";
227
239
  function useRealtime(options) {
228
240
  const client = useFluxbaseClient();
229
241
  const queryClient = useQueryClient3();
230
- const channelRef = useRef(null);
242
+ const channelRef = useRef(
243
+ null
244
+ );
231
245
  const {
232
246
  channel: channelName,
233
247
  event = "*",
@@ -257,7 +271,16 @@ function useRealtime(options) {
257
271
  channel.unsubscribe();
258
272
  channelRef.current = null;
259
273
  };
260
- }, [client, channelName, event, callback, autoInvalidate, invalidateKey, queryClient, enabled]);
274
+ }, [
275
+ client,
276
+ channelName,
277
+ event,
278
+ callback,
279
+ autoInvalidate,
280
+ invalidateKey,
281
+ queryClient,
282
+ enabled
283
+ ]);
261
284
  return {
262
285
  channel: channelRef.current
263
286
  };
@@ -294,12 +317,23 @@ function useTableDeletes(table, callback, options) {
294
317
  }
295
318
 
296
319
  // src/use-storage.ts
297
- import { useMutation as useMutation3, useQuery as useQuery3, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
320
+ import { useState } from "react";
321
+ import {
322
+ useMutation as useMutation3,
323
+ useQuery as useQuery3,
324
+ useQueryClient as useQueryClient4
325
+ } from "@tanstack/react-query";
298
326
  function useStorageList(bucket, options) {
299
327
  const client = useFluxbaseClient();
300
328
  const { prefix, limit, offset, ...queryOptions } = options || {};
301
329
  return useQuery3({
302
- queryKey: ["fluxbase", "storage", bucket, "list", { prefix, limit, offset }],
330
+ queryKey: [
331
+ "fluxbase",
332
+ "storage",
333
+ bucket,
334
+ "list",
335
+ { prefix, limit, offset }
336
+ ],
303
337
  queryFn: async () => {
304
338
  const { data, error } = await client.storage.from(bucket).list({ prefix, limit, offset });
305
339
  if (error) {
@@ -323,7 +357,9 @@ function useStorageUpload(bucket) {
323
357
  return data;
324
358
  },
325
359
  onSuccess: () => {
326
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "storage", bucket, "list"] });
360
+ queryClient.invalidateQueries({
361
+ queryKey: ["fluxbase", "storage", bucket, "list"]
362
+ });
327
363
  }
328
364
  });
329
365
  }
@@ -355,7 +391,9 @@ function useStorageDelete(bucket) {
355
391
  }
356
392
  },
357
393
  onSuccess: () => {
358
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "storage", bucket, "list"] });
394
+ queryClient.invalidateQueries({
395
+ queryKey: ["fluxbase", "storage", bucket, "list"]
396
+ });
359
397
  }
360
398
  });
361
399
  }
@@ -399,7 +437,9 @@ function useStorageMove(bucket) {
399
437
  return data;
400
438
  },
401
439
  onSuccess: () => {
402
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "storage", bucket, "list"] });
440
+ queryClient.invalidateQueries({
441
+ queryKey: ["fluxbase", "storage", bucket, "list"]
442
+ });
403
443
  }
404
444
  });
405
445
  }
@@ -416,7 +456,9 @@ function useStorageCopy(bucket) {
416
456
  return data;
417
457
  },
418
458
  onSuccess: () => {
419
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "storage", bucket, "list"] });
459
+ queryClient.invalidateQueries({
460
+ queryKey: ["fluxbase", "storage", bucket, "list"]
461
+ });
420
462
  }
421
463
  });
422
464
  }
@@ -444,7 +486,9 @@ function useCreateBucket() {
444
486
  }
445
487
  },
446
488
  onSuccess: () => {
447
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "storage", "buckets"] });
489
+ queryClient.invalidateQueries({
490
+ queryKey: ["fluxbase", "storage", "buckets"]
491
+ });
448
492
  }
449
493
  });
450
494
  }
@@ -459,74 +503,30 @@ function useDeleteBucket() {
459
503
  }
460
504
  },
461
505
  onSuccess: () => {
462
- queryClient.invalidateQueries({ queryKey: ["fluxbase", "storage", "buckets"] });
506
+ queryClient.invalidateQueries({
507
+ queryKey: ["fluxbase", "storage", "buckets"]
508
+ });
463
509
  }
464
510
  });
465
511
  }
466
512
 
467
- // src/use-rpc.ts
468
- import { useQuery as useQuery4, useMutation as useMutation4 } from "@tanstack/react-query";
469
- function useRPC(functionName, params, options) {
470
- const client = useFluxbaseClient();
471
- return useQuery4({
472
- queryKey: ["rpc", functionName, params],
473
- queryFn: async () => {
474
- const { data, error } = await client.rpc(functionName, params);
475
- if (error) {
476
- throw new Error(error.message);
477
- }
478
- return data;
479
- },
480
- ...options
481
- });
482
- }
483
- function useRPCMutation(functionName, options) {
484
- const client = useFluxbaseClient();
485
- return useMutation4({
486
- mutationFn: async (params) => {
487
- const { data, error } = await client.rpc(functionName, params);
488
- if (error) {
489
- throw new Error(error.message);
490
- }
491
- return data;
492
- },
493
- ...options
494
- });
495
- }
496
- function useRPCBatch(calls, options) {
497
- const client = useFluxbaseClient();
498
- return useQuery4({
499
- queryKey: ["rpc-batch", calls],
500
- queryFn: async () => {
501
- const results = await Promise.all(
502
- calls.map(async ({ name, params }) => {
503
- const { data, error } = await client.rpc(name, params);
504
- if (error) {
505
- throw new Error(`${name}: ${error.message}`);
506
- }
507
- return data;
508
- })
509
- );
510
- return results;
511
- },
512
- ...options
513
- });
514
- }
515
-
516
513
  // src/use-admin-auth.ts
517
- import { useState, useEffect as useEffect2, useCallback } from "react";
514
+ import { useState as useState2, useEffect as useEffect2, useCallback } from "react";
518
515
  function useAdminAuth(options = {}) {
519
516
  const { autoCheck = true } = options;
520
517
  const client = useFluxbaseClient();
521
- const [user, setUser] = useState(null);
522
- const [isLoading, setIsLoading] = useState(autoCheck);
523
- const [error, setError] = useState(null);
518
+ const [user, setUser] = useState2(null);
519
+ const [isLoading, setIsLoading] = useState2(autoCheck);
520
+ const [error, setError] = useState2(null);
524
521
  const checkAuth = useCallback(async () => {
525
522
  try {
526
523
  setIsLoading(true);
527
524
  setError(null);
528
- const { user: user2 } = await client.admin.me();
529
- setUser(user2);
525
+ const { data, error: apiError } = await client.admin.me();
526
+ if (apiError) {
527
+ throw apiError;
528
+ }
529
+ setUser(data.user);
530
530
  } catch (err) {
531
531
  setUser(null);
532
532
  setError(err);
@@ -539,9 +539,15 @@ function useAdminAuth(options = {}) {
539
539
  try {
540
540
  setIsLoading(true);
541
541
  setError(null);
542
- const response = await client.admin.login({ email, password });
543
- setUser(response.user);
544
- return response;
542
+ const { data, error: apiError } = await client.admin.login({
543
+ email,
544
+ password
545
+ });
546
+ if (apiError) {
547
+ throw apiError;
548
+ }
549
+ setUser(data.user);
550
+ return data;
545
551
  } catch (err) {
546
552
  setError(err);
547
553
  throw err;
@@ -583,21 +589,24 @@ function useAdminAuth(options = {}) {
583
589
  }
584
590
 
585
591
  // src/use-users.ts
586
- import { useState as useState2, useEffect as useEffect3, useCallback as useCallback2 } from "react";
592
+ import { useState as useState3, useEffect as useEffect3, useCallback as useCallback2 } from "react";
587
593
  function useUsers(options = {}) {
588
594
  const { autoFetch = true, refetchInterval = 0, ...listOptions } = options;
589
595
  const client = useFluxbaseClient();
590
- const [users, setUsers] = useState2([]);
591
- const [total, setTotal] = useState2(0);
592
- const [isLoading, setIsLoading] = useState2(autoFetch);
593
- const [error, setError] = useState2(null);
596
+ const [users, setUsers] = useState3([]);
597
+ const [total, setTotal] = useState3(0);
598
+ const [isLoading, setIsLoading] = useState3(autoFetch);
599
+ const [error, setError] = useState3(null);
594
600
  const fetchUsers = useCallback2(async () => {
595
601
  try {
596
602
  setIsLoading(true);
597
603
  setError(null);
598
- const response = await client.admin.listUsers(listOptions);
599
- setUsers(response.users);
600
- setTotal(response.total);
604
+ const { data, error: apiError } = await client.admin.listUsers(listOptions);
605
+ if (apiError) {
606
+ throw apiError;
607
+ }
608
+ setUsers(data.users);
609
+ setTotal(data.total);
601
610
  } catch (err) {
602
611
  setError(err);
603
612
  } finally {
@@ -627,7 +636,11 @@ function useUsers(options = {}) {
627
636
  );
628
637
  const resetPassword = useCallback2(
629
638
  async (userId) => {
630
- return await client.admin.resetUserPassword(userId);
639
+ const { data, error: error2 } = await client.admin.resetUserPassword(userId);
640
+ if (error2) {
641
+ throw error2;
642
+ }
643
+ return data;
631
644
  },
632
645
  [client]
633
646
  );
@@ -656,13 +669,13 @@ function useUsers(options = {}) {
656
669
  }
657
670
 
658
671
  // src/use-api-keys.ts
659
- import { useState as useState3, useEffect as useEffect4, useCallback as useCallback3 } from "react";
672
+ import { useState as useState4, useEffect as useEffect4, useCallback as useCallback3 } from "react";
660
673
  function useAPIKeys(options = {}) {
661
674
  const { autoFetch = true } = options;
662
675
  const client = useFluxbaseClient();
663
- const [keys, setKeys] = useState3([]);
664
- const [isLoading, setIsLoading] = useState3(autoFetch);
665
- const [error, setError] = useState3(null);
676
+ const [keys, setKeys] = useState4([]);
677
+ const [isLoading, setIsLoading] = useState4(autoFetch);
678
+ const [error, setError] = useState4(null);
666
679
  const fetchKeys = useCallback3(async () => {
667
680
  try {
668
681
  setIsLoading(true);
@@ -722,13 +735,13 @@ function useAPIKeys(options = {}) {
722
735
  }
723
736
 
724
737
  // src/use-admin-hooks.ts
725
- import { useState as useState4, useEffect as useEffect5, useCallback as useCallback4 } from "react";
738
+ import { useState as useState5, useEffect as useEffect5, useCallback as useCallback4 } from "react";
726
739
  function useAppSettings(options = {}) {
727
740
  const { autoFetch = true } = options;
728
741
  const client = useFluxbaseClient();
729
- const [settings, setSettings] = useState4(null);
730
- const [isLoading, setIsLoading] = useState4(autoFetch);
731
- const [error, setError] = useState4(null);
742
+ const [settings, setSettings] = useState5(null);
743
+ const [isLoading, setIsLoading] = useState5(autoFetch);
744
+ const [error, setError] = useState5(null);
732
745
  const fetchSettings = useCallback4(async () => {
733
746
  try {
734
747
  setIsLoading(true);
@@ -764,9 +777,9 @@ function useAppSettings(options = {}) {
764
777
  function useSystemSettings(options = {}) {
765
778
  const { autoFetch = true } = options;
766
779
  const client = useFluxbaseClient();
767
- const [settings, setSettings] = useState4([]);
768
- const [isLoading, setIsLoading] = useState4(autoFetch);
769
- const [error, setError] = useState4(null);
780
+ const [settings, setSettings] = useState5([]);
781
+ const [isLoading, setIsLoading] = useState5(autoFetch);
782
+ const [error, setError] = useState5(null);
770
783
  const fetchSettings = useCallback4(async () => {
771
784
  try {
772
785
  setIsLoading(true);
@@ -817,9 +830,9 @@ function useSystemSettings(options = {}) {
817
830
  function useWebhooks(options = {}) {
818
831
  const { autoFetch = true, refetchInterval = 0 } = options;
819
832
  const client = useFluxbaseClient();
820
- const [webhooks, setWebhooks] = useState4([]);
821
- const [isLoading, setIsLoading] = useState4(autoFetch);
822
- const [error, setError] = useState4(null);
833
+ const [webhooks, setWebhooks] = useState5([]);
834
+ const [isLoading, setIsLoading] = useState5(autoFetch);
835
+ const [error, setError] = useState5(null);
823
836
  const fetchWebhooks = useCallback4(async () => {
824
837
  try {
825
838
  setIsLoading(true);
@@ -893,9 +906,6 @@ export {
893
906
  useFluxbaseClient,
894
907
  useFluxbaseQuery,
895
908
  useInsert,
896
- useRPC,
897
- useRPCBatch,
898
- useRPCMutation,
899
909
  useRealtime,
900
910
  useSession,
901
911
  useSignIn,