@fluxbase/sdk-react 0.0.1-rc.2
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 +67 -0
- package/README-ADMIN.md +1076 -0
- package/README.md +178 -0
- package/dist/index.d.mts +606 -0
- package/dist/index.d.ts +606 -0
- package/dist/index.js +992 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +926 -0
- package/dist/index.mjs.map +1 -0
- package/examples/AdminDashboard.tsx +513 -0
- package/examples/README.md +163 -0
- package/package.json +52 -0
- package/src/context.tsx +33 -0
- package/src/index.ts +113 -0
- package/src/use-admin-auth.ts +168 -0
- package/src/use-admin-hooks.ts +309 -0
- package/src/use-api-keys.ts +174 -0
- package/src/use-auth.ts +146 -0
- package/src/use-query.ts +165 -0
- package/src/use-realtime.ts +161 -0
- package/src/use-rpc.ts +109 -0
- package/src/use-storage.ts +257 -0
- package/src/use-users.ts +191 -0
- package/tsconfig.json +24 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +11 -0
- package/typedoc.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import * as _fluxbase_sdk from '@fluxbase/sdk';
|
|
4
|
+
import { FluxbaseClient, User, AuthSession, SignInCredentials, SignUpCredentials, QueryBuilder, RealtimeCallback, RealtimeChangePayload, ListOptions, UploadOptions, AdminAuthResponse, ListUsersOptions, EnrichedUser, APIKey, CreateAPIKeyRequest, Webhook, CreateWebhookRequest, UpdateWebhookRequest, AppSettings, UpdateAppSettingsRequest, SystemSetting, UpdateSystemSettingRequest } from '@fluxbase/sdk';
|
|
5
|
+
export { APIKey, AdminUser, AppSettings, AuthSession, EnrichedUser, FluxbaseClient, PostgrestResponse, RealtimeChangePayload, SignInCredentials, SignUpCredentials, StorageObject, SystemSetting, User, Webhook } from '@fluxbase/sdk';
|
|
6
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
7
|
+
import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
8
|
+
import * as _tanstack_query_core from '@tanstack/query-core';
|
|
9
|
+
|
|
10
|
+
interface FluxbaseProviderProps {
|
|
11
|
+
client: FluxbaseClient;
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Provider component to make Fluxbase client available throughout the app
|
|
16
|
+
*/
|
|
17
|
+
declare function FluxbaseProvider({ client, children }: FluxbaseProviderProps): react_jsx_runtime.JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* Hook to access the Fluxbase client from context
|
|
20
|
+
*/
|
|
21
|
+
declare function useFluxbaseClient(): FluxbaseClient;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Hook to get the current user
|
|
25
|
+
*/
|
|
26
|
+
declare function useUser(): _tanstack_react_query.UseQueryResult<User | null, Error>;
|
|
27
|
+
/**
|
|
28
|
+
* Hook to get the current session
|
|
29
|
+
*/
|
|
30
|
+
declare function useSession(): _tanstack_react_query.UseQueryResult<AuthSession | null, Error>;
|
|
31
|
+
/**
|
|
32
|
+
* Hook for signing in
|
|
33
|
+
*/
|
|
34
|
+
declare function useSignIn(): _tanstack_react_query.UseMutationResult<AuthSession | _fluxbase_sdk.SignInWith2FAResponse, Error, SignInCredentials, unknown>;
|
|
35
|
+
/**
|
|
36
|
+
* Hook for signing up
|
|
37
|
+
*/
|
|
38
|
+
declare function useSignUp(): _tanstack_react_query.UseMutationResult<AuthSession, Error, SignUpCredentials, unknown>;
|
|
39
|
+
/**
|
|
40
|
+
* Hook for signing out
|
|
41
|
+
*/
|
|
42
|
+
declare function useSignOut(): _tanstack_react_query.UseMutationResult<void, Error, void, unknown>;
|
|
43
|
+
/**
|
|
44
|
+
* Hook for updating the current user
|
|
45
|
+
*/
|
|
46
|
+
declare function useUpdateUser(): _tanstack_react_query.UseMutationResult<User, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
|
|
47
|
+
/**
|
|
48
|
+
* Combined auth hook with all auth state and methods
|
|
49
|
+
*/
|
|
50
|
+
declare function useAuth(): {
|
|
51
|
+
user: User | null | undefined;
|
|
52
|
+
session: AuthSession | null | undefined;
|
|
53
|
+
isLoading: boolean;
|
|
54
|
+
isAuthenticated: boolean;
|
|
55
|
+
signIn: _tanstack_react_query.UseMutateAsyncFunction<AuthSession | _fluxbase_sdk.SignInWith2FAResponse, Error, SignInCredentials, unknown>;
|
|
56
|
+
signUp: _tanstack_react_query.UseMutateAsyncFunction<AuthSession, Error, SignUpCredentials, unknown>;
|
|
57
|
+
signOut: _tanstack_react_query.UseMutateAsyncFunction<void, Error, void, unknown>;
|
|
58
|
+
updateUser: _tanstack_react_query.UseMutateAsyncFunction<User, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
|
|
59
|
+
isSigningIn: boolean;
|
|
60
|
+
isSigningUp: boolean;
|
|
61
|
+
isSigningOut: boolean;
|
|
62
|
+
isUpdating: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
interface UseFluxbaseQueryOptions<T> extends Omit<UseQueryOptions<T[], Error>, 'queryKey' | 'queryFn'> {
|
|
66
|
+
/**
|
|
67
|
+
* Custom query key. If not provided, will use table name and filters.
|
|
68
|
+
*/
|
|
69
|
+
queryKey?: unknown[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Hook to execute a database query
|
|
73
|
+
* @param buildQuery - Function that builds and returns the query
|
|
74
|
+
* @param options - React Query options
|
|
75
|
+
*/
|
|
76
|
+
declare function useFluxbaseQuery<T = any>(buildQuery: (client: ReturnType<typeof useFluxbaseClient>) => QueryBuilder<T>, options?: UseFluxbaseQueryOptions<T>): _tanstack_react_query.UseQueryResult<T[], Error>;
|
|
77
|
+
/**
|
|
78
|
+
* Hook for table queries with a simpler API
|
|
79
|
+
* @param table - Table name
|
|
80
|
+
* @param buildQuery - Function to build the query
|
|
81
|
+
*/
|
|
82
|
+
declare function useTable<T = any>(table: string, buildQuery?: (query: QueryBuilder<T>) => QueryBuilder<T>, options?: UseFluxbaseQueryOptions<T>): _tanstack_react_query.UseQueryResult<T[], Error>;
|
|
83
|
+
/**
|
|
84
|
+
* Hook to insert data into a table
|
|
85
|
+
*/
|
|
86
|
+
declare function useInsert<T = any>(table: string): _tanstack_react_query.UseMutationResult<T | null, Error, Partial<T> | Partial<T>[], unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* Hook to update data in a table
|
|
89
|
+
*/
|
|
90
|
+
declare function useUpdate<T = any>(table: string): _tanstack_react_query.UseMutationResult<T | null, Error, {
|
|
91
|
+
data: Partial<T>;
|
|
92
|
+
buildQuery: (query: QueryBuilder<T>) => QueryBuilder<T>;
|
|
93
|
+
}, unknown>;
|
|
94
|
+
/**
|
|
95
|
+
* Hook to upsert data into a table
|
|
96
|
+
*/
|
|
97
|
+
declare function useUpsert<T = any>(table: string): _tanstack_react_query.UseMutationResult<T | null, Error, Partial<T> | Partial<T>[], unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* Hook to delete data from a table
|
|
100
|
+
*/
|
|
101
|
+
declare function useDelete<T = any>(table: string): _tanstack_react_query.UseMutationResult<void, Error, (query: QueryBuilder<T>) => QueryBuilder<T>, unknown>;
|
|
102
|
+
|
|
103
|
+
interface UseRealtimeOptions {
|
|
104
|
+
/**
|
|
105
|
+
* The channel name (e.g., 'table:public.products')
|
|
106
|
+
*/
|
|
107
|
+
channel: string;
|
|
108
|
+
/**
|
|
109
|
+
* Event type to listen for ('INSERT', 'UPDATE', 'DELETE', or '*' for all)
|
|
110
|
+
*/
|
|
111
|
+
event?: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
|
|
112
|
+
/**
|
|
113
|
+
* Callback function when an event is received
|
|
114
|
+
*/
|
|
115
|
+
callback?: RealtimeCallback;
|
|
116
|
+
/**
|
|
117
|
+
* Whether to automatically invalidate queries for the table
|
|
118
|
+
* Default: true
|
|
119
|
+
*/
|
|
120
|
+
autoInvalidate?: boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Custom query key to invalidate (if autoInvalidate is true)
|
|
123
|
+
* Default: ['fluxbase', 'table', tableName]
|
|
124
|
+
*/
|
|
125
|
+
invalidateKey?: unknown[];
|
|
126
|
+
/**
|
|
127
|
+
* Whether the subscription is enabled
|
|
128
|
+
* Default: true
|
|
129
|
+
*/
|
|
130
|
+
enabled?: boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Hook to subscribe to realtime changes for a channel
|
|
134
|
+
*/
|
|
135
|
+
declare function useRealtime(options: UseRealtimeOptions): {
|
|
136
|
+
channel: _fluxbase_sdk.RealtimeChannel | null;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Hook to subscribe to a table's changes
|
|
140
|
+
* @param table - Table name (with optional schema, e.g., 'public.products')
|
|
141
|
+
* @param options - Subscription options
|
|
142
|
+
*/
|
|
143
|
+
declare function useTableSubscription(table: string, options?: Omit<UseRealtimeOptions, 'channel'>): {
|
|
144
|
+
channel: _fluxbase_sdk.RealtimeChannel | null;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Hook to subscribe to INSERT events on a table
|
|
148
|
+
*/
|
|
149
|
+
declare function useTableInserts(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
|
|
150
|
+
channel: _fluxbase_sdk.RealtimeChannel | null;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Hook to subscribe to UPDATE events on a table
|
|
154
|
+
*/
|
|
155
|
+
declare function useTableUpdates(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
|
|
156
|
+
channel: _fluxbase_sdk.RealtimeChannel | null;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Hook to subscribe to DELETE events on a table
|
|
160
|
+
*/
|
|
161
|
+
declare function useTableDeletes(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
|
|
162
|
+
channel: _fluxbase_sdk.RealtimeChannel | null;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Hook to list files in a bucket
|
|
167
|
+
*/
|
|
168
|
+
declare function useStorageList(bucket: string, options?: ListOptions & Omit<UseQueryOptions<any[], Error>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<any[], Error>;
|
|
169
|
+
/**
|
|
170
|
+
* Hook to upload a file to a bucket
|
|
171
|
+
*/
|
|
172
|
+
declare function useStorageUpload(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
|
|
173
|
+
path: string;
|
|
174
|
+
file: File | Blob | ArrayBuffer;
|
|
175
|
+
options?: UploadOptions;
|
|
176
|
+
}, unknown>;
|
|
177
|
+
/**
|
|
178
|
+
* Hook to download a file from a bucket
|
|
179
|
+
*/
|
|
180
|
+
declare function useStorageDownload(bucket: string, path: string | null, enabled?: boolean): _tanstack_react_query.UseQueryResult<Blob | null, Error>;
|
|
181
|
+
/**
|
|
182
|
+
* Hook to delete files from a bucket
|
|
183
|
+
*/
|
|
184
|
+
declare function useStorageDelete(bucket: string): _tanstack_react_query.UseMutationResult<void, Error, string[], unknown>;
|
|
185
|
+
/**
|
|
186
|
+
* Hook to get a public URL for a file
|
|
187
|
+
*/
|
|
188
|
+
declare function useStoragePublicUrl(bucket: string, path: string | null): string | null;
|
|
189
|
+
/**
|
|
190
|
+
* Hook to create a signed URL
|
|
191
|
+
*/
|
|
192
|
+
declare function useStorageSignedUrl(bucket: string, path: string | null, expiresIn?: number): _tanstack_react_query.UseQueryResult<string | null, Error>;
|
|
193
|
+
/**
|
|
194
|
+
* Hook to move a file
|
|
195
|
+
*/
|
|
196
|
+
declare function useStorageMove(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
|
|
197
|
+
fromPath: string;
|
|
198
|
+
toPath: string;
|
|
199
|
+
}, unknown>;
|
|
200
|
+
/**
|
|
201
|
+
* Hook to copy a file
|
|
202
|
+
*/
|
|
203
|
+
declare function useStorageCopy(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
|
|
204
|
+
fromPath: string;
|
|
205
|
+
toPath: string;
|
|
206
|
+
}, unknown>;
|
|
207
|
+
/**
|
|
208
|
+
* Hook to manage buckets
|
|
209
|
+
*/
|
|
210
|
+
declare function useStorageBuckets(): _tanstack_react_query.UseQueryResult<{
|
|
211
|
+
name: string;
|
|
212
|
+
created_at: string;
|
|
213
|
+
}[], Error>;
|
|
214
|
+
/**
|
|
215
|
+
* Hook to create a bucket
|
|
216
|
+
*/
|
|
217
|
+
declare function useCreateBucket(): _tanstack_react_query.UseMutationResult<void, Error, string, unknown>;
|
|
218
|
+
/**
|
|
219
|
+
* Hook to delete a bucket
|
|
220
|
+
*/
|
|
221
|
+
declare function useDeleteBucket(): _tanstack_react_query.UseMutationResult<void, Error, string, unknown>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Hook to call a PostgreSQL function and cache the result
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```tsx
|
|
228
|
+
* const { data, isLoading, error } = useRPC(
|
|
229
|
+
* 'calculate_total',
|
|
230
|
+
* { order_id: 123 },
|
|
231
|
+
* { enabled: !!orderId }
|
|
232
|
+
* )
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function useRPC<TData = unknown, TParams extends Record<string, unknown> = Record<string, unknown>>(functionName: string, params?: TParams, options?: Omit<UseQueryOptions<TData, Error>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<_tanstack_query_core.NoInfer<TData>, Error>;
|
|
236
|
+
/**
|
|
237
|
+
* Hook to create a mutation for calling PostgreSQL functions
|
|
238
|
+
* Useful for functions that modify data
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```tsx
|
|
242
|
+
* const createOrder = useRPCMutation('create_order')
|
|
243
|
+
*
|
|
244
|
+
* const handleSubmit = async () => {
|
|
245
|
+
* await createOrder.mutateAsync({
|
|
246
|
+
* user_id: 123,
|
|
247
|
+
* items: [{ product_id: 1, quantity: 2 }]
|
|
248
|
+
* })
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
declare function useRPCMutation<TData = unknown, TParams extends Record<string, unknown> = Record<string, unknown>>(functionName: string, options?: Omit<UseMutationOptions<TData, Error, TParams>, 'mutationFn'>): _tanstack_react_query.UseMutationResult<TData, Error, TParams, unknown>;
|
|
253
|
+
/**
|
|
254
|
+
* Hook to call multiple RPC functions in parallel
|
|
255
|
+
*
|
|
256
|
+
* @example
|
|
257
|
+
* ```tsx
|
|
258
|
+
* const { data, isLoading } = useRPCBatch([
|
|
259
|
+
* { name: 'get_user_stats', params: { user_id: 123 } },
|
|
260
|
+
* { name: 'get_recent_orders', params: { limit: 10 } },
|
|
261
|
+
* ])
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
declare function useRPCBatch<TData = unknown>(calls: Array<{
|
|
265
|
+
name: string;
|
|
266
|
+
params?: Record<string, unknown>;
|
|
267
|
+
}>, options?: Omit<UseQueryOptions<TData[], Error, TData[], readonly unknown[]>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<TData[], Error>;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Simplified admin user type returned by authentication
|
|
271
|
+
*/
|
|
272
|
+
interface AdminUser {
|
|
273
|
+
id: string;
|
|
274
|
+
email: string;
|
|
275
|
+
role: string;
|
|
276
|
+
}
|
|
277
|
+
interface UseAdminAuthOptions {
|
|
278
|
+
/**
|
|
279
|
+
* Automatically check authentication status on mount
|
|
280
|
+
* @default true
|
|
281
|
+
*/
|
|
282
|
+
autoCheck?: boolean;
|
|
283
|
+
}
|
|
284
|
+
interface UseAdminAuthReturn {
|
|
285
|
+
/**
|
|
286
|
+
* Current admin user if authenticated
|
|
287
|
+
*/
|
|
288
|
+
user: AdminUser | null;
|
|
289
|
+
/**
|
|
290
|
+
* Whether the admin is authenticated
|
|
291
|
+
*/
|
|
292
|
+
isAuthenticated: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Whether the authentication check is in progress
|
|
295
|
+
*/
|
|
296
|
+
isLoading: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* Any error that occurred during authentication
|
|
299
|
+
*/
|
|
300
|
+
error: Error | null;
|
|
301
|
+
/**
|
|
302
|
+
* Login as admin
|
|
303
|
+
*/
|
|
304
|
+
login: (email: string, password: string) => Promise<AdminAuthResponse>;
|
|
305
|
+
/**
|
|
306
|
+
* Logout admin
|
|
307
|
+
*/
|
|
308
|
+
logout: () => Promise<void>;
|
|
309
|
+
/**
|
|
310
|
+
* Refresh admin user info
|
|
311
|
+
*/
|
|
312
|
+
refresh: () => Promise<void>;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Hook for admin authentication
|
|
316
|
+
*
|
|
317
|
+
* Manages admin login state, authentication checks, and user info.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* ```tsx
|
|
321
|
+
* function AdminLogin() {
|
|
322
|
+
* const { user, isAuthenticated, isLoading, login, logout } = useAdminAuth()
|
|
323
|
+
*
|
|
324
|
+
* const handleLogin = async (e: React.FormEvent) => {
|
|
325
|
+
* e.preventDefault()
|
|
326
|
+
* await login(email, password)
|
|
327
|
+
* }
|
|
328
|
+
*
|
|
329
|
+
* if (isLoading) return <div>Loading...</div>
|
|
330
|
+
* if (isAuthenticated) return <div>Welcome {user?.email}</div>
|
|
331
|
+
*
|
|
332
|
+
* return <form onSubmit={handleLogin}>...</form>
|
|
333
|
+
* }
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
declare function useAdminAuth(options?: UseAdminAuthOptions): UseAdminAuthReturn;
|
|
337
|
+
|
|
338
|
+
interface UseUsersOptions extends ListUsersOptions {
|
|
339
|
+
/**
|
|
340
|
+
* Whether to automatically fetch users on mount
|
|
341
|
+
* @default true
|
|
342
|
+
*/
|
|
343
|
+
autoFetch?: boolean;
|
|
344
|
+
/**
|
|
345
|
+
* Refetch interval in milliseconds (0 to disable)
|
|
346
|
+
* @default 0
|
|
347
|
+
*/
|
|
348
|
+
refetchInterval?: number;
|
|
349
|
+
}
|
|
350
|
+
interface UseUsersReturn {
|
|
351
|
+
/**
|
|
352
|
+
* Array of users
|
|
353
|
+
*/
|
|
354
|
+
users: EnrichedUser[];
|
|
355
|
+
/**
|
|
356
|
+
* Total number of users (for pagination)
|
|
357
|
+
*/
|
|
358
|
+
total: number;
|
|
359
|
+
/**
|
|
360
|
+
* Whether users are being fetched
|
|
361
|
+
*/
|
|
362
|
+
isLoading: boolean;
|
|
363
|
+
/**
|
|
364
|
+
* Any error that occurred
|
|
365
|
+
*/
|
|
366
|
+
error: Error | null;
|
|
367
|
+
/**
|
|
368
|
+
* Refetch users
|
|
369
|
+
*/
|
|
370
|
+
refetch: () => Promise<void>;
|
|
371
|
+
/**
|
|
372
|
+
* Invite a new user
|
|
373
|
+
*/
|
|
374
|
+
inviteUser: (email: string, role: 'user' | 'admin') => Promise<void>;
|
|
375
|
+
/**
|
|
376
|
+
* Update user role
|
|
377
|
+
*/
|
|
378
|
+
updateUserRole: (userId: string, role: 'user' | 'admin') => Promise<void>;
|
|
379
|
+
/**
|
|
380
|
+
* Delete a user
|
|
381
|
+
*/
|
|
382
|
+
deleteUser: (userId: string) => Promise<void>;
|
|
383
|
+
/**
|
|
384
|
+
* Reset user password
|
|
385
|
+
*/
|
|
386
|
+
resetPassword: (userId: string) => Promise<{
|
|
387
|
+
message: string;
|
|
388
|
+
}>;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Hook for managing users
|
|
392
|
+
*
|
|
393
|
+
* Provides user list with pagination, search, and management functions.
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```tsx
|
|
397
|
+
* function UserList() {
|
|
398
|
+
* const { users, total, isLoading, refetch, inviteUser, deleteUser } = useUsers({
|
|
399
|
+
* limit: 20,
|
|
400
|
+
* search: searchTerm
|
|
401
|
+
* })
|
|
402
|
+
*
|
|
403
|
+
* return (
|
|
404
|
+
* <div>
|
|
405
|
+
* {isLoading ? <Spinner /> : (
|
|
406
|
+
* <ul>
|
|
407
|
+
* {users.map(user => (
|
|
408
|
+
* <li key={user.id}>
|
|
409
|
+
* {user.email} - {user.role}
|
|
410
|
+
* <button onClick={() => deleteUser(user.id)}>Delete</button>
|
|
411
|
+
* </li>
|
|
412
|
+
* ))}
|
|
413
|
+
* </ul>
|
|
414
|
+
* )}
|
|
415
|
+
* </div>
|
|
416
|
+
* )
|
|
417
|
+
* }
|
|
418
|
+
* ```
|
|
419
|
+
*/
|
|
420
|
+
declare function useUsers(options?: UseUsersOptions): UseUsersReturn;
|
|
421
|
+
|
|
422
|
+
interface UseAPIKeysOptions {
|
|
423
|
+
/**
|
|
424
|
+
* Whether to automatically fetch API keys on mount
|
|
425
|
+
* @default true
|
|
426
|
+
*/
|
|
427
|
+
autoFetch?: boolean;
|
|
428
|
+
}
|
|
429
|
+
interface UseAPIKeysReturn {
|
|
430
|
+
/**
|
|
431
|
+
* Array of API keys
|
|
432
|
+
*/
|
|
433
|
+
keys: APIKey[];
|
|
434
|
+
/**
|
|
435
|
+
* Whether keys are being fetched
|
|
436
|
+
*/
|
|
437
|
+
isLoading: boolean;
|
|
438
|
+
/**
|
|
439
|
+
* Any error that occurred
|
|
440
|
+
*/
|
|
441
|
+
error: Error | null;
|
|
442
|
+
/**
|
|
443
|
+
* Refetch API keys
|
|
444
|
+
*/
|
|
445
|
+
refetch: () => Promise<void>;
|
|
446
|
+
/**
|
|
447
|
+
* Create a new API key
|
|
448
|
+
*/
|
|
449
|
+
createKey: (request: CreateAPIKeyRequest) => Promise<{
|
|
450
|
+
key: string;
|
|
451
|
+
keyData: APIKey;
|
|
452
|
+
}>;
|
|
453
|
+
/**
|
|
454
|
+
* Update an API key
|
|
455
|
+
*/
|
|
456
|
+
updateKey: (keyId: string, update: {
|
|
457
|
+
name?: string;
|
|
458
|
+
description?: string;
|
|
459
|
+
}) => Promise<void>;
|
|
460
|
+
/**
|
|
461
|
+
* Revoke an API key
|
|
462
|
+
*/
|
|
463
|
+
revokeKey: (keyId: string) => Promise<void>;
|
|
464
|
+
/**
|
|
465
|
+
* Delete an API key
|
|
466
|
+
*/
|
|
467
|
+
deleteKey: (keyId: string) => Promise<void>;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Hook for managing API keys
|
|
471
|
+
*
|
|
472
|
+
* Provides API key list and management functions.
|
|
473
|
+
*
|
|
474
|
+
* @example
|
|
475
|
+
* ```tsx
|
|
476
|
+
* function APIKeyManager() {
|
|
477
|
+
* const { keys, isLoading, createKey, revokeKey } = useAPIKeys()
|
|
478
|
+
*
|
|
479
|
+
* const handleCreate = async () => {
|
|
480
|
+
* const { key, keyData } = await createKey({
|
|
481
|
+
* name: 'Backend Service',
|
|
482
|
+
* description: 'API key for backend',
|
|
483
|
+
* expires_at: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString()
|
|
484
|
+
* })
|
|
485
|
+
* alert(`Key created: ${key}`)
|
|
486
|
+
* }
|
|
487
|
+
*
|
|
488
|
+
* return (
|
|
489
|
+
* <div>
|
|
490
|
+
* <button onClick={handleCreate}>Create Key</button>
|
|
491
|
+
* {keys.map(k => (
|
|
492
|
+
* <div key={k.id}>
|
|
493
|
+
* {k.name}
|
|
494
|
+
* <button onClick={() => revokeKey(k.id)}>Revoke</button>
|
|
495
|
+
* </div>
|
|
496
|
+
* ))}
|
|
497
|
+
* </div>
|
|
498
|
+
* )
|
|
499
|
+
* }
|
|
500
|
+
* ```
|
|
501
|
+
*/
|
|
502
|
+
declare function useAPIKeys(options?: UseAPIKeysOptions): UseAPIKeysReturn;
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* Admin Settings and Management Hooks
|
|
506
|
+
*
|
|
507
|
+
* Hooks for managing application settings, system settings, and webhooks.
|
|
508
|
+
*/
|
|
509
|
+
|
|
510
|
+
interface UseAppSettingsOptions {
|
|
511
|
+
autoFetch?: boolean;
|
|
512
|
+
}
|
|
513
|
+
interface UseAppSettingsReturn {
|
|
514
|
+
settings: AppSettings | null;
|
|
515
|
+
isLoading: boolean;
|
|
516
|
+
error: Error | null;
|
|
517
|
+
refetch: () => Promise<void>;
|
|
518
|
+
updateSettings: (update: UpdateAppSettingsRequest) => Promise<void>;
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Hook for managing application settings
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* ```tsx
|
|
525
|
+
* function SettingsPanel() {
|
|
526
|
+
* const { settings, isLoading, updateSettings } = useAppSettings({ autoFetch: true })
|
|
527
|
+
*
|
|
528
|
+
* const handleToggleFeature = async (feature: string, enabled: boolean) => {
|
|
529
|
+
* await updateSettings({
|
|
530
|
+
* features: { ...settings?.features, [feature]: enabled }
|
|
531
|
+
* })
|
|
532
|
+
* }
|
|
533
|
+
*
|
|
534
|
+
* return <div>...</div>
|
|
535
|
+
* }
|
|
536
|
+
* ```
|
|
537
|
+
*/
|
|
538
|
+
declare function useAppSettings(options?: UseAppSettingsOptions): UseAppSettingsReturn;
|
|
539
|
+
interface UseSystemSettingsOptions {
|
|
540
|
+
autoFetch?: boolean;
|
|
541
|
+
}
|
|
542
|
+
interface UseSystemSettingsReturn {
|
|
543
|
+
settings: SystemSetting[];
|
|
544
|
+
isLoading: boolean;
|
|
545
|
+
error: Error | null;
|
|
546
|
+
refetch: () => Promise<void>;
|
|
547
|
+
getSetting: (key: string) => SystemSetting | undefined;
|
|
548
|
+
updateSetting: (key: string, update: UpdateSystemSettingRequest) => Promise<void>;
|
|
549
|
+
deleteSetting: (key: string) => Promise<void>;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Hook for managing system settings (key-value storage)
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* ```tsx
|
|
556
|
+
* function SystemSettings() {
|
|
557
|
+
* const { settings, isLoading, updateSetting } = useSystemSettings({ autoFetch: true })
|
|
558
|
+
*
|
|
559
|
+
* const handleUpdateSetting = async (key: string, value: any) => {
|
|
560
|
+
* await updateSetting(key, { value })
|
|
561
|
+
* }
|
|
562
|
+
*
|
|
563
|
+
* return <div>...</div>
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
declare function useSystemSettings(options?: UseSystemSettingsOptions): UseSystemSettingsReturn;
|
|
568
|
+
interface UseWebhooksOptions {
|
|
569
|
+
autoFetch?: boolean;
|
|
570
|
+
refetchInterval?: number;
|
|
571
|
+
}
|
|
572
|
+
interface UseWebhooksReturn {
|
|
573
|
+
webhooks: Webhook[];
|
|
574
|
+
isLoading: boolean;
|
|
575
|
+
error: Error | null;
|
|
576
|
+
refetch: () => Promise<void>;
|
|
577
|
+
createWebhook: (webhook: CreateWebhookRequest) => Promise<Webhook>;
|
|
578
|
+
updateWebhook: (id: string, update: UpdateWebhookRequest) => Promise<Webhook>;
|
|
579
|
+
deleteWebhook: (id: string) => Promise<void>;
|
|
580
|
+
testWebhook: (id: string) => Promise<void>;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Hook for managing webhooks
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
586
|
+
* ```tsx
|
|
587
|
+
* function WebhooksManager() {
|
|
588
|
+
* const { webhooks, isLoading, createWebhook, deleteWebhook } = useWebhooks({
|
|
589
|
+
* autoFetch: true
|
|
590
|
+
* })
|
|
591
|
+
*
|
|
592
|
+
* const handleCreate = async () => {
|
|
593
|
+
* await createWebhook({
|
|
594
|
+
* url: 'https://example.com/webhook',
|
|
595
|
+
* events: ['user.created', 'user.updated'],
|
|
596
|
+
* enabled: true
|
|
597
|
+
* })
|
|
598
|
+
* }
|
|
599
|
+
*
|
|
600
|
+
* return <div>...</div>
|
|
601
|
+
* }
|
|
602
|
+
* ```
|
|
603
|
+
*/
|
|
604
|
+
declare function useWebhooks(options?: UseWebhooksOptions): UseWebhooksReturn;
|
|
605
|
+
|
|
606
|
+
export { FluxbaseProvider, useAPIKeys, useAdminAuth, useAppSettings, useAuth, useCreateBucket, useDelete, useDeleteBucket, useFluxbaseClient, useFluxbaseQuery, useInsert, useRPC, useRPCBatch, useRPCMutation, useRealtime, useSession, useSignIn, useSignOut, useSignUp, useStorageBuckets, useStorageCopy, useStorageDelete, useStorageDownload, useStorageList, useStorageMove, useStoragePublicUrl, useStorageSignedUrl, useStorageUpload, useSystemSettings, useTable, useTableDeletes, useTableInserts, useTableSubscription, useTableUpdates, useUpdate, useUpdateUser, useUpsert, useUser, useUsers, useWebhooks };
|