@rebasepro/client 0.6.0 → 0.7.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/dist/admin.d.ts +13 -0
- package/dist/api-keys.d.ts +65 -0
- package/dist/auth.d.ts +10 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +87 -3
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +87 -2
- package/dist/index.umd.js.map +1 -1
- package/package.json +12 -12
- package/src/admin.ts +19 -0
- package/src/api-keys.ts +109 -0
- package/src/auth.ts +30 -0
- package/src/index.ts +6 -0
- package/src/transport.ts +2 -2
- package/LICENSE +0 -21
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.7.0",
|
|
5
5
|
"description": "HTTP SDK client for the Rebase custom backend",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -20,6 +20,13 @@
|
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=14"
|
|
22
22
|
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"watch": "vite build --watch",
|
|
25
|
+
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
|
|
26
|
+
"test:lint": "eslint \"src/**\" --quiet",
|
|
27
|
+
"test": "jest --passWithNoTests --forceExit",
|
|
28
|
+
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
|
|
29
|
+
},
|
|
23
30
|
"exports": {
|
|
24
31
|
".": {
|
|
25
32
|
"types": "./dist/index.d.ts",
|
|
@@ -30,9 +37,9 @@
|
|
|
30
37
|
"./package.json": "./package.json"
|
|
31
38
|
},
|
|
32
39
|
"dependencies": {
|
|
33
|
-
"@rebasepro/common": "
|
|
34
|
-
"@rebasepro/
|
|
35
|
-
"@rebasepro/
|
|
40
|
+
"@rebasepro/common": "workspace:*",
|
|
41
|
+
"@rebasepro/types": "workspace:*",
|
|
42
|
+
"@rebasepro/utils": "workspace:*"
|
|
36
43
|
},
|
|
37
44
|
"devDependencies": {
|
|
38
45
|
"@jest/globals": "^30.4.1",
|
|
@@ -71,12 +78,5 @@
|
|
|
71
78
|
"^@rebasepro/types$": "<rootDir>/../types/src/index.ts",
|
|
72
79
|
"^@rebasepro/utils$": "<rootDir>/../utils/src/index.ts"
|
|
73
80
|
}
|
|
74
|
-
},
|
|
75
|
-
"scripts": {
|
|
76
|
-
"watch": "vite build --watch",
|
|
77
|
-
"build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
|
|
78
|
-
"test:lint": "eslint \"src/**\" --quiet",
|
|
79
|
-
"test": "jest --passWithNoTests --forceExit",
|
|
80
|
-
"clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
}
|
package/src/admin.ts
CHANGED
|
@@ -53,6 +53,23 @@ export function createAdmin(transport: Transport, options?: CreateAdminOptions)
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
async function resetPassword(userId: string, options?: { password?: string }) {
|
|
57
|
+
return transport.request<{ user: AdminUser; temporaryPassword?: string; invitationSent?: boolean }>(
|
|
58
|
+
adminPath + "/users/" + encodeURIComponent(userId) + "/reset-password",
|
|
59
|
+
{
|
|
60
|
+
method: "POST",
|
|
61
|
+
...(options?.password ? { body: JSON.stringify({ password: options.password }) } : {})
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function listRoles() {
|
|
67
|
+
return transport.request<{ roles: Array<{ id: string; name: string }> }>(
|
|
68
|
+
adminPath + "/roles",
|
|
69
|
+
{ method: "GET" }
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
56
73
|
async function bootstrap() {
|
|
57
74
|
return transport.request<{ success: boolean; message: string; user: { uid: string; roles: string[] } }>(adminPath + "/bootstrap", {
|
|
58
75
|
method: "POST"
|
|
@@ -66,6 +83,8 @@ export function createAdmin(transport: Transport, options?: CreateAdminOptions)
|
|
|
66
83
|
createUser,
|
|
67
84
|
updateUser,
|
|
68
85
|
deleteUser,
|
|
86
|
+
resetPassword,
|
|
87
|
+
listRoles,
|
|
69
88
|
bootstrap
|
|
70
89
|
};
|
|
71
90
|
}
|
package/src/api-keys.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { Transport } from "./transport";
|
|
2
|
+
|
|
3
|
+
// Re-define the types locally since they live in server-core, not in @rebasepro/types.
|
|
4
|
+
// These match the server-side types exactly.
|
|
5
|
+
|
|
6
|
+
/** A single permission entry scoping an API key to a collection and its allowed operations. */
|
|
7
|
+
export interface ApiKeyPermission {
|
|
8
|
+
collection: string;
|
|
9
|
+
operations: ("read" | "write" | "delete")[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** An API key with the secret portion masked (returned by list / get / update). */
|
|
13
|
+
export interface ApiKeyMasked {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
key_prefix: string;
|
|
17
|
+
permissions: ApiKeyPermission[];
|
|
18
|
+
rate_limit: number | null;
|
|
19
|
+
created_by: string;
|
|
20
|
+
created_at: string;
|
|
21
|
+
updated_at: string;
|
|
22
|
+
last_used_at: string | null;
|
|
23
|
+
expires_at: string | null;
|
|
24
|
+
revoked_at: string | null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** An API key including the full secret (returned only on creation). */
|
|
28
|
+
export interface ApiKeyWithSecret extends ApiKeyMasked {
|
|
29
|
+
key: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Payload for creating a new API key. */
|
|
33
|
+
export interface CreateApiKeyRequest {
|
|
34
|
+
name: string;
|
|
35
|
+
permissions: ApiKeyPermission[];
|
|
36
|
+
rate_limit?: number | null;
|
|
37
|
+
expires_at?: string | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Payload for updating an existing API key. */
|
|
41
|
+
export interface UpdateApiKeyRequest {
|
|
42
|
+
name?: string;
|
|
43
|
+
permissions?: ApiKeyPermission[];
|
|
44
|
+
rate_limit?: number | null;
|
|
45
|
+
expires_at?: string | null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Options for the `createApiKeys` factory. */
|
|
49
|
+
export interface CreateApiKeysOptions {
|
|
50
|
+
apiKeysPath?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Creates a client for managing API keys via the admin routes.
|
|
55
|
+
*
|
|
56
|
+
* @param transport - The shared HTTP transport created by `createTransport`.
|
|
57
|
+
* @param options - Optional overrides (e.g. a custom base path).
|
|
58
|
+
*/
|
|
59
|
+
export function createApiKeys(transport: Transport, options?: CreateApiKeysOptions) {
|
|
60
|
+
const apiKeysPath = options?.apiKeysPath || "/admin/api-keys";
|
|
61
|
+
|
|
62
|
+
/** List all API keys (masked). */
|
|
63
|
+
async function listKeys(): Promise<{ keys: ApiKeyMasked[] }> {
|
|
64
|
+
return transport.request<{ keys: ApiKeyMasked[] }>(apiKeysPath, { method: "GET" });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Get a single API key by ID (masked). */
|
|
68
|
+
async function getKey(id: string): Promise<{ key: ApiKeyMasked }> {
|
|
69
|
+
return transport.request<{ key: ApiKeyMasked }>(
|
|
70
|
+
apiKeysPath + "/" + encodeURIComponent(id),
|
|
71
|
+
{ method: "GET" }
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Create a new API key. The full secret is included in the response. */
|
|
76
|
+
async function createKey(data: CreateApiKeyRequest): Promise<{ key: ApiKeyWithSecret }> {
|
|
77
|
+
return transport.request<{ key: ApiKeyWithSecret }>(apiKeysPath, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: JSON.stringify(data)
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Update an existing API key. */
|
|
84
|
+
async function updateKey(id: string, data: UpdateApiKeyRequest): Promise<{ key: ApiKeyMasked }> {
|
|
85
|
+
return transport.request<{ key: ApiKeyMasked }>(
|
|
86
|
+
apiKeysPath + "/" + encodeURIComponent(id),
|
|
87
|
+
{
|
|
88
|
+
method: "PUT",
|
|
89
|
+
body: JSON.stringify(data)
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Revoke (soft-delete) an API key. */
|
|
95
|
+
async function revokeKey(id: string): Promise<{ success: boolean }> {
|
|
96
|
+
return transport.request<{ success: boolean }>(
|
|
97
|
+
apiKeysPath + "/" + encodeURIComponent(id),
|
|
98
|
+
{ method: "DELETE" }
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
listKeys,
|
|
104
|
+
getKey,
|
|
105
|
+
createKey,
|
|
106
|
+
updateKey,
|
|
107
|
+
revokeKey
|
|
108
|
+
};
|
|
109
|
+
}
|
package/src/auth.ts
CHANGED
|
@@ -35,6 +35,7 @@ export interface AuthConfig {
|
|
|
35
35
|
emailServiceEnabled?: boolean;
|
|
36
36
|
passwordReset?: boolean;
|
|
37
37
|
emailVerification?: boolean;
|
|
38
|
+
magicLink?: boolean;
|
|
38
39
|
enabledProviders: string[];
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -428,6 +429,33 @@ newPassword })
|
|
|
428
429
|
return body as { success: boolean; message: string; };
|
|
429
430
|
}
|
|
430
431
|
|
|
432
|
+
async function sendMagicLink(email: string) {
|
|
433
|
+
const fetchFn = getFetch();
|
|
434
|
+
const res = await fetchFn(authUrl("/magic-link"), {
|
|
435
|
+
method: "POST",
|
|
436
|
+
headers: { "Content-Type": "application/json" },
|
|
437
|
+
body: JSON.stringify({ email })
|
|
438
|
+
});
|
|
439
|
+
const body = await res.json().catch(() => ({}));
|
|
440
|
+
if (!res.ok) throwApiError(res.status, body, res.statusText);
|
|
441
|
+
return body as { success: boolean; message: string; };
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
async function verifyMagicLink(token: string) {
|
|
445
|
+
const fetchFn = getFetch();
|
|
446
|
+
const res = await fetchFn(authUrl("/magic-link/verify"), {
|
|
447
|
+
method: "POST",
|
|
448
|
+
headers: { "Content-Type": "application/json" },
|
|
449
|
+
body: JSON.stringify({ token })
|
|
450
|
+
});
|
|
451
|
+
const body = await res.json().catch(() => ({}));
|
|
452
|
+
if (!res.ok) throwApiError(res.status, body, res.statusText);
|
|
453
|
+
const session = handleAuthResponse(body, "SIGNED_IN");
|
|
454
|
+
return { user: session.user,
|
|
455
|
+
accessToken: session.accessToken,
|
|
456
|
+
refreshToken: session.refreshToken };
|
|
457
|
+
}
|
|
458
|
+
|
|
431
459
|
async function getSessions() {
|
|
432
460
|
const data = await transport.request<{ sessions: Record<string, unknown>[] }>(authPath + "/sessions", { method: "GET" });
|
|
433
461
|
return data.sessions;
|
|
@@ -517,6 +545,8 @@ newPassword })
|
|
|
517
545
|
changePassword,
|
|
518
546
|
sendVerificationEmail,
|
|
519
547
|
verifyEmail,
|
|
548
|
+
sendMagicLink,
|
|
549
|
+
verifyMagicLink,
|
|
520
550
|
getSessions,
|
|
521
551
|
revokeSession,
|
|
522
552
|
revokeAllSessions,
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { createTransport, RebaseClientConfig } from "./transport";
|
|
|
2
2
|
import { createAuth, CreateAuthOptions } from "./auth";
|
|
3
3
|
import { createAdmin, CreateAdminOptions } from "./admin";
|
|
4
4
|
import { createCron, CreateCronOptions } from "./cron";
|
|
5
|
+
import { createApiKeys, CreateApiKeysOptions } from "./api-keys";
|
|
5
6
|
import { createCollectionClient, CollectionClient } from "./collection";
|
|
6
7
|
import { createFunctionsClient } from "./functions";
|
|
7
8
|
import { createStorage } from "./storage";
|
|
@@ -13,6 +14,7 @@ export * from "./transport";
|
|
|
13
14
|
export * from "./auth";
|
|
14
15
|
export * from "./admin";
|
|
15
16
|
export * from "./cron";
|
|
17
|
+
export * from "./api-keys";
|
|
16
18
|
export * from "./collection";
|
|
17
19
|
export * from "./query_builder";
|
|
18
20
|
export * from "./websocket";
|
|
@@ -25,6 +27,7 @@ export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
|
25
27
|
auth?: CreateAuthOptions;
|
|
26
28
|
admin?: CreateAdminOptions;
|
|
27
29
|
cron?: CreateCronOptions;
|
|
30
|
+
apiKeys?: CreateApiKeysOptions;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
// ─── Typed Data Proxy ────────────────────────────────────────────────────────
|
|
@@ -62,6 +65,7 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
|
|
|
62
65
|
auth: ReturnType<typeof createAuth>;
|
|
63
66
|
admin: ReturnType<typeof createAdmin>;
|
|
64
67
|
cron: ReturnType<typeof createCron>;
|
|
68
|
+
apiKeys: ReturnType<typeof createApiKeys>;
|
|
65
69
|
functions: ReturnType<typeof createFunctionsClient>;
|
|
66
70
|
ws?: RebaseWebSocketClient;
|
|
67
71
|
storage: StorageSource;
|
|
@@ -110,6 +114,7 @@ export function createRebaseClient<DB = Record<string, unknown>>(options: Create
|
|
|
110
114
|
const auth = createAuth(transport, options.auth);
|
|
111
115
|
const admin = createAdmin(transport, options.admin);
|
|
112
116
|
const cron = createCron(transport, options.cron);
|
|
117
|
+
const apiKeys = createApiKeys(transport, options.apiKeys);
|
|
113
118
|
const storage = createStorage(transport);
|
|
114
119
|
const functions = createFunctionsClient(transport);
|
|
115
120
|
|
|
@@ -198,6 +203,7 @@ export function createRebaseClient<DB = Record<string, unknown>>(options: Create
|
|
|
198
203
|
auth,
|
|
199
204
|
admin,
|
|
200
205
|
cron,
|
|
206
|
+
apiKeys,
|
|
201
207
|
functions,
|
|
202
208
|
storage,
|
|
203
209
|
ws,
|
package/src/transport.ts
CHANGED
|
@@ -90,7 +90,7 @@ function normalizeWhereValue(value: WhereFieldValue): string {
|
|
|
90
90
|
|
|
91
91
|
function serializeLogicalCondition(cond: any): string {
|
|
92
92
|
if ("type" in cond) {
|
|
93
|
-
const sub = cond.conditions.map(serializeLogicalCondition).join(",");
|
|
93
|
+
const sub = (cond.conditions ?? []).map(serializeLogicalCondition).join(",");
|
|
94
94
|
return `${cond.type}(${sub})`;
|
|
95
95
|
} else {
|
|
96
96
|
const op = OP_MAP[cond.operator] ?? cond.operator;
|
|
@@ -126,7 +126,7 @@ export function buildQueryString(params?: FindParams): string {
|
|
|
126
126
|
|
|
127
127
|
if (params.logical) {
|
|
128
128
|
const root = params.logical;
|
|
129
|
-
const serialized = root.conditions.map(serializeLogicalCondition).join(",");
|
|
129
|
+
const serialized = (root.conditions ?? []).map(serializeLogicalCondition).join(",");
|
|
130
130
|
parts.push(`${root.type}=${encodeURIComponent(`(${serialized})`)}`);
|
|
131
131
|
}
|
|
132
132
|
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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.
|