@fluxbase/sdk-react 0.0.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/CHANGELOG.md +67 -0
- package/README-ADMIN.md +1076 -0
- package/README.md +178 -0
- package/dist/index.d.mts +606 -0
- package/dist/index.d.ts +606 -0
- package/dist/index.js +992 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +926 -0
- package/dist/index.mjs.map +1 -0
- package/examples/AdminDashboard.tsx +513 -0
- package/examples/README.md +163 -0
- package/package.json +52 -0
- package/src/context.tsx +33 -0
- package/src/index.ts +113 -0
- package/src/use-admin-auth.ts +168 -0
- package/src/use-admin-hooks.ts +309 -0
- package/src/use-api-keys.ts +174 -0
- package/src/use-auth.ts +146 -0
- package/src/use-query.ts +165 -0
- package/src/use-realtime.ts +161 -0
- package/src/use-rpc.ts +109 -0
- package/src/use-storage.ts +257 -0
- package/src/use-users.ts +191 -0
- package/tsconfig.json +24 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +11 -0
- package/typedoc.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# @fluxbase/sdk-react
|
|
2
|
+
|
|
3
|
+
React hooks for Fluxbase - Backend as a Service.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@fluxbase/sdk-react)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **React Hooks** - Idiomatic React hooks for all Fluxbase features
|
|
11
|
+
- **TanStack Query** - Built on React Query for optimal data fetching
|
|
12
|
+
- **Type-safe** - Full TypeScript support
|
|
13
|
+
- **Auto-refetch** - Smart cache invalidation and refetching
|
|
14
|
+
- **Optimistic Updates** - Instant UI updates
|
|
15
|
+
- **SSR Support** - Works with Next.js and other SSR frameworks
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @fluxbase/sdk @fluxbase/sdk-react @tanstack/react-query
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { createClient } from '@fluxbase/sdk'
|
|
27
|
+
import { FluxbaseProvider, useAuth, useTable } from '@fluxbase/sdk-react'
|
|
28
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
29
|
+
|
|
30
|
+
// Create clients
|
|
31
|
+
const fluxbaseClient = createClient({ url: 'http://localhost:8080' })
|
|
32
|
+
const queryClient = new QueryClient()
|
|
33
|
+
|
|
34
|
+
function App() {
|
|
35
|
+
return (
|
|
36
|
+
<QueryClientProvider client={queryClient}>
|
|
37
|
+
<FluxbaseProvider client={fluxbaseClient}>
|
|
38
|
+
<YourApp />
|
|
39
|
+
</FluxbaseProvider>
|
|
40
|
+
</QueryClientProvider>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function YourApp() {
|
|
45
|
+
const { user, signIn, signOut } = useAuth()
|
|
46
|
+
const { data: products } = useTable('products', (q) =>
|
|
47
|
+
q.select('*').eq('active', true).order('created_at', { ascending: false })
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div>
|
|
52
|
+
{user ? (
|
|
53
|
+
<>
|
|
54
|
+
<p>Welcome {user.email}</p>
|
|
55
|
+
<button onClick={signOut}>Sign Out</button>
|
|
56
|
+
</>
|
|
57
|
+
) : (
|
|
58
|
+
<button onClick={() => signIn({ email: 'user@example.com', password: 'pass' })}>
|
|
59
|
+
Sign In
|
|
60
|
+
</button>
|
|
61
|
+
)}
|
|
62
|
+
|
|
63
|
+
<h2>Products</h2>
|
|
64
|
+
{products?.map((product) => (
|
|
65
|
+
<div key={product.id}>{product.name}</div>
|
|
66
|
+
))}
|
|
67
|
+
</div>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Available Hooks
|
|
73
|
+
|
|
74
|
+
### Authentication
|
|
75
|
+
- `useAuth()` - Complete auth state and methods
|
|
76
|
+
- `useUser()` - Current user data
|
|
77
|
+
- `useSession()` - Current session
|
|
78
|
+
- `useSignIn()` - Sign in mutation
|
|
79
|
+
- `useSignUp()` - Sign up mutation
|
|
80
|
+
- `useSignOut()` - Sign out mutation
|
|
81
|
+
- `useUpdateUser()` - Update user profile
|
|
82
|
+
|
|
83
|
+
### Database
|
|
84
|
+
- `useTable()` - Query table with filters and ordering
|
|
85
|
+
- `useFluxbaseQuery()` - Custom query hook
|
|
86
|
+
- `useInsert()` - Insert rows
|
|
87
|
+
- `useUpdate()` - Update rows
|
|
88
|
+
- `useUpsert()` - Insert or update
|
|
89
|
+
- `useDelete()` - Delete rows
|
|
90
|
+
- `useFluxbaseMutation()` - Generic mutation hook
|
|
91
|
+
|
|
92
|
+
### Realtime
|
|
93
|
+
- `useRealtime()` - Subscribe to database changes
|
|
94
|
+
- `useTableSubscription()` - Auto-refetch on changes
|
|
95
|
+
- `useTableInserts()` - Listen to inserts
|
|
96
|
+
- `useTableUpdates()` - Listen to updates
|
|
97
|
+
- `useTableDeletes()` - Listen to deletes
|
|
98
|
+
|
|
99
|
+
### Storage
|
|
100
|
+
- `useStorageUpload()` - Upload files
|
|
101
|
+
- `useStorageList()` - List files in bucket
|
|
102
|
+
- `useStorageDownload()` - Download files
|
|
103
|
+
- `useStorageDelete()` - Delete files
|
|
104
|
+
- `useStorageSignedUrl()` - Generate signed URLs
|
|
105
|
+
- `useStoragePublicUrl()` - Get public URLs
|
|
106
|
+
|
|
107
|
+
### RPC (PostgreSQL Functions)
|
|
108
|
+
- `useRPC()` - Call PostgreSQL function (query)
|
|
109
|
+
- `useRPCMutation()` - Call PostgreSQL function (mutation)
|
|
110
|
+
- `useRPCBatch()` - Call multiple functions in parallel
|
|
111
|
+
|
|
112
|
+
### Admin (Management & Operations)
|
|
113
|
+
- `useAdminAuth()` - Admin authentication state and login/logout
|
|
114
|
+
- `useUsers()` - User management with pagination and CRUD
|
|
115
|
+
- `useAPIKeys()` - API key creation and management
|
|
116
|
+
- `useWebhooks()` - Webhook configuration and delivery monitoring
|
|
117
|
+
- `useAppSettings()` - Application-wide settings management
|
|
118
|
+
- `useSystemSettings()` - System key-value settings storage
|
|
119
|
+
|
|
120
|
+
📚 **[Complete Admin Hooks Guide](./README-ADMIN.md)** - Comprehensive admin dashboard documentation
|
|
121
|
+
|
|
122
|
+
## Documentation
|
|
123
|
+
|
|
124
|
+
📚 **[Complete React Hooks Guide](../../docs/docs/sdks/react-hooks.md)**
|
|
125
|
+
|
|
126
|
+
### Core Guides
|
|
127
|
+
- **[Getting Started](../../docs/docs/sdks/getting-started.md)** - Installation and setup
|
|
128
|
+
- **[React Hooks](../../docs/docs/sdks/react-hooks.md)** - Comprehensive hooks documentation with examples
|
|
129
|
+
- **[Database Operations](../../docs/docs/sdks/database.md)** - Query building and data operations
|
|
130
|
+
|
|
131
|
+
### API Reference
|
|
132
|
+
- **[React Hooks API](../../docs/static/api/sdk-react/)** - Auto-generated from source code
|
|
133
|
+
- **[Core SDK API](../../docs/static/api/sdk/)** - Core TypeScript SDK reference
|
|
134
|
+
|
|
135
|
+
## TypeScript Support
|
|
136
|
+
|
|
137
|
+
All hooks are fully typed. Define your table schemas for complete type safety:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
interface Product {
|
|
141
|
+
id: string
|
|
142
|
+
name: string
|
|
143
|
+
price: number
|
|
144
|
+
category: string
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function ProductList() {
|
|
148
|
+
const { data } = useTable<Product>('products', (q) => q.select('*'))
|
|
149
|
+
// data is typed as Product[] | undefined
|
|
150
|
+
return <div>{data?.[0]?.name}</div>
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Examples
|
|
155
|
+
|
|
156
|
+
Check out working examples in the [`/example`](../example/) directory:
|
|
157
|
+
- React with Vite
|
|
158
|
+
- Next.js App Router
|
|
159
|
+
- Next.js Pages Router
|
|
160
|
+
- Authentication flows
|
|
161
|
+
- Realtime features
|
|
162
|
+
- File uploads
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
Contributions are welcome! Please read our [Contributing Guide](../../CONTRIBUTING.md) for details.
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
MIT © Fluxbase
|
|
171
|
+
|
|
172
|
+
## Links
|
|
173
|
+
|
|
174
|
+
- [Documentation](../../docs/docs/sdks/react-hooks.md)
|
|
175
|
+
- [API Reference](../../docs/static/api/sdk-react/)
|
|
176
|
+
- [Core SDK](../sdk/)
|
|
177
|
+
- [GitHub](https://github.com/wayli-app/fluxbase)
|
|
178
|
+
- [Issues](https://github.com/wayli-app/fluxbase/issues)
|