@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.
Files changed (300) hide show
  1. package/README.md +2 -2
  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/index.d.ts +7 -0
  6. package/dist/api/logs-routes.d.ts +37 -0
  7. package/dist/api/openapi-generator.d.ts +16 -0
  8. package/dist/api/rest/api-generator.d.ts +68 -0
  9. package/{src/api/rest/index.ts → dist/api/rest/index.d.ts} +0 -1
  10. package/dist/api/rest/query-parser.d.ts +6 -0
  11. package/dist/api/schema-editor-routes.d.ts +3 -0
  12. package/dist/api/types.d.ts +56 -0
  13. package/dist/auth/adapter-middleware.d.ts +43 -0
  14. package/dist/auth/admin-roles-route.d.ts +18 -0
  15. package/dist/auth/admin-user-ops.d.ts +79 -0
  16. package/dist/auth/admin-users-route.d.ts +28 -0
  17. package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
  18. package/{src/auth/api-keys/api-key-permission-guard.ts → dist/auth/api-keys/api-key-permission-guard.d.ts} +2 -34
  19. package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
  20. package/dist/auth/api-keys/api-key-store.d.ts +35 -0
  21. package/{src/auth/api-keys/api-key-types.ts → dist/auth/api-keys/api-key-types.d.ts} +0 -6
  22. package/{src/auth/api-keys/index.ts → dist/auth/api-keys/index.d.ts} +2 -22
  23. package/dist/auth/apple-oauth.d.ts +30 -0
  24. package/{src/auth/auth-hooks.ts → dist/auth/auth-hooks.d.ts} +15 -73
  25. package/dist/auth/bitbucket-oauth.d.ts +11 -0
  26. package/dist/auth/builtin-auth-adapter.d.ts +55 -0
  27. package/dist/auth/cookie-utils.d.ts +32 -0
  28. package/{src/auth/crypto-utils.ts → dist/auth/crypto-utils.d.ts} +1 -16
  29. package/dist/auth/custom-auth-adapter.d.ts +39 -0
  30. package/dist/auth/discord-oauth.d.ts +14 -0
  31. package/dist/auth/facebook-oauth.d.ts +14 -0
  32. package/dist/auth/github-oauth.d.ts +15 -0
  33. package/dist/auth/gitlab-oauth.d.ts +13 -0
  34. package/dist/auth/google-oauth.d.ts +47 -0
  35. package/{src/auth/index.ts → dist/auth/index.d.ts} +4 -22
  36. package/{src/auth/interfaces.ts → dist/auth/interfaces.d.ts} +20 -89
  37. package/dist/auth/jwt.d.ts +67 -0
  38. package/dist/auth/linkedin-oauth.d.ts +18 -0
  39. package/dist/auth/magic-link-routes.d.ts +32 -0
  40. package/dist/auth/mfa-crypto.d.ts +23 -0
  41. package/dist/auth/mfa-routes.d.ts +7 -0
  42. package/dist/auth/mfa.d.ts +49 -0
  43. package/dist/auth/microsoft-oauth.d.ts +16 -0
  44. package/dist/auth/middleware.d.ts +158 -0
  45. package/dist/auth/password.d.ts +22 -0
  46. package/dist/auth/rate-limiter.d.ts +50 -0
  47. package/dist/auth/reset-password-admin.d.ts +29 -0
  48. package/dist/auth/rls-scope.d.ts +31 -0
  49. package/dist/auth/routes.d.ts +66 -0
  50. package/dist/auth/session-routes.d.ts +29 -0
  51. package/dist/auth/slack-oauth.d.ts +12 -0
  52. package/dist/auth/spotify-oauth.d.ts +12 -0
  53. package/dist/auth/twitter-oauth.d.ts +18 -0
  54. package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
  55. package/dist/collections/loader.d.ts +5 -0
  56. package/dist/cron/cron-loader.d.ts +18 -0
  57. package/dist/cron/cron-routes.d.ts +14 -0
  58. package/dist/cron/cron-scheduler.d.ts +106 -0
  59. package/dist/cron/cron-store.d.ts +32 -0
  60. package/dist/cron/define-cron.d.ts +28 -0
  61. package/{src/cron/index.ts → dist/cron/index.d.ts} +1 -0
  62. package/dist/db/interfaces.d.ts +18 -0
  63. package/dist/dynamic-import-Dvh-K5fl.js +22 -0
  64. package/dist/dynamic-import-Dvh-K5fl.js.map +1 -0
  65. package/dist/email/index.d.ts +6 -0
  66. package/dist/email/smtp-email-service.d.ts +30 -0
  67. package/dist/email/templates.d.ts +50 -0
  68. package/{src/email/types.ts → dist/email/types.d.ts} +40 -36
  69. package/dist/env.d.ts +102 -0
  70. package/dist/functions/define-function.d.ts +55 -0
  71. package/dist/functions/function-loader.d.ts +18 -0
  72. package/dist/functions/function-routes.d.ts +10 -0
  73. package/{src/functions/index.ts → dist/functions/index.d.ts} +2 -0
  74. package/dist/history/history-routes.d.ts +23 -0
  75. package/{src/history/index.ts → dist/history/index.d.ts} +0 -1
  76. package/dist/index.d.ts +35 -0
  77. package/dist/index.es.js +18184 -0
  78. package/dist/index.es.js.map +1 -0
  79. package/dist/index.umd.js +48629 -0
  80. package/dist/index.umd.js.map +1 -0
  81. package/dist/init/docs.d.ts +4 -0
  82. package/dist/init/health.d.ts +2 -0
  83. package/dist/init/middlewares.d.ts +10 -0
  84. package/dist/init/shutdown.d.ts +65 -0
  85. package/dist/init/storage.d.ts +5 -0
  86. package/dist/init.d.ts +344 -0
  87. package/dist/jwt-BwIn8xmk.js +4200 -0
  88. package/dist/jwt-BwIn8xmk.js.map +1 -0
  89. package/dist/logger-BYU66ENZ.js +94 -0
  90. package/dist/logger-BYU66ENZ.js.map +1 -0
  91. package/dist/ms-DnYXB-Wd.js +162 -0
  92. package/dist/ms-DnYXB-Wd.js.map +1 -0
  93. package/dist/openapi-generator-Z9oYWLf_.js +586 -0
  94. package/dist/openapi-generator-Z9oYWLf_.js.map +1 -0
  95. package/dist/schema-editor-routes-D3ef8zu1.js +219 -0
  96. package/dist/schema-editor-routes-D3ef8zu1.js.map +1 -0
  97. package/dist/serve-spa.d.ts +36 -0
  98. package/dist/services/driver-registry.d.ts +78 -0
  99. package/dist/services/routed-realtime-service.d.ts +43 -0
  100. package/dist/services/webhook-service.d.ts +29 -0
  101. package/dist/singleton.d.ts +51 -0
  102. package/dist/src-B4OLmNVa.js +437 -0
  103. package/dist/src-B4OLmNVa.js.map +1 -0
  104. package/dist/src-B5WkP1Rv.js +24778 -0
  105. package/dist/src-B5WkP1Rv.js.map +1 -0
  106. package/dist/storage/GCSStorageController.d.ts +43 -0
  107. package/dist/storage/LocalStorageController.d.ts +46 -0
  108. package/dist/storage/S3StorageController.d.ts +40 -0
  109. package/dist/storage/image-transform.d.ts +50 -0
  110. package/{src/storage/index.ts → dist/storage/index.d.ts} +6 -21
  111. package/dist/storage/routes.d.ts +70 -0
  112. package/dist/storage/storage-registry.d.ts +78 -0
  113. package/dist/storage/tus-handler.d.ts +53 -0
  114. package/{src/storage/types.ts → dist/storage/types.d.ts} +32 -38
  115. package/dist/types/index.d.ts +11 -0
  116. package/dist/utils/dev-port.d.ts +45 -0
  117. package/dist/utils/dynamic-import.d.ts +25 -0
  118. package/dist/utils/logger.d.ts +31 -0
  119. package/dist/utils/logging.d.ts +9 -0
  120. package/dist/utils/request-id.d.ts +4 -0
  121. package/dist/utils/request-logger.d.ts +19 -0
  122. package/{src/utils/sql.ts → dist/utils/sql.d.ts} +5 -16
  123. package/package.json +49 -22
  124. package/coverage/clover.xml +0 -3739
  125. package/coverage/coverage-final.json +0 -31
  126. package/coverage/lcov-report/base.css +0 -224
  127. package/coverage/lcov-report/block-navigation.js +0 -87
  128. package/coverage/lcov-report/favicon.png +0 -0
  129. package/coverage/lcov-report/index.html +0 -266
  130. package/coverage/lcov-report/prettify.css +0 -1
  131. package/coverage/lcov-report/prettify.js +0 -2
  132. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  133. package/coverage/lcov-report/sorter.js +0 -210
  134. package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +0 -952
  135. package/coverage/lcov-report/src/api/errors.ts.html +0 -472
  136. package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +0 -1069
  137. package/coverage/lcov-report/src/api/graphql/index.html +0 -116
  138. package/coverage/lcov-report/src/api/index.html +0 -176
  139. package/coverage/lcov-report/src/api/openapi-generator.ts.html +0 -565
  140. package/coverage/lcov-report/src/api/rest/api-generator.ts.html +0 -994
  141. package/coverage/lcov-report/src/api/rest/index.html +0 -131
  142. package/coverage/lcov-report/src/api/rest/query-parser.ts.html +0 -550
  143. package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +0 -202
  144. package/coverage/lcov-report/src/api/server.ts.html +0 -823
  145. package/coverage/lcov-report/src/auth/admin-routes.ts.html +0 -973
  146. package/coverage/lcov-report/src/auth/index.html +0 -176
  147. package/coverage/lcov-report/src/auth/jwt.ts.html +0 -574
  148. package/coverage/lcov-report/src/auth/middleware.ts.html +0 -745
  149. package/coverage/lcov-report/src/auth/password.ts.html +0 -310
  150. package/coverage/lcov-report/src/auth/services.ts.html +0 -2074
  151. package/coverage/lcov-report/src/collections/index.html +0 -116
  152. package/coverage/lcov-report/src/collections/loader.ts.html +0 -232
  153. package/coverage/lcov-report/src/db/auth-schema.ts.html +0 -523
  154. package/coverage/lcov-report/src/db/data-transformer.ts.html +0 -1753
  155. package/coverage/lcov-report/src/db/entityService.ts.html +0 -700
  156. package/coverage/lcov-report/src/db/index.html +0 -146
  157. package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +0 -4048
  158. package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +0 -883
  159. package/coverage/lcov-report/src/db/services/RelationService.ts.html +0 -3121
  160. package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +0 -442
  161. package/coverage/lcov-report/src/db/services/index.html +0 -176
  162. package/coverage/lcov-report/src/db/services/index.ts.html +0 -124
  163. package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +0 -1960
  164. package/coverage/lcov-report/src/index.html +0 -116
  165. package/coverage/lcov-report/src/services/driver-registry.ts.html +0 -631
  166. package/coverage/lcov-report/src/services/index.html +0 -131
  167. package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +0 -3025
  168. package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +0 -1189
  169. package/coverage/lcov-report/src/storage/S3StorageController.ts.html +0 -970
  170. package/coverage/lcov-report/src/storage/index.html +0 -161
  171. package/coverage/lcov-report/src/storage/storage-registry.ts.html +0 -646
  172. package/coverage/lcov-report/src/storage/types.ts.html +0 -451
  173. package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +0 -3082
  174. package/coverage/lcov-report/src/utils/index.html +0 -116
  175. package/coverage/lcov.info +0 -7179
  176. package/jest.config.cjs +0 -19
  177. package/src/api/ast-schema-editor.ts +0 -289
  178. package/src/api/collections_for_test/callbacks_test_collection.ts +0 -61
  179. package/src/api/errors.ts +0 -278
  180. package/src/api/graphql/graphql-schema-generator.ts +0 -383
  181. package/src/api/graphql/index.ts +0 -2
  182. package/src/api/index.ts +0 -11
  183. package/src/api/logs-routes.ts +0 -132
  184. package/src/api/openapi-generator.ts +0 -727
  185. package/src/api/rest/api-generator-count.test.ts +0 -126
  186. package/src/api/rest/api-generator.ts +0 -747
  187. package/src/api/rest/query-parser.ts +0 -300
  188. package/src/api/schema-editor-routes.ts +0 -41
  189. package/src/api/server.ts +0 -271
  190. package/src/api/types.ts +0 -104
  191. package/src/auth/adapter-middleware.ts +0 -114
  192. package/src/auth/admin-roles-route.ts +0 -36
  193. package/src/auth/admin-user-ops.ts +0 -236
  194. package/src/auth/admin-users-route.ts +0 -302
  195. package/src/auth/api-keys/api-key-middleware.ts +0 -133
  196. package/src/auth/api-keys/api-key-routes.ts +0 -193
  197. package/src/auth/api-keys/api-key-store.ts +0 -340
  198. package/src/auth/apple-oauth.ts +0 -122
  199. package/src/auth/bitbucket-oauth.ts +0 -84
  200. package/src/auth/builtin-auth-adapter.ts +0 -380
  201. package/src/auth/custom-auth-adapter.ts +0 -86
  202. package/src/auth/discord-oauth.ts +0 -85
  203. package/src/auth/facebook-oauth.ts +0 -74
  204. package/src/auth/github-oauth.ts +0 -112
  205. package/src/auth/gitlab-oauth.ts +0 -72
  206. package/src/auth/google-oauth.ts +0 -223
  207. package/src/auth/jwt.ts +0 -208
  208. package/src/auth/linkedin-oauth.ts +0 -83
  209. package/src/auth/magic-link-routes.ts +0 -167
  210. package/src/auth/mfa-crypto.ts +0 -91
  211. package/src/auth/mfa-routes.ts +0 -323
  212. package/src/auth/mfa.ts +0 -161
  213. package/src/auth/microsoft-oauth.ts +0 -90
  214. package/src/auth/middleware.ts +0 -369
  215. package/src/auth/password.ts +0 -77
  216. package/src/auth/rate-limiter.ts +0 -225
  217. package/src/auth/reset-password-admin.ts +0 -160
  218. package/src/auth/rls-scope.ts +0 -58
  219. package/src/auth/routes.ts +0 -802
  220. package/src/auth/session-routes.ts +0 -353
  221. package/src/auth/slack-oauth.ts +0 -73
  222. package/src/auth/spotify-oauth.ts +0 -69
  223. package/src/auth/twitter-oauth.ts +0 -128
  224. package/src/collections/BackendCollectionRegistry.ts +0 -20
  225. package/src/collections/loader.ts +0 -50
  226. package/src/cron/cron-loader.ts +0 -84
  227. package/src/cron/cron-routes.test.ts +0 -265
  228. package/src/cron/cron-routes.ts +0 -85
  229. package/src/cron/cron-scheduler.test.ts +0 -559
  230. package/src/cron/cron-scheduler.ts +0 -581
  231. package/src/cron/cron-store.ts +0 -166
  232. package/src/db/interfaces.ts +0 -60
  233. package/src/email/index.ts +0 -19
  234. package/src/email/smtp-email-service.ts +0 -123
  235. package/src/email/templates.ts +0 -470
  236. package/src/env.ts +0 -227
  237. package/src/functions/function-loader.ts +0 -116
  238. package/src/functions/function-routes.ts +0 -31
  239. package/src/history/history-routes.ts +0 -129
  240. package/src/index.ts +0 -70
  241. package/src/init/docs.ts +0 -47
  242. package/src/init/health.ts +0 -37
  243. package/src/init/middlewares.ts +0 -61
  244. package/src/init/shutdown.ts +0 -56
  245. package/src/init/storage.ts +0 -57
  246. package/src/init.ts +0 -1041
  247. package/src/serve-spa.ts +0 -89
  248. package/src/services/driver-registry.ts +0 -183
  249. package/src/services/routed-realtime-service.ts +0 -113
  250. package/src/services/webhook-service.ts +0 -155
  251. package/src/singleton.ts +0 -70
  252. package/src/storage/LocalStorageController.ts +0 -389
  253. package/src/storage/S3StorageController.ts +0 -300
  254. package/src/storage/image-transform.ts +0 -218
  255. package/src/storage/routes.ts +0 -368
  256. package/src/storage/storage-registry.ts +0 -188
  257. package/src/storage/tus-handler.ts +0 -315
  258. package/src/types/index.ts +0 -27
  259. package/src/utils/dev-port.ts +0 -196
  260. package/src/utils/logger.ts +0 -143
  261. package/src/utils/logging.ts +0 -40
  262. package/src/utils/request-id.ts +0 -40
  263. package/src/utils/request-logger.ts +0 -72
  264. package/test/api-generator.test.ts +0 -588
  265. package/test/api-key-permission-guard.test.ts +0 -144
  266. package/test/ast-schema-editor.test.ts +0 -89
  267. package/test/auth-middleware-hono.test.ts +0 -556
  268. package/test/auth-routes.test.ts +0 -1098
  269. package/test/backend-hooks-data.test.ts +0 -477
  270. package/test/custom-auth-adapter.test.ts +0 -189
  271. package/test/driver-registry.test.ts +0 -282
  272. package/test/email-templates.test.ts +0 -174
  273. package/test/env.test.ts +0 -128
  274. package/test/error-propagation.test.ts +0 -226
  275. package/test/errors-hono.test.ts +0 -133
  276. package/test/errors.test.ts +0 -155
  277. package/test/function-loader.test.ts +0 -127
  278. package/test/graphql-schema-generator.test.ts +0 -554
  279. package/test/jwt-security.test.ts +0 -182
  280. package/test/jwt.test.ts +0 -326
  281. package/test/mfa.test.ts +0 -197
  282. package/test/middleware.test.ts +0 -305
  283. package/test/multi-datasource-routing.test.ts +0 -113
  284. package/test/password.test.ts +0 -165
  285. package/test/query-parser.test.ts +0 -233
  286. package/test/rate-limiter.test.ts +0 -102
  287. package/test/reset-password-admin.test.ts +0 -113
  288. package/test/routed-realtime-service.test.ts +0 -86
  289. package/test/safe-compare.test.ts +0 -66
  290. package/test/singleton.test.ts +0 -59
  291. package/test/smtp-email-service.test.ts +0 -169
  292. package/test/storage-local.test.ts +0 -271
  293. package/test/storage-registry.test.ts +0 -282
  294. package/test/storage-routes.test.ts +0 -222
  295. package/test/storage-s3.test.ts +0 -304
  296. package/test/transform-auth-response.test.ts +0 -305
  297. package/test/webhook-service.test.ts +0 -260
  298. package/tsconfig.json +0 -54
  299. package/tsconfig.prod.json +0 -23
  300. package/vite.config.ts +0 -86
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Google Cloud Storage controller (works with GCS and Firebase Storage)
3
+ *
4
+ * The `@google-cloud/storage` package is loaded lazily so it remains an
5
+ * optional peer dependency — users who don't need GCS never pay for the
6
+ * import cost or need it installed.
7
+ */
8
+ import { StorageController, GCSStorageConfig } from "./types";
9
+ import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from "@rebasepro/types";
10
+ /**
11
+ * Google Cloud Storage implementation of `StorageController`.
12
+ *
13
+ * Works with standard GCS buckets **and** Firebase Storage buckets
14
+ * (e.g. `"my-project.appspot.com"`).
15
+ */
16
+ export declare class GCSStorageController implements StorageController {
17
+ private config;
18
+ private client;
19
+ constructor(config: GCSStorageConfig);
20
+ private getClient;
21
+ getType(): "gcs";
22
+ putObject({ file, key, metadata, bucket }: UploadFileProps): Promise<UploadFileResult>;
23
+ getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
24
+ getObject(key: string, bucket?: string): Promise<File | null>;
25
+ deleteObject(key: string, bucket?: string): Promise<void>;
26
+ listObjects(prefix: string, options?: {
27
+ bucket?: string;
28
+ maxResults?: number;
29
+ pageToken?: string;
30
+ }): Promise<StorageListResult>;
31
+ /**
32
+ * Validate file before upload
33
+ */
34
+ private validateFile;
35
+ /**
36
+ * Get the bucket name — either from parameter or config.
37
+ */
38
+ private getBucket;
39
+ /**
40
+ * Flatten nested metadata to string values (GCS custom metadata requirement)
41
+ */
42
+ private flattenMetadata;
43
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Local filesystem storage controller
3
+ */
4
+ import { StorageController, LocalStorageConfig } from "./types";
5
+ import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from "@rebasepro/types";
6
+ /**
7
+ * Local filesystem storage implementation
8
+ * Stores files in a directory structure: {basePath}/{bucket}/{path}
9
+ */
10
+ export declare class LocalStorageController implements StorageController {
11
+ private config;
12
+ private basePath;
13
+ constructor(config: LocalStorageConfig);
14
+ getType(): "local";
15
+ /**
16
+ * Ensure directory exists, creating it if necessary
17
+ */
18
+ private ensureDir;
19
+ /**
20
+ * Get the full filesystem path for a storage path.
21
+ * Includes a path traversal guard to prevent escaping the base directory.
22
+ */
23
+ private getFullPath;
24
+ /**
25
+ * Validate file before upload
26
+ */
27
+ private validateFile;
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
+ bucket?: string;
34
+ maxResults?: number;
35
+ pageToken?: string;
36
+ }): Promise<StorageListResult>;
37
+ /**
38
+ * Get the absolute filesystem path for serving files
39
+ * Used by the storage routes to serve files directly
40
+ */
41
+ getAbsolutePath(key: string, bucket?: string): string;
42
+ /**
43
+ * Get the base path for the storage
44
+ */
45
+ getBasePath(): string;
46
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * S3-compatible storage controller (works with AWS S3 and MinIO)
3
+ */
4
+ import { S3StorageConfig, StorageController } from "./types";
5
+ import { DownloadConfig, StorageListResult, UploadFileProps, UploadFileResult } from "@rebasepro/types";
6
+ /**
7
+ * S3-compatible storage implementation
8
+ * Works with AWS S3 and MinIO (with forcePathStyle option)
9
+ */
10
+ export declare class S3StorageController implements StorageController {
11
+ private config;
12
+ private _client;
13
+ constructor(config: S3StorageConfig);
14
+ /**
15
+ * Lazily create and cache the S3 client on first use
16
+ */
17
+ private getClient;
18
+ getType(): "s3";
19
+ /**
20
+ * Validate file before upload
21
+ */
22
+ private validateFile;
23
+ /**
24
+ * Get the bucket name - either from parameter or config
25
+ */
26
+ private getBucket;
27
+ putObject({ file, key, metadata, bucket }: UploadFileProps): Promise<UploadFileResult>;
28
+ /**
29
+ * Flatten nested metadata to string values (S3 requirement)
30
+ */
31
+ private flattenMetadata;
32
+ getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
33
+ getObject(key: string, bucket?: string): Promise<File | null>;
34
+ deleteObject(key: string, bucket?: string): Promise<void>;
35
+ listObjects(prefix: string, options?: {
36
+ bucket?: string;
37
+ maxResults?: number;
38
+ pageToken?: string;
39
+ }): Promise<StorageListResult>;
40
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Image Transformation Service
3
+ *
4
+ * Provides on-the-fly image resize, crop, format conversion, and quality
5
+ * adjustment using the `sharp` library. Results are cached in an LRU
6
+ * in-memory cache to avoid redundant processing.
7
+ */
8
+ /** Options that can be specified via query parameters. */
9
+ export interface ImageTransformOptions {
10
+ width?: number;
11
+ height?: number;
12
+ quality?: number;
13
+ format?: "webp" | "avif" | "jpeg" | "png";
14
+ fit?: "cover" | "contain" | "fill" | "inside" | "outside";
15
+ }
16
+ /**
17
+ * Parse transform options from URL query parameters.
18
+ * Returns `null` when no transformation is requested.
19
+ */
20
+ export declare function parseTransformOptions(query: Record<string, string>): ImageTransformOptions | null;
21
+ /** Check whether a content type is a transformable image. */
22
+ export declare function isTransformableImage(contentType: string): boolean;
23
+ /**
24
+ * Apply image transformations and return the result buffer + content type.
25
+ */
26
+ export declare function transformImage(buffer: Buffer | Uint8Array, options: ImageTransformOptions): Promise<{
27
+ data: Buffer;
28
+ contentType: string;
29
+ }>;
30
+ /**
31
+ * Simple LRU cache for transformed images.
32
+ *
33
+ * Entries expire after `maxAgeMs` (default: 1 hour) and the cache
34
+ * evicts the oldest entry when `maxEntries` is exceeded.
35
+ */
36
+ export declare class TransformCache {
37
+ private cache;
38
+ private readonly maxEntries;
39
+ private readonly maxAgeMs;
40
+ private readonly maxTotalBytes;
41
+ private totalBytes;
42
+ constructor(maxEntries?: number, maxAgeMs?: number, maxTotalBytes?: number);
43
+ /** Build a deterministic cache key from file key + transform options. */
44
+ buildKey(fileKey: string, options: ImageTransformOptions): string;
45
+ get(cacheKey: string): {
46
+ data: Buffer;
47
+ contentType: string;
48
+ } | null;
49
+ set(cacheKey: string, data: Buffer, contentType: string): void;
50
+ }
@@ -1,46 +1,31 @@
1
1
  /**
2
2
  * Storage module for Rebase backend
3
3
  *
4
- * Provides pluggable file storage with two built-in providers:
4
+ * Provides pluggable file storage with three built-in providers:
5
5
  * - **Local filesystem** — zero config, great for dev and single-server deployments.
6
6
  * - **S3-compatible** — works with AWS S3, Cloudflare R2, MinIO, Hetzner Object Storage,
7
7
  * Backblaze B2, DigitalOcean Spaces, and GCS (via S3 interop).
8
+ * - **Google Cloud Storage / Firebase Storage** — native GCS support via `@google-cloud/storage`
9
+ * (optional peer dependency, lazily loaded).
8
10
  *
9
- * For other providers (native GCS SDK, Azure Blob, etc.), implement the
11
+ * For other providers (Azure Blob, etc.), implement the
10
12
  * `StorageController` interface and pass the instance directly to the `storage` config.
11
13
  */
12
-
13
14
  export * from "./types";
14
15
  export { LocalStorageController } from "./LocalStorageController";
15
16
  export { S3StorageController } from "./S3StorageController";
17
+ export { GCSStorageController } from "./GCSStorageController";
16
18
  export { createStorageRoutes } from "./routes";
17
19
  export type { StorageRoutesConfig } from "./routes";
18
20
  export * from "./storage-registry";
19
21
  export { parseTransformOptions, transformImage, isTransformableImage, TransformCache } from "./image-transform";
20
22
  export type { ImageTransformOptions } from "./image-transform";
21
23
  export { TusHandler } from "./tus-handler";
22
-
23
24
  import { BackendStorageConfig, StorageController } from "./types";
24
- import { LocalStorageController } from "./LocalStorageController";
25
- import { S3StorageController } from "./S3StorageController";
26
-
27
25
  /**
28
26
  * Create a storage controller from a config object.
29
27
  *
30
28
  * For custom providers, implement `StorageController` directly instead
31
29
  * of going through this factory.
32
30
  */
33
- export function createStorageController(config: BackendStorageConfig): StorageController {
34
- switch (config.type) {
35
- case "local":
36
- return new LocalStorageController(config);
37
- case "s3":
38
- return new S3StorageController(config);
39
- default:
40
- throw new Error(
41
- `Unknown storage type: ${(config as Record<string, unknown>).type}. ` +
42
- "Built-in types: local, s3. " +
43
- "For other providers, implement the StorageController interface directly."
44
- );
45
- }
46
- }
31
+ export declare function createStorageController(config: BackendStorageConfig): Promise<StorageController>;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Storage REST API routes using Hono
3
+ *
4
+ * Supports multi-backend routing via `StorageRegistry`. Each endpoint
5
+ * accepts an optional `storageId` parameter (query string or form field)
6
+ * to target a named storage backend. When omitted, the default backend
7
+ * is used.
8
+ */
9
+ import { Hono } from "hono";
10
+ import { StorageController } from "./types";
11
+ import type { StorageRegistry } from "./storage-registry";
12
+ import { type StorageSourceDefinition, type AuthAdapter } from "@rebasepro/types";
13
+ import { HonoEnv } from "../api/types";
14
+ export interface StorageRoutesConfig {
15
+ /**
16
+ * Single storage controller (backward-compatible).
17
+ * Used as fallback when no `registry` is provided.
18
+ */
19
+ controller?: StorageController;
20
+ /**
21
+ * Full storage registry for multi-backend routing.
22
+ * When provided, endpoints resolve the controller from `storageId`
23
+ * parameter. Takes precedence over `controller`.
24
+ */
25
+ registry?: StorageRegistry;
26
+ /**
27
+ * Declared storage sources, surfaced by `GET /sources` so the client can
28
+ * bootstrap its registry. Carries the frontend `transport` (server vs
29
+ * direct) and human-readable labels. Server-transport sources are also
30
+ * derived from the registry; `direct` sources (e.g. Firebase Storage) only
31
+ * exist here since the backend does not proxy them.
32
+ */
33
+ sources?: StorageSourceDefinition[];
34
+ /** Base path for storage routes (default: '/api/storage') */
35
+ basePath?: string;
36
+ /** Require authentication for write operations (default: true) */
37
+ requireAuth?: boolean;
38
+ /** Allow unauthenticated read access to stored files (default: false).
39
+ * When false and requireAuth is true, reads also require authentication. */
40
+ publicRead?: boolean;
41
+ /**
42
+ * When provided, storage routes delegate auth to this adapter instead
43
+ * of the built-in JWT module. This mirrors how data routes use
44
+ * `createAdapterAuthMiddleware()` and avoids the "JWT secret not
45
+ * configured" crash when `configureJwt()` was never called.
46
+ */
47
+ authAdapter?: AuthAdapter;
48
+ }
49
+ /**
50
+ * Extract the wildcard portion of a route path from the full request path.
51
+ *
52
+ * Hono's `c.req.param('*')` does not work reliably in sub-routers mounted
53
+ * via `app.route(prefix, subRouter)`. Instead we derive the wildcard value
54
+ * from the fully-resolved `c.req.path` and `c.req.routePath`.
55
+ *
56
+ * For a route `/metadata/*` mounted at `/api/storage`, a request to
57
+ * `/api/storage/metadata/default/file.jpg` yields routePath
58
+ * `/api/storage/metadata/*`. We strip the prefix (everything before `/*`)
59
+ * plus one character for the trailing `/` to obtain `default/file.jpg`.
60
+ */
61
+ export declare function extractWildcardPath(c: {
62
+ req: {
63
+ path: string;
64
+ routePath: string;
65
+ };
66
+ }): string;
67
+ /**
68
+ * Create storage REST API routes
69
+ */
70
+ export declare function createStorageRoutes(config: StorageRoutesConfig): Hono<HonoEnv>;
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Storage Registry
3
+ *
4
+ * Manages multiple storage controllers for Rebase backend.
5
+ * Allows different storage backends for different use cases.
6
+ *
7
+ * Usage:
8
+ * - Single storage: Pass a single StorageController → maps to "(default)"
9
+ * - Multiple storages: Pass a map of { storageId: StorageController }
10
+ * - String properties use `storageId` in their config to specify which storage to use
11
+ * - Properties without `storageId` fallback to "(default)"
12
+ */
13
+ import { StorageController } from "./types";
14
+ /**
15
+ * The default storage identifier used when:
16
+ * - A single storage controller is provided (not a map)
17
+ * - A property doesn't specify a storageId
18
+ */
19
+ export declare const DEFAULT_STORAGE_ID = "(default)";
20
+ /**
21
+ * Registry for managing multiple storage controllers
22
+ */
23
+ export interface StorageRegistry {
24
+ /**
25
+ * Register a storage controller with an ID
26
+ * @param id - Unique identifier for this storage (e.g., "media", "backups")
27
+ * @param controller - The StorageController instance
28
+ */
29
+ register(id: string, controller: StorageController): void;
30
+ /**
31
+ * Get the default storage controller (id = "(default)")
32
+ * @throws Error if no default storage is registered
33
+ */
34
+ getDefault(): StorageController;
35
+ /**
36
+ * Get a storage controller by ID
37
+ * @param id - Storage identifier, or undefined/null for default
38
+ * @returns The StorageController, or undefined if not found
39
+ */
40
+ get(id: string | undefined | null): StorageController | undefined;
41
+ /**
42
+ * Get a storage controller by ID, with fallback to default
43
+ * @param id - Storage identifier, or undefined/null for default
44
+ * @returns The StorageController (falls back to default if id not found)
45
+ * @throws Error if neither the specified nor default storage exists
46
+ */
47
+ getOrDefault(id: string | undefined | null): StorageController;
48
+ /**
49
+ * Check if a storage with the given ID exists
50
+ */
51
+ has(id: string): boolean;
52
+ /**
53
+ * List all registered storage IDs
54
+ */
55
+ list(): string[];
56
+ /**
57
+ * Get the number of registered storage controllers
58
+ */
59
+ size(): number;
60
+ }
61
+ /**
62
+ * Default implementation of StorageRegistry
63
+ */
64
+ export declare class DefaultStorageRegistry implements StorageRegistry {
65
+ private controllers;
66
+ /**
67
+ * Create a StorageRegistry from either a single controller or a map
68
+ * @param input - Single StorageController (maps to "(default)") or Record<string, StorageController>
69
+ */
70
+ static create(input: StorageController | Record<string, StorageController>): DefaultStorageRegistry;
71
+ register(id: string, controller: StorageController): void;
72
+ getDefault(): StorageController;
73
+ get(id: string | undefined | null): StorageController | undefined;
74
+ getOrDefault(id: string | undefined | null): StorageController;
75
+ has(id: string): boolean;
76
+ list(): string[];
77
+ size(): number;
78
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * TUS Protocol Handler
3
+ *
4
+ * Implements the TUS v1.0.0 resumable upload protocol with the
5
+ * Creation and Termination extensions. Uploads are stored in a
6
+ * temporary directory and moved to final storage on completion.
7
+ *
8
+ * @see https://tus.io/protocols/resumable-upload
9
+ */
10
+ import type { Context } from "hono";
11
+ import type { StorageController } from "./types";
12
+ import type { StorageRegistry } from "./storage-registry";
13
+ /**
14
+ * TUS resumable upload handler.
15
+ *
16
+ * Each instance manages uploads for a single storage root. The
17
+ * `storageController` is used to finalize completed uploads by
18
+ * calling `putObject`.
19
+ */
20
+ export declare class TusHandler {
21
+ private storageController?;
22
+ private storageRegistry?;
23
+ private uploads;
24
+ private tusDir;
25
+ private cleanupTimer?;
26
+ constructor(storageBaseDir: string, storageController?: StorageController | undefined, storageRegistry?: StorageRegistry | undefined);
27
+ /** Ensure the temp directory exists. */
28
+ private ensureDir;
29
+ /** Start periodic cleanup of stale uploads. */
30
+ startCleanup(): void;
31
+ /** Remove uploads that have been idle for longer than UPLOAD_EXPIRY_MS. */
32
+ private cleanupStale;
33
+ /**
34
+ * Parse the `Upload-Metadata` header.
35
+ *
36
+ * Format: `key base64value,key2 base64value2`
37
+ */
38
+ private parseMetadata;
39
+ /** `OPTIONS /tus` — TUS capability discovery. */
40
+ options(): Response;
41
+ /** `POST /tus` — Create a new upload. */
42
+ create(c: Context): Promise<Response>;
43
+ /** `HEAD /tus/:id` — Query upload progress. */
44
+ head(c: Context, id: string): Response;
45
+ /** `PATCH /tus/:id` — Append data to an upload. */
46
+ patch(c: Context, id: string): Promise<Response>;
47
+ /** `DELETE /tus/:id` — Cancel and remove an upload. */
48
+ delete(c: Context, id: string): Promise<Response>;
49
+ /**
50
+ * Move a completed upload into the storage controller.
51
+ */
52
+ private finalize;
53
+ }
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * Storage configuration and types for Rebase backend
3
3
  */
4
-
5
- import { StorageSource, UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult, StorageReference } from "@rebasepro/types";
6
-
4
+ import { UploadFileProps, UploadFileResult, DownloadConfig, StorageListResult } from "@rebasepro/types";
7
5
  /**
8
6
  * Local filesystem storage configuration
9
7
  */
@@ -18,7 +16,6 @@ export interface LocalStorageConfig {
18
16
  /** Base URL for generating download URLs (default: auto-detected from request) */
19
17
  baseUrl?: string;
20
18
  }
21
-
22
19
  /**
23
20
  * S3-compatible storage configuration (works with AWS S3 and MinIO)
24
21
  */
@@ -43,21 +40,44 @@ export interface S3StorageConfig {
43
40
  /** URL expiration time in seconds for signed URLs (default: 3600) */
44
41
  signedUrlExpiration?: number;
45
42
  }
46
-
47
43
  /**
48
- * Storage configuration local filesystem or S3-compatible.
44
+ * Google Cloud Storage configuration (works with GCS and Firebase Storage)
45
+ */
46
+ export interface GCSStorageConfig {
47
+ type: "gcs";
48
+ /** GCS bucket name (e.g. "my-project.appspot.com" for Firebase Storage) */
49
+ bucket: string;
50
+ /** GCP project ID (optional, auto-detected from credentials) */
51
+ projectId?: string;
52
+ /** Path to service account JSON key file */
53
+ keyFilename?: string;
54
+ /** Service account credentials object (alternative to keyFilename) */
55
+ credentials?: {
56
+ client_email: string;
57
+ private_key: string;
58
+ project_id?: string;
59
+ };
60
+ /** Maximum file size in bytes (default: 50MB) */
61
+ maxFileSize?: number;
62
+ /** Allowed MIME types */
63
+ allowedMimeTypes?: string[];
64
+ /** Signed URL expiration in seconds (default: 3600) */
65
+ signedUrlExpiration?: number;
66
+ }
67
+ /**
68
+ * Storage configuration — local filesystem, S3-compatible, or Google Cloud Storage.
49
69
  *
50
70
  * **Built-in providers:**
51
71
  * - `local` — Zero-config filesystem storage. Great for dev and single-server deployments (Hetzner, bare metal).
52
72
  * - `s3` — Any S3-compatible provider. AWS S3, Cloudflare R2, MinIO, Hetzner Object Storage,
53
73
  * Backblaze B2, DigitalOcean Spaces, and even GCS (via its S3-compatible interoperability API).
74
+ * - `gcs` — Native Google Cloud Storage / Firebase Storage via `@google-cloud/storage`.
54
75
  *
55
76
  * **Custom providers:**
56
- * For cloud-native storage (GCS, Azure Blob, etc.), implement the `StorageController`
77
+ * For other cloud storage (Azure Blob, etc.), implement the `StorageController`
57
78
  * interface and pass the instance directly to the `storage` config.
58
79
  */
59
- export type BackendStorageConfig = LocalStorageConfig | S3StorageConfig;
60
-
80
+ export type BackendStorageConfig = LocalStorageConfig | S3StorageConfig | GCSStorageConfig;
61
81
  /**
62
82
  * Storage controller interface for backend implementations
63
83
  */
@@ -66,22 +86,18 @@ export interface StorageController {
66
86
  * Upload an object
67
87
  */
68
88
  putObject(props: UploadFileProps): Promise<UploadFileResult>;
69
-
70
89
  /**
71
90
  * Get a download URL (signed URL equivalent) for an object
72
91
  */
73
92
  getSignedUrl(key: string, bucket?: string): Promise<DownloadConfig>;
74
-
75
93
  /**
76
94
  * Get object as a File
77
95
  */
78
96
  getObject(key: string, bucket?: string): Promise<File | null>;
79
-
80
97
  /**
81
98
  * Delete an object
82
99
  */
83
100
  deleteObject(key: string, bucket?: string): Promise<void>;
84
-
85
101
  /**
86
102
  * List objects in a prefix
87
103
  */
@@ -90,7 +106,6 @@ export interface StorageController {
90
106
  maxResults?: number;
91
107
  pageToken?: string;
92
108
  }): Promise<StorageListResult>;
93
-
94
109
  /**
95
110
  * Get the storage provider identifier.
96
111
  *
@@ -99,36 +114,15 @@ export interface StorageController {
99
114
  */
100
115
  getType(): string;
101
116
  }
102
-
103
117
  /**
104
118
  * Default maximum file size (50MB)
105
119
  */
106
- export const DEFAULT_MAX_FILE_SIZE = 50 * 1024 * 1024;
107
-
120
+ export declare const DEFAULT_MAX_FILE_SIZE: number;
108
121
  /**
109
122
  * Common image MIME types
110
123
  */
111
- export const IMAGE_MIME_TYPES = [
112
- "image/jpeg",
113
- "image/png",
114
- "image/gif",
115
- "image/webp",
116
- "image/svg+xml",
117
- "image/bmp",
118
- "image/tiff"
119
- ];
120
-
124
+ export declare const IMAGE_MIME_TYPES: string[];
121
125
  /**
122
126
  * Common document MIME types
123
127
  */
124
- export const DOCUMENT_MIME_TYPES = [
125
- "application/pdf",
126
- "application/msword",
127
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
128
- "application/vnd.ms-excel",
129
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
130
- "application/vnd.ms-powerpoint",
131
- "application/vnd.openxmlformats-officedocument.presentationml.presentation",
132
- "text/plain",
133
- "text/csv"
134
- ];
128
+ export declare const DOCUMENT_MIME_TYPES: string[];
@@ -0,0 +1,11 @@
1
+ import { Entity, FetchCollectionProps, FetchOneProps } from "@rebasepro/types";
2
+ export interface ListenCollectionRequest<M extends Record<string, unknown> = Record<string, unknown>> extends FetchCollectionProps<M> {
3
+ subscriptionId: string;
4
+ onUpdate: (entities: Entity<M>[]) => void;
5
+ onError?: (error: Error) => void;
6
+ }
7
+ export interface ListenEntityRequest<M extends Record<string, unknown> = Record<string, unknown>> extends FetchOneProps<M> {
8
+ subscriptionId: string;
9
+ onUpdate: (entity: Entity<M> | null) => void;
10
+ onError?: (error: Error) => void;
11
+ }
@@ -0,0 +1,45 @@
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
+ * @internal Not part of the stable public API. Exported only because the
27
+ * official app template (`packages/cli/templates/template/backend/src/index.ts`
28
+ * and `app/backend/src/index.ts`) calls it directly in dev mode. Its dev-only
29
+ * port-affinity behavior is an implementation detail and may change without
30
+ * a major version bump.
31
+ */
32
+ export declare function listenWithPortRetry(server: Server, startPort: number, options?: {
33
+ host?: string;
34
+ maxAttempts?: number;
35
+ /** Absolute path to write the resolved port file into. Defaults to `process.cwd()`. */
36
+ portFileDir?: string;
37
+ /** Service key to include in the state file for MCP server auto-discovery. */
38
+ serviceKey?: string;
39
+ }): Promise<number>;
40
+ /**
41
+ * Clean up the dev port file and state file (call on graceful shutdown).
42
+ *
43
+ * @internal Not part of the stable public API. See {@link listenWithPortRetry}.
44
+ */
45
+ export declare function cleanupDevPortFile(dir: string): void;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Shape returned by a dynamic module import: an object whose `default`
3
+ * property holds the module's default export (CJS `module.exports` is exposed
4
+ * as `default` by Node's ESM interop).
5
+ */
6
+ export interface ImportedModule {
7
+ default?: unknown;
8
+ [key: string]: unknown;
9
+ }
10
+ /**
11
+ * Imports a module by file URL. Injected into the directory loaders so tests
12
+ * can supply a deterministic importer.
13
+ */
14
+ export type ModuleImporter = (url: string) => Promise<ImportedModule>;
15
+ /**
16
+ * Native ESM dynamic import.
17
+ *
18
+ * Wrapped in `new Function` so TypeScript / bundlers don't down-compile the
19
+ * `import()` to `require()` — the loaders must import user-authored `.ts`/`.js`
20
+ * files at runtime using the host's real ESM loader. This is the production
21
+ * default for {@link loadFunctionsFromDirectory} / {@link loadCronJobsFromDirectory}.
22
+ *
23
+ * @internal
24
+ */
25
+ export declare const nativeDynamicImport: ModuleImporter;