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