@rebasepro/types 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/controllers/client.d.ts +69 -1
  2. package/dist/controllers/data.d.ts +19 -47
  3. package/dist/controllers/navigation.d.ts +14 -14
  4. package/dist/controllers/registry.d.ts +8 -4
  5. package/dist/index.es.js +164 -10
  6. package/dist/index.es.js.map +1 -1
  7. package/dist/index.umd.js +171 -9
  8. package/dist/index.umd.js.map +1 -1
  9. package/dist/types/api_keys.d.ts +57 -0
  10. package/dist/types/auth_adapter.d.ts +66 -4
  11. package/dist/types/backend.d.ts +5 -0
  12. package/dist/types/collections.d.ts +200 -90
  13. package/dist/types/data_source.d.ts +79 -3
  14. package/dist/types/entity_actions.d.ts +2 -2
  15. package/dist/types/entity_callbacks.d.ts +18 -6
  16. package/dist/types/entity_views.d.ts +1 -1
  17. package/dist/types/filter-operators.d.ts +108 -0
  18. package/dist/types/index.d.ts +4 -2
  19. package/dist/types/plugins.d.ts +1 -1
  20. package/dist/types/policy.d.ts +137 -0
  21. package/dist/types/properties.d.ts +122 -37
  22. package/dist/types/property_config.d.ts +1 -1
  23. package/dist/types/storage_source.d.ts +83 -0
  24. package/dist/types/translations.d.ts +8 -0
  25. package/package.json +1 -1
  26. package/src/controllers/client.ts +69 -1
  27. package/src/controllers/data.ts +20 -59
  28. package/src/controllers/navigation.ts +17 -16
  29. package/src/controllers/registry.ts +10 -4
  30. package/src/types/api_keys.ts +52 -0
  31. package/src/types/auth_adapter.ts +80 -4
  32. package/src/types/backend.ts +6 -1
  33. package/src/types/collections.ts +235 -113
  34. package/src/types/data_source.ts +89 -5
  35. package/src/types/entity_actions.tsx +2 -2
  36. package/src/types/entity_callbacks.ts +18 -7
  37. package/src/types/entity_views.tsx +1 -1
  38. package/src/types/filter-operators.ts +167 -0
  39. package/src/types/index.ts +5 -2
  40. package/src/types/plugins.tsx +1 -1
  41. package/src/types/policy.ts +173 -0
  42. package/src/types/properties.ts +132 -39
  43. package/src/types/property_config.tsx +0 -1
  44. package/src/types/storage_source.ts +90 -0
  45. package/src/types/translations.ts +8 -0
  46. package/dist/types/backend_hooks.d.ts +0 -109
  47. package/dist/types/entity_overrides.d.ts +0 -10
  48. package/src/types/backend_hooks.ts +0 -114
  49. package/src/types/entity_overrides.tsx +0 -11
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import type { EntityReference } from "../types/entities";
3
3
  import type { EntityCollection } from "../types/collections";
4
- import type { RebasePlugin } from "../types/plugins";
4
+
5
5
 
6
6
  /**
7
7
  * Controller that handles URL path building and resolution.
@@ -104,17 +104,12 @@ export type NavigationStateController = {
104
104
  /**
105
105
  * Was there an error while loading the navigation data
106
106
  */
107
- navigationLoadingError?: unknown;
107
+ navigationLoadingError?: Error;
108
108
 
109
109
  /**
110
110
  * Call this method to recalculate the navigation
111
111
  */
112
112
  refreshNavigation: () => void;
113
-
114
- /**
115
- * Plugin system allowing to extend the CMS functionality.
116
- */
117
- plugins?: RebasePlugin[];
118
113
  };
119
114
 
120
115
  export interface NavigateOptions {
@@ -126,13 +121,7 @@ export interface NavigateOptions {
126
121
  viewTransition?: boolean;
127
122
  }
128
123
 
129
- // currently not used, in favor of a single blocker in `RebaseRoute`
130
- export type NavigationBlocker = {
131
- updateBlockListener: (path: string, block: boolean, basePath?: string) => () => void;
132
- isBlocked: (path: string) => boolean;
133
- proceed?: () => void;
134
- reset?: () => void;
135
- };
124
+
136
125
 
137
126
  /**
138
127
  * Custom additional views created by the developer, added to the main
@@ -181,9 +170,13 @@ export interface AppView {
181
170
 
182
171
  /**
183
172
  * Component to be rendered. This can be any React component, and can use
184
- * any of the provided hooks
173
+ * any of the provided hooks.
174
+ *
175
+ * Pass a `ComponentType` to enable lazy rendering — the component will
176
+ * only be instantiated when the route is visited. This is recommended
177
+ * for dynamic views generated from database data.
185
178
  */
186
- view: React.ReactNode;
179
+ view: React.ReactNode | React.ComponentType;
187
180
 
188
181
  /**
189
182
  * If true, a wildcard route (slug/*) is automatically registered
@@ -191,6 +184,14 @@ export interface AppView {
191
184
  */
192
185
  nestedRoutes?: boolean;
193
186
 
187
+ /**
188
+ * Restrict this view to users with at least one of the listed roles.
189
+ * When omitted or empty, the view is visible to all authenticated users.
190
+ * Applied during view resolution — the view is filtered out entirely
191
+ * (not just hidden from nav) if the user lacks a matching role.
192
+ */
193
+ roles?: string[];
194
+
194
195
  }
195
196
 
196
197
  /**
@@ -1,10 +1,9 @@
1
1
  import { ReactNode } from "react";
2
2
  import type { EntityCollection } from "../types/collections";
3
- import type { EntityCollectionsBuilder } from "../types/builders";
3
+ import type { EntityCollectionsBuilder, AppViewsBuilder } from "../types/builders";
4
4
  import type { EntityCustomView } from "../types/entity_views";
5
5
  import type { EntityAction } from "../types/entity_actions";
6
6
  import type { AppView, NavigationGroupMapping } from "./navigation";
7
- import type { RebasePlugin } from "../types/plugins";
8
7
 
9
8
  /**
10
9
  * Options to enable the built-in collection editor.
@@ -24,10 +23,17 @@ export interface CollectionEditorOptions {
24
23
 
25
24
  export interface RebaseCMSConfig<EC extends EntityCollection = EntityCollection> {
26
25
  collections?: EC[] | EntityCollectionsBuilder<EC>;
26
+
27
+ /**
28
+ * Custom top-level views added to the main navigation.
29
+ * Accepts a static array of views or an async builder function
30
+ * that receives the current user/auth context for role-based views.
31
+ */
32
+ views?: AppView[] | AppViewsBuilder;
33
+
27
34
  homePage?: ReactNode;
28
35
  entityViews?: EntityCustomView[];
29
36
  entityActions?: EntityAction[];
30
- plugins?: RebasePlugin[];
31
37
 
32
38
  /**
33
39
  * Centralized configuration for how collections and views are grouped
@@ -48,7 +54,7 @@ export interface RebaseCMSConfig<EC extends EntityCollection = EntityCollection>
48
54
  }
49
55
 
50
56
  export interface RebaseStudioConfig {
51
- tools?: ("sql" | "js" | "rls" | "schema" | "storage" | "cron" | "schema-visualizer" | "branches" | "api" | "logs")[];
57
+ tools?: ("sql" | "js" | "rls" | "schema" | "storage" | "cron" | "schema-visualizer" | "branches" | "api" | "logs" | "api-keys")[];
52
58
  homePage?: ReactNode;
53
59
  devViews?: AppView[];
54
60
  }
@@ -0,0 +1,52 @@
1
+ /** A single permission entry scoping an API key to a collection and its allowed operations. */
2
+ export interface ApiKeyPermission {
3
+ collection: string;
4
+ operations: ("read" | "write" | "delete")[];
5
+ }
6
+
7
+ /** An API key with the secret portion masked (returned by list / get / update). */
8
+ export interface ApiKeyMasked {
9
+ id: string;
10
+ name: string;
11
+ key_prefix: string;
12
+ permissions: ApiKeyPermission[];
13
+ admin: boolean;
14
+ rate_limit: number | null;
15
+ created_by: string;
16
+ created_at: string;
17
+ updated_at: string;
18
+ last_used_at: string | null;
19
+ expires_at: string | null;
20
+ revoked_at: string | null;
21
+ }
22
+
23
+ /** An API key including the full secret (returned only on creation). */
24
+ export interface ApiKeyWithSecret extends ApiKeyMasked {
25
+ key: string;
26
+ }
27
+
28
+ /** Payload for creating a new API key. */
29
+ export interface CreateApiKeyRequest {
30
+ name: string;
31
+ permissions: ApiKeyPermission[];
32
+ admin?: boolean;
33
+ rate_limit?: number | null;
34
+ expires_at?: string | null;
35
+ }
36
+
37
+ /** Payload for updating an existing API key. */
38
+ export interface UpdateApiKeyRequest {
39
+ name?: string;
40
+ permissions?: ApiKeyPermission[];
41
+ admin?: boolean;
42
+ rate_limit?: number | null;
43
+ expires_at?: string | null;
44
+ }
45
+
46
+ export interface ApiKeysAPI {
47
+ listKeys(): Promise<{ keys: ApiKeyMasked[] }>;
48
+ getKey(id: string): Promise<{ key: ApiKeyMasked }>;
49
+ createKey(data: CreateApiKeyRequest): Promise<{ key: ApiKeyWithSecret }>;
50
+ updateKey(id: string, data: UpdateApiKeyRequest): Promise<{ key: ApiKeyMasked }>;
51
+ revokeKey(id: string): Promise<{ success: boolean }>;
52
+ }
@@ -4,8 +4,8 @@
4
4
  * Pluggable authentication abstraction for Rebase.
5
5
  *
6
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.
7
+ * allowing users to bring their own auth system (Clerk, Auth0, or other
8
+ * external providers) while keeping the Rebase admin frontend fully functional.
9
9
  *
10
10
  * @example Built-in auth (default — zero config change)
11
11
  * ```ts
@@ -93,6 +93,8 @@ export interface AuthAdapterCapabilities {
93
93
  profileUpdate: boolean;
94
94
  /** Supports email verification. */
95
95
  emailVerification: boolean;
96
+ /** Supports passwordless magic link login. */
97
+ magicLink: boolean;
96
98
  /** List of enabled OAuth provider IDs (e.g. `["google", "github"]`). */
97
99
  enabledProviders: string[];
98
100
 
@@ -218,6 +220,49 @@ export interface UserCreationFinalizeResult {
218
220
  invitationSent: boolean;
219
221
  }
220
222
 
223
+ // ─── Auth Response Transform ─────────────────────────────────────────────────
224
+
225
+ /**
226
+ * The auth response payload shape that flows through `transformAuthResponse`.
227
+ *
228
+ * For login, register, OAuth, anonymous, and magic-link flows the payload
229
+ * contains both `user` and `tokens`. For refresh and MFA flows the payload
230
+ * contains only `tokens` (no `user`).
231
+ *
232
+ * @group Auth
233
+ */
234
+ export interface AuthResponsePayload {
235
+ user?: {
236
+ uid: string;
237
+ email: string;
238
+ displayName: string | null;
239
+ photoURL: string | null;
240
+ roles: string[];
241
+ metadata: Record<string, unknown>;
242
+ };
243
+ tokens: {
244
+ accessToken: string;
245
+ refreshToken: string;
246
+ accessTokenExpiresAt: number;
247
+ /** Additional tokens injected by `transformAuthResponse`. */
248
+ [key: string]: unknown;
249
+ };
250
+ }
251
+
252
+ /**
253
+ * Context passed to the `transformAuthResponse` hook.
254
+ *
255
+ * @group Auth
256
+ */
257
+ export interface TransformAuthResponseContext {
258
+ /** The authenticated user's ID. */
259
+ userId: string;
260
+ /** The auth method that triggered this response. */
261
+ method: "login" | "register" | "oauth" | "refresh" | "anonymous" | "magic-link" | "mfa";
262
+ /** The raw HTTP request (for reading headers, IP, etc.). */
263
+ request: Request;
264
+ }
265
+
221
266
  // ─── Auth Adapter ────────────────────────────────────────────────────────────
222
267
 
223
268
  /**
@@ -232,7 +277,7 @@ export interface UserCreationFinalizeResult {
232
277
  * 4. Advertise its capabilities so the frontend can adapt
233
278
  *
234
279
  * The built-in Rebase auth implements this interface internally.
235
- * External providers (Clerk, Auth0, Firebase Auth) provide their own adapters.
280
+ * External providers (Clerk, Auth0, or others) provide their own adapters.
236
281
  * Users with custom auth can use `createCustomAuthAdapter()` for a minimal setup.
237
282
  *
238
283
  * @group Auth
@@ -241,7 +286,7 @@ export interface AuthAdapter {
241
286
  /**
242
287
  * Unique identifier for this auth adapter.
243
288
  *
244
- * @example "rebase-builtin", "clerk", "auth0", "firebase", "custom"
289
+ * @example "rebase-builtin", "clerk", "auth0", "external-provider", "custom"
245
290
  */
246
291
  readonly id: string;
247
292
 
@@ -379,6 +424,28 @@ export interface AuthAdapter {
379
424
  * normal token verification and are granted admin-level access.
380
425
  */
381
426
  serviceKey?: string;
427
+
428
+ // ── Response Transform ───────────────────────────────────────────────
429
+
430
+ /**
431
+ * Transform the auth response before sending it to the client.
432
+ *
433
+ * Called after successful login, register, refresh, OAuth, anonymous,
434
+ * magic-link, and MFA flows. The hook receives the fully-formed
435
+ * response and returns a (potentially enriched) response.
436
+ *
437
+ * Use cases:
438
+ * - Inject tokens from external auth systems (custom provider tokens, etc.)
439
+ * - Add project-specific metadata to the response
440
+ * - Enrich the user object with data from external sources
441
+ *
442
+ * The hook runs in the request path — keep it fast.
443
+ * Heavy work should be offloaded to `onAuthenticated` (fire-and-forget).
444
+ */
445
+ transformAuthResponse?(
446
+ response: AuthResponsePayload,
447
+ context: TransformAuthResponseContext
448
+ ): Promise<AuthResponsePayload>;
382
449
  }
383
450
 
384
451
  // ─── Custom Auth Adapter Options ─────────────────────────────────────────────
@@ -413,4 +480,13 @@ export interface CustomAuthAdapterOptions {
413
480
 
414
481
  /** Override default capabilities. */
415
482
  capabilities?: Partial<AuthAdapterCapabilities>;
483
+
484
+ /**
485
+ * Transform the auth response before sending it to the client.
486
+ * Same semantics as `AuthAdapter.transformAuthResponse`.
487
+ */
488
+ transformAuthResponse?: (
489
+ response: AuthResponsePayload,
490
+ context: TransformAuthResponseContext
491
+ ) => Promise<AuthResponsePayload>;
416
492
  }
@@ -325,6 +325,11 @@ export interface CollectionRegistryInterface {
325
325
  * Get all registered collections
326
326
  */
327
327
  getCollections(): EntityCollection[];
328
+
329
+ /**
330
+ * Get the currently registered global callbacks, if any.
331
+ */
332
+ getGlobalCallbacks(): any | undefined;
328
333
  }
329
334
 
330
335
  // =============================================================================
@@ -367,7 +372,7 @@ export interface SQLAdmin {
367
372
  /**
368
373
  * Execute raw SQL against the database.
369
374
  */
370
- executeSql(sql: string, options?: { database?: string; role?: string }): Promise<Record<string, unknown>[]>;
375
+ executeSql(sql: string, options?: { database?: string; role?: string; params?: unknown[] }): Promise<Record<string, unknown>[]>;
371
376
 
372
377
  /**
373
378
  * Fetch the available databases on the server.