@rebasepro/client 0.0.1-canary.eae7889 → 0.0.1-canary.eb08332
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/LICENSE +21 -6
- package/README.md +164 -0
- package/dist/admin.d.ts +14 -41
- package/dist/api-keys.d.ts +66 -0
- package/dist/auth.d.ts +64 -39
- package/dist/backups.d.ts +13 -0
- package/dist/collection.d.ts +11 -13
- package/dist/collection.test.d.ts +1 -0
- package/dist/data-proxy.test.d.ts +1 -0
- package/dist/errors.d.ts +9 -0
- package/dist/functions.d.ts +49 -0
- package/dist/index.d.ts +64 -22
- package/dist/index.es.js +2438 -2249
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2511 -2277
- package/dist/index.umd.js.map +1 -1
- package/dist/query_builder.d.ts +1 -53
- package/dist/sdk_query_builder.d.ts +63 -0
- package/dist/storage-registry.d.ts +42 -0
- package/dist/storage.d.ts +9 -1
- package/dist/transport.d.ts +2 -6
- package/dist/websocket.d.ts +39 -26
- package/package.json +15 -15
- package/src/admin.ts +17 -46
- package/src/api-keys.ts +110 -0
- package/src/auth.ts +299 -66
- package/src/backups.ts +40 -0
- package/src/collection.test.ts +253 -0
- package/src/collection.ts +139 -168
- package/src/data-proxy.test.ts +167 -0
- package/src/errors.ts +9 -0
- package/src/functions.ts +80 -0
- package/src/index.ts +301 -38
- package/src/query_builder.ts +1 -125
- package/src/reviver.ts +2 -2
- package/src/sdk_query_builder.ts +138 -0
- package/src/storage-registry.ts +102 -0
- package/src/storage.ts +92 -50
- package/src/transport.ts +53 -85
- package/src/websocket.ts +323 -164
package/LICENSE
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Rebase
|
|
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,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 snapshot 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 snapshot. Returns `Snapshot<M> \| undefined` |
|
|
53
|
+
| `create(data, id?)` | Create snapshot. Returns `Snapshot<M>` |
|
|
54
|
+
| `update(id, data)` | Update snapshot. Returns `Snapshot<M>` |
|
|
55
|
+
| `delete(id)` | Delete snapshot |
|
|
56
|
+
| `count(params?)` | Count matching snapshots |
|
|
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 snapshots — returns `QueryBuilder` |
|
|
62
|
+
| `listen(params, onUpdate, onError?)` | Realtime subscription (requires WebSocket) |
|
|
63
|
+
| `listenById(id, onUpdate, onError?)` | Realtime single-snapshot 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
|
+
| `Snapshot`, `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) — `Snapshot`, `FindResponse`, `CollectionAccessor`, etc.
|
|
163
|
+
- [`@rebasepro/utils`](../utils) — `toSnakeCase` and other helpers
|
|
164
|
+
- [`@rebasepro/app`](../auth) — React hook adapter that wraps `client.auth` for CMS integration
|
package/dist/admin.d.ts
CHANGED
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
import { Transport } from "./transport";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
email: string;
|
|
5
|
-
displayName: string | null;
|
|
6
|
-
photoURL: string | null;
|
|
7
|
-
provider: string;
|
|
8
|
-
roles: string[];
|
|
9
|
-
createdAt: string;
|
|
10
|
-
updatedAt: string;
|
|
11
|
-
}
|
|
12
|
-
export interface RebaseRole {
|
|
13
|
-
id: string;
|
|
14
|
-
name: string;
|
|
15
|
-
isAdmin: boolean;
|
|
16
|
-
defaultPermissions: Record<string, unknown> | null;
|
|
17
|
-
config: Record<string, unknown> | null;
|
|
18
|
-
}
|
|
1
|
+
import type { Transport } from "./transport";
|
|
2
|
+
import { AdminUser } from "@rebasepro/types";
|
|
3
|
+
export type { AdminUser };
|
|
19
4
|
export interface CreateAdminOptions {
|
|
20
5
|
adminPath?: string;
|
|
21
6
|
}
|
|
@@ -57,31 +42,19 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
|
|
|
57
42
|
deleteUser: (userId: string) => Promise<{
|
|
58
43
|
success: boolean;
|
|
59
44
|
}>;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}>;
|
|
63
|
-
getRole: (roleId: string) => Promise<{
|
|
64
|
-
role: RebaseRole;
|
|
65
|
-
}>;
|
|
66
|
-
createRole: (data: {
|
|
67
|
-
id: string;
|
|
68
|
-
name: string;
|
|
69
|
-
isAdmin?: boolean;
|
|
70
|
-
defaultPermissions?: Record<string, unknown>;
|
|
71
|
-
config?: Record<string, unknown>;
|
|
72
|
-
}) => Promise<{
|
|
73
|
-
role: RebaseRole;
|
|
74
|
-
}>;
|
|
75
|
-
updateRole: (roleId: string, data: {
|
|
76
|
-
name?: string;
|
|
77
|
-
isAdmin?: boolean;
|
|
78
|
-
defaultPermissions?: Record<string, unknown>;
|
|
79
|
-
config?: Record<string, unknown>;
|
|
45
|
+
resetPassword: (userId: string, options?: {
|
|
46
|
+
password?: string;
|
|
80
47
|
}) => Promise<{
|
|
81
|
-
|
|
48
|
+
user: AdminUser;
|
|
49
|
+
temporaryPassword?: string;
|
|
50
|
+
invitationSent?: boolean;
|
|
51
|
+
emailDeliveryFailed?: boolean;
|
|
82
52
|
}>;
|
|
83
|
-
|
|
84
|
-
|
|
53
|
+
listRoles: () => Promise<{
|
|
54
|
+
roles: Array<{
|
|
55
|
+
id: string;
|
|
56
|
+
name: string;
|
|
57
|
+
}>;
|
|
85
58
|
}>;
|
|
86
59
|
bootstrap: () => Promise<{
|
|
87
60
|
success: boolean;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Transport } from "./transport";
|
|
2
|
+
/** A single permission entry scoping an API key to a collection and its allowed operations. */
|
|
3
|
+
export interface ApiKeyPermission {
|
|
4
|
+
collection: string;
|
|
5
|
+
operations: ("read" | "write" | "delete")[];
|
|
6
|
+
}
|
|
7
|
+
/** An API key with the secret portion masked (returned by list / get / update). */
|
|
8
|
+
export interface ApiKeyMasked {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
key_prefix: string;
|
|
12
|
+
permissions: ApiKeyPermission[];
|
|
13
|
+
admin: boolean;
|
|
14
|
+
rate_limit: number | null;
|
|
15
|
+
created_by: string;
|
|
16
|
+
created_at: string;
|
|
17
|
+
updated_at: string;
|
|
18
|
+
last_used_at: string | null;
|
|
19
|
+
expires_at: string | null;
|
|
20
|
+
revoked_at: string | null;
|
|
21
|
+
}
|
|
22
|
+
/** An API key including the full secret (returned only on creation). */
|
|
23
|
+
export interface ApiKeyWithSecret extends ApiKeyMasked {
|
|
24
|
+
key: string;
|
|
25
|
+
}
|
|
26
|
+
/** Payload for creating a new API key. */
|
|
27
|
+
export interface CreateApiKeyRequest {
|
|
28
|
+
name: string;
|
|
29
|
+
permissions: ApiKeyPermission[];
|
|
30
|
+
rate_limit?: number | null;
|
|
31
|
+
expires_at?: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** Payload for updating an existing API key. */
|
|
34
|
+
export interface UpdateApiKeyRequest {
|
|
35
|
+
name?: string;
|
|
36
|
+
permissions?: ApiKeyPermission[];
|
|
37
|
+
rate_limit?: number | null;
|
|
38
|
+
expires_at?: string | null;
|
|
39
|
+
}
|
|
40
|
+
/** Options for the `createApiKeys` factory. */
|
|
41
|
+
export interface CreateApiKeysOptions {
|
|
42
|
+
apiKeysPath?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a client for managing API keys via the admin routes.
|
|
46
|
+
*
|
|
47
|
+
* @param transport - The shared HTTP transport created by `createTransport`.
|
|
48
|
+
* @param options - Optional overrides (e.g. a custom base path).
|
|
49
|
+
*/
|
|
50
|
+
export declare function createApiKeys(transport: Transport, options?: CreateApiKeysOptions): {
|
|
51
|
+
listKeys: () => Promise<{
|
|
52
|
+
keys: ApiKeyMasked[];
|
|
53
|
+
}>;
|
|
54
|
+
getKey: (id: string) => Promise<{
|
|
55
|
+
key: ApiKeyMasked;
|
|
56
|
+
}>;
|
|
57
|
+
createKey: (data: CreateApiKeyRequest) => Promise<{
|
|
58
|
+
key: ApiKeyWithSecret;
|
|
59
|
+
}>;
|
|
60
|
+
updateKey: (id: string, data: UpdateApiKeyRequest) => Promise<{
|
|
61
|
+
key: ApiKeyMasked;
|
|
62
|
+
}>;
|
|
63
|
+
revokeKey: (id: string) => Promise<{
|
|
64
|
+
success: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
};
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,31 +1,24 @@
|
|
|
1
1
|
import { Transport } from "./transport";
|
|
2
|
-
|
|
2
|
+
import type { AuthChangeEvent, RebaseSession, AuthTokens, DeviceSession, User } from "@rebasepro/types";
|
|
3
|
+
export type { RebaseSession, AuthTokens, AuthChangeEvent, DeviceSession } from "@rebasepro/types";
|
|
4
|
+
/** @deprecated Use `User` from `@rebasepro/types` instead. */
|
|
5
|
+
export type RebaseUser = User;
|
|
6
|
+
/** @deprecated Use `AuthTokens` from `@rebasepro/types` instead. */
|
|
7
|
+
export type RebaseTokens = AuthTokens;
|
|
8
|
+
/** Minimal, non-sensitive user profile returned by {@link findUserByEmail}. */
|
|
9
|
+
export interface PublicUserProfile {
|
|
3
10
|
uid: string;
|
|
4
|
-
email: string | null;
|
|
5
11
|
displayName: string | null;
|
|
6
12
|
photoURL: string | null;
|
|
7
|
-
emailVerified?: boolean;
|
|
8
|
-
roles?: string[];
|
|
9
|
-
providerId: string;
|
|
10
|
-
isAnonymous: boolean;
|
|
11
13
|
}
|
|
12
|
-
export interface RebaseTokens {
|
|
13
|
-
accessToken: string;
|
|
14
|
-
refreshToken: string;
|
|
15
|
-
accessTokenExpiresAt: number;
|
|
16
|
-
}
|
|
17
|
-
export interface RebaseSession {
|
|
18
|
-
accessToken: string;
|
|
19
|
-
refreshToken: string;
|
|
20
|
-
expiresAt: number;
|
|
21
|
-
user: RebaseUser;
|
|
22
|
-
}
|
|
23
|
-
export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
|
|
24
14
|
export interface AuthConfig {
|
|
25
15
|
needsSetup: boolean;
|
|
26
16
|
registrationEnabled: boolean;
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
emailServiceEnabled?: boolean;
|
|
18
|
+
passwordReset?: boolean;
|
|
19
|
+
emailVerification?: boolean;
|
|
20
|
+
magicLink?: boolean;
|
|
21
|
+
enabledProviders: string[];
|
|
29
22
|
}
|
|
30
23
|
export interface AuthStorage {
|
|
31
24
|
getItem: (key: string) => string | null;
|
|
@@ -38,40 +31,53 @@ export interface CreateAuthOptions {
|
|
|
38
31
|
authPath?: string;
|
|
39
32
|
autoRefresh?: boolean;
|
|
40
33
|
persistSession?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Authentication flow mode.
|
|
36
|
+
* - 'json' (default): Tokens are sent/received in JSON bodies. Refresh token is stored in local storage.
|
|
37
|
+
* - 'cookie': Refresh token is sent/received via httpOnly cookies. Access token remains in memory.
|
|
38
|
+
*/
|
|
39
|
+
authFlowMode?: "json" | "cookie";
|
|
41
40
|
}
|
|
42
41
|
export declare function createAuth(transport: Transport, options?: CreateAuthOptions): {
|
|
43
42
|
signInWithEmail: (email: string, password: string) => Promise<{
|
|
44
|
-
user:
|
|
43
|
+
user: User;
|
|
45
44
|
accessToken: string;
|
|
46
45
|
refreshToken: string;
|
|
47
46
|
}>;
|
|
48
47
|
signUp: (email: string, password: string, displayName?: string) => Promise<{
|
|
49
|
-
user:
|
|
48
|
+
user: User;
|
|
50
49
|
accessToken: string;
|
|
51
50
|
refreshToken: string;
|
|
52
51
|
}>;
|
|
53
|
-
signInWithGoogle: (
|
|
54
|
-
|
|
52
|
+
signInWithGoogle: (payload: {
|
|
53
|
+
idToken: string;
|
|
54
|
+
} | {
|
|
55
|
+
accessToken: string;
|
|
56
|
+
} | {
|
|
57
|
+
code: string;
|
|
58
|
+
redirectUri: string;
|
|
59
|
+
}) => Promise<{
|
|
60
|
+
user: User;
|
|
55
61
|
accessToken: string;
|
|
56
62
|
refreshToken: string;
|
|
57
63
|
}>;
|
|
58
64
|
signInWithLinkedin: (code: string, redirectUri: string) => Promise<{
|
|
59
|
-
user:
|
|
65
|
+
user: User;
|
|
60
66
|
accessToken: string;
|
|
61
67
|
refreshToken: string;
|
|
62
68
|
}>;
|
|
63
69
|
signInWithOAuth: (providerId: string, payload: Record<string, unknown>) => Promise<{
|
|
64
|
-
user:
|
|
70
|
+
user: User;
|
|
65
71
|
accessToken: string;
|
|
66
72
|
refreshToken: string;
|
|
67
73
|
}>;
|
|
68
74
|
signInWithGitHub: (code: string, redirectUri: string) => Promise<{
|
|
69
|
-
user:
|
|
75
|
+
user: User;
|
|
70
76
|
accessToken: string;
|
|
71
77
|
refreshToken: string;
|
|
72
78
|
}>;
|
|
73
79
|
signInWithMicrosoft: (code: string, redirectUri: string) => Promise<{
|
|
74
|
-
user:
|
|
80
|
+
user: User;
|
|
75
81
|
accessToken: string;
|
|
76
82
|
refreshToken: string;
|
|
77
83
|
}>;
|
|
@@ -82,52 +88,53 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
82
88
|
};
|
|
83
89
|
email?: string;
|
|
84
90
|
}) => Promise<{
|
|
85
|
-
user:
|
|
91
|
+
user: User;
|
|
86
92
|
accessToken: string;
|
|
87
93
|
refreshToken: string;
|
|
88
94
|
}>;
|
|
89
95
|
signInWithFacebook: (code: string, redirectUri: string) => Promise<{
|
|
90
|
-
user:
|
|
96
|
+
user: User;
|
|
91
97
|
accessToken: string;
|
|
92
98
|
refreshToken: string;
|
|
93
99
|
}>;
|
|
94
100
|
signInWithTwitter: (code: string, redirectUri: string, codeVerifier: string) => Promise<{
|
|
95
|
-
user:
|
|
101
|
+
user: User;
|
|
96
102
|
accessToken: string;
|
|
97
103
|
refreshToken: string;
|
|
98
104
|
}>;
|
|
99
105
|
signInWithDiscord: (code: string, redirectUri: string) => Promise<{
|
|
100
|
-
user:
|
|
106
|
+
user: User;
|
|
101
107
|
accessToken: string;
|
|
102
108
|
refreshToken: string;
|
|
103
109
|
}>;
|
|
104
110
|
signInWithGitLab: (code: string, redirectUri: string) => Promise<{
|
|
105
|
-
user:
|
|
111
|
+
user: User;
|
|
106
112
|
accessToken: string;
|
|
107
113
|
refreshToken: string;
|
|
108
114
|
}>;
|
|
109
115
|
signInWithBitbucket: (code: string, redirectUri: string) => Promise<{
|
|
110
|
-
user:
|
|
116
|
+
user: User;
|
|
111
117
|
accessToken: string;
|
|
112
118
|
refreshToken: string;
|
|
113
119
|
}>;
|
|
114
120
|
signInWithSlack: (code: string, redirectUri: string) => Promise<{
|
|
115
|
-
user:
|
|
121
|
+
user: User;
|
|
116
122
|
accessToken: string;
|
|
117
123
|
refreshToken: string;
|
|
118
124
|
}>;
|
|
119
125
|
signInWithSpotify: (code: string, redirectUri: string) => Promise<{
|
|
120
|
-
user:
|
|
126
|
+
user: User;
|
|
121
127
|
accessToken: string;
|
|
122
128
|
refreshToken: string;
|
|
123
129
|
}>;
|
|
124
130
|
signOut: () => Promise<void>;
|
|
125
131
|
refreshSession: () => Promise<RebaseSession>;
|
|
126
|
-
getUser: () => Promise<
|
|
132
|
+
getUser: () => Promise<User>;
|
|
133
|
+
findUserByEmail: (email: string) => Promise<PublicUserProfile | null>;
|
|
127
134
|
updateUser: (updates: {
|
|
128
135
|
displayName?: string;
|
|
129
136
|
photoURL?: string;
|
|
130
|
-
}) => Promise<
|
|
137
|
+
}) => Promise<User>;
|
|
131
138
|
resetPasswordForEmail: (email: string) => Promise<{
|
|
132
139
|
success: boolean;
|
|
133
140
|
message: string;
|
|
@@ -148,7 +155,16 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
148
155
|
success: boolean;
|
|
149
156
|
message: string;
|
|
150
157
|
}>;
|
|
151
|
-
|
|
158
|
+
sendMagicLink: (email: string) => Promise<{
|
|
159
|
+
success: boolean;
|
|
160
|
+
message: string;
|
|
161
|
+
}>;
|
|
162
|
+
verifyMagicLink: (token: string) => Promise<{
|
|
163
|
+
user: User;
|
|
164
|
+
accessToken: string;
|
|
165
|
+
refreshToken: string;
|
|
166
|
+
}>;
|
|
167
|
+
getSessions: () => Promise<DeviceSession[]>;
|
|
152
168
|
revokeSession: (sessionId: string) => Promise<{
|
|
153
169
|
success: boolean;
|
|
154
170
|
}>;
|
|
@@ -158,4 +174,13 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
|
|
|
158
174
|
getAuthConfig: () => Promise<AuthConfig>;
|
|
159
175
|
getSession: () => RebaseSession | null;
|
|
160
176
|
onAuthStateChange: (callback: (event: AuthChangeEvent, session: RebaseSession | null) => void) => () => boolean;
|
|
177
|
+
isInitialized: () => Promise<void>;
|
|
161
178
|
};
|
|
179
|
+
export interface CookieStorageOptions {
|
|
180
|
+
path?: string;
|
|
181
|
+
domain?: string;
|
|
182
|
+
secure?: boolean;
|
|
183
|
+
sameSite?: "Lax" | "Strict" | "None";
|
|
184
|
+
maxAge?: number;
|
|
185
|
+
}
|
|
186
|
+
export declare function createCookieStorage(options?: CookieStorageOptions): AuthStorage;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Transport } from "./transport";
|
|
2
|
+
import type { BackupInfo, BackupDestinationKind } from "@rebasepro/types";
|
|
3
|
+
export interface CreateBackupsOptions {
|
|
4
|
+
backupsPath?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function createBackups(transport: Transport, options?: CreateBackupsOptions): {
|
|
7
|
+
list: () => Promise<{
|
|
8
|
+
backups: BackupInfo[];
|
|
9
|
+
destinationKind: BackupDestinationKind;
|
|
10
|
+
configured: boolean;
|
|
11
|
+
}>;
|
|
12
|
+
download: (key: string) => Promise<Blob>;
|
|
13
|
+
};
|
package/dist/collection.d.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { Transport } from "./transport";
|
|
1
|
+
import { FindParams, Transport } from "./transport";
|
|
2
2
|
import { RebaseWebSocketClient } from "./websocket";
|
|
3
|
-
import {
|
|
4
|
-
import { FilterOperator, QueryBuilder } from "./query_builder";
|
|
3
|
+
import { SDKCollectionClient } from "@rebasepro/types";
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* The concrete, HTTP-backed implementation of the public
|
|
6
|
+
* {@link SDKCollectionClient} contract — flat rows (no Entity wrapper), plus
|
|
7
|
+
* fluent query-builder methods (`.where()`, `.orderBy()`, …).
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* This is what `createRebaseClient().data.<collection>` returns. It is not a
|
|
10
|
+
* separate API from {@link SDKCollectionClient}; it only widens it with
|
|
11
|
+
* `count()`. Program against {@link SDKCollectionClient} when you want a
|
|
12
|
+
* transport-agnostic type.
|
|
10
13
|
*/
|
|
11
|
-
export interface CollectionClient<M extends Record<string, unknown> = Record<string, unknown>> extends
|
|
12
|
-
|
|
13
|
-
orderBy(column: keyof M & string, ascending?: "asc" | "desc"): QueryBuilder<M>;
|
|
14
|
-
limit(count: number): QueryBuilder<M>;
|
|
15
|
-
offset(count: number): QueryBuilder<M>;
|
|
16
|
-
search(searchString: string): QueryBuilder<M>;
|
|
17
|
-
include(...relations: string[]): QueryBuilder<M>;
|
|
14
|
+
export interface CollectionClient<M extends Record<string, unknown> = Record<string, unknown>, I = Partial<M>, U = Partial<M>> extends SDKCollectionClient<M, I, U> {
|
|
15
|
+
count(params?: FindParams): Promise<number>;
|
|
18
16
|
}
|
|
19
17
|
export declare function createCollectionClient<M extends Record<string, unknown> = Record<string, unknown>>(transport: Transport, slug: string, ws?: RebaseWebSocketClient): CollectionClient<M>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client-side logic error (e.g. accessing an unknown collection when a typed
|
|
3
|
+
* dictionary is available). A subclass of {@link RebaseApiError}, so a single
|
|
4
|
+
* `catch (e) { if (e instanceof RebaseApiError) ... }` covers it too.
|
|
5
|
+
*
|
|
6
|
+
* The canonical definition now lives in `@rebasepro/types`; re-exported here to
|
|
7
|
+
* preserve the historical `import { RebaseClientError } from ".../errors"` path.
|
|
8
|
+
*/
|
|
9
|
+
export { RebaseClientError } from "@rebasepro/types";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { Transport } from "./transport";
|
|
2
|
+
/**
|
|
3
|
+
* Client interface for invoking custom backend functions.
|
|
4
|
+
*
|
|
5
|
+
* Custom functions are Hono route files auto-mounted by the Rebase backend
|
|
6
|
+
* at `/api/functions/{name}`. The `FunctionsClient` wraps the shared
|
|
7
|
+
* transport so callers never need to manually construct URLs or inject
|
|
8
|
+
* auth tokens.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const result = await client.functions.invoke<{ job: Job }>('extract-job', {
|
|
13
|
+
* url: 'https://example.com/posting',
|
|
14
|
+
* html: htmlContent,
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export interface FunctionsClient {
|
|
19
|
+
/**
|
|
20
|
+
* Invoke a custom backend function by name.
|
|
21
|
+
*
|
|
22
|
+
* @typeParam T - Expected shape of the response payload.
|
|
23
|
+
* @param name - Function name (the filename without extension, e.g. `"extract-job"`).
|
|
24
|
+
* @param payload - Optional JSON-serialisable body sent as `POST`.
|
|
25
|
+
* @param options - Optional overrides (HTTP method, sub-path, extra headers).
|
|
26
|
+
* @returns The parsed JSON response from the function.
|
|
27
|
+
*/
|
|
28
|
+
invoke<T = unknown>(name: string, payload?: unknown, options?: FunctionInvokeOptions): Promise<T>;
|
|
29
|
+
}
|
|
30
|
+
export interface FunctionInvokeOptions {
|
|
31
|
+
/** HTTP method — defaults to `"POST"`. */
|
|
32
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
33
|
+
/** Sub-path appended after the function name, e.g. `"status/123"`. */
|
|
34
|
+
path?: string;
|
|
35
|
+
/** Extra headers merged into the request (auth is still injected automatically). */
|
|
36
|
+
headers?: Record<string, string>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a `FunctionsClient` backed by the given transport.
|
|
40
|
+
*
|
|
41
|
+
* The transport already handles:
|
|
42
|
+
* - Base URL resolution
|
|
43
|
+
* - JWT injection via `Authorization: Bearer`
|
|
44
|
+
* - 401 retry / `onUnauthorized` flow
|
|
45
|
+
* - Consistent error throwing via `RebaseApiError`
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export declare function createFunctionsClient(transport: Transport): FunctionsClient;
|