@fluxbase/sdk-react 0.0.1-rc.6 → 0.0.1-rc.61
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/CHANGELOG.md +1 -1
- package/README.md +27 -14
- package/dist/index.d.mts +45 -65
- package/dist/index.d.ts +45 -65
- package/dist/index.js +138 -135
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -101
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +0 -7
- package/src/use-admin-auth.ts +62 -51
- package/src/use-auth.ts +66 -49
- package/src/use-realtime.ts +58 -44
- package/src/use-storage.ts +211 -82
- package/src/use-users.ts +11 -4
- package/typedoc.json +2 -4
- package/src/use-rpc.ts +0 -109
package/dist/index.js
CHANGED
|
@@ -31,9 +31,6 @@ __export(index_exports, {
|
|
|
31
31
|
useFluxbaseClient: () => useFluxbaseClient,
|
|
32
32
|
useFluxbaseQuery: () => useFluxbaseQuery,
|
|
33
33
|
useInsert: () => useInsert,
|
|
34
|
-
useRPC: () => useRPC,
|
|
35
|
-
useRPCBatch: () => useRPCBatch,
|
|
36
|
-
useRPCMutation: () => useRPCMutation,
|
|
37
34
|
useRealtime: () => useRealtime,
|
|
38
35
|
useSession: () => useSession,
|
|
39
36
|
useSignIn: () => useSignIn,
|
|
@@ -85,12 +82,13 @@ function useUser() {
|
|
|
85
82
|
return (0, import_react_query.useQuery)({
|
|
86
83
|
queryKey: ["fluxbase", "auth", "user"],
|
|
87
84
|
queryFn: async () => {
|
|
88
|
-
const
|
|
89
|
-
if (!session) {
|
|
85
|
+
const { data } = await client.auth.getSession();
|
|
86
|
+
if (!data?.session) {
|
|
90
87
|
return null;
|
|
91
88
|
}
|
|
92
89
|
try {
|
|
93
|
-
|
|
90
|
+
const result = await client.auth.getCurrentUser();
|
|
91
|
+
return result.data?.user ?? null;
|
|
94
92
|
} catch {
|
|
95
93
|
return null;
|
|
96
94
|
}
|
|
@@ -103,7 +101,10 @@ function useSession() {
|
|
|
103
101
|
const client = useFluxbaseClient();
|
|
104
102
|
return (0, import_react_query.useQuery)({
|
|
105
103
|
queryKey: ["fluxbase", "auth", "session"],
|
|
106
|
-
queryFn: () =>
|
|
104
|
+
queryFn: async () => {
|
|
105
|
+
const { data } = await client.auth.getSession();
|
|
106
|
+
return data?.session ?? null;
|
|
107
|
+
},
|
|
107
108
|
staleTime: 1e3 * 60 * 5
|
|
108
109
|
// 5 minutes
|
|
109
110
|
});
|
|
@@ -130,9 +131,17 @@ function useSignUp() {
|
|
|
130
131
|
mutationFn: async (credentials) => {
|
|
131
132
|
return await client.auth.signUp(credentials);
|
|
132
133
|
},
|
|
133
|
-
onSuccess: (
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
onSuccess: (response) => {
|
|
135
|
+
if (response.data) {
|
|
136
|
+
queryClient.setQueryData(
|
|
137
|
+
["fluxbase", "auth", "session"],
|
|
138
|
+
response.data.session
|
|
139
|
+
);
|
|
140
|
+
queryClient.setQueryData(
|
|
141
|
+
["fluxbase", "auth", "user"],
|
|
142
|
+
response.data.user
|
|
143
|
+
);
|
|
144
|
+
}
|
|
136
145
|
}
|
|
137
146
|
});
|
|
138
147
|
}
|
|
@@ -292,7 +301,9 @@ var import_react_query3 = require("@tanstack/react-query");
|
|
|
292
301
|
function useRealtime(options) {
|
|
293
302
|
const client = useFluxbaseClient();
|
|
294
303
|
const queryClient = (0, import_react_query3.useQueryClient)();
|
|
295
|
-
const channelRef = (0, import_react2.useRef)(
|
|
304
|
+
const channelRef = (0, import_react2.useRef)(
|
|
305
|
+
null
|
|
306
|
+
);
|
|
296
307
|
const {
|
|
297
308
|
channel: channelName,
|
|
298
309
|
event = "*",
|
|
@@ -322,7 +333,16 @@ function useRealtime(options) {
|
|
|
322
333
|
channel.unsubscribe();
|
|
323
334
|
channelRef.current = null;
|
|
324
335
|
};
|
|
325
|
-
}, [
|
|
336
|
+
}, [
|
|
337
|
+
client,
|
|
338
|
+
channelName,
|
|
339
|
+
event,
|
|
340
|
+
callback,
|
|
341
|
+
autoInvalidate,
|
|
342
|
+
invalidateKey,
|
|
343
|
+
queryClient,
|
|
344
|
+
enabled
|
|
345
|
+
]);
|
|
326
346
|
return {
|
|
327
347
|
channel: channelRef.current
|
|
328
348
|
};
|
|
@@ -359,12 +379,19 @@ function useTableDeletes(table, callback, options) {
|
|
|
359
379
|
}
|
|
360
380
|
|
|
361
381
|
// src/use-storage.ts
|
|
382
|
+
var import_react3 = require("react");
|
|
362
383
|
var import_react_query4 = require("@tanstack/react-query");
|
|
363
384
|
function useStorageList(bucket, options) {
|
|
364
385
|
const client = useFluxbaseClient();
|
|
365
386
|
const { prefix, limit, offset, ...queryOptions } = options || {};
|
|
366
387
|
return (0, import_react_query4.useQuery)({
|
|
367
|
-
queryKey: [
|
|
388
|
+
queryKey: [
|
|
389
|
+
"fluxbase",
|
|
390
|
+
"storage",
|
|
391
|
+
bucket,
|
|
392
|
+
"list",
|
|
393
|
+
{ prefix, limit, offset }
|
|
394
|
+
],
|
|
368
395
|
queryFn: async () => {
|
|
369
396
|
const { data, error } = await client.storage.from(bucket).list({ prefix, limit, offset });
|
|
370
397
|
if (error) {
|
|
@@ -388,7 +415,9 @@ function useStorageUpload(bucket) {
|
|
|
388
415
|
return data;
|
|
389
416
|
},
|
|
390
417
|
onSuccess: () => {
|
|
391
|
-
queryClient.invalidateQueries({
|
|
418
|
+
queryClient.invalidateQueries({
|
|
419
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
420
|
+
});
|
|
392
421
|
}
|
|
393
422
|
});
|
|
394
423
|
}
|
|
@@ -420,7 +449,9 @@ function useStorageDelete(bucket) {
|
|
|
420
449
|
}
|
|
421
450
|
},
|
|
422
451
|
onSuccess: () => {
|
|
423
|
-
queryClient.invalidateQueries({
|
|
452
|
+
queryClient.invalidateQueries({
|
|
453
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
454
|
+
});
|
|
424
455
|
}
|
|
425
456
|
});
|
|
426
457
|
}
|
|
@@ -464,7 +495,9 @@ function useStorageMove(bucket) {
|
|
|
464
495
|
return data;
|
|
465
496
|
},
|
|
466
497
|
onSuccess: () => {
|
|
467
|
-
queryClient.invalidateQueries({
|
|
498
|
+
queryClient.invalidateQueries({
|
|
499
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
500
|
+
});
|
|
468
501
|
}
|
|
469
502
|
});
|
|
470
503
|
}
|
|
@@ -481,7 +514,9 @@ function useStorageCopy(bucket) {
|
|
|
481
514
|
return data;
|
|
482
515
|
},
|
|
483
516
|
onSuccess: () => {
|
|
484
|
-
queryClient.invalidateQueries({
|
|
517
|
+
queryClient.invalidateQueries({
|
|
518
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
519
|
+
});
|
|
485
520
|
}
|
|
486
521
|
});
|
|
487
522
|
}
|
|
@@ -509,7 +544,9 @@ function useCreateBucket() {
|
|
|
509
544
|
}
|
|
510
545
|
},
|
|
511
546
|
onSuccess: () => {
|
|
512
|
-
queryClient.invalidateQueries({
|
|
547
|
+
queryClient.invalidateQueries({
|
|
548
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
549
|
+
});
|
|
513
550
|
}
|
|
514
551
|
});
|
|
515
552
|
}
|
|
@@ -524,74 +561,30 @@ function useDeleteBucket() {
|
|
|
524
561
|
}
|
|
525
562
|
},
|
|
526
563
|
onSuccess: () => {
|
|
527
|
-
queryClient.invalidateQueries({
|
|
564
|
+
queryClient.invalidateQueries({
|
|
565
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
566
|
+
});
|
|
528
567
|
}
|
|
529
568
|
});
|
|
530
569
|
}
|
|
531
570
|
|
|
532
|
-
// src/use-rpc.ts
|
|
533
|
-
var import_react_query5 = require("@tanstack/react-query");
|
|
534
|
-
function useRPC(functionName, params, options) {
|
|
535
|
-
const client = useFluxbaseClient();
|
|
536
|
-
return (0, import_react_query5.useQuery)({
|
|
537
|
-
queryKey: ["rpc", functionName, params],
|
|
538
|
-
queryFn: async () => {
|
|
539
|
-
const { data, error } = await client.rpc(functionName, params);
|
|
540
|
-
if (error) {
|
|
541
|
-
throw new Error(error.message);
|
|
542
|
-
}
|
|
543
|
-
return data;
|
|
544
|
-
},
|
|
545
|
-
...options
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
function useRPCMutation(functionName, options) {
|
|
549
|
-
const client = useFluxbaseClient();
|
|
550
|
-
return (0, import_react_query5.useMutation)({
|
|
551
|
-
mutationFn: async (params) => {
|
|
552
|
-
const { data, error } = await client.rpc(functionName, params);
|
|
553
|
-
if (error) {
|
|
554
|
-
throw new Error(error.message);
|
|
555
|
-
}
|
|
556
|
-
return data;
|
|
557
|
-
},
|
|
558
|
-
...options
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
function useRPCBatch(calls, options) {
|
|
562
|
-
const client = useFluxbaseClient();
|
|
563
|
-
return (0, import_react_query5.useQuery)({
|
|
564
|
-
queryKey: ["rpc-batch", calls],
|
|
565
|
-
queryFn: async () => {
|
|
566
|
-
const results = await Promise.all(
|
|
567
|
-
calls.map(async ({ name, params }) => {
|
|
568
|
-
const { data, error } = await client.rpc(name, params);
|
|
569
|
-
if (error) {
|
|
570
|
-
throw new Error(`${name}: ${error.message}`);
|
|
571
|
-
}
|
|
572
|
-
return data;
|
|
573
|
-
})
|
|
574
|
-
);
|
|
575
|
-
return results;
|
|
576
|
-
},
|
|
577
|
-
...options
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
|
|
581
571
|
// src/use-admin-auth.ts
|
|
582
|
-
var
|
|
572
|
+
var import_react4 = require("react");
|
|
583
573
|
function useAdminAuth(options = {}) {
|
|
584
574
|
const { autoCheck = true } = options;
|
|
585
575
|
const client = useFluxbaseClient();
|
|
586
|
-
const [user, setUser] = (0,
|
|
587
|
-
const [isLoading, setIsLoading] = (0,
|
|
588
|
-
const [error, setError] = (0,
|
|
589
|
-
const checkAuth = (0,
|
|
576
|
+
const [user, setUser] = (0, import_react4.useState)(null);
|
|
577
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(autoCheck);
|
|
578
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
579
|
+
const checkAuth = (0, import_react4.useCallback)(async () => {
|
|
590
580
|
try {
|
|
591
581
|
setIsLoading(true);
|
|
592
582
|
setError(null);
|
|
593
|
-
const {
|
|
594
|
-
|
|
583
|
+
const { data, error: apiError } = await client.admin.me();
|
|
584
|
+
if (apiError) {
|
|
585
|
+
throw apiError;
|
|
586
|
+
}
|
|
587
|
+
setUser(data.user);
|
|
595
588
|
} catch (err) {
|
|
596
589
|
setUser(null);
|
|
597
590
|
setError(err);
|
|
@@ -599,14 +592,20 @@ function useAdminAuth(options = {}) {
|
|
|
599
592
|
setIsLoading(false);
|
|
600
593
|
}
|
|
601
594
|
}, [client]);
|
|
602
|
-
const login = (0,
|
|
595
|
+
const login = (0, import_react4.useCallback)(
|
|
603
596
|
async (email, password) => {
|
|
604
597
|
try {
|
|
605
598
|
setIsLoading(true);
|
|
606
599
|
setError(null);
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
600
|
+
const { data, error: apiError } = await client.admin.login({
|
|
601
|
+
email,
|
|
602
|
+
password
|
|
603
|
+
});
|
|
604
|
+
if (apiError) {
|
|
605
|
+
throw apiError;
|
|
606
|
+
}
|
|
607
|
+
setUser(data.user);
|
|
608
|
+
return data;
|
|
610
609
|
} catch (err) {
|
|
611
610
|
setError(err);
|
|
612
611
|
throw err;
|
|
@@ -616,7 +615,7 @@ function useAdminAuth(options = {}) {
|
|
|
616
615
|
},
|
|
617
616
|
[client]
|
|
618
617
|
);
|
|
619
|
-
const logout = (0,
|
|
618
|
+
const logout = (0, import_react4.useCallback)(async () => {
|
|
620
619
|
try {
|
|
621
620
|
setIsLoading(true);
|
|
622
621
|
setError(null);
|
|
@@ -628,10 +627,10 @@ function useAdminAuth(options = {}) {
|
|
|
628
627
|
setIsLoading(false);
|
|
629
628
|
}
|
|
630
629
|
}, []);
|
|
631
|
-
const refresh = (0,
|
|
630
|
+
const refresh = (0, import_react4.useCallback)(async () => {
|
|
632
631
|
await checkAuth();
|
|
633
632
|
}, [checkAuth]);
|
|
634
|
-
(0,
|
|
633
|
+
(0, import_react4.useEffect)(() => {
|
|
635
634
|
if (autoCheck) {
|
|
636
635
|
checkAuth();
|
|
637
636
|
}
|
|
@@ -648,60 +647,67 @@ function useAdminAuth(options = {}) {
|
|
|
648
647
|
}
|
|
649
648
|
|
|
650
649
|
// src/use-users.ts
|
|
651
|
-
var
|
|
650
|
+
var import_react5 = require("react");
|
|
652
651
|
function useUsers(options = {}) {
|
|
653
652
|
const { autoFetch = true, refetchInterval = 0, ...listOptions } = options;
|
|
654
653
|
const client = useFluxbaseClient();
|
|
655
|
-
const [users, setUsers] = (0,
|
|
656
|
-
const [total, setTotal] = (0,
|
|
657
|
-
const [isLoading, setIsLoading] = (0,
|
|
658
|
-
const [error, setError] = (0,
|
|
659
|
-
const fetchUsers = (0,
|
|
654
|
+
const [users, setUsers] = (0, import_react5.useState)([]);
|
|
655
|
+
const [total, setTotal] = (0, import_react5.useState)(0);
|
|
656
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(autoFetch);
|
|
657
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
658
|
+
const fetchUsers = (0, import_react5.useCallback)(async () => {
|
|
660
659
|
try {
|
|
661
660
|
setIsLoading(true);
|
|
662
661
|
setError(null);
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
|
|
662
|
+
const { data, error: apiError } = await client.admin.listUsers(listOptions);
|
|
663
|
+
if (apiError) {
|
|
664
|
+
throw apiError;
|
|
665
|
+
}
|
|
666
|
+
setUsers(data.users);
|
|
667
|
+
setTotal(data.total);
|
|
666
668
|
} catch (err) {
|
|
667
669
|
setError(err);
|
|
668
670
|
} finally {
|
|
669
671
|
setIsLoading(false);
|
|
670
672
|
}
|
|
671
673
|
}, [client, JSON.stringify(listOptions)]);
|
|
672
|
-
const inviteUser = (0,
|
|
674
|
+
const inviteUser = (0, import_react5.useCallback)(
|
|
673
675
|
async (email, role) => {
|
|
674
676
|
await client.admin.inviteUser({ email, role });
|
|
675
677
|
await fetchUsers();
|
|
676
678
|
},
|
|
677
679
|
[client, fetchUsers]
|
|
678
680
|
);
|
|
679
|
-
const updateUserRole = (0,
|
|
681
|
+
const updateUserRole = (0, import_react5.useCallback)(
|
|
680
682
|
async (userId, role) => {
|
|
681
683
|
await client.admin.updateUserRole(userId, role);
|
|
682
684
|
await fetchUsers();
|
|
683
685
|
},
|
|
684
686
|
[client, fetchUsers]
|
|
685
687
|
);
|
|
686
|
-
const deleteUser = (0,
|
|
688
|
+
const deleteUser = (0, import_react5.useCallback)(
|
|
687
689
|
async (userId) => {
|
|
688
690
|
await client.admin.deleteUser(userId);
|
|
689
691
|
await fetchUsers();
|
|
690
692
|
},
|
|
691
693
|
[client, fetchUsers]
|
|
692
694
|
);
|
|
693
|
-
const resetPassword = (0,
|
|
695
|
+
const resetPassword = (0, import_react5.useCallback)(
|
|
694
696
|
async (userId) => {
|
|
695
|
-
|
|
697
|
+
const { data, error: error2 } = await client.admin.resetUserPassword(userId);
|
|
698
|
+
if (error2) {
|
|
699
|
+
throw error2;
|
|
700
|
+
}
|
|
701
|
+
return data;
|
|
696
702
|
},
|
|
697
703
|
[client]
|
|
698
704
|
);
|
|
699
|
-
(0,
|
|
705
|
+
(0, import_react5.useEffect)(() => {
|
|
700
706
|
if (autoFetch) {
|
|
701
707
|
fetchUsers();
|
|
702
708
|
}
|
|
703
709
|
}, [autoFetch, fetchUsers]);
|
|
704
|
-
(0,
|
|
710
|
+
(0, import_react5.useEffect)(() => {
|
|
705
711
|
if (refetchInterval > 0) {
|
|
706
712
|
const interval = setInterval(fetchUsers, refetchInterval);
|
|
707
713
|
return () => clearInterval(interval);
|
|
@@ -721,14 +727,14 @@ function useUsers(options = {}) {
|
|
|
721
727
|
}
|
|
722
728
|
|
|
723
729
|
// src/use-api-keys.ts
|
|
724
|
-
var
|
|
730
|
+
var import_react6 = require("react");
|
|
725
731
|
function useAPIKeys(options = {}) {
|
|
726
732
|
const { autoFetch = true } = options;
|
|
727
733
|
const client = useFluxbaseClient();
|
|
728
|
-
const [keys, setKeys] = (0,
|
|
729
|
-
const [isLoading, setIsLoading] = (0,
|
|
730
|
-
const [error, setError] = (0,
|
|
731
|
-
const fetchKeys = (0,
|
|
734
|
+
const [keys, setKeys] = (0, import_react6.useState)([]);
|
|
735
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(autoFetch);
|
|
736
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
737
|
+
const fetchKeys = (0, import_react6.useCallback)(async () => {
|
|
732
738
|
try {
|
|
733
739
|
setIsLoading(true);
|
|
734
740
|
setError(null);
|
|
@@ -740,7 +746,7 @@ function useAPIKeys(options = {}) {
|
|
|
740
746
|
setIsLoading(false);
|
|
741
747
|
}
|
|
742
748
|
}, [client]);
|
|
743
|
-
const createKey = (0,
|
|
749
|
+
const createKey = (0, import_react6.useCallback)(
|
|
744
750
|
async (request) => {
|
|
745
751
|
const response = await client.admin.management.apiKeys.create(request);
|
|
746
752
|
await fetchKeys();
|
|
@@ -748,28 +754,28 @@ function useAPIKeys(options = {}) {
|
|
|
748
754
|
},
|
|
749
755
|
[client, fetchKeys]
|
|
750
756
|
);
|
|
751
|
-
const updateKey = (0,
|
|
757
|
+
const updateKey = (0, import_react6.useCallback)(
|
|
752
758
|
async (keyId, update) => {
|
|
753
759
|
await client.admin.management.apiKeys.update(keyId, update);
|
|
754
760
|
await fetchKeys();
|
|
755
761
|
},
|
|
756
762
|
[client, fetchKeys]
|
|
757
763
|
);
|
|
758
|
-
const revokeKey = (0,
|
|
764
|
+
const revokeKey = (0, import_react6.useCallback)(
|
|
759
765
|
async (keyId) => {
|
|
760
766
|
await client.admin.management.apiKeys.revoke(keyId);
|
|
761
767
|
await fetchKeys();
|
|
762
768
|
},
|
|
763
769
|
[client, fetchKeys]
|
|
764
770
|
);
|
|
765
|
-
const deleteKey = (0,
|
|
771
|
+
const deleteKey = (0, import_react6.useCallback)(
|
|
766
772
|
async (keyId) => {
|
|
767
773
|
await client.admin.management.apiKeys.delete(keyId);
|
|
768
774
|
await fetchKeys();
|
|
769
775
|
},
|
|
770
776
|
[client, fetchKeys]
|
|
771
777
|
);
|
|
772
|
-
(0,
|
|
778
|
+
(0, import_react6.useEffect)(() => {
|
|
773
779
|
if (autoFetch) {
|
|
774
780
|
fetchKeys();
|
|
775
781
|
}
|
|
@@ -787,14 +793,14 @@ function useAPIKeys(options = {}) {
|
|
|
787
793
|
}
|
|
788
794
|
|
|
789
795
|
// src/use-admin-hooks.ts
|
|
790
|
-
var
|
|
796
|
+
var import_react7 = require("react");
|
|
791
797
|
function useAppSettings(options = {}) {
|
|
792
798
|
const { autoFetch = true } = options;
|
|
793
799
|
const client = useFluxbaseClient();
|
|
794
|
-
const [settings, setSettings] = (0,
|
|
795
|
-
const [isLoading, setIsLoading] = (0,
|
|
796
|
-
const [error, setError] = (0,
|
|
797
|
-
const fetchSettings = (0,
|
|
800
|
+
const [settings, setSettings] = (0, import_react7.useState)(null);
|
|
801
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
|
|
802
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
803
|
+
const fetchSettings = (0, import_react7.useCallback)(async () => {
|
|
798
804
|
try {
|
|
799
805
|
setIsLoading(true);
|
|
800
806
|
setError(null);
|
|
@@ -806,14 +812,14 @@ function useAppSettings(options = {}) {
|
|
|
806
812
|
setIsLoading(false);
|
|
807
813
|
}
|
|
808
814
|
}, [client]);
|
|
809
|
-
const updateSettings = (0,
|
|
815
|
+
const updateSettings = (0, import_react7.useCallback)(
|
|
810
816
|
async (update) => {
|
|
811
817
|
await client.admin.settings.app.update(update);
|
|
812
818
|
await fetchSettings();
|
|
813
819
|
},
|
|
814
820
|
[client, fetchSettings]
|
|
815
821
|
);
|
|
816
|
-
(0,
|
|
822
|
+
(0, import_react7.useEffect)(() => {
|
|
817
823
|
if (autoFetch) {
|
|
818
824
|
fetchSettings();
|
|
819
825
|
}
|
|
@@ -829,10 +835,10 @@ function useAppSettings(options = {}) {
|
|
|
829
835
|
function useSystemSettings(options = {}) {
|
|
830
836
|
const { autoFetch = true } = options;
|
|
831
837
|
const client = useFluxbaseClient();
|
|
832
|
-
const [settings, setSettings] = (0,
|
|
833
|
-
const [isLoading, setIsLoading] = (0,
|
|
834
|
-
const [error, setError] = (0,
|
|
835
|
-
const fetchSettings = (0,
|
|
838
|
+
const [settings, setSettings] = (0, import_react7.useState)([]);
|
|
839
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
|
|
840
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
841
|
+
const fetchSettings = (0, import_react7.useCallback)(async () => {
|
|
836
842
|
try {
|
|
837
843
|
setIsLoading(true);
|
|
838
844
|
setError(null);
|
|
@@ -844,27 +850,27 @@ function useSystemSettings(options = {}) {
|
|
|
844
850
|
setIsLoading(false);
|
|
845
851
|
}
|
|
846
852
|
}, [client]);
|
|
847
|
-
const getSetting = (0,
|
|
853
|
+
const getSetting = (0, import_react7.useCallback)(
|
|
848
854
|
(key) => {
|
|
849
855
|
return settings.find((s) => s.key === key);
|
|
850
856
|
},
|
|
851
857
|
[settings]
|
|
852
858
|
);
|
|
853
|
-
const updateSetting = (0,
|
|
859
|
+
const updateSetting = (0, import_react7.useCallback)(
|
|
854
860
|
async (key, update) => {
|
|
855
861
|
await client.admin.settings.system.update(key, update);
|
|
856
862
|
await fetchSettings();
|
|
857
863
|
},
|
|
858
864
|
[client, fetchSettings]
|
|
859
865
|
);
|
|
860
|
-
const deleteSetting = (0,
|
|
866
|
+
const deleteSetting = (0, import_react7.useCallback)(
|
|
861
867
|
async (key) => {
|
|
862
868
|
await client.admin.settings.system.delete(key);
|
|
863
869
|
await fetchSettings();
|
|
864
870
|
},
|
|
865
871
|
[client, fetchSettings]
|
|
866
872
|
);
|
|
867
|
-
(0,
|
|
873
|
+
(0, import_react7.useEffect)(() => {
|
|
868
874
|
if (autoFetch) {
|
|
869
875
|
fetchSettings();
|
|
870
876
|
}
|
|
@@ -882,10 +888,10 @@ function useSystemSettings(options = {}) {
|
|
|
882
888
|
function useWebhooks(options = {}) {
|
|
883
889
|
const { autoFetch = true, refetchInterval = 0 } = options;
|
|
884
890
|
const client = useFluxbaseClient();
|
|
885
|
-
const [webhooks, setWebhooks] = (0,
|
|
886
|
-
const [isLoading, setIsLoading] = (0,
|
|
887
|
-
const [error, setError] = (0,
|
|
888
|
-
const fetchWebhooks = (0,
|
|
891
|
+
const [webhooks, setWebhooks] = (0, import_react7.useState)([]);
|
|
892
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
|
|
893
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
894
|
+
const fetchWebhooks = (0, import_react7.useCallback)(async () => {
|
|
889
895
|
try {
|
|
890
896
|
setIsLoading(true);
|
|
891
897
|
setError(null);
|
|
@@ -897,7 +903,7 @@ function useWebhooks(options = {}) {
|
|
|
897
903
|
setIsLoading(false);
|
|
898
904
|
}
|
|
899
905
|
}, [client]);
|
|
900
|
-
const createWebhook = (0,
|
|
906
|
+
const createWebhook = (0, import_react7.useCallback)(
|
|
901
907
|
async (webhook) => {
|
|
902
908
|
const created = await client.admin.management.webhooks.create(webhook);
|
|
903
909
|
await fetchWebhooks();
|
|
@@ -905,7 +911,7 @@ function useWebhooks(options = {}) {
|
|
|
905
911
|
},
|
|
906
912
|
[client, fetchWebhooks]
|
|
907
913
|
);
|
|
908
|
-
const updateWebhook = (0,
|
|
914
|
+
const updateWebhook = (0, import_react7.useCallback)(
|
|
909
915
|
async (id, update) => {
|
|
910
916
|
const updated = await client.admin.management.webhooks.update(id, update);
|
|
911
917
|
await fetchWebhooks();
|
|
@@ -913,20 +919,20 @@ function useWebhooks(options = {}) {
|
|
|
913
919
|
},
|
|
914
920
|
[client, fetchWebhooks]
|
|
915
921
|
);
|
|
916
|
-
const deleteWebhook = (0,
|
|
922
|
+
const deleteWebhook = (0, import_react7.useCallback)(
|
|
917
923
|
async (id) => {
|
|
918
924
|
await client.admin.management.webhooks.delete(id);
|
|
919
925
|
await fetchWebhooks();
|
|
920
926
|
},
|
|
921
927
|
[client, fetchWebhooks]
|
|
922
928
|
);
|
|
923
|
-
const testWebhook = (0,
|
|
929
|
+
const testWebhook = (0, import_react7.useCallback)(
|
|
924
930
|
async (id) => {
|
|
925
931
|
await client.admin.management.webhooks.test(id);
|
|
926
932
|
},
|
|
927
933
|
[client]
|
|
928
934
|
);
|
|
929
|
-
(0,
|
|
935
|
+
(0, import_react7.useEffect)(() => {
|
|
930
936
|
if (autoFetch) {
|
|
931
937
|
fetchWebhooks();
|
|
932
938
|
}
|
|
@@ -959,9 +965,6 @@ function useWebhooks(options = {}) {
|
|
|
959
965
|
useFluxbaseClient,
|
|
960
966
|
useFluxbaseQuery,
|
|
961
967
|
useInsert,
|
|
962
|
-
useRPC,
|
|
963
|
-
useRPCBatch,
|
|
964
|
-
useRPCMutation,
|
|
965
968
|
useRealtime,
|
|
966
969
|
useSession,
|
|
967
970
|
useSignIn,
|