@fluxbase/sdk-react 0.1.0-rc.1 → 2026.1.1-rc.10
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/README-ADMIN.md +8 -8
- package/README.md +27 -14
- package/dist/index.d.mts +713 -83
- package/dist/index.d.ts +713 -83
- package/dist/index.js +574 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +561 -172
- package/dist/index.mjs.map +1 -1
- package/examples/AdminDashboard.tsx +3 -3
- package/examples/README.md +1 -1
- package/package.json +3 -3
- package/src/index.ts +60 -18
- package/src/use-admin-auth.ts +62 -51
- package/src/use-auth-config.ts +101 -0
- package/src/use-auth.ts +66 -49
- package/src/use-captcha.ts +250 -0
- package/src/{use-api-keys.ts → use-client-keys.ts} +43 -32
- package/src/use-graphql.ts +392 -0
- package/src/use-realtime.ts +58 -44
- package/src/use-saml.ts +221 -0
- package/src/use-storage.ts +325 -82
- package/src/use-users.ts +11 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/typedoc.json +2 -4
- package/CHANGELOG.md +0 -67
- package/src/use-rpc.ts +0 -109
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
|
|
24
|
-
if (!session) {
|
|
23
|
+
const { data } = await client.auth.getSession();
|
|
24
|
+
if (!data?.session) {
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
27
|
try {
|
|
28
|
-
|
|
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: () =>
|
|
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: (
|
|
69
|
-
|
|
70
|
-
|
|
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
|
}
|
|
@@ -120,12 +132,303 @@ function useAuth() {
|
|
|
120
132
|
};
|
|
121
133
|
}
|
|
122
134
|
|
|
135
|
+
// src/use-captcha.ts
|
|
136
|
+
import { useQuery as useQuery2 } from "@tanstack/react-query";
|
|
137
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
138
|
+
function useCaptchaConfig() {
|
|
139
|
+
const client = useFluxbaseClient();
|
|
140
|
+
return useQuery2({
|
|
141
|
+
queryKey: ["fluxbase", "auth", "captcha", "config"],
|
|
142
|
+
queryFn: async () => {
|
|
143
|
+
const { data, error } = await client.auth.getCaptchaConfig();
|
|
144
|
+
if (error) {
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
return data;
|
|
148
|
+
},
|
|
149
|
+
staleTime: 1e3 * 60 * 60,
|
|
150
|
+
// Cache for 1 hour (config rarely changes)
|
|
151
|
+
gcTime: 1e3 * 60 * 60 * 24
|
|
152
|
+
// Keep in cache for 24 hours
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function useCaptcha(provider) {
|
|
156
|
+
const [token, setToken] = useState(null);
|
|
157
|
+
const [isReady, setIsReady] = useState(false);
|
|
158
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
159
|
+
const [error, setError] = useState(null);
|
|
160
|
+
const executeResolverRef = useRef(null);
|
|
161
|
+
const executeRejecterRef = useRef(null);
|
|
162
|
+
const onVerify = useCallback((newToken) => {
|
|
163
|
+
setToken(newToken);
|
|
164
|
+
setIsLoading(false);
|
|
165
|
+
setError(null);
|
|
166
|
+
setIsReady(true);
|
|
167
|
+
if (executeResolverRef.current) {
|
|
168
|
+
executeResolverRef.current(newToken);
|
|
169
|
+
executeResolverRef.current = null;
|
|
170
|
+
executeRejecterRef.current = null;
|
|
171
|
+
}
|
|
172
|
+
}, []);
|
|
173
|
+
const onExpire = useCallback(() => {
|
|
174
|
+
setToken(null);
|
|
175
|
+
setIsReady(true);
|
|
176
|
+
}, []);
|
|
177
|
+
const onError = useCallback((err) => {
|
|
178
|
+
setError(err);
|
|
179
|
+
setIsLoading(false);
|
|
180
|
+
setToken(null);
|
|
181
|
+
if (executeRejecterRef.current) {
|
|
182
|
+
executeRejecterRef.current(err);
|
|
183
|
+
executeResolverRef.current = null;
|
|
184
|
+
executeRejecterRef.current = null;
|
|
185
|
+
}
|
|
186
|
+
}, []);
|
|
187
|
+
const reset = useCallback(() => {
|
|
188
|
+
setToken(null);
|
|
189
|
+
setError(null);
|
|
190
|
+
setIsLoading(false);
|
|
191
|
+
}, []);
|
|
192
|
+
const execute = useCallback(async () => {
|
|
193
|
+
if (token) {
|
|
194
|
+
return token;
|
|
195
|
+
}
|
|
196
|
+
if (!provider) {
|
|
197
|
+
return "";
|
|
198
|
+
}
|
|
199
|
+
setIsLoading(true);
|
|
200
|
+
setError(null);
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
executeResolverRef.current = resolve;
|
|
203
|
+
executeRejecterRef.current = reject;
|
|
204
|
+
});
|
|
205
|
+
}, [token, provider]);
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
if (provider) {
|
|
208
|
+
setIsReady(true);
|
|
209
|
+
}
|
|
210
|
+
}, [provider]);
|
|
211
|
+
return {
|
|
212
|
+
token,
|
|
213
|
+
isReady,
|
|
214
|
+
isLoading,
|
|
215
|
+
error,
|
|
216
|
+
reset,
|
|
217
|
+
execute,
|
|
218
|
+
onVerify,
|
|
219
|
+
onExpire,
|
|
220
|
+
onError
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function isCaptchaRequiredForEndpoint(config, endpoint) {
|
|
224
|
+
if (!config?.enabled) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
return config.endpoints?.includes(endpoint) ?? false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/use-auth-config.ts
|
|
231
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
232
|
+
function useAuthConfig() {
|
|
233
|
+
const client = useFluxbaseClient();
|
|
234
|
+
return useQuery3({
|
|
235
|
+
queryKey: ["fluxbase", "auth", "config"],
|
|
236
|
+
queryFn: async () => {
|
|
237
|
+
const { data, error } = await client.auth.getAuthConfig();
|
|
238
|
+
if (error) {
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
return data;
|
|
242
|
+
},
|
|
243
|
+
staleTime: 1e3 * 60 * 5,
|
|
244
|
+
// Cache for 5 minutes (config changes infrequently)
|
|
245
|
+
gcTime: 1e3 * 60 * 60
|
|
246
|
+
// Keep in cache for 1 hour
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/use-saml.ts
|
|
251
|
+
import { useMutation as useMutation2, useQuery as useQuery4, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
252
|
+
function useSAMLProviders() {
|
|
253
|
+
const client = useFluxbaseClient();
|
|
254
|
+
return useQuery4({
|
|
255
|
+
queryKey: ["fluxbase", "auth", "saml", "providers"],
|
|
256
|
+
queryFn: async () => {
|
|
257
|
+
const { data, error } = await client.auth.getSAMLProviders();
|
|
258
|
+
if (error) throw error;
|
|
259
|
+
return data.providers;
|
|
260
|
+
},
|
|
261
|
+
staleTime: 1e3 * 60 * 5
|
|
262
|
+
// 5 minutes - providers don't change often
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function useGetSAMLLoginUrl() {
|
|
266
|
+
const client = useFluxbaseClient();
|
|
267
|
+
return useMutation2({
|
|
268
|
+
mutationFn: async ({
|
|
269
|
+
provider,
|
|
270
|
+
options
|
|
271
|
+
}) => {
|
|
272
|
+
return await client.auth.getSAMLLoginUrl(provider, options);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function useSignInWithSAML() {
|
|
277
|
+
const client = useFluxbaseClient();
|
|
278
|
+
return useMutation2({
|
|
279
|
+
mutationFn: async ({
|
|
280
|
+
provider,
|
|
281
|
+
options
|
|
282
|
+
}) => {
|
|
283
|
+
return await client.auth.signInWithSAML(provider, options);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
function useHandleSAMLCallback() {
|
|
288
|
+
const client = useFluxbaseClient();
|
|
289
|
+
const queryClient = useQueryClient2();
|
|
290
|
+
return useMutation2({
|
|
291
|
+
mutationFn: async ({
|
|
292
|
+
samlResponse,
|
|
293
|
+
provider
|
|
294
|
+
}) => {
|
|
295
|
+
return await client.auth.handleSAMLCallback(samlResponse, provider);
|
|
296
|
+
},
|
|
297
|
+
onSuccess: (result) => {
|
|
298
|
+
if (result.data) {
|
|
299
|
+
queryClient.setQueryData(
|
|
300
|
+
["fluxbase", "auth", "session"],
|
|
301
|
+
result.data.session
|
|
302
|
+
);
|
|
303
|
+
queryClient.setQueryData(
|
|
304
|
+
["fluxbase", "auth", "user"],
|
|
305
|
+
result.data.user
|
|
306
|
+
);
|
|
307
|
+
queryClient.invalidateQueries({ queryKey: ["fluxbase"] });
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
function useSAMLMetadataUrl() {
|
|
313
|
+
const client = useFluxbaseClient();
|
|
314
|
+
return (provider) => {
|
|
315
|
+
return client.auth.getSAMLMetadataUrl(provider);
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/use-graphql.ts
|
|
320
|
+
import { useMutation as useMutation3, useQuery as useQuery5, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
|
|
321
|
+
function useGraphQLQuery(queryKey, query, options) {
|
|
322
|
+
const client = useFluxbaseClient();
|
|
323
|
+
const normalizedKey = Array.isArray(queryKey) ? ["fluxbase", "graphql", ...queryKey] : ["fluxbase", "graphql", queryKey];
|
|
324
|
+
return useQuery5({
|
|
325
|
+
queryKey: normalizedKey,
|
|
326
|
+
queryFn: async () => {
|
|
327
|
+
const response = await client.graphql.execute(
|
|
328
|
+
query,
|
|
329
|
+
options?.variables,
|
|
330
|
+
options?.operationName,
|
|
331
|
+
options?.requestOptions
|
|
332
|
+
);
|
|
333
|
+
if (response.errors && response.errors.length > 0) {
|
|
334
|
+
throw response.errors[0];
|
|
335
|
+
}
|
|
336
|
+
return response.data;
|
|
337
|
+
},
|
|
338
|
+
enabled: options?.enabled ?? true,
|
|
339
|
+
staleTime: options?.staleTime ?? 0,
|
|
340
|
+
gcTime: options?.gcTime,
|
|
341
|
+
refetchOnWindowFocus: options?.refetchOnWindowFocus ?? true,
|
|
342
|
+
select: options?.select
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
function useGraphQLMutation(mutation, options) {
|
|
346
|
+
const client = useFluxbaseClient();
|
|
347
|
+
const queryClient = useQueryClient3();
|
|
348
|
+
return useMutation3({
|
|
349
|
+
mutationFn: async (variables) => {
|
|
350
|
+
const response = await client.graphql.execute(
|
|
351
|
+
mutation,
|
|
352
|
+
variables,
|
|
353
|
+
options?.operationName,
|
|
354
|
+
options?.requestOptions
|
|
355
|
+
);
|
|
356
|
+
if (response.errors && response.errors.length > 0) {
|
|
357
|
+
throw response.errors[0];
|
|
358
|
+
}
|
|
359
|
+
return response.data;
|
|
360
|
+
},
|
|
361
|
+
onSuccess: (data, variables) => {
|
|
362
|
+
if (options?.invalidateQueries) {
|
|
363
|
+
for (const key of options.invalidateQueries) {
|
|
364
|
+
queryClient.invalidateQueries({
|
|
365
|
+
queryKey: ["fluxbase", "graphql", key]
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (options?.onSuccess && data !== void 0) {
|
|
370
|
+
options.onSuccess(data, variables);
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
onError: (error, variables) => {
|
|
374
|
+
if (options?.onError) {
|
|
375
|
+
options.onError(error, variables);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function useGraphQLIntrospection(options) {
|
|
381
|
+
const client = useFluxbaseClient();
|
|
382
|
+
return useQuery5({
|
|
383
|
+
queryKey: ["fluxbase", "graphql", "__introspection"],
|
|
384
|
+
queryFn: async () => {
|
|
385
|
+
const response = await client.graphql.introspect(options?.requestOptions);
|
|
386
|
+
if (response.errors && response.errors.length > 0) {
|
|
387
|
+
throw response.errors[0];
|
|
388
|
+
}
|
|
389
|
+
return response.data;
|
|
390
|
+
},
|
|
391
|
+
enabled: options?.enabled ?? true,
|
|
392
|
+
staleTime: options?.staleTime ?? 1e3 * 60 * 5
|
|
393
|
+
// 5 minutes - schema doesn't change often
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
function useGraphQL() {
|
|
397
|
+
const client = useFluxbaseClient();
|
|
398
|
+
return {
|
|
399
|
+
/**
|
|
400
|
+
* Execute a GraphQL query
|
|
401
|
+
*/
|
|
402
|
+
executeQuery: (query, variables, options) => {
|
|
403
|
+
return client.graphql.query(query, variables, options);
|
|
404
|
+
},
|
|
405
|
+
/**
|
|
406
|
+
* Execute a GraphQL mutation
|
|
407
|
+
*/
|
|
408
|
+
executeMutation: (mutation, variables, options) => {
|
|
409
|
+
return client.graphql.mutation(mutation, variables, options);
|
|
410
|
+
},
|
|
411
|
+
/**
|
|
412
|
+
* Execute a GraphQL operation with an explicit operation name
|
|
413
|
+
*/
|
|
414
|
+
execute: (document, variables, operationName, options) => {
|
|
415
|
+
return client.graphql.execute(document, variables, operationName, options);
|
|
416
|
+
},
|
|
417
|
+
/**
|
|
418
|
+
* Fetch the GraphQL schema via introspection
|
|
419
|
+
*/
|
|
420
|
+
introspect: (options) => {
|
|
421
|
+
return client.graphql.introspect(options);
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
|
|
123
426
|
// src/use-query.ts
|
|
124
|
-
import { useQuery as
|
|
427
|
+
import { useQuery as useQuery6, useMutation as useMutation4, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
|
|
125
428
|
function useFluxbaseQuery(buildQuery, options) {
|
|
126
429
|
const client = useFluxbaseClient();
|
|
127
430
|
const queryKey = options?.queryKey || ["fluxbase", "query", buildQuery.toString()];
|
|
128
|
-
return
|
|
431
|
+
return useQuery6({
|
|
129
432
|
queryKey,
|
|
130
433
|
queryFn: async () => {
|
|
131
434
|
const query = buildQuery(client);
|
|
@@ -153,8 +456,8 @@ function useTable(table, buildQuery, options) {
|
|
|
153
456
|
}
|
|
154
457
|
function useInsert(table) {
|
|
155
458
|
const client = useFluxbaseClient();
|
|
156
|
-
const queryClient =
|
|
157
|
-
return
|
|
459
|
+
const queryClient = useQueryClient4();
|
|
460
|
+
return useMutation4({
|
|
158
461
|
mutationFn: async (data) => {
|
|
159
462
|
const query = client.from(table);
|
|
160
463
|
const { data: result, error } = await query.insert(data);
|
|
@@ -170,8 +473,8 @@ function useInsert(table) {
|
|
|
170
473
|
}
|
|
171
474
|
function useUpdate(table) {
|
|
172
475
|
const client = useFluxbaseClient();
|
|
173
|
-
const queryClient =
|
|
174
|
-
return
|
|
476
|
+
const queryClient = useQueryClient4();
|
|
477
|
+
return useMutation4({
|
|
175
478
|
mutationFn: async (params) => {
|
|
176
479
|
const query = client.from(table);
|
|
177
480
|
const builtQuery = params.buildQuery(query);
|
|
@@ -188,8 +491,8 @@ function useUpdate(table) {
|
|
|
188
491
|
}
|
|
189
492
|
function useUpsert(table) {
|
|
190
493
|
const client = useFluxbaseClient();
|
|
191
|
-
const queryClient =
|
|
192
|
-
return
|
|
494
|
+
const queryClient = useQueryClient4();
|
|
495
|
+
return useMutation4({
|
|
193
496
|
mutationFn: async (data) => {
|
|
194
497
|
const query = client.from(table);
|
|
195
498
|
const { data: result, error } = await query.upsert(data);
|
|
@@ -205,8 +508,8 @@ function useUpsert(table) {
|
|
|
205
508
|
}
|
|
206
509
|
function useDelete(table) {
|
|
207
510
|
const client = useFluxbaseClient();
|
|
208
|
-
const queryClient =
|
|
209
|
-
return
|
|
511
|
+
const queryClient = useQueryClient4();
|
|
512
|
+
return useMutation4({
|
|
210
513
|
mutationFn: async (buildQuery) => {
|
|
211
514
|
const query = client.from(table);
|
|
212
515
|
const builtQuery = buildQuery(query);
|
|
@@ -222,12 +525,14 @@ function useDelete(table) {
|
|
|
222
525
|
}
|
|
223
526
|
|
|
224
527
|
// src/use-realtime.ts
|
|
225
|
-
import { useEffect, useRef } from "react";
|
|
226
|
-
import { useQueryClient as
|
|
528
|
+
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
529
|
+
import { useQueryClient as useQueryClient5 } from "@tanstack/react-query";
|
|
227
530
|
function useRealtime(options) {
|
|
228
531
|
const client = useFluxbaseClient();
|
|
229
|
-
const queryClient =
|
|
230
|
-
const channelRef =
|
|
532
|
+
const queryClient = useQueryClient5();
|
|
533
|
+
const channelRef = useRef2(
|
|
534
|
+
null
|
|
535
|
+
);
|
|
231
536
|
const {
|
|
232
537
|
channel: channelName,
|
|
233
538
|
event = "*",
|
|
@@ -236,7 +541,7 @@ function useRealtime(options) {
|
|
|
236
541
|
invalidateKey,
|
|
237
542
|
enabled = true
|
|
238
543
|
} = options;
|
|
239
|
-
|
|
544
|
+
useEffect2(() => {
|
|
240
545
|
if (!enabled) {
|
|
241
546
|
return;
|
|
242
547
|
}
|
|
@@ -257,7 +562,16 @@ function useRealtime(options) {
|
|
|
257
562
|
channel.unsubscribe();
|
|
258
563
|
channelRef.current = null;
|
|
259
564
|
};
|
|
260
|
-
}, [
|
|
565
|
+
}, [
|
|
566
|
+
client,
|
|
567
|
+
channelName,
|
|
568
|
+
event,
|
|
569
|
+
callback,
|
|
570
|
+
autoInvalidate,
|
|
571
|
+
invalidateKey,
|
|
572
|
+
queryClient,
|
|
573
|
+
enabled
|
|
574
|
+
]);
|
|
261
575
|
return {
|
|
262
576
|
channel: channelRef.current
|
|
263
577
|
};
|
|
@@ -294,12 +608,23 @@ function useTableDeletes(table, callback, options) {
|
|
|
294
608
|
}
|
|
295
609
|
|
|
296
610
|
// src/use-storage.ts
|
|
297
|
-
import {
|
|
611
|
+
import { useState as useState2 } from "react";
|
|
612
|
+
import {
|
|
613
|
+
useMutation as useMutation5,
|
|
614
|
+
useQuery as useQuery7,
|
|
615
|
+
useQueryClient as useQueryClient6
|
|
616
|
+
} from "@tanstack/react-query";
|
|
298
617
|
function useStorageList(bucket, options) {
|
|
299
618
|
const client = useFluxbaseClient();
|
|
300
619
|
const { prefix, limit, offset, ...queryOptions } = options || {};
|
|
301
|
-
return
|
|
302
|
-
queryKey: [
|
|
620
|
+
return useQuery7({
|
|
621
|
+
queryKey: [
|
|
622
|
+
"fluxbase",
|
|
623
|
+
"storage",
|
|
624
|
+
bucket,
|
|
625
|
+
"list",
|
|
626
|
+
{ prefix, limit, offset }
|
|
627
|
+
],
|
|
303
628
|
queryFn: async () => {
|
|
304
629
|
const { data, error } = await client.storage.from(bucket).list({ prefix, limit, offset });
|
|
305
630
|
if (error) {
|
|
@@ -312,8 +637,8 @@ function useStorageList(bucket, options) {
|
|
|
312
637
|
}
|
|
313
638
|
function useStorageUpload(bucket) {
|
|
314
639
|
const client = useFluxbaseClient();
|
|
315
|
-
const queryClient =
|
|
316
|
-
return
|
|
640
|
+
const queryClient = useQueryClient6();
|
|
641
|
+
return useMutation5({
|
|
317
642
|
mutationFn: async (params) => {
|
|
318
643
|
const { path, file, options } = params;
|
|
319
644
|
const { data, error } = await client.storage.from(bucket).upload(path, file, options);
|
|
@@ -323,13 +648,49 @@ function useStorageUpload(bucket) {
|
|
|
323
648
|
return data;
|
|
324
649
|
},
|
|
325
650
|
onSuccess: () => {
|
|
326
|
-
queryClient.invalidateQueries({
|
|
651
|
+
queryClient.invalidateQueries({
|
|
652
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
653
|
+
});
|
|
327
654
|
}
|
|
328
655
|
});
|
|
329
656
|
}
|
|
657
|
+
function useStorageUploadWithProgress(bucket) {
|
|
658
|
+
const client = useFluxbaseClient();
|
|
659
|
+
const queryClient = useQueryClient6();
|
|
660
|
+
const [progress, setProgress] = useState2(null);
|
|
661
|
+
const mutation = useMutation5({
|
|
662
|
+
mutationFn: async (params) => {
|
|
663
|
+
const { path, file, options } = params;
|
|
664
|
+
setProgress({ loaded: 0, total: 0, percentage: 0 });
|
|
665
|
+
const { data, error } = await client.storage.from(bucket).upload(path, file, {
|
|
666
|
+
...options,
|
|
667
|
+
onUploadProgress: (p) => {
|
|
668
|
+
setProgress(p);
|
|
669
|
+
}
|
|
670
|
+
});
|
|
671
|
+
if (error) {
|
|
672
|
+
throw error;
|
|
673
|
+
}
|
|
674
|
+
return data;
|
|
675
|
+
},
|
|
676
|
+
onSuccess: () => {
|
|
677
|
+
queryClient.invalidateQueries({
|
|
678
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
679
|
+
});
|
|
680
|
+
},
|
|
681
|
+
onError: () => {
|
|
682
|
+
setProgress(null);
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
return {
|
|
686
|
+
upload: mutation,
|
|
687
|
+
progress,
|
|
688
|
+
reset: () => setProgress(null)
|
|
689
|
+
};
|
|
690
|
+
}
|
|
330
691
|
function useStorageDownload(bucket, path, enabled = true) {
|
|
331
692
|
const client = useFluxbaseClient();
|
|
332
|
-
return
|
|
693
|
+
return useQuery7({
|
|
333
694
|
queryKey: ["fluxbase", "storage", bucket, "download", path],
|
|
334
695
|
queryFn: async () => {
|
|
335
696
|
if (!path) {
|
|
@@ -346,8 +707,8 @@ function useStorageDownload(bucket, path, enabled = true) {
|
|
|
346
707
|
}
|
|
347
708
|
function useStorageDelete(bucket) {
|
|
348
709
|
const client = useFluxbaseClient();
|
|
349
|
-
const queryClient =
|
|
350
|
-
return
|
|
710
|
+
const queryClient = useQueryClient6();
|
|
711
|
+
return useMutation5({
|
|
351
712
|
mutationFn: async (paths) => {
|
|
352
713
|
const { error } = await client.storage.from(bucket).remove(paths);
|
|
353
714
|
if (error) {
|
|
@@ -355,7 +716,9 @@ function useStorageDelete(bucket) {
|
|
|
355
716
|
}
|
|
356
717
|
},
|
|
357
718
|
onSuccess: () => {
|
|
358
|
-
queryClient.invalidateQueries({
|
|
719
|
+
queryClient.invalidateQueries({
|
|
720
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
721
|
+
});
|
|
359
722
|
}
|
|
360
723
|
});
|
|
361
724
|
}
|
|
@@ -367,9 +730,16 @@ function useStoragePublicUrl(bucket, path) {
|
|
|
367
730
|
const { data } = client.storage.from(bucket).getPublicUrl(path);
|
|
368
731
|
return data.publicUrl;
|
|
369
732
|
}
|
|
733
|
+
function useStorageTransformUrl(bucket, path, transform) {
|
|
734
|
+
const client = useFluxbaseClient();
|
|
735
|
+
if (!path) {
|
|
736
|
+
return null;
|
|
737
|
+
}
|
|
738
|
+
return client.storage.from(bucket).getTransformUrl(path, transform);
|
|
739
|
+
}
|
|
370
740
|
function useStorageSignedUrl(bucket, path, expiresIn) {
|
|
371
741
|
const client = useFluxbaseClient();
|
|
372
|
-
return
|
|
742
|
+
return useQuery7({
|
|
373
743
|
queryKey: ["fluxbase", "storage", bucket, "signed-url", path, expiresIn],
|
|
374
744
|
queryFn: async () => {
|
|
375
745
|
if (!path) {
|
|
@@ -386,10 +756,39 @@ function useStorageSignedUrl(bucket, path, expiresIn) {
|
|
|
386
756
|
// Refresh 1 minute before expiry
|
|
387
757
|
});
|
|
388
758
|
}
|
|
759
|
+
function useStorageSignedUrlWithOptions(bucket, path, options) {
|
|
760
|
+
const client = useFluxbaseClient();
|
|
761
|
+
const expiresIn = options?.expiresIn;
|
|
762
|
+
const transformKey = options?.transform ? JSON.stringify(options.transform) : null;
|
|
763
|
+
return useQuery7({
|
|
764
|
+
queryKey: [
|
|
765
|
+
"fluxbase",
|
|
766
|
+
"storage",
|
|
767
|
+
bucket,
|
|
768
|
+
"signed-url",
|
|
769
|
+
path,
|
|
770
|
+
expiresIn,
|
|
771
|
+
transformKey
|
|
772
|
+
],
|
|
773
|
+
queryFn: async () => {
|
|
774
|
+
if (!path) {
|
|
775
|
+
return null;
|
|
776
|
+
}
|
|
777
|
+
const { data, error } = await client.storage.from(bucket).createSignedUrl(path, options);
|
|
778
|
+
if (error) {
|
|
779
|
+
throw error;
|
|
780
|
+
}
|
|
781
|
+
return data?.signedUrl || null;
|
|
782
|
+
},
|
|
783
|
+
enabled: !!path,
|
|
784
|
+
staleTime: expiresIn ? expiresIn * 1e3 - 6e4 : 1e3 * 60 * 50
|
|
785
|
+
// Refresh 1 minute before expiry
|
|
786
|
+
});
|
|
787
|
+
}
|
|
389
788
|
function useStorageMove(bucket) {
|
|
390
789
|
const client = useFluxbaseClient();
|
|
391
|
-
const queryClient =
|
|
392
|
-
return
|
|
790
|
+
const queryClient = useQueryClient6();
|
|
791
|
+
return useMutation5({
|
|
393
792
|
mutationFn: async (params) => {
|
|
394
793
|
const { fromPath, toPath } = params;
|
|
395
794
|
const { data, error } = await client.storage.from(bucket).move(fromPath, toPath);
|
|
@@ -399,14 +798,16 @@ function useStorageMove(bucket) {
|
|
|
399
798
|
return data;
|
|
400
799
|
},
|
|
401
800
|
onSuccess: () => {
|
|
402
|
-
queryClient.invalidateQueries({
|
|
801
|
+
queryClient.invalidateQueries({
|
|
802
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
803
|
+
});
|
|
403
804
|
}
|
|
404
805
|
});
|
|
405
806
|
}
|
|
406
807
|
function useStorageCopy(bucket) {
|
|
407
808
|
const client = useFluxbaseClient();
|
|
408
|
-
const queryClient =
|
|
409
|
-
return
|
|
809
|
+
const queryClient = useQueryClient6();
|
|
810
|
+
return useMutation5({
|
|
410
811
|
mutationFn: async (params) => {
|
|
411
812
|
const { fromPath, toPath } = params;
|
|
412
813
|
const { data, error } = await client.storage.from(bucket).copy(fromPath, toPath);
|
|
@@ -416,13 +817,15 @@ function useStorageCopy(bucket) {
|
|
|
416
817
|
return data;
|
|
417
818
|
},
|
|
418
819
|
onSuccess: () => {
|
|
419
|
-
queryClient.invalidateQueries({
|
|
820
|
+
queryClient.invalidateQueries({
|
|
821
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
822
|
+
});
|
|
420
823
|
}
|
|
421
824
|
});
|
|
422
825
|
}
|
|
423
826
|
function useStorageBuckets() {
|
|
424
827
|
const client = useFluxbaseClient();
|
|
425
|
-
return
|
|
828
|
+
return useQuery7({
|
|
426
829
|
queryKey: ["fluxbase", "storage", "buckets"],
|
|
427
830
|
queryFn: async () => {
|
|
428
831
|
const { data, error } = await client.storage.listBuckets();
|
|
@@ -435,8 +838,8 @@ function useStorageBuckets() {
|
|
|
435
838
|
}
|
|
436
839
|
function useCreateBucket() {
|
|
437
840
|
const client = useFluxbaseClient();
|
|
438
|
-
const queryClient =
|
|
439
|
-
return
|
|
841
|
+
const queryClient = useQueryClient6();
|
|
842
|
+
return useMutation5({
|
|
440
843
|
mutationFn: async (bucketName) => {
|
|
441
844
|
const { error } = await client.storage.createBucket(bucketName);
|
|
442
845
|
if (error) {
|
|
@@ -444,14 +847,16 @@ function useCreateBucket() {
|
|
|
444
847
|
}
|
|
445
848
|
},
|
|
446
849
|
onSuccess: () => {
|
|
447
|
-
queryClient.invalidateQueries({
|
|
850
|
+
queryClient.invalidateQueries({
|
|
851
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
852
|
+
});
|
|
448
853
|
}
|
|
449
854
|
});
|
|
450
855
|
}
|
|
451
856
|
function useDeleteBucket() {
|
|
452
857
|
const client = useFluxbaseClient();
|
|
453
|
-
const queryClient =
|
|
454
|
-
return
|
|
858
|
+
const queryClient = useQueryClient6();
|
|
859
|
+
return useMutation5({
|
|
455
860
|
mutationFn: async (bucketName) => {
|
|
456
861
|
const { error } = await client.storage.deleteBucket(bucketName);
|
|
457
862
|
if (error) {
|
|
@@ -459,74 +864,30 @@ function useDeleteBucket() {
|
|
|
459
864
|
}
|
|
460
865
|
},
|
|
461
866
|
onSuccess: () => {
|
|
462
|
-
queryClient.invalidateQueries({
|
|
867
|
+
queryClient.invalidateQueries({
|
|
868
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
869
|
+
});
|
|
463
870
|
}
|
|
464
871
|
});
|
|
465
872
|
}
|
|
466
873
|
|
|
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
874
|
// src/use-admin-auth.ts
|
|
517
|
-
import { useState, useEffect as
|
|
875
|
+
import { useState as useState3, useEffect as useEffect3, useCallback as useCallback2 } from "react";
|
|
518
876
|
function useAdminAuth(options = {}) {
|
|
519
877
|
const { autoCheck = true } = options;
|
|
520
878
|
const client = useFluxbaseClient();
|
|
521
|
-
const [user, setUser] =
|
|
522
|
-
const [isLoading, setIsLoading] =
|
|
523
|
-
const [error, setError] =
|
|
524
|
-
const checkAuth =
|
|
879
|
+
const [user, setUser] = useState3(null);
|
|
880
|
+
const [isLoading, setIsLoading] = useState3(autoCheck);
|
|
881
|
+
const [error, setError] = useState3(null);
|
|
882
|
+
const checkAuth = useCallback2(async () => {
|
|
525
883
|
try {
|
|
526
884
|
setIsLoading(true);
|
|
527
885
|
setError(null);
|
|
528
|
-
const {
|
|
529
|
-
|
|
886
|
+
const { data, error: apiError } = await client.admin.me();
|
|
887
|
+
if (apiError) {
|
|
888
|
+
throw apiError;
|
|
889
|
+
}
|
|
890
|
+
setUser(data.user);
|
|
530
891
|
} catch (err) {
|
|
531
892
|
setUser(null);
|
|
532
893
|
setError(err);
|
|
@@ -534,14 +895,20 @@ function useAdminAuth(options = {}) {
|
|
|
534
895
|
setIsLoading(false);
|
|
535
896
|
}
|
|
536
897
|
}, [client]);
|
|
537
|
-
const login =
|
|
898
|
+
const login = useCallback2(
|
|
538
899
|
async (email, password) => {
|
|
539
900
|
try {
|
|
540
901
|
setIsLoading(true);
|
|
541
902
|
setError(null);
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
903
|
+
const { data, error: apiError } = await client.admin.login({
|
|
904
|
+
email,
|
|
905
|
+
password
|
|
906
|
+
});
|
|
907
|
+
if (apiError) {
|
|
908
|
+
throw apiError;
|
|
909
|
+
}
|
|
910
|
+
setUser(data.user);
|
|
911
|
+
return data;
|
|
545
912
|
} catch (err) {
|
|
546
913
|
setError(err);
|
|
547
914
|
throw err;
|
|
@@ -551,7 +918,7 @@ function useAdminAuth(options = {}) {
|
|
|
551
918
|
},
|
|
552
919
|
[client]
|
|
553
920
|
);
|
|
554
|
-
const logout =
|
|
921
|
+
const logout = useCallback2(async () => {
|
|
555
922
|
try {
|
|
556
923
|
setIsLoading(true);
|
|
557
924
|
setError(null);
|
|
@@ -563,10 +930,10 @@ function useAdminAuth(options = {}) {
|
|
|
563
930
|
setIsLoading(false);
|
|
564
931
|
}
|
|
565
932
|
}, []);
|
|
566
|
-
const refresh =
|
|
933
|
+
const refresh = useCallback2(async () => {
|
|
567
934
|
await checkAuth();
|
|
568
935
|
}, [checkAuth]);
|
|
569
|
-
|
|
936
|
+
useEffect3(() => {
|
|
570
937
|
if (autoCheck) {
|
|
571
938
|
checkAuth();
|
|
572
939
|
}
|
|
@@ -583,60 +950,67 @@ function useAdminAuth(options = {}) {
|
|
|
583
950
|
}
|
|
584
951
|
|
|
585
952
|
// src/use-users.ts
|
|
586
|
-
import { useState as
|
|
953
|
+
import { useState as useState4, useEffect as useEffect4, useCallback as useCallback3 } from "react";
|
|
587
954
|
function useUsers(options = {}) {
|
|
588
955
|
const { autoFetch = true, refetchInterval = 0, ...listOptions } = options;
|
|
589
956
|
const client = useFluxbaseClient();
|
|
590
|
-
const [users, setUsers] =
|
|
591
|
-
const [total, setTotal] =
|
|
592
|
-
const [isLoading, setIsLoading] =
|
|
593
|
-
const [error, setError] =
|
|
594
|
-
const fetchUsers =
|
|
957
|
+
const [users, setUsers] = useState4([]);
|
|
958
|
+
const [total, setTotal] = useState4(0);
|
|
959
|
+
const [isLoading, setIsLoading] = useState4(autoFetch);
|
|
960
|
+
const [error, setError] = useState4(null);
|
|
961
|
+
const fetchUsers = useCallback3(async () => {
|
|
595
962
|
try {
|
|
596
963
|
setIsLoading(true);
|
|
597
964
|
setError(null);
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
965
|
+
const { data, error: apiError } = await client.admin.listUsers(listOptions);
|
|
966
|
+
if (apiError) {
|
|
967
|
+
throw apiError;
|
|
968
|
+
}
|
|
969
|
+
setUsers(data.users);
|
|
970
|
+
setTotal(data.total);
|
|
601
971
|
} catch (err) {
|
|
602
972
|
setError(err);
|
|
603
973
|
} finally {
|
|
604
974
|
setIsLoading(false);
|
|
605
975
|
}
|
|
606
976
|
}, [client, JSON.stringify(listOptions)]);
|
|
607
|
-
const inviteUser =
|
|
977
|
+
const inviteUser = useCallback3(
|
|
608
978
|
async (email, role) => {
|
|
609
979
|
await client.admin.inviteUser({ email, role });
|
|
610
980
|
await fetchUsers();
|
|
611
981
|
},
|
|
612
982
|
[client, fetchUsers]
|
|
613
983
|
);
|
|
614
|
-
const updateUserRole =
|
|
984
|
+
const updateUserRole = useCallback3(
|
|
615
985
|
async (userId, role) => {
|
|
616
986
|
await client.admin.updateUserRole(userId, role);
|
|
617
987
|
await fetchUsers();
|
|
618
988
|
},
|
|
619
989
|
[client, fetchUsers]
|
|
620
990
|
);
|
|
621
|
-
const deleteUser =
|
|
991
|
+
const deleteUser = useCallback3(
|
|
622
992
|
async (userId) => {
|
|
623
993
|
await client.admin.deleteUser(userId);
|
|
624
994
|
await fetchUsers();
|
|
625
995
|
},
|
|
626
996
|
[client, fetchUsers]
|
|
627
997
|
);
|
|
628
|
-
const resetPassword =
|
|
998
|
+
const resetPassword = useCallback3(
|
|
629
999
|
async (userId) => {
|
|
630
|
-
|
|
1000
|
+
const { data, error: error2 } = await client.admin.resetUserPassword(userId);
|
|
1001
|
+
if (error2) {
|
|
1002
|
+
throw error2;
|
|
1003
|
+
}
|
|
1004
|
+
return data;
|
|
631
1005
|
},
|
|
632
1006
|
[client]
|
|
633
1007
|
);
|
|
634
|
-
|
|
1008
|
+
useEffect4(() => {
|
|
635
1009
|
if (autoFetch) {
|
|
636
1010
|
fetchUsers();
|
|
637
1011
|
}
|
|
638
1012
|
}, [autoFetch, fetchUsers]);
|
|
639
|
-
|
|
1013
|
+
useEffect4(() => {
|
|
640
1014
|
if (refetchInterval > 0) {
|
|
641
1015
|
const interval = setInterval(fetchUsers, refetchInterval);
|
|
642
1016
|
return () => clearInterval(interval);
|
|
@@ -655,56 +1029,56 @@ function useUsers(options = {}) {
|
|
|
655
1029
|
};
|
|
656
1030
|
}
|
|
657
1031
|
|
|
658
|
-
// src/use-
|
|
659
|
-
import { useState as
|
|
660
|
-
function
|
|
1032
|
+
// src/use-client-keys.ts
|
|
1033
|
+
import { useState as useState5, useEffect as useEffect5, useCallback as useCallback4 } from "react";
|
|
1034
|
+
function useClientKeys(options = {}) {
|
|
661
1035
|
const { autoFetch = true } = options;
|
|
662
1036
|
const client = useFluxbaseClient();
|
|
663
|
-
const [keys, setKeys] =
|
|
664
|
-
const [isLoading, setIsLoading] =
|
|
665
|
-
const [error, setError] =
|
|
666
|
-
const fetchKeys =
|
|
1037
|
+
const [keys, setKeys] = useState5([]);
|
|
1038
|
+
const [isLoading, setIsLoading] = useState5(autoFetch);
|
|
1039
|
+
const [error, setError] = useState5(null);
|
|
1040
|
+
const fetchKeys = useCallback4(async () => {
|
|
667
1041
|
try {
|
|
668
1042
|
setIsLoading(true);
|
|
669
1043
|
setError(null);
|
|
670
|
-
const response = await client.admin.management.
|
|
671
|
-
setKeys(response.
|
|
1044
|
+
const response = await client.admin.management.clientKeys.list();
|
|
1045
|
+
setKeys(response.client_keys);
|
|
672
1046
|
} catch (err) {
|
|
673
1047
|
setError(err);
|
|
674
1048
|
} finally {
|
|
675
1049
|
setIsLoading(false);
|
|
676
1050
|
}
|
|
677
1051
|
}, [client]);
|
|
678
|
-
const createKey =
|
|
1052
|
+
const createKey = useCallback4(
|
|
679
1053
|
async (request) => {
|
|
680
|
-
const response = await client.admin.management.
|
|
1054
|
+
const response = await client.admin.management.clientKeys.create(request);
|
|
681
1055
|
await fetchKeys();
|
|
682
|
-
return { key: response.key, keyData: response.
|
|
1056
|
+
return { key: response.key, keyData: response.client_key };
|
|
683
1057
|
},
|
|
684
1058
|
[client, fetchKeys]
|
|
685
1059
|
);
|
|
686
|
-
const updateKey =
|
|
1060
|
+
const updateKey = useCallback4(
|
|
687
1061
|
async (keyId, update) => {
|
|
688
|
-
await client.admin.management.
|
|
1062
|
+
await client.admin.management.clientKeys.update(keyId, update);
|
|
689
1063
|
await fetchKeys();
|
|
690
1064
|
},
|
|
691
1065
|
[client, fetchKeys]
|
|
692
1066
|
);
|
|
693
|
-
const revokeKey =
|
|
1067
|
+
const revokeKey = useCallback4(
|
|
694
1068
|
async (keyId) => {
|
|
695
|
-
await client.admin.management.
|
|
1069
|
+
await client.admin.management.clientKeys.revoke(keyId);
|
|
696
1070
|
await fetchKeys();
|
|
697
1071
|
},
|
|
698
1072
|
[client, fetchKeys]
|
|
699
1073
|
);
|
|
700
|
-
const deleteKey =
|
|
1074
|
+
const deleteKey = useCallback4(
|
|
701
1075
|
async (keyId) => {
|
|
702
|
-
await client.admin.management.
|
|
1076
|
+
await client.admin.management.clientKeys.delete(keyId);
|
|
703
1077
|
await fetchKeys();
|
|
704
1078
|
},
|
|
705
1079
|
[client, fetchKeys]
|
|
706
1080
|
);
|
|
707
|
-
|
|
1081
|
+
useEffect5(() => {
|
|
708
1082
|
if (autoFetch) {
|
|
709
1083
|
fetchKeys();
|
|
710
1084
|
}
|
|
@@ -720,16 +1094,17 @@ function useAPIKeys(options = {}) {
|
|
|
720
1094
|
deleteKey
|
|
721
1095
|
};
|
|
722
1096
|
}
|
|
1097
|
+
var useAPIKeys = useClientKeys;
|
|
723
1098
|
|
|
724
1099
|
// src/use-admin-hooks.ts
|
|
725
|
-
import { useState as
|
|
1100
|
+
import { useState as useState6, useEffect as useEffect6, useCallback as useCallback5 } from "react";
|
|
726
1101
|
function useAppSettings(options = {}) {
|
|
727
1102
|
const { autoFetch = true } = options;
|
|
728
1103
|
const client = useFluxbaseClient();
|
|
729
|
-
const [settings, setSettings] =
|
|
730
|
-
const [isLoading, setIsLoading] =
|
|
731
|
-
const [error, setError] =
|
|
732
|
-
const fetchSettings =
|
|
1104
|
+
const [settings, setSettings] = useState6(null);
|
|
1105
|
+
const [isLoading, setIsLoading] = useState6(autoFetch);
|
|
1106
|
+
const [error, setError] = useState6(null);
|
|
1107
|
+
const fetchSettings = useCallback5(async () => {
|
|
733
1108
|
try {
|
|
734
1109
|
setIsLoading(true);
|
|
735
1110
|
setError(null);
|
|
@@ -741,14 +1116,14 @@ function useAppSettings(options = {}) {
|
|
|
741
1116
|
setIsLoading(false);
|
|
742
1117
|
}
|
|
743
1118
|
}, [client]);
|
|
744
|
-
const updateSettings =
|
|
1119
|
+
const updateSettings = useCallback5(
|
|
745
1120
|
async (update) => {
|
|
746
1121
|
await client.admin.settings.app.update(update);
|
|
747
1122
|
await fetchSettings();
|
|
748
1123
|
},
|
|
749
1124
|
[client, fetchSettings]
|
|
750
1125
|
);
|
|
751
|
-
|
|
1126
|
+
useEffect6(() => {
|
|
752
1127
|
if (autoFetch) {
|
|
753
1128
|
fetchSettings();
|
|
754
1129
|
}
|
|
@@ -764,10 +1139,10 @@ function useAppSettings(options = {}) {
|
|
|
764
1139
|
function useSystemSettings(options = {}) {
|
|
765
1140
|
const { autoFetch = true } = options;
|
|
766
1141
|
const client = useFluxbaseClient();
|
|
767
|
-
const [settings, setSettings] =
|
|
768
|
-
const [isLoading, setIsLoading] =
|
|
769
|
-
const [error, setError] =
|
|
770
|
-
const fetchSettings =
|
|
1142
|
+
const [settings, setSettings] = useState6([]);
|
|
1143
|
+
const [isLoading, setIsLoading] = useState6(autoFetch);
|
|
1144
|
+
const [error, setError] = useState6(null);
|
|
1145
|
+
const fetchSettings = useCallback5(async () => {
|
|
771
1146
|
try {
|
|
772
1147
|
setIsLoading(true);
|
|
773
1148
|
setError(null);
|
|
@@ -779,27 +1154,27 @@ function useSystemSettings(options = {}) {
|
|
|
779
1154
|
setIsLoading(false);
|
|
780
1155
|
}
|
|
781
1156
|
}, [client]);
|
|
782
|
-
const getSetting =
|
|
1157
|
+
const getSetting = useCallback5(
|
|
783
1158
|
(key) => {
|
|
784
1159
|
return settings.find((s) => s.key === key);
|
|
785
1160
|
},
|
|
786
1161
|
[settings]
|
|
787
1162
|
);
|
|
788
|
-
const updateSetting =
|
|
1163
|
+
const updateSetting = useCallback5(
|
|
789
1164
|
async (key, update) => {
|
|
790
1165
|
await client.admin.settings.system.update(key, update);
|
|
791
1166
|
await fetchSettings();
|
|
792
1167
|
},
|
|
793
1168
|
[client, fetchSettings]
|
|
794
1169
|
);
|
|
795
|
-
const deleteSetting =
|
|
1170
|
+
const deleteSetting = useCallback5(
|
|
796
1171
|
async (key) => {
|
|
797
1172
|
await client.admin.settings.system.delete(key);
|
|
798
1173
|
await fetchSettings();
|
|
799
1174
|
},
|
|
800
1175
|
[client, fetchSettings]
|
|
801
1176
|
);
|
|
802
|
-
|
|
1177
|
+
useEffect6(() => {
|
|
803
1178
|
if (autoFetch) {
|
|
804
1179
|
fetchSettings();
|
|
805
1180
|
}
|
|
@@ -817,10 +1192,10 @@ function useSystemSettings(options = {}) {
|
|
|
817
1192
|
function useWebhooks(options = {}) {
|
|
818
1193
|
const { autoFetch = true, refetchInterval = 0 } = options;
|
|
819
1194
|
const client = useFluxbaseClient();
|
|
820
|
-
const [webhooks, setWebhooks] =
|
|
821
|
-
const [isLoading, setIsLoading] =
|
|
822
|
-
const [error, setError] =
|
|
823
|
-
const fetchWebhooks =
|
|
1195
|
+
const [webhooks, setWebhooks] = useState6([]);
|
|
1196
|
+
const [isLoading, setIsLoading] = useState6(autoFetch);
|
|
1197
|
+
const [error, setError] = useState6(null);
|
|
1198
|
+
const fetchWebhooks = useCallback5(async () => {
|
|
824
1199
|
try {
|
|
825
1200
|
setIsLoading(true);
|
|
826
1201
|
setError(null);
|
|
@@ -832,7 +1207,7 @@ function useWebhooks(options = {}) {
|
|
|
832
1207
|
setIsLoading(false);
|
|
833
1208
|
}
|
|
834
1209
|
}, [client]);
|
|
835
|
-
const createWebhook =
|
|
1210
|
+
const createWebhook = useCallback5(
|
|
836
1211
|
async (webhook) => {
|
|
837
1212
|
const created = await client.admin.management.webhooks.create(webhook);
|
|
838
1213
|
await fetchWebhooks();
|
|
@@ -840,7 +1215,7 @@ function useWebhooks(options = {}) {
|
|
|
840
1215
|
},
|
|
841
1216
|
[client, fetchWebhooks]
|
|
842
1217
|
);
|
|
843
|
-
const updateWebhook =
|
|
1218
|
+
const updateWebhook = useCallback5(
|
|
844
1219
|
async (id, update) => {
|
|
845
1220
|
const updated = await client.admin.management.webhooks.update(id, update);
|
|
846
1221
|
await fetchWebhooks();
|
|
@@ -848,20 +1223,20 @@ function useWebhooks(options = {}) {
|
|
|
848
1223
|
},
|
|
849
1224
|
[client, fetchWebhooks]
|
|
850
1225
|
);
|
|
851
|
-
const deleteWebhook =
|
|
1226
|
+
const deleteWebhook = useCallback5(
|
|
852
1227
|
async (id) => {
|
|
853
1228
|
await client.admin.management.webhooks.delete(id);
|
|
854
1229
|
await fetchWebhooks();
|
|
855
1230
|
},
|
|
856
1231
|
[client, fetchWebhooks]
|
|
857
1232
|
);
|
|
858
|
-
const testWebhook =
|
|
1233
|
+
const testWebhook = useCallback5(
|
|
859
1234
|
async (id) => {
|
|
860
1235
|
await client.admin.management.webhooks.test(id);
|
|
861
1236
|
},
|
|
862
1237
|
[client]
|
|
863
1238
|
);
|
|
864
|
-
|
|
1239
|
+
useEffect6(() => {
|
|
865
1240
|
if (autoFetch) {
|
|
866
1241
|
fetchWebhooks();
|
|
867
1242
|
}
|
|
@@ -883,22 +1258,33 @@ function useWebhooks(options = {}) {
|
|
|
883
1258
|
}
|
|
884
1259
|
export {
|
|
885
1260
|
FluxbaseProvider,
|
|
1261
|
+
isCaptchaRequiredForEndpoint,
|
|
886
1262
|
useAPIKeys,
|
|
887
1263
|
useAdminAuth,
|
|
888
1264
|
useAppSettings,
|
|
889
1265
|
useAuth,
|
|
1266
|
+
useAuthConfig,
|
|
1267
|
+
useCaptcha,
|
|
1268
|
+
useCaptchaConfig,
|
|
1269
|
+
useClientKeys,
|
|
890
1270
|
useCreateBucket,
|
|
891
1271
|
useDelete,
|
|
892
1272
|
useDeleteBucket,
|
|
893
1273
|
useFluxbaseClient,
|
|
894
1274
|
useFluxbaseQuery,
|
|
1275
|
+
useGetSAMLLoginUrl,
|
|
1276
|
+
useGraphQL,
|
|
1277
|
+
useGraphQLIntrospection,
|
|
1278
|
+
useGraphQLMutation,
|
|
1279
|
+
useGraphQLQuery,
|
|
1280
|
+
useHandleSAMLCallback,
|
|
895
1281
|
useInsert,
|
|
896
|
-
useRPC,
|
|
897
|
-
useRPCBatch,
|
|
898
|
-
useRPCMutation,
|
|
899
1282
|
useRealtime,
|
|
1283
|
+
useSAMLMetadataUrl,
|
|
1284
|
+
useSAMLProviders,
|
|
900
1285
|
useSession,
|
|
901
1286
|
useSignIn,
|
|
1287
|
+
useSignInWithSAML,
|
|
902
1288
|
useSignOut,
|
|
903
1289
|
useSignUp,
|
|
904
1290
|
useStorageBuckets,
|
|
@@ -909,7 +1295,10 @@ export {
|
|
|
909
1295
|
useStorageMove,
|
|
910
1296
|
useStoragePublicUrl,
|
|
911
1297
|
useStorageSignedUrl,
|
|
1298
|
+
useStorageSignedUrlWithOptions,
|
|
1299
|
+
useStorageTransformUrl,
|
|
912
1300
|
useStorageUpload,
|
|
1301
|
+
useStorageUploadWithProgress,
|
|
913
1302
|
useSystemSettings,
|
|
914
1303
|
useTable,
|
|
915
1304
|
useTableDeletes,
|