@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.js
CHANGED
|
@@ -21,22 +21,33 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
FluxbaseProvider: () => FluxbaseProvider,
|
|
24
|
+
isCaptchaRequiredForEndpoint: () => isCaptchaRequiredForEndpoint,
|
|
24
25
|
useAPIKeys: () => useAPIKeys,
|
|
25
26
|
useAdminAuth: () => useAdminAuth,
|
|
26
27
|
useAppSettings: () => useAppSettings,
|
|
27
28
|
useAuth: () => useAuth,
|
|
29
|
+
useAuthConfig: () => useAuthConfig,
|
|
30
|
+
useCaptcha: () => useCaptcha,
|
|
31
|
+
useCaptchaConfig: () => useCaptchaConfig,
|
|
32
|
+
useClientKeys: () => useClientKeys,
|
|
28
33
|
useCreateBucket: () => useCreateBucket,
|
|
29
34
|
useDelete: () => useDelete,
|
|
30
35
|
useDeleteBucket: () => useDeleteBucket,
|
|
31
36
|
useFluxbaseClient: () => useFluxbaseClient,
|
|
32
37
|
useFluxbaseQuery: () => useFluxbaseQuery,
|
|
38
|
+
useGetSAMLLoginUrl: () => useGetSAMLLoginUrl,
|
|
39
|
+
useGraphQL: () => useGraphQL,
|
|
40
|
+
useGraphQLIntrospection: () => useGraphQLIntrospection,
|
|
41
|
+
useGraphQLMutation: () => useGraphQLMutation,
|
|
42
|
+
useGraphQLQuery: () => useGraphQLQuery,
|
|
43
|
+
useHandleSAMLCallback: () => useHandleSAMLCallback,
|
|
33
44
|
useInsert: () => useInsert,
|
|
34
|
-
useRPC: () => useRPC,
|
|
35
|
-
useRPCBatch: () => useRPCBatch,
|
|
36
|
-
useRPCMutation: () => useRPCMutation,
|
|
37
45
|
useRealtime: () => useRealtime,
|
|
46
|
+
useSAMLMetadataUrl: () => useSAMLMetadataUrl,
|
|
47
|
+
useSAMLProviders: () => useSAMLProviders,
|
|
38
48
|
useSession: () => useSession,
|
|
39
49
|
useSignIn: () => useSignIn,
|
|
50
|
+
useSignInWithSAML: () => useSignInWithSAML,
|
|
40
51
|
useSignOut: () => useSignOut,
|
|
41
52
|
useSignUp: () => useSignUp,
|
|
42
53
|
useStorageBuckets: () => useStorageBuckets,
|
|
@@ -47,7 +58,10 @@ __export(index_exports, {
|
|
|
47
58
|
useStorageMove: () => useStorageMove,
|
|
48
59
|
useStoragePublicUrl: () => useStoragePublicUrl,
|
|
49
60
|
useStorageSignedUrl: () => useStorageSignedUrl,
|
|
61
|
+
useStorageSignedUrlWithOptions: () => useStorageSignedUrlWithOptions,
|
|
62
|
+
useStorageTransformUrl: () => useStorageTransformUrl,
|
|
50
63
|
useStorageUpload: () => useStorageUpload,
|
|
64
|
+
useStorageUploadWithProgress: () => useStorageUploadWithProgress,
|
|
51
65
|
useSystemSettings: () => useSystemSettings,
|
|
52
66
|
useTable: () => useTable,
|
|
53
67
|
useTableDeletes: () => useTableDeletes,
|
|
@@ -85,12 +99,13 @@ function useUser() {
|
|
|
85
99
|
return (0, import_react_query.useQuery)({
|
|
86
100
|
queryKey: ["fluxbase", "auth", "user"],
|
|
87
101
|
queryFn: async () => {
|
|
88
|
-
const
|
|
89
|
-
if (!session) {
|
|
102
|
+
const { data } = await client.auth.getSession();
|
|
103
|
+
if (!data?.session) {
|
|
90
104
|
return null;
|
|
91
105
|
}
|
|
92
106
|
try {
|
|
93
|
-
|
|
107
|
+
const result = await client.auth.getCurrentUser();
|
|
108
|
+
return result.data?.user ?? null;
|
|
94
109
|
} catch {
|
|
95
110
|
return null;
|
|
96
111
|
}
|
|
@@ -103,7 +118,10 @@ function useSession() {
|
|
|
103
118
|
const client = useFluxbaseClient();
|
|
104
119
|
return (0, import_react_query.useQuery)({
|
|
105
120
|
queryKey: ["fluxbase", "auth", "session"],
|
|
106
|
-
queryFn: () =>
|
|
121
|
+
queryFn: async () => {
|
|
122
|
+
const { data } = await client.auth.getSession();
|
|
123
|
+
return data?.session ?? null;
|
|
124
|
+
},
|
|
107
125
|
staleTime: 1e3 * 60 * 5
|
|
108
126
|
// 5 minutes
|
|
109
127
|
});
|
|
@@ -130,9 +148,17 @@ function useSignUp() {
|
|
|
130
148
|
mutationFn: async (credentials) => {
|
|
131
149
|
return await client.auth.signUp(credentials);
|
|
132
150
|
},
|
|
133
|
-
onSuccess: (
|
|
134
|
-
|
|
135
|
-
|
|
151
|
+
onSuccess: (response) => {
|
|
152
|
+
if (response.data) {
|
|
153
|
+
queryClient.setQueryData(
|
|
154
|
+
["fluxbase", "auth", "session"],
|
|
155
|
+
response.data.session
|
|
156
|
+
);
|
|
157
|
+
queryClient.setQueryData(
|
|
158
|
+
["fluxbase", "auth", "user"],
|
|
159
|
+
response.data.user
|
|
160
|
+
);
|
|
161
|
+
}
|
|
136
162
|
}
|
|
137
163
|
});
|
|
138
164
|
}
|
|
@@ -185,12 +211,303 @@ function useAuth() {
|
|
|
185
211
|
};
|
|
186
212
|
}
|
|
187
213
|
|
|
188
|
-
// src/use-
|
|
214
|
+
// src/use-captcha.ts
|
|
189
215
|
var import_react_query2 = require("@tanstack/react-query");
|
|
216
|
+
var import_react2 = require("react");
|
|
217
|
+
function useCaptchaConfig() {
|
|
218
|
+
const client = useFluxbaseClient();
|
|
219
|
+
return (0, import_react_query2.useQuery)({
|
|
220
|
+
queryKey: ["fluxbase", "auth", "captcha", "config"],
|
|
221
|
+
queryFn: async () => {
|
|
222
|
+
const { data, error } = await client.auth.getCaptchaConfig();
|
|
223
|
+
if (error) {
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
return data;
|
|
227
|
+
},
|
|
228
|
+
staleTime: 1e3 * 60 * 60,
|
|
229
|
+
// Cache for 1 hour (config rarely changes)
|
|
230
|
+
gcTime: 1e3 * 60 * 60 * 24
|
|
231
|
+
// Keep in cache for 24 hours
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
function useCaptcha(provider) {
|
|
235
|
+
const [token, setToken] = (0, import_react2.useState)(null);
|
|
236
|
+
const [isReady, setIsReady] = (0, import_react2.useState)(false);
|
|
237
|
+
const [isLoading, setIsLoading] = (0, import_react2.useState)(false);
|
|
238
|
+
const [error, setError] = (0, import_react2.useState)(null);
|
|
239
|
+
const executeResolverRef = (0, import_react2.useRef)(null);
|
|
240
|
+
const executeRejecterRef = (0, import_react2.useRef)(null);
|
|
241
|
+
const onVerify = (0, import_react2.useCallback)((newToken) => {
|
|
242
|
+
setToken(newToken);
|
|
243
|
+
setIsLoading(false);
|
|
244
|
+
setError(null);
|
|
245
|
+
setIsReady(true);
|
|
246
|
+
if (executeResolverRef.current) {
|
|
247
|
+
executeResolverRef.current(newToken);
|
|
248
|
+
executeResolverRef.current = null;
|
|
249
|
+
executeRejecterRef.current = null;
|
|
250
|
+
}
|
|
251
|
+
}, []);
|
|
252
|
+
const onExpire = (0, import_react2.useCallback)(() => {
|
|
253
|
+
setToken(null);
|
|
254
|
+
setIsReady(true);
|
|
255
|
+
}, []);
|
|
256
|
+
const onError = (0, import_react2.useCallback)((err) => {
|
|
257
|
+
setError(err);
|
|
258
|
+
setIsLoading(false);
|
|
259
|
+
setToken(null);
|
|
260
|
+
if (executeRejecterRef.current) {
|
|
261
|
+
executeRejecterRef.current(err);
|
|
262
|
+
executeResolverRef.current = null;
|
|
263
|
+
executeRejecterRef.current = null;
|
|
264
|
+
}
|
|
265
|
+
}, []);
|
|
266
|
+
const reset = (0, import_react2.useCallback)(() => {
|
|
267
|
+
setToken(null);
|
|
268
|
+
setError(null);
|
|
269
|
+
setIsLoading(false);
|
|
270
|
+
}, []);
|
|
271
|
+
const execute = (0, import_react2.useCallback)(async () => {
|
|
272
|
+
if (token) {
|
|
273
|
+
return token;
|
|
274
|
+
}
|
|
275
|
+
if (!provider) {
|
|
276
|
+
return "";
|
|
277
|
+
}
|
|
278
|
+
setIsLoading(true);
|
|
279
|
+
setError(null);
|
|
280
|
+
return new Promise((resolve, reject) => {
|
|
281
|
+
executeResolverRef.current = resolve;
|
|
282
|
+
executeRejecterRef.current = reject;
|
|
283
|
+
});
|
|
284
|
+
}, [token, provider]);
|
|
285
|
+
(0, import_react2.useEffect)(() => {
|
|
286
|
+
if (provider) {
|
|
287
|
+
setIsReady(true);
|
|
288
|
+
}
|
|
289
|
+
}, [provider]);
|
|
290
|
+
return {
|
|
291
|
+
token,
|
|
292
|
+
isReady,
|
|
293
|
+
isLoading,
|
|
294
|
+
error,
|
|
295
|
+
reset,
|
|
296
|
+
execute,
|
|
297
|
+
onVerify,
|
|
298
|
+
onExpire,
|
|
299
|
+
onError
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
function isCaptchaRequiredForEndpoint(config, endpoint) {
|
|
303
|
+
if (!config?.enabled) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
return config.endpoints?.includes(endpoint) ?? false;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/use-auth-config.ts
|
|
310
|
+
var import_react_query3 = require("@tanstack/react-query");
|
|
311
|
+
function useAuthConfig() {
|
|
312
|
+
const client = useFluxbaseClient();
|
|
313
|
+
return (0, import_react_query3.useQuery)({
|
|
314
|
+
queryKey: ["fluxbase", "auth", "config"],
|
|
315
|
+
queryFn: async () => {
|
|
316
|
+
const { data, error } = await client.auth.getAuthConfig();
|
|
317
|
+
if (error) {
|
|
318
|
+
throw error;
|
|
319
|
+
}
|
|
320
|
+
return data;
|
|
321
|
+
},
|
|
322
|
+
staleTime: 1e3 * 60 * 5,
|
|
323
|
+
// Cache for 5 minutes (config changes infrequently)
|
|
324
|
+
gcTime: 1e3 * 60 * 60
|
|
325
|
+
// Keep in cache for 1 hour
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// src/use-saml.ts
|
|
330
|
+
var import_react_query4 = require("@tanstack/react-query");
|
|
331
|
+
function useSAMLProviders() {
|
|
332
|
+
const client = useFluxbaseClient();
|
|
333
|
+
return (0, import_react_query4.useQuery)({
|
|
334
|
+
queryKey: ["fluxbase", "auth", "saml", "providers"],
|
|
335
|
+
queryFn: async () => {
|
|
336
|
+
const { data, error } = await client.auth.getSAMLProviders();
|
|
337
|
+
if (error) throw error;
|
|
338
|
+
return data.providers;
|
|
339
|
+
},
|
|
340
|
+
staleTime: 1e3 * 60 * 5
|
|
341
|
+
// 5 minutes - providers don't change often
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
function useGetSAMLLoginUrl() {
|
|
345
|
+
const client = useFluxbaseClient();
|
|
346
|
+
return (0, import_react_query4.useMutation)({
|
|
347
|
+
mutationFn: async ({
|
|
348
|
+
provider,
|
|
349
|
+
options
|
|
350
|
+
}) => {
|
|
351
|
+
return await client.auth.getSAMLLoginUrl(provider, options);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
function useSignInWithSAML() {
|
|
356
|
+
const client = useFluxbaseClient();
|
|
357
|
+
return (0, import_react_query4.useMutation)({
|
|
358
|
+
mutationFn: async ({
|
|
359
|
+
provider,
|
|
360
|
+
options
|
|
361
|
+
}) => {
|
|
362
|
+
return await client.auth.signInWithSAML(provider, options);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
function useHandleSAMLCallback() {
|
|
367
|
+
const client = useFluxbaseClient();
|
|
368
|
+
const queryClient = (0, import_react_query4.useQueryClient)();
|
|
369
|
+
return (0, import_react_query4.useMutation)({
|
|
370
|
+
mutationFn: async ({
|
|
371
|
+
samlResponse,
|
|
372
|
+
provider
|
|
373
|
+
}) => {
|
|
374
|
+
return await client.auth.handleSAMLCallback(samlResponse, provider);
|
|
375
|
+
},
|
|
376
|
+
onSuccess: (result) => {
|
|
377
|
+
if (result.data) {
|
|
378
|
+
queryClient.setQueryData(
|
|
379
|
+
["fluxbase", "auth", "session"],
|
|
380
|
+
result.data.session
|
|
381
|
+
);
|
|
382
|
+
queryClient.setQueryData(
|
|
383
|
+
["fluxbase", "auth", "user"],
|
|
384
|
+
result.data.user
|
|
385
|
+
);
|
|
386
|
+
queryClient.invalidateQueries({ queryKey: ["fluxbase"] });
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
function useSAMLMetadataUrl() {
|
|
392
|
+
const client = useFluxbaseClient();
|
|
393
|
+
return (provider) => {
|
|
394
|
+
return client.auth.getSAMLMetadataUrl(provider);
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/use-graphql.ts
|
|
399
|
+
var import_react_query5 = require("@tanstack/react-query");
|
|
400
|
+
function useGraphQLQuery(queryKey, query, options) {
|
|
401
|
+
const client = useFluxbaseClient();
|
|
402
|
+
const normalizedKey = Array.isArray(queryKey) ? ["fluxbase", "graphql", ...queryKey] : ["fluxbase", "graphql", queryKey];
|
|
403
|
+
return (0, import_react_query5.useQuery)({
|
|
404
|
+
queryKey: normalizedKey,
|
|
405
|
+
queryFn: async () => {
|
|
406
|
+
const response = await client.graphql.execute(
|
|
407
|
+
query,
|
|
408
|
+
options?.variables,
|
|
409
|
+
options?.operationName,
|
|
410
|
+
options?.requestOptions
|
|
411
|
+
);
|
|
412
|
+
if (response.errors && response.errors.length > 0) {
|
|
413
|
+
throw response.errors[0];
|
|
414
|
+
}
|
|
415
|
+
return response.data;
|
|
416
|
+
},
|
|
417
|
+
enabled: options?.enabled ?? true,
|
|
418
|
+
staleTime: options?.staleTime ?? 0,
|
|
419
|
+
gcTime: options?.gcTime,
|
|
420
|
+
refetchOnWindowFocus: options?.refetchOnWindowFocus ?? true,
|
|
421
|
+
select: options?.select
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function useGraphQLMutation(mutation, options) {
|
|
425
|
+
const client = useFluxbaseClient();
|
|
426
|
+
const queryClient = (0, import_react_query5.useQueryClient)();
|
|
427
|
+
return (0, import_react_query5.useMutation)({
|
|
428
|
+
mutationFn: async (variables) => {
|
|
429
|
+
const response = await client.graphql.execute(
|
|
430
|
+
mutation,
|
|
431
|
+
variables,
|
|
432
|
+
options?.operationName,
|
|
433
|
+
options?.requestOptions
|
|
434
|
+
);
|
|
435
|
+
if (response.errors && response.errors.length > 0) {
|
|
436
|
+
throw response.errors[0];
|
|
437
|
+
}
|
|
438
|
+
return response.data;
|
|
439
|
+
},
|
|
440
|
+
onSuccess: (data, variables) => {
|
|
441
|
+
if (options?.invalidateQueries) {
|
|
442
|
+
for (const key of options.invalidateQueries) {
|
|
443
|
+
queryClient.invalidateQueries({
|
|
444
|
+
queryKey: ["fluxbase", "graphql", key]
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
if (options?.onSuccess && data !== void 0) {
|
|
449
|
+
options.onSuccess(data, variables);
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
onError: (error, variables) => {
|
|
453
|
+
if (options?.onError) {
|
|
454
|
+
options.onError(error, variables);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
function useGraphQLIntrospection(options) {
|
|
460
|
+
const client = useFluxbaseClient();
|
|
461
|
+
return (0, import_react_query5.useQuery)({
|
|
462
|
+
queryKey: ["fluxbase", "graphql", "__introspection"],
|
|
463
|
+
queryFn: async () => {
|
|
464
|
+
const response = await client.graphql.introspect(options?.requestOptions);
|
|
465
|
+
if (response.errors && response.errors.length > 0) {
|
|
466
|
+
throw response.errors[0];
|
|
467
|
+
}
|
|
468
|
+
return response.data;
|
|
469
|
+
},
|
|
470
|
+
enabled: options?.enabled ?? true,
|
|
471
|
+
staleTime: options?.staleTime ?? 1e3 * 60 * 5
|
|
472
|
+
// 5 minutes - schema doesn't change often
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
function useGraphQL() {
|
|
476
|
+
const client = useFluxbaseClient();
|
|
477
|
+
return {
|
|
478
|
+
/**
|
|
479
|
+
* Execute a GraphQL query
|
|
480
|
+
*/
|
|
481
|
+
executeQuery: (query, variables, options) => {
|
|
482
|
+
return client.graphql.query(query, variables, options);
|
|
483
|
+
},
|
|
484
|
+
/**
|
|
485
|
+
* Execute a GraphQL mutation
|
|
486
|
+
*/
|
|
487
|
+
executeMutation: (mutation, variables, options) => {
|
|
488
|
+
return client.graphql.mutation(mutation, variables, options);
|
|
489
|
+
},
|
|
490
|
+
/**
|
|
491
|
+
* Execute a GraphQL operation with an explicit operation name
|
|
492
|
+
*/
|
|
493
|
+
execute: (document, variables, operationName, options) => {
|
|
494
|
+
return client.graphql.execute(document, variables, operationName, options);
|
|
495
|
+
},
|
|
496
|
+
/**
|
|
497
|
+
* Fetch the GraphQL schema via introspection
|
|
498
|
+
*/
|
|
499
|
+
introspect: (options) => {
|
|
500
|
+
return client.graphql.introspect(options);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/use-query.ts
|
|
506
|
+
var import_react_query6 = require("@tanstack/react-query");
|
|
190
507
|
function useFluxbaseQuery(buildQuery, options) {
|
|
191
508
|
const client = useFluxbaseClient();
|
|
192
509
|
const queryKey = options?.queryKey || ["fluxbase", "query", buildQuery.toString()];
|
|
193
|
-
return (0,
|
|
510
|
+
return (0, import_react_query6.useQuery)({
|
|
194
511
|
queryKey,
|
|
195
512
|
queryFn: async () => {
|
|
196
513
|
const query = buildQuery(client);
|
|
@@ -218,8 +535,8 @@ function useTable(table, buildQuery, options) {
|
|
|
218
535
|
}
|
|
219
536
|
function useInsert(table) {
|
|
220
537
|
const client = useFluxbaseClient();
|
|
221
|
-
const queryClient = (0,
|
|
222
|
-
return (0,
|
|
538
|
+
const queryClient = (0, import_react_query6.useQueryClient)();
|
|
539
|
+
return (0, import_react_query6.useMutation)({
|
|
223
540
|
mutationFn: async (data) => {
|
|
224
541
|
const query = client.from(table);
|
|
225
542
|
const { data: result, error } = await query.insert(data);
|
|
@@ -235,8 +552,8 @@ function useInsert(table) {
|
|
|
235
552
|
}
|
|
236
553
|
function useUpdate(table) {
|
|
237
554
|
const client = useFluxbaseClient();
|
|
238
|
-
const queryClient = (0,
|
|
239
|
-
return (0,
|
|
555
|
+
const queryClient = (0, import_react_query6.useQueryClient)();
|
|
556
|
+
return (0, import_react_query6.useMutation)({
|
|
240
557
|
mutationFn: async (params) => {
|
|
241
558
|
const query = client.from(table);
|
|
242
559
|
const builtQuery = params.buildQuery(query);
|
|
@@ -253,8 +570,8 @@ function useUpdate(table) {
|
|
|
253
570
|
}
|
|
254
571
|
function useUpsert(table) {
|
|
255
572
|
const client = useFluxbaseClient();
|
|
256
|
-
const queryClient = (0,
|
|
257
|
-
return (0,
|
|
573
|
+
const queryClient = (0, import_react_query6.useQueryClient)();
|
|
574
|
+
return (0, import_react_query6.useMutation)({
|
|
258
575
|
mutationFn: async (data) => {
|
|
259
576
|
const query = client.from(table);
|
|
260
577
|
const { data: result, error } = await query.upsert(data);
|
|
@@ -270,8 +587,8 @@ function useUpsert(table) {
|
|
|
270
587
|
}
|
|
271
588
|
function useDelete(table) {
|
|
272
589
|
const client = useFluxbaseClient();
|
|
273
|
-
const queryClient = (0,
|
|
274
|
-
return (0,
|
|
590
|
+
const queryClient = (0, import_react_query6.useQueryClient)();
|
|
591
|
+
return (0, import_react_query6.useMutation)({
|
|
275
592
|
mutationFn: async (buildQuery) => {
|
|
276
593
|
const query = client.from(table);
|
|
277
594
|
const builtQuery = buildQuery(query);
|
|
@@ -287,12 +604,14 @@ function useDelete(table) {
|
|
|
287
604
|
}
|
|
288
605
|
|
|
289
606
|
// src/use-realtime.ts
|
|
290
|
-
var
|
|
291
|
-
var
|
|
607
|
+
var import_react3 = require("react");
|
|
608
|
+
var import_react_query7 = require("@tanstack/react-query");
|
|
292
609
|
function useRealtime(options) {
|
|
293
610
|
const client = useFluxbaseClient();
|
|
294
|
-
const queryClient = (0,
|
|
295
|
-
const channelRef = (0,
|
|
611
|
+
const queryClient = (0, import_react_query7.useQueryClient)();
|
|
612
|
+
const channelRef = (0, import_react3.useRef)(
|
|
613
|
+
null
|
|
614
|
+
);
|
|
296
615
|
const {
|
|
297
616
|
channel: channelName,
|
|
298
617
|
event = "*",
|
|
@@ -301,7 +620,7 @@ function useRealtime(options) {
|
|
|
301
620
|
invalidateKey,
|
|
302
621
|
enabled = true
|
|
303
622
|
} = options;
|
|
304
|
-
(0,
|
|
623
|
+
(0, import_react3.useEffect)(() => {
|
|
305
624
|
if (!enabled) {
|
|
306
625
|
return;
|
|
307
626
|
}
|
|
@@ -322,7 +641,16 @@ function useRealtime(options) {
|
|
|
322
641
|
channel.unsubscribe();
|
|
323
642
|
channelRef.current = null;
|
|
324
643
|
};
|
|
325
|
-
}, [
|
|
644
|
+
}, [
|
|
645
|
+
client,
|
|
646
|
+
channelName,
|
|
647
|
+
event,
|
|
648
|
+
callback,
|
|
649
|
+
autoInvalidate,
|
|
650
|
+
invalidateKey,
|
|
651
|
+
queryClient,
|
|
652
|
+
enabled
|
|
653
|
+
]);
|
|
326
654
|
return {
|
|
327
655
|
channel: channelRef.current
|
|
328
656
|
};
|
|
@@ -359,12 +687,19 @@ function useTableDeletes(table, callback, options) {
|
|
|
359
687
|
}
|
|
360
688
|
|
|
361
689
|
// src/use-storage.ts
|
|
362
|
-
var
|
|
690
|
+
var import_react4 = require("react");
|
|
691
|
+
var import_react_query8 = require("@tanstack/react-query");
|
|
363
692
|
function useStorageList(bucket, options) {
|
|
364
693
|
const client = useFluxbaseClient();
|
|
365
694
|
const { prefix, limit, offset, ...queryOptions } = options || {};
|
|
366
|
-
return (0,
|
|
367
|
-
queryKey: [
|
|
695
|
+
return (0, import_react_query8.useQuery)({
|
|
696
|
+
queryKey: [
|
|
697
|
+
"fluxbase",
|
|
698
|
+
"storage",
|
|
699
|
+
bucket,
|
|
700
|
+
"list",
|
|
701
|
+
{ prefix, limit, offset }
|
|
702
|
+
],
|
|
368
703
|
queryFn: async () => {
|
|
369
704
|
const { data, error } = await client.storage.from(bucket).list({ prefix, limit, offset });
|
|
370
705
|
if (error) {
|
|
@@ -377,8 +712,8 @@ function useStorageList(bucket, options) {
|
|
|
377
712
|
}
|
|
378
713
|
function useStorageUpload(bucket) {
|
|
379
714
|
const client = useFluxbaseClient();
|
|
380
|
-
const queryClient = (0,
|
|
381
|
-
return (0,
|
|
715
|
+
const queryClient = (0, import_react_query8.useQueryClient)();
|
|
716
|
+
return (0, import_react_query8.useMutation)({
|
|
382
717
|
mutationFn: async (params) => {
|
|
383
718
|
const { path, file, options } = params;
|
|
384
719
|
const { data, error } = await client.storage.from(bucket).upload(path, file, options);
|
|
@@ -388,13 +723,49 @@ function useStorageUpload(bucket) {
|
|
|
388
723
|
return data;
|
|
389
724
|
},
|
|
390
725
|
onSuccess: () => {
|
|
391
|
-
queryClient.invalidateQueries({
|
|
726
|
+
queryClient.invalidateQueries({
|
|
727
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
function useStorageUploadWithProgress(bucket) {
|
|
733
|
+
const client = useFluxbaseClient();
|
|
734
|
+
const queryClient = (0, import_react_query8.useQueryClient)();
|
|
735
|
+
const [progress, setProgress] = (0, import_react4.useState)(null);
|
|
736
|
+
const mutation = (0, import_react_query8.useMutation)({
|
|
737
|
+
mutationFn: async (params) => {
|
|
738
|
+
const { path, file, options } = params;
|
|
739
|
+
setProgress({ loaded: 0, total: 0, percentage: 0 });
|
|
740
|
+
const { data, error } = await client.storage.from(bucket).upload(path, file, {
|
|
741
|
+
...options,
|
|
742
|
+
onUploadProgress: (p) => {
|
|
743
|
+
setProgress(p);
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
if (error) {
|
|
747
|
+
throw error;
|
|
748
|
+
}
|
|
749
|
+
return data;
|
|
750
|
+
},
|
|
751
|
+
onSuccess: () => {
|
|
752
|
+
queryClient.invalidateQueries({
|
|
753
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
754
|
+
});
|
|
755
|
+
},
|
|
756
|
+
onError: () => {
|
|
757
|
+
setProgress(null);
|
|
392
758
|
}
|
|
393
759
|
});
|
|
760
|
+
return {
|
|
761
|
+
upload: mutation,
|
|
762
|
+
progress,
|
|
763
|
+
reset: () => setProgress(null)
|
|
764
|
+
};
|
|
394
765
|
}
|
|
395
766
|
function useStorageDownload(bucket, path, enabled = true) {
|
|
396
767
|
const client = useFluxbaseClient();
|
|
397
|
-
return (0,
|
|
768
|
+
return (0, import_react_query8.useQuery)({
|
|
398
769
|
queryKey: ["fluxbase", "storage", bucket, "download", path],
|
|
399
770
|
queryFn: async () => {
|
|
400
771
|
if (!path) {
|
|
@@ -411,8 +782,8 @@ function useStorageDownload(bucket, path, enabled = true) {
|
|
|
411
782
|
}
|
|
412
783
|
function useStorageDelete(bucket) {
|
|
413
784
|
const client = useFluxbaseClient();
|
|
414
|
-
const queryClient = (0,
|
|
415
|
-
return (0,
|
|
785
|
+
const queryClient = (0, import_react_query8.useQueryClient)();
|
|
786
|
+
return (0, import_react_query8.useMutation)({
|
|
416
787
|
mutationFn: async (paths) => {
|
|
417
788
|
const { error } = await client.storage.from(bucket).remove(paths);
|
|
418
789
|
if (error) {
|
|
@@ -420,7 +791,9 @@ function useStorageDelete(bucket) {
|
|
|
420
791
|
}
|
|
421
792
|
},
|
|
422
793
|
onSuccess: () => {
|
|
423
|
-
queryClient.invalidateQueries({
|
|
794
|
+
queryClient.invalidateQueries({
|
|
795
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
796
|
+
});
|
|
424
797
|
}
|
|
425
798
|
});
|
|
426
799
|
}
|
|
@@ -432,9 +805,16 @@ function useStoragePublicUrl(bucket, path) {
|
|
|
432
805
|
const { data } = client.storage.from(bucket).getPublicUrl(path);
|
|
433
806
|
return data.publicUrl;
|
|
434
807
|
}
|
|
808
|
+
function useStorageTransformUrl(bucket, path, transform) {
|
|
809
|
+
const client = useFluxbaseClient();
|
|
810
|
+
if (!path) {
|
|
811
|
+
return null;
|
|
812
|
+
}
|
|
813
|
+
return client.storage.from(bucket).getTransformUrl(path, transform);
|
|
814
|
+
}
|
|
435
815
|
function useStorageSignedUrl(bucket, path, expiresIn) {
|
|
436
816
|
const client = useFluxbaseClient();
|
|
437
|
-
return (0,
|
|
817
|
+
return (0, import_react_query8.useQuery)({
|
|
438
818
|
queryKey: ["fluxbase", "storage", bucket, "signed-url", path, expiresIn],
|
|
439
819
|
queryFn: async () => {
|
|
440
820
|
if (!path) {
|
|
@@ -451,10 +831,39 @@ function useStorageSignedUrl(bucket, path, expiresIn) {
|
|
|
451
831
|
// Refresh 1 minute before expiry
|
|
452
832
|
});
|
|
453
833
|
}
|
|
834
|
+
function useStorageSignedUrlWithOptions(bucket, path, options) {
|
|
835
|
+
const client = useFluxbaseClient();
|
|
836
|
+
const expiresIn = options?.expiresIn;
|
|
837
|
+
const transformKey = options?.transform ? JSON.stringify(options.transform) : null;
|
|
838
|
+
return (0, import_react_query8.useQuery)({
|
|
839
|
+
queryKey: [
|
|
840
|
+
"fluxbase",
|
|
841
|
+
"storage",
|
|
842
|
+
bucket,
|
|
843
|
+
"signed-url",
|
|
844
|
+
path,
|
|
845
|
+
expiresIn,
|
|
846
|
+
transformKey
|
|
847
|
+
],
|
|
848
|
+
queryFn: async () => {
|
|
849
|
+
if (!path) {
|
|
850
|
+
return null;
|
|
851
|
+
}
|
|
852
|
+
const { data, error } = await client.storage.from(bucket).createSignedUrl(path, options);
|
|
853
|
+
if (error) {
|
|
854
|
+
throw error;
|
|
855
|
+
}
|
|
856
|
+
return data?.signedUrl || null;
|
|
857
|
+
},
|
|
858
|
+
enabled: !!path,
|
|
859
|
+
staleTime: expiresIn ? expiresIn * 1e3 - 6e4 : 1e3 * 60 * 50
|
|
860
|
+
// Refresh 1 minute before expiry
|
|
861
|
+
});
|
|
862
|
+
}
|
|
454
863
|
function useStorageMove(bucket) {
|
|
455
864
|
const client = useFluxbaseClient();
|
|
456
|
-
const queryClient = (0,
|
|
457
|
-
return (0,
|
|
865
|
+
const queryClient = (0, import_react_query8.useQueryClient)();
|
|
866
|
+
return (0, import_react_query8.useMutation)({
|
|
458
867
|
mutationFn: async (params) => {
|
|
459
868
|
const { fromPath, toPath } = params;
|
|
460
869
|
const { data, error } = await client.storage.from(bucket).move(fromPath, toPath);
|
|
@@ -464,14 +873,16 @@ function useStorageMove(bucket) {
|
|
|
464
873
|
return data;
|
|
465
874
|
},
|
|
466
875
|
onSuccess: () => {
|
|
467
|
-
queryClient.invalidateQueries({
|
|
876
|
+
queryClient.invalidateQueries({
|
|
877
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
878
|
+
});
|
|
468
879
|
}
|
|
469
880
|
});
|
|
470
881
|
}
|
|
471
882
|
function useStorageCopy(bucket) {
|
|
472
883
|
const client = useFluxbaseClient();
|
|
473
|
-
const queryClient = (0,
|
|
474
|
-
return (0,
|
|
884
|
+
const queryClient = (0, import_react_query8.useQueryClient)();
|
|
885
|
+
return (0, import_react_query8.useMutation)({
|
|
475
886
|
mutationFn: async (params) => {
|
|
476
887
|
const { fromPath, toPath } = params;
|
|
477
888
|
const { data, error } = await client.storage.from(bucket).copy(fromPath, toPath);
|
|
@@ -481,13 +892,15 @@ function useStorageCopy(bucket) {
|
|
|
481
892
|
return data;
|
|
482
893
|
},
|
|
483
894
|
onSuccess: () => {
|
|
484
|
-
queryClient.invalidateQueries({
|
|
895
|
+
queryClient.invalidateQueries({
|
|
896
|
+
queryKey: ["fluxbase", "storage", bucket, "list"]
|
|
897
|
+
});
|
|
485
898
|
}
|
|
486
899
|
});
|
|
487
900
|
}
|
|
488
901
|
function useStorageBuckets() {
|
|
489
902
|
const client = useFluxbaseClient();
|
|
490
|
-
return (0,
|
|
903
|
+
return (0, import_react_query8.useQuery)({
|
|
491
904
|
queryKey: ["fluxbase", "storage", "buckets"],
|
|
492
905
|
queryFn: async () => {
|
|
493
906
|
const { data, error } = await client.storage.listBuckets();
|
|
@@ -500,8 +913,8 @@ function useStorageBuckets() {
|
|
|
500
913
|
}
|
|
501
914
|
function useCreateBucket() {
|
|
502
915
|
const client = useFluxbaseClient();
|
|
503
|
-
const queryClient = (0,
|
|
504
|
-
return (0,
|
|
916
|
+
const queryClient = (0, import_react_query8.useQueryClient)();
|
|
917
|
+
return (0, import_react_query8.useMutation)({
|
|
505
918
|
mutationFn: async (bucketName) => {
|
|
506
919
|
const { error } = await client.storage.createBucket(bucketName);
|
|
507
920
|
if (error) {
|
|
@@ -509,14 +922,16 @@ function useCreateBucket() {
|
|
|
509
922
|
}
|
|
510
923
|
},
|
|
511
924
|
onSuccess: () => {
|
|
512
|
-
queryClient.invalidateQueries({
|
|
925
|
+
queryClient.invalidateQueries({
|
|
926
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
927
|
+
});
|
|
513
928
|
}
|
|
514
929
|
});
|
|
515
930
|
}
|
|
516
931
|
function useDeleteBucket() {
|
|
517
932
|
const client = useFluxbaseClient();
|
|
518
|
-
const queryClient = (0,
|
|
519
|
-
return (0,
|
|
933
|
+
const queryClient = (0, import_react_query8.useQueryClient)();
|
|
934
|
+
return (0, import_react_query8.useMutation)({
|
|
520
935
|
mutationFn: async (bucketName) => {
|
|
521
936
|
const { error } = await client.storage.deleteBucket(bucketName);
|
|
522
937
|
if (error) {
|
|
@@ -524,74 +939,30 @@ function useDeleteBucket() {
|
|
|
524
939
|
}
|
|
525
940
|
},
|
|
526
941
|
onSuccess: () => {
|
|
527
|
-
queryClient.invalidateQueries({
|
|
942
|
+
queryClient.invalidateQueries({
|
|
943
|
+
queryKey: ["fluxbase", "storage", "buckets"]
|
|
944
|
+
});
|
|
528
945
|
}
|
|
529
946
|
});
|
|
530
947
|
}
|
|
531
948
|
|
|
532
|
-
// src/use-rpc.ts
|
|
533
|
-
var import_react_query5 = require("@tanstack/react-query");
|
|
534
|
-
function useRPC(functionName, params, options) {
|
|
535
|
-
const client = useFluxbaseClient();
|
|
536
|
-
return (0, import_react_query5.useQuery)({
|
|
537
|
-
queryKey: ["rpc", functionName, params],
|
|
538
|
-
queryFn: async () => {
|
|
539
|
-
const { data, error } = await client.rpc(functionName, params);
|
|
540
|
-
if (error) {
|
|
541
|
-
throw new Error(error.message);
|
|
542
|
-
}
|
|
543
|
-
return data;
|
|
544
|
-
},
|
|
545
|
-
...options
|
|
546
|
-
});
|
|
547
|
-
}
|
|
548
|
-
function useRPCMutation(functionName, options) {
|
|
549
|
-
const client = useFluxbaseClient();
|
|
550
|
-
return (0, import_react_query5.useMutation)({
|
|
551
|
-
mutationFn: async (params) => {
|
|
552
|
-
const { data, error } = await client.rpc(functionName, params);
|
|
553
|
-
if (error) {
|
|
554
|
-
throw new Error(error.message);
|
|
555
|
-
}
|
|
556
|
-
return data;
|
|
557
|
-
},
|
|
558
|
-
...options
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
function useRPCBatch(calls, options) {
|
|
562
|
-
const client = useFluxbaseClient();
|
|
563
|
-
return (0, import_react_query5.useQuery)({
|
|
564
|
-
queryKey: ["rpc-batch", calls],
|
|
565
|
-
queryFn: async () => {
|
|
566
|
-
const results = await Promise.all(
|
|
567
|
-
calls.map(async ({ name, params }) => {
|
|
568
|
-
const { data, error } = await client.rpc(name, params);
|
|
569
|
-
if (error) {
|
|
570
|
-
throw new Error(`${name}: ${error.message}`);
|
|
571
|
-
}
|
|
572
|
-
return data;
|
|
573
|
-
})
|
|
574
|
-
);
|
|
575
|
-
return results;
|
|
576
|
-
},
|
|
577
|
-
...options
|
|
578
|
-
});
|
|
579
|
-
}
|
|
580
|
-
|
|
581
949
|
// src/use-admin-auth.ts
|
|
582
|
-
var
|
|
950
|
+
var import_react5 = require("react");
|
|
583
951
|
function useAdminAuth(options = {}) {
|
|
584
952
|
const { autoCheck = true } = options;
|
|
585
953
|
const client = useFluxbaseClient();
|
|
586
|
-
const [user, setUser] = (0,
|
|
587
|
-
const [isLoading, setIsLoading] = (0,
|
|
588
|
-
const [error, setError] = (0,
|
|
589
|
-
const checkAuth = (0,
|
|
954
|
+
const [user, setUser] = (0, import_react5.useState)(null);
|
|
955
|
+
const [isLoading, setIsLoading] = (0, import_react5.useState)(autoCheck);
|
|
956
|
+
const [error, setError] = (0, import_react5.useState)(null);
|
|
957
|
+
const checkAuth = (0, import_react5.useCallback)(async () => {
|
|
590
958
|
try {
|
|
591
959
|
setIsLoading(true);
|
|
592
960
|
setError(null);
|
|
593
|
-
const {
|
|
594
|
-
|
|
961
|
+
const { data, error: apiError } = await client.admin.me();
|
|
962
|
+
if (apiError) {
|
|
963
|
+
throw apiError;
|
|
964
|
+
}
|
|
965
|
+
setUser(data.user);
|
|
595
966
|
} catch (err) {
|
|
596
967
|
setUser(null);
|
|
597
968
|
setError(err);
|
|
@@ -599,14 +970,20 @@ function useAdminAuth(options = {}) {
|
|
|
599
970
|
setIsLoading(false);
|
|
600
971
|
}
|
|
601
972
|
}, [client]);
|
|
602
|
-
const login = (0,
|
|
973
|
+
const login = (0, import_react5.useCallback)(
|
|
603
974
|
async (email, password) => {
|
|
604
975
|
try {
|
|
605
976
|
setIsLoading(true);
|
|
606
977
|
setError(null);
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
978
|
+
const { data, error: apiError } = await client.admin.login({
|
|
979
|
+
email,
|
|
980
|
+
password
|
|
981
|
+
});
|
|
982
|
+
if (apiError) {
|
|
983
|
+
throw apiError;
|
|
984
|
+
}
|
|
985
|
+
setUser(data.user);
|
|
986
|
+
return data;
|
|
610
987
|
} catch (err) {
|
|
611
988
|
setError(err);
|
|
612
989
|
throw err;
|
|
@@ -616,7 +993,7 @@ function useAdminAuth(options = {}) {
|
|
|
616
993
|
},
|
|
617
994
|
[client]
|
|
618
995
|
);
|
|
619
|
-
const logout = (0,
|
|
996
|
+
const logout = (0, import_react5.useCallback)(async () => {
|
|
620
997
|
try {
|
|
621
998
|
setIsLoading(true);
|
|
622
999
|
setError(null);
|
|
@@ -628,10 +1005,10 @@ function useAdminAuth(options = {}) {
|
|
|
628
1005
|
setIsLoading(false);
|
|
629
1006
|
}
|
|
630
1007
|
}, []);
|
|
631
|
-
const refresh = (0,
|
|
1008
|
+
const refresh = (0, import_react5.useCallback)(async () => {
|
|
632
1009
|
await checkAuth();
|
|
633
1010
|
}, [checkAuth]);
|
|
634
|
-
(0,
|
|
1011
|
+
(0, import_react5.useEffect)(() => {
|
|
635
1012
|
if (autoCheck) {
|
|
636
1013
|
checkAuth();
|
|
637
1014
|
}
|
|
@@ -648,60 +1025,67 @@ function useAdminAuth(options = {}) {
|
|
|
648
1025
|
}
|
|
649
1026
|
|
|
650
1027
|
// src/use-users.ts
|
|
651
|
-
var
|
|
1028
|
+
var import_react6 = require("react");
|
|
652
1029
|
function useUsers(options = {}) {
|
|
653
1030
|
const { autoFetch = true, refetchInterval = 0, ...listOptions } = options;
|
|
654
1031
|
const client = useFluxbaseClient();
|
|
655
|
-
const [users, setUsers] = (0,
|
|
656
|
-
const [total, setTotal] = (0,
|
|
657
|
-
const [isLoading, setIsLoading] = (0,
|
|
658
|
-
const [error, setError] = (0,
|
|
659
|
-
const fetchUsers = (0,
|
|
1032
|
+
const [users, setUsers] = (0, import_react6.useState)([]);
|
|
1033
|
+
const [total, setTotal] = (0, import_react6.useState)(0);
|
|
1034
|
+
const [isLoading, setIsLoading] = (0, import_react6.useState)(autoFetch);
|
|
1035
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
1036
|
+
const fetchUsers = (0, import_react6.useCallback)(async () => {
|
|
660
1037
|
try {
|
|
661
1038
|
setIsLoading(true);
|
|
662
1039
|
setError(null);
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
|
|
1040
|
+
const { data, error: apiError } = await client.admin.listUsers(listOptions);
|
|
1041
|
+
if (apiError) {
|
|
1042
|
+
throw apiError;
|
|
1043
|
+
}
|
|
1044
|
+
setUsers(data.users);
|
|
1045
|
+
setTotal(data.total);
|
|
666
1046
|
} catch (err) {
|
|
667
1047
|
setError(err);
|
|
668
1048
|
} finally {
|
|
669
1049
|
setIsLoading(false);
|
|
670
1050
|
}
|
|
671
1051
|
}, [client, JSON.stringify(listOptions)]);
|
|
672
|
-
const inviteUser = (0,
|
|
1052
|
+
const inviteUser = (0, import_react6.useCallback)(
|
|
673
1053
|
async (email, role) => {
|
|
674
1054
|
await client.admin.inviteUser({ email, role });
|
|
675
1055
|
await fetchUsers();
|
|
676
1056
|
},
|
|
677
1057
|
[client, fetchUsers]
|
|
678
1058
|
);
|
|
679
|
-
const updateUserRole = (0,
|
|
1059
|
+
const updateUserRole = (0, import_react6.useCallback)(
|
|
680
1060
|
async (userId, role) => {
|
|
681
1061
|
await client.admin.updateUserRole(userId, role);
|
|
682
1062
|
await fetchUsers();
|
|
683
1063
|
},
|
|
684
1064
|
[client, fetchUsers]
|
|
685
1065
|
);
|
|
686
|
-
const deleteUser = (0,
|
|
1066
|
+
const deleteUser = (0, import_react6.useCallback)(
|
|
687
1067
|
async (userId) => {
|
|
688
1068
|
await client.admin.deleteUser(userId);
|
|
689
1069
|
await fetchUsers();
|
|
690
1070
|
},
|
|
691
1071
|
[client, fetchUsers]
|
|
692
1072
|
);
|
|
693
|
-
const resetPassword = (0,
|
|
1073
|
+
const resetPassword = (0, import_react6.useCallback)(
|
|
694
1074
|
async (userId) => {
|
|
695
|
-
|
|
1075
|
+
const { data, error: error2 } = await client.admin.resetUserPassword(userId);
|
|
1076
|
+
if (error2) {
|
|
1077
|
+
throw error2;
|
|
1078
|
+
}
|
|
1079
|
+
return data;
|
|
696
1080
|
},
|
|
697
1081
|
[client]
|
|
698
1082
|
);
|
|
699
|
-
(0,
|
|
1083
|
+
(0, import_react6.useEffect)(() => {
|
|
700
1084
|
if (autoFetch) {
|
|
701
1085
|
fetchUsers();
|
|
702
1086
|
}
|
|
703
1087
|
}, [autoFetch, fetchUsers]);
|
|
704
|
-
(0,
|
|
1088
|
+
(0, import_react6.useEffect)(() => {
|
|
705
1089
|
if (refetchInterval > 0) {
|
|
706
1090
|
const interval = setInterval(fetchUsers, refetchInterval);
|
|
707
1091
|
return () => clearInterval(interval);
|
|
@@ -720,56 +1104,56 @@ function useUsers(options = {}) {
|
|
|
720
1104
|
};
|
|
721
1105
|
}
|
|
722
1106
|
|
|
723
|
-
// src/use-
|
|
724
|
-
var
|
|
725
|
-
function
|
|
1107
|
+
// src/use-client-keys.ts
|
|
1108
|
+
var import_react7 = require("react");
|
|
1109
|
+
function useClientKeys(options = {}) {
|
|
726
1110
|
const { autoFetch = true } = options;
|
|
727
1111
|
const client = useFluxbaseClient();
|
|
728
|
-
const [keys, setKeys] = (0,
|
|
729
|
-
const [isLoading, setIsLoading] = (0,
|
|
730
|
-
const [error, setError] = (0,
|
|
731
|
-
const fetchKeys = (0,
|
|
1112
|
+
const [keys, setKeys] = (0, import_react7.useState)([]);
|
|
1113
|
+
const [isLoading, setIsLoading] = (0, import_react7.useState)(autoFetch);
|
|
1114
|
+
const [error, setError] = (0, import_react7.useState)(null);
|
|
1115
|
+
const fetchKeys = (0, import_react7.useCallback)(async () => {
|
|
732
1116
|
try {
|
|
733
1117
|
setIsLoading(true);
|
|
734
1118
|
setError(null);
|
|
735
|
-
const response = await client.admin.management.
|
|
736
|
-
setKeys(response.
|
|
1119
|
+
const response = await client.admin.management.clientKeys.list();
|
|
1120
|
+
setKeys(response.client_keys);
|
|
737
1121
|
} catch (err) {
|
|
738
1122
|
setError(err);
|
|
739
1123
|
} finally {
|
|
740
1124
|
setIsLoading(false);
|
|
741
1125
|
}
|
|
742
1126
|
}, [client]);
|
|
743
|
-
const createKey = (0,
|
|
1127
|
+
const createKey = (0, import_react7.useCallback)(
|
|
744
1128
|
async (request) => {
|
|
745
|
-
const response = await client.admin.management.
|
|
1129
|
+
const response = await client.admin.management.clientKeys.create(request);
|
|
746
1130
|
await fetchKeys();
|
|
747
|
-
return { key: response.key, keyData: response.
|
|
1131
|
+
return { key: response.key, keyData: response.client_key };
|
|
748
1132
|
},
|
|
749
1133
|
[client, fetchKeys]
|
|
750
1134
|
);
|
|
751
|
-
const updateKey = (0,
|
|
1135
|
+
const updateKey = (0, import_react7.useCallback)(
|
|
752
1136
|
async (keyId, update) => {
|
|
753
|
-
await client.admin.management.
|
|
1137
|
+
await client.admin.management.clientKeys.update(keyId, update);
|
|
754
1138
|
await fetchKeys();
|
|
755
1139
|
},
|
|
756
1140
|
[client, fetchKeys]
|
|
757
1141
|
);
|
|
758
|
-
const revokeKey = (0,
|
|
1142
|
+
const revokeKey = (0, import_react7.useCallback)(
|
|
759
1143
|
async (keyId) => {
|
|
760
|
-
await client.admin.management.
|
|
1144
|
+
await client.admin.management.clientKeys.revoke(keyId);
|
|
761
1145
|
await fetchKeys();
|
|
762
1146
|
},
|
|
763
1147
|
[client, fetchKeys]
|
|
764
1148
|
);
|
|
765
|
-
const deleteKey = (0,
|
|
1149
|
+
const deleteKey = (0, import_react7.useCallback)(
|
|
766
1150
|
async (keyId) => {
|
|
767
|
-
await client.admin.management.
|
|
1151
|
+
await client.admin.management.clientKeys.delete(keyId);
|
|
768
1152
|
await fetchKeys();
|
|
769
1153
|
},
|
|
770
1154
|
[client, fetchKeys]
|
|
771
1155
|
);
|
|
772
|
-
(0,
|
|
1156
|
+
(0, import_react7.useEffect)(() => {
|
|
773
1157
|
if (autoFetch) {
|
|
774
1158
|
fetchKeys();
|
|
775
1159
|
}
|
|
@@ -785,16 +1169,17 @@ function useAPIKeys(options = {}) {
|
|
|
785
1169
|
deleteKey
|
|
786
1170
|
};
|
|
787
1171
|
}
|
|
1172
|
+
var useAPIKeys = useClientKeys;
|
|
788
1173
|
|
|
789
1174
|
// src/use-admin-hooks.ts
|
|
790
|
-
var
|
|
1175
|
+
var import_react8 = require("react");
|
|
791
1176
|
function useAppSettings(options = {}) {
|
|
792
1177
|
const { autoFetch = true } = options;
|
|
793
1178
|
const client = useFluxbaseClient();
|
|
794
|
-
const [settings, setSettings] = (0,
|
|
795
|
-
const [isLoading, setIsLoading] = (0,
|
|
796
|
-
const [error, setError] = (0,
|
|
797
|
-
const fetchSettings = (0,
|
|
1179
|
+
const [settings, setSettings] = (0, import_react8.useState)(null);
|
|
1180
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(autoFetch);
|
|
1181
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
1182
|
+
const fetchSettings = (0, import_react8.useCallback)(async () => {
|
|
798
1183
|
try {
|
|
799
1184
|
setIsLoading(true);
|
|
800
1185
|
setError(null);
|
|
@@ -806,14 +1191,14 @@ function useAppSettings(options = {}) {
|
|
|
806
1191
|
setIsLoading(false);
|
|
807
1192
|
}
|
|
808
1193
|
}, [client]);
|
|
809
|
-
const updateSettings = (0,
|
|
1194
|
+
const updateSettings = (0, import_react8.useCallback)(
|
|
810
1195
|
async (update) => {
|
|
811
1196
|
await client.admin.settings.app.update(update);
|
|
812
1197
|
await fetchSettings();
|
|
813
1198
|
},
|
|
814
1199
|
[client, fetchSettings]
|
|
815
1200
|
);
|
|
816
|
-
(0,
|
|
1201
|
+
(0, import_react8.useEffect)(() => {
|
|
817
1202
|
if (autoFetch) {
|
|
818
1203
|
fetchSettings();
|
|
819
1204
|
}
|
|
@@ -829,10 +1214,10 @@ function useAppSettings(options = {}) {
|
|
|
829
1214
|
function useSystemSettings(options = {}) {
|
|
830
1215
|
const { autoFetch = true } = options;
|
|
831
1216
|
const client = useFluxbaseClient();
|
|
832
|
-
const [settings, setSettings] = (0,
|
|
833
|
-
const [isLoading, setIsLoading] = (0,
|
|
834
|
-
const [error, setError] = (0,
|
|
835
|
-
const fetchSettings = (0,
|
|
1217
|
+
const [settings, setSettings] = (0, import_react8.useState)([]);
|
|
1218
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(autoFetch);
|
|
1219
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
1220
|
+
const fetchSettings = (0, import_react8.useCallback)(async () => {
|
|
836
1221
|
try {
|
|
837
1222
|
setIsLoading(true);
|
|
838
1223
|
setError(null);
|
|
@@ -844,27 +1229,27 @@ function useSystemSettings(options = {}) {
|
|
|
844
1229
|
setIsLoading(false);
|
|
845
1230
|
}
|
|
846
1231
|
}, [client]);
|
|
847
|
-
const getSetting = (0,
|
|
1232
|
+
const getSetting = (0, import_react8.useCallback)(
|
|
848
1233
|
(key) => {
|
|
849
1234
|
return settings.find((s) => s.key === key);
|
|
850
1235
|
},
|
|
851
1236
|
[settings]
|
|
852
1237
|
);
|
|
853
|
-
const updateSetting = (0,
|
|
1238
|
+
const updateSetting = (0, import_react8.useCallback)(
|
|
854
1239
|
async (key, update) => {
|
|
855
1240
|
await client.admin.settings.system.update(key, update);
|
|
856
1241
|
await fetchSettings();
|
|
857
1242
|
},
|
|
858
1243
|
[client, fetchSettings]
|
|
859
1244
|
);
|
|
860
|
-
const deleteSetting = (0,
|
|
1245
|
+
const deleteSetting = (0, import_react8.useCallback)(
|
|
861
1246
|
async (key) => {
|
|
862
1247
|
await client.admin.settings.system.delete(key);
|
|
863
1248
|
await fetchSettings();
|
|
864
1249
|
},
|
|
865
1250
|
[client, fetchSettings]
|
|
866
1251
|
);
|
|
867
|
-
(0,
|
|
1252
|
+
(0, import_react8.useEffect)(() => {
|
|
868
1253
|
if (autoFetch) {
|
|
869
1254
|
fetchSettings();
|
|
870
1255
|
}
|
|
@@ -882,10 +1267,10 @@ function useSystemSettings(options = {}) {
|
|
|
882
1267
|
function useWebhooks(options = {}) {
|
|
883
1268
|
const { autoFetch = true, refetchInterval = 0 } = options;
|
|
884
1269
|
const client = useFluxbaseClient();
|
|
885
|
-
const [webhooks, setWebhooks] = (0,
|
|
886
|
-
const [isLoading, setIsLoading] = (0,
|
|
887
|
-
const [error, setError] = (0,
|
|
888
|
-
const fetchWebhooks = (0,
|
|
1270
|
+
const [webhooks, setWebhooks] = (0, import_react8.useState)([]);
|
|
1271
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(autoFetch);
|
|
1272
|
+
const [error, setError] = (0, import_react8.useState)(null);
|
|
1273
|
+
const fetchWebhooks = (0, import_react8.useCallback)(async () => {
|
|
889
1274
|
try {
|
|
890
1275
|
setIsLoading(true);
|
|
891
1276
|
setError(null);
|
|
@@ -897,7 +1282,7 @@ function useWebhooks(options = {}) {
|
|
|
897
1282
|
setIsLoading(false);
|
|
898
1283
|
}
|
|
899
1284
|
}, [client]);
|
|
900
|
-
const createWebhook = (0,
|
|
1285
|
+
const createWebhook = (0, import_react8.useCallback)(
|
|
901
1286
|
async (webhook) => {
|
|
902
1287
|
const created = await client.admin.management.webhooks.create(webhook);
|
|
903
1288
|
await fetchWebhooks();
|
|
@@ -905,7 +1290,7 @@ function useWebhooks(options = {}) {
|
|
|
905
1290
|
},
|
|
906
1291
|
[client, fetchWebhooks]
|
|
907
1292
|
);
|
|
908
|
-
const updateWebhook = (0,
|
|
1293
|
+
const updateWebhook = (0, import_react8.useCallback)(
|
|
909
1294
|
async (id, update) => {
|
|
910
1295
|
const updated = await client.admin.management.webhooks.update(id, update);
|
|
911
1296
|
await fetchWebhooks();
|
|
@@ -913,20 +1298,20 @@ function useWebhooks(options = {}) {
|
|
|
913
1298
|
},
|
|
914
1299
|
[client, fetchWebhooks]
|
|
915
1300
|
);
|
|
916
|
-
const deleteWebhook = (0,
|
|
1301
|
+
const deleteWebhook = (0, import_react8.useCallback)(
|
|
917
1302
|
async (id) => {
|
|
918
1303
|
await client.admin.management.webhooks.delete(id);
|
|
919
1304
|
await fetchWebhooks();
|
|
920
1305
|
},
|
|
921
1306
|
[client, fetchWebhooks]
|
|
922
1307
|
);
|
|
923
|
-
const testWebhook = (0,
|
|
1308
|
+
const testWebhook = (0, import_react8.useCallback)(
|
|
924
1309
|
async (id) => {
|
|
925
1310
|
await client.admin.management.webhooks.test(id);
|
|
926
1311
|
},
|
|
927
1312
|
[client]
|
|
928
1313
|
);
|
|
929
|
-
(0,
|
|
1314
|
+
(0, import_react8.useEffect)(() => {
|
|
930
1315
|
if (autoFetch) {
|
|
931
1316
|
fetchWebhooks();
|
|
932
1317
|
}
|
|
@@ -949,22 +1334,33 @@ function useWebhooks(options = {}) {
|
|
|
949
1334
|
// Annotate the CommonJS export names for ESM import in node:
|
|
950
1335
|
0 && (module.exports = {
|
|
951
1336
|
FluxbaseProvider,
|
|
1337
|
+
isCaptchaRequiredForEndpoint,
|
|
952
1338
|
useAPIKeys,
|
|
953
1339
|
useAdminAuth,
|
|
954
1340
|
useAppSettings,
|
|
955
1341
|
useAuth,
|
|
1342
|
+
useAuthConfig,
|
|
1343
|
+
useCaptcha,
|
|
1344
|
+
useCaptchaConfig,
|
|
1345
|
+
useClientKeys,
|
|
956
1346
|
useCreateBucket,
|
|
957
1347
|
useDelete,
|
|
958
1348
|
useDeleteBucket,
|
|
959
1349
|
useFluxbaseClient,
|
|
960
1350
|
useFluxbaseQuery,
|
|
1351
|
+
useGetSAMLLoginUrl,
|
|
1352
|
+
useGraphQL,
|
|
1353
|
+
useGraphQLIntrospection,
|
|
1354
|
+
useGraphQLMutation,
|
|
1355
|
+
useGraphQLQuery,
|
|
1356
|
+
useHandleSAMLCallback,
|
|
961
1357
|
useInsert,
|
|
962
|
-
useRPC,
|
|
963
|
-
useRPCBatch,
|
|
964
|
-
useRPCMutation,
|
|
965
1358
|
useRealtime,
|
|
1359
|
+
useSAMLMetadataUrl,
|
|
1360
|
+
useSAMLProviders,
|
|
966
1361
|
useSession,
|
|
967
1362
|
useSignIn,
|
|
1363
|
+
useSignInWithSAML,
|
|
968
1364
|
useSignOut,
|
|
969
1365
|
useSignUp,
|
|
970
1366
|
useStorageBuckets,
|
|
@@ -975,7 +1371,10 @@ function useWebhooks(options = {}) {
|
|
|
975
1371
|
useStorageMove,
|
|
976
1372
|
useStoragePublicUrl,
|
|
977
1373
|
useStorageSignedUrl,
|
|
1374
|
+
useStorageSignedUrlWithOptions,
|
|
1375
|
+
useStorageTransformUrl,
|
|
978
1376
|
useStorageUpload,
|
|
1377
|
+
useStorageUploadWithProgress,
|
|
979
1378
|
useSystemSettings,
|
|
980
1379
|
useTable,
|
|
981
1380
|
useTableDeletes,
|