@rebasepro/types 0.2.4 → 0.2.5

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.
@@ -1,4 +1,4 @@
1
- import { Role, User } from "../users";
1
+ import type { User } from "../users";
2
2
  /**
3
3
  * Result of creating a new user via admin flow.
4
4
  * Contains the created user plus information about how credentials were delivered.
@@ -15,56 +15,46 @@ export interface UserCreationResult<USER extends User = User> {
15
15
  temporaryPassword?: string;
16
16
  }
17
17
  /**
18
- * Delegate to manage users, roles, and their permissions.
19
- * This interface allows the CMS to be completely agnostic of the underlying
20
- * authentication provider or backend.
18
+ * Delegate to manage auth-specific user operations.
19
+ *
20
+ * This interface allows the CMS to be agnostic of the underlying
21
+ * authentication provider or backend. User/role CRUD is now handled
22
+ * by the collection system; this delegate only exposes auth-specific
23
+ * operations (password hashing, invitations, bootstrap).
21
24
  *
22
25
  * @group Models
23
26
  */
24
27
  export interface UserManagementDelegate<USER extends User = User> {
25
28
  /**
26
- * Are the users and roles currently being fetched?
29
+ * Are auth-related operations currently loading?
27
30
  */
28
31
  loading: boolean;
29
32
  /**
30
- * List of users managed by the CMS.
33
+ * In-memory list of users (used for client-side filtering fallback).
31
34
  */
32
- users: USER[];
35
+ users?: USER[];
33
36
  /**
34
- * Optional error if users failed to load.
37
+ * Error from fetching the users list, if any.
35
38
  */
36
39
  usersError?: Error;
37
40
  /**
38
- * Function to get a user by its uid. This is used to show
39
- * user information when assigning ownership of an entity.
40
- * @param uid
41
+ * Look up a single user by UID from the in-memory cache.
41
42
  */
42
- getUser: (uid: string) => USER | null;
43
+ getUser?: (uid: string) => USER | null;
43
44
  /**
44
- * Search users with server-side pagination.
45
- * When provided, the CMS will use this for the users table
46
- * instead of loading all users into memory.
45
+ * Server-side user search with pagination.
47
46
  */
48
- searchUsers?: (options: {
47
+ searchUsers?: (params: {
49
48
  search?: string;
50
49
  limit?: number;
51
50
  offset?: number;
52
- orderBy?: string;
53
- orderDir?: "asc" | "desc";
54
- roleId?: string;
55
51
  }) => Promise<{
56
52
  users: USER[];
57
53
  total: number;
58
54
  }>;
59
- /**
60
- * Save a user (create or update)
61
- * @param user
62
- */
63
- saveUser?: (user: USER) => Promise<USER>;
64
55
  /**
65
56
  * Create a new user with invitation/password generation support.
66
57
  * Returns additional info about how the credentials were delivered.
67
- * Falls back to saveUser if not provided.
68
58
  */
69
59
  createUser?: (user: USER) => Promise<UserCreationResult<USER>>;
70
60
  /**
@@ -73,42 +63,15 @@ export interface UserManagementDelegate<USER extends User = User> {
73
63
  * or a flag indicating an email invitation was sent.
74
64
  */
75
65
  resetPassword?: (user: USER) => Promise<UserCreationResult<USER>>;
76
- /**
77
- * Delete a user
78
- * @param user
79
- */
80
- deleteUser?: (user: USER) => Promise<void>;
81
- /**
82
- * List of roles defined in the CMS.
83
- */
84
- roles?: Role[];
85
- /**
86
- * Optional error if roles failed to load.
87
- */
88
- rolesError?: Error;
89
- /**
90
- * Save a role (create or update)
91
- * @param role
92
- */
93
- saveRole?: (role: Role) => Promise<void>;
94
- /**
95
- * Delete a role
96
- * @param role
97
- */
98
- deleteRole?: (role: Role) => Promise<void>;
99
66
  /**
100
67
  * Is the currently logged in user an admin?
101
68
  */
102
69
  isAdmin?: boolean;
103
- /**
104
- * If true, the UI will allow the user to create the default roles (admin, editor, viewer).
105
- */
106
- allowDefaultRolesCreation?: boolean;
107
70
  /**
108
71
  * Optionally define roles for a given user. This is useful when the roles
109
72
  * are coming from a separate provider than the one issuing the tokens.
110
73
  */
111
- defineRolesFor?: (user: USER) => Promise<Role[] | undefined> | Role[] | undefined;
74
+ defineRolesFor?: (user: USER) => Promise<string[] | undefined> | string[] | undefined;
112
75
  /**
113
76
  * Whether any admin users exist. Used by the bootstrap banner to decide
114
77
  * whether to prompt. Populated via a lightweight check (e.g. `limit=1`
@@ -1,2 +1 @@
1
1
  export * from "./user";
2
- export * from "./roles";
@@ -35,7 +35,6 @@ export type User = {
35
35
  readonly isAnonymous: boolean;
36
36
  /**
37
37
  * Role IDs assigned to this user (e.g. ["admin", "editor"]).
38
- * These are plain string IDs — use the UserManagementDelegate to look up full Role objects.
39
38
  */
40
39
  roles?: string[];
41
40
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rebasepro/types",
3
3
  "type": "module",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "description": "Rebase type definitions — shared interfaces and controller types",
6
6
  "funding": {
7
7
  "url": "https://github.com/sponsors/rebaseco"
@@ -1,4 +1,4 @@
1
- import { Role, User } from "../users";
1
+ import type { User } from "../users";
2
2
 
3
3
  /**
4
4
  * Capabilities advertised by an auth provider.
@@ -77,7 +77,7 @@ export type AuthController<USER extends User = User, ExtraData = unknown> = {
77
77
 
78
78
  setUser?(user: USER | null): void;
79
79
 
80
- setUserRoles?(roles: Role[]): void;
80
+ setUserRoles?(roles: string[]): void;
81
81
 
82
82
  /**
83
83
  * Capabilities advertised by the auth provider.
@@ -1,6 +1,6 @@
1
- import { User } from "../users";
2
- import { RebaseData } from "./data";
3
- import { EmailService } from "./email";
1
+ import type { User } from "../users";
2
+ import type { RebaseData } from "./data";
3
+ import type { EmailService } from "./email";
4
4
 
5
5
  /**
6
6
  * Event type for authentication state changes
@@ -17,7 +17,7 @@ export interface RebaseSession {
17
17
  user: User;
18
18
  }
19
19
 
20
- import { StorageSource } from "./storage";
20
+ import type { StorageSource } from "./storage";
21
21
 
22
22
  /**
23
23
  * Unified Authentication Client Interface
@@ -66,20 +66,9 @@ export interface AdminUser {
66
66
  updatedAt: string;
67
67
  }
68
68
 
69
- /**
70
- * Role record as returned by the Admin API.
71
- * @group Admin
72
- */
73
- export interface AdminRole {
74
- id: string;
75
- name: string;
76
- isAdmin: boolean;
77
- defaultPermissions: Record<string, unknown> | null;
78
- }
79
-
80
69
  /**
81
70
  * Client-side Admin API interface.
82
- * Provides user and role management operations.
71
+ * Provides user management operations.
83
72
  * @group Admin
84
73
  */
85
74
  export interface AdminAPI {
@@ -95,11 +84,6 @@ export interface AdminAPI {
95
84
  createUser(data: { email: string; displayName?: string; password?: string; roles?: string[]; metadata?: Record<string, any> }): Promise<{ user: AdminUser }>;
96
85
  updateUser(userId: string, data: { email?: string; displayName?: string; password?: string; roles?: string[]; metadata?: Record<string, any> }): Promise<{ user: AdminUser }>;
97
86
  deleteUser(userId: string): Promise<{ success: boolean }>;
98
- listRoles(): Promise<{ roles: AdminRole[] }>;
99
- getRole(roleId: string): Promise<{ role: AdminRole }>;
100
- createRole(data: { id: string; name: string; isAdmin?: boolean; defaultPermissions?: Record<string, unknown> }): Promise<{ role: AdminRole }>;
101
- updateRole(roleId: string, data: { name?: string; isAdmin?: boolean; defaultPermissions?: Record<string, unknown> }): Promise<{ role: AdminRole }>;
102
- deleteRole(roleId: string): Promise<{ success: boolean }>;
103
87
  bootstrap(): Promise<{ success: boolean; message: string; user: { uid: string; roles: string[] } }>;
104
88
  }
105
89
 
@@ -128,7 +112,7 @@ export interface RebaseClient<DB = unknown> {
128
112
  */
129
113
  email?: EmailService;
130
114
 
131
- /** Admin API for user and role management */
115
+ /** Admin API for user management */
132
116
  admin?: AdminAPI;
133
117
 
134
118
  /**
@@ -145,4 +129,21 @@ export interface RebaseClient<DB = unknown> {
145
129
  * detection (e.g. `typeof ws.executeSql === "function"`).
146
130
  */
147
131
  ws?: unknown;
132
+
133
+ /**
134
+ * Execute raw SQL against the database.
135
+ *
136
+ * Only available server-side when the backend uses a SQL database
137
+ * (PostgreSQL, MySQL, etc.). `undefined` for document databases
138
+ * (MongoDB, Firestore) and on the client-side SDK.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * // In a cron job or custom function:
143
+ * if (ctx.client.sql) {
144
+ * const rows = await ctx.client.sql("SELECT count(*) FROM orders");
145
+ * }
146
+ * ```
147
+ */
148
+ sql?(query: string, options?: { database?: string; role?: string }): Promise<Record<string, unknown>[]>;
148
149
  }
@@ -146,6 +146,11 @@ export interface CollectionAccessor<M extends Record<string, unknown> = Record<s
146
146
  */
147
147
  delete(id: string | number): Promise<void>;
148
148
 
149
+ /**
150
+ * Delete all records in this collection.
151
+ */
152
+ deleteAll?(): Promise<void>;
153
+
149
154
  /**
150
155
  * Subscribe to a collection for real-time updates.
151
156
  * Optional method, may not be supported by all implementations (like stateless HTTP clients).
@@ -153,6 +153,12 @@ export interface DataDriver {
153
153
  */
154
154
  deleteEntity<M extends Record<string, unknown> = Record<string, unknown>>(props: DeleteEntityProps<M>): Promise<void>;
155
155
 
156
+ /**
157
+ * Delete all entities from a collection.
158
+ * @param path Collection path
159
+ */
160
+ deleteAll?(path: string): Promise<void>;
161
+
156
162
  /**
157
163
  * Check if the given property is unique in the given collection
158
164
  * @param path Collection path
@@ -113,7 +113,7 @@ export interface AuthAdapterCapabilities {
113
113
  registrationEnabled?: boolean;
114
114
  }
115
115
 
116
- // ─── User & Role Management ─────────────────────────────────────────────────
116
+ // ─── User Management ────────────────────────────────────────────────────────
117
117
 
118
118
  /**
119
119
  * Options for paginated user listing.
@@ -166,40 +166,6 @@ export interface AuthCreateUserData {
166
166
  metadata?: Record<string, unknown>;
167
167
  }
168
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
- }
190
-
191
- /**
192
- * Data for creating a role.
193
- * @group Auth
194
- */
195
- export interface AuthCreateRoleData {
196
- id: string;
197
- name: string;
198
- isAdmin?: boolean;
199
- defaultPermissions?: AuthRoleData["defaultPermissions"];
200
- collectionPermissions?: AuthRoleData["collectionPermissions"];
201
- }
202
-
203
169
  /**
204
170
  * User management operations for the admin panel.
205
171
  *
@@ -213,25 +179,10 @@ export interface UserManagementAdapter {
213
179
  createUser(data: AuthCreateUserData): Promise<AuthUserData>;
214
180
  updateUser(id: string, data: Partial<AuthCreateUserData>): Promise<AuthUserData | null>;
215
181
  deleteUser(id: string): Promise<void>;
216
- getUserRoles(userId: string): Promise<AuthRoleData[]>;
182
+ getUserRoles(userId: string): Promise<string[]>;
217
183
  setUserRoles(userId: string, roleIds: string[]): Promise<void>;
218
184
  }
219
185
 
220
- /**
221
- * Role management operations for the admin panel.
222
- *
223
- * Optional — if not provided by the adapter, role management is disabled.
224
- *
225
- * @group Auth
226
- */
227
- export interface RoleManagementAdapter {
228
- listRoles(): Promise<AuthRoleData[]>;
229
- getRoleById(id: string): Promise<AuthRoleData | null>;
230
- createRole(data: AuthCreateRoleData): Promise<AuthRoleData>;
231
- updateRole(id: string, data: Partial<AuthRoleData>): Promise<AuthRoleData | null>;
232
- deleteRole(id: string): Promise<void>;
233
- }
234
-
235
186
  // ─── Auth Adapter ────────────────────────────────────────────────────────────
236
187
 
237
188
  /**
@@ -241,7 +192,7 @@ export interface RoleManagementAdapter {
241
192
  * database layer. Each auth adapter knows how to:
242
193
  *
243
194
  * 1. Verify incoming HTTP requests (`verifyRequest`)
244
- * 2. Optionally manage users and roles (for the admin panel)
195
+ * 2. Optionally manage users (for the admin panel)
245
196
  * 3. Optionally mount auth-specific routes (login, register, etc.)
246
197
  * 4. Advertise its capabilities so the frontend can adapt
247
198
  *
@@ -293,7 +244,7 @@ export interface AuthAdapter {
293
244
  */
294
245
  verifyToken?(token: string): Promise<AuthenticatedUser | null>;
295
246
 
296
- // ── User & Role Management (for admin panel) ────────────────────────
247
+ // ── User Management (for admin panel) ────────────────────────────
297
248
 
298
249
  /**
299
250
  * User CRUD for the admin panel's user management UI.
@@ -301,12 +252,6 @@ export interface AuthAdapter {
301
252
  */
302
253
  userManagement?: UserManagementAdapter;
303
254
 
304
- /**
305
- * Role CRUD for the admin panel.
306
- * Optional — if not provided, role management is disabled.
307
- */
308
- roleManagement?: RoleManagementAdapter;
309
-
310
255
  // ── Auth Routes ─────────────────────────────────────────────────────
311
256
 
312
257
  /**
@@ -325,7 +270,7 @@ export interface AuthAdapter {
325
270
  createAuthRoutes?(): Hono<any, any, any> | undefined;
326
271
 
327
272
  /**
328
- * Mount admin routes for user/role management.
273
+ * Mount admin routes for user management.
329
274
  *
330
275
  * Same typing rationale as `createAuthRoutes` — the sub-app env is
331
276
  * unconstrained to support arbitrary adapter implementations.
@@ -397,9 +342,6 @@ export interface CustomAuthAdapterOptions {
397
342
  /** Optional user management for the admin panel. */
398
343
  userManagement?: UserManagementAdapter;
399
344
 
400
- /** Optional role management for the admin panel. */
401
- roleManagement?: RoleManagementAdapter;
402
-
403
345
  /** Static service key for server-to-server auth. */
404
346
  serviceKey?: string;
405
347
 
@@ -711,8 +711,8 @@ export interface InitializedDriver {
711
711
  export interface BootstrappedAuth {
712
712
  /** User management service. */
713
713
  userService: unknown;
714
- /** Role management service. */
715
- roleService: unknown;
714
+ /** Role management service (optional, roles are now simple strings). */
715
+ roleService?: unknown;
716
716
  /** Email service (optional). */
717
717
  emailService?: unknown;
718
718
  /** Combined Auth Repository for unified token and user management. */
@@ -1,4 +1,4 @@
1
- import type { AdminUser, AdminRole } from "../controllers/client";
1
+ import type { AdminUser } from "../controllers/client";
2
2
 
3
3
  /**
4
4
  * Context passed to every backend hook.
@@ -56,20 +56,6 @@ export interface UserHooks {
56
56
  afterDelete?(userId: string, context: BackendHookContext): void | Promise<void>;
57
57
  }
58
58
 
59
- /**
60
- * Hooks for intercepting Admin Role data at the API boundary.
61
- * @group Backend Hooks
62
- */
63
- export interface RoleHooks {
64
- /**
65
- * Transform a role record after it's read from the database,
66
- * before it's returned to the client.
67
- *
68
- * Return the modified role, or `null` to filter it out entirely.
69
- */
70
- afterRead?(role: AdminRole, context: BackendHookContext): AdminRole | null | Promise<AdminRole | null>;
71
- }
72
-
73
59
  /**
74
60
  * Hooks for intercepting collection entity data at the REST API boundary.
75
61
  *
@@ -144,7 +130,7 @@ export interface DataHooks {
144
130
  * These hooks run server-side after database operations complete and before
145
131
  * API responses are sent.
146
132
  *
147
- * - `users` / `roles` — intercept admin user and role management endpoints
133
+ * - `users` — intercept admin user management endpoints
148
134
  * - `data` — intercept ALL collection entity data flowing through the REST API
149
135
  *
150
136
  * `data` hooks complement per-collection `EntityCallbacks`. Entity callbacks
@@ -178,8 +164,6 @@ export interface DataHooks {
178
164
  export interface BackendHooks {
179
165
  /** Hooks for intercepting user management data */
180
166
  users?: UserHooks;
181
- /** Hooks for intercepting role management data */
182
- roles?: RoleHooks;
183
167
  /** Hooks for intercepting ALL collection entity data via the REST API */
184
168
  data?: DataHooks;
185
169
  }
@@ -1,15 +1,12 @@
1
- import React from "react";
2
-
3
1
  import type { ComponentRef } from "./component_ref";
4
2
 
5
- import type { EntityReference, EntityRelation, EntityValues, GeoPoint, Entity, Vector } from "./entities";
6
- import type { Relation, JoinStep, OnAction } from "./relations";
3
+ import type { Entity, EntityReference, EntityRelation, EntityValues, GeoPoint, Vector } from "./entities";
4
+ import type { JoinStep, OnAction, Relation } from "./relations";
7
5
  import type { EntityCollection, FilterValues } from "./collections";
8
6
  import type { ColorKey, ColorScheme } from "./chips";
9
7
  import type { AuthController } from "../controllers/auth";
10
8
  import type { EntityAfterReadProps, EntityBeforeSaveProps } from "./entity_callbacks";
11
9
  import type { User } from "../users";
12
- import type { RebaseContext } from "../rebase_context";
13
10
 
14
11
  /**
15
12
  * Callbacks/Hooks for individual property fields
@@ -24,7 +21,6 @@ export type PropertyCallbacks<T = unknown, M extends Record<string, unknown> = R
24
21
  entity: Entity<M> | undefined;
25
22
  }): Promise<T> | T;
26
23
 
27
-
28
24
  /**
29
25
  * Callback used before saving, after validation.
30
26
  * You can modify the value before it's saved.
@@ -85,17 +81,17 @@ export type FirebaseProperties = {
85
81
  */
86
82
  export type InferPropertyType<P extends Property> =
87
83
  P extends StringProperty ? string :
88
- P extends NumberProperty ? number :
89
- P extends BooleanProperty ? boolean :
90
- P extends DateProperty ? Date :
91
- P extends GeopointProperty ? GeoPoint :
92
- P extends ReferenceProperty ? EntityReference :
93
- P extends RelationProperty ? EntityRelation | EntityRelation[] :
94
- P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) :
95
- P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) :
96
- P extends VectorProperty ? Vector :
97
- P extends BinaryProperty ? string :
98
- never;
84
+ P extends NumberProperty ? number :
85
+ P extends BooleanProperty ? boolean :
86
+ P extends DateProperty ? Date :
87
+ P extends GeopointProperty ? GeoPoint :
88
+ P extends ReferenceProperty ? EntityReference :
89
+ P extends RelationProperty ? EntityRelation | EntityRelation[] :
90
+ P extends ArrayProperty ? (P["of"] extends Property ? InferPropertyType<P["of"]>[] : unknown[]) :
91
+ P extends MapProperty ? (P["properties"] extends Properties ? InferEntityType<P["properties"]> : Record<string, unknown>) :
92
+ P extends VectorProperty ? Vector :
93
+ P extends BinaryProperty ? string :
94
+ never;
99
95
 
100
96
  /**
101
97
  * Helper type that determines whether a property is required.
@@ -189,10 +185,6 @@ export interface BaseProperty<CustomProps = unknown> {
189
185
  */
190
186
  columnName?: string;
191
187
 
192
-
193
-
194
-
195
-
196
188
  /**
197
189
  * Rules for validating this property
198
190
  */
@@ -203,9 +195,6 @@ export interface BaseProperty<CustomProps = unknown> {
203
195
  */
204
196
  defaultValue?: unknown;
205
197
 
206
-
207
-
208
-
209
198
  /**
210
199
  * Use this to define dynamic properties that change based on certain conditions
211
200
  * or on the entity's values. For example, you can make a field read-only if
@@ -232,7 +221,6 @@ export interface BaseProperty<CustomProps = unknown> {
232
221
  */
233
222
  callbacks?: PropertyCallbacks;
234
223
 
235
-
236
224
  }
237
225
 
238
226
  /**
@@ -253,7 +241,7 @@ export interface StringProperty extends BaseProperty {
253
241
  * Optional database column type. If not set, it defaults to `varchar` or `uuid` depending on `isId` configuration.
254
242
  * Use `text` for strings with unbound length, `char` for fixed-length strings, or `varchar` for variable-length strings with a limit.
255
243
  */
256
- columnType?: "varchar" | "text" | "char";
244
+ columnType?: "varchar" | "text" | "char" | "uuid";
257
245
  /**
258
246
  * Rules for validating this property
259
247
  */
@@ -325,7 +313,6 @@ export interface StringProperty extends BaseProperty {
325
313
  */
326
314
  previewAsTag?: boolean;
327
315
 
328
-
329
316
  /**
330
317
  * You can use this property (a string) to behave as a reference to another
331
318
  * collection. The stored value is the ID of the entity in the
@@ -655,9 +642,11 @@ export interface ArrayProperty extends BaseProperty {
655
642
  ui?: ArrayUIConfig;
656
643
  type: "array";
657
644
  /**
658
- * Optional database column type. Defaults to `jsonb`.
645
+ * Optional database column type. By default, maps to a native Postgres array
646
+ * (e.g. `text[]`, `integer[]`/`numeric[]`, `boolean[]`) if the element type
647
+ * is a primitive, otherwise defaults to `jsonb`.
659
648
  */
660
- columnType?: "json" | "jsonb";
649
+ columnType?: "json" | "jsonb" | "text[]" | "integer[]" | "boolean[]" | "numeric[]";
661
650
  /**
662
651
  * The property of this array.
663
652
  * You can specify any property (except another Array property)