@fluxbase/sdk-react 0.0.1-rc.26 → 0.0.1-rc.27
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 +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +97 -68
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +70 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/use-auth.ts +63 -48
- package/src/use-storage.ts +211 -82
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as _fluxbase_sdk from '@fluxbase/sdk';
|
|
4
|
-
import { FluxbaseClient, AuthSession, SignInCredentials, SignUpCredentials,
|
|
4
|
+
import { FluxbaseClient, User, AuthSession, SignInCredentials, SignUpCredentials, QueryBuilder, RealtimeCallback, RealtimePostgresChangesPayload, ListOptions, UploadOptions, AdminAuthResponse, ListUsersOptions, EnrichedUser, APIKey, CreateAPIKeyRequest, Webhook, CreateWebhookRequest, UpdateWebhookRequest, AppSettings, UpdateAppSettingsRequest, SystemSetting, UpdateSystemSettingRequest } from '@fluxbase/sdk';
|
|
5
5
|
export { APIKey, AdminUser, AppSettings, AuthSession, EnrichedUser, FluxbaseClient, PostgrestResponse, RealtimeChangePayload, SignInCredentials, SignUpCredentials, StorageObject, SystemSetting, User, Webhook } from '@fluxbase/sdk';
|
|
6
6
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
7
7
|
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
@@ -23,7 +23,7 @@ declare function useFluxbaseClient(): FluxbaseClient;
|
|
|
23
23
|
/**
|
|
24
24
|
* Hook to get the current user
|
|
25
25
|
*/
|
|
26
|
-
declare function useUser(): _tanstack_react_query.UseQueryResult<
|
|
26
|
+
declare function useUser(): _tanstack_react_query.UseQueryResult<User | null, Error>;
|
|
27
27
|
/**
|
|
28
28
|
* Hook to get the current session
|
|
29
29
|
*/
|
|
@@ -48,7 +48,7 @@ declare function useUpdateUser(): _tanstack_react_query.UseMutationResult<_fluxb
|
|
|
48
48
|
* Combined auth hook with all auth state and methods
|
|
49
49
|
*/
|
|
50
50
|
declare function useAuth(): {
|
|
51
|
-
user:
|
|
51
|
+
user: User | null | undefined;
|
|
52
52
|
session: AuthSession | null | undefined;
|
|
53
53
|
isLoading: boolean;
|
|
54
54
|
isAuthenticated: boolean;
|
|
@@ -165,9 +165,28 @@ declare function useTableDeletes(table: string, callback: (payload: RealtimePost
|
|
|
165
165
|
/**
|
|
166
166
|
* Hook to list files in a bucket
|
|
167
167
|
*/
|
|
168
|
-
declare function useStorageList(bucket: string, options?: ListOptions & Omit<UseQueryOptions<any[], Error>,
|
|
168
|
+
declare function useStorageList(bucket: string, options?: ListOptions & Omit<UseQueryOptions<any[], Error>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<any[], Error>;
|
|
169
169
|
/**
|
|
170
170
|
* Hook to upload a file to a bucket
|
|
171
|
+
*
|
|
172
|
+
* Note: You can track upload progress by passing an `onUploadProgress` callback in the options:
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```tsx
|
|
176
|
+
* const upload = useStorageUpload('avatars')
|
|
177
|
+
*
|
|
178
|
+
* upload.mutate({
|
|
179
|
+
* path: 'user.jpg',
|
|
180
|
+
* file: file,
|
|
181
|
+
* options: {
|
|
182
|
+
* onUploadProgress: (progress) => {
|
|
183
|
+
* console.log(`${progress.percentage}% uploaded`)
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* })
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* For automatic progress state management, use `useStorageUploadWithProgress` instead.
|
|
171
190
|
*/
|
|
172
191
|
declare function useStorageUpload(bucket: string): _tanstack_react_query.UseMutationResult<{
|
|
173
192
|
id: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as _fluxbase_sdk from '@fluxbase/sdk';
|
|
4
|
-
import { FluxbaseClient, AuthSession, SignInCredentials, SignUpCredentials,
|
|
4
|
+
import { FluxbaseClient, User, AuthSession, SignInCredentials, SignUpCredentials, QueryBuilder, RealtimeCallback, RealtimePostgresChangesPayload, ListOptions, UploadOptions, AdminAuthResponse, ListUsersOptions, EnrichedUser, APIKey, CreateAPIKeyRequest, Webhook, CreateWebhookRequest, UpdateWebhookRequest, AppSettings, UpdateAppSettingsRequest, SystemSetting, UpdateSystemSettingRequest } from '@fluxbase/sdk';
|
|
5
5
|
export { APIKey, AdminUser, AppSettings, AuthSession, EnrichedUser, FluxbaseClient, PostgrestResponse, RealtimeChangePayload, SignInCredentials, SignUpCredentials, StorageObject, SystemSetting, User, Webhook } from '@fluxbase/sdk';
|
|
6
6
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
7
7
|
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
@@ -23,7 +23,7 @@ declare function useFluxbaseClient(): FluxbaseClient;
|
|
|
23
23
|
/**
|
|
24
24
|
* Hook to get the current user
|
|
25
25
|
*/
|
|
26
|
-
declare function useUser(): _tanstack_react_query.UseQueryResult<
|
|
26
|
+
declare function useUser(): _tanstack_react_query.UseQueryResult<User | null, Error>;
|
|
27
27
|
/**
|
|
28
28
|
* Hook to get the current session
|
|
29
29
|
*/
|
|
@@ -48,7 +48,7 @@ declare function useUpdateUser(): _tanstack_react_query.UseMutationResult<_fluxb
|
|
|
48
48
|
* Combined auth hook with all auth state and methods
|
|
49
49
|
*/
|
|
50
50
|
declare function useAuth(): {
|
|
51
|
-
user:
|
|
51
|
+
user: User | null | undefined;
|
|
52
52
|
session: AuthSession | null | undefined;
|
|
53
53
|
isLoading: boolean;
|
|
54
54
|
isAuthenticated: boolean;
|
|
@@ -165,9 +165,28 @@ declare function useTableDeletes(table: string, callback: (payload: RealtimePost
|
|
|
165
165
|
/**
|
|
166
166
|
* Hook to list files in a bucket
|
|
167
167
|
*/
|
|
168
|
-
declare function useStorageList(bucket: string, options?: ListOptions & Omit<UseQueryOptions<any[], Error>,
|
|
168
|
+
declare function useStorageList(bucket: string, options?: ListOptions & Omit<UseQueryOptions<any[], Error>, "queryKey" | "queryFn">): _tanstack_react_query.UseQueryResult<any[], Error>;
|
|
169
169
|
/**
|
|
170
170
|
* Hook to upload a file to a bucket
|
|
171
|
+
*
|
|
172
|
+
* Note: You can track upload progress by passing an `onUploadProgress` callback in the options:
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```tsx
|
|
176
|
+
* const upload = useStorageUpload('avatars')
|
|
177
|
+
*
|
|
178
|
+
* upload.mutate({
|
|
179
|
+
* path: 'user.jpg',
|
|
180
|
+
* file: file,
|
|
181
|
+
* options: {
|
|
182
|
+
* onUploadProgress: (progress) => {
|
|
183
|
+
* console.log(`${progress.percentage}% uploaded`)
|
|
184
|
+
* }
|
|
185
|
+
* }
|
|
186
|
+
* })
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* For automatic progress state management, use `useStorageUploadWithProgress` instead.
|
|
171
190
|
*/
|
|
172
191
|
declare function useStorageUpload(bucket: string): _tanstack_react_query.UseMutationResult<{
|
|
173
192
|
id: string;
|
package/dist/index.js
CHANGED
|
@@ -85,12 +85,13 @@ function useUser() {
|
|
|
85
85
|
return (0, import_react_query.useQuery)({
|
|
86
86
|
queryKey: ["fluxbase", "auth", "user"],
|
|
87
87
|
queryFn: async () => {
|
|
88
|
-
const
|
|
89
|
-
if (!session) {
|
|
88
|
+
const { data } = await client.auth.getSession();
|
|
89
|
+
if (!data?.session) {
|
|
90
90
|
return null;
|
|
91
91
|
}
|
|
92
92
|
try {
|
|
93
|
-
|
|
93
|
+
const result = await client.auth.getCurrentUser();
|
|
94
|
+
return result.data?.user ?? null;
|
|
94
95
|
} catch {
|
|
95
96
|
return null;
|
|
96
97
|
}
|
|
@@ -103,7 +104,10 @@ function useSession() {
|
|
|
103
104
|
const client = useFluxbaseClient();
|
|
104
105
|
return (0, import_react_query.useQuery)({
|
|
105
106
|
queryKey: ["fluxbase", "auth", "session"],
|
|
106
|
-
queryFn: () =>
|
|
107
|
+
queryFn: async () => {
|
|
108
|
+
const { data } = await client.auth.getSession();
|
|
109
|
+
return data?.session ?? null;
|
|
110
|
+
},
|
|
107
111
|
staleTime: 1e3 * 60 * 5
|
|
108
112
|
// 5 minutes
|
|
109
113
|
});
|
|
@@ -132,8 +136,14 @@ function useSignUp() {
|
|
|
132
136
|
},
|
|
133
137
|
onSuccess: (response) => {
|
|
134
138
|
if (response.data) {
|
|
135
|
-
queryClient.setQueryData(
|
|
136
|
-
|
|
139
|
+
queryClient.setQueryData(
|
|
140
|
+
["fluxbase", "auth", "session"],
|
|
141
|
+
response.data.session
|
|
142
|
+
);
|
|
143
|
+
queryClient.setQueryData(
|
|
144
|
+
["fluxbase", "auth", "user"],
|
|
145
|
+
response.data.user
|
|
146
|
+
);
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
});
|
|
@@ -372,12 +382,19 @@ function useTableDeletes(table, callback, options) {
|
|
|
372
382
|
}
|
|
373
383
|
|
|
374
384
|
// src/use-storage.ts
|
|
385
|
+
var import_react3 = require("react");
|
|
375
386
|
var import_react_query4 = require("@tanstack/react-query");
|
|
376
387
|
function useStorageList(bucket, options) {
|
|
377
388
|
const client = useFluxbaseClient();
|
|
378
389
|
const { prefix, limit, offset, ...queryOptions } = options || {};
|
|
379
390
|
return (0, import_react_query4.useQuery)({
|
|
380
|
-
queryKey: [
|
|
391
|
+
queryKey: [
|
|
392
|
+
"fluxbase",
|
|
393
|
+
"storage",
|
|
394
|
+
bucket,
|
|
395
|
+
"list",
|
|
396
|
+
{ prefix, limit, offset }
|
|
397
|
+
],
|
|
381
398
|
queryFn: async () => {
|
|
382
399
|
const { data, error } = await client.storage.from(bucket).list({ prefix, limit, offset });
|
|
383
400
|
if (error) {
|
|
@@ -401,7 +418,9 @@ function useStorageUpload(bucket) {
|
|
|
401
418
|
return data;
|
|
402
419
|
},
|
|
403
420
|
onSuccess: () => {
|
|
404
|
-
queryClient.invalidateQueries({
|
|
421
|
+
queryClient.invalidateQueries({
|
|
422
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
423
|
+
});
|
|
405
424
|
}
|
|
406
425
|
});
|
|
407
426
|
}
|
|
@@ -433,7 +452,9 @@ function useStorageDelete(bucket) {
|
|
|
433
452
|
}
|
|
434
453
|
},
|
|
435
454
|
onSuccess: () => {
|
|
436
|
-
queryClient.invalidateQueries({
|
|
455
|
+
queryClient.invalidateQueries({
|
|
456
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
457
|
+
});
|
|
437
458
|
}
|
|
438
459
|
});
|
|
439
460
|
}
|
|
@@ -477,7 +498,9 @@ function useStorageMove(bucket) {
|
|
|
477
498
|
return data;
|
|
478
499
|
},
|
|
479
500
|
onSuccess: () => {
|
|
480
|
-
queryClient.invalidateQueries({
|
|
501
|
+
queryClient.invalidateQueries({
|
|
502
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
503
|
+
});
|
|
481
504
|
}
|
|
482
505
|
});
|
|
483
506
|
}
|
|
@@ -494,7 +517,9 @@ function useStorageCopy(bucket) {
|
|
|
494
517
|
return data;
|
|
495
518
|
},
|
|
496
519
|
onSuccess: () => {
|
|
497
|
-
queryClient.invalidateQueries({
|
|
520
|
+
queryClient.invalidateQueries({
|
|
521
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
522
|
+
});
|
|
498
523
|
}
|
|
499
524
|
});
|
|
500
525
|
}
|
|
@@ -522,7 +547,9 @@ function useCreateBucket() {
|
|
|
522
547
|
}
|
|
523
548
|
},
|
|
524
549
|
onSuccess: () => {
|
|
525
|
-
queryClient.invalidateQueries({
|
|
550
|
+
queryClient.invalidateQueries({
|
|
551
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
552
|
+
});
|
|
526
553
|
}
|
|
527
554
|
});
|
|
528
555
|
}
|
|
@@ -537,7 +564,9 @@ function useDeleteBucket() {
|
|
|
537
564
|
}
|
|
538
565
|
},
|
|
539
566
|
onSuccess: () => {
|
|
540
|
-
queryClient.invalidateQueries({
|
|
567
|
+
queryClient.invalidateQueries({
|
|
568
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
569
|
+
});
|
|
541
570
|
}
|
|
542
571
|
});
|
|
543
572
|
}
|
|
@@ -592,14 +621,14 @@ function useRPCBatch(calls, options) {
|
|
|
592
621
|
}
|
|
593
622
|
|
|
594
623
|
// src/use-admin-auth.ts
|
|
595
|
-
var
|
|
624
|
+
var import_react4 = require("react");
|
|
596
625
|
function useAdminAuth(options = {}) {
|
|
597
626
|
const { autoCheck = true } = options;
|
|
598
627
|
const client = useFluxbaseClient();
|
|
599
|
-
const [user, setUser] = (0,
|
|
600
|
-
const [isLoading, setIsLoading] = (0,
|
|
601
|
-
const [error, setError] = (0,
|
|
602
|
-
const checkAuth = (0,
|
|
628
|
+
const [user, setUser] = (0, import_react4.useState)(null);
|
|
629
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(autoCheck);
|
|
630
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
631
|
+
const checkAuth = (0, import_react4.useCallback)(async () => {
|
|
603
632
|
try {
|
|
604
633
|
setIsLoading(true);
|
|
605
634
|
setError(null);
|
|
@@ -615,7 +644,7 @@ function useAdminAuth(options = {}) {
|
|
|
615
644
|
setIsLoading(false);
|
|
616
645
|
}
|
|
617
646
|
}, [client]);
|
|
618
|
-
const login = (0,
|
|
647
|
+
const login = (0, import_react4.useCallback)(
|
|
619
648
|
async (email, password) => {
|
|
620
649
|
try {
|
|
621
650
|
setIsLoading(true);
|
|
@@ -638,7 +667,7 @@ function useAdminAuth(options = {}) {
|
|
|
638
667
|
},
|
|
639
668
|
[client]
|
|
640
669
|
);
|
|
641
|
-
const logout = (0,
|
|
670
|
+
const logout = (0, import_react4.useCallback)(async () => {
|
|
642
671
|
try {
|
|
643
672
|
setIsLoading(true);
|
|
644
673
|
setError(null);
|
|
@@ -650,10 +679,10 @@ function useAdminAuth(options = {}) {
|
|
|
650
679
|
setIsLoading(false);
|
|
651
680
|
}
|
|
652
681
|
}, []);
|
|
653
|
-
const refresh = (0,
|
|
682
|
+
const refresh = (0, import_react4.useCallback)(async () => {
|
|
654
683
|
await checkAuth();
|
|
655
684
|
}, [checkAuth]);
|
|
656
|
-
(0,
|
|
685
|
+
(0, import_react4.useEffect)(() => {
|
|
657
686
|
if (autoCheck) {
|
|
658
687
|
checkAuth();
|
|
659
688
|
}
|
|
@@ -670,15 +699,15 @@ function useAdminAuth(options = {}) {
|
|
|
670
699
|
}
|
|
671
700
|
|
|
672
701
|
// src/use-users.ts
|
|
673
|
-
var
|
|
702
|
+
var import_react5 = require("react");
|
|
674
703
|
function useUsers(options = {}) {
|
|
675
704
|
const { autoFetch = true, refetchInterval = 0, ...listOptions } = options;
|
|
676
705
|
const client = useFluxbaseClient();
|
|
677
|
-
const [users, setUsers] = (0,
|
|
678
|
-
const [total, setTotal] = (0,
|
|
679
|
-
const [isLoading, setIsLoading] = (0,
|
|
680
|
-
const [error, setError] = (0,
|
|
681
|
-
const fetchUsers = (0,
|
|
706
|
+
const [users, setUsers] = (0, import_react5.useState)([]);
|
|
707
|
+
const [total, setTotal] = (0, import_react5.useState)(0);
|
|
708
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(autoFetch);
|
|
709
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
710
|
+
const fetchUsers = (0, import_react5.useCallback)(async () => {
|
|
682
711
|
try {
|
|
683
712
|
setIsLoading(true);
|
|
684
713
|
setError(null);
|
|
@@ -694,28 +723,28 @@ function useUsers(options = {}) {
|
|
|
694
723
|
setIsLoading(false);
|
|
695
724
|
}
|
|
696
725
|
}, [client, JSON.stringify(listOptions)]);
|
|
697
|
-
const inviteUser = (0,
|
|
726
|
+
const inviteUser = (0, import_react5.useCallback)(
|
|
698
727
|
async (email, role) => {
|
|
699
728
|
await client.admin.inviteUser({ email, role });
|
|
700
729
|
await fetchUsers();
|
|
701
730
|
},
|
|
702
731
|
[client, fetchUsers]
|
|
703
732
|
);
|
|
704
|
-
const updateUserRole = (0,
|
|
733
|
+
const updateUserRole = (0, import_react5.useCallback)(
|
|
705
734
|
async (userId, role) => {
|
|
706
735
|
await client.admin.updateUserRole(userId, role);
|
|
707
736
|
await fetchUsers();
|
|
708
737
|
},
|
|
709
738
|
[client, fetchUsers]
|
|
710
739
|
);
|
|
711
|
-
const deleteUser = (0,
|
|
740
|
+
const deleteUser = (0, import_react5.useCallback)(
|
|
712
741
|
async (userId) => {
|
|
713
742
|
await client.admin.deleteUser(userId);
|
|
714
743
|
await fetchUsers();
|
|
715
744
|
},
|
|
716
745
|
[client, fetchUsers]
|
|
717
746
|
);
|
|
718
|
-
const resetPassword = (0,
|
|
747
|
+
const resetPassword = (0, import_react5.useCallback)(
|
|
719
748
|
async (userId) => {
|
|
720
749
|
const { data, error: error2 } = await client.admin.resetUserPassword(userId);
|
|
721
750
|
if (error2) {
|
|
@@ -725,12 +754,12 @@ function useUsers(options = {}) {
|
|
|
725
754
|
},
|
|
726
755
|
[client]
|
|
727
756
|
);
|
|
728
|
-
(0,
|
|
757
|
+
(0, import_react5.useEffect)(() => {
|
|
729
758
|
if (autoFetch) {
|
|
730
759
|
fetchUsers();
|
|
731
760
|
}
|
|
732
761
|
}, [autoFetch, fetchUsers]);
|
|
733
|
-
(0,
|
|
762
|
+
(0, import_react5.useEffect)(() => {
|
|
734
763
|
if (refetchInterval > 0) {
|
|
735
764
|
const interval = setInterval(fetchUsers, refetchInterval);
|
|
736
765
|
return () => clearInterval(interval);
|
|
@@ -750,14 +779,14 @@ function useUsers(options = {}) {
|
|
|
750
779
|
}
|
|
751
780
|
|
|
752
781
|
// src/use-api-keys.ts
|
|
753
|
-
var
|
|
782
|
+
var import_react6 = require("react");
|
|
754
783
|
function useAPIKeys(options = {}) {
|
|
755
784
|
const { autoFetch = true } = options;
|
|
756
785
|
const client = useFluxbaseClient();
|
|
757
|
-
const [keys, setKeys] = (0,
|
|
758
|
-
const [isLoading, setIsLoading] = (0,
|
|
759
|
-
const [error, setError] = (0,
|
|
760
|
-
const fetchKeys = (0,
|
|
786
|
+
const [keys, setKeys] = (0, import_react6.useState)([]);
|
|
787
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(autoFetch);
|
|
788
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
789
|
+
const fetchKeys = (0, import_react6.useCallback)(async () => {
|
|
761
790
|
try {
|
|
762
791
|
setIsLoading(true);
|
|
763
792
|
setError(null);
|
|
@@ -769,7 +798,7 @@ function useAPIKeys(options = {}) {
|
|
|
769
798
|
setIsLoading(false);
|
|
770
799
|
}
|
|
771
800
|
}, [client]);
|
|
772
|
-
const createKey = (0,
|
|
801
|
+
const createKey = (0, import_react6.useCallback)(
|
|
773
802
|
async (request) => {
|
|
774
803
|
const response = await client.admin.management.apiKeys.create(request);
|
|
775
804
|
await fetchKeys();
|
|
@@ -777,28 +806,28 @@ function useAPIKeys(options = {}) {
|
|
|
777
806
|
},
|
|
778
807
|
[client, fetchKeys]
|
|
779
808
|
);
|
|
780
|
-
const updateKey = (0,
|
|
809
|
+
const updateKey = (0, import_react6.useCallback)(
|
|
781
810
|
async (keyId, update) => {
|
|
782
811
|
await client.admin.management.apiKeys.update(keyId, update);
|
|
783
812
|
await fetchKeys();
|
|
784
813
|
},
|
|
785
814
|
[client, fetchKeys]
|
|
786
815
|
);
|
|
787
|
-
const revokeKey = (0,
|
|
816
|
+
const revokeKey = (0, import_react6.useCallback)(
|
|
788
817
|
async (keyId) => {
|
|
789
818
|
await client.admin.management.apiKeys.revoke(keyId);
|
|
790
819
|
await fetchKeys();
|
|
791
820
|
},
|
|
792
821
|
[client, fetchKeys]
|
|
793
822
|
);
|
|
794
|
-
const deleteKey = (0,
|
|
823
|
+
const deleteKey = (0, import_react6.useCallback)(
|
|
795
824
|
async (keyId) => {
|
|
796
825
|
await client.admin.management.apiKeys.delete(keyId);
|
|
797
826
|
await fetchKeys();
|
|
798
827
|
},
|
|
799
828
|
[client, fetchKeys]
|
|
800
829
|
);
|
|
801
|
-
(0,
|
|
830
|
+
(0, import_react6.useEffect)(() => {
|
|
802
831
|
if (autoFetch) {
|
|
803
832
|
fetchKeys();
|
|
804
833
|
}
|
|
@@ -816,14 +845,14 @@ function useAPIKeys(options = {}) {
|
|
|
816
845
|
}
|
|
817
846
|
|
|
818
847
|
// src/use-admin-hooks.ts
|
|
819
|
-
var
|
|
848
|
+
var import_react7 = require("react");
|
|
820
849
|
function useAppSettings(options = {}) {
|
|
821
850
|
const { autoFetch = true } = options;
|
|
822
851
|
const client = useFluxbaseClient();
|
|
823
|
-
const [settings, setSettings] = (0,
|
|
824
|
-
const [isLoading, setIsLoading] = (0,
|
|
825
|
-
const [error, setError] = (0,
|
|
826
|
-
const fetchSettings = (0,
|
|
852
|
+
const [settings, setSettings] = (0, import_react7.useState)(null);
|
|
853
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
|
|
854
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
855
|
+
const fetchSettings = (0, import_react7.useCallback)(async () => {
|
|
827
856
|
try {
|
|
828
857
|
setIsLoading(true);
|
|
829
858
|
setError(null);
|
|
@@ -835,14 +864,14 @@ function useAppSettings(options = {}) {
|
|
|
835
864
|
setIsLoading(false);
|
|
836
865
|
}
|
|
837
866
|
}, [client]);
|
|
838
|
-
const updateSettings = (0,
|
|
867
|
+
const updateSettings = (0, import_react7.useCallback)(
|
|
839
868
|
async (update) => {
|
|
840
869
|
await client.admin.settings.app.update(update);
|
|
841
870
|
await fetchSettings();
|
|
842
871
|
},
|
|
843
872
|
[client, fetchSettings]
|
|
844
873
|
);
|
|
845
|
-
(0,
|
|
874
|
+
(0, import_react7.useEffect)(() => {
|
|
846
875
|
if (autoFetch) {
|
|
847
876
|
fetchSettings();
|
|
848
877
|
}
|
|
@@ -858,10 +887,10 @@ function useAppSettings(options = {}) {
|
|
|
858
887
|
function useSystemSettings(options = {}) {
|
|
859
888
|
const { autoFetch = true } = options;
|
|
860
889
|
const client = useFluxbaseClient();
|
|
861
|
-
const [settings, setSettings] = (0,
|
|
862
|
-
const [isLoading, setIsLoading] = (0,
|
|
863
|
-
const [error, setError] = (0,
|
|
864
|
-
const fetchSettings = (0,
|
|
890
|
+
const [settings, setSettings] = (0, import_react7.useState)([]);
|
|
891
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
|
|
892
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
893
|
+
const fetchSettings = (0, import_react7.useCallback)(async () => {
|
|
865
894
|
try {
|
|
866
895
|
setIsLoading(true);
|
|
867
896
|
setError(null);
|
|
@@ -873,27 +902,27 @@ function useSystemSettings(options = {}) {
|
|
|
873
902
|
setIsLoading(false);
|
|
874
903
|
}
|
|
875
904
|
}, [client]);
|
|
876
|
-
const getSetting = (0,
|
|
905
|
+
const getSetting = (0, import_react7.useCallback)(
|
|
877
906
|
(key) => {
|
|
878
907
|
return settings.find((s) => s.key === key);
|
|
879
908
|
},
|
|
880
909
|
[settings]
|
|
881
910
|
);
|
|
882
|
-
const updateSetting = (0,
|
|
911
|
+
const updateSetting = (0, import_react7.useCallback)(
|
|
883
912
|
async (key, update) => {
|
|
884
913
|
await client.admin.settings.system.update(key, update);
|
|
885
914
|
await fetchSettings();
|
|
886
915
|
},
|
|
887
916
|
[client, fetchSettings]
|
|
888
917
|
);
|
|
889
|
-
const deleteSetting = (0,
|
|
918
|
+
const deleteSetting = (0, import_react7.useCallback)(
|
|
890
919
|
async (key) => {
|
|
891
920
|
await client.admin.settings.system.delete(key);
|
|
892
921
|
await fetchSettings();
|
|
893
922
|
},
|
|
894
923
|
[client, fetchSettings]
|
|
895
924
|
);
|
|
896
|
-
(0,
|
|
925
|
+
(0, import_react7.useEffect)(() => {
|
|
897
926
|
if (autoFetch) {
|
|
898
927
|
fetchSettings();
|
|
899
928
|
}
|
|
@@ -911,10 +940,10 @@ function useSystemSettings(options = {}) {
|
|
|
911
940
|
function useWebhooks(options = {}) {
|
|
912
941
|
const { autoFetch = true, refetchInterval = 0 } = options;
|
|
913
942
|
const client = useFluxbaseClient();
|
|
914
|
-
const [webhooks, setWebhooks] = (0,
|
|
915
|
-
const [isLoading, setIsLoading] = (0,
|
|
916
|
-
const [error, setError] = (0,
|
|
917
|
-
const fetchWebhooks = (0,
|
|
943
|
+
const [webhooks, setWebhooks] = (0, import_react7.useState)([]);
|
|
944
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
|
|
945
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
946
|
+
const fetchWebhooks = (0, import_react7.useCallback)(async () => {
|
|
918
947
|
try {
|
|
919
948
|
setIsLoading(true);
|
|
920
949
|
setError(null);
|
|
@@ -926,7 +955,7 @@ function useWebhooks(options = {}) {
|
|
|
926
955
|
setIsLoading(false);
|
|
927
956
|
}
|
|
928
957
|
}, [client]);
|
|
929
|
-
const createWebhook = (0,
|
|
958
|
+
const createWebhook = (0, import_react7.useCallback)(
|
|
930
959
|
async (webhook) => {
|
|
931
960
|
const created = await client.admin.management.webhooks.create(webhook);
|
|
932
961
|
await fetchWebhooks();
|
|
@@ -934,7 +963,7 @@ function useWebhooks(options = {}) {
|
|
|
934
963
|
},
|
|
935
964
|
[client, fetchWebhooks]
|
|
936
965
|
);
|
|
937
|
-
const updateWebhook = (0,
|
|
966
|
+
const updateWebhook = (0, import_react7.useCallback)(
|
|
938
967
|
async (id, update) => {
|
|
939
968
|
const updated = await client.admin.management.webhooks.update(id, update);
|
|
940
969
|
await fetchWebhooks();
|
|
@@ -942,20 +971,20 @@ function useWebhooks(options = {}) {
|
|
|
942
971
|
},
|
|
943
972
|
[client, fetchWebhooks]
|
|
944
973
|
);
|
|
945
|
-
const deleteWebhook = (0,
|
|
974
|
+
const deleteWebhook = (0, import_react7.useCallback)(
|
|
946
975
|
async (id) => {
|
|
947
976
|
await client.admin.management.webhooks.delete(id);
|
|
948
977
|
await fetchWebhooks();
|
|
949
978
|
},
|
|
950
979
|
[client, fetchWebhooks]
|
|
951
980
|
);
|
|
952
|
-
const testWebhook = (0,
|
|
981
|
+
const testWebhook = (0, import_react7.useCallback)(
|
|
953
982
|
async (id) => {
|
|
954
983
|
await client.admin.management.webhooks.test(id);
|
|
955
984
|
},
|
|
956
985
|
[client]
|
|
957
986
|
);
|
|
958
|
-
(0,
|
|
987
|
+
(0, import_react7.useEffect)(() => {
|
|
959
988
|
if (autoFetch) {
|
|
960
989
|
fetchWebhooks();
|
|
961
990
|
}
|