@rebasepro/server-core 0.0.1-canary.09e5ec5

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/LICENSE +6 -0
  2. package/README.md +40 -0
  3. package/build-errors.txt +52 -0
  4. package/coverage/clover.xml +3739 -0
  5. package/coverage/coverage-final.json +31 -0
  6. package/coverage/lcov-report/base.css +224 -0
  7. package/coverage/lcov-report/block-navigation.js +87 -0
  8. package/coverage/lcov-report/favicon.png +0 -0
  9. package/coverage/lcov-report/index.html +266 -0
  10. package/coverage/lcov-report/prettify.css +1 -0
  11. package/coverage/lcov-report/prettify.js +2 -0
  12. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  13. package/coverage/lcov-report/sorter.js +210 -0
  14. package/coverage/lcov-report/src/api/ast-schema-editor.ts.html +952 -0
  15. package/coverage/lcov-report/src/api/errors.ts.html +472 -0
  16. package/coverage/lcov-report/src/api/graphql/graphql-schema-generator.ts.html +1069 -0
  17. package/coverage/lcov-report/src/api/graphql/index.html +116 -0
  18. package/coverage/lcov-report/src/api/index.html +176 -0
  19. package/coverage/lcov-report/src/api/openapi-generator.ts.html +565 -0
  20. package/coverage/lcov-report/src/api/rest/api-generator.ts.html +994 -0
  21. package/coverage/lcov-report/src/api/rest/index.html +131 -0
  22. package/coverage/lcov-report/src/api/rest/query-parser.ts.html +550 -0
  23. package/coverage/lcov-report/src/api/schema-editor-routes.ts.html +202 -0
  24. package/coverage/lcov-report/src/api/server.ts.html +823 -0
  25. package/coverage/lcov-report/src/auth/admin-routes.ts.html +973 -0
  26. package/coverage/lcov-report/src/auth/index.html +176 -0
  27. package/coverage/lcov-report/src/auth/jwt.ts.html +574 -0
  28. package/coverage/lcov-report/src/auth/middleware.ts.html +745 -0
  29. package/coverage/lcov-report/src/auth/password.ts.html +310 -0
  30. package/coverage/lcov-report/src/auth/services.ts.html +2074 -0
  31. package/coverage/lcov-report/src/collections/index.html +116 -0
  32. package/coverage/lcov-report/src/collections/loader.ts.html +232 -0
  33. package/coverage/lcov-report/src/db/auth-schema.ts.html +523 -0
  34. package/coverage/lcov-report/src/db/data-transformer.ts.html +1753 -0
  35. package/coverage/lcov-report/src/db/entityService.ts.html +700 -0
  36. package/coverage/lcov-report/src/db/index.html +146 -0
  37. package/coverage/lcov-report/src/db/services/EntityFetchService.ts.html +4048 -0
  38. package/coverage/lcov-report/src/db/services/EntityPersistService.ts.html +883 -0
  39. package/coverage/lcov-report/src/db/services/RelationService.ts.html +3121 -0
  40. package/coverage/lcov-report/src/db/services/entity-helpers.ts.html +442 -0
  41. package/coverage/lcov-report/src/db/services/index.html +176 -0
  42. package/coverage/lcov-report/src/db/services/index.ts.html +124 -0
  43. package/coverage/lcov-report/src/generate-drizzle-schema-logic.ts.html +1960 -0
  44. package/coverage/lcov-report/src/index.html +116 -0
  45. package/coverage/lcov-report/src/services/driver-registry.ts.html +631 -0
  46. package/coverage/lcov-report/src/services/index.html +131 -0
  47. package/coverage/lcov-report/src/services/postgresDataDriver.ts.html +3025 -0
  48. package/coverage/lcov-report/src/storage/LocalStorageController.ts.html +1189 -0
  49. package/coverage/lcov-report/src/storage/S3StorageController.ts.html +970 -0
  50. package/coverage/lcov-report/src/storage/index.html +161 -0
  51. package/coverage/lcov-report/src/storage/storage-registry.ts.html +646 -0
  52. package/coverage/lcov-report/src/storage/types.ts.html +451 -0
  53. package/coverage/lcov-report/src/utils/drizzle-conditions.ts.html +3082 -0
  54. package/coverage/lcov-report/src/utils/index.html +116 -0
  55. package/coverage/lcov.info +7179 -0
  56. package/dist/common/src/collections/CollectionRegistry.d.ts +56 -0
  57. package/dist/common/src/collections/index.d.ts +1 -0
  58. package/dist/common/src/data/buildRebaseData.d.ts +14 -0
  59. package/dist/common/src/index.d.ts +3 -0
  60. package/dist/common/src/util/builders.d.ts +57 -0
  61. package/dist/common/src/util/callbacks.d.ts +6 -0
  62. package/dist/common/src/util/collections.d.ts +11 -0
  63. package/dist/common/src/util/common.d.ts +2 -0
  64. package/dist/common/src/util/conditions.d.ts +26 -0
  65. package/dist/common/src/util/entities.d.ts +58 -0
  66. package/dist/common/src/util/enums.d.ts +3 -0
  67. package/dist/common/src/util/index.d.ts +16 -0
  68. package/dist/common/src/util/navigation_from_path.d.ts +34 -0
  69. package/dist/common/src/util/navigation_utils.d.ts +20 -0
  70. package/dist/common/src/util/parent_references_from_path.d.ts +6 -0
  71. package/dist/common/src/util/paths.d.ts +14 -0
  72. package/dist/common/src/util/permissions.d.ts +5 -0
  73. package/dist/common/src/util/references.d.ts +2 -0
  74. package/dist/common/src/util/relations.d.ts +22 -0
  75. package/dist/common/src/util/resolutions.d.ts +72 -0
  76. package/dist/common/src/util/storage.d.ts +24 -0
  77. package/dist/index-DXVBFp5V.js +37 -0
  78. package/dist/index-DXVBFp5V.js.map +1 -0
  79. package/dist/index.es.js +49934 -0
  80. package/dist/index.es.js.map +1 -0
  81. package/dist/index.umd.js +49968 -0
  82. package/dist/index.umd.js.map +1 -0
  83. package/dist/server-core/src/api/ast-schema-editor.d.ts +21 -0
  84. package/dist/server-core/src/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
  85. package/dist/server-core/src/api/errors.d.ts +35 -0
  86. package/dist/server-core/src/api/graphql/graphql-schema-generator.d.ts +35 -0
  87. package/dist/server-core/src/api/graphql/index.d.ts +1 -0
  88. package/dist/server-core/src/api/index.d.ts +9 -0
  89. package/dist/server-core/src/api/openapi-generator.d.ts +16 -0
  90. package/dist/server-core/src/api/rest/api-generator.d.ts +64 -0
  91. package/dist/server-core/src/api/rest/index.d.ts +1 -0
  92. package/dist/server-core/src/api/rest/query-parser.d.ts +9 -0
  93. package/dist/server-core/src/api/schema-editor-routes.d.ts +3 -0
  94. package/dist/server-core/src/api/server.d.ts +40 -0
  95. package/dist/server-core/src/api/types.d.ts +90 -0
  96. package/dist/server-core/src/auth/admin-routes.d.ts +16 -0
  97. package/dist/server-core/src/auth/apple-oauth.d.ts +30 -0
  98. package/dist/server-core/src/auth/bitbucket-oauth.d.ts +11 -0
  99. package/dist/server-core/src/auth/discord-oauth.d.ts +14 -0
  100. package/dist/server-core/src/auth/facebook-oauth.d.ts +14 -0
  101. package/dist/server-core/src/auth/github-oauth.d.ts +15 -0
  102. package/dist/server-core/src/auth/gitlab-oauth.d.ts +13 -0
  103. package/dist/server-core/src/auth/google-oauth.d.ts +14 -0
  104. package/dist/server-core/src/auth/index.d.ts +23 -0
  105. package/dist/server-core/src/auth/interfaces.d.ts +309 -0
  106. package/dist/server-core/src/auth/jwt.d.ts +43 -0
  107. package/dist/server-core/src/auth/linkedin-oauth.d.ts +18 -0
  108. package/dist/server-core/src/auth/microsoft-oauth.d.ts +16 -0
  109. package/dist/server-core/src/auth/middleware.d.ts +81 -0
  110. package/dist/server-core/src/auth/password.d.ts +22 -0
  111. package/dist/server-core/src/auth/rate-limiter.d.ts +31 -0
  112. package/dist/server-core/src/auth/routes.d.ts +27 -0
  113. package/dist/server-core/src/auth/slack-oauth.d.ts +12 -0
  114. package/dist/server-core/src/auth/spotify-oauth.d.ts +12 -0
  115. package/dist/server-core/src/auth/twitter-oauth.d.ts +18 -0
  116. package/dist/server-core/src/bootstrappers/index.d.ts +0 -0
  117. package/dist/server-core/src/collections/BackendCollectionRegistry.d.ts +13 -0
  118. package/dist/server-core/src/collections/loader.d.ts +5 -0
  119. package/dist/server-core/src/cron/cron-loader.d.ts +17 -0
  120. package/dist/server-core/src/cron/cron-routes.d.ts +14 -0
  121. package/dist/server-core/src/cron/cron-scheduler.d.ts +61 -0
  122. package/dist/server-core/src/cron/cron-store.d.ts +32 -0
  123. package/dist/server-core/src/cron/index.d.ts +6 -0
  124. package/dist/server-core/src/db/interfaces.d.ts +18 -0
  125. package/dist/server-core/src/email/index.d.ts +6 -0
  126. package/dist/server-core/src/email/smtp-email-service.d.ts +25 -0
  127. package/dist/server-core/src/email/templates.d.ts +42 -0
  128. package/dist/server-core/src/email/types.d.ts +107 -0
  129. package/dist/server-core/src/functions/function-loader.d.ts +17 -0
  130. package/dist/server-core/src/functions/function-routes.d.ts +10 -0
  131. package/dist/server-core/src/functions/index.d.ts +3 -0
  132. package/dist/server-core/src/history/history-routes.d.ts +23 -0
  133. package/dist/server-core/src/history/index.d.ts +1 -0
  134. package/dist/server-core/src/index.d.ts +29 -0
  135. package/dist/server-core/src/init.d.ts +159 -0
  136. package/dist/server-core/src/serve-spa.d.ts +30 -0
  137. package/dist/server-core/src/services/driver-registry.d.ts +78 -0
  138. package/dist/server-core/src/singleton.d.ts +35 -0
  139. package/dist/server-core/src/storage/LocalStorageController.d.ts +46 -0
  140. package/dist/server-core/src/storage/S3StorageController.d.ts +36 -0
  141. package/dist/server-core/src/storage/index.d.ts +25 -0
  142. package/dist/server-core/src/storage/routes.d.ts +38 -0
  143. package/dist/server-core/src/storage/storage-registry.d.ts +78 -0
  144. package/dist/server-core/src/storage/types.d.ts +103 -0
  145. package/dist/server-core/src/types/index.d.ts +11 -0
  146. package/dist/server-core/src/utils/dev-port.d.ts +35 -0
  147. package/dist/server-core/src/utils/logger.d.ts +31 -0
  148. package/dist/server-core/src/utils/logging.d.ts +9 -0
  149. package/dist/server-core/src/utils/request-logger.d.ts +19 -0
  150. package/dist/server-core/src/utils/sql.d.ts +27 -0
  151. package/dist/types/src/controllers/analytics_controller.d.ts +7 -0
  152. package/dist/types/src/controllers/auth.d.ts +119 -0
  153. package/dist/types/src/controllers/client.d.ts +170 -0
  154. package/dist/types/src/controllers/collection_registry.d.ts +45 -0
  155. package/dist/types/src/controllers/customization_controller.d.ts +60 -0
  156. package/dist/types/src/controllers/data.d.ts +168 -0
  157. package/dist/types/src/controllers/data_driver.d.ts +160 -0
  158. package/dist/types/src/controllers/database_admin.d.ts +11 -0
  159. package/dist/types/src/controllers/dialogs_controller.d.ts +36 -0
  160. package/dist/types/src/controllers/effective_role.d.ts +4 -0
  161. package/dist/types/src/controllers/email.d.ts +34 -0
  162. package/dist/types/src/controllers/index.d.ts +18 -0
  163. package/dist/types/src/controllers/local_config_persistence.d.ts +20 -0
  164. package/dist/types/src/controllers/navigation.d.ts +213 -0
  165. package/dist/types/src/controllers/registry.d.ts +54 -0
  166. package/dist/types/src/controllers/side_dialogs_controller.d.ts +67 -0
  167. package/dist/types/src/controllers/side_entity_controller.d.ts +90 -0
  168. package/dist/types/src/controllers/snackbar.d.ts +24 -0
  169. package/dist/types/src/controllers/storage.d.ts +171 -0
  170. package/dist/types/src/index.d.ts +4 -0
  171. package/dist/types/src/rebase_context.d.ts +105 -0
  172. package/dist/types/src/types/backend.d.ts +536 -0
  173. package/dist/types/src/types/builders.d.ts +15 -0
  174. package/dist/types/src/types/chips.d.ts +5 -0
  175. package/dist/types/src/types/collections.d.ts +856 -0
  176. package/dist/types/src/types/cron.d.ts +102 -0
  177. package/dist/types/src/types/data_source.d.ts +64 -0
  178. package/dist/types/src/types/entities.d.ts +145 -0
  179. package/dist/types/src/types/entity_actions.d.ts +98 -0
  180. package/dist/types/src/types/entity_callbacks.d.ts +173 -0
  181. package/dist/types/src/types/entity_link_builder.d.ts +7 -0
  182. package/dist/types/src/types/entity_overrides.d.ts +10 -0
  183. package/dist/types/src/types/entity_views.d.ts +61 -0
  184. package/dist/types/src/types/export_import.d.ts +21 -0
  185. package/dist/types/src/types/index.d.ts +23 -0
  186. package/dist/types/src/types/locales.d.ts +4 -0
  187. package/dist/types/src/types/modify_collections.d.ts +5 -0
  188. package/dist/types/src/types/plugins.d.ts +279 -0
  189. package/dist/types/src/types/properties.d.ts +1176 -0
  190. package/dist/types/src/types/property_config.d.ts +70 -0
  191. package/dist/types/src/types/relations.d.ts +336 -0
  192. package/dist/types/src/types/slots.d.ts +252 -0
  193. package/dist/types/src/types/translations.d.ts +870 -0
  194. package/dist/types/src/types/user_management_delegate.d.ts +121 -0
  195. package/dist/types/src/types/websockets.d.ts +78 -0
  196. package/dist/types/src/users/index.d.ts +2 -0
  197. package/dist/types/src/users/roles.d.ts +22 -0
  198. package/dist/types/src/users/user.d.ts +46 -0
  199. package/history_diff.log +385 -0
  200. package/jest.config.cjs +16 -0
  201. package/package.json +86 -0
  202. package/scratch.ts +9 -0
  203. package/src/api/ast-schema-editor.ts +289 -0
  204. package/src/api/collections_for_test/callbacks_test_collection.ts +60 -0
  205. package/src/api/errors.ts +179 -0
  206. package/src/api/graphql/graphql-schema-generator.ts +336 -0
  207. package/src/api/graphql/index.ts +2 -0
  208. package/src/api/index.ts +11 -0
  209. package/src/api/openapi-generator.ts +715 -0
  210. package/src/api/rest/api-generator.ts +472 -0
  211. package/src/api/rest/index.ts +2 -0
  212. package/src/api/rest/query-parser.ts +155 -0
  213. package/src/api/schema-editor-routes.ts +41 -0
  214. package/src/api/server.ts +248 -0
  215. package/src/api/types.ts +90 -0
  216. package/src/auth/admin-routes.ts +529 -0
  217. package/src/auth/apple-oauth.ts +130 -0
  218. package/src/auth/bitbucket-oauth.ts +82 -0
  219. package/src/auth/discord-oauth.ts +83 -0
  220. package/src/auth/facebook-oauth.ts +72 -0
  221. package/src/auth/github-oauth.ts +110 -0
  222. package/src/auth/gitlab-oauth.ts +70 -0
  223. package/src/auth/google-oauth.ts +48 -0
  224. package/src/auth/index.ts +34 -0
  225. package/src/auth/interfaces.ts +363 -0
  226. package/src/auth/jwt.ts +181 -0
  227. package/src/auth/linkedin-oauth.ts +81 -0
  228. package/src/auth/microsoft-oauth.ts +88 -0
  229. package/src/auth/middleware.ts +384 -0
  230. package/src/auth/password.ts +77 -0
  231. package/src/auth/rate-limiter.ts +129 -0
  232. package/src/auth/routes.ts +788 -0
  233. package/src/auth/slack-oauth.ts +71 -0
  234. package/src/auth/spotify-oauth.ts +67 -0
  235. package/src/auth/twitter-oauth.ts +120 -0
  236. package/src/bootstrappers/index.ts +1 -0
  237. package/src/collections/BackendCollectionRegistry.ts +20 -0
  238. package/src/collections/loader.ts +49 -0
  239. package/src/cron/cron-loader.ts +89 -0
  240. package/src/cron/cron-routes.test.ts +265 -0
  241. package/src/cron/cron-routes.ts +85 -0
  242. package/src/cron/cron-scheduler.test.ts +421 -0
  243. package/src/cron/cron-scheduler.ts +413 -0
  244. package/src/cron/cron-store.ts +163 -0
  245. package/src/cron/index.ts +6 -0
  246. package/src/db/interfaces.ts +60 -0
  247. package/src/email/index.ts +18 -0
  248. package/src/email/smtp-email-service.ts +91 -0
  249. package/src/email/templates.ts +388 -0
  250. package/src/email/types.ts +105 -0
  251. package/src/functions/function-loader.ts +119 -0
  252. package/src/functions/function-routes.ts +31 -0
  253. package/src/functions/index.ts +3 -0
  254. package/src/history/history-routes.ts +129 -0
  255. package/src/history/index.ts +2 -0
  256. package/src/index.ts +66 -0
  257. package/src/init.ts +727 -0
  258. package/src/serve-spa.ts +81 -0
  259. package/src/services/driver-registry.ts +182 -0
  260. package/src/singleton.test.ts +28 -0
  261. package/src/singleton.ts +70 -0
  262. package/src/storage/LocalStorageController.ts +365 -0
  263. package/src/storage/S3StorageController.ts +298 -0
  264. package/src/storage/index.ts +43 -0
  265. package/src/storage/routes.ts +264 -0
  266. package/src/storage/storage-registry.ts +187 -0
  267. package/src/storage/types.ts +134 -0
  268. package/src/types/index.ts +27 -0
  269. package/src/utils/dev-port.ts +176 -0
  270. package/src/utils/logger.ts +143 -0
  271. package/src/utils/logging.ts +38 -0
  272. package/src/utils/request-logger.ts +66 -0
  273. package/src/utils/sql.ts +38 -0
  274. package/test/admin-routes.test.ts +640 -0
  275. package/test/api-generator.test.ts +501 -0
  276. package/test/ast-schema-editor.test.ts +63 -0
  277. package/test/auth-middleware-hono.test.ts +556 -0
  278. package/test/auth-routes.test.ts +1047 -0
  279. package/test/driver-registry.test.ts +282 -0
  280. package/test/error-propagation.test.ts +226 -0
  281. package/test/errors-hono.test.ts +133 -0
  282. package/test/errors.test.ts +155 -0
  283. package/test/jwt-security.test.ts +182 -0
  284. package/test/jwt.test.ts +324 -0
  285. package/test/middleware.test.ts +300 -0
  286. package/test/password.test.ts +165 -0
  287. package/test/query-parser.test.ts +263 -0
  288. package/test/rate-limiter.test.ts +102 -0
  289. package/test/safe-compare.test.ts +66 -0
  290. package/test/singleton.test.ts +59 -0
  291. package/test/storage-local.test.ts +271 -0
  292. package/test/storage-registry.test.ts +282 -0
  293. package/test/storage-routes.test.ts +222 -0
  294. package/test/storage-s3.test.ts +304 -0
  295. package/test-ast.ts +28 -0
  296. package/test.ts +6 -0
  297. package/test_output.txt +1133 -0
  298. package/tsconfig.json +49 -0
  299. package/tsconfig.prod.json +20 -0
  300. package/vite.config.ts +80 -0
@@ -0,0 +1,61 @@
1
+ import type { CronJobStatus, CronJobLogEntry } from "@rebasepro/types";
2
+ import type { RebaseClient } from "@rebasepro/client";
3
+ import type { LoadedCronJob } from "./cron-loader";
4
+ import type { CronStore } from "./cron-store";
5
+ export declare class CronScheduler {
6
+ private jobs;
7
+ private started;
8
+ private store?;
9
+ private client?;
10
+ /**
11
+ * Set the RebaseClient instance to make it available to cron job handlers.
12
+ */
13
+ setClient(client: RebaseClient): void;
14
+ /**
15
+ * Attach a persistence store for cron logs.
16
+ * When set, execution logs are written to the database after each run,
17
+ * and counters are seeded from the database on start.
18
+ */
19
+ setStore(store: CronStore): void;
20
+ /**
21
+ * Register a batch of loaded cron jobs.
22
+ */
23
+ registerJobs(loadedJobs: LoadedCronJob[]): void;
24
+ /**
25
+ * Start the scheduler — begins ticking all enabled jobs.
26
+ */
27
+ start(): void;
28
+ /**
29
+ * Stop the scheduler and clear all timers.
30
+ */
31
+ stop(): void;
32
+ /**
33
+ * List all registered jobs with their current status.
34
+ */
35
+ listJobs(): CronJobStatus[];
36
+ /**
37
+ * Get a single job status by ID.
38
+ */
39
+ getJob(id: string): CronJobStatus | undefined;
40
+ /**
41
+ * Get log entries for a job.
42
+ */
43
+ getJobLogs(id: string, limit?: number): CronJobLogEntry[];
44
+ /**
45
+ * Get log entries for a job from the database (if store is available).
46
+ * Falls back to in-memory logs if no store is configured.
47
+ */
48
+ getJobLogsFromDb(id: string, limit?: number): Promise<CronJobLogEntry[]>;
49
+ /**
50
+ * Enable or disable a job at runtime.
51
+ */
52
+ setJobEnabled(id: string, enabled: boolean): CronJobStatus | undefined;
53
+ /**
54
+ * Manually trigger a job execution immediately.
55
+ */
56
+ triggerJob(id: string): Promise<CronJobLogEntry | undefined>;
57
+ private scheduleNext;
58
+ private stopJob;
59
+ private executeJob;
60
+ private toStatus;
61
+ }
@@ -0,0 +1,32 @@
1
+ import type { CronJobLogEntry } from "@rebasepro/types";
2
+ import type { DataDriver } from "@rebasepro/types";
3
+ /**
4
+ * Persistence layer for cron job execution logs.
5
+ *
6
+ * Uses the DataDriver's `admin.executeSql` capability to store logs in a
7
+ * `rebase.cron_logs` table. Falls back gracefully if the driver doesn't
8
+ * support SQL (e.g. MongoDB) — in that case, no persistence occurs.
9
+ */
10
+ export interface CronStore {
11
+ /** Ensure the backing table exists. Called once on startup. */
12
+ ensureTable(): Promise<void>;
13
+ /** Persist a single log entry after execution. */
14
+ insertLog(entry: CronJobLogEntry): Promise<void>;
15
+ /**
16
+ * Fetch the most recent logs for a job.
17
+ * @param jobId The job identifier
18
+ * @param limit Max entries to return (default 50)
19
+ * @returns Logs sorted newest-first
20
+ */
21
+ fetchLogs(jobId: string, limit?: number): Promise<CronJobLogEntry[]>;
22
+ /**
23
+ * Fetch aggregate stats for all jobs (totalRuns, totalFailures, lastRunAt).
24
+ * Used to seed in-memory counters on startup.
25
+ */
26
+ fetchJobStats(): Promise<Map<string, {
27
+ totalRuns: number;
28
+ totalFailures: number;
29
+ lastRunAt?: string;
30
+ }>>;
31
+ }
32
+ export declare function createCronStore(driver: DataDriver): CronStore | undefined;
@@ -0,0 +1,6 @@
1
+ export { loadCronJobsFromDirectory } from "./cron-loader";
2
+ export type { LoadedCronJob } from "./cron-loader";
3
+ export { CronScheduler } from "./cron-scheduler";
4
+ export { createCronRoutes } from "./cron-routes";
5
+ export { createCronStore } from "./cron-store";
6
+ export type { CronStore } from "./cron-store";
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Database Abstraction Interfaces
3
+ *
4
+ * These interfaces define the contracts that any database backend must implement
5
+ * to be used with Rebase. This allows for pluggable database backends like
6
+ * PostgreSQL, MongoDB, MySQL, etc.
7
+ */
8
+ import { DatabaseConnection, QueryFilter, FetchCollectionOptions, SearchOptions, CountOptions, ConditionBuilder, ConditionBuilderStatic, EntityRepository, CollectionSubscriptionConfig, EntitySubscriptionConfig, RealtimeProvider, CollectionRegistryInterface, DataTransformer, BackendConfig, BackendInstance, BackendFactory } from "@rebasepro/types";
9
+ import { NodePgDatabase } from "drizzle-orm/node-postgres";
10
+ import { PgTransaction } from "drizzle-orm/pg-core";
11
+ /**
12
+ * Type representing either a direct database connection or a transaction.
13
+ * Used to allow services to operate within a transaction context.
14
+ * Note: `any` is intentional here — it represents a Drizzle client with
15
+ * a dynamic schema, enabling `db.query[tableName]` access without casts.
16
+ */
17
+ export type DrizzleClient = NodePgDatabase<Record<string, unknown>> | PgTransaction<any, any, any>;
18
+ export type { DatabaseConnection, QueryFilter, FetchCollectionOptions, SearchOptions, CountOptions, ConditionBuilder, ConditionBuilderStatic, EntityRepository, CollectionSubscriptionConfig, EntitySubscriptionConfig, RealtimeProvider, CollectionRegistryInterface, DataTransformer, BackendConfig, BackendInstance, BackendFactory };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Email module exports
3
+ */
4
+ export type { EmailService, EmailSendOptions, SMTPConfig, EmailConfig, PasswordResetTemplateFunction, EmailVerificationTemplateFunction, UserInvitationTemplateFunction, WelcomeEmailTemplateFunction } from "./types";
5
+ export { SMTPEmailService, createEmailService } from "./smtp-email-service";
6
+ export { getPasswordResetTemplate, getEmailVerificationTemplate, getUserInvitationTemplate, getWelcomeEmailTemplate } from "./templates";
@@ -0,0 +1,25 @@
1
+ import { EmailService, EmailSendOptions, EmailConfig } from "./types";
2
+ /**
3
+ * SMTP Email Service implementation using Nodemailer
4
+ */
5
+ export declare class SMTPEmailService implements EmailService {
6
+ private transporter;
7
+ private config;
8
+ constructor(config: EmailConfig);
9
+ /**
10
+ * Check if the email service is properly configured
11
+ */
12
+ isConfigured(): boolean;
13
+ /**
14
+ * Send an email using SMTP or custom send function
15
+ */
16
+ send(options: EmailSendOptions): Promise<void>;
17
+ /**
18
+ * Verify SMTP connection (useful for startup checks)
19
+ */
20
+ verifyConnection(): Promise<boolean>;
21
+ }
22
+ /**
23
+ * Create an email service from configuration
24
+ */
25
+ export declare function createEmailService(config: EmailConfig): EmailService;
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Default email templates for authentication emails
3
+ */
4
+ interface TemplateUser {
5
+ email: string;
6
+ displayName?: string | null;
7
+ }
8
+ /**
9
+ * Default password reset email template
10
+ */
11
+ export declare function getPasswordResetTemplate(resetUrl: string, user: TemplateUser, appName?: string): {
12
+ subject: string;
13
+ html: string;
14
+ text: string;
15
+ };
16
+ /**
17
+ * Default email verification template
18
+ */
19
+ export declare function getEmailVerificationTemplate(verifyUrl: string, user: TemplateUser, appName?: string): {
20
+ subject: string;
21
+ html: string;
22
+ text: string;
23
+ };
24
+ /**
25
+ * Default user invitation email template
26
+ * Sent when an admin creates a new user account
27
+ */
28
+ export declare function getUserInvitationTemplate(setPasswordUrl: string, user: TemplateUser, appName?: string): {
29
+ subject: string;
30
+ html: string;
31
+ text: string;
32
+ };
33
+ /**
34
+ * Default welcome email template
35
+ * Sent automatically when a new user registers
36
+ */
37
+ export declare function getWelcomeEmailTemplate(user: TemplateUser, appName?: string, loginUrl?: string): {
38
+ subject: string;
39
+ html: string;
40
+ text: string;
41
+ };
42
+ export {};
@@ -0,0 +1,107 @@
1
+ /**
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.).
8
+ */
9
+ import type { EmailService, EmailSendOptions } from "@rebasepro/types";
10
+ export type { EmailService, EmailSendOptions };
11
+ /**
12
+ * SMTP server configuration
13
+ */
14
+ export interface SMTPConfig {
15
+ host: string;
16
+ port: number;
17
+ secure?: boolean;
18
+ auth?: {
19
+ user: string;
20
+ pass: string;
21
+ };
22
+ }
23
+ /**
24
+ * Template function for password reset emails
25
+ */
26
+ export type PasswordResetTemplateFunction = (resetUrl: string, user: {
27
+ email: string;
28
+ displayName?: string | null;
29
+ }) => {
30
+ subject: string;
31
+ html: string;
32
+ text?: string;
33
+ };
34
+ /**
35
+ * Template function for email verification emails
36
+ */
37
+ export type EmailVerificationTemplateFunction = (verifyUrl: string, user: {
38
+ email: string;
39
+ displayName?: string | null;
40
+ }) => {
41
+ subject: string;
42
+ html: string;
43
+ text?: string;
44
+ };
45
+ /**
46
+ * Template function for user invitation emails
47
+ */
48
+ export type UserInvitationTemplateFunction = (setPasswordUrl: string, user: {
49
+ email: string;
50
+ displayName?: string | null;
51
+ }) => {
52
+ subject: string;
53
+ html: string;
54
+ text?: string;
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
+ };
67
+ /**
68
+ * Complete email configuration
69
+ */
70
+ export interface EmailConfig {
71
+ /**
72
+ * From address for all emails (e.g., "noreply@example.com" or "MyApp <noreply@example.com>")
73
+ */
74
+ from: string;
75
+ /**
76
+ * SMTP configuration for sending emails via SMTP server
77
+ */
78
+ smtp?: SMTPConfig;
79
+ /**
80
+ * Alternative: custom function to send emails
81
+ * Use this for custom email providers (AWS SES SDK, Resend, etc.)
82
+ */
83
+ sendEmail?: (options: EmailSendOptions) => Promise<void>;
84
+ /**
85
+ * Base URL for password reset links (e.g., "https://myapp.com")
86
+ * The reset link will be: {baseUrl}/reset-password?token={token}
87
+ */
88
+ resetPasswordUrl?: string;
89
+ /**
90
+ * Base URL for email verification links (e.g., "https://myapp.com")
91
+ * The verification link will be: {baseUrl}/verify-email?token={token}
92
+ */
93
+ verifyEmailUrl?: string;
94
+ /**
95
+ * Application name to use in email templates
96
+ */
97
+ appName?: string;
98
+ /**
99
+ * Custom email templates (optional - defaults are provided)
100
+ */
101
+ templates?: {
102
+ passwordReset?: PasswordResetTemplateFunction;
103
+ emailVerification?: EmailVerificationTemplateFunction;
104
+ userInvitation?: UserInvitationTemplateFunction;
105
+ welcomeEmail?: WelcomeEmailTemplateFunction;
106
+ };
107
+ }
@@ -0,0 +1,17 @@
1
+ import { Hono } from "hono";
2
+ export interface LoadedFunction {
3
+ /** Endpoint name derived from filename (e.g., "send-invoice") */
4
+ name: string;
5
+ /** The Hono sub-app to mount */
6
+ app: Hono<import("hono").Env>;
7
+ }
8
+ /**
9
+ * Auto-discover Hono route files from a directory.
10
+ *
11
+ * Each file should default-export a Hono app (or router).
12
+ * The filename (without extension) becomes the mount path:
13
+ * `functions/send-invoice.ts` → mounted at `/send-invoice`
14
+ *
15
+ * This mirrors how `loadCollectionsFromDirectory` works for collections.
16
+ */
17
+ export declare function loadFunctionsFromDirectory(directory: string): Promise<LoadedFunction[]>;
@@ -0,0 +1,10 @@
1
+ import { Hono } from "hono";
2
+ import { HonoEnv } from "../api/types";
3
+ import { LoadedFunction } from "./function-loader";
4
+ /**
5
+ * Mount all loaded function routes under a single Hono router.
6
+ *
7
+ * Each function is mounted at `/<function-name>`, preserving
8
+ * whatever HTTP methods and middleware the Hono sub-app defines.
9
+ */
10
+ export declare function createFunctionRoutes(functions: LoadedFunction[]): Hono<HonoEnv>;
@@ -0,0 +1,3 @@
1
+ export { loadFunctionsFromDirectory } from "./function-loader";
2
+ export type { LoadedFunction } from "./function-loader";
3
+ export { createFunctionRoutes } from "./function-routes";
@@ -0,0 +1,23 @@
1
+ import { Hono } from "hono";
2
+ import { HonoEnv } from "../api/types";
3
+ import { BackendCollectionRegistry } from "../collections/BackendCollectionRegistry";
4
+ import { DataDriver } from "@rebasepro/types";
5
+ /**
6
+ * Create Hono routes for entity history.
7
+ * Mounted at `{basePath}/data/:slug/:entityId/history`.
8
+ */
9
+ export interface HistoryService {
10
+ fetchHistory(tableName: string, entityId: string, options: {
11
+ limit: number;
12
+ offset: number;
13
+ }): Promise<{
14
+ data: Record<string, unknown>[];
15
+ total: number;
16
+ }>;
17
+ fetchHistoryEntry(historyId: string): Promise<Record<string, unknown> | null>;
18
+ }
19
+ export declare function createHistoryRoutes(params: {
20
+ historyService: HistoryService;
21
+ registry: BackendCollectionRegistry;
22
+ driver: DataDriver;
23
+ }): Hono<HonoEnv>;
@@ -0,0 +1 @@
1
+ export { createHistoryRoutes } from "./history-routes";
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @rebasepro/server-core
3
+ *
4
+ * Database-Agnostic Backend Core for Rebase.
5
+ * This package provides the core backend services, generic driver routing,
6
+ * and API layers. Database implementations (e.g., PostgreSQL) are provided
7
+ * by specialized driver packages like `@rebasepro/server-postgresql`.
8
+ */
9
+ export * from "./db/interfaces";
10
+ export * from "./auth/interfaces";
11
+ export * from "./init";
12
+ export { rebase, _setRebaseMock, _resetRebaseMock } from "./singleton";
13
+ export * from "./services/driver-registry";
14
+ export * from "./api/types";
15
+ export * from "./api";
16
+ export * from "./types";
17
+ export * from "./types/index";
18
+ export * from "./auth";
19
+ export * from "./email";
20
+ export * from "./storage";
21
+ export * from "./utils/logging";
22
+ export * from "./utils/logger";
23
+ export * from "./utils/request-logger";
24
+ export * from "./utils/sql";
25
+ export * from "./history";
26
+ export * from "./functions";
27
+ export * from "./cron";
28
+ export * from "./serve-spa";
29
+ export * from "./utils/dev-port";
@@ -0,0 +1,159 @@
1
+ import { DataDriver, EntityCollection, BackendBootstrapper, BootstrappedAuth, RealtimeProvider, HealthCheckResult } from "@rebasepro/types";
2
+ import { BackendCollectionRegistry } from "./collections/BackendCollectionRegistry";
3
+ import { DriverRegistry } from "./services/driver-registry";
4
+ import { Server } from "http";
5
+ import { Hono } from "hono";
6
+ import { HonoEnv } from "./api/types";
7
+ import { BackendStorageConfig, StorageController, StorageRegistry } from "./storage";
8
+ import { EmailConfig } from "./email";
9
+ import type { OAuthProvider } from "./auth/interfaces";
10
+ export interface RebaseAuthConfig {
11
+ jwtSecret?: string;
12
+ accessExpiresIn?: string;
13
+ refreshExpiresIn?: string;
14
+ requireAuth?: boolean;
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;
29
+ email?: EmailConfig;
30
+ google?: {
31
+ clientId: string;
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
+ };
81
+ defaultRole?: string;
82
+ providers?: OAuthProvider<any>[];
83
+ [key: string]: unknown;
84
+ }
85
+ export interface RebaseBackendConfig {
86
+ collections?: EntityCollection[];
87
+ collectionsDir?: string;
88
+ server: Server;
89
+ app: Hono<HonoEnv>;
90
+ basePath?: string;
91
+ bootstrappers: BackendBootstrapper[];
92
+ logging?: {
93
+ level?: "error" | "warn" | "info" | "debug";
94
+ };
95
+ auth?: RebaseAuthConfig;
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>;
104
+ history?: unknown;
105
+ enableSwagger?: boolean;
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
+ };
132
+ }
133
+ export interface RebaseBackendInstance {
134
+ driverRegistry: DriverRegistry;
135
+ driver: DataDriver;
136
+ realtimeServices: Record<string, RealtimeProvider>;
137
+ realtimeService: RealtimeProvider;
138
+ auth?: BootstrappedAuth;
139
+ history?: unknown;
140
+ storageRegistry?: StorageRegistry;
141
+ storageController?: StorageController;
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>;
158
+ }
159
+ export declare function initializeRebaseBackend(config: RebaseBackendConfig): Promise<RebaseBackendInstance>;
@@ -0,0 +1,30 @@
1
+ import { Hono } from "hono";
2
+ /**
3
+ * Configuration for serving a Single Page Application
4
+ */
5
+ export interface ServeSPAConfig {
6
+ /**
7
+ * Absolute path to the frontend build directory
8
+ * @example path.join(__dirname, "../../frontend/dist")
9
+ */
10
+ frontendPath: string;
11
+ /**
12
+ * Base path for API routes (default: "/api")
13
+ * Requests to this path will be passed through to API handlers
14
+ */
15
+ apiBasePath?: string;
16
+ /**
17
+ * Additional paths to exclude from SPA handling
18
+ * These paths will be passed through to other handlers
19
+ * @example ["/health", "/ws", "/metrics"]
20
+ */
21
+ excludePaths?: string[];
22
+ /**
23
+ * Index file to serve for SPA routes (default: "index.html")
24
+ */
25
+ indexFile?: string;
26
+ }
27
+ /**
28
+ * Serve a Single Page Application from an Hono app.
29
+ */
30
+ export declare function serveSPA<E extends import("hono").Env>(app: Hono<E>, config: ServeSPAConfig): void;
@@ -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
+ }