@rebasepro/server-postgresql 0.1.2 → 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.
Files changed (68) hide show
  1. package/LICENSE +22 -6
  2. package/dist/common/src/util/entities.d.ts +2 -2
  3. package/dist/common/src/util/relations.d.ts +1 -1
  4. package/dist/index.es.js +1160 -612
  5. package/dist/index.es.js.map +1 -1
  6. package/dist/index.umd.js +1158 -610
  7. package/dist/index.umd.js.map +1 -1
  8. package/dist/server-postgresql/src/PostgresAdapter.d.ts +6 -0
  9. package/dist/server-postgresql/src/PostgresBackendDriver.d.ts +2 -1
  10. package/dist/server-postgresql/src/PostgresBootstrapper.d.ts +0 -5
  11. package/dist/server-postgresql/src/auth/ensure-tables.d.ts +2 -1
  12. package/dist/server-postgresql/src/auth/services.d.ts +37 -15
  13. package/dist/server-postgresql/src/index.d.ts +1 -0
  14. package/dist/server-postgresql/src/schema/auth-schema.d.ts +43 -856
  15. package/dist/server-postgresql/src/schema/default-collections.d.ts +2 -0
  16. package/dist/server-postgresql/src/schema/doctor.d.ts +10 -1
  17. package/dist/server-postgresql/src/schema/introspect-db-logic.d.ts +1 -0
  18. package/dist/server-postgresql/src/services/entity-helpers.d.ts +1 -1
  19. package/dist/server-postgresql/src/services/realtimeService.d.ts +12 -0
  20. package/dist/server-postgresql/src/websocket.d.ts +2 -1
  21. package/dist/types/src/controllers/auth.d.ts +9 -8
  22. package/dist/types/src/controllers/client.d.ts +3 -0
  23. package/dist/types/src/types/auth_adapter.d.ts +356 -0
  24. package/dist/types/src/types/collections.d.ts +67 -2
  25. package/dist/types/src/types/database_adapter.d.ts +94 -0
  26. package/dist/types/src/types/entity_actions.d.ts +7 -1
  27. package/dist/types/src/types/entity_callbacks.d.ts +1 -1
  28. package/dist/types/src/types/entity_views.d.ts +36 -1
  29. package/dist/types/src/types/index.d.ts +2 -0
  30. package/dist/types/src/types/plugins.d.ts +1 -1
  31. package/dist/types/src/types/properties.d.ts +24 -5
  32. package/dist/types/src/types/property_config.d.ts +6 -2
  33. package/dist/types/src/types/relations.d.ts +1 -1
  34. package/dist/types/src/types/translations.d.ts +8 -0
  35. package/dist/types/src/users/user.d.ts +5 -0
  36. package/package.json +21 -15
  37. package/src/PostgresAdapter.ts +59 -0
  38. package/src/PostgresBackendDriver.ts +57 -8
  39. package/src/PostgresBootstrapper.ts +35 -15
  40. package/src/auth/ensure-tables.ts +82 -189
  41. package/src/auth/services.ts +421 -170
  42. package/src/cli.ts +44 -13
  43. package/src/data-transformer.ts +78 -8
  44. package/src/history/HistoryService.ts +25 -2
  45. package/src/index.ts +1 -0
  46. package/src/schema/auth-schema.ts +130 -98
  47. package/src/schema/default-collections.ts +68 -0
  48. package/src/schema/doctor-cli.ts +5 -1
  49. package/src/schema/doctor.ts +85 -8
  50. package/src/schema/generate-drizzle-schema-logic.ts +74 -27
  51. package/src/schema/generate-drizzle-schema.ts +13 -3
  52. package/src/schema/introspect-db-inference.ts +5 -5
  53. package/src/schema/introspect-db-logic.ts +9 -2
  54. package/src/schema/introspect-db.ts +14 -3
  55. package/src/services/EntityFetchService.ts +5 -5
  56. package/src/services/RelationService.ts +2 -2
  57. package/src/services/entity-helpers.ts +1 -1
  58. package/src/services/realtimeService.ts +145 -136
  59. package/src/utils/drizzle-conditions.ts +16 -2
  60. package/src/websocket.ts +113 -37
  61. package/test/auth-services.test.ts +163 -74
  62. package/test/data-transformer-hardening.test.ts +57 -0
  63. package/test/data-transformer.test.ts +43 -0
  64. package/test/generate-drizzle-schema.test.ts +7 -5
  65. package/test/introspect-db-utils.test.ts +4 -1
  66. package/test/postgresDataDriver.test.ts +17 -0
  67. package/test/realtimeService.test.ts +7 -7
  68. package/test/websocket.test.ts +139 -0
@@ -0,0 +1,2 @@
1
+ import { PostgresCollection } from "@rebasepro/types";
2
+ export declare const defaultUsersCollection: PostgresCollection;
@@ -2,7 +2,7 @@ import { EntityCollection, Property } from "@rebasepro/types";
2
2
  export type IssueSeverity = "error" | "warning" | "info";
3
3
  export interface DoctorIssue {
4
4
  severity: IssueSeverity;
5
- category: "missing_table" | "missing_column" | "type_mismatch" | "missing_constraint" | "schema_stale" | "missing_enum" | "enum_value_mismatch" | "missing_foreign_key";
5
+ category: "missing_table" | "missing_column" | "type_mismatch" | "missing_constraint" | "schema_stale" | "missing_enum" | "enum_value_mismatch" | "missing_foreign_key" | "sdk_stale";
6
6
  table?: string;
7
7
  column?: string;
8
8
  expected?: string;
@@ -15,6 +15,10 @@ export interface DoctorReport {
15
15
  passed: boolean;
16
16
  issues: DoctorIssue[];
17
17
  };
18
+ collectionsToSdk: {
19
+ passed: boolean;
20
+ issues: DoctorIssue[];
21
+ };
18
22
  schemaToDatabase: {
19
23
  passed: boolean;
20
24
  issues: DoctorIssue[];
@@ -31,6 +35,10 @@ export declare function checkCollectionsVsSchema(collections: EntityCollection[]
31
35
  passed: boolean;
32
36
  issues: DoctorIssue[];
33
37
  }>;
38
+ export declare function checkCollectionsVsSdk(collections: EntityCollection[], sdkFilePath: string): Promise<{
39
+ passed: boolean;
40
+ issues: DoctorIssue[];
41
+ }>;
34
42
  export declare function checkCollectionsVsDatabase(collections: EntityCollection[], databaseUrl: string): Promise<{
35
43
  passed: boolean;
36
44
  issues: DoctorIssue[];
@@ -39,5 +47,6 @@ export declare function renderReport(report: DoctorReport): void;
39
47
  export declare function runDoctor(options: {
40
48
  collectionsPath: string;
41
49
  schemaPath: string;
50
+ sdkPath: string;
42
51
  databaseUrl?: string;
43
52
  }): Promise<DoctorReport>;
@@ -8,6 +8,7 @@ export interface TableColumn {
8
8
  udt_name: string;
9
9
  is_nullable: string;
10
10
  column_default: string | null;
11
+ atttypmod: number | null;
11
12
  }
12
13
  export interface EnumValue {
13
14
  enum_name: string;
@@ -10,7 +10,7 @@ import { PostgresCollectionRegistry } from "../collections/PostgresCollectionReg
10
10
  */
11
11
  /**
12
12
  * Interface for Drizzle column metadata introspection.
13
- * Replaces unsafe `as unknown as Record<string, unknown>` double-cast chains.
13
+ * Replaces unsafe `as Record<string, unknown>` double-cast chains.
14
14
  */
15
15
  export interface DrizzleColumnMeta {
16
16
  columnType?: string;
@@ -152,6 +152,18 @@ export declare class RealtimeService extends EventEmitter implements RealtimePro
152
152
  * Returns ["posts", "posts/70"] for the example above
153
153
  */
154
154
  private getParentPaths;
155
+ /**
156
+ * Gracefully tear down all realtime resources.
157
+ *
158
+ * This MUST be called during process shutdown, **before** `pool.end()`.
159
+ * It ensures:
160
+ * 1. All debounced refetch timers are cancelled (prevents queries after pool closes).
161
+ * 2. All subscription state and callbacks are cleared.
162
+ * 3. The dedicated LISTEN client (outside the pool) is disconnected.
163
+ * 4. All WebSocket clients are removed (but not forcefully closed — the
164
+ * HTTP server close will handle that).
165
+ */
166
+ destroy(): Promise<void>;
155
167
  /**
156
168
  * Enable cross-instance realtime broadcasting via Postgres LISTEN/NOTIFY.
157
169
  * Creates a dedicated pg.Client (outside the Drizzle pool) that stays
@@ -1,5 +1,6 @@
1
1
  import { RealtimeService } from "./services/realtimeService";
2
2
  import { PostgresBackendDriver } from "./PostgresBackendDriver";
3
+ import { AuthAdapter } from "@rebasepro/types";
3
4
  import { Server } from "http";
4
5
  import { AuthConfig } from "@rebasepro/server-core";
5
- export declare function createPostgresWebSocket(server: Server, realtimeService: RealtimeService, driver: PostgresBackendDriver, authConfig?: AuthConfig): void;
6
+ export declare function createPostgresWebSocket(server: Server, realtimeService: RealtimeService, driver: PostgresBackendDriver, authConfig?: AuthConfig, authAdapter?: AuthAdapter): void;
@@ -80,14 +80,15 @@ export type AuthController<USER extends User = User, ExtraData = unknown> = {
80
80
  export interface AuthControllerExtended<USER extends User = User, ExtraData = unknown> extends AuthController<USER, ExtraData> {
81
81
  /** Login with email and password */
82
82
  emailPasswordLogin?(email: string, password: string): Promise<void>;
83
- /** Login with a Google token or authorization code */
84
- googleLogin?: {
85
- (token: string, tokenType?: "idToken" | "accessToken"): Promise<void>;
86
- (payload: {
87
- code: string;
88
- redirectUri: string;
89
- }): Promise<void>;
90
- };
83
+ /** Login with Google — accepts an ID token, access token, or authorization code payload */
84
+ googleLogin?: (payload: {
85
+ idToken: string;
86
+ } | {
87
+ accessToken: string;
88
+ } | {
89
+ code: string;
90
+ redirectUri: string;
91
+ }) => Promise<void>;
91
92
  /** Register a new user */
92
93
  register?(email: string, password: string, displayName?: string): Promise<void>;
93
94
  /** Skip login (for anonymous access if enabled) */
@@ -52,6 +52,7 @@ export interface AdminUser {
52
52
  photoURL: string | null;
53
53
  provider: string;
54
54
  roles: string[];
55
+ metadata?: Record<string, any>;
55
56
  createdAt: string;
56
57
  updatedAt: string;
57
58
  }
@@ -95,6 +96,7 @@ export interface AdminAPI {
95
96
  displayName?: string;
96
97
  password?: string;
97
98
  roles?: string[];
99
+ metadata?: Record<string, any>;
98
100
  }): Promise<{
99
101
  user: AdminUser;
100
102
  }>;
@@ -103,6 +105,7 @@ export interface AdminAPI {
103
105
  displayName?: string;
104
106
  password?: string;
105
107
  roles?: string[];
108
+ metadata?: Record<string, any>;
106
109
  }): Promise<{
107
110
  user: AdminUser;
108
111
  }>;
@@ -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