@rebasepro/server 0.0.1-canary.4829d6e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +77 -0
- package/dist/api/ast-schema-editor.d.ts +21 -0
- package/dist/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
- package/dist/api/errors.d.ts +53 -0
- package/dist/api/index.d.ts +7 -0
- package/dist/api/logs-routes.d.ts +37 -0
- package/dist/api/openapi-generator.d.ts +16 -0
- package/dist/api/rest/api-generator.d.ts +68 -0
- package/dist/api/rest/index.d.ts +1 -0
- package/dist/api/rest/query-parser.d.ts +6 -0
- package/dist/api/schema-editor-routes.d.ts +3 -0
- package/dist/api/types.d.ts +56 -0
- package/dist/auth/adapter-middleware.d.ts +43 -0
- package/dist/auth/admin-roles-route.d.ts +18 -0
- package/dist/auth/admin-user-ops.d.ts +80 -0
- package/dist/auth/admin-users-route.d.ts +28 -0
- package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
- package/dist/auth/api-keys/api-key-permission-guard.d.ts +32 -0
- package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
- package/dist/auth/api-keys/api-key-store.d.ts +35 -0
- package/dist/auth/api-keys/api-key-types.d.ts +96 -0
- package/dist/auth/api-keys/index.d.ts +17 -0
- package/dist/auth/apple-oauth.d.ts +30 -0
- package/dist/auth/auth-hooks.d.ts +242 -0
- package/dist/auth/bitbucket-oauth.d.ts +11 -0
- package/dist/auth/builtin-auth-adapter.d.ts +55 -0
- package/dist/auth/cookie-utils.d.ts +32 -0
- package/dist/auth/crypto-utils.d.ts +16 -0
- package/dist/auth/custom-auth-adapter.d.ts +39 -0
- package/dist/auth/discord-oauth.d.ts +14 -0
- package/dist/auth/facebook-oauth.d.ts +14 -0
- package/dist/auth/github-oauth.d.ts +15 -0
- package/dist/auth/gitlab-oauth.d.ts +13 -0
- package/dist/auth/google-oauth.d.ts +47 -0
- package/dist/auth/index.d.ts +38 -0
- package/dist/auth/interfaces.d.ts +431 -0
- package/dist/auth/jwt.d.ts +67 -0
- package/dist/auth/linkedin-oauth.d.ts +18 -0
- package/dist/auth/magic-link-routes.d.ts +32 -0
- package/dist/auth/mfa-crypto.d.ts +23 -0
- package/dist/auth/mfa-routes.d.ts +7 -0
- package/dist/auth/mfa.d.ts +49 -0
- package/dist/auth/microsoft-oauth.d.ts +16 -0
- package/dist/auth/middleware.d.ts +158 -0
- package/dist/auth/password.d.ts +22 -0
- package/dist/auth/rate-limiter.d.ts +50 -0
- package/dist/auth/reset-password-admin.d.ts +29 -0
- package/dist/auth/rls-scope.d.ts +31 -0
- package/dist/auth/routes.d.ts +66 -0
- package/dist/auth/session-routes.d.ts +29 -0
- package/dist/auth/slack-oauth.d.ts +12 -0
- package/dist/auth/spotify-oauth.d.ts +12 -0
- package/dist/auth/twitter-oauth.d.ts +18 -0
- package/dist/backup/backup-common.d.ts +31 -0
- package/dist/backup/backup-routes.d.ts +22 -0
- package/dist/backup/index.d.ts +7 -0
- package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
- package/dist/collections/loader.d.ts +39 -0
- package/dist/cron/cron-loader.d.ts +18 -0
- package/dist/cron/cron-routes.d.ts +14 -0
- package/dist/cron/cron-scheduler.d.ts +106 -0
- package/dist/cron/cron-store.d.ts +32 -0
- package/dist/cron/define-cron.d.ts +28 -0
- package/dist/cron/index.d.ts +7 -0
- package/dist/db/interfaces.d.ts +18 -0
- package/dist/dynamic-import-Dvh-K5fl.js +22 -0
- package/dist/dynamic-import-Dvh-K5fl.js.map +1 -0
- package/dist/email/index.d.ts +6 -0
- package/dist/email/smtp-email-service.d.ts +30 -0
- package/dist/email/templates.d.ts +50 -0
- package/dist/email/types.d.ts +126 -0
- package/dist/env.d.ts +102 -0
- package/dist/functions/define-function.d.ts +55 -0
- package/dist/functions/function-loader.d.ts +18 -0
- package/dist/functions/function-routes.d.ts +10 -0
- package/dist/functions/index.d.ts +5 -0
- package/dist/history/history-routes.d.ts +23 -0
- package/dist/history/index.d.ts +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.es.js +18458 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +48745 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/init/docs.d.ts +4 -0
- package/dist/init/health.d.ts +2 -0
- package/dist/init/middlewares.d.ts +10 -0
- package/dist/init/shutdown.d.ts +65 -0
- package/dist/init/storage.d.ts +5 -0
- package/dist/init.d.ts +375 -0
- package/dist/jwt-BwIn8xmk.js +4200 -0
- package/dist/jwt-BwIn8xmk.js.map +1 -0
- package/dist/logger-BYU66ENZ.js +94 -0
- package/dist/logger-BYU66ENZ.js.map +1 -0
- package/dist/ms-DnYXB-Wd.js +162 -0
- package/dist/ms-DnYXB-Wd.js.map +1 -0
- package/dist/openapi-generator-Z9oYWLf_.js +586 -0
- package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
- package/dist/schema-editor-routes-D3ef8zu1.js +219 -0
- package/dist/schema-editor-routes-D3ef8zu1.js.map +1 -0
- package/dist/serve-spa.d.ts +36 -0
- package/dist/services/driver-registry.d.ts +78 -0
- package/dist/services/routed-realtime-service.d.ts +43 -0
- package/dist/services/webhook-service.d.ts +29 -0
- package/dist/singleton.d.ts +51 -0
- package/dist/src-B4OLmNVa.js +437 -0
- package/dist/src-B4OLmNVa.js.map +1 -0
- package/dist/src-B9tjYmqP.js +24598 -0
- package/dist/src-B9tjYmqP.js.map +1 -0
- package/dist/storage/GCSStorageController.d.ts +43 -0
- package/dist/storage/LocalStorageController.d.ts +46 -0
- package/dist/storage/S3StorageController.d.ts +40 -0
- package/dist/storage/image-transform.d.ts +50 -0
- package/dist/storage/index.d.ts +31 -0
- package/dist/storage/routes.d.ts +70 -0
- package/dist/storage/storage-registry.d.ts +78 -0
- package/dist/storage/tus-handler.d.ts +53 -0
- package/dist/storage/types.d.ts +128 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/utils/dev-port.d.ts +45 -0
- package/dist/utils/dynamic-import.d.ts +25 -0
- package/dist/utils/logger.d.ts +31 -0
- package/dist/utils/logging.d.ts +9 -0
- package/dist/utils/request-id.d.ts +4 -0
- package/dist/utils/request-logger.d.ts +19 -0
- package/dist/utils/sql.d.ts +27 -0
- package/package.json +115 -0
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { CollectionConfig } from "@rebasepro/types";
|
|
3
|
+
import { HonoEnv } from "../api/types";
|
|
4
|
+
export declare function mountOpenApiDocs(app: Hono<HonoEnv>, basePath: string, enableSwagger: boolean | undefined, activeCollections: CollectionConfig[], requireAuth: boolean): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { HonoEnv } from "../api/types";
|
|
3
|
+
interface MiddlewareConfig {
|
|
4
|
+
maxBodySize?: number;
|
|
5
|
+
csrf?: {
|
|
6
|
+
origin: string | string[] | ((origin: string) => boolean);
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare function configureMiddlewares(app: Hono<HonoEnv>, basePath: string, isProduction: boolean, config: MiddlewareConfig): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Server } from "http";
|
|
2
|
+
import { RealtimeProvider } from "@rebasepro/types";
|
|
3
|
+
interface ShutdownConfig {
|
|
4
|
+
server: Server;
|
|
5
|
+
cronScheduler?: {
|
|
6
|
+
stop(): void;
|
|
7
|
+
};
|
|
8
|
+
realtimeServices: Record<string, RealtimeProvider>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Minimal structural view of the backend instance needed by
|
|
12
|
+
* {@link installShutdownHandlers}. Structural (rather than importing
|
|
13
|
+
* `RebaseBackendInstance`) to avoid a circular import with `../init`.
|
|
14
|
+
*/
|
|
15
|
+
interface ShutdownCapableBackend {
|
|
16
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface ShutdownHandlerOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Cleanup to run after the backend has drained — e.g. closing your
|
|
21
|
+
* database pool: `onCleanup: () => pool.end()`.
|
|
22
|
+
*/
|
|
23
|
+
onCleanup?: () => Promise<void> | void;
|
|
24
|
+
/**
|
|
25
|
+
* Hard force-exit timeout in milliseconds. If the shutdown sequence
|
|
26
|
+
* (drain + cleanup) has not completed by then, the process exits with
|
|
27
|
+
* code 1. Also passed to `backend.shutdown()` as its drain timeout.
|
|
28
|
+
*
|
|
29
|
+
* @default 15000
|
|
30
|
+
*/
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Process signals to handle.
|
|
34
|
+
* @default ["SIGTERM", "SIGINT"]
|
|
35
|
+
*/
|
|
36
|
+
signals?: NodeJS.Signals[];
|
|
37
|
+
/** @internal Injectable exit function for tests. */
|
|
38
|
+
exit?: (code: number) => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Install graceful-shutdown signal handlers for a Rebase backend.
|
|
42
|
+
*
|
|
43
|
+
* On the first signal received, this drains the backend via
|
|
44
|
+
* `backend.shutdown()` — which stops the cron scheduler, tears down
|
|
45
|
+
* realtime services, and closes the HTTP server. Do **not** call
|
|
46
|
+
* `server.close()` yourself in addition: closing an already-closing
|
|
47
|
+
* server deadlocks, because the second close's callback never fires.
|
|
48
|
+
*
|
|
49
|
+
* After the drain, `onCleanup` runs (close your database pool here),
|
|
50
|
+
* and the process exits 0. A force-exit timer guards the whole
|
|
51
|
+
* sequence: if it has not completed within `timeoutMs`, the process
|
|
52
|
+
* exits 1. Repeated signals while a shutdown is in flight are ignored.
|
|
53
|
+
*
|
|
54
|
+
* @returns An uninstall function that removes the signal listeners
|
|
55
|
+
* (useful in tests).
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const backend = await initializeRebaseBackend({ ... });
|
|
60
|
+
* installShutdownHandlers(backend, { onCleanup: () => pool.end() });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function installShutdownHandlers(backend: ShutdownCapableBackend, options?: ShutdownHandlerOptions): () => void;
|
|
64
|
+
export declare function createShutdown(config: ShutdownConfig): (timeoutMs?: number) => Promise<void>;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BackendStorageConfig, StorageController, StorageRegistry } from "../storage";
|
|
2
|
+
export declare function initializeStorage(storageConfig: BackendStorageConfig | StorageController | Record<string, BackendStorageConfig | StorageController> | undefined, isProduction: boolean): Promise<{
|
|
3
|
+
storageRegistry?: StorageRegistry;
|
|
4
|
+
storageController?: StorageController;
|
|
5
|
+
}>;
|
package/dist/init.d.ts
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { AuthAdapter, BackendBootstrapper, BootstrappedAuth, DatabaseAdapter, DataDriver, DataSourceDefinition, CollectionCallbacks, CollectionConfig, HealthCheckResult, HistoryConfig, RealtimeProvider } from "@rebasepro/types";
|
|
2
|
+
import { BackendCollectionRegistry } from "./collections/BackendCollectionRegistry";
|
|
3
|
+
import { DriverRegistry } from "./services/driver-registry";
|
|
4
|
+
import { Server } from "http";
|
|
5
|
+
import { Hono } from "hono";
|
|
6
|
+
import { HonoEnv } from "./api/types";
|
|
7
|
+
import { BackendStorageConfig, StorageController, StorageRegistry } from "./storage";
|
|
8
|
+
import { EmailConfig } from "./email";
|
|
9
|
+
import type { OAuthProvider } from "./auth/interfaces";
|
|
10
|
+
import type { AuthHooks } from "./auth/auth-hooks";
|
|
11
|
+
export interface RebaseAuthConfig {
|
|
12
|
+
/**
|
|
13
|
+
* The collection that represents auth users.
|
|
14
|
+
*
|
|
15
|
+
* When provided, this collection's underlying database table is used
|
|
16
|
+
* for all auth operations (login, registration, password reset, etc.).
|
|
17
|
+
*
|
|
18
|
+
* Import the built-in default:
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { defaultUsersCollection } from "@rebasepro/common";
|
|
21
|
+
* auth: { collection: defaultUsersCollection, jwtSecret: "..." }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Or pass your own collection with the required auth fields
|
|
25
|
+
* (email, passwordHash, displayName, etc.).
|
|
26
|
+
*/
|
|
27
|
+
collection?: CollectionConfig;
|
|
28
|
+
jwtSecret?: string;
|
|
29
|
+
accessExpiresIn?: string;
|
|
30
|
+
refreshExpiresIn?: string;
|
|
31
|
+
requireAuth?: boolean;
|
|
32
|
+
allowRegistration?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Opt-in: expose `POST /auth/find-user` so an authenticated user can resolve
|
|
35
|
+
* an email address to a minimal public profile (`uid`, `displayName`,
|
|
36
|
+
* `photoURL` only). This powers invite-by-email flows without a custom
|
|
37
|
+
* admin server function. Off by default because it enables user enumeration
|
|
38
|
+
* by any signed-in user. Available on the client as `auth.findUserByEmail`.
|
|
39
|
+
*/
|
|
40
|
+
allowUserLookup?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* A static secret key for server-to-server / script authentication.
|
|
43
|
+
*
|
|
44
|
+
* When a request includes `Authorization: Bearer <serviceKey>`, it is
|
|
45
|
+
* granted admin-level access without JWT verification. This is the
|
|
46
|
+
* Rebase equivalent of a Service Account key.
|
|
47
|
+
*
|
|
48
|
+
* Generate with: `node -e "logger.info(require('crypto').randomBytes(48).toString('base64'))"`
|
|
49
|
+
*
|
|
50
|
+
* Set via `REBASE_SERVICE_KEY` in your `.env`.
|
|
51
|
+
* Must be at least 32 characters.
|
|
52
|
+
*/
|
|
53
|
+
serviceKey?: string;
|
|
54
|
+
email?: EmailConfig;
|
|
55
|
+
google?: {
|
|
56
|
+
clientId: string;
|
|
57
|
+
clientSecret?: string;
|
|
58
|
+
};
|
|
59
|
+
linkedin?: {
|
|
60
|
+
clientId: string;
|
|
61
|
+
clientSecret: string;
|
|
62
|
+
};
|
|
63
|
+
github?: {
|
|
64
|
+
clientId: string;
|
|
65
|
+
clientSecret: string;
|
|
66
|
+
};
|
|
67
|
+
microsoft?: {
|
|
68
|
+
clientId: string;
|
|
69
|
+
clientSecret: string;
|
|
70
|
+
tenantId?: string;
|
|
71
|
+
};
|
|
72
|
+
apple?: {
|
|
73
|
+
clientId: string;
|
|
74
|
+
teamId: string;
|
|
75
|
+
keyId: string;
|
|
76
|
+
privateKey: string;
|
|
77
|
+
};
|
|
78
|
+
facebook?: {
|
|
79
|
+
clientId: string;
|
|
80
|
+
clientSecret: string;
|
|
81
|
+
};
|
|
82
|
+
twitter?: {
|
|
83
|
+
clientId: string;
|
|
84
|
+
clientSecret: string;
|
|
85
|
+
};
|
|
86
|
+
discord?: {
|
|
87
|
+
clientId: string;
|
|
88
|
+
clientSecret: string;
|
|
89
|
+
};
|
|
90
|
+
gitlab?: {
|
|
91
|
+
clientId: string;
|
|
92
|
+
clientSecret: string;
|
|
93
|
+
baseUrl?: string;
|
|
94
|
+
};
|
|
95
|
+
bitbucket?: {
|
|
96
|
+
clientId: string;
|
|
97
|
+
clientSecret: string;
|
|
98
|
+
};
|
|
99
|
+
slack?: {
|
|
100
|
+
clientId: string;
|
|
101
|
+
clientSecret: string;
|
|
102
|
+
};
|
|
103
|
+
spotify?: {
|
|
104
|
+
clientId: string;
|
|
105
|
+
clientSecret: string;
|
|
106
|
+
};
|
|
107
|
+
defaultRole?: string;
|
|
108
|
+
/**
|
|
109
|
+
* Canonical array of OAuth providers.
|
|
110
|
+
*
|
|
111
|
+
* This is the primary extension point for **all** OAuth integrations.
|
|
112
|
+
* Each entry is an `OAuthProvider<unknown>` constructed via one of
|
|
113
|
+
* the `create*Provider` factories exported from `@rebasepro/server`
|
|
114
|
+
* (e.g. `createGoogleProvider`, `createGitHubProvider`).
|
|
115
|
+
*
|
|
116
|
+
* The named convenience fields above (`google`, `github`, etc.) are
|
|
117
|
+
* automatically resolved into this array at startup. You can mix both
|
|
118
|
+
* approaches; named fields and explicit entries are merged (named
|
|
119
|
+
* fields are appended after explicit entries).
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { createGoogleProvider } from "@rebasepro/server";
|
|
124
|
+
*
|
|
125
|
+
* auth: {
|
|
126
|
+
* providers: [
|
|
127
|
+
* createGoogleProvider({ clientId: "…", clientSecret: "…" }),
|
|
128
|
+
* ],
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
providers?: OAuthProvider<unknown>[];
|
|
133
|
+
/**
|
|
134
|
+
* Override specific parts of the built-in auth implementation.
|
|
135
|
+
*
|
|
136
|
+
* Each override replaces one piece of the default behavior while
|
|
137
|
+
* keeping everything else intact. Unset overrides fall through
|
|
138
|
+
* to the built-in defaults (scrypt passwords, standard validation, etc.).
|
|
139
|
+
*
|
|
140
|
+
* @example bcrypt passwords with a custom hash
|
|
141
|
+
* ```ts
|
|
142
|
+
* import bcrypt from "bcrypt";
|
|
143
|
+
*
|
|
144
|
+
* hooks: {
|
|
145
|
+
* hashPassword: (pw) => bcrypt.hash(pw, 12),
|
|
146
|
+
* verifyPassword: (pw, hash) => bcrypt.compare(pw, hash),
|
|
147
|
+
* }
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
hooks?: AuthHooks;
|
|
151
|
+
/**
|
|
152
|
+
* Enable magic link (passwordless email) authentication.
|
|
153
|
+
* Requires email to be configured.
|
|
154
|
+
*/
|
|
155
|
+
magicLink?: boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Opt-in httpOnly cookie mode for refresh tokens.
|
|
158
|
+
*
|
|
159
|
+
* When set, the refresh token is delivered as an `httpOnly`, `Secure`,
|
|
160
|
+
* `SameSite` cookie instead of in the JSON response body. This
|
|
161
|
+
* prevents XSS from stealing the long-lived refresh token.
|
|
162
|
+
*
|
|
163
|
+
* The access token remains in the JSON body so the client can use it
|
|
164
|
+
* in `Authorization: Bearer` headers for API calls.
|
|
165
|
+
*
|
|
166
|
+
* **Requires** `credentials: "include"` on client-side fetch calls to
|
|
167
|
+
* auth endpoints, and CORS must allow credentials (no `origin: "*"`).
|
|
168
|
+
*/
|
|
169
|
+
cookieAuth?: import("./auth").CookieAuthConfig;
|
|
170
|
+
}
|
|
171
|
+
/** @see RebaseBackendConfig.baas */
|
|
172
|
+
export interface BaasOptions {
|
|
173
|
+
/**
|
|
174
|
+
* What to do with introspected tables that have row-level security
|
|
175
|
+
* disabled.
|
|
176
|
+
*
|
|
177
|
+
* Such a table carries no authorization model. Every authenticated request
|
|
178
|
+
* runs as `rebase_user`, which is granted DML on the schema, so serving one
|
|
179
|
+
* hands every row to every logged-in user — the API would be an open door
|
|
180
|
+
* onto whatever the database happens to contain.
|
|
181
|
+
*
|
|
182
|
+
* - `"exclude"` (default) — do not serve it. Each excluded table is logged
|
|
183
|
+
* with the SQL to protect it. Secure by default, consistent with the rest
|
|
184
|
+
* of the driver, which fails a boot rather than serve unenforced requests.
|
|
185
|
+
* - `"serve"` — serve it anyway. Only sensible when every caller is already
|
|
186
|
+
* trusted, e.g. an internal service behind its own authorization.
|
|
187
|
+
*/
|
|
188
|
+
unprotectedTables?: "exclude" | "serve";
|
|
189
|
+
}
|
|
190
|
+
export interface RebaseBackendConfig {
|
|
191
|
+
collections?: CollectionConfig[];
|
|
192
|
+
collectionsDir?: string;
|
|
193
|
+
server: Server;
|
|
194
|
+
app: Hono<HonoEnv>;
|
|
195
|
+
basePath?: string;
|
|
196
|
+
/**
|
|
197
|
+
* How much of Rebase to run.
|
|
198
|
+
*
|
|
199
|
+
* - `"cms"` (default) — collections come from `collections`/`collectionsDir`
|
|
200
|
+
* and describe both the API and the admin UI. The schema editor is
|
|
201
|
+
* available outside production.
|
|
202
|
+
* - `"baas"` — no collection config at all. Collections are derived from the
|
|
203
|
+
* live database at boot (see `BackendBootstrapper.introspectCollections`),
|
|
204
|
+
* so every table is served over REST with nothing to define. The schema
|
|
205
|
+
* editor is off, since it exists to write collection files back to disk.
|
|
206
|
+
*
|
|
207
|
+
* Both modes serve the same control plane: auth, storage, realtime,
|
|
208
|
+
* backups, cron, functions and OpenAPI. Neither serves the admin SPA —
|
|
209
|
+
* that is the application's call, via `serveSPA`.
|
|
210
|
+
*/
|
|
211
|
+
mode?: "cms" | "baas";
|
|
212
|
+
/**
|
|
213
|
+
* Force the schema-editor routes on or off.
|
|
214
|
+
*
|
|
215
|
+
* Defaults to enabled when `collectionsDir` is set, outside production, in
|
|
216
|
+
* `cms` mode. The editor rewrites collection files, so it needs a
|
|
217
|
+
* `collectionsDir` to write to.
|
|
218
|
+
*/
|
|
219
|
+
schemaEditor?: boolean;
|
|
220
|
+
/** Options that only apply in `baas` mode. */
|
|
221
|
+
baas?: BaasOptions;
|
|
222
|
+
/**
|
|
223
|
+
* Declared data sources, shared with the frontend `<Rebase dataSources>`.
|
|
224
|
+
*
|
|
225
|
+
* Used to resolve each collection's engine (capabilities) and transport.
|
|
226
|
+
* Collections on a `direct`/`custom` transport are client-only: the backend
|
|
227
|
+
* still owns their schema/registry but does **not** generate server data
|
|
228
|
+
* routes for them. Server-mediated sources (the default) need no entry.
|
|
229
|
+
*/
|
|
230
|
+
dataSources?: DataSourceDefinition[];
|
|
231
|
+
/**
|
|
232
|
+
* Database bootstrappers.
|
|
233
|
+
*/
|
|
234
|
+
bootstrappers?: BackendBootstrapper[];
|
|
235
|
+
/**
|
|
236
|
+
* Database adapter.
|
|
237
|
+
*
|
|
238
|
+
* When set, this takes precedence over `bootstrappers`.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* import { createPostgresAdapter } from "@rebasepro/server-postgres";
|
|
243
|
+
* database: createPostgresAdapter({ connection: db, schema }),
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
database?: DatabaseAdapter;
|
|
247
|
+
logging?: {
|
|
248
|
+
level?: "error" | "warn" | "info" | "debug";
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* Authentication configuration.
|
|
252
|
+
*
|
|
253
|
+
* Accepts **either**:
|
|
254
|
+
* - `RebaseAuthConfig` — built-in configuration
|
|
255
|
+
* - `AuthAdapter` — pluggable adapter for external auth (Clerk, Auth0, etc.)
|
|
256
|
+
*
|
|
257
|
+
* When a plain config object is provided, the built-in adapter is created
|
|
258
|
+
* automatically from the bootstrapper's `initializeAuth()` result.
|
|
259
|
+
*/
|
|
260
|
+
auth?: RebaseAuthConfig | AuthAdapter;
|
|
261
|
+
/**
|
|
262
|
+
* Storage configuration. Accepts:
|
|
263
|
+
*
|
|
264
|
+
* - A `BackendStorageConfig` object (`{ type: 'local' | 's3' | 'gcs', ... }`)
|
|
265
|
+
* - A `StorageController` instance (for custom providers like Azure, etc.)
|
|
266
|
+
* - A `Record<string, ...>` of either, for multi-backend setups
|
|
267
|
+
*/
|
|
268
|
+
storage?: BackendStorageConfig | StorageController | Record<string, BackendStorageConfig | StorageController>;
|
|
269
|
+
/**
|
|
270
|
+
* Declared storage sources. Drives the client-side StorageSourceRegistry
|
|
271
|
+
* and the transport distinction (server vs direct).
|
|
272
|
+
*
|
|
273
|
+
* Server-backed sources are auto-derived from the `storage` map — you
|
|
274
|
+
* only need explicit entries for "direct" transport sources (e.g.
|
|
275
|
+
* external storage) that the backend does not proxy.
|
|
276
|
+
*/
|
|
277
|
+
storageSources?: import("@rebasepro/types").StorageSourceDefinition[];
|
|
278
|
+
/**
|
|
279
|
+
* Entity history / audit-log configuration.
|
|
280
|
+
*
|
|
281
|
+
* - `true` — enable history with default settings
|
|
282
|
+
* - `{ retention?: number }` — enable with optional retention period (days)
|
|
283
|
+
*/
|
|
284
|
+
history?: HistoryConfig;
|
|
285
|
+
enableSwagger?: boolean;
|
|
286
|
+
functionsDir?: string;
|
|
287
|
+
cronsDir?: string;
|
|
288
|
+
/**
|
|
289
|
+
* Enable/disable database persistence for cron job execution logs.
|
|
290
|
+
* When set to false, cron jobs will run but logs will not be persisted to the database.
|
|
291
|
+
* Default: true.
|
|
292
|
+
*/
|
|
293
|
+
cronPersistence?: boolean;
|
|
294
|
+
/**
|
|
295
|
+
* Maximum request body size in bytes for API routes (default: 10MB).
|
|
296
|
+
* Set to 0 to disable the global limit entirely.
|
|
297
|
+
*
|
|
298
|
+
* Note: Storage upload routes use their own limit from the storage config's
|
|
299
|
+
* `maxFileSize` property (default: 50MB), which takes precedence over this.
|
|
300
|
+
*/
|
|
301
|
+
maxBodySize?: number;
|
|
302
|
+
/**
|
|
303
|
+
* CSRF protection configuration. **Opt-in** — disabled by default.
|
|
304
|
+
*
|
|
305
|
+
* BaaS APIs are consumed by mobile apps, SPAs on different domains,
|
|
306
|
+
* and CLI tools, so CSRF is intentionally not enabled unless you
|
|
307
|
+
* explicitly configure it with allowed origins.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* csrf: { origin: ["https://myapp.com", "https://admin.myapp.com"] }
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
314
|
+
csrf?: {
|
|
315
|
+
/** Allowed origins for CSRF validation. */
|
|
316
|
+
origin: string | string[] | ((origin: string) => boolean);
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Global lifecycle callbacks applied to every collection.
|
|
320
|
+
*
|
|
321
|
+
* Same type as per-collection `callbacks` — fires on **every** data path
|
|
322
|
+
* (REST API, WebSocket / realtime, server-side `rebase.data`).
|
|
323
|
+
*
|
|
324
|
+
* Execution order: global callbacks → collection callbacks → property callbacks.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* callbacks: {
|
|
329
|
+
* afterRead({ row, collection }) {
|
|
330
|
+
* console.log(`Read ${collection.slug}/${row.id}`);
|
|
331
|
+
* return row;
|
|
332
|
+
* }
|
|
333
|
+
* }
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
callbacks?: CollectionCallbacks;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Type guard to detect whether the `auth` config is an `AuthAdapter`
|
|
340
|
+
* (has a `verifyRequest` method) vs a plain `RebaseAuthConfig` (plain object).
|
|
341
|
+
*/
|
|
342
|
+
export declare function isAuthAdapter(auth: RebaseAuthConfig | AuthAdapter): auth is AuthAdapter;
|
|
343
|
+
/**
|
|
344
|
+
* Type guard to detect whether `database` is a `DatabaseAdapter`.
|
|
345
|
+
*/
|
|
346
|
+
export declare function isDatabaseAdapter(db: unknown): db is DatabaseAdapter;
|
|
347
|
+
export interface RebaseBackendInstance {
|
|
348
|
+
driverRegistry: DriverRegistry;
|
|
349
|
+
driver: DataDriver;
|
|
350
|
+
realtimeServices: Record<string, RealtimeProvider>;
|
|
351
|
+
realtimeService: RealtimeProvider;
|
|
352
|
+
auth?: BootstrappedAuth;
|
|
353
|
+
history?: {
|
|
354
|
+
historyService: import("./history/history-routes").HistoryService;
|
|
355
|
+
};
|
|
356
|
+
storageRegistry?: StorageRegistry;
|
|
357
|
+
storageController?: StorageController;
|
|
358
|
+
collectionRegistry: BackendCollectionRegistry;
|
|
359
|
+
cronScheduler?: import("./cron").CronScheduler;
|
|
360
|
+
/**
|
|
361
|
+
* Deep health check that verifies database connectivity.
|
|
362
|
+
* Returns latency and component status.
|
|
363
|
+
*/
|
|
364
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
365
|
+
/**
|
|
366
|
+
* Graceful shutdown helper for the BaaS instance.
|
|
367
|
+
* Stops the cron scheduler and closes the HTTP server, allowing
|
|
368
|
+
* in-flight requests to drain within the given timeout.
|
|
369
|
+
*
|
|
370
|
+
* @param timeoutMs - Maximum time (ms) to wait for drain before force-exit (default: 15000).
|
|
371
|
+
* Pass 0 to skip the force-exit timer (useful in tests).
|
|
372
|
+
*/
|
|
373
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
374
|
+
}
|
|
375
|
+
export declare function initializeRebaseBackend(config: RebaseBackendConfig): Promise<RebaseBackendInstance>;
|