@rebasepro/server-core 0.0.1-canary.eae7889 → 0.1.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 (132) hide show
  1. package/app/frontend/node_modules/esbuild/LICENSE.md +21 -0
  2. package/app/frontend/node_modules/esbuild/README.md +3 -0
  3. package/app/frontend/node_modules/esbuild/bin/esbuild +220 -0
  4. package/app/frontend/node_modules/esbuild/install.js +285 -0
  5. package/app/frontend/node_modules/esbuild/lib/main.d.ts +705 -0
  6. package/app/frontend/node_modules/esbuild/lib/main.js +2239 -0
  7. package/app/frontend/node_modules/esbuild/package.json +46 -0
  8. package/dist/index.es.js +1186 -1673
  9. package/dist/index.es.js.map +1 -1
  10. package/dist/index.umd.js +1185 -1672
  11. package/dist/index.umd.js.map +1 -1
  12. package/dist/server-core/src/api/rest/api-generator.d.ts +15 -3
  13. package/dist/server-core/src/auth/admin-routes.d.ts +5 -0
  14. package/dist/server-core/src/auth/google-oauth.d.ts +36 -3
  15. package/dist/server-core/src/auth/index.d.ts +1 -0
  16. package/dist/server-core/src/cron/cron-scheduler.d.ts +45 -0
  17. package/dist/server-core/src/cron/index.d.ts +1 -1
  18. package/dist/server-core/src/init.d.ts +11 -1
  19. package/dist/types/src/controllers/auth.d.ts +8 -2
  20. package/dist/types/src/controllers/client.d.ts +13 -0
  21. package/dist/types/src/controllers/collection_registry.d.ts +2 -1
  22. package/dist/types/src/controllers/data_driver.d.ts +36 -1
  23. package/dist/types/src/controllers/navigation.d.ts +18 -6
  24. package/dist/types/src/controllers/registry.d.ts +9 -1
  25. package/dist/types/src/controllers/side_entity_controller.d.ts +7 -0
  26. package/dist/types/src/rebase_context.d.ts +17 -0
  27. package/dist/types/src/types/backend_hooks.d.ts +187 -0
  28. package/dist/types/src/types/collections.d.ts +31 -11
  29. package/dist/types/src/types/component_ref.d.ts +47 -0
  30. package/dist/types/src/types/cron.d.ts +1 -1
  31. package/dist/types/src/types/entity_views.d.ts +6 -7
  32. package/dist/types/src/types/formex.d.ts +40 -0
  33. package/dist/types/src/types/index.d.ts +3 -0
  34. package/dist/types/src/types/plugins.d.ts +6 -3
  35. package/dist/types/src/types/properties.d.ts +72 -88
  36. package/dist/types/src/types/slots.d.ts +20 -10
  37. package/dist/types/src/types/translations.d.ts +6 -0
  38. package/examples/firebase/node_modules/esbuild/LICENSE.md +21 -0
  39. package/examples/firebase/node_modules/esbuild/README.md +3 -0
  40. package/examples/firebase/node_modules/esbuild/bin/esbuild +220 -0
  41. package/examples/firebase/node_modules/esbuild/install.js +285 -0
  42. package/examples/firebase/node_modules/esbuild/lib/main.d.ts +705 -0
  43. package/examples/firebase/node_modules/esbuild/lib/main.js +2239 -0
  44. package/examples/firebase/node_modules/esbuild/package.json +46 -0
  45. package/examples/medmot-staging/frontend/node_modules/esbuild/LICENSE.md +21 -0
  46. package/examples/medmot-staging/frontend/node_modules/esbuild/README.md +3 -0
  47. package/examples/medmot-staging/frontend/node_modules/esbuild/bin/esbuild +220 -0
  48. package/examples/medmot-staging/frontend/node_modules/esbuild/install.js +285 -0
  49. package/examples/medmot-staging/frontend/node_modules/esbuild/lib/main.d.ts +705 -0
  50. package/examples/medmot-staging/frontend/node_modules/esbuild/lib/main.js +2239 -0
  51. package/examples/medmot-staging/frontend/node_modules/esbuild/package.json +46 -0
  52. package/examples/sdk-demo/node_modules/esbuild/LICENSE.md +21 -0
  53. package/examples/sdk-demo/node_modules/esbuild/README.md +3 -0
  54. package/examples/sdk-demo/node_modules/esbuild/bin/esbuild +223 -0
  55. package/examples/sdk-demo/node_modules/esbuild/install.js +289 -0
  56. package/examples/sdk-demo/node_modules/esbuild/lib/main.d.ts +716 -0
  57. package/examples/sdk-demo/node_modules/esbuild/lib/main.js +2242 -0
  58. package/examples/sdk-demo/node_modules/esbuild/package.json +49 -0
  59. package/package.json +9 -9
  60. package/packages/client/node_modules/esbuild/LICENSE.md +21 -0
  61. package/packages/client/node_modules/esbuild/README.md +3 -0
  62. package/packages/client/node_modules/esbuild/bin/esbuild +220 -0
  63. package/packages/client/node_modules/esbuild/install.js +285 -0
  64. package/packages/client/node_modules/esbuild/lib/main.d.ts +705 -0
  65. package/packages/client/node_modules/esbuild/lib/main.js +2239 -0
  66. package/packages/client/node_modules/esbuild/package.json +46 -0
  67. package/packages/client-postgresql/node_modules/esbuild/LICENSE.md +21 -0
  68. package/packages/client-postgresql/node_modules/esbuild/README.md +3 -0
  69. package/packages/client-postgresql/node_modules/esbuild/bin/esbuild +220 -0
  70. package/packages/client-postgresql/node_modules/esbuild/install.js +285 -0
  71. package/packages/client-postgresql/node_modules/esbuild/lib/main.d.ts +705 -0
  72. package/packages/client-postgresql/node_modules/esbuild/lib/main.js +2239 -0
  73. package/packages/client-postgresql/node_modules/esbuild/package.json +46 -0
  74. package/packages/common/node_modules/esbuild/LICENSE.md +21 -0
  75. package/packages/common/node_modules/esbuild/README.md +3 -0
  76. package/packages/common/node_modules/esbuild/bin/esbuild +220 -0
  77. package/packages/common/node_modules/esbuild/install.js +285 -0
  78. package/packages/common/node_modules/esbuild/lib/main.d.ts +705 -0
  79. package/packages/common/node_modules/esbuild/lib/main.js +2239 -0
  80. package/packages/common/node_modules/esbuild/package.json +46 -0
  81. package/packages/server-mongodb/node_modules/esbuild/LICENSE.md +21 -0
  82. package/packages/server-mongodb/node_modules/esbuild/README.md +3 -0
  83. package/packages/server-mongodb/node_modules/esbuild/bin/esbuild +220 -0
  84. package/packages/server-mongodb/node_modules/esbuild/install.js +285 -0
  85. package/packages/server-mongodb/node_modules/esbuild/lib/main.d.ts +705 -0
  86. package/packages/server-mongodb/node_modules/esbuild/lib/main.js +2239 -0
  87. package/packages/server-mongodb/node_modules/esbuild/package.json +46 -0
  88. package/packages/server-postgresql/node_modules/esbuild/LICENSE.md +21 -0
  89. package/packages/server-postgresql/node_modules/esbuild/README.md +3 -0
  90. package/packages/server-postgresql/node_modules/esbuild/bin/esbuild +220 -0
  91. package/packages/server-postgresql/node_modules/esbuild/install.js +285 -0
  92. package/packages/server-postgresql/node_modules/esbuild/lib/main.d.ts +705 -0
  93. package/packages/server-postgresql/node_modules/esbuild/lib/main.js +2239 -0
  94. package/packages/server-postgresql/node_modules/esbuild/package.json +46 -0
  95. package/packages/types/node_modules/esbuild/LICENSE.md +21 -0
  96. package/packages/types/node_modules/esbuild/README.md +3 -0
  97. package/packages/types/node_modules/esbuild/bin/esbuild +220 -0
  98. package/packages/types/node_modules/esbuild/install.js +285 -0
  99. package/packages/types/node_modules/esbuild/lib/main.d.ts +705 -0
  100. package/packages/types/node_modules/esbuild/lib/main.js +2239 -0
  101. package/packages/types/node_modules/esbuild/package.json +46 -0
  102. package/packages/utils/node_modules/esbuild/LICENSE.md +21 -0
  103. package/packages/utils/node_modules/esbuild/README.md +3 -0
  104. package/packages/utils/node_modules/esbuild/bin/esbuild +220 -0
  105. package/packages/utils/node_modules/esbuild/install.js +285 -0
  106. package/packages/utils/node_modules/esbuild/lib/main.d.ts +705 -0
  107. package/packages/utils/node_modules/esbuild/lib/main.js +2239 -0
  108. package/packages/utils/node_modules/esbuild/package.json +46 -0
  109. package/src/api/errors.ts +3 -2
  110. package/src/api/rest/api-generator-count.test.ts +113 -0
  111. package/src/api/rest/api-generator.ts +123 -22
  112. package/src/api/server.ts +8 -4
  113. package/src/auth/admin-routes.ts +133 -57
  114. package/src/auth/apple-oauth.ts +8 -18
  115. package/src/auth/google-oauth.ts +192 -22
  116. package/src/auth/index.ts +1 -0
  117. package/src/auth/rate-limiter.ts +9 -5
  118. package/src/auth/routes.ts +25 -5
  119. package/src/collections/loader.ts +3 -3
  120. package/src/cron/cron-scheduler.test.ts +301 -175
  121. package/src/cron/cron-scheduler.ts +220 -57
  122. package/src/cron/index.ts +1 -1
  123. package/src/init.ts +27 -5
  124. package/src/storage/LocalStorageController.ts +37 -13
  125. package/src/storage/S3StorageController.ts +4 -1
  126. package/src/storage/routes.ts +51 -5
  127. package/test/backend-hooks-admin.test.ts +394 -0
  128. package/test/backend-hooks-data.test.ts +408 -0
  129. package/history_diff.log +0 -385
  130. package/scratch.ts +0 -9
  131. package/test-ast.ts +0 -28
  132. package/test_output.txt +0 -1133
@@ -1,5 +1,5 @@
1
1
  import { Hono } from "hono";
2
- import { DataDriver, EntityCollection } from "@rebasepro/types";
2
+ import { DataDriver, EntityCollection, DataHooks } from "@rebasepro/types";
3
3
  import { HonoEnv } from "../types";
4
4
  /**
5
5
  * Lightweight REST API generator that leverages existing Rebase DataDriver.
@@ -9,13 +9,16 @@ export declare class RestApiGenerator {
9
9
  private collections;
10
10
  private router;
11
11
  private driver;
12
- constructor(collections: EntityCollection[], driver: DataDriver);
12
+ private dataHooks?;
13
+ constructor(collections: EntityCollection[], driver: DataDriver, dataHooks?: DataHooks);
14
+ /** Build a BackendHookContext from a Hono context */
15
+ private buildHookContext;
13
16
  /**
14
17
  * Generate REST routes using existing DataDriver
15
18
  */
16
19
  generateRoutes(): Hono<HonoEnv>;
17
20
  /**
18
- * Get the EntityFetchService from a driver if it exposes one (for include support)
21
+ * Get the typed RestFetchService from a driver if it exposes one (for include support).
19
22
  */
20
23
  private getFetchService;
21
24
  /**
@@ -61,4 +64,13 @@ export declare class RestApiGenerator {
61
64
  * Fetch single entity raw data without Entity wrapper (fallback)
62
65
  */
63
66
  private fetchRawEntity;
67
+ /**
68
+ * Apply data.afterRead hook to a single entity.
69
+ * Returns the transformed entity, or null to filter it out.
70
+ */
71
+ private applyAfterRead;
72
+ /**
73
+ * Apply data.afterRead hook to an array of entities, filtering out nulls.
74
+ */
75
+ private applyAfterReadBatch;
64
76
  }
@@ -1,5 +1,6 @@
1
1
  import { Hono } from "hono";
2
2
  import { AuthModuleConfig } from "./routes";
3
+ import type { BackendHooks } from "@rebasepro/types";
3
4
  interface AdminRouteOptions extends AuthModuleConfig {
4
5
  serviceKey?: string;
5
6
  /**
@@ -7,6 +8,10 @@ interface AdminRouteOptions extends AuthModuleConfig {
7
8
  * Invoked after the first admin user is promoted via POST /admin/bootstrap.
8
9
  */
9
10
  setBootstrapCompleted?: () => Promise<void>;
11
+ /**
12
+ * Backend-level hooks for intercepting admin data.
13
+ */
14
+ hooks?: BackendHooks;
10
15
  }
11
16
  import { HonoEnv } from "../api/types";
12
17
  /**
@@ -6,9 +6,42 @@ export interface GoogleUserInfo {
6
6
  photoUrl: string | null;
7
7
  emailVerified: boolean;
8
8
  }
9
+ export interface GoogleProviderConfig {
10
+ clientId: string;
11
+ /**
12
+ * The OAuth 2.0 client secret from Google Cloud Console.
13
+ *
14
+ * Required for the **authorization code flow** (Path 3), where the
15
+ * frontend sends an authorization `code` and the backend exchanges it
16
+ * server-side for tokens. This is the most secure flow because tokens
17
+ * never touch the browser.
18
+ *
19
+ * When omitted, only ID-token and access-token verification are available
20
+ * (Paths 1 & 2), which rely on the frontend obtaining tokens directly.
21
+ */
22
+ clientSecret?: string;
23
+ }
9
24
  /**
10
- * Creates a Google OAuth Provider integration
25
+ * Creates a Google OAuth Provider integration.
26
+ *
27
+ * Supports three verification paths:
28
+ *
29
+ * **Path 1 – ID Token** (One Tap / Sign In With Google button):
30
+ * Frontend sends `idToken`. Backend verifies cryptographically using
31
+ * Google's public keys. No secret required.
32
+ *
33
+ * **Path 2 – Access Token** (popup via `initTokenClient`):
34
+ * Frontend sends `accessToken`. Backend validates by calling Google's
35
+ * userinfo endpoint. No secret required.
36
+ *
37
+ * **Path 3 – Authorization Code** (most secure, requires `clientSecret`):
38
+ * Frontend sends `code` + `redirectUri`. Backend exchanges the code
39
+ * server-side for an ID token using `clientId` + `clientSecret`, then
40
+ * verifies the ID token. Tokens never touch the browser.
11
41
  */
12
- export declare function createGoogleProvider(clientId: string): OAuthProvider<{
13
- idToken: string;
42
+ export declare function createGoogleProvider(config: GoogleProviderConfig | string): OAuthProvider<{
43
+ idToken?: string;
44
+ accessToken?: string;
45
+ code?: string;
46
+ redirectUri?: string;
14
47
  }>;
@@ -4,6 +4,7 @@ export type { JwtConfig, AccessTokenPayload } from "./jwt";
4
4
  export { hashPassword, verifyPassword, validatePasswordStrength } from "./password";
5
5
  export type { PasswordValidationResult } from "./password";
6
6
  export { createGoogleProvider } from "./google-oauth";
7
+ export type { GoogleProviderConfig } from "./google-oauth";
7
8
  export { createLinkedinProvider } from "./linkedin-oauth";
8
9
  export { createGitHubProvider } from "./github-oauth";
9
10
  export { createMicrosoftProvider } from "./microsoft-oauth";
@@ -2,6 +2,16 @@ import type { CronJobStatus, CronJobLogEntry } from "@rebasepro/types";
2
2
  import type { RebaseClient } from "@rebasepro/client";
3
3
  import type { LoadedCronJob } from "./cron-loader";
4
4
  import type { CronStore } from "./cron-store";
5
+ /**
6
+ * Validates a standard 5-field cron expression structurally and semantically.
7
+ * Returns `{ valid: true }` or `{ valid: false, reason: string }`.
8
+ */
9
+ export declare function validateCronExpression(schedule: string): {
10
+ valid: true;
11
+ } | {
12
+ valid: false;
13
+ reason: string;
14
+ };
5
15
  export declare class CronScheduler {
6
16
  private jobs;
7
17
  private started;
@@ -19,6 +29,12 @@ export declare class CronScheduler {
19
29
  setStore(store: CronStore): void;
20
30
  /**
21
31
  * Register a batch of loaded cron jobs.
32
+ *
33
+ * If the scheduler is already started, newly registered jobs are
34
+ * automatically scheduled (so late-registered jobs don't sit idle).
35
+ *
36
+ * Validates the cron schedule on registration — invalid schedules
37
+ * are rejected with a warning and the job is NOT registered.
22
38
  */
23
39
  registerJobs(loadedJobs: LoadedCronJob[]): void;
24
40
  /**
@@ -27,6 +43,9 @@ export declare class CronScheduler {
27
43
  start(): void;
28
44
  /**
29
45
  * Stop the scheduler and clear all timers.
46
+ *
47
+ * Currently-executing handlers run to completion (they are async),
48
+ * but no further scheduling occurs after stop.
30
49
  */
31
50
  stop(): void;
32
51
  /**
@@ -52,10 +71,36 @@ export declare class CronScheduler {
52
71
  setJobEnabled(id: string, enabled: boolean): CronJobStatus | undefined;
53
72
  /**
54
73
  * Manually trigger a job execution immediately.
74
+ *
75
+ * Returns `undefined` if the job doesn't exist.
76
+ * If the job is currently executing, returns the log entry with
77
+ * a `skipped: true` result rather than running concurrently.
55
78
  */
56
79
  triggerJob(id: string): Promise<CronJobLogEntry | undefined>;
80
+ /**
81
+ * Schedule the next execution for a job.
82
+ *
83
+ * Safety guarantees:
84
+ * 1. Clears any existing timer first (prevents leaked/duplicate timers)
85
+ * 2. Enforces a minimum delay to prevent tight loops from jitter
86
+ * 3. Unref's the timer so it doesn't prevent process exit
87
+ * 4. Re-checks enabled & started state before executing
88
+ * 5. Concurrency guard prevents overlapping handler executions
89
+ */
57
90
  private scheduleNext;
91
+ /**
92
+ * Stop a single job's timer and clear its next run state.
93
+ */
58
94
  private stopJob;
95
+ /**
96
+ * Execute a job's handler with full isolation and safety.
97
+ *
98
+ * - Sets a concurrency flag to prevent overlapping runs
99
+ * - Wraps handler in a timeout race
100
+ * - Captures all logs, errors, and results
101
+ * - Persists to store (non-blocking) if available
102
+ * - Always restores state even on catastrophic errors
103
+ */
59
104
  private executeJob;
60
105
  private toStatus;
61
106
  }
@@ -1,6 +1,6 @@
1
1
  export { loadCronJobsFromDirectory } from "./cron-loader";
2
2
  export type { LoadedCronJob } from "./cron-loader";
3
- export { CronScheduler } from "./cron-scheduler";
3
+ export { CronScheduler, validateCronExpression } from "./cron-scheduler";
4
4
  export { createCronRoutes } from "./cron-routes";
5
5
  export { createCronStore } from "./cron-store";
6
6
  export type { CronStore } from "./cron-store";
@@ -1,4 +1,4 @@
1
- import { DataDriver, EntityCollection, BackendBootstrapper, BootstrappedAuth, RealtimeProvider, HealthCheckResult } from "@rebasepro/types";
1
+ import { DataDriver, EntityCollection, BackendBootstrapper, BootstrappedAuth, RealtimeProvider, HealthCheckResult, BackendHooks } from "@rebasepro/types";
2
2
  import { BackendCollectionRegistry } from "./collections/BackendCollectionRegistry";
3
3
  import { DriverRegistry } from "./services/driver-registry";
4
4
  import { Server } from "http";
@@ -29,6 +29,7 @@ export interface RebaseAuthConfig {
29
29
  email?: EmailConfig;
30
30
  google?: {
31
31
  clientId: string;
32
+ clientSecret?: string;
32
33
  };
33
34
  linkedin?: {
34
35
  clientId: string;
@@ -129,6 +130,15 @@ export interface RebaseBackendConfig {
129
130
  /** Allowed origins for CSRF validation. */
130
131
  origin: string | string[] | ((origin: string) => boolean);
131
132
  };
133
+ /**
134
+ * Backend-level hooks for intercepting admin data (users, roles)
135
+ * at the API boundary. These run server-side after database reads
136
+ * and before API responses are sent.
137
+ *
138
+ * Complement the per-collection `EntityCallbacks` system which
139
+ * handles collection CRUD operations.
140
+ */
141
+ hooks?: BackendHooks;
132
142
  }
133
143
  export interface RebaseBackendInstance {
134
144
  driverRegistry: DriverRegistry;
@@ -80,8 +80,14 @@ 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 ID token or trigger Google popup */
84
- googleLogin?(idToken: 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
+ };
85
91
  /** Register a new user */
86
92
  register?(email: string, password: string, displayName?: string): Promise<void>;
87
93
  /** Skip login (for anonymous access if enabled) */
@@ -167,4 +167,17 @@ export interface RebaseClient<DB = unknown> {
167
167
  email?: EmailService;
168
168
  /** Admin API for user and role management */
169
169
  admin?: AdminAPI;
170
+ /**
171
+ * The base HTTP URL of the backend server.
172
+ * Exposed by the SDK client (`@rebasepro/client`) and used to auto-derive
173
+ * the `ApiConfigProvider` URL.
174
+ */
175
+ baseUrl?: string;
176
+ /**
177
+ * WebSocket client for realtime subscriptions and admin capabilities.
178
+ * Exposed by the SDK client (`@rebasepro/client`). The shape is intentionally
179
+ * left as `unknown` in the base interface — callers should narrow via feature
180
+ * detection (e.g. `typeof ws.executeSql === "function"`).
181
+ */
182
+ ws?: unknown;
170
183
  }
@@ -36,7 +36,8 @@ export type CollectionRegistryController<DB = Record<string, unknown>, EC extend
36
36
  * Retrieve all the related parent collection ids for a given path
37
37
  * @param path
38
38
  */
39
- getParentCollectionIds: (path: string) => string[];
39
+ getParentCollectionSlugs: (path: string) => string[];
40
+ getParentEntityIds: (path: string) => string[];
40
41
  /**
41
42
  * Resolve paths from a list of ids
42
43
  * @param ids
@@ -144,12 +144,19 @@ export interface DataDriver {
144
144
  path: string;
145
145
  databaseId?: string;
146
146
  collection: EntityCollection;
147
- parentCollectionIds?: string[];
147
+ parentCollectionSlugs?: string[];
148
+ parentEntityIds?: string[];
148
149
  }) => Promise<boolean>;
149
150
  /**
150
151
  * Flag to indicate if the driver has requested the initialization of the text search index
151
152
  */
152
153
  needsInitTextSearch?: boolean;
154
+ /**
155
+ * Optional REST-optimised fetch service. When present, the REST API
156
+ * generator uses these methods instead of the generic `fetchEntity` /
157
+ * `fetchCollection` pipeline, enabling include-aware eager-loading.
158
+ */
159
+ restFetchService?: RestFetchService;
153
160
  /**
154
161
  * Return the admin capabilities of this driver.
155
162
  * @see SQLAdmin
@@ -158,3 +165,31 @@ export interface DataDriver {
158
165
  */
159
166
  admin?: import("../types/backend").DatabaseAdmin;
160
167
  }
168
+ /**
169
+ * REST-optimised fetch service exposed by drivers that support
170
+ * eager-loading of relations via `include`.
171
+ *
172
+ * The methods return flattened rows (`{ id, ...columns }`) rather
173
+ * than the `Entity<M>` wrapper used by the generic DataDriver API.
174
+ *
175
+ * @group DataDriver
176
+ */
177
+ export interface RestFetchService {
178
+ /**
179
+ * Fetch a collection of flattened entities with optional relation includes.
180
+ */
181
+ fetchCollectionForRest(collectionPath: string, options?: {
182
+ filter?: FilterValues<string>;
183
+ orderBy?: string;
184
+ order?: "desc" | "asc";
185
+ limit?: number;
186
+ offset?: number;
187
+ startAfter?: Record<string, unknown>;
188
+ searchString?: string;
189
+ databaseId?: string;
190
+ }, include?: string[]): Promise<Record<string, unknown>[]>;
191
+ /**
192
+ * Fetch a single flattened entity with optional relation includes.
193
+ */
194
+ fetchEntityForRest(collectionPath: string, entityId: string | number, include?: string[], databaseId?: string): Promise<Record<string, unknown> | null>;
195
+ }
@@ -144,17 +144,18 @@ export interface AppView {
144
144
  * It will still be accessible if you reach the specified path
145
145
  */
146
146
  hideFromNavigation?: boolean;
147
+ /**
148
+ * Navigation group for this view.
149
+ * Views sharing the same group name will be visually grouped
150
+ * together in the drawer and home page. If not set, the view
151
+ * falls into the default "Views" group.
152
+ */
153
+ group?: string;
147
154
  /**
148
155
  * Component to be rendered. This can be any React component, and can use
149
156
  * any of the provided hooks
150
157
  */
151
158
  view: React.ReactNode;
152
- /**
153
- * Optional field used to group top level navigation entries under a
154
- * navigation view.
155
- * This prop is ignored for admin views.
156
- */
157
- group?: string;
158
159
  /**
159
160
  * If true, a wildcard route (slug/*) is automatically registered
160
161
  * alongside the base route, enabling nested navigation within this view.
@@ -193,6 +194,17 @@ export interface NavigationGroupMapping {
193
194
  * List of collection ids or view paths that belong to this group.
194
195
  */
195
196
  entries: string[];
197
+ /**
198
+ * Configure which groups start collapsed.
199
+ * Set to `true` to collapse in both drawer and home page,
200
+ * or use an object to control each independently.
201
+ *
202
+ * @defaultValue false (expanded)
203
+ */
204
+ collapsedByDefault?: boolean | {
205
+ drawer?: boolean;
206
+ home?: boolean;
207
+ };
196
208
  }
197
209
  export interface NavigationEntry {
198
210
  id: string;
@@ -3,7 +3,7 @@ import type { EntityCollection } from "../types/collections";
3
3
  import type { EntityCollectionsBuilder } from "../types/builders";
4
4
  import type { EntityCustomView } from "../types/entity_views";
5
5
  import type { EntityAction } from "../types/entity_actions";
6
- import type { AppView } from "./navigation";
6
+ import type { AppView, NavigationGroupMapping } from "./navigation";
7
7
  /**
8
8
  * Options to enable the built-in collection editor.
9
9
  * When provided to `<RebaseCMS>`, the editor is auto-wired as a native feature.
@@ -25,6 +25,14 @@ export interface RebaseCMSConfig<EC extends EntityCollection = any> {
25
25
  entityViews?: EntityCustomView<any>[];
26
26
  entityActions?: EntityAction[];
27
27
  plugins?: any[];
28
+ /**
29
+ * Centralized configuration for how collections and views are grouped
30
+ * in the navigation sidebar and home page.
31
+ * Each mapping defines a named group and the collection/view slugs
32
+ * that belong to it. The array order determines group display order.
33
+ * Entry order within each group determines card order.
34
+ */
35
+ navigationGroupMappings?: NavigationGroupMapping[];
28
36
  /**
29
37
  * Enable the built-in visual collection/schema editor.
30
38
  * Pass `true` for zero-config, or an options object for fine-grained control.
@@ -62,6 +62,13 @@ export interface EntitySidePanelProps<M extends Record<string, unknown> = Record
62
62
  * Allow the user to open the entity fullscreen
63
63
  */
64
64
  allowFullScreen?: boolean;
65
+ /**
66
+ * Pre-populate the form with these values when creating a new entity.
67
+ * Only applied when `entityId` is not set (i.e. the form is in "new" mode).
68
+ * Useful for actions that fetch data from an external source (e.g. a URL)
69
+ * and want to pre-fill the document before the user saves.
70
+ */
71
+ defaultValues?: Partial<M>;
65
72
  }
66
73
  /**
67
74
  * Controller to open the side dialog displaying entity forms
@@ -3,6 +3,7 @@ import type { AuthController } from "./controllers/auth";
3
3
  import type { StorageSource } from "./controllers/storage";
4
4
  import type { UserConfigurationPersistence } from "./controllers/local_config_persistence";
5
5
  import type { DatabaseAdmin } from "./types/backend";
6
+ import type { RebaseClient } from "./controllers/client";
6
7
  import type { RebaseData } from "./controllers/data";
7
8
  import type { User } from "./users";
8
9
  import type { UserManagementDelegate } from "./types/user_management_delegate";
@@ -12,6 +13,22 @@ import type { UserManagementDelegate } from "./types/user_management_delegate";
12
13
  * @group Hooks and utilities
13
14
  */
14
15
  export type RebaseCallContext<USER extends User = User> = {
16
+ /**
17
+ * The Rebase client instance.
18
+ * Available in all entity callbacks (beforeSave, afterSave, afterRead,
19
+ * beforeDelete, afterDelete) and in CollectionActionsProps via context.
20
+ * Use it to call backend functions, access data, storage, etc.
21
+ *
22
+ * @example
23
+ * // In a beforeSave callback:
24
+ * const result = await context.client.functions.invoke('my-function', { ... });
25
+ *
26
+ * @example
27
+ * // In a CollectionAction component:
28
+ * const { client } = props.context;
29
+ * const result = await client.functions.invoke('extract-job', { url });
30
+ */
31
+ client: RebaseClient<any>;
15
32
  /**
16
33
  * Unified data access — `context.data.products.create(...)`.
17
34
  * Access any collection as a dynamic property.
@@ -0,0 +1,187 @@
1
+ import type { AdminUser, AdminRole } from "../controllers/client";
2
+ /**
3
+ * Context passed to every backend hook.
4
+ * Provides information about the request that triggered the hook.
5
+ * @group Backend Hooks
6
+ */
7
+ export interface BackendHookContext {
8
+ /** The currently authenticated user making the request (if any) */
9
+ requestUser?: {
10
+ userId: string;
11
+ roles: string[];
12
+ };
13
+ /** The HTTP method of the request */
14
+ method: "GET" | "POST" | "PUT" | "DELETE";
15
+ }
16
+ /**
17
+ * Hooks for intercepting Admin User data at the API boundary.
18
+ *
19
+ * These hooks run on the server after the database operation completes
20
+ * but before the response is sent to the client.
21
+ *
22
+ * @group Backend Hooks
23
+ */
24
+ export interface UserHooks {
25
+ /**
26
+ * Transform a user record after it's read from the database,
27
+ * before it's returned to the client.
28
+ *
29
+ * Return the modified user, or `null` to filter it out entirely
30
+ * (the user won't appear in listings or individual fetches).
31
+ */
32
+ afterRead?(user: AdminUser, context: BackendHookContext): AdminUser | null | Promise<AdminUser | null>;
33
+ /**
34
+ * Transform user data before it's written to the database.
35
+ * Runs on POST (create) and PUT (update).
36
+ *
37
+ * Return the (possibly modified) data to proceed with the save.
38
+ * Throw an error to abort the operation.
39
+ */
40
+ beforeSave?(data: {
41
+ email?: string;
42
+ displayName?: string;
43
+ roles?: string[];
44
+ }, context: BackendHookContext): {
45
+ email?: string;
46
+ displayName?: string;
47
+ roles?: string[];
48
+ } | Promise<{
49
+ email?: string;
50
+ displayName?: string;
51
+ roles?: string[];
52
+ }>;
53
+ /**
54
+ * Called after a user is successfully created or updated.
55
+ * Useful for side-effects like sending notifications.
56
+ */
57
+ afterSave?(user: AdminUser, context: BackendHookContext): void | Promise<void>;
58
+ /**
59
+ * Called before a user is deleted. Throw to prevent deletion.
60
+ */
61
+ beforeDelete?(userId: string, context: BackendHookContext): void | Promise<void>;
62
+ /**
63
+ * Called after a user is successfully deleted.
64
+ */
65
+ afterDelete?(userId: string, context: BackendHookContext): void | Promise<void>;
66
+ }
67
+ /**
68
+ * Hooks for intercepting Admin Role data at the API boundary.
69
+ * @group Backend Hooks
70
+ */
71
+ export interface RoleHooks {
72
+ /**
73
+ * Transform a role record after it's read from the database,
74
+ * before it's returned to the client.
75
+ *
76
+ * Return the modified role, or `null` to filter it out entirely.
77
+ */
78
+ afterRead?(role: AdminRole, context: BackendHookContext): AdminRole | null | Promise<AdminRole | null>;
79
+ }
80
+ /**
81
+ * Hooks for intercepting collection entity data at the REST API boundary.
82
+ *
83
+ * These run **after** per-collection `EntityCallbacks` (which execute inside
84
+ * the DataDriver) and provide a single cross-cutting interception point for
85
+ * ALL collections flowing through the REST API.
86
+ *
87
+ * Every callback receives the collection `slug` so you can target specific
88
+ * collections or apply logic globally.
89
+ *
90
+ * @group Backend Hooks
91
+ */
92
+ export interface DataHooks {
93
+ /**
94
+ * Transform an entity after it's read from the database,
95
+ * before it's returned to the client.
96
+ *
97
+ * Runs for both list (GET /:slug) and single (GET /:slug/:id) fetches.
98
+ * Return the modified entity, or `null` to filter it out.
99
+ *
100
+ * @param slug - The collection slug (e.g. "orders", "products")
101
+ * @param entity - The flattened entity object (id + values merged)
102
+ * @param context - Request context (authenticated user, HTTP method)
103
+ */
104
+ afterRead?(slug: string, entity: Record<string, unknown>, context: BackendHookContext): Record<string, unknown> | null | Promise<Record<string, unknown> | null>;
105
+ /**
106
+ * Transform entity values before they are written to the database.
107
+ * Runs on POST (create) and PUT (update).
108
+ *
109
+ * Return the (possibly modified) values. Throw to abort the save.
110
+ *
111
+ * @param slug - The collection slug
112
+ * @param values - The raw request body values
113
+ * @param entityId - The entity ID (only present on updates)
114
+ * @param context - Request context
115
+ */
116
+ beforeSave?(slug: string, values: Record<string, unknown>, entityId: string | undefined, context: BackendHookContext): Record<string, unknown> | Promise<Record<string, unknown>>;
117
+ /**
118
+ * Called after an entity is successfully saved (created or updated).
119
+ * Useful for side-effects like syncing to external systems.
120
+ *
121
+ * @param slug - The collection slug
122
+ * @param entity - The saved entity (flattened)
123
+ * @param context - Request context
124
+ */
125
+ afterSave?(slug: string, entity: Record<string, unknown>, context: BackendHookContext): void | Promise<void>;
126
+ /**
127
+ * Called before an entity is deleted. Throw to prevent deletion.
128
+ *
129
+ * @param slug - The collection slug
130
+ * @param entityId - The entity ID being deleted
131
+ * @param context - Request context
132
+ */
133
+ beforeDelete?(slug: string, entityId: string, context: BackendHookContext): void | Promise<void>;
134
+ /**
135
+ * Called after an entity is successfully deleted.
136
+ *
137
+ * @param slug - The collection slug
138
+ * @param entityId - The deleted entity ID
139
+ * @param context - Request context
140
+ */
141
+ afterDelete?(slug: string, entityId: string, context: BackendHookContext): void | Promise<void>;
142
+ }
143
+ /**
144
+ * Backend-level hooks for intercepting data at the API boundary.
145
+ *
146
+ * These hooks run server-side after database operations complete and before
147
+ * API responses are sent.
148
+ *
149
+ * - `users` / `roles` — intercept admin user and role management endpoints
150
+ * - `data` — intercept ALL collection entity data flowing through the REST API
151
+ *
152
+ * `data` hooks complement per-collection `EntityCallbacks`. Entity callbacks
153
+ * run inside the DataDriver (close to the DB); data hooks run at the HTTP
154
+ * boundary (close to the client). Use data hooks for cross-cutting concerns
155
+ * like audit logging, response enrichment, or field masking.
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const hooks: BackendHooks = {
160
+ * data: {
161
+ * afterRead(slug, entity, ctx) {
162
+ * // Mask PII for non-admin users across all collections
163
+ * if (!ctx.requestUser?.roles.includes("admin") && entity.email) {
164
+ * return { ...entity, email: "***" };
165
+ * }
166
+ * return entity;
167
+ * }
168
+ * },
169
+ * users: {
170
+ * afterRead(user, ctx) {
171
+ * if (user.email.endsWith("@system.internal")) return null;
172
+ * return user;
173
+ * }
174
+ * }
175
+ * };
176
+ * ```
177
+ *
178
+ * @group Backend Hooks
179
+ */
180
+ export interface BackendHooks {
181
+ /** Hooks for intercepting user management data */
182
+ users?: UserHooks;
183
+ /** Hooks for intercepting role management data */
184
+ roles?: RoleHooks;
185
+ /** Hooks for intercepting ALL collection entity data via the REST API */
186
+ data?: DataHooks;
187
+ }