@rebasepro/server-core 0.7.0 → 0.9.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.
- package/README.md +2 -2
- 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/{src/api/rest/index.ts → dist/api/rest/index.d.ts} +0 -1
- 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 +79 -0
- package/dist/auth/admin-users-route.d.ts +28 -0
- package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
- package/{src/auth/api-keys/api-key-permission-guard.ts → dist/auth/api-keys/api-key-permission-guard.d.ts} +2 -34
- 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/{src/auth/api-keys/api-key-types.ts → dist/auth/api-keys/api-key-types.d.ts} +0 -6
- package/{src/auth/api-keys/index.ts → dist/auth/api-keys/index.d.ts} +2 -22
- package/dist/auth/apple-oauth.d.ts +30 -0
- package/{src/auth/auth-hooks.ts → dist/auth/auth-hooks.d.ts} +15 -73
- 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/{src/auth/crypto-utils.ts → dist/auth/crypto-utils.d.ts} +1 -16
- 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/{src/auth/index.ts → dist/auth/index.d.ts} +4 -22
- package/{src/auth/interfaces.ts → dist/auth/interfaces.d.ts} +20 -89
- 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/collections/BackendCollectionRegistry.d.ts +13 -0
- package/dist/collections/loader.d.ts +5 -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/{src/cron/index.ts → dist/cron/index.d.ts} +1 -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/{src/email/types.ts → dist/email/types.d.ts} +40 -36
- 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/{src/functions/index.ts → dist/functions/index.d.ts} +2 -0
- package/dist/history/history-routes.d.ts +23 -0
- package/{src/history/index.ts → dist/history/index.d.ts} +0 -1
- package/dist/index.d.ts +35 -0
- package/dist/index.es.js +18184 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +48629 -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 +344 -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-B5WkP1Rv.js +24778 -0
- package/dist/src-B5WkP1Rv.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/{src/storage/index.ts → dist/storage/index.d.ts} +6 -21
- 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/{src/storage/types.ts → dist/storage/types.d.ts} +32 -38
- 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/{src/utils/sql.ts → dist/utils/sql.d.ts} +5 -16
- package/package.json +49 -22
- package/coverage/clover.xml +0 -3739
- package/coverage/coverage-final.json +0 -31
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -266
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -210
- package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +0 -952
- package/coverage/lcov-report/src/api/errors.ts.html +0 -472
- package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +0 -1069
- package/coverage/lcov-report/src/api/graphql/index.html +0 -116
- package/coverage/lcov-report/src/api/index.html +0 -176
- package/coverage/lcov-report/src/api/openapi-generator.ts.html +0 -565
- package/coverage/lcov-report/src/api/rest/api-generator.ts.html +0 -994
- package/coverage/lcov-report/src/api/rest/index.html +0 -131
- package/coverage/lcov-report/src/api/rest/query-parser.ts.html +0 -550
- package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +0 -202
- package/coverage/lcov-report/src/api/server.ts.html +0 -823
- package/coverage/lcov-report/src/auth/admin-routes.ts.html +0 -973
- package/coverage/lcov-report/src/auth/index.html +0 -176
- package/coverage/lcov-report/src/auth/jwt.ts.html +0 -574
- package/coverage/lcov-report/src/auth/middleware.ts.html +0 -745
- package/coverage/lcov-report/src/auth/password.ts.html +0 -310
- package/coverage/lcov-report/src/auth/services.ts.html +0 -2074
- package/coverage/lcov-report/src/collections/index.html +0 -116
- package/coverage/lcov-report/src/collections/loader.ts.html +0 -232
- package/coverage/lcov-report/src/db/auth-schema.ts.html +0 -523
- package/coverage/lcov-report/src/db/data-transformer.ts.html +0 -1753
- package/coverage/lcov-report/src/db/entityService.ts.html +0 -700
- package/coverage/lcov-report/src/db/index.html +0 -146
- package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +0 -4048
- package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +0 -883
- package/coverage/lcov-report/src/db/services/RelationService.ts.html +0 -3121
- package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +0 -442
- package/coverage/lcov-report/src/db/services/index.html +0 -176
- package/coverage/lcov-report/src/db/services/index.ts.html +0 -124
- package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +0 -1960
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/services/driver-registry.ts.html +0 -631
- package/coverage/lcov-report/src/services/index.html +0 -131
- package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +0 -3025
- package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +0 -1189
- package/coverage/lcov-report/src/storage/S3StorageController.ts.html +0 -970
- package/coverage/lcov-report/src/storage/index.html +0 -161
- package/coverage/lcov-report/src/storage/storage-registry.ts.html +0 -646
- package/coverage/lcov-report/src/storage/types.ts.html +0 -451
- package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +0 -3082
- package/coverage/lcov-report/src/utils/index.html +0 -116
- package/coverage/lcov.info +0 -7179
- package/jest.config.cjs +0 -19
- package/src/api/ast-schema-editor.ts +0 -289
- package/src/api/collections_for_test/callbacks_test_collection.ts +0 -61
- package/src/api/errors.ts +0 -278
- package/src/api/graphql/graphql-schema-generator.ts +0 -383
- package/src/api/graphql/index.ts +0 -2
- package/src/api/index.ts +0 -11
- package/src/api/logs-routes.ts +0 -132
- package/src/api/openapi-generator.ts +0 -727
- package/src/api/rest/api-generator-count.test.ts +0 -126
- package/src/api/rest/api-generator.ts +0 -747
- package/src/api/rest/query-parser.ts +0 -300
- package/src/api/schema-editor-routes.ts +0 -41
- package/src/api/server.ts +0 -271
- package/src/api/types.ts +0 -104
- package/src/auth/adapter-middleware.ts +0 -114
- package/src/auth/admin-roles-route.ts +0 -36
- package/src/auth/admin-user-ops.ts +0 -236
- package/src/auth/admin-users-route.ts +0 -302
- package/src/auth/api-keys/api-key-middleware.ts +0 -133
- package/src/auth/api-keys/api-key-routes.ts +0 -193
- package/src/auth/api-keys/api-key-store.ts +0 -340
- package/src/auth/apple-oauth.ts +0 -122
- package/src/auth/bitbucket-oauth.ts +0 -84
- package/src/auth/builtin-auth-adapter.ts +0 -380
- package/src/auth/custom-auth-adapter.ts +0 -86
- package/src/auth/discord-oauth.ts +0 -85
- package/src/auth/facebook-oauth.ts +0 -74
- package/src/auth/github-oauth.ts +0 -112
- package/src/auth/gitlab-oauth.ts +0 -72
- package/src/auth/google-oauth.ts +0 -223
- package/src/auth/jwt.ts +0 -208
- package/src/auth/linkedin-oauth.ts +0 -83
- package/src/auth/magic-link-routes.ts +0 -167
- package/src/auth/mfa-crypto.ts +0 -91
- package/src/auth/mfa-routes.ts +0 -323
- package/src/auth/mfa.ts +0 -161
- package/src/auth/microsoft-oauth.ts +0 -90
- package/src/auth/middleware.ts +0 -369
- package/src/auth/password.ts +0 -77
- package/src/auth/rate-limiter.ts +0 -225
- package/src/auth/reset-password-admin.ts +0 -160
- package/src/auth/rls-scope.ts +0 -58
- package/src/auth/routes.ts +0 -802
- package/src/auth/session-routes.ts +0 -353
- package/src/auth/slack-oauth.ts +0 -73
- package/src/auth/spotify-oauth.ts +0 -69
- package/src/auth/twitter-oauth.ts +0 -128
- package/src/collections/BackendCollectionRegistry.ts +0 -20
- package/src/collections/loader.ts +0 -50
- package/src/cron/cron-loader.ts +0 -84
- package/src/cron/cron-routes.test.ts +0 -265
- package/src/cron/cron-routes.ts +0 -85
- package/src/cron/cron-scheduler.test.ts +0 -559
- package/src/cron/cron-scheduler.ts +0 -581
- package/src/cron/cron-store.ts +0 -166
- package/src/db/interfaces.ts +0 -60
- package/src/email/index.ts +0 -19
- package/src/email/smtp-email-service.ts +0 -123
- package/src/email/templates.ts +0 -470
- package/src/env.ts +0 -227
- package/src/functions/function-loader.ts +0 -116
- package/src/functions/function-routes.ts +0 -31
- package/src/history/history-routes.ts +0 -129
- package/src/index.ts +0 -70
- package/src/init/docs.ts +0 -47
- package/src/init/health.ts +0 -37
- package/src/init/middlewares.ts +0 -61
- package/src/init/shutdown.ts +0 -56
- package/src/init/storage.ts +0 -57
- package/src/init.ts +0 -1041
- package/src/serve-spa.ts +0 -89
- package/src/services/driver-registry.ts +0 -183
- package/src/services/routed-realtime-service.ts +0 -113
- package/src/services/webhook-service.ts +0 -155
- package/src/singleton.ts +0 -70
- package/src/storage/LocalStorageController.ts +0 -389
- package/src/storage/S3StorageController.ts +0 -300
- package/src/storage/image-transform.ts +0 -218
- package/src/storage/routes.ts +0 -368
- package/src/storage/storage-registry.ts +0 -188
- package/src/storage/tus-handler.ts +0 -315
- package/src/types/index.ts +0 -27
- package/src/utils/dev-port.ts +0 -196
- package/src/utils/logger.ts +0 -143
- package/src/utils/logging.ts +0 -40
- package/src/utils/request-id.ts +0 -40
- package/src/utils/request-logger.ts +0 -72
- package/test/api-generator.test.ts +0 -588
- package/test/api-key-permission-guard.test.ts +0 -144
- package/test/ast-schema-editor.test.ts +0 -89
- package/test/auth-middleware-hono.test.ts +0 -556
- package/test/auth-routes.test.ts +0 -1098
- package/test/backend-hooks-data.test.ts +0 -477
- package/test/custom-auth-adapter.test.ts +0 -189
- package/test/driver-registry.test.ts +0 -282
- package/test/email-templates.test.ts +0 -174
- package/test/env.test.ts +0 -128
- package/test/error-propagation.test.ts +0 -226
- package/test/errors-hono.test.ts +0 -133
- package/test/errors.test.ts +0 -155
- package/test/function-loader.test.ts +0 -127
- package/test/graphql-schema-generator.test.ts +0 -554
- package/test/jwt-security.test.ts +0 -182
- package/test/jwt.test.ts +0 -326
- package/test/mfa.test.ts +0 -197
- package/test/middleware.test.ts +0 -305
- package/test/multi-datasource-routing.test.ts +0 -113
- package/test/password.test.ts +0 -165
- package/test/query-parser.test.ts +0 -233
- package/test/rate-limiter.test.ts +0 -102
- package/test/reset-password-admin.test.ts +0 -113
- package/test/routed-realtime-service.test.ts +0 -86
- package/test/safe-compare.test.ts +0 -66
- package/test/singleton.test.ts +0 -59
- package/test/smtp-email-service.test.ts +0 -169
- package/test/storage-local.test.ts +0 -271
- package/test/storage-registry.test.ts +0 -282
- package/test/storage-routes.test.ts +0 -222
- package/test/storage-s3.test.ts +0 -304
- package/test/transform-auth-response.test.ts +0 -305
- package/test/webhook-service.test.ts +0 -260
- package/tsconfig.json +0 -54
- package/tsconfig.prod.json +0 -23
- package/vite.config.ts +0 -86
|
@@ -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,344 @@
|
|
|
1
|
+
import { AuthAdapter, BackendBootstrapper, BootstrappedAuth, DatabaseAdapter, DataDriver, DataSourceDefinition, CollectionCallbacks, CollectionConfig, HealthCheckResult, HistoryConfig, RealtimeProvider, SecurityRule } 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-core`
|
|
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-core";
|
|
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
|
+
export interface RebaseBackendConfig {
|
|
172
|
+
collections?: CollectionConfig[];
|
|
173
|
+
collectionsDir?: string;
|
|
174
|
+
server: Server;
|
|
175
|
+
app: Hono<HonoEnv>;
|
|
176
|
+
basePath?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Declared data sources, shared with the frontend `<Rebase dataSources>`.
|
|
179
|
+
*
|
|
180
|
+
* Used to resolve each collection's engine (capabilities) and transport.
|
|
181
|
+
* Collections on a `direct`/`custom` transport are client-only: the backend
|
|
182
|
+
* still owns their schema/registry but does **not** generate server data
|
|
183
|
+
* routes for them. Server-mediated sources (the default) need no entry.
|
|
184
|
+
*/
|
|
185
|
+
dataSources?: DataSourceDefinition[];
|
|
186
|
+
/**
|
|
187
|
+
* Database bootstrappers.
|
|
188
|
+
*/
|
|
189
|
+
bootstrappers?: BackendBootstrapper[];
|
|
190
|
+
/**
|
|
191
|
+
* Database adapter.
|
|
192
|
+
*
|
|
193
|
+
* When set, this takes precedence over `bootstrappers`.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* import { createPostgresAdapter } from "@rebasepro/server-postgresql";
|
|
198
|
+
* database: createPostgresAdapter({ connection: db, schema }),
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
database?: DatabaseAdapter;
|
|
202
|
+
logging?: {
|
|
203
|
+
level?: "error" | "warn" | "info" | "debug";
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* Authentication configuration.
|
|
207
|
+
*
|
|
208
|
+
* Accepts **either**:
|
|
209
|
+
* - `RebaseAuthConfig` — built-in configuration
|
|
210
|
+
* - `AuthAdapter` — pluggable adapter for external auth (Clerk, Auth0, etc.)
|
|
211
|
+
*
|
|
212
|
+
* When a plain config object is provided, the built-in adapter is created
|
|
213
|
+
* automatically from the bootstrapper's `initializeAuth()` result.
|
|
214
|
+
*/
|
|
215
|
+
auth?: RebaseAuthConfig | AuthAdapter;
|
|
216
|
+
/**
|
|
217
|
+
* Storage configuration. Accepts:
|
|
218
|
+
*
|
|
219
|
+
* - A `BackendStorageConfig` object (`{ type: 'local' | 's3' | 'gcs', ... }`)
|
|
220
|
+
* - A `StorageController` instance (for custom providers like Azure, etc.)
|
|
221
|
+
* - A `Record<string, ...>` of either, for multi-backend setups
|
|
222
|
+
*/
|
|
223
|
+
storage?: BackendStorageConfig | StorageController | Record<string, BackendStorageConfig | StorageController>;
|
|
224
|
+
/**
|
|
225
|
+
* Declared storage sources. Drives the client-side StorageSourceRegistry
|
|
226
|
+
* and the transport distinction (server vs direct).
|
|
227
|
+
*
|
|
228
|
+
* Server-backed sources are auto-derived from the `storage` map — you
|
|
229
|
+
* only need explicit entries for "direct" transport sources (e.g.
|
|
230
|
+
* external storage) that the backend does not proxy.
|
|
231
|
+
*/
|
|
232
|
+
storageSources?: import("@rebasepro/types").StorageSourceDefinition[];
|
|
233
|
+
/**
|
|
234
|
+
* Entity history / audit-log configuration.
|
|
235
|
+
*
|
|
236
|
+
* - `true` — enable history with default settings
|
|
237
|
+
* - `{ retention?: number }` — enable with optional retention period (days)
|
|
238
|
+
*/
|
|
239
|
+
history?: HistoryConfig;
|
|
240
|
+
/**
|
|
241
|
+
* Default security rules applied to any collection that does not define
|
|
242
|
+
* its own `securityRules`. Opt-in — if not set, collections without
|
|
243
|
+
* explicit rules remain unrestricted (beyond `requireAuth`).
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```ts
|
|
247
|
+
* defaultSecurityRules: [
|
|
248
|
+
* { operation: "select", access: "public" },
|
|
249
|
+
* { operations: ["insert", "update", "delete"], roles: ["admin"] }
|
|
250
|
+
* ]
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
defaultSecurityRules?: SecurityRule[];
|
|
254
|
+
enableSwagger?: boolean;
|
|
255
|
+
functionsDir?: string;
|
|
256
|
+
cronsDir?: string;
|
|
257
|
+
/**
|
|
258
|
+
* Enable/disable database persistence for cron job execution logs.
|
|
259
|
+
* When set to false, cron jobs will run but logs will not be persisted to the database.
|
|
260
|
+
* Default: true.
|
|
261
|
+
*/
|
|
262
|
+
cronPersistence?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Maximum request body size in bytes for API routes (default: 10MB).
|
|
265
|
+
* Set to 0 to disable the global limit entirely.
|
|
266
|
+
*
|
|
267
|
+
* Note: Storage upload routes use their own limit from the storage config's
|
|
268
|
+
* `maxFileSize` property (default: 50MB), which takes precedence over this.
|
|
269
|
+
*/
|
|
270
|
+
maxBodySize?: number;
|
|
271
|
+
/**
|
|
272
|
+
* CSRF protection configuration. **Opt-in** — disabled by default.
|
|
273
|
+
*
|
|
274
|
+
* BaaS APIs are consumed by mobile apps, SPAs on different domains,
|
|
275
|
+
* and CLI tools, so CSRF is intentionally not enabled unless you
|
|
276
|
+
* explicitly configure it with allowed origins.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* csrf: { origin: ["https://myapp.com", "https://admin.myapp.com"] }
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
csrf?: {
|
|
284
|
+
/** Allowed origins for CSRF validation. */
|
|
285
|
+
origin: string | string[] | ((origin: string) => boolean);
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Global lifecycle callbacks applied to every collection.
|
|
289
|
+
*
|
|
290
|
+
* Same type as per-collection `callbacks` — fires on **every** data path
|
|
291
|
+
* (REST API, WebSocket / realtime, server-side `rebase.data`).
|
|
292
|
+
*
|
|
293
|
+
* Execution order: global callbacks → collection callbacks → property callbacks.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```ts
|
|
297
|
+
* callbacks: {
|
|
298
|
+
* afterRead({ row, collection }) {
|
|
299
|
+
* console.log(`Read ${collection.slug}/${row.id}`);
|
|
300
|
+
* return row;
|
|
301
|
+
* }
|
|
302
|
+
* }
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
callbacks?: CollectionCallbacks;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Type guard to detect whether the `auth` config is an `AuthAdapter`
|
|
309
|
+
* (has a `verifyRequest` method) vs a plain `RebaseAuthConfig` (plain object).
|
|
310
|
+
*/
|
|
311
|
+
export declare function isAuthAdapter(auth: RebaseAuthConfig | AuthAdapter): auth is AuthAdapter;
|
|
312
|
+
/**
|
|
313
|
+
* Type guard to detect whether `database` is a `DatabaseAdapter`.
|
|
314
|
+
*/
|
|
315
|
+
export declare function isDatabaseAdapter(db: unknown): db is DatabaseAdapter;
|
|
316
|
+
export interface RebaseBackendInstance {
|
|
317
|
+
driverRegistry: DriverRegistry;
|
|
318
|
+
driver: DataDriver;
|
|
319
|
+
realtimeServices: Record<string, RealtimeProvider>;
|
|
320
|
+
realtimeService: RealtimeProvider;
|
|
321
|
+
auth?: BootstrappedAuth;
|
|
322
|
+
history?: {
|
|
323
|
+
historyService: import("./history/history-routes").HistoryService;
|
|
324
|
+
};
|
|
325
|
+
storageRegistry?: StorageRegistry;
|
|
326
|
+
storageController?: StorageController;
|
|
327
|
+
collectionRegistry: BackendCollectionRegistry;
|
|
328
|
+
cronScheduler?: import("./cron").CronScheduler;
|
|
329
|
+
/**
|
|
330
|
+
* Deep health check that verifies database connectivity.
|
|
331
|
+
* Returns latency and component status.
|
|
332
|
+
*/
|
|
333
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
334
|
+
/**
|
|
335
|
+
* Graceful shutdown helper for the BaaS instance.
|
|
336
|
+
* Stops the cron scheduler and closes the HTTP server, allowing
|
|
337
|
+
* in-flight requests to drain within the given timeout.
|
|
338
|
+
*
|
|
339
|
+
* @param timeoutMs - Maximum time (ms) to wait for drain before force-exit (default: 15000).
|
|
340
|
+
* Pass 0 to skip the force-exit timer (useful in tests).
|
|
341
|
+
*/
|
|
342
|
+
shutdown(timeoutMs?: number): Promise<void>;
|
|
343
|
+
}
|
|
344
|
+
export declare function initializeRebaseBackend(config: RebaseBackendConfig): Promise<RebaseBackendInstance>;
|