@fluxbase/sdk-react 0.0.1-rc.2 → 0.0.1-rc.21

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/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
3
  import * as _fluxbase_sdk from '@fluxbase/sdk';
4
- import { FluxbaseClient, User, AuthSession, SignInCredentials, SignUpCredentials, QueryBuilder, RealtimeCallback, RealtimeChangePayload, ListOptions, UploadOptions, AdminAuthResponse, ListUsersOptions, EnrichedUser, APIKey, CreateAPIKeyRequest, Webhook, CreateWebhookRequest, UpdateWebhookRequest, AppSettings, UpdateAppSettingsRequest, SystemSetting, UpdateSystemSettingRequest } from '@fluxbase/sdk';
4
+ import { FluxbaseClient, AuthSession, SignInCredentials, SignUpCredentials, User, QueryBuilder, RealtimeCallback, RealtimePostgresChangesPayload, ListOptions, UploadOptions, AdminAuthResponse, ListUsersOptions, EnrichedUser, APIKey, CreateAPIKeyRequest, Webhook, CreateWebhookRequest, UpdateWebhookRequest, AppSettings, UpdateAppSettingsRequest, SystemSetting, UpdateSystemSettingRequest } from '@fluxbase/sdk';
5
5
  export { APIKey, AdminUser, AppSettings, AuthSession, EnrichedUser, FluxbaseClient, PostgrestResponse, RealtimeChangePayload, SignInCredentials, SignUpCredentials, StorageObject, SystemSetting, User, Webhook } from '@fluxbase/sdk';
6
6
  import * as _tanstack_react_query from '@tanstack/react-query';
7
7
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
@@ -23,7 +23,7 @@ declare function useFluxbaseClient(): FluxbaseClient;
23
23
  /**
24
24
  * Hook to get the current user
25
25
  */
26
- declare function useUser(): _tanstack_react_query.UseQueryResult<User | null, Error>;
26
+ declare function useUser(): _tanstack_react_query.UseQueryResult<_fluxbase_sdk.UserResponse | null, Error>;
27
27
  /**
28
28
  * Hook to get the current session
29
29
  */
@@ -31,11 +31,11 @@ declare function useSession(): _tanstack_react_query.UseQueryResult<AuthSession
31
31
  /**
32
32
  * Hook for signing in
33
33
  */
34
- declare function useSignIn(): _tanstack_react_query.UseMutationResult<AuthSession | _fluxbase_sdk.SignInWith2FAResponse, Error, SignInCredentials, unknown>;
34
+ declare function useSignIn(): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.FluxbaseResponse<AuthSession | _fluxbase_sdk.SignInWith2FAResponse>, Error, SignInCredentials, unknown>;
35
35
  /**
36
36
  * Hook for signing up
37
37
  */
38
- declare function useSignUp(): _tanstack_react_query.UseMutationResult<AuthSession, Error, SignUpCredentials, unknown>;
38
+ declare function useSignUp(): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.FluxbaseAuthResponse, Error, SignUpCredentials, unknown>;
39
39
  /**
40
40
  * Hook for signing out
41
41
  */
@@ -43,19 +43,19 @@ declare function useSignOut(): _tanstack_react_query.UseMutationResult<void, Err
43
43
  /**
44
44
  * Hook for updating the current user
45
45
  */
46
- declare function useUpdateUser(): _tanstack_react_query.UseMutationResult<User, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
46
+ declare function useUpdateUser(): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.UserResponse, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
47
47
  /**
48
48
  * Combined auth hook with all auth state and methods
49
49
  */
50
50
  declare function useAuth(): {
51
- user: User | null | undefined;
51
+ user: _fluxbase_sdk.UserResponse | null | undefined;
52
52
  session: AuthSession | null | undefined;
53
53
  isLoading: boolean;
54
54
  isAuthenticated: boolean;
55
- signIn: _tanstack_react_query.UseMutateAsyncFunction<AuthSession | _fluxbase_sdk.SignInWith2FAResponse, Error, SignInCredentials, unknown>;
56
- signUp: _tanstack_react_query.UseMutateAsyncFunction<AuthSession, Error, SignUpCredentials, unknown>;
55
+ signIn: _tanstack_react_query.UseMutateAsyncFunction<_fluxbase_sdk.FluxbaseResponse<AuthSession | _fluxbase_sdk.SignInWith2FAResponse>, Error, SignInCredentials, unknown>;
56
+ signUp: _tanstack_react_query.UseMutateAsyncFunction<_fluxbase_sdk.FluxbaseAuthResponse, Error, SignUpCredentials, unknown>;
57
57
  signOut: _tanstack_react_query.UseMutateAsyncFunction<void, Error, void, unknown>;
58
- updateUser: _tanstack_react_query.UseMutateAsyncFunction<User, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
58
+ updateUser: _tanstack_react_query.UseMutateAsyncFunction<_fluxbase_sdk.UserResponse, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
59
59
  isSigningIn: boolean;
60
60
  isSigningUp: boolean;
61
61
  isSigningOut: boolean;
@@ -108,7 +108,7 @@ interface UseRealtimeOptions {
108
108
  /**
109
109
  * Event type to listen for ('INSERT', 'UPDATE', 'DELETE', or '*' for all)
110
110
  */
111
- event?: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
111
+ event?: "INSERT" | "UPDATE" | "DELETE" | "*";
112
112
  /**
113
113
  * Callback function when an event is received
114
114
  */
@@ -140,25 +140,25 @@ declare function useRealtime(options: UseRealtimeOptions): {
140
140
  * @param table - Table name (with optional schema, e.g., 'public.products')
141
141
  * @param options - Subscription options
142
142
  */
143
- declare function useTableSubscription(table: string, options?: Omit<UseRealtimeOptions, 'channel'>): {
143
+ declare function useTableSubscription(table: string, options?: Omit<UseRealtimeOptions, "channel">): {
144
144
  channel: _fluxbase_sdk.RealtimeChannel | null;
145
145
  };
146
146
  /**
147
147
  * Hook to subscribe to INSERT events on a table
148
148
  */
149
- declare function useTableInserts(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
149
+ declare function useTableInserts(table: string, callback: (payload: RealtimePostgresChangesPayload) => void, options?: Omit<UseRealtimeOptions, "channel" | "event" | "callback">): {
150
150
  channel: _fluxbase_sdk.RealtimeChannel | null;
151
151
  };
152
152
  /**
153
153
  * Hook to subscribe to UPDATE events on a table
154
154
  */
155
- declare function useTableUpdates(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
155
+ declare function useTableUpdates(table: string, callback: (payload: RealtimePostgresChangesPayload) => void, options?: Omit<UseRealtimeOptions, "channel" | "event" | "callback">): {
156
156
  channel: _fluxbase_sdk.RealtimeChannel | null;
157
157
  };
158
158
  /**
159
159
  * Hook to subscribe to DELETE events on a table
160
160
  */
161
- declare function useTableDeletes(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
161
+ declare function useTableDeletes(table: string, callback: (payload: RealtimePostgresChangesPayload) => void, options?: Omit<UseRealtimeOptions, "channel" | "event" | "callback">): {
162
162
  channel: _fluxbase_sdk.RealtimeChannel | null;
163
163
  };
164
164
 
@@ -169,7 +169,11 @@ declare function useStorageList(bucket: string, options?: ListOptions & Omit<Use
169
169
  /**
170
170
  * Hook to upload a file to a bucket
171
171
  */
172
- declare function useStorageUpload(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
172
+ declare function useStorageUpload(bucket: string): _tanstack_react_query.UseMutationResult<{
173
+ id: string;
174
+ path: string;
175
+ fullPath: string;
176
+ } | null, Error, {
173
177
  path: string;
174
178
  file: File | Blob | ArrayBuffer;
175
179
  options?: UploadOptions;
@@ -193,14 +197,18 @@ declare function useStorageSignedUrl(bucket: string, path: string | null, expire
193
197
  /**
194
198
  * Hook to move a file
195
199
  */
196
- declare function useStorageMove(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
200
+ declare function useStorageMove(bucket: string): _tanstack_react_query.UseMutationResult<{
201
+ message: string;
202
+ } | null, Error, {
197
203
  fromPath: string;
198
204
  toPath: string;
199
205
  }, unknown>;
200
206
  /**
201
207
  * Hook to copy a file
202
208
  */
203
- declare function useStorageCopy(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
209
+ declare function useStorageCopy(bucket: string): _tanstack_react_query.UseMutationResult<{
210
+ path: string;
211
+ } | null, Error, {
204
212
  fromPath: string;
205
213
  toPath: string;
206
214
  }, unknown>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
3
  import * as _fluxbase_sdk from '@fluxbase/sdk';
4
- import { FluxbaseClient, User, AuthSession, SignInCredentials, SignUpCredentials, QueryBuilder, RealtimeCallback, RealtimeChangePayload, ListOptions, UploadOptions, AdminAuthResponse, ListUsersOptions, EnrichedUser, APIKey, CreateAPIKeyRequest, Webhook, CreateWebhookRequest, UpdateWebhookRequest, AppSettings, UpdateAppSettingsRequest, SystemSetting, UpdateSystemSettingRequest } from '@fluxbase/sdk';
4
+ import { FluxbaseClient, AuthSession, SignInCredentials, SignUpCredentials, User, QueryBuilder, RealtimeCallback, RealtimePostgresChangesPayload, ListOptions, UploadOptions, AdminAuthResponse, ListUsersOptions, EnrichedUser, APIKey, CreateAPIKeyRequest, Webhook, CreateWebhookRequest, UpdateWebhookRequest, AppSettings, UpdateAppSettingsRequest, SystemSetting, UpdateSystemSettingRequest } from '@fluxbase/sdk';
5
5
  export { APIKey, AdminUser, AppSettings, AuthSession, EnrichedUser, FluxbaseClient, PostgrestResponse, RealtimeChangePayload, SignInCredentials, SignUpCredentials, StorageObject, SystemSetting, User, Webhook } from '@fluxbase/sdk';
6
6
  import * as _tanstack_react_query from '@tanstack/react-query';
7
7
  import { UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
@@ -23,7 +23,7 @@ declare function useFluxbaseClient(): FluxbaseClient;
23
23
  /**
24
24
  * Hook to get the current user
25
25
  */
26
- declare function useUser(): _tanstack_react_query.UseQueryResult<User | null, Error>;
26
+ declare function useUser(): _tanstack_react_query.UseQueryResult<_fluxbase_sdk.UserResponse | null, Error>;
27
27
  /**
28
28
  * Hook to get the current session
29
29
  */
@@ -31,11 +31,11 @@ declare function useSession(): _tanstack_react_query.UseQueryResult<AuthSession
31
31
  /**
32
32
  * Hook for signing in
33
33
  */
34
- declare function useSignIn(): _tanstack_react_query.UseMutationResult<AuthSession | _fluxbase_sdk.SignInWith2FAResponse, Error, SignInCredentials, unknown>;
34
+ declare function useSignIn(): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.FluxbaseResponse<AuthSession | _fluxbase_sdk.SignInWith2FAResponse>, Error, SignInCredentials, unknown>;
35
35
  /**
36
36
  * Hook for signing up
37
37
  */
38
- declare function useSignUp(): _tanstack_react_query.UseMutationResult<AuthSession, Error, SignUpCredentials, unknown>;
38
+ declare function useSignUp(): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.FluxbaseAuthResponse, Error, SignUpCredentials, unknown>;
39
39
  /**
40
40
  * Hook for signing out
41
41
  */
@@ -43,19 +43,19 @@ declare function useSignOut(): _tanstack_react_query.UseMutationResult<void, Err
43
43
  /**
44
44
  * Hook for updating the current user
45
45
  */
46
- declare function useUpdateUser(): _tanstack_react_query.UseMutationResult<User, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
46
+ declare function useUpdateUser(): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.UserResponse, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
47
47
  /**
48
48
  * Combined auth hook with all auth state and methods
49
49
  */
50
50
  declare function useAuth(): {
51
- user: User | null | undefined;
51
+ user: _fluxbase_sdk.UserResponse | null | undefined;
52
52
  session: AuthSession | null | undefined;
53
53
  isLoading: boolean;
54
54
  isAuthenticated: boolean;
55
- signIn: _tanstack_react_query.UseMutateAsyncFunction<AuthSession | _fluxbase_sdk.SignInWith2FAResponse, Error, SignInCredentials, unknown>;
56
- signUp: _tanstack_react_query.UseMutateAsyncFunction<AuthSession, Error, SignUpCredentials, unknown>;
55
+ signIn: _tanstack_react_query.UseMutateAsyncFunction<_fluxbase_sdk.FluxbaseResponse<AuthSession | _fluxbase_sdk.SignInWith2FAResponse>, Error, SignInCredentials, unknown>;
56
+ signUp: _tanstack_react_query.UseMutateAsyncFunction<_fluxbase_sdk.FluxbaseAuthResponse, Error, SignUpCredentials, unknown>;
57
57
  signOut: _tanstack_react_query.UseMutateAsyncFunction<void, Error, void, unknown>;
58
- updateUser: _tanstack_react_query.UseMutateAsyncFunction<User, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
58
+ updateUser: _tanstack_react_query.UseMutateAsyncFunction<_fluxbase_sdk.UserResponse, Error, Partial<Pick<User, "email" | "metadata">>, unknown>;
59
59
  isSigningIn: boolean;
60
60
  isSigningUp: boolean;
61
61
  isSigningOut: boolean;
@@ -108,7 +108,7 @@ interface UseRealtimeOptions {
108
108
  /**
109
109
  * Event type to listen for ('INSERT', 'UPDATE', 'DELETE', or '*' for all)
110
110
  */
111
- event?: 'INSERT' | 'UPDATE' | 'DELETE' | '*';
111
+ event?: "INSERT" | "UPDATE" | "DELETE" | "*";
112
112
  /**
113
113
  * Callback function when an event is received
114
114
  */
@@ -140,25 +140,25 @@ declare function useRealtime(options: UseRealtimeOptions): {
140
140
  * @param table - Table name (with optional schema, e.g., 'public.products')
141
141
  * @param options - Subscription options
142
142
  */
143
- declare function useTableSubscription(table: string, options?: Omit<UseRealtimeOptions, 'channel'>): {
143
+ declare function useTableSubscription(table: string, options?: Omit<UseRealtimeOptions, "channel">): {
144
144
  channel: _fluxbase_sdk.RealtimeChannel | null;
145
145
  };
146
146
  /**
147
147
  * Hook to subscribe to INSERT events on a table
148
148
  */
149
- declare function useTableInserts(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
149
+ declare function useTableInserts(table: string, callback: (payload: RealtimePostgresChangesPayload) => void, options?: Omit<UseRealtimeOptions, "channel" | "event" | "callback">): {
150
150
  channel: _fluxbase_sdk.RealtimeChannel | null;
151
151
  };
152
152
  /**
153
153
  * Hook to subscribe to UPDATE events on a table
154
154
  */
155
- declare function useTableUpdates(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
155
+ declare function useTableUpdates(table: string, callback: (payload: RealtimePostgresChangesPayload) => void, options?: Omit<UseRealtimeOptions, "channel" | "event" | "callback">): {
156
156
  channel: _fluxbase_sdk.RealtimeChannel | null;
157
157
  };
158
158
  /**
159
159
  * Hook to subscribe to DELETE events on a table
160
160
  */
161
- declare function useTableDeletes(table: string, callback: (payload: RealtimeChangePayload) => void, options?: Omit<UseRealtimeOptions, 'channel' | 'event' | 'callback'>): {
161
+ declare function useTableDeletes(table: string, callback: (payload: RealtimePostgresChangesPayload) => void, options?: Omit<UseRealtimeOptions, "channel" | "event" | "callback">): {
162
162
  channel: _fluxbase_sdk.RealtimeChannel | null;
163
163
  };
164
164
 
@@ -169,7 +169,11 @@ declare function useStorageList(bucket: string, options?: ListOptions & Omit<Use
169
169
  /**
170
170
  * Hook to upload a file to a bucket
171
171
  */
172
- declare function useStorageUpload(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
172
+ declare function useStorageUpload(bucket: string): _tanstack_react_query.UseMutationResult<{
173
+ id: string;
174
+ path: string;
175
+ fullPath: string;
176
+ } | null, Error, {
173
177
  path: string;
174
178
  file: File | Blob | ArrayBuffer;
175
179
  options?: UploadOptions;
@@ -193,14 +197,18 @@ declare function useStorageSignedUrl(bucket: string, path: string | null, expire
193
197
  /**
194
198
  * Hook to move a file
195
199
  */
196
- declare function useStorageMove(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
200
+ declare function useStorageMove(bucket: string): _tanstack_react_query.UseMutationResult<{
201
+ message: string;
202
+ } | null, Error, {
197
203
  fromPath: string;
198
204
  toPath: string;
199
205
  }, unknown>;
200
206
  /**
201
207
  * Hook to copy a file
202
208
  */
203
- declare function useStorageCopy(bucket: string): _tanstack_react_query.UseMutationResult<_fluxbase_sdk.StorageObject | null, Error, {
209
+ declare function useStorageCopy(bucket: string): _tanstack_react_query.UseMutationResult<{
210
+ path: string;
211
+ } | null, Error, {
204
212
  fromPath: string;
205
213
  toPath: string;
206
214
  }, unknown>;
package/dist/index.js CHANGED
@@ -130,9 +130,11 @@ function useSignUp() {
130
130
  mutationFn: async (credentials) => {
131
131
  return await client.auth.signUp(credentials);
132
132
  },
133
- onSuccess: (session) => {
134
- queryClient.setQueryData(["fluxbase", "auth", "session"], session);
135
- queryClient.setQueryData(["fluxbase", "auth", "user"], session.user);
133
+ onSuccess: (response) => {
134
+ if (response.data) {
135
+ queryClient.setQueryData(["fluxbase", "auth", "session"], response.data.session);
136
+ queryClient.setQueryData(["fluxbase", "auth", "user"], response.data.user);
137
+ }
136
138
  }
137
139
  });
138
140
  }
@@ -292,7 +294,9 @@ var import_react_query3 = require("@tanstack/react-query");
292
294
  function useRealtime(options) {
293
295
  const client = useFluxbaseClient();
294
296
  const queryClient = (0, import_react_query3.useQueryClient)();
295
- const channelRef = (0, import_react2.useRef)(null);
297
+ const channelRef = (0, import_react2.useRef)(
298
+ null
299
+ );
296
300
  const {
297
301
  channel: channelName,
298
302
  event = "*",
@@ -322,7 +326,16 @@ function useRealtime(options) {
322
326
  channel.unsubscribe();
323
327
  channelRef.current = null;
324
328
  };
325
- }, [client, channelName, event, callback, autoInvalidate, invalidateKey, queryClient, enabled]);
329
+ }, [
330
+ client,
331
+ channelName,
332
+ event,
333
+ callback,
334
+ autoInvalidate,
335
+ invalidateKey,
336
+ queryClient,
337
+ enabled
338
+ ]);
326
339
  return {
327
340
  channel: channelRef.current
328
341
  };
@@ -590,8 +603,11 @@ function useAdminAuth(options = {}) {
590
603
  try {
591
604
  setIsLoading(true);
592
605
  setError(null);
593
- const { user: user2 } = await client.admin.me();
594
- setUser(user2);
606
+ const { data, error: apiError } = await client.admin.me();
607
+ if (apiError) {
608
+ throw apiError;
609
+ }
610
+ setUser(data.user);
595
611
  } catch (err) {
596
612
  setUser(null);
597
613
  setError(err);
@@ -604,9 +620,15 @@ function useAdminAuth(options = {}) {
604
620
  try {
605
621
  setIsLoading(true);
606
622
  setError(null);
607
- const response = await client.admin.login({ email, password });
608
- setUser(response.user);
609
- return response;
623
+ const { data, error: apiError } = await client.admin.login({
624
+ email,
625
+ password
626
+ });
627
+ if (apiError) {
628
+ throw apiError;
629
+ }
630
+ setUser(data.user);
631
+ return data;
610
632
  } catch (err) {
611
633
  setError(err);
612
634
  throw err;
@@ -660,9 +682,12 @@ function useUsers(options = {}) {
660
682
  try {
661
683
  setIsLoading(true);
662
684
  setError(null);
663
- const response = await client.admin.listUsers(listOptions);
664
- setUsers(response.users);
665
- setTotal(response.total);
685
+ const { data, error: apiError } = await client.admin.listUsers(listOptions);
686
+ if (apiError) {
687
+ throw apiError;
688
+ }
689
+ setUsers(data.users);
690
+ setTotal(data.total);
666
691
  } catch (err) {
667
692
  setError(err);
668
693
  } finally {
@@ -692,7 +717,11 @@ function useUsers(options = {}) {
692
717
  );
693
718
  const resetPassword = (0, import_react4.useCallback)(
694
719
  async (userId) => {
695
- return await client.admin.resetUserPassword(userId);
720
+ const { data, error: error2 } = await client.admin.resetUserPassword(userId);
721
+ if (error2) {
722
+ throw error2;
723
+ }
724
+ return data;
696
725
  },
697
726
  [client]
698
727
  );