@fluxbase/sdk-react 2026.1.22 → 2026.2.1
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.d.mts +33 -2
- package/dist/index.d.ts +33 -2
- package/dist/index.js +33 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -10
- package/src/context.test.tsx +147 -0
- package/src/index.test.ts +255 -0
- package/src/test-setup.ts +22 -0
- package/src/test-utils.tsx +215 -0
- package/src/use-admin-auth.test.ts +175 -0
- package/src/use-admin-auth.ts +10 -2
- package/src/use-admin-hooks.test.ts +457 -0
- package/src/use-auth-config.test.ts +145 -0
- package/src/use-auth.test.ts +313 -0
- package/src/use-auth.ts +2 -1
- package/src/use-captcha.test.ts +273 -0
- package/src/use-client-keys.test.ts +286 -0
- package/src/use-graphql.test.ts +424 -0
- package/src/use-query.test.ts +348 -0
- package/src/use-query.ts +50 -4
- package/src/use-realtime.test.ts +359 -0
- package/src/use-realtime.ts +20 -15
- package/src/use-saml.test.ts +269 -0
- package/src/use-storage.test.ts +549 -0
- package/src/use-storage.ts +10 -2
- package/src/use-users.test.ts +264 -0
- package/vitest.config.ts +22 -0
package/dist/index.mjs
CHANGED
|
@@ -56,7 +56,7 @@ function useSignIn() {
|
|
|
56
56
|
},
|
|
57
57
|
onSuccess: (session) => {
|
|
58
58
|
queryClient.setQueryData(["fluxbase", "auth", "session"], session);
|
|
59
|
-
if ("user" in session) {
|
|
59
|
+
if (session && "user" in session && session.user) {
|
|
60
60
|
queryClient.setQueryData(["fluxbase", "auth", "user"], session.user);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -427,7 +427,12 @@ function useGraphQL() {
|
|
|
427
427
|
import { useQuery as useQuery6, useMutation as useMutation4, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
|
|
428
428
|
function useFluxbaseQuery(buildQuery, options) {
|
|
429
429
|
const client = useFluxbaseClient();
|
|
430
|
-
|
|
430
|
+
if (!options?.queryKey) {
|
|
431
|
+
console.warn(
|
|
432
|
+
"[useFluxbaseQuery] No queryKey provided. This may cause cache misses. Please provide a stable queryKey in options."
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
const queryKey = options?.queryKey || ["fluxbase", "query", "unstable"];
|
|
431
436
|
return useQuery6({
|
|
432
437
|
queryKey,
|
|
433
438
|
queryFn: async () => {
|
|
@@ -443,6 +448,11 @@ function useFluxbaseQuery(buildQuery, options) {
|
|
|
443
448
|
}
|
|
444
449
|
function useTable(table, buildQuery, options) {
|
|
445
450
|
const client = useFluxbaseClient();
|
|
451
|
+
if (buildQuery && !options?.queryKey) {
|
|
452
|
+
console.warn(
|
|
453
|
+
`[useTable] Using buildQuery without a custom queryKey for table "${table}". This may cause cache misses. Provide a queryKey that includes your filter values.`
|
|
454
|
+
);
|
|
455
|
+
}
|
|
446
456
|
return useFluxbaseQuery(
|
|
447
457
|
(client2) => {
|
|
448
458
|
const query = client2.from(table);
|
|
@@ -450,7 +460,8 @@ function useTable(table, buildQuery, options) {
|
|
|
450
460
|
},
|
|
451
461
|
{
|
|
452
462
|
...options,
|
|
453
|
-
|
|
463
|
+
// Use table name as base key, or custom key if provided
|
|
464
|
+
queryKey: options?.queryKey || ["fluxbase", "table", table]
|
|
454
465
|
}
|
|
455
466
|
);
|
|
456
467
|
}
|
|
@@ -541,6 +552,12 @@ function useRealtime(options) {
|
|
|
541
552
|
invalidateKey,
|
|
542
553
|
enabled = true
|
|
543
554
|
} = options;
|
|
555
|
+
const callbackRef = useRef2(callback);
|
|
556
|
+
const invalidateKeyRef = useRef2(invalidateKey);
|
|
557
|
+
const autoInvalidateRef = useRef2(autoInvalidate);
|
|
558
|
+
callbackRef.current = callback;
|
|
559
|
+
invalidateKeyRef.current = invalidateKey;
|
|
560
|
+
autoInvalidateRef.current = autoInvalidate;
|
|
544
561
|
useEffect2(() => {
|
|
545
562
|
if (!enabled) {
|
|
546
563
|
return;
|
|
@@ -548,12 +565,12 @@ function useRealtime(options) {
|
|
|
548
565
|
const channel = client.realtime.channel(channelName);
|
|
549
566
|
channelRef.current = channel;
|
|
550
567
|
const handleChange = (payload) => {
|
|
551
|
-
if (
|
|
552
|
-
|
|
568
|
+
if (callbackRef.current) {
|
|
569
|
+
callbackRef.current(payload);
|
|
553
570
|
}
|
|
554
|
-
if (
|
|
571
|
+
if (autoInvalidateRef.current) {
|
|
555
572
|
const tableName = channelName.replace(/^table:/, "");
|
|
556
|
-
const key =
|
|
573
|
+
const key = invalidateKeyRef.current || ["fluxbase", "table", tableName];
|
|
557
574
|
queryClient.invalidateQueries({ queryKey: key });
|
|
558
575
|
}
|
|
559
576
|
};
|
|
@@ -562,16 +579,7 @@ function useRealtime(options) {
|
|
|
562
579
|
channel.unsubscribe();
|
|
563
580
|
channelRef.current = null;
|
|
564
581
|
};
|
|
565
|
-
}, [
|
|
566
|
-
client,
|
|
567
|
-
channelName,
|
|
568
|
-
event,
|
|
569
|
-
callback,
|
|
570
|
-
autoInvalidate,
|
|
571
|
-
invalidateKey,
|
|
572
|
-
queryClient,
|
|
573
|
-
enabled
|
|
574
|
-
]);
|
|
582
|
+
}, [client, channelName, event, queryClient, enabled]);
|
|
575
583
|
return {
|
|
576
584
|
channel: channelRef.current
|
|
577
585
|
};
|
|
@@ -752,8 +760,10 @@ function useStorageSignedUrl(bucket, path, expiresIn) {
|
|
|
752
760
|
return data?.signedUrl || null;
|
|
753
761
|
},
|
|
754
762
|
enabled: !!path,
|
|
755
|
-
|
|
756
|
-
//
|
|
763
|
+
// Refresh 1 minute before expiry, but ensure staleTime is never negative
|
|
764
|
+
// For very short expirations (<60s), use half the expiration time
|
|
765
|
+
staleTime: expiresIn ? Math.max(expiresIn * 500, expiresIn * 1e3 - 6e4) : 1e3 * 60 * 50
|
|
766
|
+
// 50 minutes default
|
|
757
767
|
});
|
|
758
768
|
}
|
|
759
769
|
function useStorageSignedUrlWithOptions(bucket, path, options) {
|
|
@@ -781,8 +791,10 @@ function useStorageSignedUrlWithOptions(bucket, path, options) {
|
|
|
781
791
|
return data?.signedUrl || null;
|
|
782
792
|
},
|
|
783
793
|
enabled: !!path,
|
|
784
|
-
|
|
785
|
-
//
|
|
794
|
+
// Refresh 1 minute before expiry, but ensure staleTime is never negative
|
|
795
|
+
// For very short expirations (<60s), use half the expiration time
|
|
796
|
+
staleTime: expiresIn ? Math.max(expiresIn * 500, expiresIn * 1e3 - 6e4) : 1e3 * 60 * 50
|
|
797
|
+
// 50 minutes default
|
|
786
798
|
});
|
|
787
799
|
}
|
|
788
800
|
function useStorageMove(bucket) {
|