Skip to content

Commit b36eaac

Browse files
committed
fix(mailbox): default SSE bus; keep it out of the Quickstart
1 parent f6f50f4 commit b36eaac

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,9 @@ bun add @corbits/mailbox @intx/log @intx/hub-api @intx/db @intx/hub-sessions hon
1515
**Run the host this package ships:** [`examples/reference-host`](./examples/reference-host). That file calls `createApp` from `@intx/hub-api`, then this:
1616

1717
```ts
18-
const bus = createInMemoryMailboxEventBus();
19-
// SSE only (inbox live updates). Mail itself is Postgres, not this bus.
20-
const deliveries: {
21-
raw: Uint8Array;
22-
from: string;
23-
to: string[];
24-
messageId: string;
25-
}[] = [];
26-
2718
const api = new Hono<AppEnv>();
2819
mountMailbox(api, {
29-
db, // hub.db — one drizzle pool, mailbox schema on the same Postgres
30-
bus,
20+
db, // hub.db — Postgres. Mail is not in-memory.
3121
resolvePrincipal: (ctx) => {
3222
const user = (ctx as Context<AppEnv>).get("user");
3323
if (!user) return null;
@@ -43,7 +33,7 @@ mountMailbox(api, {
4333
app.route("/api", api);
4434
```
4535

46-
`db`, `app`, `AppEnv`, and `getSession` are created in that same file (`createDB` + `createApp`). `deliver` in the example **appends to `deliveries`** so tests can assert without SMTP. Production replaces that push with the hub’s real send of `message.raw`.
36+
`db`, `app`, `AppEnv`, `deliveries`, and `getSession` are in [`examples/reference-host`](./examples/reference-host). Mail is Postgres. `bus` is optional: default is an in-process **SSE** fan-out (not the store). Pass `bus` only if several hub processes must share live inbox events.
4737

4838
Inbox paths: `GET/POST /api/me/inbox…`.
4939

src/mount.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { Thread } from "@intx/types/runtime";
88
import type { MailboxDb } from "./db.js";
99
import type { NativeMailboxStore } from "./native-store.js";
1010
import {
11+
createInMemoryMailboxEventBus,
1112
publishMailboxEvent,
1213
type MailboxEvent,
1314
type MailboxEventBus,
@@ -30,7 +31,12 @@ export type OutgoingMailboxMessage = {
3031

3132
export type MountMailboxOpts = {
3233
db: MailboxDb;
33-
bus: MailboxEventBus;
34+
/**
35+
* SSE live-update bus only. Mail is Postgres. Defaults to an in-process
36+
* bus (one hub process). Pass a shared bus if several hub processes must
37+
* fan the same inbox events.
38+
*/
39+
bus?: MailboxEventBus;
3440
resolvePrincipal: (
3541
ctx: unknown,
3642
) => Promise<ResolvedPrincipal | null> | ResolvedPrincipal | null;
@@ -202,7 +208,8 @@ export function mountMailbox<E extends Env>(
202208
app: Hono<E>,
203209
opts: MountMailboxOpts,
204210
): Hono<E> {
205-
const { db, bus, resolvePrincipal, senderAddressFor, deliver } = opts;
211+
const { db, resolvePrincipal, senderAddressFor, deliver } = opts;
212+
const bus = opts.bus ?? createInMemoryMailboxEventBus();
206213
const heartbeatIntervalMs =
207214
opts.heartbeatIntervalMs ?? DEFAULT_HEARTBEAT_INTERVAL_MS;
208215
if (!Number.isFinite(heartbeatIntervalMs) || heartbeatIntervalMs <= 0) {

0 commit comments

Comments
 (0)