@rebasepro/server-core 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/build-errors.txt +52 -0
  2. package/dist/api/ast-schema-editor.d.ts +21 -0
  3. package/dist/api/collections_for_test/callbacks_test_collection.d.ts +2 -0
  4. package/dist/api/errors.d.ts +53 -0
  5. package/dist/api/graphql/graphql-schema-generator.d.ts +44 -0
  6. package/dist/api/graphql/index.d.ts +1 -0
  7. package/dist/api/index.d.ts +9 -0
  8. package/dist/api/logs-routes.d.ts +37 -0
  9. package/dist/api/openapi-generator.d.ts +16 -0
  10. package/dist/api/rest/api-generator.d.ts +76 -0
  11. package/dist/api/rest/index.d.ts +1 -0
  12. package/dist/api/rest/query-parser.d.ts +8 -0
  13. package/dist/api/schema-editor-routes.d.ts +3 -0
  14. package/dist/api/server.d.ts +40 -0
  15. package/dist/api/types.d.ts +104 -0
  16. package/dist/auth/adapter-middleware.d.ts +43 -0
  17. package/dist/auth/admin-roles-route.d.ts +18 -0
  18. package/dist/auth/admin-user-ops.d.ts +79 -0
  19. package/dist/auth/admin-users-route.d.ts +28 -0
  20. package/dist/auth/api-keys/api-key-middleware.d.ts +39 -0
  21. package/dist/auth/api-keys/api-key-permission-guard.d.ts +32 -0
  22. package/dist/auth/api-keys/api-key-routes.d.ts +20 -0
  23. package/dist/auth/api-keys/api-key-store.d.ts +35 -0
  24. package/dist/auth/api-keys/api-key-types.d.ts +96 -0
  25. package/dist/auth/api-keys/index.d.ts +17 -0
  26. package/dist/auth/apple-oauth.d.ts +30 -0
  27. package/dist/auth/auth-hooks.d.ts +242 -0
  28. package/dist/auth/bitbucket-oauth.d.ts +11 -0
  29. package/dist/auth/builtin-auth-adapter.d.ts +51 -0
  30. package/dist/auth/crypto-utils.d.ts +16 -0
  31. package/dist/auth/custom-auth-adapter.d.ts +39 -0
  32. package/dist/auth/discord-oauth.d.ts +14 -0
  33. package/dist/auth/facebook-oauth.d.ts +14 -0
  34. package/dist/auth/github-oauth.d.ts +15 -0
  35. package/dist/auth/gitlab-oauth.d.ts +13 -0
  36. package/dist/auth/google-oauth.d.ts +47 -0
  37. package/dist/auth/index.d.ts +37 -0
  38. package/dist/auth/interfaces.d.ts +431 -0
  39. package/dist/auth/jwt.d.ts +55 -0
  40. package/dist/auth/linkedin-oauth.d.ts +18 -0
  41. package/dist/auth/magic-link-routes.d.ts +30 -0
  42. package/dist/auth/mfa-crypto.d.ts +23 -0
  43. package/dist/auth/mfa-routes.d.ts +7 -0
  44. package/dist/auth/mfa.d.ts +49 -0
  45. package/dist/auth/microsoft-oauth.d.ts +16 -0
  46. package/dist/auth/middleware.d.ts +113 -0
  47. package/dist/auth/password.d.ts +22 -0
  48. package/dist/auth/rate-limiter.d.ts +50 -0
  49. package/dist/auth/reset-password-admin.d.ts +29 -0
  50. package/dist/auth/rls-scope.d.ts +31 -0
  51. package/dist/auth/routes.d.ts +35 -0
  52. package/dist/auth/session-routes.d.ts +27 -0
  53. package/dist/auth/slack-oauth.d.ts +12 -0
  54. package/dist/auth/spotify-oauth.d.ts +12 -0
  55. package/dist/auth/twitter-oauth.d.ts +18 -0
  56. package/dist/backend-CIxN4FVm.js +15 -0
  57. package/dist/backend-CIxN4FVm.js.map +1 -0
  58. package/dist/base64-js-C_frYBkI.js +1687 -0
  59. package/dist/base64-js-C_frYBkI.js.map +1 -0
  60. package/dist/chunk-Dze3rakg.js +42 -0
  61. package/dist/collections/BackendCollectionRegistry.d.ts +13 -0
  62. package/dist/collections/loader.d.ts +5 -0
  63. package/dist/cron/cron-loader.d.ts +17 -0
  64. package/dist/cron/cron-routes.d.ts +14 -0
  65. package/dist/cron/cron-scheduler.d.ts +106 -0
  66. package/dist/cron/cron-store.d.ts +32 -0
  67. package/dist/cron/index.d.ts +6 -0
  68. package/dist/db/interfaces.d.ts +18 -0
  69. package/dist/dist-DMO-zF6D.js +832 -0
  70. package/dist/dist-DMO-zF6D.js.map +1 -0
  71. package/dist/email/index.d.ts +6 -0
  72. package/dist/email/smtp-email-service.d.ts +25 -0
  73. package/dist/email/templates.d.ts +50 -0
  74. package/dist/email/types.d.ts +126 -0
  75. package/dist/env.d.ts +102 -0
  76. package/dist/from-VbwD7xRf.js +3849 -0
  77. package/dist/from-VbwD7xRf.js.map +1 -0
  78. package/dist/functions/define-function.d.ts +50 -0
  79. package/dist/functions/function-loader.d.ts +17 -0
  80. package/dist/functions/function-routes.d.ts +10 -0
  81. package/dist/functions/index.d.ts +5 -0
  82. package/dist/history/history-routes.d.ts +23 -0
  83. package/dist/history/index.d.ts +1 -0
  84. package/dist/index.d.ts +31 -0
  85. package/dist/index.es.js +61322 -0
  86. package/dist/index.es.js.map +1 -0
  87. package/dist/index.umd.js +103633 -0
  88. package/dist/index.umd.js.map +1 -0
  89. package/dist/init/docs.d.ts +4 -0
  90. package/dist/init/health.d.ts +2 -0
  91. package/dist/init/middlewares.d.ts +10 -0
  92. package/dist/init/shutdown.d.ts +11 -0
  93. package/dist/init/storage.d.ts +5 -0
  94. package/dist/init.d.ts +314 -0
  95. package/dist/jws-BqRRaK11.js +616 -0
  96. package/dist/jws-BqRRaK11.js.map +1 -0
  97. package/dist/jwt-BETC8a1J.js +3560 -0
  98. package/dist/jwt-BETC8a1J.js.map +1 -0
  99. package/dist/logger-BYU66ENZ.js +94 -0
  100. package/dist/logger-BYU66ENZ.js.map +1 -0
  101. package/dist/ms-BeBSuOXN.js +125 -0
  102. package/dist/ms-BeBSuOXN.js.map +1 -0
  103. package/dist/multipart-parser-CedBDOeC.js +299 -0
  104. package/dist/multipart-parser-CedBDOeC.js.map +1 -0
  105. package/dist/serve-spa.d.ts +30 -0
  106. package/dist/services/driver-registry.d.ts +78 -0
  107. package/dist/services/routed-realtime-service.d.ts +43 -0
  108. package/dist/services/webhook-service.d.ts +29 -0
  109. package/dist/singleton.d.ts +35 -0
  110. package/dist/src-CB2PIpBe.js +1182 -0
  111. package/dist/src-CB2PIpBe.js.map +1 -0
  112. package/dist/src-DjzOT1kG.js +29746 -0
  113. package/dist/src-DjzOT1kG.js.map +1 -0
  114. package/dist/storage/GCSStorageController.d.ts +43 -0
  115. package/dist/storage/LocalStorageController.d.ts +46 -0
  116. package/dist/storage/S3StorageController.d.ts +36 -0
  117. package/dist/storage/image-transform.d.ts +50 -0
  118. package/dist/storage/index.d.ts +31 -0
  119. package/dist/storage/routes.d.ts +70 -0
  120. package/dist/storage/storage-registry.d.ts +78 -0
  121. package/dist/storage/tus-handler.d.ts +53 -0
  122. package/dist/storage/types.d.ts +128 -0
  123. package/dist/types/index.d.ts +11 -0
  124. package/dist/utils/dev-port.d.ts +37 -0
  125. package/dist/utils/logger.d.ts +31 -0
  126. package/dist/utils/logging.d.ts +9 -0
  127. package/dist/utils/request-id.d.ts +4 -0
  128. package/dist/utils/request-logger.d.ts +19 -0
  129. package/dist/utils/sql.d.ts +27 -0
  130. package/package.json +22 -14
  131. package/src/api/graphql/graphql-schema-generator.ts +5 -5
  132. package/src/api/openapi-generator.ts +2 -2
  133. package/src/api/rest/api-generator.ts +44 -123
  134. package/src/api/rest/query-parser.ts +6 -23
  135. package/src/api/types.ts +2 -2
  136. package/src/auth/auth-hooks.ts +1 -1
  137. package/src/auth/builtin-auth-adapter.ts +1 -2
  138. package/src/auth/interfaces.ts +11 -2
  139. package/src/auth/middleware.ts +4 -4
  140. package/src/auth/routes.ts +1 -2
  141. package/src/functions/define-function.ts +59 -0
  142. package/src/functions/function-loader.ts +16 -0
  143. package/src/functions/index.ts +2 -0
  144. package/src/index.ts +70 -37
  145. package/src/init.ts +78 -21
  146. package/src/storage/GCSStorageController.ts +334 -0
  147. package/src/storage/index.ts +9 -3
  148. package/src/storage/routes.ts +191 -23
  149. package/src/storage/tus-handler.ts +16 -4
  150. package/src/storage/types.ts +25 -3
  151. package/test/api-generator.test.ts +1 -1
  152. package/test/auth-config-types.test.ts +40 -0
  153. package/test/define-function.test.ts +45 -0
  154. package/test/storage-routes.test.ts +160 -0
  155. package/test/backend-hooks-data.test.ts +0 -477
@@ -0,0 +1,50 @@
1
+ import { Hono } from "hono";
2
+ import type { RebaseClient } from "@rebasepro/types";
3
+ import type { HonoEnv } from "../api/types";
4
+ /**
5
+ * Typed context injected into a function authored with {@link defineFunction}.
6
+ *
7
+ * Surfaces the app-scoped Rebase singleton so handlers don't need to reach
8
+ * for the global `rebase` import. Request-scoped values (the authenticated
9
+ * `user`, the RLS-scoped `driver`, the `apiKey`, the `requestId`) are typed
10
+ * on the Hono context via {@link HonoEnv} — read them with `c.get("user")`
11
+ * / `c.var.driver` inside a handler.
12
+ */
13
+ export interface RebaseFunctionContext {
14
+ /**
15
+ * The server-side Rebase singleton (`data`, `auth`, `storage`, `email`,
16
+ * `sql`). `rebase.data` runs with **admin privileges** (no RLS) — use the
17
+ * request `driver` (`c.var.driver`) for user-scoped queries.
18
+ */
19
+ rebase: RebaseClient;
20
+ }
21
+ /**
22
+ * Typed authoring contract for a custom backend function.
23
+ *
24
+ * A custom function is a file in the `functionsDir` that default-exports a
25
+ * Hono app; the loader mounts it at `/<filename>`. `defineFunction` is the
26
+ * typed opt-in for that contract: it hands you a pre-typed `Hono<HonoEnv>`
27
+ * app (so `c.var.user` / `c.var.driver` are typed) plus a
28
+ * {@link RebaseFunctionContext}, and returns exactly the Hono app the loader
29
+ * already accepts — so it is fully interchangeable with a plain
30
+ * `export default new Hono()`.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { defineFunction, requireAuth } from "@rebasepro/server-core";
35
+ *
36
+ * export default defineFunction((app, { rebase }) => {
37
+ * app.use("/*", requireAuth);
38
+ * app.get("/home", async (c) => {
39
+ * const [stats] = await rebase.sql!(`SELECT count(*) AS n FROM orders`);
40
+ * return c.json({ orders: Number(stats.n) });
41
+ * });
42
+ * });
43
+ * ```
44
+ *
45
+ * @param definition Receives the function's Hono app and the typed context.
46
+ * Register routes on the provided `app` and return nothing, or return your
47
+ * own `Hono<HonoEnv>` app to use instead.
48
+ * @returns The Hono app to default-export from the function file.
49
+ */
50
+ export declare function defineFunction(definition: (app: Hono<HonoEnv>, ctx: RebaseFunctionContext) => void | Hono<HonoEnv>): Hono<HonoEnv>;
@@ -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,5 @@
1
+ export { loadFunctionsFromDirectory } from "./function-loader";
2
+ export type { LoadedFunction } from "./function-loader";
3
+ export { createFunctionRoutes } from "./function-routes";
4
+ export { defineFunction } from "./define-function";
5
+ export type { RebaseFunctionContext } from "./define-function";
@@ -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,31 @@
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 { initializeRebaseBackend, isAuthAdapter, isDatabaseAdapter } from "./init";
10
+ export type { RebaseBackendConfig, RebaseBackendInstance, RebaseAuthConfig } from "./init";
11
+ export { rebase, _setRebaseMock, _resetRebaseMock } from "./singleton";
12
+ export * from "./db/interfaces";
13
+ export * from "./auth";
14
+ export * from "./api";
15
+ export * from "./email";
16
+ export * from "./storage";
17
+ export { createHistoryRoutes } from "./history";
18
+ export { loadFunctionsFromDirectory, createFunctionRoutes, defineFunction } from "./functions";
19
+ export type { LoadedFunction, RebaseFunctionContext } from "./functions";
20
+ export { loadCronJobsFromDirectory, CronScheduler, validateCronExpression, createCronRoutes, createCronStore } from "./cron";
21
+ export type { LoadedCronJob, CronStore } from "./cron";
22
+ export { authUid, authRoles, authJwt } from "./utils/sql";
23
+ export { logger } from "./utils/logger";
24
+ export type { Logger } from "./utils/logger";
25
+ export { loadEnv } from "./env";
26
+ export type { RebaseEnv } from "./env";
27
+ export * from "./types";
28
+ export * from "./services/driver-registry";
29
+ export { cleanupDevPortFile, listenWithPortRetry } from "./utils/dev-port";
30
+ export { serveSPA } from "./serve-spa";
31
+ export { z } from "zod";