@rebasepro/server-core 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/build-errors.txt +52 -0
  2. package/dist/api/ast-schema-editor.d.ts +21 -0
  3. package/dist/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
  4. package/dist/api/errors.d.ts +53 -0
  5. package/dist/api/graphql/graphql-schema-generator.d.ts +44 -0
  6. package/dist/api/graphql/index.d.ts +1 -0
  7. package/dist/api/index.d.ts +9 -0
  8. package/dist/api/logs-routes.d.ts +37 -0
  9. package/dist/api/openapi-generator.d.ts +16 -0
  10. package/dist/api/rest/api-generator.d.ts +76 -0
  11. package/dist/api/rest/index.d.ts +1 -0
  12. package/dist/api/rest/query-parser.d.ts +8 -0
  13. package/dist/api/schema-editor-routes.d.ts +3 -0
  14. package/dist/api/server.d.ts +40 -0
  15. package/dist/api/types.d.ts +104 -0
  16. package/dist/auth/adapter-middleware.d.ts +43 -0
  17. package/dist/auth/admin-roles-route.d.ts +18 -0
  18. package/dist/auth/admin-user-ops.d.ts +79 -0
  19. package/dist/auth/admin-users-route.d.ts +28 -0
  20. package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
  21. package/dist/auth/api-keys/api-key-permission-guard.d.ts +32 -0
  22. package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
  23. package/dist/auth/api-keys/api-key-store.d.ts +35 -0
  24. package/dist/auth/api-keys/api-key-types.d.ts +96 -0
  25. package/dist/auth/api-keys/index.d.ts +17 -0
  26. package/dist/auth/apple-oauth.d.ts +30 -0
  27. package/dist/auth/auth-hooks.d.ts +242 -0
  28. package/dist/auth/bitbucket-oauth.d.ts +11 -0
  29. package/dist/auth/builtin-auth-adapter.d.ts +51 -0
  30. package/dist/auth/crypto-utils.d.ts +16 -0
  31. package/dist/auth/custom-auth-adapter.d.ts +39 -0
  32. package/dist/auth/discord-oauth.d.ts +14 -0
  33. package/dist/auth/facebook-oauth.d.ts +14 -0
  34. package/dist/auth/github-oauth.d.ts +15 -0
  35. package/dist/auth/gitlab-oauth.d.ts +13 -0
  36. package/dist/auth/google-oauth.d.ts +47 -0
  37. package/dist/auth/index.d.ts +37 -0
  38. package/dist/auth/interfaces.d.ts +431 -0
  39. package/dist/auth/jwt.d.ts +55 -0
  40. package/dist/auth/linkedin-oauth.d.ts +18 -0
  41. package/dist/auth/magic-link-routes.d.ts +30 -0
  42. package/dist/auth/mfa-crypto.d.ts +23 -0
  43. package/dist/auth/mfa-routes.d.ts +7 -0
  44. package/dist/auth/mfa.d.ts +49 -0
  45. package/dist/auth/microsoft-oauth.d.ts +16 -0
  46. package/dist/auth/middleware.d.ts +113 -0
  47. package/dist/auth/password.d.ts +22 -0
  48. package/dist/auth/rate-limiter.d.ts +50 -0
  49. package/dist/auth/reset-password-admin.d.ts +29 -0
  50. package/dist/auth/rls-scope.d.ts +31 -0
  51. package/dist/auth/routes.d.ts +35 -0
  52. package/dist/auth/session-routes.d.ts +27 -0
  53. package/dist/auth/slack-oauth.d.ts +12 -0
  54. package/dist/auth/spotify-oauth.d.ts +12 -0
  55. package/dist/auth/twitter-oauth.d.ts +18 -0
  56. package/dist/backend-CIxN4FVm.js +15 -0
  57. package/dist/backend-CIxN4FVm.js.map +1 -0
  58. package/dist/base64-js-C_frYBkI.js +1687 -0
  59. package/dist/base64-js-C_frYBkI.js.map +1 -0
  60. package/dist/chunk-Dze3rakg.js +42 -0
  61. package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
  62. package/dist/collections/loader.d.ts +5 -0
  63. package/dist/cron/cron-loader.d.ts +17 -0
  64. package/dist/cron/cron-routes.d.ts +14 -0
  65. package/dist/cron/cron-scheduler.d.ts +106 -0
  66. package/dist/cron/cron-store.d.ts +32 -0
  67. package/dist/cron/index.d.ts +6 -0
  68. package/dist/db/interfaces.d.ts +18 -0
  69. package/dist/dist-DMO-zF6D.js +832 -0
  70. package/dist/dist-DMO-zF6D.js.map +1 -0
  71. package/dist/email/index.d.ts +6 -0
  72. package/dist/email/smtp-email-service.d.ts +25 -0
  73. package/dist/email/templates.d.ts +50 -0
  74. package/dist/email/types.d.ts +126 -0
  75. package/dist/env.d.ts +102 -0
  76. package/dist/from-VbwD7xRf.js +3849 -0
  77. package/dist/from-VbwD7xRf.js.map +1 -0
  78. package/dist/functions/define-function.d.ts +50 -0
  79. package/dist/functions/function-loader.d.ts +17 -0
  80. package/dist/functions/function-routes.d.ts +10 -0
  81. package/dist/functions/index.d.ts +5 -0
  82. package/dist/history/history-routes.d.ts +23 -0
  83. package/dist/history/index.d.ts +1 -0
  84. package/dist/index.d.ts +31 -0
  85. package/dist/index.es.js +61322 -0
  86. package/dist/index.es.js.map +1 -0
  87. package/dist/index.umd.js +103633 -0
  88. package/dist/index.umd.js.map +1 -0
  89. package/dist/init/docs.d.ts +4 -0
  90. package/dist/init/health.d.ts +2 -0
  91. package/dist/init/middlewares.d.ts +10 -0
  92. package/dist/init/shutdown.d.ts +11 -0
  93. package/dist/init/storage.d.ts +5 -0
  94. package/dist/init.d.ts +314 -0
  95. package/dist/jws-BqRRaK11.js +616 -0
  96. package/dist/jws-BqRRaK11.js.map +1 -0
  97. package/dist/jwt-BETC8a1J.js +3560 -0
  98. package/dist/jwt-BETC8a1J.js.map +1 -0
  99. package/dist/logger-BYU66ENZ.js +94 -0
  100. package/dist/logger-BYU66ENZ.js.map +1 -0
  101. package/dist/ms-BeBSuOXN.js +125 -0
  102. package/dist/ms-BeBSuOXN.js.map +1 -0
  103. package/dist/multipart-parser-CedBDOeC.js +299 -0
  104. package/dist/multipart-parser-CedBDOeC.js.map +1 -0
  105. package/dist/serve-spa.d.ts +30 -0
  106. package/dist/services/driver-registry.d.ts +78 -0
  107. package/dist/services/routed-realtime-service.d.ts +43 -0
  108. package/dist/services/webhook-service.d.ts +29 -0
  109. package/dist/singleton.d.ts +35 -0
  110. package/dist/src-CB2PIpBe.js +1182 -0
  111. package/dist/src-CB2PIpBe.js.map +1 -0
  112. package/dist/src-DjzOT1kG.js +29746 -0
  113. package/dist/src-DjzOT1kG.js.map +1 -0
  114. package/dist/storage/GCSStorageController.d.ts +43 -0
  115. package/dist/storage/LocalStorageController.d.ts +46 -0
  116. package/dist/storage/S3StorageController.d.ts +36 -0
  117. package/dist/storage/image-transform.d.ts +50 -0
  118. package/dist/storage/index.d.ts +31 -0
  119. package/dist/storage/routes.d.ts +70 -0
  120. package/dist/storage/storage-registry.d.ts +78 -0
  121. package/dist/storage/tus-handler.d.ts +53 -0
  122. package/dist/storage/types.d.ts +128 -0
  123. package/dist/types/index.d.ts +11 -0
  124. package/dist/utils/dev-port.d.ts +37 -0
  125. package/dist/utils/logger.d.ts +31 -0
  126. package/dist/utils/logging.d.ts +9 -0
  127. package/dist/utils/request-id.d.ts +4 -0
  128. package/dist/utils/request-logger.d.ts +19 -0
  129. package/dist/utils/sql.d.ts +27 -0
  130. package/package.json +22 -14
  131. package/src/api/graphql/graphql-schema-generator.ts +5 -5
  132. package/src/api/openapi-generator.ts +2 -2
  133. package/src/api/rest/api-generator.ts +44 -123
  134. package/src/api/rest/query-parser.ts +6 -23
  135. package/src/api/types.ts +2 -2
  136. package/src/auth/auth-hooks.ts +1 -1
  137. package/src/auth/builtin-auth-adapter.ts +1 -2
  138. package/src/auth/interfaces.ts +11 -2
  139. package/src/auth/middleware.ts +4 -4
  140. package/src/auth/routes.ts +1 -2
  141. package/src/functions/define-function.ts +59 -0
  142. package/src/functions/function-loader.ts +16 -0
  143. package/src/functions/index.ts +2 -0
  144. package/src/index.ts +70 -37
  145. package/src/init.ts +78 -21
  146. package/src/storage/GCSStorageController.ts +334 -0
  147. package/src/storage/index.ts +9 -3
  148. package/src/storage/routes.ts +191 -23
  149. package/src/storage/tus-handler.ts +16 -4
  150. package/src/storage/types.ts +25 -3
  151. package/test/api-generator.test.ts +1 -1
  152. package/test/auth-config-types.test.ts +40 -0
  153. package/test/define-function.test.ts +45 -0
  154. package/test/storage-routes.test.ts +160 -0
  155. package/test/backend-hooks-data.test.ts +0 -477
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Driver Registry
3
+ *
4
+ * Manages multiple driver delegates for Rebase backend.
5
+ * Allows different databases for different collections.
6
+ *
7
+ * Usage:
8
+ * - Single DB: Pass a single DataDriver → maps to "(default)"
9
+ * - Multiple DBs: Pass a map of { dbId: DataDriver }
10
+ * - Collections use `databaseId` property to specify which driver to use
11
+ * - Collections without `databaseId` fallback to "(default)"
12
+ */
13
+ import { DataDriver } from "@rebasepro/types";
14
+ /**
15
+ * The default driver identifier used when:
16
+ * - A single driver is provided (not a map)
17
+ * - A collection doesn't specify a databaseId
18
+ */
19
+ export declare const DEFAULT_DRIVER_ID = "(default)";
20
+ /**
21
+ * Registry for managing multiple driver delegates
22
+ */
23
+ export interface DriverRegistry {
24
+ /**
25
+ * Register a driver delegate with an ID
26
+ * @param id - Unique identifier for this driver (e.g., "analytics", "users")
27
+ * @param delegate - The DataDriver instance
28
+ */
29
+ register(id: string, delegate: DataDriver): void;
30
+ /**
31
+ * Get the default driver delegate (id = "(default)")
32
+ * @throws Error if no default driver is registered
33
+ */
34
+ getDefault(): DataDriver;
35
+ /**
36
+ * Get a driver delegate by ID
37
+ * @param id - Driver identifier, or undefined/null for default
38
+ * @returns The DataDriver, or undefined if not found
39
+ */
40
+ get(id: string | undefined | null): DataDriver | undefined;
41
+ /**
42
+ * Get a driver delegate by ID, with fallback to default
43
+ * @param id - Driver identifier, or undefined/null for default
44
+ * @returns The DataDriver (falls back to default if id not found)
45
+ * @throws Error if neither the specified nor default driver exists
46
+ */
47
+ getOrDefault(id: string | undefined | null): DataDriver;
48
+ /**
49
+ * Check if a driver with the given ID exists
50
+ */
51
+ has(id: string): boolean;
52
+ /**
53
+ * List all registered driver IDs
54
+ */
55
+ list(): string[];
56
+ /**
57
+ * Get the number of registered drivers
58
+ */
59
+ size(): number;
60
+ }
61
+ /**
62
+ * Default implementation of DriverRegistry
63
+ */
64
+ export declare class DefaultDriverRegistry implements DriverRegistry {
65
+ private delegates;
66
+ /**
67
+ * Create a DriverRegistry from either a single delegate or a map
68
+ * @param input - Single DataDriver (maps to "(default)") or Record<string, DataDriver>
69
+ */
70
+ static create(input: DataDriver | Record<string, DataDriver>): DefaultDriverRegistry;
71
+ register(id: string, delegate: DataDriver): void;
72
+ getDefault(): DataDriver;
73
+ get(id: string | undefined | null): DataDriver | undefined;
74
+ getOrDefault(id: string | undefined | null): DataDriver;
75
+ has(id: string): boolean;
76
+ list(): string[];
77
+ size(): number;
78
+ }
@@ -0,0 +1,43 @@
1
+ import { RealtimeProvider } from "@rebasepro/types";
2
+ /**
3
+ * A realtime client message as forwarded by the WebSocket server.
4
+ */
5
+ interface ClientMessage {
6
+ type: string;
7
+ payload?: Record<string, unknown>;
8
+ subscriptionId?: string;
9
+ }
10
+ /**
11
+ * The concrete realtime service surface the WebSocket server drives — the
12
+ * typed {@link RealtimeProvider} plus the client-connection methods that
13
+ * every engine's realtime service implements.
14
+ */
15
+ export interface WsRealtimeService extends RealtimeProvider {
16
+ addClient(clientId: string, ws: unknown): void;
17
+ handleClientMessage(clientId: string, message: ClientMessage, authContext?: unknown): Promise<void> | void;
18
+ }
19
+ export interface RoutedRealtimeOptions {
20
+ /** Per-engine realtime providers, keyed by data-source key. */
21
+ providers: Record<string, RealtimeProvider>;
22
+ /** Key of the default provider (handles channels/presence/broadcast). */
23
+ defaultKey: string;
24
+ /** Resolve a collection path to its data-source key. */
25
+ resolveKey: (collectionPath: string) => string;
26
+ }
27
+ /**
28
+ * Compose multiple per-engine {@link RealtimeProvider}s into one that routes
29
+ * each subscription to the provider owning the subscribed collection — the
30
+ * realtime counterpart of `buildRoutedRebaseData`.
31
+ *
32
+ * The WebSocket server stays single and engine-agnostic; this composite is
33
+ * passed in its place. Routing rules:
34
+ * - `subscribe_collection` / `subscribe_entity` → the provider for the
35
+ * collection's data source (by `payload.path`).
36
+ * - `unsubscribe` → forwarded to all providers (a no-op on non-owners).
37
+ * - channel / presence / broadcast → the default provider (these are global
38
+ * pub/sub, not bound to an engine).
39
+ * - `addClient` and lifecycle (`onServerReady`/`destroy`/`stopListening`) →
40
+ * all providers (each registers its own ws close handler for cleanup).
41
+ */
42
+ export declare function createRoutedRealtimeService(opts: RoutedRealtimeOptions): WsRealtimeService;
43
+ export {};
@@ -0,0 +1,29 @@
1
+ export interface WebhookConfig {
2
+ id: string;
3
+ url: string;
4
+ secret?: string;
5
+ headers?: Record<string, string>;
6
+ events: string[];
7
+ table: string;
8
+ enabled: boolean;
9
+ }
10
+ export interface WebhookDeliveryResult {
11
+ webhookId: string;
12
+ event: string;
13
+ payload: Record<string, unknown>;
14
+ statusCode: number;
15
+ responseBody: string;
16
+ success: boolean;
17
+ attemptNumber: number;
18
+ }
19
+ export declare class WebhookDispatcher {
20
+ private webhooks;
21
+ private maxRetries;
22
+ private retryDelays;
23
+ /** Register webhooks to watch */
24
+ setWebhooks(webhooks: WebhookConfig[]): void;
25
+ /** Called when an entity changes — checks if any webhook matches */
26
+ onEntityChange(table: string, event: "INSERT" | "UPDATE" | "DELETE", entityId: string, entity: Record<string, unknown> | null, previousEntity?: Record<string, unknown> | null): Promise<WebhookDeliveryResult[]>;
27
+ private deliverWithRetry;
28
+ private deliver;
29
+ }
@@ -0,0 +1,35 @@
1
+ import type { RebaseClient } from "@rebasepro/types";
2
+ /**
3
+ * @internal Called once during server initialization to set the backing instance.
4
+ * This is invoked by `initializeRebaseBackend()` — never call it manually.
5
+ */
6
+ export declare function _initRebase(client: RebaseClient): void;
7
+ /**
8
+ * @internal Allows overriding the underlying instance for unit testing.
9
+ * Throws an error if used in a non-test environment to prevent production abuse.
10
+ */
11
+ export declare function _setRebaseMock(mockInstance: Partial<RebaseClient>): void;
12
+ /**
13
+ * @internal Resets the singleton instance, useful for afterEach() in test suites.
14
+ */
15
+ export declare function _resetRebaseMock(): void;
16
+ /**
17
+ * The server-side Rebase singleton.
18
+ *
19
+ * Initialized automatically during server startup. Provides access to all
20
+ * app-scoped services: **data**, **auth**, **storage**, and **email**.
21
+ *
22
+ * `rebase.data` runs with **admin privileges** (no RLS). For user-scoped
23
+ * queries inside request handlers, continue using the handler's context
24
+ * or the RLS-scoped driver.
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * import { rebase } from "@rebasepro/server-core";
29
+ *
30
+ * // In a Hono handler, cron job, hook, or service file:
31
+ * await rebase.email?.send({ to: "admin@co.com", subject: "Alert", html: "<p>Hi</p>" });
32
+ * const jobs = await rebase.data.jobs.find({ limit: 10 });
33
+ * ```
34
+ */
35
+ export declare const rebase: RebaseClient;