@rebasepro/server-core 0.0.1-canary.4d4fb3e → 0.0.1-canary.ca2cb6e

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 (176) hide show
  1. package/dist/common/src/collections/CollectionRegistry.d.ts +8 -0
  2. package/dist/common/src/util/entities.d.ts +22 -0
  3. package/dist/common/src/util/relations.d.ts +14 -4
  4. package/dist/common/src/util/resolutions.d.ts +1 -1
  5. package/dist/index-DXVBFp5V.js +37 -0
  6. package/dist/index-DXVBFp5V.js.map +1 -0
  7. package/dist/index.es.js +49931 -55
  8. package/dist/index.es.js.map +1 -1
  9. package/dist/index.umd.js +28475 -34569
  10. package/dist/index.umd.js.map +1 -1
  11. package/dist/server-core/src/api/openapi-generator.d.ts +15 -1
  12. package/dist/server-core/src/api/types.d.ts +1 -1
  13. package/dist/server-core/src/auth/admin-routes.d.ts +10 -1
  14. package/dist/server-core/src/auth/apple-oauth.d.ts +30 -0
  15. package/dist/server-core/src/auth/bitbucket-oauth.d.ts +11 -0
  16. package/dist/server-core/src/auth/discord-oauth.d.ts +14 -0
  17. package/dist/server-core/src/auth/facebook-oauth.d.ts +14 -0
  18. package/dist/server-core/src/auth/github-oauth.d.ts +15 -0
  19. package/dist/server-core/src/auth/gitlab-oauth.d.ts +13 -0
  20. package/dist/server-core/src/auth/google-oauth.d.ts +5 -11
  21. package/dist/server-core/src/auth/index.d.ts +13 -2
  22. package/dist/server-core/src/auth/interfaces.d.ts +45 -6
  23. package/dist/server-core/src/auth/jwt.d.ts +1 -0
  24. package/dist/server-core/src/auth/linkedin-oauth.d.ts +18 -0
  25. package/dist/server-core/src/auth/microsoft-oauth.d.ts +16 -0
  26. package/dist/server-core/src/auth/middleware.d.ts +36 -11
  27. package/dist/server-core/src/auth/rate-limiter.d.ts +2 -2
  28. package/dist/server-core/src/auth/routes.d.ts +13 -3
  29. package/dist/server-core/src/auth/slack-oauth.d.ts +12 -0
  30. package/dist/server-core/src/auth/spotify-oauth.d.ts +12 -0
  31. package/dist/server-core/src/auth/twitter-oauth.d.ts +18 -0
  32. package/dist/server-core/src/cron/cron-loader.d.ts +17 -0
  33. package/dist/server-core/src/cron/cron-routes.d.ts +14 -0
  34. package/dist/server-core/src/cron/cron-scheduler.d.ts +61 -0
  35. package/dist/server-core/src/cron/cron-store.d.ts +32 -0
  36. package/dist/server-core/src/cron/index.d.ts +6 -0
  37. package/dist/server-core/src/email/index.d.ts +2 -2
  38. package/dist/server-core/src/email/templates.d.ts +9 -0
  39. package/dist/server-core/src/email/types.d.ts +20 -23
  40. package/dist/server-core/src/history/history-routes.d.ts +2 -2
  41. package/dist/server-core/src/index.d.ts +5 -0
  42. package/dist/server-core/src/init.d.ts +112 -2
  43. package/dist/server-core/src/singleton.d.ts +35 -0
  44. package/dist/server-core/src/storage/LocalStorageController.d.ts +9 -9
  45. package/dist/server-core/src/storage/S3StorageController.d.ts +8 -8
  46. package/dist/server-core/src/storage/index.d.ts +18 -11
  47. package/dist/server-core/src/storage/routes.d.ts +3 -3
  48. package/dist/server-core/src/storage/types.d.ts +28 -16
  49. package/dist/server-core/src/utils/dev-port.d.ts +35 -0
  50. package/dist/server-core/src/utils/logger.d.ts +31 -0
  51. package/dist/server-core/src/utils/request-logger.d.ts +19 -0
  52. package/dist/types/src/controllers/auth.d.ts +2 -0
  53. package/dist/types/src/controllers/client.d.ts +119 -7
  54. package/dist/types/src/controllers/collection_registry.d.ts +4 -3
  55. package/dist/types/src/controllers/customization_controller.d.ts +7 -1
  56. package/dist/types/src/controllers/data.d.ts +34 -7
  57. package/dist/types/src/controllers/data_driver.d.ts +20 -28
  58. package/dist/types/src/controllers/database_admin.d.ts +2 -2
  59. package/dist/types/src/controllers/email.d.ts +34 -0
  60. package/dist/types/src/controllers/index.d.ts +1 -0
  61. package/dist/types/src/controllers/local_config_persistence.d.ts +4 -4
  62. package/dist/types/src/controllers/navigation.d.ts +5 -5
  63. package/dist/types/src/controllers/registry.d.ts +6 -3
  64. package/dist/types/src/controllers/side_entity_controller.d.ts +7 -6
  65. package/dist/types/src/controllers/storage.d.ts +24 -26
  66. package/dist/types/src/rebase_context.d.ts +8 -4
  67. package/dist/types/src/types/backend.d.ts +4 -1
  68. package/dist/types/src/types/builders.d.ts +5 -4
  69. package/dist/types/src/types/chips.d.ts +1 -1
  70. package/dist/types/src/types/collections.d.ts +169 -125
  71. package/dist/types/src/types/cron.d.ts +102 -0
  72. package/dist/types/src/types/data_source.d.ts +1 -1
  73. package/dist/types/src/types/entity_actions.d.ts +8 -8
  74. package/dist/types/src/types/entity_callbacks.d.ts +15 -15
  75. package/dist/types/src/types/entity_link_builder.d.ts +1 -1
  76. package/dist/types/src/types/entity_overrides.d.ts +2 -1
  77. package/dist/types/src/types/entity_views.d.ts +8 -8
  78. package/dist/types/src/types/export_import.d.ts +3 -3
  79. package/dist/types/src/types/index.d.ts +1 -0
  80. package/dist/types/src/types/plugins.d.ts +72 -18
  81. package/dist/types/src/types/properties.d.ts +118 -33
  82. package/dist/types/src/types/relations.d.ts +1 -1
  83. package/dist/types/src/types/slots.d.ts +30 -6
  84. package/dist/types/src/types/translations.d.ts +44 -0
  85. package/dist/types/src/types/user_management_delegate.d.ts +1 -0
  86. package/package.json +84 -84
  87. package/scratch.ts +6 -5
  88. package/src/api/ast-schema-editor.ts +11 -11
  89. package/src/api/collections_for_test/callbacks_test_collection.ts +5 -2
  90. package/src/api/errors.ts +38 -14
  91. package/src/api/graphql/graphql-schema-generator.ts +5 -3
  92. package/src/api/openapi-generator.ts +613 -58
  93. package/src/api/rest/api-generator.ts +17 -11
  94. package/src/api/rest/query-parser.ts +1 -1
  95. package/src/api/schema-editor-routes.ts +2 -0
  96. package/src/api/server.ts +8 -5
  97. package/src/api/types.ts +1 -1
  98. package/src/auth/admin-routes.ts +58 -17
  99. package/src/auth/apple-oauth.ts +130 -0
  100. package/src/auth/bitbucket-oauth.ts +82 -0
  101. package/src/auth/discord-oauth.ts +83 -0
  102. package/src/auth/facebook-oauth.ts +72 -0
  103. package/src/auth/github-oauth.ts +110 -0
  104. package/src/auth/gitlab-oauth.ts +70 -0
  105. package/src/auth/google-oauth.ts +34 -46
  106. package/src/auth/index.ts +15 -2
  107. package/src/auth/interfaces.ts +54 -7
  108. package/src/auth/jwt.ts +22 -5
  109. package/src/auth/linkedin-oauth.ts +81 -0
  110. package/src/auth/microsoft-oauth.ts +88 -0
  111. package/src/auth/middleware.ts +194 -45
  112. package/src/auth/password.ts +3 -1
  113. package/src/auth/rate-limiter.ts +4 -4
  114. package/src/auth/routes.ts +197 -139
  115. package/src/auth/slack-oauth.ts +71 -0
  116. package/src/auth/spotify-oauth.ts +67 -0
  117. package/src/auth/twitter-oauth.ts +120 -0
  118. package/src/collections/loader.ts +6 -6
  119. package/src/cron/cron-loader.ts +89 -0
  120. package/src/cron/cron-routes.test.ts +265 -0
  121. package/src/cron/cron-routes.ts +85 -0
  122. package/src/cron/cron-scheduler.test.ts +421 -0
  123. package/src/cron/cron-scheduler.ts +413 -0
  124. package/src/cron/cron-store.ts +163 -0
  125. package/src/cron/index.ts +6 -0
  126. package/src/db/interfaces.ts +2 -2
  127. package/src/email/index.ts +3 -2
  128. package/src/email/smtp-email-service.ts +5 -2
  129. package/src/email/templates.ts +93 -6
  130. package/src/email/types.ts +17 -24
  131. package/src/functions/function-loader.ts +34 -6
  132. package/src/functions/function-routes.ts +2 -2
  133. package/src/history/history-routes.ts +4 -3
  134. package/src/index.ts +10 -0
  135. package/src/init.ts +475 -57
  136. package/src/services/driver-registry.ts +1 -1
  137. package/src/singleton.test.ts +28 -0
  138. package/src/singleton.ts +70 -0
  139. package/src/storage/LocalStorageController.ts +50 -53
  140. package/src/storage/S3StorageController.ts +49 -46
  141. package/src/storage/index.ts +27 -16
  142. package/src/storage/routes.ts +76 -59
  143. package/src/storage/storage-registry.ts +5 -5
  144. package/src/storage/types.ts +44 -32
  145. package/src/types/index.ts +4 -4
  146. package/src/utils/dev-port.ts +176 -0
  147. package/src/utils/logger.ts +143 -0
  148. package/src/utils/logging.ts +5 -2
  149. package/src/utils/request-logger.ts +66 -0
  150. package/test/admin-routes.test.ts +114 -65
  151. package/test/api-generator.test.ts +73 -30
  152. package/test/ast-schema-editor.test.ts +5 -3
  153. package/test/auth-middleware-hono.test.ts +268 -33
  154. package/test/auth-routes.test.ts +325 -146
  155. package/test/driver-registry.test.ts +4 -2
  156. package/test/error-propagation.test.ts +226 -0
  157. package/test/errors.test.ts +12 -7
  158. package/test/jwt-security.test.ts +18 -9
  159. package/test/jwt.test.ts +26 -13
  160. package/test/middleware.test.ts +13 -8
  161. package/test/query-parser.test.ts +13 -8
  162. package/test/rate-limiter.test.ts +7 -7
  163. package/test/safe-compare.test.ts +66 -0
  164. package/test/singleton.test.ts +59 -0
  165. package/test/storage-local.test.ts +36 -43
  166. package/test/storage-registry.test.ts +38 -36
  167. package/test/storage-routes.test.ts +9 -5
  168. package/test/storage-s3.test.ts +51 -48
  169. package/test.ts +6 -0
  170. package/tsconfig.json +1 -1
  171. package/vite.config.ts +7 -5
  172. package/dist/index-BeMqpmfQ.js +0 -239
  173. package/dist/index-BeMqpmfQ.js.map +0 -1
  174. package/dist/index-bl4J3lNb.js +0 -55823
  175. package/dist/index-bl4J3lNb.js.map +0 -1
  176. package/vite.config.ts.timestamp-1775065397568-8a853255edf6e.mjs +0 -46
@@ -1,28 +1,13 @@
1
1
  /**
2
- * Email service types and interfaces
2
+ * Email service types and interfaces.
3
+ *
4
+ * The canonical `EmailService` and `EmailSendOptions` live in `@rebasepro/types`
5
+ * so they can be used on the `RebaseClient` interface without pulling in nodemailer.
6
+ * This file re-exports them for backward compatibility and adds server-specific
7
+ * config types (SMTP, template functions, etc.).
3
8
  */
4
- /**
5
- * Options for sending an email
6
- */
7
- export interface EmailSendOptions {
8
- to: string;
9
- subject: string;
10
- html: string;
11
- text?: string;
12
- }
13
- /**
14
- * Email service interface - abstraction for sending emails
15
- */
16
- export interface EmailService {
17
- /**
18
- * Send an email
19
- */
20
- send(options: EmailSendOptions): Promise<void>;
21
- /**
22
- * Check if the email service is properly configured
23
- */
24
- isConfigured(): boolean;
25
- }
9
+ import type { EmailService, EmailSendOptions } from "@rebasepro/types";
10
+ export type { EmailService, EmailSendOptions };
26
11
  /**
27
12
  * SMTP server configuration
28
13
  */
@@ -68,6 +53,17 @@ export type UserInvitationTemplateFunction = (setPasswordUrl: string, user: {
68
53
  html: string;
69
54
  text?: string;
70
55
  };
56
+ /**
57
+ * Template function for welcome emails sent after registration
58
+ */
59
+ export type WelcomeEmailTemplateFunction = (user: {
60
+ email: string;
61
+ displayName?: string | null;
62
+ }, appName: string) => {
63
+ subject: string;
64
+ html: string;
65
+ text?: string;
66
+ };
71
67
  /**
72
68
  * Complete email configuration
73
69
  */
@@ -106,5 +102,6 @@ export interface EmailConfig {
106
102
  passwordReset?: PasswordResetTemplateFunction;
107
103
  emailVerification?: EmailVerificationTemplateFunction;
108
104
  userInvitation?: UserInvitationTemplateFunction;
105
+ welcomeEmail?: WelcomeEmailTemplateFunction;
109
106
  };
110
107
  }
@@ -11,10 +11,10 @@ export interface HistoryService {
11
11
  limit: number;
12
12
  offset: number;
13
13
  }): Promise<{
14
- data: any[];
14
+ data: Record<string, unknown>[];
15
15
  total: number;
16
16
  }>;
17
- fetchHistoryEntry(historyId: string): Promise<any>;
17
+ fetchHistoryEntry(historyId: string): Promise<Record<string, unknown> | null>;
18
18
  }
19
19
  export declare function createHistoryRoutes(params: {
20
20
  historyService: HistoryService;
@@ -9,6 +9,7 @@
9
9
  export * from "./db/interfaces";
10
10
  export * from "./auth/interfaces";
11
11
  export * from "./init";
12
+ export { rebase, _setRebaseMock, _resetRebaseMock } from "./singleton";
12
13
  export * from "./services/driver-registry";
13
14
  export * from "./api/types";
14
15
  export * from "./api";
@@ -18,7 +19,11 @@ export * from "./auth";
18
19
  export * from "./email";
19
20
  export * from "./storage";
20
21
  export * from "./utils/logging";
22
+ export * from "./utils/logger";
23
+ export * from "./utils/request-logger";
21
24
  export * from "./utils/sql";
22
25
  export * from "./history";
23
26
  export * from "./functions";
27
+ export * from "./cron";
24
28
  export * from "./serve-spa";
29
+ export * from "./utils/dev-port";
@@ -1,4 +1,4 @@
1
- import { DataDriver, EntityCollection, BackendBootstrapper, BootstrappedAuth, RealtimeProvider } from "@rebasepro/types";
1
+ import { DataDriver, EntityCollection, BackendBootstrapper, BootstrappedAuth, RealtimeProvider, HealthCheckResult } from "@rebasepro/types";
2
2
  import { BackendCollectionRegistry } from "./collections/BackendCollectionRegistry";
3
3
  import { DriverRegistry } from "./services/driver-registry";
4
4
  import { Server } from "http";
@@ -6,17 +6,80 @@ import { Hono } from "hono";
6
6
  import { HonoEnv } from "./api/types";
7
7
  import { BackendStorageConfig, StorageController, StorageRegistry } from "./storage";
8
8
  import { EmailConfig } from "./email";
9
+ import type { OAuthProvider } from "./auth/interfaces";
9
10
  export interface RebaseAuthConfig {
10
11
  jwtSecret?: string;
11
12
  accessExpiresIn?: string;
12
13
  refreshExpiresIn?: string;
13
14
  requireAuth?: boolean;
14
15
  allowRegistration?: boolean;
16
+ /**
17
+ * A static secret key for server-to-server / script authentication.
18
+ *
19
+ * When a request includes `Authorization: Bearer <serviceKey>`, it is
20
+ * granted admin-level access without JWT verification. This is the
21
+ * Rebase equivalent of a Firebase Service Account key.
22
+ *
23
+ * Generate with: `node -e "console.log(require('crypto').randomBytes(48).toString('base64'))"`
24
+ *
25
+ * Set via `REBASE_SERVICE_KEY` in your `.env`.
26
+ * Must be at least 32 characters.
27
+ */
28
+ serviceKey?: string;
15
29
  email?: EmailConfig;
16
30
  google?: {
17
31
  clientId: string;
18
32
  };
33
+ linkedin?: {
34
+ clientId: string;
35
+ clientSecret: string;
36
+ };
37
+ github?: {
38
+ clientId: string;
39
+ clientSecret: string;
40
+ };
41
+ microsoft?: {
42
+ clientId: string;
43
+ clientSecret: string;
44
+ tenantId?: string;
45
+ };
46
+ apple?: {
47
+ clientId: string;
48
+ teamId: string;
49
+ keyId: string;
50
+ privateKey: string;
51
+ };
52
+ facebook?: {
53
+ clientId: string;
54
+ clientSecret: string;
55
+ };
56
+ twitter?: {
57
+ clientId: string;
58
+ clientSecret: string;
59
+ };
60
+ discord?: {
61
+ clientId: string;
62
+ clientSecret: string;
63
+ };
64
+ gitlab?: {
65
+ clientId: string;
66
+ clientSecret: string;
67
+ baseUrl?: string;
68
+ };
69
+ bitbucket?: {
70
+ clientId: string;
71
+ clientSecret: string;
72
+ };
73
+ slack?: {
74
+ clientId: string;
75
+ clientSecret: string;
76
+ };
77
+ spotify?: {
78
+ clientId: string;
79
+ clientSecret: string;
80
+ };
19
81
  defaultRole?: string;
82
+ providers?: OAuthProvider<any>[];
20
83
  [key: string]: unknown;
21
84
  }
22
85
  export interface RebaseBackendConfig {
@@ -30,10 +93,42 @@ export interface RebaseBackendConfig {
30
93
  level?: "error" | "warn" | "info" | "debug";
31
94
  };
32
95
  auth?: RebaseAuthConfig;
33
- storage?: BackendStorageConfig | Record<string, BackendStorageConfig>;
96
+ /**
97
+ * Storage configuration. Accepts:
98
+ *
99
+ * - A `BackendStorageConfig` object (`{ type: 'local' | 's3', ... }`)
100
+ * - A `StorageController` instance (for custom providers like GCS, Azure, etc.)
101
+ * - A `Record<string, ...>` of either, for multi-backend setups
102
+ */
103
+ storage?: BackendStorageConfig | StorageController | Record<string, BackendStorageConfig | StorageController>;
34
104
  history?: unknown;
35
105
  enableSwagger?: boolean;
36
106
  functionsDir?: string;
107
+ cronsDir?: string;
108
+ /**
109
+ * Maximum request body size in bytes for API routes (default: 10MB).
110
+ * Set to 0 to disable the global limit entirely.
111
+ *
112
+ * Note: Storage upload routes use their own limit from the storage config's
113
+ * `maxFileSize` property (default: 50MB), which takes precedence over this.
114
+ */
115
+ maxBodySize?: number;
116
+ /**
117
+ * CSRF protection configuration. **Opt-in** — disabled by default.
118
+ *
119
+ * BaaS APIs are consumed by mobile apps, SPAs on different domains,
120
+ * and CLI tools, so CSRF is intentionally not enabled unless you
121
+ * explicitly configure it with allowed origins.
122
+ *
123
+ * @example
124
+ * ```ts
125
+ * csrf: { origin: ["https://myapp.com", "https://admin.myapp.com"] }
126
+ * ```
127
+ */
128
+ csrf?: {
129
+ /** Allowed origins for CSRF validation. */
130
+ origin: string | string[] | ((origin: string) => boolean);
131
+ };
37
132
  }
38
133
  export interface RebaseBackendInstance {
39
134
  driverRegistry: DriverRegistry;
@@ -45,5 +140,20 @@ export interface RebaseBackendInstance {
45
140
  storageRegistry?: StorageRegistry;
46
141
  storageController?: StorageController;
47
142
  collectionRegistry: BackendCollectionRegistry;
143
+ cronScheduler?: import("./cron").CronScheduler;
144
+ /**
145
+ * Deep health check that verifies database connectivity.
146
+ * Returns latency and component status.
147
+ */
148
+ healthCheck(): Promise<HealthCheckResult>;
149
+ /**
150
+ * Graceful shutdown helper for the BaaS instance.
151
+ * Stops the cron scheduler and closes the HTTP server, allowing
152
+ * in-flight requests to drain within the given timeout.
153
+ *
154
+ * @param timeoutMs - Maximum time (ms) to wait for drain before force-exit (default: 15000).
155
+ * Pass 0 to skip the force-exit timer (useful in tests).
156
+ */
157
+ shutdown(timeoutMs?: number): Promise<void>;
48
158
  }
49
159
  export declare function initializeRebaseBackend(config: RebaseBackendConfig): Promise<RebaseBackendInstance>;
@@ -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;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Local filesystem storage controller
3
3
  */
4
- import { StorageController, LocalStorageConfig } from './types';
5
- import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from '@rebasepro/types';
4
+ import { StorageController, LocalStorageConfig } from "./types";
5
+ import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from "@rebasepro/types";
6
6
  /**
7
7
  * Local filesystem storage implementation
8
8
  * Stores files in a directory structure: {basePath}/{bucket}/{path}
@@ -11,7 +11,7 @@ export declare class LocalStorageController implements StorageController {
11
11
  private config;
12
12
  private basePath;
13
13
  constructor(config: LocalStorageConfig);
14
- getType(): 'local';
14
+ getType(): "local";
15
15
  /**
16
16
  * Ensure directory exists, creating it if necessary
17
17
  */
@@ -25,11 +25,11 @@ export declare class LocalStorageController implements StorageController {
25
25
  * Validate file before upload
26
26
  */
27
27
  private validateFile;
28
- uploadFile({ file, fileName, path: storagePath, metadata, bucket }: UploadFileProps): Promise<UploadFileResult>;
29
- getDownloadURL(storagePath: string, bucket?: string): Promise<DownloadConfig>;
30
- getFile(storagePath: string, bucket?: string): Promise<File | null>;
31
- deleteFile(storagePath: string, bucket?: string): Promise<void>;
32
- list(storagePath: string, options?: {
28
+ putObject({ file, key, metadata, bucket }: UploadFileProps): Promise<UploadFileResult>;
29
+ getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
30
+ getObject(key: string, bucket?: string): Promise<File | null>;
31
+ deleteObject(key: string, bucket?: string): Promise<void>;
32
+ listObjects(prefix: string, options?: {
33
33
  bucket?: string;
34
34
  maxResults?: number;
35
35
  pageToken?: string;
@@ -38,7 +38,7 @@ export declare class LocalStorageController implements StorageController {
38
38
  * Get the absolute filesystem path for serving files
39
39
  * Used by the storage routes to serve files directly
40
40
  */
41
- getAbsolutePath(storagePath: string, bucket?: string): string;
41
+ getAbsolutePath(key: string, bucket?: string): string;
42
42
  /**
43
43
  * Get the base path for the storage
44
44
  */
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * S3-compatible storage controller (works with AWS S3 and MinIO)
3
3
  */
4
- import { StorageController, S3StorageConfig } from './types';
5
- import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from '@rebasepro/types';
4
+ import { StorageController, S3StorageConfig } from "./types";
5
+ import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from "@rebasepro/types";
6
6
  /**
7
7
  * S3-compatible storage implementation
8
8
  * Works with AWS S3 and MinIO (with forcePathStyle option)
@@ -11,7 +11,7 @@ export declare class S3StorageController implements StorageController {
11
11
  private config;
12
12
  private client;
13
13
  constructor(config: S3StorageConfig);
14
- getType(): 's3';
14
+ getType(): "s3";
15
15
  /**
16
16
  * Validate file before upload
17
17
  */
@@ -20,15 +20,15 @@ export declare class S3StorageController implements StorageController {
20
20
  * Get the bucket name - either from parameter or config
21
21
  */
22
22
  private getBucket;
23
- uploadFile({ file, fileName, path: storagePath, metadata, bucket }: UploadFileProps): Promise<UploadFileResult>;
23
+ putObject({ file, key, metadata, bucket }: UploadFileProps): Promise<UploadFileResult>;
24
24
  /**
25
25
  * Flatten nested metadata to string values (S3 requirement)
26
26
  */
27
27
  private flattenMetadata;
28
- getDownloadURL(storagePath: string, bucket?: string): Promise<DownloadConfig>;
29
- getFile(storagePath: string, bucket?: string): Promise<File | null>;
30
- deleteFile(storagePath: string, bucket?: string): Promise<void>;
31
- list(storagePath: string, options?: {
28
+ getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
29
+ getObject(key: string, bucket?: string): Promise<File | null>;
30
+ deleteObject(key: string, bucket?: string): Promise<void>;
31
+ listObjects(prefix: string, options?: {
32
32
  bucket?: string;
33
33
  maxResults?: number;
34
34
  pageToken?: string;
@@ -1,18 +1,25 @@
1
1
  /**
2
2
  * Storage module for Rebase backend
3
3
  *
4
- * Provides file storage functionality with support for:
5
- * - Local filesystem storage (default, zero config)
6
- * - S3-compatible storage (AWS S3, MinIO)
4
+ * Provides pluggable file storage with two built-in providers:
5
+ * - **Local filesystem** zero config, great for dev and single-server deployments.
6
+ * - **S3-compatible** works with AWS S3, Cloudflare R2, MinIO, Hetzner Object Storage,
7
+ * Backblaze B2, DigitalOcean Spaces, and GCS (via S3 interop).
8
+ *
9
+ * For other providers (native GCS SDK, Azure Blob, etc.), implement the
10
+ * `StorageController` interface and pass the instance directly to the `storage` config.
7
11
  */
8
- export * from './types';
9
- export { LocalStorageController } from './LocalStorageController';
10
- export { S3StorageController } from './S3StorageController';
11
- export { createStorageRoutes } from './routes';
12
- export type { StorageRoutesConfig } from './routes';
13
- export * from './storage-registry';
14
- import { BackendStorageConfig, StorageController } from './types';
12
+ export * from "./types";
13
+ export { LocalStorageController } from "./LocalStorageController";
14
+ export { S3StorageController } from "./S3StorageController";
15
+ export { createStorageRoutes } from "./routes";
16
+ export type { StorageRoutesConfig } from "./routes";
17
+ export * from "./storage-registry";
18
+ import { BackendStorageConfig, StorageController } from "./types";
15
19
  /**
16
- * Factory function to create a storage controller based on configuration
20
+ * Create a storage controller from a config object.
21
+ *
22
+ * For custom providers, implement `StorageController` directly instead
23
+ * of going through this factory.
17
24
  */
18
25
  export declare function createStorageController(config: BackendStorageConfig): StorageController;
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Storage REST API routes using Hono
3
3
  */
4
- import { Hono } from 'hono';
5
- import { StorageController } from './types';
6
- import { HonoEnv } from '../api/types';
4
+ import { Hono } from "hono";
5
+ import { StorageController } from "./types";
6
+ import { HonoEnv } from "../api/types";
7
7
  export interface StorageRoutesConfig {
8
8
  controller: StorageController;
9
9
  /** Base path for storage routes (default: '/api/storage') */
@@ -6,7 +6,7 @@ import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult }
6
6
  * Local filesystem storage configuration
7
7
  */
8
8
  export interface LocalStorageConfig {
9
- type: 'local';
9
+ type: "local";
10
10
  /** Base directory for file storage (e.g., './uploads') */
11
11
  basePath: string;
12
12
  /** Maximum file size in bytes (default: 50MB) */
@@ -20,12 +20,12 @@ export interface LocalStorageConfig {
20
20
  * S3-compatible storage configuration (works with AWS S3 and MinIO)
21
21
  */
22
22
  export interface S3StorageConfig {
23
- type: 's3';
23
+ type: "s3";
24
24
  /** S3 bucket name */
25
25
  bucket: string;
26
26
  /** AWS region (e.g., 'us-east-1') */
27
27
  region?: string;
28
- /** Custom endpoint URL (required for MinIO) */
28
+ /** Custom endpoint URL (required for MinIO, Cloudflare R2, Hetzner Object Storage) */
29
29
  endpoint?: string;
30
30
  /** AWS access key ID */
31
31
  accessKeyId: string;
@@ -41,7 +41,16 @@ export interface S3StorageConfig {
41
41
  signedUrlExpiration?: number;
42
42
  }
43
43
  /**
44
- * Storage configuration - either local filesystem or S3-compatible
44
+ * Storage configuration local filesystem or S3-compatible.
45
+ *
46
+ * **Built-in providers:**
47
+ * - `local` — Zero-config filesystem storage. Great for dev and single-server deployments (Hetzner, bare metal).
48
+ * - `s3` — Any S3-compatible provider. AWS S3, Cloudflare R2, MinIO, Hetzner Object Storage,
49
+ * Backblaze B2, DigitalOcean Spaces, and even GCS (via its S3-compatible interoperability API).
50
+ *
51
+ * **Custom providers:**
52
+ * For cloud-native storage (GCS, Azure Blob, etc.), implement the `StorageController`
53
+ * interface and pass the instance directly to the `storage` config.
45
54
  */
46
55
  export type BackendStorageConfig = LocalStorageConfig | S3StorageConfig;
47
56
  /**
@@ -49,33 +58,36 @@ export type BackendStorageConfig = LocalStorageConfig | S3StorageConfig;
49
58
  */
50
59
  export interface StorageController {
51
60
  /**
52
- * Upload a file
61
+ * Upload an object
53
62
  */
54
- uploadFile(props: UploadFileProps): Promise<UploadFileResult>;
63
+ putObject(props: UploadFileProps): Promise<UploadFileResult>;
55
64
  /**
56
- * Get a download URL for a file
65
+ * Get a download URL (signed URL equivalent) for an object
57
66
  */
58
- getDownloadURL(path: string, bucket?: string): Promise<DownloadConfig>;
67
+ getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
59
68
  /**
60
- * Get file as a File object
69
+ * Get object as a File
61
70
  */
62
- getFile(path: string, bucket?: string): Promise<File | null>;
71
+ getObject(key: string, bucket?: string): Promise<File | null>;
63
72
  /**
64
- * Delete a file
73
+ * Delete an object
65
74
  */
66
- deleteFile(path: string, bucket?: string): Promise<void>;
75
+ deleteObject(key: string, bucket?: string): Promise<void>;
67
76
  /**
68
- * List files in a path
77
+ * List objects in a prefix
69
78
  */
70
- list(path: string, options?: {
79
+ listObjects(prefix: string, options?: {
71
80
  bucket?: string;
72
81
  maxResults?: number;
73
82
  pageToken?: string;
74
83
  }): Promise<StorageListResult>;
75
84
  /**
76
- * Get the storage configuration type
85
+ * Get the storage provider identifier.
86
+ *
87
+ * Built-in values are `'local'` and `'s3'`. Custom implementations
88
+ * should return their own identifier (e.g. `'gcs'`, `'azure'`).
77
89
  */
78
- getType(): 'local' | 's3';
90
+ getType(): string;
79
91
  }
80
92
  /**
81
93
  * Default maximum file size (50MB)
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Dev-mode port resolution utilities.
3
+ *
4
+ * Provides a `listen` wrapper that automatically retries the next port when
5
+ * the requested one is already in use, and writes the resolved port to a
6
+ * well-known temp file so the CLI / frontend can discover it.
7
+ *
8
+ * Port affinity: when a port file already exists (e.g. after a tsx watch
9
+ * restart), the saved port is tried FIRST so the backend stays on the same
10
+ * port the frontend was configured with.
11
+ *
12
+ * This module is dev-only and should never run in production.
13
+ */
14
+ import type { Server } from "http";
15
+ /** Filename written next to the project `.env` so the CLI can read it. */
16
+ export declare const DEV_PORT_FILENAME = ".rebase-dev-port";
17
+ /**
18
+ * Try to `listen` on `startPort`. If the port is busy (`EADDRINUSE`), increment
19
+ * and retry up to `maxAttempts` times.
20
+ *
21
+ * When a port file already exists (written by a previous run), the saved port
22
+ * is tried first to maintain port affinity across tsx watch restarts.
23
+ *
24
+ * Resolves with the port that was actually bound.
25
+ */
26
+ export declare function listenWithPortRetry(server: Server, startPort: number, options?: {
27
+ host?: string;
28
+ maxAttempts?: number;
29
+ /** Absolute path to write the resolved port file into. Defaults to `process.cwd()`. */
30
+ portFileDir?: string;
31
+ }): Promise<number>;
32
+ /**
33
+ * Clean up the dev port file and state file (call on graceful shutdown).
34
+ */
35
+ export declare function cleanupDevPortFile(dir: string): void;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Structured Logger for Rebase Backend
3
+ *
4
+ * Outputs JSON lines when `NODE_ENV=production`, human-readable prefixed
5
+ * lines otherwise. Designed to work with Google Cloud Logging severity levels.
6
+ *
7
+ * Usage:
8
+ * import { logger } from "./utils/logger";
9
+ * logger.info("Server started", { port: 3001 });
10
+ * logger.error("Request failed", { path: "/api/test", error: err });
11
+ */
12
+ export type LogLevel = "debug" | "info" | "warn" | "error";
13
+ export interface LogEntry {
14
+ severity: string;
15
+ message: string;
16
+ timestamp: string;
17
+ [key: string]: unknown;
18
+ }
19
+ export interface Logger {
20
+ debug(message: string, data?: Record<string, unknown>): void;
21
+ info(message: string, data?: Record<string, unknown>): void;
22
+ warn(message: string, data?: Record<string, unknown>): void;
23
+ error(message: string, data?: Record<string, unknown>): void;
24
+ child(defaultFields: Record<string, unknown>): Logger;
25
+ }
26
+ /**
27
+ * Singleton logger instance.
28
+ * In production: emits JSON lines with `severity`, `message`, `timestamp`.
29
+ * In development: emits human-readable prefixed lines.
30
+ */
31
+ export declare const logger: Logger;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Structured HTTP request logging middleware for Hono.
3
+ *
4
+ * Logs every request with method, path, status code, latency, and
5
+ * content-length. In production, outputs JSON for Cloud Logging; in
6
+ * development, emits a coloured one-liner.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { requestLogger } from "@rebasepro/server-core";
11
+ * app.use("/*", requestLogger());
12
+ * ```
13
+ */
14
+ import type { MiddlewareHandler } from "hono";
15
+ export interface RequestLoggerOptions {
16
+ /** Paths to skip logging (e.g. "/health"). Supports exact match. */
17
+ skip?: string[];
18
+ }
19
+ export declare function requestLogger(options?: RequestLoggerOptions): MiddlewareHandler;
@@ -15,6 +15,8 @@ export interface AuthCapabilities {
15
15
  sessionManagement?: boolean;
16
16
  profileUpdate?: boolean;
17
17
  emailVerification?: boolean;
18
+ /** List of enabled OAuth provider IDs (e.g. ["google", "github", "discord"]) */
19
+ enabledProviders?: string[];
18
20
  }
19
21
  /**
20
22
  * Controller for retrieving the logged user or performing auth related operations.