@rebasepro/server 0.21.0 → 0.21.1-canary.g8c5a265

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 (39) hide show
  1. package/README.md +29 -11
  2. package/dist/auth/admin-user-ops.d.ts +23 -1
  3. package/dist/{auth-gzoRjnuh.js → auth-BvBllZjy.js} +1555 -1525
  4. package/dist/auth-BvBllZjy.js.map +1 -0
  5. package/dist/backup/backup-common.d.ts +2 -1
  6. package/dist/{backup-DGu0v9Ku.js → backup-De-Xm4tg.js} +37 -9
  7. package/dist/backup-De-Xm4tg.js.map +1 -0
  8. package/dist/collections/validate-config.d.ts +4 -2
  9. package/dist/{cron-routes-BamgO0Xr.js → cron-routes-3FVef5QO.js} +2 -2
  10. package/dist/{cron-routes-BamgO0Xr.js.map → cron-routes-3FVef5QO.js.map} +1 -1
  11. package/dist/{cron-scheduler-D47tdB9T.js → cron-scheduler-COPQxlEq.js} +59 -10
  12. package/dist/cron-scheduler-COPQxlEq.js.map +1 -0
  13. package/dist/{cron-store-yXOyIEmn.js → cron-store-Dp0X7zRB.js} +2 -2
  14. package/dist/{cron-store-yXOyIEmn.js.map → cron-store-Dp0X7zRB.js.map} +1 -1
  15. package/dist/deploy/pod-contract.d.ts +14 -0
  16. package/dist/{history-recorder-hBGuXcZc.js → history-recorder-5VKT7nss.js} +2 -2
  17. package/dist/{history-recorder-hBGuXcZc.js.map → history-recorder-5VKT7nss.js.map} +1 -1
  18. package/dist/{history-store-C9EtGtoL.js → history-store-By2R_G1b.js} +2 -2
  19. package/dist/{history-store-C9EtGtoL.js.map → history-store-By2R_G1b.js.map} +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.es.js +255 -221
  22. package/dist/index.es.js.map +1 -1
  23. package/dist/init/middlewares.d.ts +19 -1
  24. package/dist/init/storage.d.ts +17 -0
  25. package/dist/init.d.ts +6 -2
  26. package/dist/{jobs-DZ8DLLcU.js → jobs-1IkI4Lle.js} +2 -2
  27. package/dist/{jobs-DZ8DLLcU.js.map → jobs-1IkI4Lle.js.map} +1 -1
  28. package/dist/{openapi-generator-CAFKF36E.js → openapi-generator-BDpoKZQ9.js} +2 -2
  29. package/dist/{openapi-generator-CAFKF36E.js.map → openapi-generator-BDpoKZQ9.js.map} +1 -1
  30. package/dist/{query-parser-uqzkZ82i.js → query-parser-DUl8d557.js} +2 -2
  31. package/dist/{query-parser-uqzkZ82i.js.map → query-parser-DUl8d557.js.map} +1 -1
  32. package/dist/src-Br6ARbs6.js.map +1 -1
  33. package/dist/{src-DW1cQ_28.js → src-Caz7nREj.js} +2 -3
  34. package/dist/src-Caz7nREj.js.map +1 -0
  35. package/package.json +5 -5
  36. package/dist/auth-gzoRjnuh.js.map +0 -1
  37. package/dist/backup-DGu0v9Ku.js.map +0 -1
  38. package/dist/cron-scheduler-D47tdB9T.js.map +0 -1
  39. package/dist/src-DW1cQ_28.js.map +0 -1
package/README.md CHANGED
@@ -9,8 +9,8 @@ pnpm add @rebasepro/server
9
9
  ```
10
10
 
11
11
  ESM-only: `"type": "module"` with no CommonJS build, so it is loaded with
12
- `import`. `require()` of it resolves only on Node 22.12+, which supports
13
- `require(esm)`.
12
+ `import`. It needs Node `>=22.22.0` (its `engines` floor), where `require()`
13
+ of it resolves too: Node has supported `require(esm)` since 22.12.
14
14
 
15
15
  ## What This Package Does
16
16
 
@@ -21,7 +21,7 @@ This is the central orchestrator for any Rebase backend. It provides the framewo
21
21
  | Export | Description |
22
22
  |--------|-------------|
23
23
  | `initializeRebaseBackend(config)` | Main entry point. Wires up drivers, auth, storage, API routes, cron, and custom functions. Returns a `RebaseBackendInstance`. |
24
- | `rebase` | Server-side singleton (`RebaseClient`). Available after init. Admin-level access to data, auth, email, and storage. |
24
+ | `rebase` | Server-side singleton — a `RebaseServerClient` (from `@rebasepro/types`): the client without `data`, plus `dataAsAdmin`. Available after init. Admin-scoped access to data (RLS is evaluated as the service identity, not skipped), auth, email, and storage. |
25
25
  | `loadEnv()` | Validates `process.env` against the Rebase env schema (Zod). Auto-generates dev secrets. Supports `extend` for custom vars. |
26
26
  | `serveSPA(app, config)` | Mounts SPA static-file serving + index.html fallback on a Hono app. |
27
27
  | `RebaseBackendConfig` | Config type for `initializeRebaseBackend`. |
@@ -31,43 +31,61 @@ This is the central orchestrator for any Rebase backend. It provides the framewo
31
31
  | `z` | The runtime's own Zod instance. Build `loadEnv({ extend })` schemas with this one — a schema from a second copy of zod is silently ignored. |
32
32
  | `_setRebaseMock` / `_resetRebaseMock` | Test helpers to mock the `rebase` singleton (NODE_ENV=test only). |
33
33
 
34
- Also re-exports all abstract interfaces (`DatabaseAdapter`, `AuthAdapter`, `DataDriver`, etc.), API types (`HonoEnv`, `ApiConfig`), auth module, email module, storage module, history module, cron module, custom functions, logging utilities, and driver registry.
34
+ Also exports `HonoEnv`, the auth, email, storage, history and cron modules, custom functions, logging utilities, and the driver registry. The abstract driver interfaces (`DatabaseAdapter`, `AuthAdapter`, `DataDriver`, …) are not re-exported: import them from `@rebasepro/types`.
35
+
36
+ `@rebasepro/server/functions` is the portable surface a function file imports — `defineFunction`, the `requireAuth`/`requireAdmin` guards, `getUser`, `rebase` and the rest. The package also ships the `rebase-server` binary, which runs a built project bundle (`rebase-server ./dist-bundle`); it is what the `rebasepro/server` image executes.
35
37
 
36
38
  ## Quick Start
37
39
 
38
40
  ```typescript
39
- import { serve } from "@hono/node-server";
41
+ import { createServer } from "node:http";
42
+ import { getRequestListener } from "@hono/node-server";
40
43
  import { Hono } from "hono";
41
- import { initializeRebaseBackend, loadEnv, serveSPA } from "@rebasepro/server";
44
+ import { initializeRebaseBackend, loadEnv, serveSPA, type HonoEnv } from "@rebasepro/server";
42
45
  import { createPostgresAdapter } from "@rebasepro/server-postgres";
43
46
 
44
47
  // 1. Load and validate environment
45
48
  const env = loadEnv();
46
49
 
47
50
  // 2. Create Hono app + HTTP server
48
- const app = new Hono();
49
- const server = serve({ fetch: app.fetch, port: env.PORT });
51
+ const app = new Hono<HonoEnv>();
52
+ const server = createServer(getRequestListener(app.fetch));
50
53
 
51
54
  // 3. Initialize Rebase
52
55
  const backend = await initializeRebaseBackend({
53
56
  app,
54
57
  server,
55
- database: createPostgresAdapter({ connection: db, schema }),
58
+ database: createPostgresAdapter({ connection: db, schema: { tables, enums, relations } }),
56
59
  collections: myCollections,
57
60
  auth: {
58
61
  collection: defaultUsersCollection,
59
62
  jwtSecret: env.JWT_SECRET,
60
63
  allowRegistration: env.ALLOW_REGISTRATION,
61
64
  serviceKey: env.REBASE_SERVICE_KEY,
62
- google: { clientId: env.GOOGLE_CLIENT_ID },
65
+ google: env.GOOGLE_CLIENT_ID ? { clientId: env.GOOGLE_CLIENT_ID } : undefined,
66
+ },
67
+ storage: {
68
+ type: "s3",
69
+ bucket: env.S3_BUCKET!,
70
+ accessKeyId: env.S3_ACCESS_KEY_ID!,
71
+ secretAccessKey: env.S3_SECRET_ACCESS_KEY!,
72
+ },
73
+ // Storage is not under row-level security. In production the server refuses
74
+ // to boot storage without an access model: this hook (or `storagePolicies`),
75
+ // or `storagePublicRead: true` for a bucket that really is public.
76
+ storageAuthorize: async ({ key, user, operation }) => {
77
+ if (!user) return false;
78
+ const [ownerId] = key.split("/");
79
+ return ownerId === user.uid || operation === "read";
63
80
  },
64
- storage: { type: "s3", bucket: env.S3_BUCKET },
65
81
  functionsDir: "./functions",
66
82
  cronsDir: "./crons",
67
83
  });
68
84
 
69
85
  // 4. Optionally serve a frontend SPA
70
86
  serveSPA(app, { frontendPath: "./frontend/dist" });
87
+
88
+ server.listen(env.PORT);
71
89
  ```
72
90
 
73
91
  ## Related Packages
@@ -12,7 +12,7 @@
12
12
  import type { AuthRepository } from "./interfaces.js";
13
13
  import type { EmailService, EmailConfig } from "../email/index.js";
14
14
  import type { ResolvedAuthHooks } from "./auth-hooks.js";
15
- import type { AuthCollectionConfig } from "@rebasepro/types";
15
+ import type { AuthCollectionConfig, UserCreationFinalizeResult, UserCreationPrepareResult } from "@rebasepro/types";
16
16
  /**
17
17
  * Generate a cryptographically secure random password that meets strength requirements.
18
18
  *
@@ -78,3 +78,25 @@ export declare function finalizeAdminUserCreation(entity: {
78
78
  invitationSent: boolean;
79
79
  emailDeliveryFailed?: boolean;
80
80
  }>;
81
+ /**
82
+ * The step after a new user's row is written: who delivers the credentials,
83
+ * and what the create response says about it.
84
+ *
85
+ * A create hook that ran owns delivery. What it reported is the answer: the
86
+ * invitation it says it sent, and the temporary password it chose, which the
87
+ * admin has to see because it is the one the user will be told. The framework
88
+ * sends nothing of its own. Without a hook, `finalize` runs: the built-in
89
+ * invitation, or the generated password when email is not configured or fails.
90
+ *
91
+ * Both doors that create a user call this, the auth collection's REST route
92
+ * and `POST /admin/users`. The second used to call `finalizeAdminUserCreation`
93
+ * directly and read neither `hookHandledEmail` nor `invitationSent`, so it
94
+ * handled a hook's password as if the framework had generated it. With email
95
+ * configured it sent its own invitation, a second one when the hook had sent
96
+ * its own, and left the password out of the response. The decision lives here
97
+ * so that the two doors cannot disagree about it again.
98
+ *
99
+ * The result has exactly the fields a create response carries, with absent
100
+ * ones left out.
101
+ */
102
+ export declare function completeUserCreation(prepared: UserCreationPrepareResult, finalize?: (clearPassword: string | undefined) => Promise<UserCreationFinalizeResult>): Promise<UserCreationFinalizeResult>;