@fluxbase/sdk-react 0.0.7-rc.11 → 2026.1.1-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-ADMIN.md +8 -8
- package/README.md +27 -14
- package/dist/index.d.mts +638 -83
- package/dist/index.d.ts +638 -83
- package/dist/index.js +552 -175
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +540 -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 +57 -18
- package/src/use-admin-auth.ts +62 -51
- 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,283 @@ 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-saml.ts
|
|
231
|
+
import { useMutation as useMutation2, useQuery as useQuery3, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
232
|
+
function useSAMLProviders() {
|
|
233
|
+
const client = useFluxbaseClient();
|
|
234
|
+
return useQuery3({
|
|
235
|
+
queryKey: ["fluxbase", "auth", "saml", "providers"],
|
|
236
|
+
queryFn: async () => {
|
|
237
|
+
const { data, error } = await client.auth.getSAMLProviders();
|
|
238
|
+
if (error) throw error;
|
|
239
|
+
return data.providers;
|
|
240
|
+
},
|
|
241
|
+
staleTime: 1e3 * 60 * 5
|
|
242
|
+
// 5 minutes - providers don't change often
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
function useGetSAMLLoginUrl() {
|
|
246
|
+
const client = useFluxbaseClient();
|
|
247
|
+
return useMutation2({
|
|
248
|
+
mutationFn: async ({
|
|
249
|
+
provider,
|
|
250
|
+
options
|
|
251
|
+
}) => {
|
|
252
|
+
return await client.auth.getSAMLLoginUrl(provider, options);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
function useSignInWithSAML() {
|
|
257
|
+
const client = useFluxbaseClient();
|
|
258
|
+
return useMutation2({
|
|
259
|
+
mutationFn: async ({
|
|
260
|
+
provider,
|
|
261
|
+
options
|
|
262
|
+
}) => {
|
|
263
|
+
return await client.auth.signInWithSAML(provider, options);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function useHandleSAMLCallback() {
|
|
268
|
+
const client = useFluxbaseClient();
|
|
269
|
+
const queryClient = useQueryClient2();
|
|
270
|
+
return useMutation2({
|
|
271
|
+
mutationFn: async ({
|
|
272
|
+
samlResponse,
|
|
273
|
+
provider
|
|
274
|
+
}) => {
|
|
275
|
+
return await client.auth.handleSAMLCallback(samlResponse, provider);
|
|
276
|
+
},
|
|
277
|
+
onSuccess: (result) => {
|
|
278
|
+
if (result.data) {
|
|
279
|
+
queryClient.setQueryData(
|
|
280
|
+
["fluxbase", "auth", "session"],
|
|
281
|
+
result.data.session
|
|
282
|
+
);
|
|
283
|
+
queryClient.setQueryData(
|
|
284
|
+
["fluxbase", "auth", "user"],
|
|
285
|
+
result.data.user
|
|
286
|
+
);
|
|
287
|
+
queryClient.invalidateQueries({ queryKey: ["fluxbase"] });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
function useSAMLMetadataUrl() {
|
|
293
|
+
const client = useFluxbaseClient();
|
|
294
|
+
return (provider) => {
|
|
295
|
+
return client.auth.getSAMLMetadataUrl(provider);
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/use-graphql.ts
|
|
300
|
+
import { useMutation as useMutation3, useQuery as useQuery4, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
|
|
301
|
+
function useGraphQLQuery(queryKey, query, options) {
|
|
302
|
+
const client = useFluxbaseClient();
|
|
303
|
+
const normalizedKey = Array.isArray(queryKey) ? ["fluxbase", "graphql", ...queryKey] : ["fluxbase", "graphql", queryKey];
|
|
304
|
+
return useQuery4({
|
|
305
|
+
queryKey: normalizedKey,
|
|
306
|
+
queryFn: async () => {
|
|
307
|
+
const response = await client.graphql.execute(
|
|
308
|
+
query,
|
|
309
|
+
options?.variables,
|
|
310
|
+
options?.operationName,
|
|
311
|
+
options?.requestOptions
|
|
312
|
+
);
|
|
313
|
+
if (response.errors && response.errors.length > 0) {
|
|
314
|
+
throw response.errors[0];
|
|
315
|
+
}
|
|
316
|
+
return response.data;
|
|
317
|
+
},
|
|
318
|
+
enabled: options?.enabled ?? true,
|
|
319
|
+
staleTime: options?.staleTime ?? 0,
|
|
320
|
+
gcTime: options?.gcTime,
|
|
321
|
+
refetchOnWindowFocus: options?.refetchOnWindowFocus ?? true,
|
|
322
|
+
select: options?.select
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function useGraphQLMutation(mutation, options) {
|
|
326
|
+
const client = useFluxbaseClient();
|
|
327
|
+
const queryClient = useQueryClient3();
|
|
328
|
+
return useMutation3({
|
|
329
|
+
mutationFn: async (variables) => {
|
|
330
|
+
const response = await client.graphql.execute(
|
|
331
|
+
mutation,
|
|
332
|
+
variables,
|
|
333
|
+
options?.operationName,
|
|
334
|
+
options?.requestOptions
|
|
335
|
+
);
|
|
336
|
+
if (response.errors && response.errors.length > 0) {
|
|
337
|
+
throw response.errors[0];
|
|
338
|
+
}
|
|
339
|
+
return response.data;
|
|
340
|
+
},
|
|
341
|
+
onSuccess: (data, variables) => {
|
|
342
|
+
if (options?.invalidateQueries) {
|
|
343
|
+
for (const key of options.invalidateQueries) {
|
|
344
|
+
queryClient.invalidateQueries({
|
|
345
|
+
queryKey: ["fluxbase", "graphql", key]
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (options?.onSuccess && data !== void 0) {
|
|
350
|
+
options.onSuccess(data, variables);
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
onError: (error, variables) => {
|
|
354
|
+
if (options?.onError) {
|
|
355
|
+
options.onError(error, variables);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function useGraphQLIntrospection(options) {
|
|
361
|
+
const client = useFluxbaseClient();
|
|
362
|
+
return useQuery4({
|
|
363
|
+
queryKey: ["fluxbase", "graphql", "__introspection"],
|
|
364
|
+
queryFn: async () => {
|
|
365
|
+
const response = await client.graphql.introspect(options?.requestOptions);
|
|
366
|
+
if (response.errors && response.errors.length > 0) {
|
|
367
|
+
throw response.errors[0];
|
|
368
|
+
}
|
|
369
|
+
return response.data;
|
|
370
|
+
},
|
|
371
|
+
enabled: options?.enabled ?? true,
|
|
372
|
+
staleTime: options?.staleTime ?? 1e3 * 60 * 5
|
|
373
|
+
// 5 minutes - schema doesn't change often
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
function useGraphQL() {
|
|
377
|
+
const client = useFluxbaseClient();
|
|
378
|
+
return {
|
|
379
|
+
/**
|
|
380
|
+
* Execute a GraphQL query
|
|
381
|
+
*/
|
|
382
|
+
executeQuery: (query, variables, options) => {
|
|
383
|
+
return client.graphql.query(query, variables, options);
|
|
384
|
+
},
|
|
385
|
+
/**
|
|
386
|
+
* Execute a GraphQL mutation
|
|
387
|
+
*/
|
|
388
|
+
executeMutation: (mutation, variables, options) => {
|
|
389
|
+
return client.graphql.mutation(mutation, variables, options);
|
|
390
|
+
},
|
|
391
|
+
/**
|
|
392
|
+
* Execute a GraphQL operation with an explicit operation name
|
|
393
|
+
*/
|
|
394
|
+
execute: (document, variables, operationName, options) => {
|
|
395
|
+
return client.graphql.execute(document, variables, operationName, options);
|
|
396
|
+
},
|
|
397
|
+
/**
|
|
398
|
+
* Fetch the GraphQL schema via introspection
|
|
399
|
+
*/
|
|
400
|
+
introspect: (options) => {
|
|
401
|
+
return client.graphql.introspect(options);
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
|
|
123
406
|
// src/use-query.ts
|
|
124
|
-
import { useQuery as
|
|
407
|
+
import { useQuery as useQuery5, useMutation as useMutation4, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
|
|
125
408
|
function useFluxbaseQuery(buildQuery, options) {
|
|
126
409
|
const client = useFluxbaseClient();
|
|
127
410
|
const queryKey = options?.queryKey || ["fluxbase", "query", buildQuery.toString()];
|
|
128
|
-
return
|
|
411
|
+
return useQuery5({
|
|
129
412
|
queryKey,
|
|
130
413
|
queryFn: async () => {
|
|
131
414
|
const query = buildQuery(client);
|
|
@@ -153,8 +436,8 @@ function useTable(table, buildQuery, options) {
|
|
|
153
436
|
}
|
|
154
437
|
function useInsert(table) {
|
|
155
438
|
const client = useFluxbaseClient();
|
|
156
|
-
const queryClient =
|
|
157
|
-
return
|
|
439
|
+
const queryClient = useQueryClient4();
|
|
440
|
+
return useMutation4({
|
|
158
441
|
mutationFn: async (data) => {
|
|
159
442
|
const query = client.from(table);
|
|
160
443
|
const { data: result, error } = await query.insert(data);
|
|
@@ -170,8 +453,8 @@ function useInsert(table) {
|
|
|
170
453
|
}
|
|
171
454
|
function useUpdate(table) {
|
|
172
455
|
const client = useFluxbaseClient();
|
|
173
|
-
const queryClient =
|
|
174
|
-
return
|
|
456
|
+
const queryClient = useQueryClient4();
|
|
457
|
+
return useMutation4({
|
|
175
458
|
mutationFn: async (params) => {
|
|
176
459
|
const query = client.from(table);
|
|
177
460
|
const builtQuery = params.buildQuery(query);
|
|
@@ -188,8 +471,8 @@ function useUpdate(table) {
|
|
|
188
471
|
}
|
|
189
472
|
function useUpsert(table) {
|
|
190
473
|
const client = useFluxbaseClient();
|
|
191
|
-
const queryClient =
|
|
192
|
-
return
|
|
474
|
+
const queryClient = useQueryClient4();
|
|
475
|
+
return useMutation4({
|
|
193
476
|
mutationFn: async (data) => {
|
|
194
477
|
const query = client.from(table);
|
|
195
478
|
const { data: result, error } = await query.upsert(data);
|
|
@@ -205,8 +488,8 @@ function useUpsert(table) {
|
|
|
205
488
|
}
|
|
206
489
|
function useDelete(table) {
|
|
207
490
|
const client = useFluxbaseClient();
|
|
208
|
-
const queryClient =
|
|
209
|
-
return
|
|
491
|
+
const queryClient = useQueryClient4();
|
|
492
|
+
return useMutation4({
|
|
210
493
|
mutationFn: async (buildQuery) => {
|
|
211
494
|
const query = client.from(table);
|
|
212
495
|
const builtQuery = buildQuery(query);
|
|
@@ -222,12 +505,14 @@ function useDelete(table) {
|
|
|
222
505
|
}
|
|
223
506
|
|
|
224
507
|
// src/use-realtime.ts
|
|
225
|
-
import { useEffect, useRef } from "react";
|
|
226
|
-
import { useQueryClient as
|
|
508
|
+
import { useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
509
|
+
import { useQueryClient as useQueryClient5 } from "@tanstack/react-query";
|
|
227
510
|
function useRealtime(options) {
|
|
228
511
|
const client = useFluxbaseClient();
|
|
229
|
-
const queryClient =
|
|
230
|
-
const channelRef =
|
|
512
|
+
const queryClient = useQueryClient5();
|
|
513
|
+
const channelRef = useRef2(
|
|
514
|
+
null
|
|
515
|
+
);
|
|
231
516
|
const {
|
|
232
517
|
channel: channelName,
|
|
233
518
|
event = "*",
|
|
@@ -236,7 +521,7 @@ function useRealtime(options) {
|
|
|
236
521
|
invalidateKey,
|
|
237
522
|
enabled = true
|
|
238
523
|
} = options;
|
|
239
|
-
|
|
524
|
+
useEffect2(() => {
|
|
240
525
|
if (!enabled) {
|
|
241
526
|
return;
|
|
242
527
|
}
|
|
@@ -257,7 +542,16 @@ function useRealtime(options) {
|
|
|
257
542
|
channel.unsubscribe();
|
|
258
543
|
channelRef.current = null;
|
|
259
544
|
};
|
|
260
|
-
}, [
|
|
545
|
+
}, [
|
|
546
|
+
client,
|
|
547
|
+
channelName,
|
|
548
|
+
event,
|
|
549
|
+
callback,
|
|
550
|
+
autoInvalidate,
|
|
551
|
+
invalidateKey,
|
|
552
|
+
queryClient,
|
|
553
|
+
enabled
|
|
554
|
+
]);
|
|
261
555
|
return {
|
|
262
556
|
channel: channelRef.current
|
|
263
557
|
};
|
|
@@ -294,12 +588,23 @@ function useTableDeletes(table, callback, options) {
|
|
|
294
588
|
}
|
|
295
589
|
|
|
296
590
|
// src/use-storage.ts
|
|
297
|
-
import {
|
|
591
|
+
import { useState as useState2 } from "react";
|
|
592
|
+
import {
|
|
593
|
+
useMutation as useMutation5,
|
|
594
|
+
useQuery as useQuery6,
|
|
595
|
+
useQueryClient as useQueryClient6
|
|
596
|
+
} from "@tanstack/react-query";
|
|
298
597
|
function useStorageList(bucket, options) {
|
|
299
598
|
const client = useFluxbaseClient();
|
|
300
599
|
const { prefix, limit, offset, ...queryOptions } = options || {};
|
|
301
|
-
return
|
|
302
|
-
queryKey: [
|
|
600
|
+
return useQuery6({
|
|
601
|
+
queryKey: [
|
|
602
|
+
"fluxbase",
|
|
603
|
+
"storage",
|
|
604
|
+
bucket,
|
|
605
|
+
"list",
|
|
606
|
+
{ prefix, limit, offset }
|
|
607
|
+
],
|
|
303
608
|
queryFn: async () => {
|
|
304
609
|
const { data, error } = await client.storage.from(bucket).list({ prefix, limit, offset });
|
|
305
610
|
if (error) {
|
|
@@ -312,8 +617,8 @@ function useStorageList(bucket, options) {
|
|
|
312
617
|
}
|
|
313
618
|
function useStorageUpload(bucket) {
|
|
314
619
|
const client = useFluxbaseClient();
|
|
315
|
-
const queryClient =
|
|
316
|
-
return
|
|
620
|
+
const queryClient = useQueryClient6();
|
|
621
|
+
return useMutation5({
|
|
317
622
|
mutationFn: async (params) => {
|
|
318
623
|
const { path, file, options } = params;
|
|
319
624
|
const { data, error } = await client.storage.from(bucket).upload(path, file, options);
|
|
@@ -323,13 +628,49 @@ function useStorageUpload(bucket) {
|
|
|
323
628
|
return data;
|
|
324
629
|
},
|
|
325
630
|
onSuccess: () => {
|
|
326
|
-
queryClient.invalidateQueries({
|
|
631
|
+
queryClient.invalidateQueries({
|
|
632
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
633
|
+
});
|
|
327
634
|
}
|
|
328
635
|
});
|
|
329
636
|
}
|
|
637
|
+
function useStorageUploadWithProgress(bucket) {
|
|
638
|
+
const client = useFluxbaseClient();
|
|
639
|
+
const queryClient = useQueryClient6();
|
|
640
|
+
const [progress, setProgress] = useState2(null);
|
|
641
|
+
const mutation = useMutation5({
|
|
642
|
+
mutationFn: async (params) => {
|
|
643
|
+
const { path, file, options } = params;
|
|
644
|
+
setProgress({ loaded: 0, total: 0, percentage: 0 });
|
|
645
|
+
const { data, error } = await client.storage.from(bucket).upload(path, file, {
|
|
646
|
+
...options,
|
|
647
|
+
onUploadProgress: (p) => {
|
|
648
|
+
setProgress(p);
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
if (error) {
|
|
652
|
+
throw error;
|
|
653
|
+
}
|
|
654
|
+
return data;
|
|
655
|
+
},
|
|
656
|
+
onSuccess: () => {
|
|
657
|
+
queryClient.invalidateQueries({
|
|
658
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
659
|
+
});
|
|
660
|
+
},
|
|
661
|
+
onError: () => {
|
|
662
|
+
setProgress(null);
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
return {
|
|
666
|
+
upload: mutation,
|
|
667
|
+
progress,
|
|
668
|
+
reset: () => setProgress(null)
|
|
669
|
+
};
|
|
670
|
+
}
|
|
330
671
|
function useStorageDownload(bucket, path, enabled = true) {
|
|
331
672
|
const client = useFluxbaseClient();
|
|
332
|
-
return
|
|
673
|
+
return useQuery6({
|
|
333
674
|
queryKey: ["fluxbase", "storage", bucket, "download", path],
|
|
334
675
|
queryFn: async () => {
|
|
335
676
|
if (!path) {
|
|
@@ -346,8 +687,8 @@ function useStorageDownload(bucket, path, enabled = true) {
|
|
|
346
687
|
}
|
|
347
688
|
function useStorageDelete(bucket) {
|
|
348
689
|
const client = useFluxbaseClient();
|
|
349
|
-
const queryClient =
|
|
350
|
-
return
|
|
690
|
+
const queryClient = useQueryClient6();
|
|
691
|
+
return useMutation5({
|
|
351
692
|
mutationFn: async (paths) => {
|
|
352
693
|
const { error } = await client.storage.from(bucket).remove(paths);
|
|
353
694
|
if (error) {
|
|
@@ -355,7 +696,9 @@ function useStorageDelete(bucket) {
|
|
|
355
696
|
}
|
|
356
697
|
},
|
|
357
698
|
onSuccess: () => {
|
|
358
|
-
queryClient.invalidateQueries({
|
|
699
|
+
queryClient.invalidateQueries({
|
|
700
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
701
|
+
});
|
|
359
702
|
}
|
|
360
703
|
});
|
|
361
704
|
}
|
|
@@ -367,9 +710,16 @@ function useStoragePublicUrl(bucket, path) {
|
|
|
367
710
|
const { data } = client.storage.from(bucket).getPublicUrl(path);
|
|
368
711
|
return data.publicUrl;
|
|
369
712
|
}
|
|
713
|
+
function useStorageTransformUrl(bucket, path, transform) {
|
|
714
|
+
const client = useFluxbaseClient();
|
|
715
|
+
if (!path) {
|
|
716
|
+
return null;
|
|
717
|
+
}
|
|
718
|
+
return client.storage.from(bucket).getTransformUrl(path, transform);
|
|
719
|
+
}
|
|
370
720
|
function useStorageSignedUrl(bucket, path, expiresIn) {
|
|
371
721
|
const client = useFluxbaseClient();
|
|
372
|
-
return
|
|
722
|
+
return useQuery6({
|
|
373
723
|
queryKey: ["fluxbase", "storage", bucket, "signed-url", path, expiresIn],
|
|
374
724
|
queryFn: async () => {
|
|
375
725
|
if (!path) {
|
|
@@ -386,10 +736,39 @@ function useStorageSignedUrl(bucket, path, expiresIn) {
|
|
|
386
736
|
// Refresh 1 minute before expiry
|
|
387
737
|
});
|
|
388
738
|
}
|
|
739
|
+
function useStorageSignedUrlWithOptions(bucket, path, options) {
|
|
740
|
+
const client = useFluxbaseClient();
|
|
741
|
+
const expiresIn = options?.expiresIn;
|
|
742
|
+
const transformKey = options?.transform ? JSON.stringify(options.transform) : null;
|
|
743
|
+
return useQuery6({
|
|
744
|
+
queryKey: [
|
|
745
|
+
"fluxbase",
|
|
746
|
+
"storage",
|
|
747
|
+
bucket,
|
|
748
|
+
"signed-url",
|
|
749
|
+
path,
|
|
750
|
+
expiresIn,
|
|
751
|
+
transformKey
|
|
752
|
+
],
|
|
753
|
+
queryFn: async () => {
|
|
754
|
+
if (!path) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
const { data, error } = await client.storage.from(bucket).createSignedUrl(path, options);
|
|
758
|
+
if (error) {
|
|
759
|
+
throw error;
|
|
760
|
+
}
|
|
761
|
+
return data?.signedUrl || null;
|
|
762
|
+
},
|
|
763
|
+
enabled: !!path,
|
|
764
|
+
staleTime: expiresIn ? expiresIn * 1e3 - 6e4 : 1e3 * 60 * 50
|
|
765
|
+
// Refresh 1 minute before expiry
|
|
766
|
+
});
|
|
767
|
+
}
|
|
389
768
|
function useStorageMove(bucket) {
|
|
390
769
|
const client = useFluxbaseClient();
|
|
391
|
-
const queryClient =
|
|
392
|
-
return
|
|
770
|
+
const queryClient = useQueryClient6();
|
|
771
|
+
return useMutation5({
|
|
393
772
|
mutationFn: async (params) => {
|
|
394
773
|
const { fromPath, toPath } = params;
|
|
395
774
|
const { data, error } = await client.storage.from(bucket).move(fromPath, toPath);
|
|
@@ -399,14 +778,16 @@ function useStorageMove(bucket) {
|
|
|
399
778
|
return data;
|
|
400
779
|
},
|
|
401
780
|
onSuccess: () => {
|
|
402
|
-
queryClient.invalidateQueries({
|
|
781
|
+
queryClient.invalidateQueries({
|
|
782
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
783
|
+
});
|
|
403
784
|
}
|
|
404
785
|
});
|
|
405
786
|
}
|
|
406
787
|
function useStorageCopy(bucket) {
|
|
407
788
|
const client = useFluxbaseClient();
|
|
408
|
-
const queryClient =
|
|
409
|
-
return
|
|
789
|
+
const queryClient = useQueryClient6();
|
|
790
|
+
return useMutation5({
|
|
410
791
|
mutationFn: async (params) => {
|
|
411
792
|
const { fromPath, toPath } = params;
|
|
412
793
|
const { data, error } = await client.storage.from(bucket).copy(fromPath, toPath);
|
|
@@ -416,13 +797,15 @@ function useStorageCopy(bucket) {
|
|
|
416
797
|
return data;
|
|
417
798
|
},
|
|
418
799
|
onSuccess: () => {
|
|
419
|
-
queryClient.invalidateQueries({
|
|
800
|
+
queryClient.invalidateQueries({
|
|
801
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
802
|
+
});
|
|
420
803
|
}
|
|
421
804
|
});
|
|
422
805
|
}
|
|
423
806
|
function useStorageBuckets() {
|
|
424
807
|
const client = useFluxbaseClient();
|
|
425
|
-
return
|
|
808
|
+
return useQuery6({
|
|
426
809
|
queryKey: ["fluxbase", "storage", "buckets"],
|
|
427
810
|
queryFn: async () => {
|
|
428
811
|
const { data, error } = await client.storage.listBuckets();
|
|
@@ -435,8 +818,8 @@ function useStorageBuckets() {
|
|
|
435
818
|
}
|
|
436
819
|
function useCreateBucket() {
|
|
437
820
|
const client = useFluxbaseClient();
|
|
438
|
-
const queryClient =
|
|
439
|
-
return
|
|
821
|
+
const queryClient = useQueryClient6();
|
|
822
|
+
return useMutation5({
|
|
440
823
|
mutationFn: async (bucketName) => {
|
|
441
824
|
const { error } = await client.storage.createBucket(bucketName);
|
|
442
825
|
if (error) {
|
|
@@ -444,14 +827,16 @@ function useCreateBucket() {
|
|
|
444
827
|
}
|
|
445
828
|
},
|
|
446
829
|
onSuccess: () => {
|
|
447
|
-
queryClient.invalidateQueries({
|
|
830
|
+
queryClient.invalidateQueries({
|
|
831
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
832
|
+
});
|
|
448
833
|
}
|
|
449
834
|
});
|
|
450
835
|
}
|
|
451
836
|
function useDeleteBucket() {
|
|
452
837
|
const client = useFluxbaseClient();
|
|
453
|
-
const queryClient =
|
|
454
|
-
return
|
|
838
|
+
const queryClient = useQueryClient6();
|
|
839
|
+
return useMutation5({
|
|
455
840
|
mutationFn: async (bucketName) => {
|
|
456
841
|
const { error } = await client.storage.deleteBucket(bucketName);
|
|
457
842
|
if (error) {
|
|
@@ -459,74 +844,30 @@ function useDeleteBucket() {
|
|
|
459
844
|
}
|
|
460
845
|
},
|
|
461
846
|
onSuccess: () => {
|
|
462
|
-
queryClient.invalidateQueries({
|
|
847
|
+
queryClient.invalidateQueries({
|
|
848
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
849
|
+
});
|
|
463
850
|
}
|
|
464
851
|
});
|
|
465
852
|
}
|
|
466
853
|
|
|
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
854
|
// src/use-admin-auth.ts
|
|
517
|
-
import { useState, useEffect as
|
|
855
|
+
import { useState as useState3, useEffect as useEffect3, useCallback as useCallback2 } from "react";
|
|
518
856
|
function useAdminAuth(options = {}) {
|
|
519
857
|
const { autoCheck = true } = options;
|
|
520
858
|
const client = useFluxbaseClient();
|
|
521
|
-
const [user, setUser] =
|
|
522
|
-
const [isLoading, setIsLoading] =
|
|
523
|
-
const [error, setError] =
|
|
524
|
-
const checkAuth =
|
|
859
|
+
const [user, setUser] = useState3(null);
|
|
860
|
+
const [isLoading, setIsLoading] = useState3(autoCheck);
|
|
861
|
+
const [error, setError] = useState3(null);
|
|
862
|
+
const checkAuth = useCallback2(async () => {
|
|
525
863
|
try {
|
|
526
864
|
setIsLoading(true);
|
|
527
865
|
setError(null);
|
|
528
|
-
const {
|
|
529
|
-
|
|
866
|
+
const { data, error: apiError } = await client.admin.me();
|
|
867
|
+
if (apiError) {
|
|
868
|
+
throw apiError;
|
|
869
|
+
}
|
|
870
|
+
setUser(data.user);
|
|
530
871
|
} catch (err) {
|
|
531
872
|
setUser(null);
|
|
532
873
|
setError(err);
|
|
@@ -534,14 +875,20 @@ function useAdminAuth(options = {}) {
|
|
|
534
875
|
setIsLoading(false);
|
|
535
876
|
}
|
|
536
877
|
}, [client]);
|
|
537
|
-
const login =
|
|
878
|
+
const login = useCallback2(
|
|
538
879
|
async (email, password) => {
|
|
539
880
|
try {
|
|
540
881
|
setIsLoading(true);
|
|
541
882
|
setError(null);
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
883
|
+
const { data, error: apiError } = await client.admin.login({
|
|
884
|
+
email,
|
|
885
|
+
password
|
|
886
|
+
});
|
|
887
|
+
if (apiError) {
|
|
888
|
+
throw apiError;
|
|
889
|
+
}
|
|
890
|
+
setUser(data.user);
|
|
891
|
+
return data;
|
|
545
892
|
} catch (err) {
|
|
546
893
|
setError(err);
|
|
547
894
|
throw err;
|
|
@@ -551,7 +898,7 @@ function useAdminAuth(options = {}) {
|
|
|
551
898
|
},
|
|
552
899
|
[client]
|
|
553
900
|
);
|
|
554
|
-
const logout =
|
|
901
|
+
const logout = useCallback2(async () => {
|
|
555
902
|
try {
|
|
556
903
|
setIsLoading(true);
|
|
557
904
|
setError(null);
|
|
@@ -563,10 +910,10 @@ function useAdminAuth(options = {}) {
|
|
|
563
910
|
setIsLoading(false);
|
|
564
911
|
}
|
|
565
912
|
}, []);
|
|
566
|
-
const refresh =
|
|
913
|
+
const refresh = useCallback2(async () => {
|
|
567
914
|
await checkAuth();
|
|
568
915
|
}, [checkAuth]);
|
|
569
|
-
|
|
916
|
+
useEffect3(() => {
|
|
570
917
|
if (autoCheck) {
|
|
571
918
|
checkAuth();
|
|
572
919
|
}
|
|
@@ -583,60 +930,67 @@ function useAdminAuth(options = {}) {
|
|
|
583
930
|
}
|
|
584
931
|
|
|
585
932
|
// src/use-users.ts
|
|
586
|
-
import { useState as
|
|
933
|
+
import { useState as useState4, useEffect as useEffect4, useCallback as useCallback3 } from "react";
|
|
587
934
|
function useUsers(options = {}) {
|
|
588
935
|
const { autoFetch = true, refetchInterval = 0, ...listOptions } = options;
|
|
589
936
|
const client = useFluxbaseClient();
|
|
590
|
-
const [users, setUsers] =
|
|
591
|
-
const [total, setTotal] =
|
|
592
|
-
const [isLoading, setIsLoading] =
|
|
593
|
-
const [error, setError] =
|
|
594
|
-
const fetchUsers =
|
|
937
|
+
const [users, setUsers] = useState4([]);
|
|
938
|
+
const [total, setTotal] = useState4(0);
|
|
939
|
+
const [isLoading, setIsLoading] = useState4(autoFetch);
|
|
940
|
+
const [error, setError] = useState4(null);
|
|
941
|
+
const fetchUsers = useCallback3(async () => {
|
|
595
942
|
try {
|
|
596
943
|
setIsLoading(true);
|
|
597
944
|
setError(null);
|
|
598
|
-
const
|
|
599
|
-
|
|
600
|
-
|
|
945
|
+
const { data, error: apiError } = await client.admin.listUsers(listOptions);
|
|
946
|
+
if (apiError) {
|
|
947
|
+
throw apiError;
|
|
948
|
+
}
|
|
949
|
+
setUsers(data.users);
|
|
950
|
+
setTotal(data.total);
|
|
601
951
|
} catch (err) {
|
|
602
952
|
setError(err);
|
|
603
953
|
} finally {
|
|
604
954
|
setIsLoading(false);
|
|
605
955
|
}
|
|
606
956
|
}, [client, JSON.stringify(listOptions)]);
|
|
607
|
-
const inviteUser =
|
|
957
|
+
const inviteUser = useCallback3(
|
|
608
958
|
async (email, role) => {
|
|
609
959
|
await client.admin.inviteUser({ email, role });
|
|
610
960
|
await fetchUsers();
|
|
611
961
|
},
|
|
612
962
|
[client, fetchUsers]
|
|
613
963
|
);
|
|
614
|
-
const updateUserRole =
|
|
964
|
+
const updateUserRole = useCallback3(
|
|
615
965
|
async (userId, role) => {
|
|
616
966
|
await client.admin.updateUserRole(userId, role);
|
|
617
967
|
await fetchUsers();
|
|
618
968
|
},
|
|
619
969
|
[client, fetchUsers]
|
|
620
970
|
);
|
|
621
|
-
const deleteUser =
|
|
971
|
+
const deleteUser = useCallback3(
|
|
622
972
|
async (userId) => {
|
|
623
973
|
await client.admin.deleteUser(userId);
|
|
624
974
|
await fetchUsers();
|
|
625
975
|
},
|
|
626
976
|
[client, fetchUsers]
|
|
627
977
|
);
|
|
628
|
-
const resetPassword =
|
|
978
|
+
const resetPassword = useCallback3(
|
|
629
979
|
async (userId) => {
|
|
630
|
-
|
|
980
|
+
const { data, error: error2 } = await client.admin.resetUserPassword(userId);
|
|
981
|
+
if (error2) {
|
|
982
|
+
throw error2;
|
|
983
|
+
}
|
|
984
|
+
return data;
|
|
631
985
|
},
|
|
632
986
|
[client]
|
|
633
987
|
);
|
|
634
|
-
|
|
988
|
+
useEffect4(() => {
|
|
635
989
|
if (autoFetch) {
|
|
636
990
|
fetchUsers();
|
|
637
991
|
}
|
|
638
992
|
}, [autoFetch, fetchUsers]);
|
|
639
|
-
|
|
993
|
+
useEffect4(() => {
|
|
640
994
|
if (refetchInterval > 0) {
|
|
641
995
|
const interval = setInterval(fetchUsers, refetchInterval);
|
|
642
996
|
return () => clearInterval(interval);
|
|
@@ -655,56 +1009,56 @@ function useUsers(options = {}) {
|
|
|
655
1009
|
};
|
|
656
1010
|
}
|
|
657
1011
|
|
|
658
|
-
// src/use-
|
|
659
|
-
import { useState as
|
|
660
|
-
function
|
|
1012
|
+
// src/use-client-keys.ts
|
|
1013
|
+
import { useState as useState5, useEffect as useEffect5, useCallback as useCallback4 } from "react";
|
|
1014
|
+
function useClientKeys(options = {}) {
|
|
661
1015
|
const { autoFetch = true } = options;
|
|
662
1016
|
const client = useFluxbaseClient();
|
|
663
|
-
const [keys, setKeys] =
|
|
664
|
-
const [isLoading, setIsLoading] =
|
|
665
|
-
const [error, setError] =
|
|
666
|
-
const fetchKeys =
|
|
1017
|
+
const [keys, setKeys] = useState5([]);
|
|
1018
|
+
const [isLoading, setIsLoading] = useState5(autoFetch);
|
|
1019
|
+
const [error, setError] = useState5(null);
|
|
1020
|
+
const fetchKeys = useCallback4(async () => {
|
|
667
1021
|
try {
|
|
668
1022
|
setIsLoading(true);
|
|
669
1023
|
setError(null);
|
|
670
|
-
const response = await client.admin.management.
|
|
671
|
-
setKeys(response.
|
|
1024
|
+
const response = await client.admin.management.clientKeys.list();
|
|
1025
|
+
setKeys(response.client_keys);
|
|
672
1026
|
} catch (err) {
|
|
673
1027
|
setError(err);
|
|
674
1028
|
} finally {
|
|
675
1029
|
setIsLoading(false);
|
|
676
1030
|
}
|
|
677
1031
|
}, [client]);
|
|
678
|
-
const createKey =
|
|
1032
|
+
const createKey = useCallback4(
|
|
679
1033
|
async (request) => {
|
|
680
|
-
const response = await client.admin.management.
|
|
1034
|
+
const response = await client.admin.management.clientKeys.create(request);
|
|
681
1035
|
await fetchKeys();
|
|
682
|
-
return { key: response.key, keyData: response.
|
|
1036
|
+
return { key: response.key, keyData: response.client_key };
|
|
683
1037
|
},
|
|
684
1038
|
[client, fetchKeys]
|
|
685
1039
|
);
|
|
686
|
-
const updateKey =
|
|
1040
|
+
const updateKey = useCallback4(
|
|
687
1041
|
async (keyId, update) => {
|
|
688
|
-
await client.admin.management.
|
|
1042
|
+
await client.admin.management.clientKeys.update(keyId, update);
|
|
689
1043
|
await fetchKeys();
|
|
690
1044
|
},
|
|
691
1045
|
[client, fetchKeys]
|
|
692
1046
|
);
|
|
693
|
-
const revokeKey =
|
|
1047
|
+
const revokeKey = useCallback4(
|
|
694
1048
|
async (keyId) => {
|
|
695
|
-
await client.admin.management.
|
|
1049
|
+
await client.admin.management.clientKeys.revoke(keyId);
|
|
696
1050
|
await fetchKeys();
|
|
697
1051
|
},
|
|
698
1052
|
[client, fetchKeys]
|
|
699
1053
|
);
|
|
700
|
-
const deleteKey =
|
|
1054
|
+
const deleteKey = useCallback4(
|
|
701
1055
|
async (keyId) => {
|
|
702
|
-
await client.admin.management.
|
|
1056
|
+
await client.admin.management.clientKeys.delete(keyId);
|
|
703
1057
|
await fetchKeys();
|
|
704
1058
|
},
|
|
705
1059
|
[client, fetchKeys]
|
|
706
1060
|
);
|
|
707
|
-
|
|
1061
|
+
useEffect5(() => {
|
|
708
1062
|
if (autoFetch) {
|
|
709
1063
|
fetchKeys();
|
|
710
1064
|
}
|
|
@@ -720,16 +1074,17 @@ function useAPIKeys(options = {}) {
|
|
|
720
1074
|
deleteKey
|
|
721
1075
|
};
|
|
722
1076
|
}
|
|
1077
|
+
var useAPIKeys = useClientKeys;
|
|
723
1078
|
|
|
724
1079
|
// src/use-admin-hooks.ts
|
|
725
|
-
import { useState as
|
|
1080
|
+
import { useState as useState6, useEffect as useEffect6, useCallback as useCallback5 } from "react";
|
|
726
1081
|
function useAppSettings(options = {}) {
|
|
727
1082
|
const { autoFetch = true } = options;
|
|
728
1083
|
const client = useFluxbaseClient();
|
|
729
|
-
const [settings, setSettings] =
|
|
730
|
-
const [isLoading, setIsLoading] =
|
|
731
|
-
const [error, setError] =
|
|
732
|
-
const fetchSettings =
|
|
1084
|
+
const [settings, setSettings] = useState6(null);
|
|
1085
|
+
const [isLoading, setIsLoading] = useState6(autoFetch);
|
|
1086
|
+
const [error, setError] = useState6(null);
|
|
1087
|
+
const fetchSettings = useCallback5(async () => {
|
|
733
1088
|
try {
|
|
734
1089
|
setIsLoading(true);
|
|
735
1090
|
setError(null);
|
|
@@ -741,14 +1096,14 @@ function useAppSettings(options = {}) {
|
|
|
741
1096
|
setIsLoading(false);
|
|
742
1097
|
}
|
|
743
1098
|
}, [client]);
|
|
744
|
-
const updateSettings =
|
|
1099
|
+
const updateSettings = useCallback5(
|
|
745
1100
|
async (update) => {
|
|
746
1101
|
await client.admin.settings.app.update(update);
|
|
747
1102
|
await fetchSettings();
|
|
748
1103
|
},
|
|
749
1104
|
[client, fetchSettings]
|
|
750
1105
|
);
|
|
751
|
-
|
|
1106
|
+
useEffect6(() => {
|
|
752
1107
|
if (autoFetch) {
|
|
753
1108
|
fetchSettings();
|
|
754
1109
|
}
|
|
@@ -764,10 +1119,10 @@ function useAppSettings(options = {}) {
|
|
|
764
1119
|
function useSystemSettings(options = {}) {
|
|
765
1120
|
const { autoFetch = true } = options;
|
|
766
1121
|
const client = useFluxbaseClient();
|
|
767
|
-
const [settings, setSettings] =
|
|
768
|
-
const [isLoading, setIsLoading] =
|
|
769
|
-
const [error, setError] =
|
|
770
|
-
const fetchSettings =
|
|
1122
|
+
const [settings, setSettings] = useState6([]);
|
|
1123
|
+
const [isLoading, setIsLoading] = useState6(autoFetch);
|
|
1124
|
+
const [error, setError] = useState6(null);
|
|
1125
|
+
const fetchSettings = useCallback5(async () => {
|
|
771
1126
|
try {
|
|
772
1127
|
setIsLoading(true);
|
|
773
1128
|
setError(null);
|
|
@@ -779,27 +1134,27 @@ function useSystemSettings(options = {}) {
|
|
|
779
1134
|
setIsLoading(false);
|
|
780
1135
|
}
|
|
781
1136
|
}, [client]);
|
|
782
|
-
const getSetting =
|
|
1137
|
+
const getSetting = useCallback5(
|
|
783
1138
|
(key) => {
|
|
784
1139
|
return settings.find((s) => s.key === key);
|
|
785
1140
|
},
|
|
786
1141
|
[settings]
|
|
787
1142
|
);
|
|
788
|
-
const updateSetting =
|
|
1143
|
+
const updateSetting = useCallback5(
|
|
789
1144
|
async (key, update) => {
|
|
790
1145
|
await client.admin.settings.system.update(key, update);
|
|
791
1146
|
await fetchSettings();
|
|
792
1147
|
},
|
|
793
1148
|
[client, fetchSettings]
|
|
794
1149
|
);
|
|
795
|
-
const deleteSetting =
|
|
1150
|
+
const deleteSetting = useCallback5(
|
|
796
1151
|
async (key) => {
|
|
797
1152
|
await client.admin.settings.system.delete(key);
|
|
798
1153
|
await fetchSettings();
|
|
799
1154
|
},
|
|
800
1155
|
[client, fetchSettings]
|
|
801
1156
|
);
|
|
802
|
-
|
|
1157
|
+
useEffect6(() => {
|
|
803
1158
|
if (autoFetch) {
|
|
804
1159
|
fetchSettings();
|
|
805
1160
|
}
|
|
@@ -817,10 +1172,10 @@ function useSystemSettings(options = {}) {
|
|
|
817
1172
|
function useWebhooks(options = {}) {
|
|
818
1173
|
const { autoFetch = true, refetchInterval = 0 } = options;
|
|
819
1174
|
const client = useFluxbaseClient();
|
|
820
|
-
const [webhooks, setWebhooks] =
|
|
821
|
-
const [isLoading, setIsLoading] =
|
|
822
|
-
const [error, setError] =
|
|
823
|
-
const fetchWebhooks =
|
|
1175
|
+
const [webhooks, setWebhooks] = useState6([]);
|
|
1176
|
+
const [isLoading, setIsLoading] = useState6(autoFetch);
|
|
1177
|
+
const [error, setError] = useState6(null);
|
|
1178
|
+
const fetchWebhooks = useCallback5(async () => {
|
|
824
1179
|
try {
|
|
825
1180
|
setIsLoading(true);
|
|
826
1181
|
setError(null);
|
|
@@ -832,7 +1187,7 @@ function useWebhooks(options = {}) {
|
|
|
832
1187
|
setIsLoading(false);
|
|
833
1188
|
}
|
|
834
1189
|
}, [client]);
|
|
835
|
-
const createWebhook =
|
|
1190
|
+
const createWebhook = useCallback5(
|
|
836
1191
|
async (webhook) => {
|
|
837
1192
|
const created = await client.admin.management.webhooks.create(webhook);
|
|
838
1193
|
await fetchWebhooks();
|
|
@@ -840,7 +1195,7 @@ function useWebhooks(options = {}) {
|
|
|
840
1195
|
},
|
|
841
1196
|
[client, fetchWebhooks]
|
|
842
1197
|
);
|
|
843
|
-
const updateWebhook =
|
|
1198
|
+
const updateWebhook = useCallback5(
|
|
844
1199
|
async (id, update) => {
|
|
845
1200
|
const updated = await client.admin.management.webhooks.update(id, update);
|
|
846
1201
|
await fetchWebhooks();
|
|
@@ -848,20 +1203,20 @@ function useWebhooks(options = {}) {
|
|
|
848
1203
|
},
|
|
849
1204
|
[client, fetchWebhooks]
|
|
850
1205
|
);
|
|
851
|
-
const deleteWebhook =
|
|
1206
|
+
const deleteWebhook = useCallback5(
|
|
852
1207
|
async (id) => {
|
|
853
1208
|
await client.admin.management.webhooks.delete(id);
|
|
854
1209
|
await fetchWebhooks();
|
|
855
1210
|
},
|
|
856
1211
|
[client, fetchWebhooks]
|
|
857
1212
|
);
|
|
858
|
-
const testWebhook =
|
|
1213
|
+
const testWebhook = useCallback5(
|
|
859
1214
|
async (id) => {
|
|
860
1215
|
await client.admin.management.webhooks.test(id);
|
|
861
1216
|
},
|
|
862
1217
|
[client]
|
|
863
1218
|
);
|
|
864
|
-
|
|
1219
|
+
useEffect6(() => {
|
|
865
1220
|
if (autoFetch) {
|
|
866
1221
|
fetchWebhooks();
|
|
867
1222
|
}
|
|
@@ -883,22 +1238,32 @@ function useWebhooks(options = {}) {
|
|
|
883
1238
|
}
|
|
884
1239
|
export {
|
|
885
1240
|
FluxbaseProvider,
|
|
1241
|
+
isCaptchaRequiredForEndpoint,
|
|
886
1242
|
useAPIKeys,
|
|
887
1243
|
useAdminAuth,
|
|
888
1244
|
useAppSettings,
|
|
889
1245
|
useAuth,
|
|
1246
|
+
useCaptcha,
|
|
1247
|
+
useCaptchaConfig,
|
|
1248
|
+
useClientKeys,
|
|
890
1249
|
useCreateBucket,
|
|
891
1250
|
useDelete,
|
|
892
1251
|
useDeleteBucket,
|
|
893
1252
|
useFluxbaseClient,
|
|
894
1253
|
useFluxbaseQuery,
|
|
1254
|
+
useGetSAMLLoginUrl,
|
|
1255
|
+
useGraphQL,
|
|
1256
|
+
useGraphQLIntrospection,
|
|
1257
|
+
useGraphQLMutation,
|
|
1258
|
+
useGraphQLQuery,
|
|
1259
|
+
useHandleSAMLCallback,
|
|
895
1260
|
useInsert,
|
|
896
|
-
useRPC,
|
|
897
|
-
useRPCBatch,
|
|
898
|
-
useRPCMutation,
|
|
899
1261
|
useRealtime,
|
|
1262
|
+
useSAMLMetadataUrl,
|
|
1263
|
+
useSAMLProviders,
|
|
900
1264
|
useSession,
|
|
901
1265
|
useSignIn,
|
|
1266
|
+
useSignInWithSAML,
|
|
902
1267
|
useSignOut,
|
|
903
1268
|
useSignUp,
|
|
904
1269
|
useStorageBuckets,
|
|
@@ -909,7 +1274,10 @@ export {
|
|
|
909
1274
|
useStorageMove,
|
|
910
1275
|
useStoragePublicUrl,
|
|
911
1276
|
useStorageSignedUrl,
|
|
1277
|
+
useStorageSignedUrlWithOptions,
|
|
1278
|
+
useStorageTransformUrl,
|
|
912
1279
|
useStorageUpload,
|
|
1280
|
+
useStorageUploadWithProgress,
|
|
913
1281
|
useSystemSettings,
|
|
914
1282
|
useTable,
|
|
915
1283
|
useTableDeletes,
|