@rebasepro/client 0.4.0 → 0.5.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/README.md +164 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# @rebasepro/client
|
|
2
|
+
|
|
3
|
+
HTTP SDK client for the Rebase backend — typed CRUD, auth, storage, realtime WebSockets, admin, cron, and custom functions.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @rebasepro/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## What This Package Does
|
|
12
|
+
|
|
13
|
+
`@rebasepro/client` is the primary SDK for interacting with a Rebase backend from any JavaScript/TypeScript environment (browser, Node.js, edge). It creates a single client instance that provides:
|
|
14
|
+
|
|
15
|
+
- **Collection CRUD** with a fluent query builder (`.where()`, `.orderBy()`, `.limit()`, etc.)
|
|
16
|
+
- **Authentication** — email/password, Google, 10+ OAuth providers, session management, password reset
|
|
17
|
+
- **Admin** — user CRUD for admins
|
|
18
|
+
- **Storage** — file upload, download, delete, list
|
|
19
|
+
- **Realtime** — WebSocket subscriptions for collection and entity changes
|
|
20
|
+
- **Cron** — list, trigger, and manage cron jobs
|
|
21
|
+
- **Custom functions** — invoke server-side Hono route functions
|
|
22
|
+
- **Type-safe data proxy** — `client.data.products` auto-maps to the `products` collection
|
|
23
|
+
|
|
24
|
+
## Key Exports
|
|
25
|
+
|
|
26
|
+
### Client Factory
|
|
27
|
+
|
|
28
|
+
| Export | Description |
|
|
29
|
+
|---|---|
|
|
30
|
+
| `createRebaseClient<DB>(options)` | Create a `RebaseClient` instance. Generic `DB` parameter enables type-safe `client.data.*` access. |
|
|
31
|
+
| `RebaseClient<DB>` | The client type — includes `auth`, `admin`, `cron`, `functions`, `storage`, `ws`, `data`, `call`, and token management methods. |
|
|
32
|
+
| `CreateRebaseClientOptions` | Extends `RebaseClientConfig` with `auth`, `admin`, and `cron` sub-configs. |
|
|
33
|
+
|
|
34
|
+
### Config
|
|
35
|
+
|
|
36
|
+
| Option | Type | Default | Description |
|
|
37
|
+
|---|---|---|---|
|
|
38
|
+
| `baseUrl` | `string` | `""` | Backend URL (e.g. `http://localhost:3001`) |
|
|
39
|
+
| `token` | `string` | — | Static auth token |
|
|
40
|
+
| `apiPath` | `string` | `"/api"` | API path prefix |
|
|
41
|
+
| `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch implementation |
|
|
42
|
+
| `onUnauthorized` | `() => Promise<boolean>` | auto-refresh | Handler for 401 responses |
|
|
43
|
+
| `websocketUrl` | `string` | derived from `baseUrl` | WebSocket URL for realtime |
|
|
44
|
+
|
|
45
|
+
### Collection Client
|
|
46
|
+
|
|
47
|
+
`client.data.collection("slug")` or `client.data.myCollection` returns a `CollectionClient<M>`:
|
|
48
|
+
|
|
49
|
+
| Method | Description |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `find(params?)` | Query with pagination. Returns `FindResponse<M>` (`{ data, meta }`) |
|
|
52
|
+
| `findById(id)` | Fetch a single entity. Returns `Entity<M> \| undefined` |
|
|
53
|
+
| `create(data, id?)` | Create entity. Returns `Entity<M>` |
|
|
54
|
+
| `update(id, data)` | Update entity. Returns `Entity<M>` |
|
|
55
|
+
| `delete(id)` | Delete entity |
|
|
56
|
+
| `count(params?)` | Count matching entities |
|
|
57
|
+
| `where(col, op, val)` | Start a fluent query — returns `QueryBuilder` |
|
|
58
|
+
| `orderBy(col, dir?)` | Order results — returns `QueryBuilder` |
|
|
59
|
+
| `limit(n)` / `offset(n)` | Pagination — returns `QueryBuilder` |
|
|
60
|
+
| `search(str)` | Full-text search — returns `QueryBuilder` |
|
|
61
|
+
| `include(...rels)` | Include related entities — returns `QueryBuilder` |
|
|
62
|
+
| `listen(params, onUpdate, onError?)` | Realtime subscription (requires WebSocket) |
|
|
63
|
+
| `listenById(id, onUpdate, onError?)` | Realtime single-entity subscription |
|
|
64
|
+
|
|
65
|
+
### Auth Module (`client.auth`)
|
|
66
|
+
|
|
67
|
+
| Method | Description |
|
|
68
|
+
|---|---|
|
|
69
|
+
| `signInWithEmail(email, password)` | Email/password login |
|
|
70
|
+
| `signUp(email, password, displayName?)` | Register new user |
|
|
71
|
+
| `signInWithGoogle(payload)` | Google OAuth (ID token, access token, or auth code) |
|
|
72
|
+
| `signInWithOAuth(providerId, payload)` | Generic OAuth for any provider |
|
|
73
|
+
| `signInWithGitHub/Microsoft/Apple/Facebook/Twitter/Discord/GitLab/Bitbucket/Slack/Spotify` | Provider-specific convenience methods |
|
|
74
|
+
| `signOut()` | Sign out and invalidate refresh token |
|
|
75
|
+
| `refreshSession()` | Refresh the access token |
|
|
76
|
+
| `getUser()` / `updateUser(updates)` | Current user profile |
|
|
77
|
+
| `resetPasswordForEmail(email)` | Request password reset |
|
|
78
|
+
| `resetPassword(token, password)` | Complete password reset |
|
|
79
|
+
| `changePassword(old, new)` | Change password (authenticated) |
|
|
80
|
+
| `sendVerificationEmail()` / `verifyEmail(token)` | Email verification |
|
|
81
|
+
| `getSessions()` / `revokeSession(id)` / `revokeAllSessions()` | Session management |
|
|
82
|
+
| `getAuthConfig()` | Fetch backend auth configuration |
|
|
83
|
+
| `getSession()` | Get current session (sync) |
|
|
84
|
+
| `onAuthStateChange(callback)` | Subscribe to auth events (`SIGNED_IN`, `SIGNED_OUT`, `TOKEN_REFRESHED`, `USER_UPDATED`) |
|
|
85
|
+
|
|
86
|
+
### Storage Module (`client.storage`)
|
|
87
|
+
|
|
88
|
+
| Method | Description |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `putObject({ file, key, metadata, bucket })` | Upload a file |
|
|
91
|
+
| `getSignedUrl(key, bucket?)` | Get download URL + metadata |
|
|
92
|
+
| `getObject(key, bucket?)` | Download file as `File` object |
|
|
93
|
+
| `deleteObject(key, bucket?)` | Delete a file |
|
|
94
|
+
| `listObjects(prefix, options?)` | List files with optional pagination |
|
|
95
|
+
|
|
96
|
+
### Admin Module (`client.admin`)
|
|
97
|
+
|
|
98
|
+
| Method | Description |
|
|
99
|
+
|---|---|
|
|
100
|
+
| `listUsers()` / `listUsersPaginated(options?)` | List all users |
|
|
101
|
+
| `getUser(userId)` | Get a single user |
|
|
102
|
+
| `createUser(data)` | Create a user |
|
|
103
|
+
| `updateUser(userId, data)` | Update a user |
|
|
104
|
+
| `deleteUser(userId)` | Delete a user |
|
|
105
|
+
| `bootstrap()` | First-user bootstrap |
|
|
106
|
+
|
|
107
|
+
### Functions Module (`client.functions`)
|
|
108
|
+
|
|
109
|
+
| Method | Description |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `invoke<T>(name, payload?, options?)` | Call a custom backend function at `/api/functions/{name}` |
|
|
112
|
+
|
|
113
|
+
### Other Exports
|
|
114
|
+
|
|
115
|
+
| Export | Description |
|
|
116
|
+
|---|---|
|
|
117
|
+
| `RebaseApiError` | Error class with `status`, `message`, `code`, `details` |
|
|
118
|
+
| `RebaseWebSocketClient` | WebSocket client for realtime subscriptions |
|
|
119
|
+
| `createCookieStorage(options?)` | Cookie-based auth storage adapter |
|
|
120
|
+
| `createMemoryStorage()` | In-memory auth storage adapter |
|
|
121
|
+
| `QueryBuilder` | Fluent query builder (also re-exported from `@rebasepro/common`) |
|
|
122
|
+
| `Entity`, `FindResponse` | Re-exported from `@rebasepro/types` |
|
|
123
|
+
|
|
124
|
+
## Quick Start
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
import { createRebaseClient } from "@rebasepro/client";
|
|
128
|
+
|
|
129
|
+
const client = createRebaseClient({
|
|
130
|
+
baseUrl: "http://localhost:3001",
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Auth
|
|
134
|
+
await client.auth.signInWithEmail("user@example.com", "password");
|
|
135
|
+
|
|
136
|
+
// CRUD
|
|
137
|
+
const { data: products } = await client.data.products.find({ limit: 10 });
|
|
138
|
+
const product = await client.data.products.create({ name: "Camera", price: 299 });
|
|
139
|
+
await client.data.products.update(product.id, { price: 249 });
|
|
140
|
+
await client.data.products.delete(product.id);
|
|
141
|
+
|
|
142
|
+
// Fluent queries
|
|
143
|
+
const { data: expensive } = await client.data.products
|
|
144
|
+
.where("price", ">=", 100)
|
|
145
|
+
.orderBy("price", "desc")
|
|
146
|
+
.limit(5)
|
|
147
|
+
.find();
|
|
148
|
+
|
|
149
|
+
// Custom function
|
|
150
|
+
const result = await client.functions.invoke("process-order", { orderId: "123" });
|
|
151
|
+
|
|
152
|
+
// Realtime
|
|
153
|
+
const unsubscribe = client.data.products.listen(
|
|
154
|
+
{ limit: 50 },
|
|
155
|
+
(response) => console.log("Update:", response.data)
|
|
156
|
+
);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Related Packages
|
|
160
|
+
|
|
161
|
+
- [`@rebasepro/common`](../common) — `QueryBuilder`, `buildRebaseData`, shared utilities
|
|
162
|
+
- [`@rebasepro/types`](../types) — `Entity`, `FindResponse`, `CollectionAccessor`, etc.
|
|
163
|
+
- [`@rebasepro/utils`](../utils) — `toSnakeCase` and other helpers
|
|
164
|
+
- [`@rebasepro/auth`](../auth) — React hook adapter that wraps `client.auth` for CMS integration
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/client",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "HTTP SDK client for the Rebase custom backend",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"./package.json": "./package.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@rebasepro/
|
|
34
|
-
"@rebasepro/
|
|
35
|
-
"@rebasepro/utils": "0.
|
|
33
|
+
"@rebasepro/types": "0.5.0",
|
|
34
|
+
"@rebasepro/common": "0.5.0",
|
|
35
|
+
"@rebasepro/utils": "0.5.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@jest/globals": "^29.7.0",
|