@snackbase/sdk 0.1.0
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 +61 -0
- package/LICENSE +21 -0
- package/README.md +287 -0
- package/dist/index-Dr6K4PMl.d.mts +2118 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2516 -0
- package/dist/react/index.d.mts +63 -0
- package/dist/react/index.mjs +271 -0
- package/package.json +48 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial release of SnackBase SDK for JavaScript/TypeScript
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
- **Core Client**: `SnackBaseClient` with configuration validation
|
|
15
|
+
- **HTTP Client**: Fetch-based HTTP client with interceptors
|
|
16
|
+
- **Authentication**: Email/password, OAuth, SAML, and API key authentication
|
|
17
|
+
- **Services**: 17+ service classes for all SnackBase resources
|
|
18
|
+
- Accounts, Users, Collections, Records
|
|
19
|
+
- Roles, Collection Rules (Permission System V2)
|
|
20
|
+
- Groups, Invitations, Macros
|
|
21
|
+
- API Keys, Audit Logs, Dashboard, Admin
|
|
22
|
+
- Email Templates, Files
|
|
23
|
+
- **Real-Time**: WebSocket/SSE support with automatic reconnection
|
|
24
|
+
- **Query Builder**: Fluent API for complex queries
|
|
25
|
+
- **React Integration**: Context provider and hooks
|
|
26
|
+
- `useAuth`, `useQuery`, `useRecord`, `useMutation`, `useSubscription`
|
|
27
|
+
- **Type Safety**: Complete TypeScript definitions
|
|
28
|
+
- **Error Handling**: Typed error hierarchy
|
|
29
|
+
- **Storage Abstraction**: Platform-agnostic storage backends
|
|
30
|
+
- **Logging**: Structured logging system with configurable levels
|
|
31
|
+
|
|
32
|
+
### Package Exports
|
|
33
|
+
- `@snackbase/sdk` - Core SDK
|
|
34
|
+
- `@snackbase/sdk/react` - React integration
|
|
35
|
+
|
|
36
|
+
### Build Output
|
|
37
|
+
- ESM (`.mjs`) - 14.87 KB gzipped
|
|
38
|
+
- CommonJS (`.js`)
|
|
39
|
+
- TypeScript declarations (`.d.ts`)
|
|
40
|
+
|
|
41
|
+
## [0.1.0] - 2025-01-XX
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
- Initial beta release
|
|
45
|
+
- Complete Phase 1-4 implementation
|
|
46
|
+
- Core SDK features
|
|
47
|
+
- React hooks
|
|
48
|
+
- Real-time subscriptions
|
|
49
|
+
- Query builder
|
|
50
|
+
- 231 tests passing
|
|
51
|
+
|
|
52
|
+
## [Future Releases]
|
|
53
|
+
|
|
54
|
+
### Planned
|
|
55
|
+
- Integration tests with test server
|
|
56
|
+
- Performance benchmarks
|
|
57
|
+
- Request deduplication
|
|
58
|
+
- Advanced caching strategies
|
|
59
|
+
- Vue 3 integration
|
|
60
|
+
- Angular integration
|
|
61
|
+
- Svelte integration
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SnackBase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
# SnackBase SDK
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@snackbase/sdk)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/snackbase/snackbase-js/actions)
|
|
6
|
+
|
|
7
|
+
The official JavaScript/TypeScript SDK for [SnackBase](https://snackbase.dev) - a powerful backend-as-a-service platform.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Type-Safe**: Built with TypeScript for full type safety and excellent developer experience
|
|
12
|
+
- **Authentication**: Support for JWT tokens, OAuth, SAML, and API keys
|
|
13
|
+
- **Real-Time**: WebSocket and SSE support for real-time data synchronization
|
|
14
|
+
- **React Integration**: Dedicated React hooks and context for seamless integration
|
|
15
|
+
- **Query Builder**: Fluent API for building complex queries with filtering, sorting, and pagination
|
|
16
|
+
- **Platform Agnostic**: Works in browsers, React Native, and Node.js
|
|
17
|
+
- **Lightweight**: Only 14.87 KB gzipped for the core SDK
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# npm
|
|
23
|
+
npm install @snackbase/sdk
|
|
24
|
+
|
|
25
|
+
# yarn
|
|
26
|
+
yarn add @snackbase/sdk
|
|
27
|
+
|
|
28
|
+
# pnpm
|
|
29
|
+
pnpm add @snackbase/sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### React Integration
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# npm
|
|
36
|
+
npm install @snackbase/sdk react
|
|
37
|
+
|
|
38
|
+
# yarn
|
|
39
|
+
yarn add @snackbase/sdk react
|
|
40
|
+
|
|
41
|
+
# pnpm
|
|
42
|
+
pnpm add @snackbase/sdk react
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### Basic Usage
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { SnackBaseClient } from "@snackbase/sdk";
|
|
51
|
+
|
|
52
|
+
// Initialize the client
|
|
53
|
+
const client = new SnackBaseClient({
|
|
54
|
+
baseUrl: "https://your-project.snackbase.dev",
|
|
55
|
+
apiKey: "your-api-key", // Optional for public access
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Authenticate with email/password
|
|
59
|
+
const auth = await client.auth.authenticateWithPassword({
|
|
60
|
+
email: "user@example.com",
|
|
61
|
+
password: "password123",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
console.log("Logged in as:", auth.user.email);
|
|
65
|
+
|
|
66
|
+
// List records from a collection
|
|
67
|
+
const records = await client.records.list("posts", {
|
|
68
|
+
filter: { status: "published" },
|
|
69
|
+
sort: "-createdAt",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Subscribe to real-time updates
|
|
73
|
+
client.realtime.subscribe("posts", (event) => {
|
|
74
|
+
console.log("New event:", event.action, event.record);
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### React Integration
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { SnackBaseProvider, useAuth, useRecord } from "@snackbase/sdk/react";
|
|
82
|
+
|
|
83
|
+
function App() {
|
|
84
|
+
return (
|
|
85
|
+
<SnackBaseProvider
|
|
86
|
+
baseUrl="https://your-project.snackbase.dev"
|
|
87
|
+
apiKey="your-api-key"
|
|
88
|
+
>
|
|
89
|
+
<Posts />
|
|
90
|
+
</SnackBaseProvider>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function Posts() {
|
|
95
|
+
const { user, login, logout } = useAuth();
|
|
96
|
+
const { data: posts, loading } = useRecord("posts", {
|
|
97
|
+
filter: { status: "published" },
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
if (!user) {
|
|
101
|
+
return <button onClick={() => login(email, password)}>Login</button>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<div>
|
|
106
|
+
<button onClick={logout}>Logout</button>
|
|
107
|
+
{loading ? <p>Loading...</p> : <PostList posts={posts?.items} />}
|
|
108
|
+
</div>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Documentation
|
|
114
|
+
|
|
115
|
+
- [Getting Started Guide](./docs/getting-started.md)
|
|
116
|
+
- [Authentication Guide](./docs/authentication.md)
|
|
117
|
+
- [Real-Time Features](./docs/realtime.md)
|
|
118
|
+
- [React Integration](./docs/react-integration.md)
|
|
119
|
+
- [API Reference](./docs/api-reference.md)
|
|
120
|
+
- [Migration Guides](./docs/migration/)
|
|
121
|
+
|
|
122
|
+
## Platform Support
|
|
123
|
+
|
|
124
|
+
| Platform | Support |
|
|
125
|
+
| --------------------------------------- | ------- |
|
|
126
|
+
| Browser (Chrome, Firefox, Safari, Edge) | ✅ Full |
|
|
127
|
+
| React Native | ✅ Full |
|
|
128
|
+
| Node.js | ✅ Full |
|
|
129
|
+
| Next.js | ✅ Full |
|
|
130
|
+
| Vue/Nuxt | ✅ Full |
|
|
131
|
+
|
|
132
|
+
## Authentication Methods
|
|
133
|
+
|
|
134
|
+
| Method | Description |
|
|
135
|
+
| ------------------ | -------------------------------------------------- |
|
|
136
|
+
| **Email/Password** | Traditional authentication with email and password |
|
|
137
|
+
| **OAuth** | Sign in with Google, GitHub, etc. |
|
|
138
|
+
| **SAML** | Enterprise SSO support |
|
|
139
|
+
| **API Key** | Server-to-server authentication |
|
|
140
|
+
|
|
141
|
+
## Core Services
|
|
142
|
+
|
|
143
|
+
The SDK provides 17+ services for interacting with SnackBase:
|
|
144
|
+
|
|
145
|
+
- `client.auth` - Authentication and user management
|
|
146
|
+
- `client.users` - User CRUD operations
|
|
147
|
+
- `client.accounts` - Account management
|
|
148
|
+
- `client.collections` - Collection/schema management
|
|
149
|
+
- `client.records` - Dynamic record operations (CRUD, queries)
|
|
150
|
+
- `client.roles` - Role-based access control
|
|
151
|
+
- `client.groups` - Group management
|
|
152
|
+
- `client.invitations` - User invitations
|
|
153
|
+
- `client.macros` - Macro operations
|
|
154
|
+
- `client.apiKeys` - API key management
|
|
155
|
+
- `client.auditLogs` - Audit log access
|
|
156
|
+
- `client.dashboard` - Dashboard metrics
|
|
157
|
+
- `client.admin` - Admin operations
|
|
158
|
+
- `client.emailTemplates` - Email template management
|
|
159
|
+
- `client.files` - File upload/download
|
|
160
|
+
- `client.realtime` - Real-time subscriptions
|
|
161
|
+
- `client.query` - Query builder
|
|
162
|
+
|
|
163
|
+
## Query Builder
|
|
164
|
+
|
|
165
|
+
Build complex queries with a fluent API:
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
const results = await client
|
|
169
|
+
.query("posts")
|
|
170
|
+
.select("id", "title", "author.name")
|
|
171
|
+
.expand("author", "comments")
|
|
172
|
+
.filter("status", "=", "published")
|
|
173
|
+
.filter("createdAt", ">", "2024-01-01")
|
|
174
|
+
.sort("createdAt", "desc")
|
|
175
|
+
.page(1)
|
|
176
|
+
.perPage(20)
|
|
177
|
+
.execute();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Real-Time Subscriptions
|
|
181
|
+
|
|
182
|
+
Subscribe to record changes in real-time:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
// Subscribe to a collection
|
|
186
|
+
const unsubscribe = client.realtime.subscribe("posts", (event) => {
|
|
187
|
+
switch (event.action) {
|
|
188
|
+
case "create":
|
|
189
|
+
console.log("New post created:", event.record);
|
|
190
|
+
break;
|
|
191
|
+
case "update":
|
|
192
|
+
console.log("Post updated:", event.record);
|
|
193
|
+
break;
|
|
194
|
+
case "delete":
|
|
195
|
+
console.log("Post deleted:", event.record);
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Unsubscribe when done
|
|
201
|
+
unsubscribe();
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Error Handling
|
|
205
|
+
|
|
206
|
+
The SDK provides typed errors for comprehensive error handling:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import {
|
|
210
|
+
SnackBaseError,
|
|
211
|
+
AuthenticationError,
|
|
212
|
+
ValidationError,
|
|
213
|
+
NetworkError,
|
|
214
|
+
} from "@snackbase/sdk";
|
|
215
|
+
|
|
216
|
+
try {
|
|
217
|
+
await client.records.create("posts", data);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
if (error instanceof ValidationError) {
|
|
220
|
+
console.error("Validation failed:", error.fields);
|
|
221
|
+
} else if (error instanceof AuthenticationError) {
|
|
222
|
+
console.error("Authentication failed:", error.message);
|
|
223
|
+
} else if (error instanceof NetworkError) {
|
|
224
|
+
console.error("Network error:", error.message);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## TypeScript Support
|
|
230
|
+
|
|
231
|
+
The SDK is written in TypeScript and provides full type definitions:
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import type { User, Post, Comment } from "@snackbase/sdk";
|
|
235
|
+
|
|
236
|
+
// Type-safe record operations
|
|
237
|
+
const post: Post = await client.records.get<Post>("posts", "record-id");
|
|
238
|
+
|
|
239
|
+
// Type-safe auth state
|
|
240
|
+
const user: User = await client.auth.getCurrentUser();
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Development
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
# Clone the repository
|
|
247
|
+
git clone https://github.com/snackbase/snackbase-js.git
|
|
248
|
+
cd snackbase-js
|
|
249
|
+
|
|
250
|
+
# Install dependencies
|
|
251
|
+
npm install
|
|
252
|
+
|
|
253
|
+
# Build
|
|
254
|
+
npm run build
|
|
255
|
+
|
|
256
|
+
# Run tests
|
|
257
|
+
npm test
|
|
258
|
+
|
|
259
|
+
# Watch mode
|
|
260
|
+
npm run dev
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Bundle Size
|
|
264
|
+
|
|
265
|
+
- Core SDK: **14.87 KB** (gzipped)
|
|
266
|
+
- React Integration: **1.42 KB** (gzipped)
|
|
267
|
+
- Total: **16.29 KB** (gzipped)
|
|
268
|
+
|
|
269
|
+
## License
|
|
270
|
+
|
|
271
|
+
MIT © [SnackBase](https://snackbase.dev)
|
|
272
|
+
|
|
273
|
+
## Contributing
|
|
274
|
+
|
|
275
|
+
We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md) for details.
|
|
276
|
+
|
|
277
|
+
## Support
|
|
278
|
+
|
|
279
|
+
- Documentation: [https://docs.snackbase.dev](https://docs.snackbase.dev)
|
|
280
|
+
- GitHub Issues: [https://github.com/snackbase/snackbase-js/issues](https://github.com/snackbase/snackbase-js/issues)
|
|
281
|
+
- Discord: [https://discord.gg/snackbase](https://discord.gg/snackbase)
|
|
282
|
+
|
|
283
|
+
## Related Projects
|
|
284
|
+
|
|
285
|
+
- [SnackBase](https://snackbase.dev) - The official SnackBase platform
|
|
286
|
+
- [snackbase-python](https://github.com/snackbase/snackbase-python) - Python SDK
|
|
287
|
+
- [snackbase-go](https://github.com/snackbase/snackbase-go) - Go SDK
|