@nimbleflux/fluxbase-sdk-react 2026.3.6 → 2026.3.7-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -1
- package/package.json +10 -10
- package/src/index.ts +15 -0
- package/src/use-admin-auth.ts +1 -1
- package/src/use-admin-hooks.ts +122 -113
- package/src/use-auth-config.ts +1 -1
- package/src/use-auth.ts +1 -1
- package/src/use-captcha.ts +2 -2
- package/src/use-client-keys.ts +66 -51
- package/src/use-graphql.ts +14 -9
- package/src/use-query.ts +73 -62
- package/src/use-realtime.ts +6 -2
- package/src/use-saml.ts +1 -1
- package/src/use-storage.ts +4 -2
- package/src/use-table-export.ts +178 -139
- package/src/use-tenant.ts +311 -0
- package/src/use-users.ts +56 -55
- package/tsconfig.json +1 -0
- package/tsup.config.ts +1 -1
package/src/use-client-keys.ts
CHANGED
|
@@ -1,55 +1,63 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback } from
|
|
2
|
-
import { useFluxbaseClient } from
|
|
3
|
-
import type {
|
|
1
|
+
import { useState, useEffect, useCallback } from "react";
|
|
2
|
+
import { useFluxbaseClient } from "./context";
|
|
3
|
+
import type {
|
|
4
|
+
ClientKey,
|
|
5
|
+
CreateClientKeyRequest,
|
|
6
|
+
} from "@nimbleflux/fluxbase-sdk";
|
|
4
7
|
|
|
5
8
|
export interface UseClientKeysOptions {
|
|
6
9
|
/**
|
|
7
10
|
* Whether to automatically fetch client keys on mount
|
|
8
11
|
* @default true
|
|
9
12
|
*/
|
|
10
|
-
autoFetch?: boolean
|
|
13
|
+
autoFetch?: boolean;
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export interface UseClientKeysReturn {
|
|
14
17
|
/**
|
|
15
18
|
* Array of client keys
|
|
16
19
|
*/
|
|
17
|
-
keys: ClientKey[]
|
|
20
|
+
keys: ClientKey[];
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
23
|
* Whether keys are being fetched
|
|
21
24
|
*/
|
|
22
|
-
isLoading: boolean
|
|
25
|
+
isLoading: boolean;
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* Any error that occurred
|
|
26
29
|
*/
|
|
27
|
-
error: Error | null
|
|
30
|
+
error: Error | null;
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
33
|
* Refetch client keys
|
|
31
34
|
*/
|
|
32
|
-
refetch: () => Promise<void
|
|
35
|
+
refetch: () => Promise<void>;
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* Create a new client key
|
|
36
39
|
*/
|
|
37
|
-
createKey: (
|
|
40
|
+
createKey: (
|
|
41
|
+
request: CreateClientKeyRequest,
|
|
42
|
+
) => Promise<{ key: string; keyData: ClientKey }>;
|
|
38
43
|
|
|
39
44
|
/**
|
|
40
45
|
* Update a client key
|
|
41
46
|
*/
|
|
42
|
-
updateKey: (
|
|
47
|
+
updateKey: (
|
|
48
|
+
keyId: string,
|
|
49
|
+
update: { name?: string; description?: string },
|
|
50
|
+
) => Promise<void>;
|
|
43
51
|
|
|
44
52
|
/**
|
|
45
53
|
* Revoke a client key
|
|
46
54
|
*/
|
|
47
|
-
revokeKey: (keyId: string) => Promise<void
|
|
55
|
+
revokeKey: (keyId: string) => Promise<void>;
|
|
48
56
|
|
|
49
57
|
/**
|
|
50
58
|
* Delete a client key
|
|
51
59
|
*/
|
|
52
|
-
deleteKey: (keyId: string) => Promise<void
|
|
60
|
+
deleteKey: (keyId: string) => Promise<void>;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
/**
|
|
@@ -85,81 +93,88 @@ export interface UseClientKeysReturn {
|
|
|
85
93
|
* }
|
|
86
94
|
* ```
|
|
87
95
|
*/
|
|
88
|
-
export function useClientKeys(
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
export function useClientKeys(
|
|
97
|
+
options: UseClientKeysOptions = {},
|
|
98
|
+
): UseClientKeysReturn {
|
|
99
|
+
const { autoFetch = true } = options;
|
|
100
|
+
const client = useFluxbaseClient();
|
|
91
101
|
|
|
92
|
-
const [keys, setKeys] = useState<ClientKey[]>([])
|
|
93
|
-
const [isLoading, setIsLoading] = useState(autoFetch)
|
|
94
|
-
const [error, setError] = useState<Error | null>(null)
|
|
102
|
+
const [keys, setKeys] = useState<ClientKey[]>([]);
|
|
103
|
+
const [isLoading, setIsLoading] = useState(autoFetch);
|
|
104
|
+
const [error, setError] = useState<Error | null>(null);
|
|
95
105
|
|
|
96
106
|
/**
|
|
97
107
|
* Fetch client keys from API
|
|
98
108
|
*/
|
|
99
109
|
const fetchKeys = useCallback(async () => {
|
|
100
110
|
try {
|
|
101
|
-
setIsLoading(true)
|
|
102
|
-
setError(null)
|
|
103
|
-
const response = await client.admin.management.clientKeys.list()
|
|
104
|
-
setKeys(response.client_keys)
|
|
111
|
+
setIsLoading(true);
|
|
112
|
+
setError(null);
|
|
113
|
+
const response = await client.admin.management.clientKeys.list();
|
|
114
|
+
setKeys(response.client_keys);
|
|
105
115
|
} catch (err) {
|
|
106
|
-
setError(err as Error)
|
|
116
|
+
setError(err as Error);
|
|
107
117
|
} finally {
|
|
108
|
-
setIsLoading(false)
|
|
118
|
+
setIsLoading(false);
|
|
109
119
|
}
|
|
110
|
-
}, [client])
|
|
120
|
+
}, [client]);
|
|
111
121
|
|
|
112
122
|
/**
|
|
113
123
|
* Create a new client key
|
|
114
124
|
*/
|
|
115
125
|
const createKey = useCallback(
|
|
116
|
-
async (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
async (
|
|
127
|
+
request: CreateClientKeyRequest,
|
|
128
|
+
): Promise<{ key: string; keyData: ClientKey }> => {
|
|
129
|
+
const response = await client.admin.management.clientKeys.create(request);
|
|
130
|
+
await fetchKeys(); // Refresh list
|
|
131
|
+
return { key: response.key, keyData: response.client_key };
|
|
120
132
|
},
|
|
121
|
-
[client, fetchKeys]
|
|
122
|
-
)
|
|
133
|
+
[client, fetchKeys],
|
|
134
|
+
);
|
|
123
135
|
|
|
124
136
|
/**
|
|
125
137
|
* Update a client key
|
|
126
138
|
*/
|
|
127
139
|
const updateKey = useCallback(
|
|
128
|
-
async (
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
async (
|
|
141
|
+
keyId: string,
|
|
142
|
+
update: { name?: string; description?: string },
|
|
143
|
+
): Promise<void> => {
|
|
144
|
+
await client.admin.management.clientKeys.update(keyId, update);
|
|
145
|
+
await fetchKeys(); // Refresh list
|
|
131
146
|
},
|
|
132
|
-
[client, fetchKeys]
|
|
133
|
-
)
|
|
147
|
+
[client, fetchKeys],
|
|
148
|
+
);
|
|
134
149
|
|
|
135
150
|
/**
|
|
136
151
|
* Revoke a client key
|
|
137
152
|
*/
|
|
138
153
|
const revokeKey = useCallback(
|
|
139
154
|
async (keyId: string): Promise<void> => {
|
|
140
|
-
await client.admin.management.clientKeys.revoke(keyId)
|
|
141
|
-
await fetchKeys() // Refresh list
|
|
155
|
+
await client.admin.management.clientKeys.revoke(keyId);
|
|
156
|
+
await fetchKeys(); // Refresh list
|
|
142
157
|
},
|
|
143
|
-
[client, fetchKeys]
|
|
144
|
-
)
|
|
158
|
+
[client, fetchKeys],
|
|
159
|
+
);
|
|
145
160
|
|
|
146
161
|
/**
|
|
147
162
|
* Delete a client key
|
|
148
163
|
*/
|
|
149
164
|
const deleteKey = useCallback(
|
|
150
165
|
async (keyId: string): Promise<void> => {
|
|
151
|
-
await client.admin.management.clientKeys.delete(keyId)
|
|
152
|
-
await fetchKeys() // Refresh list
|
|
166
|
+
await client.admin.management.clientKeys.delete(keyId);
|
|
167
|
+
await fetchKeys(); // Refresh list
|
|
153
168
|
},
|
|
154
|
-
[client, fetchKeys]
|
|
155
|
-
)
|
|
169
|
+
[client, fetchKeys],
|
|
170
|
+
);
|
|
156
171
|
|
|
157
172
|
// Auto-fetch on mount
|
|
158
173
|
useEffect(() => {
|
|
159
174
|
if (autoFetch) {
|
|
160
|
-
fetchKeys()
|
|
175
|
+
fetchKeys();
|
|
161
176
|
}
|
|
162
|
-
}, [autoFetch, fetchKeys])
|
|
177
|
+
}, [autoFetch, fetchKeys]);
|
|
163
178
|
|
|
164
179
|
return {
|
|
165
180
|
keys,
|
|
@@ -169,17 +184,17 @@ export function useClientKeys(options: UseClientKeysOptions = {}): UseClientKeys
|
|
|
169
184
|
createKey,
|
|
170
185
|
updateKey,
|
|
171
186
|
revokeKey,
|
|
172
|
-
deleteKey
|
|
173
|
-
}
|
|
187
|
+
deleteKey,
|
|
188
|
+
};
|
|
174
189
|
}
|
|
175
190
|
|
|
176
191
|
/**
|
|
177
192
|
* @deprecated Use useClientKeys instead
|
|
178
193
|
*/
|
|
179
|
-
export const useAPIKeys = useClientKeys
|
|
194
|
+
export const useAPIKeys = useClientKeys;
|
|
180
195
|
|
|
181
196
|
/** @deprecated Use UseClientKeysOptions instead */
|
|
182
|
-
export type UseAPIKeysOptions = UseClientKeysOptions
|
|
197
|
+
export type UseAPIKeysOptions = UseClientKeysOptions;
|
|
183
198
|
|
|
184
199
|
/** @deprecated Use UseClientKeysReturn instead */
|
|
185
|
-
export type UseAPIKeysReturn = UseClientKeysReturn
|
|
200
|
+
export type UseAPIKeysReturn = UseClientKeysReturn;
|
package/src/use-graphql.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```tsx
|
|
8
|
-
* import { useGraphQLQuery, useGraphQLMutation } from '@fluxbase
|
|
8
|
+
* import { useGraphQLQuery, useGraphQLMutation } from '@nimbleflux/fluxbase-sdk-react'
|
|
9
9
|
*
|
|
10
10
|
* function UsersList() {
|
|
11
11
|
* const { data, isLoading, error } = useGraphQLQuery<UsersQuery>(
|
|
@@ -33,7 +33,7 @@ import type {
|
|
|
33
33
|
GraphQLResponse,
|
|
34
34
|
GraphQLError,
|
|
35
35
|
GraphQLRequestOptions,
|
|
36
|
-
} from "@fluxbase
|
|
36
|
+
} from "@nimbleflux/fluxbase-sdk";
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* Options for useGraphQLQuery hook
|
|
@@ -152,7 +152,7 @@ export interface UseGraphQLMutationOptions<T, V> {
|
|
|
152
152
|
export function useGraphQLQuery<T = unknown>(
|
|
153
153
|
queryKey: string | readonly unknown[],
|
|
154
154
|
query: string,
|
|
155
|
-
options?: UseGraphQLQueryOptions<T
|
|
155
|
+
options?: UseGraphQLQueryOptions<T>,
|
|
156
156
|
) {
|
|
157
157
|
const client = useFluxbaseClient();
|
|
158
158
|
const normalizedKey = Array.isArray(queryKey)
|
|
@@ -166,7 +166,7 @@ export function useGraphQLQuery<T = unknown>(
|
|
|
166
166
|
query,
|
|
167
167
|
options?.variables,
|
|
168
168
|
options?.operationName,
|
|
169
|
-
options?.requestOptions
|
|
169
|
+
options?.requestOptions,
|
|
170
170
|
);
|
|
171
171
|
|
|
172
172
|
if (response.errors && response.errors.length > 0) {
|
|
@@ -241,7 +241,7 @@ export function useGraphQLMutation<
|
|
|
241
241
|
mutation,
|
|
242
242
|
variables,
|
|
243
243
|
options?.operationName,
|
|
244
|
-
options?.requestOptions
|
|
244
|
+
options?.requestOptions,
|
|
245
245
|
);
|
|
246
246
|
|
|
247
247
|
if (response.errors && response.errors.length > 0) {
|
|
@@ -354,7 +354,7 @@ export function useGraphQL() {
|
|
|
354
354
|
executeQuery: <T = unknown>(
|
|
355
355
|
query: string,
|
|
356
356
|
variables?: Record<string, unknown>,
|
|
357
|
-
options?: GraphQLRequestOptions
|
|
357
|
+
options?: GraphQLRequestOptions,
|
|
358
358
|
): Promise<GraphQLResponse<T>> => {
|
|
359
359
|
return client.graphql.query<T>(query, variables, options);
|
|
360
360
|
},
|
|
@@ -365,7 +365,7 @@ export function useGraphQL() {
|
|
|
365
365
|
executeMutation: <T = unknown>(
|
|
366
366
|
mutation: string,
|
|
367
367
|
variables?: Record<string, unknown>,
|
|
368
|
-
options?: GraphQLRequestOptions
|
|
368
|
+
options?: GraphQLRequestOptions,
|
|
369
369
|
): Promise<GraphQLResponse<T>> => {
|
|
370
370
|
return client.graphql.mutation<T>(mutation, variables, options);
|
|
371
371
|
},
|
|
@@ -377,9 +377,14 @@ export function useGraphQL() {
|
|
|
377
377
|
document: string,
|
|
378
378
|
variables?: Record<string, unknown>,
|
|
379
379
|
operationName?: string,
|
|
380
|
-
options?: GraphQLRequestOptions
|
|
380
|
+
options?: GraphQLRequestOptions,
|
|
381
381
|
): Promise<GraphQLResponse<T>> => {
|
|
382
|
-
return client.graphql.execute<T>(
|
|
382
|
+
return client.graphql.execute<T>(
|
|
383
|
+
document,
|
|
384
|
+
variables,
|
|
385
|
+
operationName,
|
|
386
|
+
options,
|
|
387
|
+
);
|
|
383
388
|
},
|
|
384
389
|
|
|
385
390
|
/**
|
package/src/use-query.ts
CHANGED
|
@@ -2,15 +2,23 @@
|
|
|
2
2
|
* Database query hooks for Fluxbase SDK
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import {
|
|
6
|
+
useQuery,
|
|
7
|
+
useMutation,
|
|
8
|
+
useQueryClient,
|
|
9
|
+
type UseQueryOptions,
|
|
10
|
+
} from "@tanstack/react-query";
|
|
11
|
+
import { useFluxbaseClient } from "./context";
|
|
12
|
+
import type { QueryBuilder } from "@nimbleflux/fluxbase-sdk";
|
|
13
|
+
|
|
14
|
+
export interface UseFluxbaseQueryOptions<T> extends Omit<
|
|
15
|
+
UseQueryOptions<T[], Error>,
|
|
16
|
+
"queryKey" | "queryFn"
|
|
17
|
+
> {
|
|
10
18
|
/**
|
|
11
19
|
* Custom query key. If not provided, will use table name and filters.
|
|
12
20
|
*/
|
|
13
|
-
queryKey?: unknown[]
|
|
21
|
+
queryKey?: unknown[];
|
|
14
22
|
}
|
|
15
23
|
|
|
16
24
|
/**
|
|
@@ -32,35 +40,35 @@ export interface UseFluxbaseQueryOptions<T> extends Omit<UseQueryOptions<T[], Er
|
|
|
32
40
|
*/
|
|
33
41
|
export function useFluxbaseQuery<T = any>(
|
|
34
42
|
buildQuery: (client: ReturnType<typeof useFluxbaseClient>) => QueryBuilder<T>,
|
|
35
|
-
options?: UseFluxbaseQueryOptions<T
|
|
43
|
+
options?: UseFluxbaseQueryOptions<T>,
|
|
36
44
|
) {
|
|
37
|
-
const client = useFluxbaseClient()
|
|
45
|
+
const client = useFluxbaseClient();
|
|
38
46
|
|
|
39
47
|
// Require queryKey for stable caching - function.toString() is not reliable
|
|
40
48
|
// as it can vary between renders for inline functions
|
|
41
49
|
if (!options?.queryKey) {
|
|
42
50
|
console.warn(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
51
|
+
"[useFluxbaseQuery] No queryKey provided. This may cause cache misses. " +
|
|
52
|
+
"Please provide a stable queryKey in options.",
|
|
53
|
+
);
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
const queryKey = options?.queryKey || [
|
|
56
|
+
const queryKey = options?.queryKey || ["fluxbase", "query", "unstable"];
|
|
49
57
|
|
|
50
58
|
return useQuery({
|
|
51
59
|
queryKey,
|
|
52
60
|
queryFn: async () => {
|
|
53
|
-
const query = buildQuery(client)
|
|
54
|
-
const { data, error } = await query.execute()
|
|
61
|
+
const query = buildQuery(client);
|
|
62
|
+
const { data, error } = await query.execute();
|
|
55
63
|
|
|
56
64
|
if (error) {
|
|
57
|
-
throw error
|
|
65
|
+
throw error;
|
|
58
66
|
}
|
|
59
67
|
|
|
60
|
-
return (Array.isArray(data) ? data : data ? [data] : []) as T[]
|
|
68
|
+
return (Array.isArray(data) ? data : data ? [data] : []) as T[];
|
|
61
69
|
},
|
|
62
70
|
...options,
|
|
63
|
-
})
|
|
71
|
+
});
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
/**
|
|
@@ -87,125 +95,128 @@ export function useFluxbaseQuery<T = any>(
|
|
|
87
95
|
export function useTable<T = any>(
|
|
88
96
|
table: string,
|
|
89
97
|
buildQuery?: (query: QueryBuilder<T>) => QueryBuilder<T>,
|
|
90
|
-
options?: UseFluxbaseQueryOptions<T
|
|
98
|
+
options?: UseFluxbaseQueryOptions<T>,
|
|
91
99
|
) {
|
|
92
|
-
const client = useFluxbaseClient()
|
|
93
|
-
|
|
94
100
|
// Generate a stable base queryKey from table name
|
|
95
101
|
// When buildQuery is provided without a custom queryKey, warn about potential cache issues
|
|
96
102
|
if (buildQuery && !options?.queryKey) {
|
|
97
103
|
console.warn(
|
|
98
104
|
`[useTable] Using buildQuery without a custom queryKey for table "${table}". ` +
|
|
99
|
-
|
|
100
|
-
)
|
|
105
|
+
"This may cause cache misses. Provide a queryKey that includes your filter values.",
|
|
106
|
+
);
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
return useFluxbaseQuery(
|
|
104
110
|
(client) => {
|
|
105
|
-
const query = client.from<T>(table)
|
|
106
|
-
return buildQuery ? buildQuery(query) : query
|
|
111
|
+
const query = client.from<T>(table);
|
|
112
|
+
return buildQuery ? buildQuery(query) : query;
|
|
107
113
|
},
|
|
108
114
|
{
|
|
109
115
|
...options,
|
|
110
116
|
// Use table name as base key, or custom key if provided
|
|
111
|
-
queryKey: options?.queryKey || [
|
|
112
|
-
}
|
|
113
|
-
)
|
|
117
|
+
queryKey: options?.queryKey || ["fluxbase", "table", table],
|
|
118
|
+
},
|
|
119
|
+
);
|
|
114
120
|
}
|
|
115
121
|
|
|
116
122
|
/**
|
|
117
123
|
* Hook to insert data into a table
|
|
118
124
|
*/
|
|
119
125
|
export function useInsert<T = any>(table: string) {
|
|
120
|
-
const client = useFluxbaseClient()
|
|
121
|
-
const queryClient = useQueryClient()
|
|
126
|
+
const client = useFluxbaseClient();
|
|
127
|
+
const queryClient = useQueryClient();
|
|
122
128
|
|
|
123
129
|
return useMutation({
|
|
124
130
|
mutationFn: async (data: Partial<T> | Partial<T>[]) => {
|
|
125
|
-
const query = client.from<T>(table)
|
|
126
|
-
const { data: result, error } = await query.insert(data as Partial<T>)
|
|
131
|
+
const query = client.from<T>(table);
|
|
132
|
+
const { data: result, error } = await query.insert(data as Partial<T>);
|
|
127
133
|
|
|
128
134
|
if (error) {
|
|
129
|
-
throw error
|
|
135
|
+
throw error;
|
|
130
136
|
}
|
|
131
137
|
|
|
132
|
-
return result
|
|
138
|
+
return result;
|
|
133
139
|
},
|
|
134
140
|
onSuccess: () => {
|
|
135
141
|
// Invalidate all queries for this table
|
|
136
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
142
|
+
queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
|
|
137
143
|
},
|
|
138
|
-
})
|
|
144
|
+
});
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
/**
|
|
142
148
|
* Hook to update data in a table
|
|
143
149
|
*/
|
|
144
150
|
export function useUpdate<T = any>(table: string) {
|
|
145
|
-
const client = useFluxbaseClient()
|
|
146
|
-
const queryClient = useQueryClient()
|
|
151
|
+
const client = useFluxbaseClient();
|
|
152
|
+
const queryClient = useQueryClient();
|
|
147
153
|
|
|
148
154
|
return useMutation({
|
|
149
|
-
mutationFn: async (params: {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
155
|
+
mutationFn: async (params: {
|
|
156
|
+
data: Partial<T>;
|
|
157
|
+
buildQuery: (query: QueryBuilder<T>) => QueryBuilder<T>;
|
|
158
|
+
}) => {
|
|
159
|
+
const query = client.from<T>(table);
|
|
160
|
+
const builtQuery = params.buildQuery(query);
|
|
161
|
+
const { data: result, error } = await builtQuery.update(params.data);
|
|
153
162
|
|
|
154
163
|
if (error) {
|
|
155
|
-
throw error
|
|
164
|
+
throw error;
|
|
156
165
|
}
|
|
157
166
|
|
|
158
|
-
return result
|
|
167
|
+
return result;
|
|
159
168
|
},
|
|
160
169
|
onSuccess: () => {
|
|
161
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
170
|
+
queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
|
|
162
171
|
},
|
|
163
|
-
})
|
|
172
|
+
});
|
|
164
173
|
}
|
|
165
174
|
|
|
166
175
|
/**
|
|
167
176
|
* Hook to upsert data into a table
|
|
168
177
|
*/
|
|
169
178
|
export function useUpsert<T = any>(table: string) {
|
|
170
|
-
const client = useFluxbaseClient()
|
|
171
|
-
const queryClient = useQueryClient()
|
|
179
|
+
const client = useFluxbaseClient();
|
|
180
|
+
const queryClient = useQueryClient();
|
|
172
181
|
|
|
173
182
|
return useMutation({
|
|
174
183
|
mutationFn: async (data: Partial<T> | Partial<T>[]) => {
|
|
175
|
-
const query = client.from<T>(table)
|
|
176
|
-
const { data: result, error } = await query.upsert(data as Partial<T>)
|
|
184
|
+
const query = client.from<T>(table);
|
|
185
|
+
const { data: result, error } = await query.upsert(data as Partial<T>);
|
|
177
186
|
|
|
178
187
|
if (error) {
|
|
179
|
-
throw error
|
|
188
|
+
throw error;
|
|
180
189
|
}
|
|
181
190
|
|
|
182
|
-
return result
|
|
191
|
+
return result;
|
|
183
192
|
},
|
|
184
193
|
onSuccess: () => {
|
|
185
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
194
|
+
queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
|
|
186
195
|
},
|
|
187
|
-
})
|
|
196
|
+
});
|
|
188
197
|
}
|
|
189
198
|
|
|
190
199
|
/**
|
|
191
200
|
* Hook to delete data from a table
|
|
192
201
|
*/
|
|
193
202
|
export function useDelete<T = any>(table: string) {
|
|
194
|
-
const client = useFluxbaseClient()
|
|
195
|
-
const queryClient = useQueryClient()
|
|
203
|
+
const client = useFluxbaseClient();
|
|
204
|
+
const queryClient = useQueryClient();
|
|
196
205
|
|
|
197
206
|
return useMutation({
|
|
198
|
-
mutationFn: async (
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
207
|
+
mutationFn: async (
|
|
208
|
+
buildQuery: (query: QueryBuilder<T>) => QueryBuilder<T>,
|
|
209
|
+
) => {
|
|
210
|
+
const query = client.from<T>(table);
|
|
211
|
+
const builtQuery = buildQuery(query);
|
|
212
|
+
const { error } = await builtQuery.delete();
|
|
202
213
|
|
|
203
214
|
if (error) {
|
|
204
|
-
throw error
|
|
215
|
+
throw error;
|
|
205
216
|
}
|
|
206
217
|
},
|
|
207
218
|
onSuccess: () => {
|
|
208
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
219
|
+
queryClient.invalidateQueries({ queryKey: ["fluxbase", "table", table] });
|
|
209
220
|
},
|
|
210
|
-
})
|
|
221
|
+
});
|
|
211
222
|
}
|
package/src/use-realtime.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { useFluxbaseClient } from "./context";
|
|
|
8
8
|
import type {
|
|
9
9
|
RealtimeCallback,
|
|
10
10
|
RealtimePostgresChangesPayload,
|
|
11
|
-
} from "@fluxbase
|
|
11
|
+
} from "@nimbleflux/fluxbase-sdk";
|
|
12
12
|
|
|
13
13
|
export interface UseRealtimeOptions {
|
|
14
14
|
/**
|
|
@@ -98,7 +98,11 @@ export function useRealtime(options: UseRealtimeOptions) {
|
|
|
98
98
|
// Extract table name from channel (e.g., 'table:public.products' -> 'public.products')
|
|
99
99
|
const tableName = channelName.replace(/^table:/, "");
|
|
100
100
|
|
|
101
|
-
const key = invalidateKeyRef.current || [
|
|
101
|
+
const key = invalidateKeyRef.current || [
|
|
102
|
+
"fluxbase",
|
|
103
|
+
"table",
|
|
104
|
+
tableName,
|
|
105
|
+
];
|
|
102
106
|
queryClient.invalidateQueries({ queryKey: key });
|
|
103
107
|
}
|
|
104
108
|
};
|
package/src/use-saml.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
6
6
|
import { useFluxbaseClient } from "./context";
|
|
7
|
-
import type { SAMLLoginOptions, SAMLProvider } from "@fluxbase
|
|
7
|
+
import type { SAMLLoginOptions, SAMLProvider } from "@nimbleflux/fluxbase-sdk";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Hook to get available SAML SSO providers
|
package/src/use-storage.ts
CHANGED
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
UploadProgress,
|
|
17
17
|
TransformOptions,
|
|
18
18
|
SignedUrlOptions,
|
|
19
|
-
} from "@fluxbase
|
|
19
|
+
} from "@nimbleflux/fluxbase-sdk";
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Hook to list files in a bucket
|
|
@@ -141,7 +141,9 @@ export function useStorageUploadWithProgress(bucket: string) {
|
|
|
141
141
|
.from(bucket)
|
|
142
142
|
.upload(path, file, {
|
|
143
143
|
...options,
|
|
144
|
-
onUploadProgress: (
|
|
144
|
+
onUploadProgress: (
|
|
145
|
+
p: import("@nimbleflux/fluxbase-sdk").UploadProgress,
|
|
146
|
+
) => {
|
|
145
147
|
setProgress(p);
|
|
146
148
|
},
|
|
147
149
|
});
|