@rebasepro/plugin-data-enhancement 0.1.0 → 0.2.1
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 +17 -109
- package/README.md +1 -1
- package/dist/common/src/util/entities.d.ts +2 -2
- package/dist/common/src/util/relations.d.ts +1 -1
- package/dist/core/src/components/LoginView/LoginView.d.ts +1 -6
- package/dist/core/src/contexts/SnackbarProvider.d.ts +1 -1
- package/dist/core/src/hooks/data/save.d.ts +2 -2
- package/dist/core/src/hooks/data/useEntityFetch.d.ts +5 -0
- package/dist/core/src/hooks/useResolvedComponent.d.ts +1 -1
- package/dist/index.es.js +1 -2
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +5 -5
- package/dist/index.umd.js.map +1 -1
- package/dist/types/src/controllers/auth.d.ts +9 -8
- package/dist/types/src/controllers/client.d.ts +3 -0
- package/dist/types/src/types/auth_adapter.d.ts +356 -0
- package/dist/types/src/types/collections.d.ts +67 -2
- package/dist/types/src/types/database_adapter.d.ts +94 -0
- package/dist/types/src/types/entity_actions.d.ts +7 -1
- package/dist/types/src/types/entity_callbacks.d.ts +1 -1
- package/dist/types/src/types/entity_views.d.ts +36 -1
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/plugins.d.ts +1 -1
- package/dist/types/src/types/properties.d.ts +24 -5
- package/dist/types/src/types/property_config.d.ts +6 -2
- package/dist/types/src/types/relations.d.ts +1 -1
- package/dist/types/src/types/translations.d.ts +8 -0
- package/dist/types/src/users/user.d.ts +5 -0
- package/dist/ui/src/components/FilterChip.d.ts +42 -0
- package/dist/ui/src/components/index.d.ts +5 -0
- package/dist/ui/src/icons/index.d.ts +2 -0
- package/package.json +15 -16
- package/src/components/FormEnhanceAction.tsx +14 -2
|
@@ -0,0 +1,356 @@
|
|
|
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
|
+
import type { Hono } from "hono";
|
|
33
|
+
/**
|
|
34
|
+
* The normalized user object returned by `AuthAdapter.verifyRequest()`.
|
|
35
|
+
*
|
|
36
|
+
* Regardless of the auth provider, every request is resolved to this shape
|
|
37
|
+
* so that downstream middleware (RLS scoping, route guards) can work uniformly.
|
|
38
|
+
*
|
|
39
|
+
* @group Auth
|
|
40
|
+
*/
|
|
41
|
+
export interface AuthenticatedUser {
|
|
42
|
+
/** Unique user identifier (provider-specific). */
|
|
43
|
+
uid: string;
|
|
44
|
+
/** Primary email address. */
|
|
45
|
+
email: string;
|
|
46
|
+
/** Human-readable display name. */
|
|
47
|
+
displayName?: string | null;
|
|
48
|
+
/** Avatar URL. */
|
|
49
|
+
photoUrl?: string | null;
|
|
50
|
+
/** Role identifiers the user holds. */
|
|
51
|
+
roles: string[];
|
|
52
|
+
/** Whether the user has admin privileges. */
|
|
53
|
+
isAdmin: boolean;
|
|
54
|
+
/** Raw bearer token from the request (for forwarding). */
|
|
55
|
+
rawToken?: string;
|
|
56
|
+
/** Extra claims/metadata from the auth provider. */
|
|
57
|
+
claims?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Feature flags advertised by an auth adapter.
|
|
61
|
+
*
|
|
62
|
+
* The frontend reads these from `GET /api/auth/config` to dynamically
|
|
63
|
+
* show/hide UI elements (login form, registration, password reset, etc.).
|
|
64
|
+
*
|
|
65
|
+
* @group Auth
|
|
66
|
+
*/
|
|
67
|
+
export interface AuthAdapterCapabilities {
|
|
68
|
+
/**
|
|
69
|
+
* Whether this adapter mounts its own `/auth/*` routes.
|
|
70
|
+
*
|
|
71
|
+
* - `true` for the built-in Rebase auth (login, register, refresh, etc.)
|
|
72
|
+
* - `false` for external providers like Clerk or Auth0 that handle
|
|
73
|
+
* auth flows outside of the Rebase backend.
|
|
74
|
+
*/
|
|
75
|
+
hasBuiltInAuthRoutes: boolean;
|
|
76
|
+
/** Supports email/password login. */
|
|
77
|
+
emailPasswordLogin: boolean;
|
|
78
|
+
/** Supports new user registration. */
|
|
79
|
+
registration: boolean;
|
|
80
|
+
/** Supports password reset flow. */
|
|
81
|
+
passwordReset: boolean;
|
|
82
|
+
/** Supports session listing/revocation. */
|
|
83
|
+
sessionManagement: boolean;
|
|
84
|
+
/** Supports profile updates (display name, photo). */
|
|
85
|
+
profileUpdate: boolean;
|
|
86
|
+
/** Supports email verification. */
|
|
87
|
+
emailVerification: boolean;
|
|
88
|
+
/** List of enabled OAuth provider IDs (e.g. `["google", "github"]`). */
|
|
89
|
+
enabledProviders: string[];
|
|
90
|
+
/**
|
|
91
|
+
* For external auth (Clerk, Auth0, etc.): the URL where the user should
|
|
92
|
+
* be redirected for login. The Rebase frontend will navigate here instead
|
|
93
|
+
* of showing its own login form.
|
|
94
|
+
*/
|
|
95
|
+
externalLoginUrl?: string;
|
|
96
|
+
/**
|
|
97
|
+
* True when no users exist yet — first-user bootstrap mode.
|
|
98
|
+
* Only applicable for built-in auth.
|
|
99
|
+
*/
|
|
100
|
+
needsSetup?: boolean;
|
|
101
|
+
/** Whether new user registration is enabled (may differ from `registration` capability at runtime). */
|
|
102
|
+
registrationEnabled?: boolean;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Options for paginated user listing.
|
|
106
|
+
* @group Auth
|
|
107
|
+
*/
|
|
108
|
+
export interface AuthUserListOptions {
|
|
109
|
+
limit?: number;
|
|
110
|
+
offset?: number;
|
|
111
|
+
search?: string;
|
|
112
|
+
orderBy?: string;
|
|
113
|
+
orderDir?: "asc" | "desc";
|
|
114
|
+
roleId?: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Paginated user listing result.
|
|
118
|
+
* @group Auth
|
|
119
|
+
*/
|
|
120
|
+
export interface AuthUserListResult {
|
|
121
|
+
users: AuthUserData[];
|
|
122
|
+
total: number;
|
|
123
|
+
limit: number;
|
|
124
|
+
offset: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* User data exposed by the auth adapter.
|
|
128
|
+
* @group Auth
|
|
129
|
+
*/
|
|
130
|
+
export interface AuthUserData {
|
|
131
|
+
id: string;
|
|
132
|
+
email: string;
|
|
133
|
+
displayName?: string | null;
|
|
134
|
+
photoUrl?: string | null;
|
|
135
|
+
emailVerified?: boolean;
|
|
136
|
+
metadata?: Record<string, any>;
|
|
137
|
+
createdAt?: Date;
|
|
138
|
+
updatedAt?: Date;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Data for creating a user.
|
|
142
|
+
* @group Auth
|
|
143
|
+
*/
|
|
144
|
+
export interface AuthCreateUserData {
|
|
145
|
+
email: string;
|
|
146
|
+
password?: string;
|
|
147
|
+
displayName?: string;
|
|
148
|
+
photoUrl?: string;
|
|
149
|
+
metadata?: Record<string, any>;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Role data exposed by the auth adapter.
|
|
153
|
+
* @group Auth
|
|
154
|
+
*/
|
|
155
|
+
export interface AuthRoleData {
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
isAdmin: boolean;
|
|
159
|
+
defaultPermissions?: {
|
|
160
|
+
read?: boolean;
|
|
161
|
+
create?: boolean;
|
|
162
|
+
edit?: boolean;
|
|
163
|
+
delete?: boolean;
|
|
164
|
+
} | null;
|
|
165
|
+
collectionPermissions?: Record<string, {
|
|
166
|
+
read?: boolean;
|
|
167
|
+
create?: boolean;
|
|
168
|
+
edit?: boolean;
|
|
169
|
+
delete?: boolean;
|
|
170
|
+
}> | null;
|
|
171
|
+
config?: Record<string, unknown> | null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Data for creating a role.
|
|
175
|
+
* @group Auth
|
|
176
|
+
*/
|
|
177
|
+
export interface AuthCreateRoleData {
|
|
178
|
+
id: string;
|
|
179
|
+
name: string;
|
|
180
|
+
isAdmin?: boolean;
|
|
181
|
+
defaultPermissions?: AuthRoleData["defaultPermissions"];
|
|
182
|
+
collectionPermissions?: AuthRoleData["collectionPermissions"];
|
|
183
|
+
config?: AuthRoleData["config"];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* User management operations for the admin panel.
|
|
187
|
+
*
|
|
188
|
+
* Optional — if not provided by the adapter, the user management UI is hidden.
|
|
189
|
+
*
|
|
190
|
+
* @group Auth
|
|
191
|
+
*/
|
|
192
|
+
export interface UserManagementAdapter {
|
|
193
|
+
listUsers(options?: AuthUserListOptions): Promise<AuthUserListResult>;
|
|
194
|
+
getUserById(id: string): Promise<AuthUserData | null>;
|
|
195
|
+
createUser(data: AuthCreateUserData): Promise<AuthUserData>;
|
|
196
|
+
updateUser(id: string, data: Partial<AuthCreateUserData>): Promise<AuthUserData | null>;
|
|
197
|
+
deleteUser(id: string): Promise<void>;
|
|
198
|
+
getUserRoles(userId: string): Promise<AuthRoleData[]>;
|
|
199
|
+
setUserRoles(userId: string, roleIds: string[]): Promise<void>;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Role management operations for the admin panel.
|
|
203
|
+
*
|
|
204
|
+
* Optional — if not provided by the adapter, role management is disabled.
|
|
205
|
+
*
|
|
206
|
+
* @group Auth
|
|
207
|
+
*/
|
|
208
|
+
export interface RoleManagementAdapter {
|
|
209
|
+
listRoles(): Promise<AuthRoleData[]>;
|
|
210
|
+
getRoleById(id: string): Promise<AuthRoleData | null>;
|
|
211
|
+
createRole(data: AuthCreateRoleData): Promise<AuthRoleData>;
|
|
212
|
+
updateRole(id: string, data: Partial<AuthRoleData>): Promise<AuthRoleData | null>;
|
|
213
|
+
deleteRole(id: string): Promise<void>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Pluggable authentication adapter for Rebase.
|
|
217
|
+
*
|
|
218
|
+
* This is the **key interface** that decouples authentication from the
|
|
219
|
+
* database layer. Each auth adapter knows how to:
|
|
220
|
+
*
|
|
221
|
+
* 1. Verify incoming HTTP requests (`verifyRequest`)
|
|
222
|
+
* 2. Optionally manage users and roles (for the admin panel)
|
|
223
|
+
* 3. Optionally mount auth-specific routes (login, register, etc.)
|
|
224
|
+
* 4. Advertise its capabilities so the frontend can adapt
|
|
225
|
+
*
|
|
226
|
+
* The built-in Rebase auth implements this interface internally.
|
|
227
|
+
* External providers (Clerk, Auth0, Firebase Auth) provide their own adapters.
|
|
228
|
+
* Users with custom auth can use `createCustomAuthAdapter()` for a minimal setup.
|
|
229
|
+
*
|
|
230
|
+
* @group Auth
|
|
231
|
+
*/
|
|
232
|
+
export interface AuthAdapter {
|
|
233
|
+
/**
|
|
234
|
+
* Unique identifier for this auth adapter.
|
|
235
|
+
*
|
|
236
|
+
* @example "rebase-builtin", "clerk", "auth0", "firebase", "custom"
|
|
237
|
+
*/
|
|
238
|
+
readonly id: string;
|
|
239
|
+
/**
|
|
240
|
+
* Verify an incoming request and extract the authenticated user.
|
|
241
|
+
*
|
|
242
|
+
* This replaces the hardcoded JWT verification in server-core's middleware.
|
|
243
|
+
* Each adapter implements its own token verification strategy:
|
|
244
|
+
* - Built-in: verify Rebase JWT
|
|
245
|
+
* - Clerk: call Clerk's `verifyToken()`
|
|
246
|
+
* - Auth0: validate Auth0 JWT with JWKS
|
|
247
|
+
* - Custom: whatever logic the user provides
|
|
248
|
+
*
|
|
249
|
+
* @param request - The raw `Request` object (portable across Hono, Express, Fastify)
|
|
250
|
+
* @returns The authenticated user, or `null` for unauthenticated requests.
|
|
251
|
+
* Throw an error to reject the request with 401.
|
|
252
|
+
*/
|
|
253
|
+
verifyRequest(request: Request): Promise<AuthenticatedUser | null>;
|
|
254
|
+
/**
|
|
255
|
+
* Verify a raw bearer token and extract the authenticated user.
|
|
256
|
+
*
|
|
257
|
+
* Used for **WebSocket authentication**, where there is no HTTP `Request`
|
|
258
|
+
* object — only a token string sent over the socket.
|
|
259
|
+
*
|
|
260
|
+
* If not implemented, the default behavior synthesizes a minimal `Request`
|
|
261
|
+
* with an `Authorization: Bearer <token>` header and delegates to
|
|
262
|
+
* `verifyRequest()`. Adapters should override this if their token
|
|
263
|
+
* verification logic doesn't depend on request headers/cookies.
|
|
264
|
+
*
|
|
265
|
+
* @param token - The raw bearer token string.
|
|
266
|
+
* @returns The authenticated user, or `null` if the token is invalid.
|
|
267
|
+
*/
|
|
268
|
+
verifyToken?(token: string): Promise<AuthenticatedUser | null>;
|
|
269
|
+
/**
|
|
270
|
+
* User CRUD for the admin panel's user management UI.
|
|
271
|
+
* Optional — if not provided, user management UI is hidden.
|
|
272
|
+
*/
|
|
273
|
+
userManagement?: UserManagementAdapter;
|
|
274
|
+
/**
|
|
275
|
+
* Role CRUD for the admin panel.
|
|
276
|
+
* Optional — if not provided, role management is disabled.
|
|
277
|
+
*/
|
|
278
|
+
roleManagement?: RoleManagementAdapter;
|
|
279
|
+
/**
|
|
280
|
+
* Mount adapter-specific auth routes (login, register, refresh, etc.).
|
|
281
|
+
*
|
|
282
|
+
* - Built-in adapter: mounts `/auth/login`, `/auth/register`, etc.
|
|
283
|
+
* - External adapter: typically returns `undefined` (auth is handled externally).
|
|
284
|
+
* - Custom adapter: user mounts their own routes.
|
|
285
|
+
*
|
|
286
|
+
* The return type uses `Hono<any, any, any>` because this sub-app will be
|
|
287
|
+
* mounted into a parent app via `.route()`, which accepts any Hono env type.
|
|
288
|
+
* Adapter implementations are free to use their own env (e.g. `Hono<HonoEnv>`).
|
|
289
|
+
*
|
|
290
|
+
* @returns A Hono sub-app with auth routes, or `undefined` to skip route mounting.
|
|
291
|
+
*/
|
|
292
|
+
createAuthRoutes?(): Hono<any, any, any> | undefined;
|
|
293
|
+
/**
|
|
294
|
+
* Mount admin routes for user/role management.
|
|
295
|
+
*
|
|
296
|
+
* Same typing rationale as `createAuthRoutes` — the sub-app env is
|
|
297
|
+
* unconstrained to support arbitrary adapter implementations.
|
|
298
|
+
*
|
|
299
|
+
* @returns A Hono sub-app with admin routes, or `undefined` to skip.
|
|
300
|
+
*/
|
|
301
|
+
createAdminRoutes?(): Hono<any, any, any> | undefined;
|
|
302
|
+
/**
|
|
303
|
+
* Advertise what this auth adapter supports.
|
|
304
|
+
*
|
|
305
|
+
* The frontend reads this from `GET /api/auth/config` to dynamically
|
|
306
|
+
* show/hide UI elements. This is the bridge between backend capabilities
|
|
307
|
+
* and the frontend's `AuthCapabilities` type.
|
|
308
|
+
*/
|
|
309
|
+
getCapabilities(): AuthAdapterCapabilities | Promise<AuthAdapterCapabilities>;
|
|
310
|
+
/**
|
|
311
|
+
* Called during backend initialization.
|
|
312
|
+
* Use for running migrations, creating tables, seeding initial data, etc.
|
|
313
|
+
*/
|
|
314
|
+
initialize?(): Promise<void>;
|
|
315
|
+
/**
|
|
316
|
+
* Called during graceful shutdown.
|
|
317
|
+
* Use for closing connections, flushing caches, etc.
|
|
318
|
+
*/
|
|
319
|
+
destroy?(): Promise<void>;
|
|
320
|
+
/**
|
|
321
|
+
* A static secret key for server-to-server / script authentication.
|
|
322
|
+
*
|
|
323
|
+
* When set, requests with `Authorization: Bearer <serviceKey>` bypass
|
|
324
|
+
* normal token verification and are granted admin-level access.
|
|
325
|
+
*/
|
|
326
|
+
serviceKey?: string;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Options for creating a minimal custom auth adapter via `createCustomAuthAdapter()`.
|
|
330
|
+
*
|
|
331
|
+
* This is the simplest way to plug an existing auth system into Rebase.
|
|
332
|
+
* Only `verifyRequest` is required — everything else is optional.
|
|
333
|
+
*
|
|
334
|
+
* @group Auth
|
|
335
|
+
*/
|
|
336
|
+
export interface CustomAuthAdapterOptions {
|
|
337
|
+
/**
|
|
338
|
+
* Verify an incoming request and return the authenticated user.
|
|
339
|
+
* This is the only required method.
|
|
340
|
+
*/
|
|
341
|
+
verifyRequest: (request: Request) => Promise<AuthenticatedUser | null>;
|
|
342
|
+
/**
|
|
343
|
+
* Verify a raw bearer token for WebSocket authentication.
|
|
344
|
+
* Optional — if omitted, a synthetic `Request` is constructed and passed
|
|
345
|
+
* to `verifyRequest`.
|
|
346
|
+
*/
|
|
347
|
+
verifyToken?: (token: string) => Promise<AuthenticatedUser | null>;
|
|
348
|
+
/** Optional user management for the admin panel. */
|
|
349
|
+
userManagement?: UserManagementAdapter;
|
|
350
|
+
/** Optional role management for the admin panel. */
|
|
351
|
+
roleManagement?: RoleManagementAdapter;
|
|
352
|
+
/** Static service key for server-to-server auth. */
|
|
353
|
+
serviceKey?: string;
|
|
354
|
+
/** Override default capabilities. */
|
|
355
|
+
capabilities?: Partial<AuthAdapterCapabilities>;
|
|
356
|
+
}
|
|
@@ -7,7 +7,7 @@ import type { EntityOverrides } from "./entity_overrides";
|
|
|
7
7
|
import type { User } from "../users";
|
|
8
8
|
import type { RebaseContext } from "../rebase_context";
|
|
9
9
|
import type { Relation } from "./relations";
|
|
10
|
-
import type { EntityCustomView } from "./entity_views";
|
|
10
|
+
import type { EntityCustomView, EntityDetailViewConfig } from "./entity_views";
|
|
11
11
|
import type { EntityAction } from "./entity_actions";
|
|
12
12
|
import type { ComponentRef } from "./component_ref";
|
|
13
13
|
/**
|
|
@@ -116,7 +116,22 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
|
|
|
116
116
|
* When editing an entity, you can choose to open the entity in a side dialog
|
|
117
117
|
* or in a full screen dialog. Defaults to `full_screen`.
|
|
118
118
|
*/
|
|
119
|
-
openEntityMode?: "side_panel" | "full_screen" | "split";
|
|
119
|
+
openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
|
|
120
|
+
/**
|
|
121
|
+
* Controls what happens when a user clicks on an entity in the collection view.
|
|
122
|
+
* - `"edit"` (default): Opens the entity in the edit form.
|
|
123
|
+
* - `"view"`: Opens a read-only detail view with an "Edit" button.
|
|
124
|
+
*/
|
|
125
|
+
defaultEntityAction?: "view" | "edit";
|
|
126
|
+
/**
|
|
127
|
+
* Customization options for the read-only detail view.
|
|
128
|
+
* Only used when `defaultEntityAction` is `"view"`.
|
|
129
|
+
*/
|
|
130
|
+
detailView?: EntityDetailViewConfig;
|
|
131
|
+
/**
|
|
132
|
+
* Prevent default actions from being displayed or executed on this collection.
|
|
133
|
+
*/
|
|
134
|
+
disableDefaultActions?: ("edit" | "copy" | "delete")[];
|
|
120
135
|
/**
|
|
121
136
|
* Order in which the properties are displayed.
|
|
122
137
|
* If you are specifying your collection as code, the order is the same as the
|
|
@@ -172,6 +187,24 @@ export interface BaseEntityCollection<M extends Record<string, unknown> = Record
|
|
|
172
187
|
* e.g. `defaultFilter: { related_user: ["==", new EntityReference("sdc43dsw2", "users")] }`
|
|
173
188
|
*/
|
|
174
189
|
readonly defaultFilter?: FilterValues<Extract<keyof M, string> | (string & {})>;
|
|
190
|
+
/**
|
|
191
|
+
* Pre-defined filter presets that appear as quick-access options in the
|
|
192
|
+
* collection toolbar. Each preset applies a set of filters (and
|
|
193
|
+
* optionally a sort order) with a single click.
|
|
194
|
+
*
|
|
195
|
+
* ```ts
|
|
196
|
+
* filterPresets: [
|
|
197
|
+
* {
|
|
198
|
+
* label: "Shipped this month",
|
|
199
|
+
* filterValues: {
|
|
200
|
+
* status: ["==", "shipped"],
|
|
201
|
+
* order_date: [">=", new Date(Date.now() - 30 * 86400000)]
|
|
202
|
+
* }
|
|
203
|
+
* }
|
|
204
|
+
* ]
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
readonly filterPresets?: FilterPreset<Extract<keyof M, string> | (string & {})>[];
|
|
175
208
|
/**
|
|
176
209
|
* Default sort applied to this collection.
|
|
177
210
|
* When setting this prop, entities will have a default order
|
|
@@ -327,6 +360,12 @@ export interface PostgresCollection<M extends Record<string, unknown> = Record<s
|
|
|
327
360
|
* The PostgreSQL table name for this collection.
|
|
328
361
|
*/
|
|
329
362
|
table: string;
|
|
363
|
+
/**
|
|
364
|
+
* The PostgreSQL schema name for this table.
|
|
365
|
+
* E.g. "public", "rebase", "auth".
|
|
366
|
+
* If not specified, "public" is used (or the default search path).
|
|
367
|
+
*/
|
|
368
|
+
schema?: string;
|
|
330
369
|
/**
|
|
331
370
|
* For SQL databases, you can define the relations between collections here.
|
|
332
371
|
* Relations describe JOINs, foreign keys, and junction tables.
|
|
@@ -528,6 +567,32 @@ export type WhereFilterOp = "<" | "<=" | "==" | "!=" | ">=" | ">" | "array-conta
|
|
|
528
567
|
* @group Models
|
|
529
568
|
*/
|
|
530
569
|
export type FilterValues<Key extends string> = Partial<Record<Key, [WhereFilterOp, unknown]>>;
|
|
570
|
+
/**
|
|
571
|
+
* A pre-defined filter preset for quick access in the collection toolbar.
|
|
572
|
+
* Users can select a preset to instantly apply a set of filters and
|
|
573
|
+
* optionally a sort order.
|
|
574
|
+
*
|
|
575
|
+
* @group Models
|
|
576
|
+
*/
|
|
577
|
+
export interface FilterPreset<Key extends string = string> {
|
|
578
|
+
/**
|
|
579
|
+
* Display label shown in the preset menu.
|
|
580
|
+
* If omitted, a summary is auto-generated from the filter keys.
|
|
581
|
+
*/
|
|
582
|
+
label?: string;
|
|
583
|
+
/**
|
|
584
|
+
* The filter values to apply when this preset is selected.
|
|
585
|
+
*/
|
|
586
|
+
filterValues: FilterValues<Key>;
|
|
587
|
+
/**
|
|
588
|
+
* Optional sort override to apply alongside the filter values.
|
|
589
|
+
*/
|
|
590
|
+
sort?: [Key, "asc" | "desc"];
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* @deprecated Use {@link FilterPreset} instead.
|
|
594
|
+
*/
|
|
595
|
+
export type QuickFilter<Key extends string = string> = FilterPreset<Key>;
|
|
531
596
|
/**
|
|
532
597
|
* Used to indicate valid filter combinations (e.g. created in Firestore)
|
|
533
598
|
* If the user selects a specific filter/sort combination, the CMS checks if it's
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module DatabaseAdapter
|
|
3
|
+
*
|
|
4
|
+
* Pluggable database abstraction for Rebase.
|
|
5
|
+
*
|
|
6
|
+
*
|
|
7
|
+
* A `DatabaseAdapter` focuses purely on data persistence and related concerns (realtime, history).
|
|
8
|
+
* It does NOT handle authentication — auth is managed separately by an `AuthAdapter`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { createPostgresAdapter } from "@rebasepro/server-postgresql";
|
|
13
|
+
*
|
|
14
|
+
* initializeRebaseBackend({
|
|
15
|
+
* database: createPostgresAdapter({ connection: db, schema }),
|
|
16
|
+
* auth: { jwtSecret: "..." },
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @group Backend
|
|
21
|
+
*/
|
|
22
|
+
import type { DataDriver } from "../controllers/data_driver";
|
|
23
|
+
import type { EntityCollection } from "./collections";
|
|
24
|
+
import type { CollectionRegistryInterface, DatabaseAdmin, InitializedDriver, RealtimeProvider, BootstrappedAuth } from "./backend";
|
|
25
|
+
/**
|
|
26
|
+
* A `DatabaseAdapter` provides data persistence for Rebase.
|
|
27
|
+
*
|
|
28
|
+
* @group Backend
|
|
29
|
+
*/
|
|
30
|
+
export interface DatabaseAdapter {
|
|
31
|
+
/**
|
|
32
|
+
* Which database engine this adapter handles.
|
|
33
|
+
*
|
|
34
|
+
* @example "postgres", "mysql", "mongodb", "sqlite"
|
|
35
|
+
*/
|
|
36
|
+
readonly type: string;
|
|
37
|
+
/**
|
|
38
|
+
* Create the DataDriver for CRUD operations.
|
|
39
|
+
*
|
|
40
|
+
* This is the only **required** method.
|
|
41
|
+
*
|
|
42
|
+
* @param config - Coordinator-provided config containing registered
|
|
43
|
+
* collections and the collection registry.
|
|
44
|
+
*/
|
|
45
|
+
initializeDriver(config: DatabaseAdapterInitConfig): Promise<InitializedDriver>;
|
|
46
|
+
/**
|
|
47
|
+
* Create a realtime provider for this database.
|
|
48
|
+
*
|
|
49
|
+
* Return `undefined` if the database does not support realtime
|
|
50
|
+
* change notifications.
|
|
51
|
+
*/
|
|
52
|
+
initializeRealtime?(driverResult: InitializedDriver): Promise<RealtimeProvider | undefined>;
|
|
53
|
+
/**
|
|
54
|
+
* Initialize auth tables / services if this driver supports them.
|
|
55
|
+
*/
|
|
56
|
+
initializeAuth?(config: unknown, driverResult: InitializedDriver): Promise<BootstrappedAuth | undefined>;
|
|
57
|
+
/**
|
|
58
|
+
* Initialize entity history tracking.
|
|
59
|
+
*
|
|
60
|
+
* Return `undefined` if the database does not support history.
|
|
61
|
+
*/
|
|
62
|
+
initializeHistory?(config: unknown, driverResult: InitializedDriver): Promise<{
|
|
63
|
+
historyService: unknown;
|
|
64
|
+
} | undefined>;
|
|
65
|
+
/**
|
|
66
|
+
* Initialize WebSocket server for realtime operations.
|
|
67
|
+
*/
|
|
68
|
+
initializeWebsockets?(server: unknown, realtimeService: RealtimeProvider, driver: DataDriver, config?: unknown): Promise<void> | void;
|
|
69
|
+
/**
|
|
70
|
+
* Return admin capabilities for this database (SQL editor, schema browser, branching).
|
|
71
|
+
*/
|
|
72
|
+
getAdmin?(driverResult: InitializedDriver): DatabaseAdmin | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Mount any database-specific HTTP routes (e.g., custom admin endpoints).
|
|
75
|
+
*
|
|
76
|
+
* Called after all adapters are initialized.
|
|
77
|
+
*/
|
|
78
|
+
mountRoutes?(app: unknown, basePath: string, driverResult: InitializedDriver): void;
|
|
79
|
+
/**
|
|
80
|
+
* Graceful shutdown: close connections, release resources.
|
|
81
|
+
*/
|
|
82
|
+
destroy?(): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Configuration passed by the coordinator to `DatabaseAdapter.initializeDriver()`.
|
|
86
|
+
*
|
|
87
|
+
* @group Backend
|
|
88
|
+
*/
|
|
89
|
+
export interface DatabaseAdapterInitConfig {
|
|
90
|
+
/** Registered collection definitions. */
|
|
91
|
+
collections: EntityCollection[];
|
|
92
|
+
/** The shared collection registry to register into. */
|
|
93
|
+
collectionRegistry: CollectionRegistryInterface;
|
|
94
|
+
}
|
|
@@ -40,6 +40,12 @@ export interface EntityAction<M extends Record<string, unknown> = Record<string,
|
|
|
40
40
|
* @param props
|
|
41
41
|
*/
|
|
42
42
|
isEnabled?(props: EntityActionClickProps<M, USER>): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* When true, this action is rendered inline on each row in the list view.
|
|
45
|
+
* By default, entity actions only appear in the table view and entity form.
|
|
46
|
+
* Use this for actions that should be easily accessible regardless of view mode.
|
|
47
|
+
*/
|
|
48
|
+
showActionsInListView?: boolean;
|
|
43
49
|
/**
|
|
44
50
|
* Show this action collapsed in the menu of the collection view.
|
|
45
51
|
* Defaults to true
|
|
@@ -72,7 +78,7 @@ export type EntityActionClickProps<M extends Record<string, unknown>, USER exten
|
|
|
72
78
|
/**
|
|
73
79
|
* If the action is rendered in the form, is it open in a side panel or full screen?
|
|
74
80
|
*/
|
|
75
|
-
openEntityMode: "side_panel" | "full_screen" | "split";
|
|
81
|
+
openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
|
|
76
82
|
/**
|
|
77
83
|
* Optional selection controller, present if the action is being called from a collection view
|
|
78
84
|
*/
|
|
@@ -39,7 +39,7 @@ export type EntityCallbacks<M extends Record<string, unknown> = Record<string, u
|
|
|
39
39
|
*
|
|
40
40
|
* @param props
|
|
41
41
|
*/
|
|
42
|
-
beforeDelete?(props: EntityBeforeDeleteProps<M, USER>): void;
|
|
42
|
+
beforeDelete?(props: EntityBeforeDeleteProps<M, USER>): Promise<boolean | void> | boolean | void;
|
|
43
43
|
/**
|
|
44
44
|
* Callback used after the entity is deleted.
|
|
45
45
|
*
|
|
@@ -35,12 +35,17 @@ export interface FormContext<M extends Record<string, unknown> = Record<string,
|
|
|
35
35
|
status: "new" | "existing" | "copy";
|
|
36
36
|
entity?: Entity<M>;
|
|
37
37
|
savingError?: Error;
|
|
38
|
-
openEntityMode: "side_panel" | "full_screen" | "split";
|
|
38
|
+
openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
|
|
39
39
|
/**
|
|
40
40
|
* The underlying formex controller that powers the form.
|
|
41
41
|
*/
|
|
42
42
|
formex: FormexController<M>;
|
|
43
43
|
disabled: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Whether the form context is in read-only detail view mode.
|
|
46
|
+
* Custom entity views can use this to adjust their rendering.
|
|
47
|
+
*/
|
|
48
|
+
readOnly?: boolean;
|
|
44
49
|
}
|
|
45
50
|
export type EntityCustomView<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
46
51
|
key: string;
|
|
@@ -58,3 +63,33 @@ export interface EntityCustomViewParams<M extends Record<string, unknown> = Reco
|
|
|
58
63
|
parentCollectionSlugs?: string[];
|
|
59
64
|
parentEntityIds?: string[];
|
|
60
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Configuration for customizing the read-only detail view of an entity.
|
|
68
|
+
* Only used when `defaultEntityAction` is set to `"view"` on the collection.
|
|
69
|
+
* @group Models
|
|
70
|
+
*/
|
|
71
|
+
export type EntityDetailViewConfig<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
72
|
+
/**
|
|
73
|
+
* Custom component rendered above the property display in the detail view.
|
|
74
|
+
*/
|
|
75
|
+
Header?: ComponentRef<EntityDetailViewParams<M>>;
|
|
76
|
+
/**
|
|
77
|
+
* Custom component rendered below the property display in the detail view.
|
|
78
|
+
*/
|
|
79
|
+
Footer?: ComponentRef<EntityDetailViewParams<M>>;
|
|
80
|
+
/**
|
|
81
|
+
* Completely replace the default detail view with a custom component.
|
|
82
|
+
* When set, Header and Footer are ignored.
|
|
83
|
+
*/
|
|
84
|
+
Builder?: ComponentRef<EntityDetailViewParams<M>>;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Props passed to detail view customization components (Header, Footer, Builder).
|
|
88
|
+
* @group Models
|
|
89
|
+
*/
|
|
90
|
+
export interface EntityDetailViewParams<M extends Record<string, unknown> = Record<string, unknown>> {
|
|
91
|
+
collection: EntityCollection<M>;
|
|
92
|
+
entity: Entity<M>;
|
|
93
|
+
path: string;
|
|
94
|
+
onEditClick: () => void;
|
|
95
|
+
}
|
|
@@ -250,7 +250,7 @@ export interface PluginFormActionProps<USER extends User = User, EC extends Enti
|
|
|
250
250
|
disabled: boolean;
|
|
251
251
|
formContext?: FormContext;
|
|
252
252
|
context: RebaseContext<USER>;
|
|
253
|
-
openEntityMode: "side_panel" | "full_screen" | "split";
|
|
253
|
+
openEntityMode: "side_panel" | "full_screen" | "split" | "dialog";
|
|
254
254
|
}
|
|
255
255
|
/**
|
|
256
256
|
* Parameters passed to the field builder wrap function.
|