@rebasepro/types 0.1.2 → 0.2.3
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 +1 -1
- package/dist/controllers/auth.d.ts +9 -8
- package/dist/controllers/client.d.ts +3 -0
- package/dist/controllers/data.d.ts +21 -0
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types/auth_adapter.d.ts +356 -0
- package/dist/types/collections.d.ts +67 -2
- package/dist/types/database_adapter.d.ts +94 -0
- package/dist/types/entity_actions.d.ts +7 -1
- package/dist/types/entity_callbacks.d.ts +1 -1
- package/dist/types/entity_views.d.ts +36 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/properties.d.ts +24 -5
- package/dist/types/property_config.d.ts +6 -2
- package/dist/types/relations.d.ts +1 -1
- package/dist/types/translations.d.ts +8 -0
- package/dist/users/user.d.ts +5 -0
- package/package.json +13 -10
- package/src/controllers/auth.tsx +2 -5
- package/src/controllers/client.ts +3 -2
- package/src/controllers/data.ts +25 -0
- package/src/types/auth_adapter.ts +410 -0
- package/src/types/collections.ts +77 -2
- package/src/types/database_adapter.ts +120 -0
- package/src/types/entity_actions.tsx +8 -1
- package/src/types/entity_callbacks.ts +1 -1
- package/src/types/entity_views.tsx +39 -1
- package/src/types/index.ts +2 -0
- package/src/types/plugins.tsx +1 -1
- package/src/types/properties.ts +34 -4
- package/src/types/property_config.tsx +6 -3
- package/src/types/relations.ts +1 -1
- package/src/types/translations.ts +11 -0
- package/src/users/user.ts +6 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentRef } from "./component_ref";
|
|
2
|
-
import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity } from "./entities";
|
|
2
|
+
import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity, Vector } from "./entities";
|
|
3
3
|
import type { Relation, JoinStep, OnAction } from "./relations";
|
|
4
4
|
import type { EntityCollection, FilterValues } from "./collections";
|
|
5
5
|
import type { ColorKey, ColorScheme } from "./chips";
|
|
@@ -31,8 +31,8 @@ export type PropertyCallbacks<T = unknown, M extends Record<string, unknown> = R
|
|
|
31
31
|
/**
|
|
32
32
|
* @group Entity properties
|
|
33
33
|
*/
|
|
34
|
-
export type DataType = "string" | "number" | "boolean" | "date" | "geopoint" | "reference" | "relation" | "array" | "map";
|
|
35
|
-
export type Property = StringProperty | NumberProperty | BooleanProperty | DateProperty | GeopointProperty | ReferenceProperty | RelationProperty | ArrayProperty | MapProperty;
|
|
34
|
+
export type DataType = "string" | "number" | "boolean" | "date" | "geopoint" | "reference" | "relation" | "array" | "map" | "vector" | "binary";
|
|
35
|
+
export type Property = StringProperty | NumberProperty | BooleanProperty | DateProperty | GeopointProperty | ReferenceProperty | RelationProperty | ArrayProperty | MapProperty | VectorProperty | BinaryProperty;
|
|
36
36
|
export type Properties = {
|
|
37
37
|
[key: string]: Property;
|
|
38
38
|
};
|
|
@@ -48,7 +48,7 @@ export type FirebaseProperties = {
|
|
|
48
48
|
* A helper type to infer the underlying data type from a Property definition.
|
|
49
49
|
* This is the core of the type inference system.
|
|
50
50
|
*/
|
|
51
|
-
export type InferPropertyType<P extends Property> = P extends StringProperty ? string : P extends NumberProperty ? number : P extends BooleanProperty ? boolean : P extends DateProperty ? Date : P extends GeopointProperty ? GeoPoint : P extends ReferenceProperty ? EntityReference : P extends RelationProperty ? EntityRelation | EntityRelation[] : P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) : P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) : never;
|
|
51
|
+
export type InferPropertyType<P extends Property> = P extends StringProperty ? string : P extends NumberProperty ? number : P extends BooleanProperty ? boolean : P extends DateProperty ? Date : P extends GeopointProperty ? GeoPoint : P extends ReferenceProperty ? EntityReference : P extends RelationProperty ? EntityRelation | EntityRelation[] : P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) : P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) : P extends VectorProperty ? Vector : P extends BinaryProperty ? string : never;
|
|
52
52
|
/**
|
|
53
53
|
* Helper type that determines whether a property is required.
|
|
54
54
|
* Uses direct structural matching against `{ validation: { required: true } }`
|
|
@@ -309,6 +309,25 @@ export interface BooleanProperty extends BaseProperty {
|
|
|
309
309
|
*/
|
|
310
310
|
validation?: PropertyValidationSchema;
|
|
311
311
|
}
|
|
312
|
+
/**
|
|
313
|
+
* @group Entity properties
|
|
314
|
+
*/
|
|
315
|
+
export interface VectorUIConfig extends BaseUIConfig {
|
|
316
|
+
clearable?: boolean;
|
|
317
|
+
}
|
|
318
|
+
export interface VectorProperty extends BaseProperty {
|
|
319
|
+
ui?: VectorUIConfig;
|
|
320
|
+
type: "vector";
|
|
321
|
+
dimensions: number;
|
|
322
|
+
validation?: PropertyValidationSchema;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* @group Entity properties
|
|
326
|
+
*/
|
|
327
|
+
export interface BinaryProperty extends BaseProperty {
|
|
328
|
+
type: "binary";
|
|
329
|
+
validation?: PropertyValidationSchema;
|
|
330
|
+
}
|
|
312
331
|
/**
|
|
313
332
|
* @group Entity properties
|
|
314
333
|
*/
|
|
@@ -421,7 +440,7 @@ export interface RelationProperty extends BaseProperty {
|
|
|
421
440
|
* When set, the framework treats this property as a self-contained relation
|
|
422
441
|
* definition and no separate `relations[]` entry is needed.
|
|
423
442
|
*/
|
|
424
|
-
target?: () => EntityCollection;
|
|
443
|
+
target?: string | (() => EntityCollection | string);
|
|
425
444
|
/**
|
|
426
445
|
* Whether this property references one or many records.
|
|
427
446
|
* Defaults to `"one"`.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ArrayProperty, MapProperty, StringProperty, NumberProperty, BooleanProperty, DateProperty, GeopointProperty, ReferenceProperty, RelationProperty } from "./properties";
|
|
2
|
+
import { ArrayProperty, MapProperty, StringProperty, NumberProperty, BooleanProperty, DateProperty, GeopointProperty, ReferenceProperty, RelationProperty, VectorProperty, BinaryProperty } from "./properties";
|
|
3
3
|
import { BaseProperty } from "./properties";
|
|
4
4
|
type CMSBasePropertyNoName = Omit<BaseProperty, "name">;
|
|
5
5
|
export type ConfigProperty = (Omit<StringProperty, "name"> & {
|
|
@@ -28,6 +28,10 @@ export type ConfigProperty = (Omit<StringProperty, "name"> & {
|
|
|
28
28
|
} & CMSBasePropertyNoName) | (Omit<MapProperty, "name" | "properties"> & {
|
|
29
29
|
name?: string;
|
|
30
30
|
properties?: Record<string, ConfigProperty>;
|
|
31
|
+
} & CMSBasePropertyNoName) | (Omit<VectorProperty, "name"> & {
|
|
32
|
+
name?: string;
|
|
33
|
+
} & CMSBasePropertyNoName) | (Omit<BinaryProperty, "name"> & {
|
|
34
|
+
name?: string;
|
|
31
35
|
} & CMSBasePropertyNoName);
|
|
32
36
|
/**
|
|
33
37
|
* This is the configuration object for a property.
|
|
@@ -66,5 +70,5 @@ export type PropertyConfig = {
|
|
|
66
70
|
*/
|
|
67
71
|
description?: string;
|
|
68
72
|
};
|
|
69
|
-
export type PropertyConfigId = "text_field" | "multiline" | "markdown" | "url" | "email" | "user_select" | "select" | "multi_select" | "number_input" | "number_select" | "multi_number_select" | "file_upload" | "multi_file_upload" | "group" | "key_value" | "reference" | "reference_as_string" | "multi_references" | "relation" | "switch" | "date_time" | "repeat" | "custom_array" | "block";
|
|
73
|
+
export type PropertyConfigId = "text_field" | "multiline" | "markdown" | "url" | "email" | "user_select" | "select" | "multi_select" | "number_input" | "number_select" | "multi_number_select" | "file_upload" | "multi_file_upload" | "group" | "key_value" | "reference" | "reference_as_string" | "multi_references" | "relation" | "switch" | "date_time" | "repeat" | "custom_array" | "block" | "vector_input";
|
|
70
74
|
export {};
|
|
@@ -17,7 +17,7 @@ export interface Relation {
|
|
|
17
17
|
/**
|
|
18
18
|
* The final collection you want to retrieve records from.
|
|
19
19
|
*/
|
|
20
|
-
target: () => EntityCollection;
|
|
20
|
+
target: (() => EntityCollection) | any;
|
|
21
21
|
/**
|
|
22
22
|
* The nature of the relationship, determining if one or many records are returned.
|
|
23
23
|
*/
|
|
@@ -30,6 +30,8 @@ export interface RebaseTranslations {
|
|
|
30
30
|
copy: string;
|
|
31
31
|
delete: string;
|
|
32
32
|
delete_not_allowed: string;
|
|
33
|
+
edit_entity?: string;
|
|
34
|
+
back_to_detail?: string;
|
|
33
35
|
delete_confirmation_title: string;
|
|
34
36
|
delete_confirmation_body: string;
|
|
35
37
|
delete_multiple_confirmation_body: string;
|
|
@@ -392,6 +394,12 @@ export interface RebaseTranslations {
|
|
|
392
394
|
submit: string;
|
|
393
395
|
no_filterable_properties: string;
|
|
394
396
|
apply_filters: string;
|
|
397
|
+
/** Label shown on the filter presets dropdown trigger */
|
|
398
|
+
filter_presets?: string;
|
|
399
|
+
/** Tooltip shown when hovering over a preset entry */
|
|
400
|
+
filter_preset_apply?: string;
|
|
401
|
+
/** Shown when a preset is active, with {{label}} interpolation */
|
|
402
|
+
filter_preset_active?: string;
|
|
395
403
|
list: string;
|
|
396
404
|
table_view_mode: string;
|
|
397
405
|
cards: string;
|
package/dist/users/user.d.ts
CHANGED
|
@@ -42,5 +42,10 @@ export type User = {
|
|
|
42
42
|
* The date and time when the user was created.
|
|
43
43
|
*/
|
|
44
44
|
createdAt?: Date | string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Additional metadata/custom claims associated with the user.
|
|
47
|
+
* Accessible by the frontend, but only writable by the backend.
|
|
48
|
+
*/
|
|
49
|
+
readonly metadata?: Record<string, any>;
|
|
45
50
|
getIdToken?: (forceRefresh?: boolean) => Promise<string>;
|
|
46
51
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rebasepro/types",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.3",
|
|
5
5
|
"description": "Rebase type definitions — shared interfaces and controller types",
|
|
6
6
|
"funding": {
|
|
7
7
|
"url": "https://github.com/sponsors/rebaseco"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
34
34
|
"types": "./dist/index.d.ts",
|
|
35
|
-
"development": "./
|
|
35
|
+
"development": "./dist/index.es.js",
|
|
36
36
|
"import": "./dist/index.es.js",
|
|
37
37
|
"require": "./dist/index.umd.js"
|
|
38
38
|
},
|
|
@@ -40,17 +40,20 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/jest": "^29.5.14",
|
|
43
|
-
"@types/node": "^20.
|
|
43
|
+
"@types/node": "^20.19.41",
|
|
44
44
|
"@types/object-hash": "^3.0.6",
|
|
45
|
-
"@types/react": "^19.
|
|
46
|
-
"@types/react-dom": "^19.
|
|
45
|
+
"@types/react": "^19.2.15",
|
|
46
|
+
"@types/react-dom": "^19.2.3",
|
|
47
47
|
"@types/react-measure": "^2.0.12",
|
|
48
|
-
"@vitejs/plugin-react": "^4.
|
|
49
|
-
"
|
|
48
|
+
"@vitejs/plugin-react": "^4.7.0",
|
|
49
|
+
"hono": "^4.12.21",
|
|
50
50
|
"jest": "^29.7.0",
|
|
51
|
-
"ts-jest": "^29.
|
|
52
|
-
"typescript": "^5.
|
|
53
|
-
"vite": "^5.4.
|
|
51
|
+
"ts-jest": "^29.4.10",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"vite": "^5.4.21"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"hono": "^4.12.21"
|
|
54
57
|
},
|
|
55
58
|
"files": [
|
|
56
59
|
"dist",
|
package/src/controllers/auth.tsx
CHANGED
|
@@ -98,11 +98,8 @@ export type AuthController<USER extends User = User, ExtraData = unknown> = {
|
|
|
98
98
|
export interface AuthControllerExtended<USER extends User = User, ExtraData = unknown> extends AuthController<USER, ExtraData> {
|
|
99
99
|
/** Login with email and password */
|
|
100
100
|
emailPasswordLogin?(email: string, password: string): Promise<void>;
|
|
101
|
-
/** Login with
|
|
102
|
-
googleLogin?: {
|
|
103
|
-
(token: string, tokenType?: "idToken" | "accessToken"): Promise<void>;
|
|
104
|
-
(payload: { code: string; redirectUri: string }): Promise<void>;
|
|
105
|
-
};
|
|
101
|
+
/** Login with Google — accepts an ID token, access token, or authorization code payload */
|
|
102
|
+
googleLogin?: (payload: { idToken: string } | { accessToken: string } | { code: string; redirectUri: string }) => Promise<void>;
|
|
106
103
|
/** Register a new user */
|
|
107
104
|
register?(email: string, password: string, displayName?: string): Promise<void>;
|
|
108
105
|
/** Skip login (for anonymous access if enabled) */
|
|
@@ -61,6 +61,7 @@ export interface AdminUser {
|
|
|
61
61
|
photoURL: string | null;
|
|
62
62
|
provider: string;
|
|
63
63
|
roles: string[];
|
|
64
|
+
metadata?: Record<string, any>;
|
|
64
65
|
createdAt: string;
|
|
65
66
|
updatedAt: string;
|
|
66
67
|
}
|
|
@@ -92,8 +93,8 @@ export interface AdminAPI {
|
|
|
92
93
|
orderDir?: "asc" | "desc";
|
|
93
94
|
}): Promise<{ users: AdminUser[]; total: number; limit: number; offset: number }>;
|
|
94
95
|
getUser(userId: string): Promise<{ user: AdminUser }>;
|
|
95
|
-
createUser(data: { email: string; displayName?: string; password?: string; roles?: string[] }): Promise<{ user: AdminUser }>;
|
|
96
|
-
updateUser(userId: string, data: { email?: string; displayName?: string; password?: string; roles?: string[] }): Promise<{ user: AdminUser }>;
|
|
96
|
+
createUser(data: { email: string; displayName?: string; password?: string; roles?: string[]; metadata?: Record<string, any> }): Promise<{ user: AdminUser }>;
|
|
97
|
+
updateUser(userId: string, data: { email?: string; displayName?: string; password?: string; roles?: string[]; metadata?: Record<string, any> }): Promise<{ user: AdminUser }>;
|
|
97
98
|
deleteUser(userId: string): Promise<{ success: boolean }>;
|
|
98
99
|
listRoles(): Promise<{ roles: AdminRole[] }>;
|
|
99
100
|
getRole(roleId: string): Promise<{ role: AdminRole }>;
|
package/src/controllers/data.ts
CHANGED
|
@@ -90,6 +90,23 @@ export interface FindResponse<M extends Record<string, unknown> = Record<string,
|
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
export type FilterOperator = WhereFilterOpShort;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Fluent Query Builder Interface supported on both client and server accessors.
|
|
97
|
+
* @group Data
|
|
98
|
+
*/
|
|
99
|
+
export interface QueryBuilderInterface<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
100
|
+
where(column: keyof M & string, operator: FilterOperator, value: unknown): this;
|
|
101
|
+
orderBy(column: keyof M & string, ascending?: "asc" | "desc"): this;
|
|
102
|
+
limit(count: number): this;
|
|
103
|
+
offset(count: number): this;
|
|
104
|
+
search(searchString: string): this;
|
|
105
|
+
include(...relations: string[]): this;
|
|
106
|
+
find(): Promise<FindResponse<M>>;
|
|
107
|
+
listen(onUpdate: (data: FindResponse<M>) => void, onError?: (error: Error) => void): () => void;
|
|
108
|
+
}
|
|
109
|
+
|
|
93
110
|
/**
|
|
94
111
|
* A single collection's CRUD accessor.
|
|
95
112
|
*
|
|
@@ -145,6 +162,14 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
|
|
|
145
162
|
* Count the number of records matching the given filter.
|
|
146
163
|
*/
|
|
147
164
|
count?(params?: FindParams): Promise<number>;
|
|
165
|
+
|
|
166
|
+
// Fluent Query Builder
|
|
167
|
+
where(column: keyof M & string, operator: FilterOperator, value: unknown): QueryBuilderInterface<M>;
|
|
168
|
+
orderBy(column: keyof M & string, ascending?: "asc" | "desc"): QueryBuilderInterface<M>;
|
|
169
|
+
limit(count: number): QueryBuilderInterface<M>;
|
|
170
|
+
offset(count: number): QueryBuilderInterface<M>;
|
|
171
|
+
search(searchString: string): QueryBuilderInterface<M>;
|
|
172
|
+
include(...relations: string[]): QueryBuilderInterface<M>;
|
|
148
173
|
}
|
|
149
174
|
|
|
150
175
|
/**
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module AuthAdapter
|
|
3
|
+
*
|
|
4
|
+
* Pluggable authentication abstraction for Rebase.
|
|
5
|
+
*
|
|
6
|
+
* An `AuthAdapter` decouples authentication from the database layer,
|
|
7
|
+
* allowing users to bring their own auth system (Clerk, Auth0, Firebase Auth,
|
|
8
|
+
* custom JWT, etc.) while keeping the Rebase admin frontend fully functional.
|
|
9
|
+
*
|
|
10
|
+
* @example Built-in auth (default — zero config change)
|
|
11
|
+
* ```ts
|
|
12
|
+
* initializeRebaseBackend({
|
|
13
|
+
* auth: { jwtSecret: "...", google: { clientId: "..." } },
|
|
14
|
+
* database: createPostgresAdapter({ ... }),
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @example Custom auth
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { createCustomAuthAdapter } from "@rebasepro/server-core";
|
|
21
|
+
*
|
|
22
|
+
* initializeRebaseBackend({
|
|
23
|
+
* auth: createCustomAuthAdapter({
|
|
24
|
+
* verifyRequest: async (req) => { ... },
|
|
25
|
+
* }),
|
|
26
|
+
* database: createPostgresAdapter({ ... }),
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @group Auth
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type { Hono } from "hono";
|
|
34
|
+
|
|
35
|
+
// ─── Authenticated User ──────────────────────────────────────────────────────
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The normalized user object returned by `AuthAdapter.verifyRequest()`.
|
|
39
|
+
*
|
|
40
|
+
* Regardless of the auth provider, every request is resolved to this shape
|
|
41
|
+
* so that downstream middleware (RLS scoping, route guards) can work uniformly.
|
|
42
|
+
*
|
|
43
|
+
* @group Auth
|
|
44
|
+
*/
|
|
45
|
+
export interface AuthenticatedUser {
|
|
46
|
+
/** Unique user identifier (provider-specific). */
|
|
47
|
+
uid: string;
|
|
48
|
+
/** Primary email address. */
|
|
49
|
+
email: string;
|
|
50
|
+
/** Human-readable display name. */
|
|
51
|
+
displayName?: string | null;
|
|
52
|
+
/** Avatar URL. */
|
|
53
|
+
photoUrl?: string | null;
|
|
54
|
+
/** Role identifiers the user holds. */
|
|
55
|
+
roles: string[];
|
|
56
|
+
/** Whether the user has admin privileges. */
|
|
57
|
+
isAdmin: boolean;
|
|
58
|
+
/** Raw bearer token from the request (for forwarding). */
|
|
59
|
+
rawToken?: string;
|
|
60
|
+
/** Extra claims/metadata from the auth provider. */
|
|
61
|
+
claims?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ─── Capabilities ────────────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Feature flags advertised by an auth adapter.
|
|
68
|
+
*
|
|
69
|
+
* The frontend reads these from `GET /api/auth/config` to dynamically
|
|
70
|
+
* show/hide UI elements (login form, registration, password reset, etc.).
|
|
71
|
+
*
|
|
72
|
+
* @group Auth
|
|
73
|
+
*/
|
|
74
|
+
export interface AuthAdapterCapabilities {
|
|
75
|
+
/**
|
|
76
|
+
* Whether this adapter mounts its own `/auth/*` routes.
|
|
77
|
+
*
|
|
78
|
+
* - `true` for the built-in Rebase auth (login, register, refresh, etc.)
|
|
79
|
+
* - `false` for external providers like Clerk or Auth0 that handle
|
|
80
|
+
* auth flows outside of the Rebase backend.
|
|
81
|
+
*/
|
|
82
|
+
hasBuiltInAuthRoutes: boolean;
|
|
83
|
+
|
|
84
|
+
/** Supports email/password login. */
|
|
85
|
+
emailPasswordLogin: boolean;
|
|
86
|
+
/** Supports new user registration. */
|
|
87
|
+
registration: boolean;
|
|
88
|
+
/** Supports password reset flow. */
|
|
89
|
+
passwordReset: boolean;
|
|
90
|
+
/** Supports session listing/revocation. */
|
|
91
|
+
sessionManagement: boolean;
|
|
92
|
+
/** Supports profile updates (display name, photo). */
|
|
93
|
+
profileUpdate: boolean;
|
|
94
|
+
/** Supports email verification. */
|
|
95
|
+
emailVerification: boolean;
|
|
96
|
+
/** List of enabled OAuth provider IDs (e.g. `["google", "github"]`). */
|
|
97
|
+
enabledProviders: string[];
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* For external auth (Clerk, Auth0, etc.): the URL where the user should
|
|
101
|
+
* be redirected for login. The Rebase frontend will navigate here instead
|
|
102
|
+
* of showing its own login form.
|
|
103
|
+
*/
|
|
104
|
+
externalLoginUrl?: string;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* True when no users exist yet — first-user bootstrap mode.
|
|
108
|
+
* Only applicable for built-in auth.
|
|
109
|
+
*/
|
|
110
|
+
needsSetup?: boolean;
|
|
111
|
+
|
|
112
|
+
/** Whether new user registration is enabled (may differ from `registration` capability at runtime). */
|
|
113
|
+
registrationEnabled?: boolean;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ─── User & Role Management ─────────────────────────────────────────────────
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Options for paginated user listing.
|
|
120
|
+
* @group Auth
|
|
121
|
+
*/
|
|
122
|
+
export interface AuthUserListOptions {
|
|
123
|
+
limit?: number;
|
|
124
|
+
offset?: number;
|
|
125
|
+
search?: string;
|
|
126
|
+
orderBy?: string;
|
|
127
|
+
orderDir?: "asc" | "desc";
|
|
128
|
+
roleId?: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Paginated user listing result.
|
|
133
|
+
* @group Auth
|
|
134
|
+
*/
|
|
135
|
+
export interface AuthUserListResult {
|
|
136
|
+
users: AuthUserData[];
|
|
137
|
+
total: number;
|
|
138
|
+
limit: number;
|
|
139
|
+
offset: number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* User data exposed by the auth adapter.
|
|
144
|
+
* @group Auth
|
|
145
|
+
*/
|
|
146
|
+
export interface AuthUserData {
|
|
147
|
+
id: string;
|
|
148
|
+
email: string;
|
|
149
|
+
displayName?: string | null;
|
|
150
|
+
photoUrl?: string | null;
|
|
151
|
+
emailVerified?: boolean;
|
|
152
|
+
metadata?: Record<string, any>;
|
|
153
|
+
createdAt?: Date;
|
|
154
|
+
updatedAt?: Date;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Data for creating a user.
|
|
159
|
+
* @group Auth
|
|
160
|
+
*/
|
|
161
|
+
export interface AuthCreateUserData {
|
|
162
|
+
email: string;
|
|
163
|
+
password?: string;
|
|
164
|
+
displayName?: string;
|
|
165
|
+
photoUrl?: string;
|
|
166
|
+
metadata?: Record<string, any>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Role data exposed by the auth adapter.
|
|
171
|
+
* @group Auth
|
|
172
|
+
*/
|
|
173
|
+
export interface AuthRoleData {
|
|
174
|
+
id: string;
|
|
175
|
+
name: string;
|
|
176
|
+
isAdmin: boolean;
|
|
177
|
+
defaultPermissions?: {
|
|
178
|
+
read?: boolean;
|
|
179
|
+
create?: boolean;
|
|
180
|
+
edit?: boolean;
|
|
181
|
+
delete?: boolean;
|
|
182
|
+
} | null;
|
|
183
|
+
collectionPermissions?: Record<string, {
|
|
184
|
+
read?: boolean;
|
|
185
|
+
create?: boolean;
|
|
186
|
+
edit?: boolean;
|
|
187
|
+
delete?: boolean;
|
|
188
|
+
}> | null;
|
|
189
|
+
config?: Record<string, unknown> | null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Data for creating a role.
|
|
194
|
+
* @group Auth
|
|
195
|
+
*/
|
|
196
|
+
export interface AuthCreateRoleData {
|
|
197
|
+
id: string;
|
|
198
|
+
name: string;
|
|
199
|
+
isAdmin?: boolean;
|
|
200
|
+
defaultPermissions?: AuthRoleData["defaultPermissions"];
|
|
201
|
+
collectionPermissions?: AuthRoleData["collectionPermissions"];
|
|
202
|
+
config?: AuthRoleData["config"];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* User management operations for the admin panel.
|
|
207
|
+
*
|
|
208
|
+
* Optional — if not provided by the adapter, the user management UI is hidden.
|
|
209
|
+
*
|
|
210
|
+
* @group Auth
|
|
211
|
+
*/
|
|
212
|
+
export interface UserManagementAdapter {
|
|
213
|
+
listUsers(options?: AuthUserListOptions): Promise<AuthUserListResult>;
|
|
214
|
+
getUserById(id: string): Promise<AuthUserData | null>;
|
|
215
|
+
createUser(data: AuthCreateUserData): Promise<AuthUserData>;
|
|
216
|
+
updateUser(id: string, data: Partial<AuthCreateUserData>): Promise<AuthUserData | null>;
|
|
217
|
+
deleteUser(id: string): Promise<void>;
|
|
218
|
+
getUserRoles(userId: string): Promise<AuthRoleData[]>;
|
|
219
|
+
setUserRoles(userId: string, roleIds: string[]): Promise<void>;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Role management operations for the admin panel.
|
|
224
|
+
*
|
|
225
|
+
* Optional — if not provided by the adapter, role management is disabled.
|
|
226
|
+
*
|
|
227
|
+
* @group Auth
|
|
228
|
+
*/
|
|
229
|
+
export interface RoleManagementAdapter {
|
|
230
|
+
listRoles(): Promise<AuthRoleData[]>;
|
|
231
|
+
getRoleById(id: string): Promise<AuthRoleData | null>;
|
|
232
|
+
createRole(data: AuthCreateRoleData): Promise<AuthRoleData>;
|
|
233
|
+
updateRole(id: string, data: Partial<AuthRoleData>): Promise<AuthRoleData | null>;
|
|
234
|
+
deleteRole(id: string): Promise<void>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// ─── Auth Adapter ────────────────────────────────────────────────────────────
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Pluggable authentication adapter for Rebase.
|
|
241
|
+
*
|
|
242
|
+
* This is the **key interface** that decouples authentication from the
|
|
243
|
+
* database layer. Each auth adapter knows how to:
|
|
244
|
+
*
|
|
245
|
+
* 1. Verify incoming HTTP requests (`verifyRequest`)
|
|
246
|
+
* 2. Optionally manage users and roles (for the admin panel)
|
|
247
|
+
* 3. Optionally mount auth-specific routes (login, register, etc.)
|
|
248
|
+
* 4. Advertise its capabilities so the frontend can adapt
|
|
249
|
+
*
|
|
250
|
+
* The built-in Rebase auth implements this interface internally.
|
|
251
|
+
* External providers (Clerk, Auth0, Firebase Auth) provide their own adapters.
|
|
252
|
+
* Users with custom auth can use `createCustomAuthAdapter()` for a minimal setup.
|
|
253
|
+
*
|
|
254
|
+
* @group Auth
|
|
255
|
+
*/
|
|
256
|
+
export interface AuthAdapter {
|
|
257
|
+
/**
|
|
258
|
+
* Unique identifier for this auth adapter.
|
|
259
|
+
*
|
|
260
|
+
* @example "rebase-builtin", "clerk", "auth0", "firebase", "custom"
|
|
261
|
+
*/
|
|
262
|
+
readonly id: string;
|
|
263
|
+
|
|
264
|
+
// ── Request Authentication ──────────────────────────────────────────
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Verify an incoming request and extract the authenticated user.
|
|
268
|
+
*
|
|
269
|
+
* This replaces the hardcoded JWT verification in server-core's middleware.
|
|
270
|
+
* Each adapter implements its own token verification strategy:
|
|
271
|
+
* - Built-in: verify Rebase JWT
|
|
272
|
+
* - Clerk: call Clerk's `verifyToken()`
|
|
273
|
+
* - Auth0: validate Auth0 JWT with JWKS
|
|
274
|
+
* - Custom: whatever logic the user provides
|
|
275
|
+
*
|
|
276
|
+
* @param request - The raw `Request` object (portable across Hono, Express, Fastify)
|
|
277
|
+
* @returns The authenticated user, or `null` for unauthenticated requests.
|
|
278
|
+
* Throw an error to reject the request with 401.
|
|
279
|
+
*/
|
|
280
|
+
verifyRequest(request: Request): Promise<AuthenticatedUser | null>;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Verify a raw bearer token and extract the authenticated user.
|
|
284
|
+
*
|
|
285
|
+
* Used for **WebSocket authentication**, where there is no HTTP `Request`
|
|
286
|
+
* object — only a token string sent over the socket.
|
|
287
|
+
*
|
|
288
|
+
* If not implemented, the default behavior synthesizes a minimal `Request`
|
|
289
|
+
* with an `Authorization: Bearer <token>` header and delegates to
|
|
290
|
+
* `verifyRequest()`. Adapters should override this if their token
|
|
291
|
+
* verification logic doesn't depend on request headers/cookies.
|
|
292
|
+
*
|
|
293
|
+
* @param token - The raw bearer token string.
|
|
294
|
+
* @returns The authenticated user, or `null` if the token is invalid.
|
|
295
|
+
*/
|
|
296
|
+
verifyToken?(token: string): Promise<AuthenticatedUser | null>;
|
|
297
|
+
|
|
298
|
+
// ── User & Role Management (for admin panel) ────────────────────────
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* User CRUD for the admin panel's user management UI.
|
|
302
|
+
* Optional — if not provided, user management UI is hidden.
|
|
303
|
+
*/
|
|
304
|
+
userManagement?: UserManagementAdapter;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Role CRUD for the admin panel.
|
|
308
|
+
* Optional — if not provided, role management is disabled.
|
|
309
|
+
*/
|
|
310
|
+
roleManagement?: RoleManagementAdapter;
|
|
311
|
+
|
|
312
|
+
// ── Auth Routes ─────────────────────────────────────────────────────
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Mount adapter-specific auth routes (login, register, refresh, etc.).
|
|
316
|
+
*
|
|
317
|
+
* - Built-in adapter: mounts `/auth/login`, `/auth/register`, etc.
|
|
318
|
+
* - External adapter: typically returns `undefined` (auth is handled externally).
|
|
319
|
+
* - Custom adapter: user mounts their own routes.
|
|
320
|
+
*
|
|
321
|
+
* The return type uses `Hono<any, any, any>` because this sub-app will be
|
|
322
|
+
* mounted into a parent app via `.route()`, which accepts any Hono env type.
|
|
323
|
+
* Adapter implementations are free to use their own env (e.g. `Hono<HonoEnv>`).
|
|
324
|
+
*
|
|
325
|
+
* @returns A Hono sub-app with auth routes, or `undefined` to skip route mounting.
|
|
326
|
+
*/
|
|
327
|
+
createAuthRoutes?(): Hono<any, any, any> | undefined;
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Mount admin routes for user/role management.
|
|
331
|
+
*
|
|
332
|
+
* Same typing rationale as `createAuthRoutes` — the sub-app env is
|
|
333
|
+
* unconstrained to support arbitrary adapter implementations.
|
|
334
|
+
*
|
|
335
|
+
* @returns A Hono sub-app with admin routes, or `undefined` to skip.
|
|
336
|
+
*/
|
|
337
|
+
createAdminRoutes?(): Hono<any, any, any> | undefined;
|
|
338
|
+
|
|
339
|
+
// ── Feature Detection ───────────────────────────────────────────────
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Advertise what this auth adapter supports.
|
|
343
|
+
*
|
|
344
|
+
* The frontend reads this from `GET /api/auth/config` to dynamically
|
|
345
|
+
* show/hide UI elements. This is the bridge between backend capabilities
|
|
346
|
+
* and the frontend's `AuthCapabilities` type.
|
|
347
|
+
*/
|
|
348
|
+
getCapabilities(): AuthAdapterCapabilities | Promise<AuthAdapterCapabilities>;
|
|
349
|
+
|
|
350
|
+
// ── Lifecycle ───────────────────────────────────────────────────────
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Called during backend initialization.
|
|
354
|
+
* Use for running migrations, creating tables, seeding initial data, etc.
|
|
355
|
+
*/
|
|
356
|
+
initialize?(): Promise<void>;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Called during graceful shutdown.
|
|
360
|
+
* Use for closing connections, flushing caches, etc.
|
|
361
|
+
*/
|
|
362
|
+
destroy?(): Promise<void>;
|
|
363
|
+
|
|
364
|
+
// ── Service Key (optional) ──────────────────────────────────────────
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* A static secret key for server-to-server / script authentication.
|
|
368
|
+
*
|
|
369
|
+
* When set, requests with `Authorization: Bearer <serviceKey>` bypass
|
|
370
|
+
* normal token verification and are granted admin-level access.
|
|
371
|
+
*/
|
|
372
|
+
serviceKey?: string;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// ─── Custom Auth Adapter Options ─────────────────────────────────────────────
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Options for creating a minimal custom auth adapter via `createCustomAuthAdapter()`.
|
|
379
|
+
*
|
|
380
|
+
* This is the simplest way to plug an existing auth system into Rebase.
|
|
381
|
+
* Only `verifyRequest` is required — everything else is optional.
|
|
382
|
+
*
|
|
383
|
+
* @group Auth
|
|
384
|
+
*/
|
|
385
|
+
export interface CustomAuthAdapterOptions {
|
|
386
|
+
/**
|
|
387
|
+
* Verify an incoming request and return the authenticated user.
|
|
388
|
+
* This is the only required method.
|
|
389
|
+
*/
|
|
390
|
+
verifyRequest: (request: Request) => Promise<AuthenticatedUser | null>;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Verify a raw bearer token for WebSocket authentication.
|
|
394
|
+
* Optional — if omitted, a synthetic `Request` is constructed and passed
|
|
395
|
+
* to `verifyRequest`.
|
|
396
|
+
*/
|
|
397
|
+
verifyToken?: (token: string) => Promise<AuthenticatedUser | null>;
|
|
398
|
+
|
|
399
|
+
/** Optional user management for the admin panel. */
|
|
400
|
+
userManagement?: UserManagementAdapter;
|
|
401
|
+
|
|
402
|
+
/** Optional role management for the admin panel. */
|
|
403
|
+
roleManagement?: RoleManagementAdapter;
|
|
404
|
+
|
|
405
|
+
/** Static service key for server-to-server auth. */
|
|
406
|
+
serviceKey?: string;
|
|
407
|
+
|
|
408
|
+
/** Override default capabilities. */
|
|
409
|
+
capabilities?: Partial<AuthAdapterCapabilities>;
|
|
410
|
+
}
|