Skip to content

Capture auth email in development instead of refusing it - #12

Merged
fgatti675 merged 21 commits into
mainfrom
feat/email-dev-sink
Aug 22, 2026
Merged

fgatti675 merged 21 commits into
mainfrom
feat/email-dev-sink

Conversation

@fgatti675

Copy link
Copy Markdown
Member

First item of #4.

The first thing a new project could not do was log in. POST /auth/magic-link
and POST /auth/forgot-password answered 503 EMAIL_NOT_CONFIGURED until
someone went and found an SMTP host. The token was never the problem — it is
minted, stored and valid. Only delivery was missing.

Delivery is now the terminal:

⚠️  No SMTP is configured, so auth email is being captured here instead of sent.
ℹ️  [email] Sign in to Acme → [email protected]
             http://localhost:5173/auth/magic-link?token=…

Follow the link and the flow completes. Nothing about the token changes.

Why there is no new service

EmailConfig.sendEmail was already the extension point, so the sink is just one
of those. Templates, link-base resolution and isConfigured() all behave exactly
as they do with a real transport, and no auth route needed a new branch.

The gate is the security-relevant part

A captured password-reset mail carries a working reset token, so the buffer
is a credential store. Three conditions, all required, none configurable:

Condition Why
no SMTP_HOST a configured mail server always wins
NODE_ENV !== "production" see above — there is deliberately no setting that turns this on in production
absolute FRONTEND_URL otherwise the emailed link has no base and is dead in every mail client. This is the same condition assertEmailLinkBases already fails the boot on, so enabling the sink without it would turn a working no-email boot into a broken one

If any does not hold, resolveEmailOptions returns undefined exactly as before
and the routes report the missing service themselves. The existing 503 path is
untouched and still tested.

Deliberately not included

Showing captured mail in the panel — the second half of that checklist item —
would need an HTTP route serving live reset tokens. That deserves its own change
with its own thought about gating, so the buffer stays in-process and unexported
for now. The terminal is where a rebase dev user is already looking.

Verification

  • 19 new tests, including every branch of the gate (production, missing base,
    relative base, localhost:5173 without a scheme, SMTP-wins)
  • packages/server: 2147 passing, no regressions — the tests asserting
    EMAIL_NOT_CONFIGURED still pass, because that path still exists
  • pnpm typecheck clean, verify:docs clean

Not verified: a real end-to-end magic-link login driven through a browser. The
sink is asserted at the unit level.


Note on the diff size: cut from local main, which is 17 commits ahead of
origin/main and unpushed; those appear here until main is pushed. I did not
push main — a push to main publishes a canary.

fgatti675 and others added 18 commits August 20, 2026 23:41
`rebase cloud resources` printed a Plan line reading "legacy (no plan)" against
a column that no longer exists, and `rebase cloud billing` built a
`compute_<provider>_<vmSize>` lookup key — a price for a machine on a list this
platform does not buy from, dead since `vmSize` was removed on 2026-08-20 and
printing a bare label ever since.

Both now ask the control plane what the project's dials cost
(`POST /api/functions/pricing/quote`) and print the itemised answer. Best-effort:
an older control plane has no such endpoint, and a resources listing that failed
because a price could not be fetched would be worse than one without it.

Four dials the plans used to decide are flags now — `--replicas`, `--spot`,
`--scale-to-zero`, `--storage` — and `projects create` takes the same set, so a
project can be created at the size it needs rather than resized afterwards. It
also stops sending `vm_size`, which the control plane dropped.

`--spot false` is parsed to the boolean `false`, not the string. The string is
truthy, and would have put a project that asked for on-demand capacity onto
preemptible nodes at a third of the price with the restarts it declined.

Co-Authored-By: Claude Opus 5 <[email protected]>
`import { defineFunction } from "@rebasepro/server"` reaches the whole
framework — boot, the collection loader, the backup routes, the SPA server,
`@hono/node-server`, `ws`, `jsonwebtoken`, Drizzle. On Node that costs start-up
time and nothing else. It also means a function file can only ever resolve
inside a Node process, however portable the function's own code is, and that
import line is in every function file, template and doc page — so it is not a
thing that can be changed later without breaking everyone who wrote one.

The new entry point carries the authoring surface and nothing else. Its
published bundle imports exactly two things, `hono` and `hono/adapter`, and two
gates keep it that way: a test walks the import graph from source and names the
chain that broke the rule, and the build evaluates the emitted file in a `vm`
context holding web globals and no `process`, `Buffer` or `require` at all.
Both are mutation-tested. Importing from the package root still works and
behaves identically.

Also in the authoring surface, because each was a gap the same move exposed:

- Typed context accessors. `getUser(c)` returns `{ uid, roles, …claims }` with
  `roles` always an array, replacing the `c.get("user") as { uid: string;
  roles?: string[] } | undefined` cast that every example opened with — an
  assertion in a security-relevant position, and wrong for at least one auth
  path that reaches it. Plus `requireDriver`, `requireRole`, and guards that
  read the resolved identity rather than parsing a token (equivalent inside a
  function, where the middleware has already run; fail-closed outside one).

- `waitUntil(c, promise)`. A floating promise at SIGTERM is dropped mid-flight,
  so a rolling deploy could always lose a webhook the request had already
  answered 200 for; shutdown now drains tracked work, bounded, and reports what
  it could not wait for.

- Configuration read from the request: `getEnv`/`env`/`requireEnv`/
  `lazyResource`. `new Stripe(process.env.KEY!)` at module scope is a live
  defect today — it throws while the file is being imported, and the loader
  reports that as a *skipped function*, so the route 404s with the reason in a
  boot log. `rebase build` and `rebase doctor` now report those reads.

- `rebase build` records per-function portability in the bundle manifest, so a
  host can tell what is in a bundle without booting it.

`packages/server/functions/package.json` is a resolution redirect, not a
package: TypeScript's `moduleResolution: "node"` — which the scaffolded backend
uses — ignores `exports`, and without it the template's own import fails `tsc`
while running fine. `assert-build-output.mjs` verifies redirect targets for the
same reason it verifies entry points: a broken one is silent.

Docs rewritten in all six locales, with the anchors fixed (the machine
translations had kept the English ones), and the scaffolded template and the
three agent skills moved onto the new import. The API-surface gate now tracks
both entry points.

Co-Authored-By: Claude Opus 5 <[email protected]>
`tsc` writes relative specifiers into `.d.ts` exactly as the source wrote them
— extensionless, because the source is compiled by a bundler. Every package
here is `"type": "module"`, and under `moduleResolution: "nodenext"` an
extensionless relative specifier inside an ESM declaration file is an error.
TypeScript's response is the part that matters: it does not fail at the
consumer's import. It resolves the package, discards every declaration it could
not follow, and types the whole import `any`.

So there was no diagnostic anywhere near the cause. The first thing a consumer
saw was an implicit-any error in *their own file*, pointing at their code, in a
project that had done nothing wrong. Measured on `@rebasepro/server`: `bundler`
resolution sees 170 value exports, `nodenext` sees zero. It has been that way
for the whole life of the packages.

Fixed by appending the extension the declarations always needed — `./init` →
`./init.js`, and `./auth` → `./auth/index.js` where the target is a directory,
resolved against the filesystem rather than guessed, because a dangling
specifier degrades to `any` again. Not a trade: TypeScript maps `./x.js` onto
`./x.d.ts` under node10, bundler and nodenext alike, so nothing that worked
before stops working. 547 specifiers across the five packages that were built
to verify it; the step runs in all 21 published builds.

The rewriter refuses a `dist` whose realpath is outside its package. That is
what a git worktree's symlinked node_modules looks like, and without the guard
a build run there silently rewrites the primary checkout's published output.

`pnpm check:dts` is the gate, in verify.yml after the build. Nothing in this
repository could have caught the original defect, which is the more interesting
half: `pnpm typecheck`, the docs verifier and the template checks all map
`@rebasepro/*` onto source, and the API-surface gate reads a single `.d.ts` in
isolation. Every gate looked at something other than the artifact a stranger
installs. So this one installs each built package into a throwaway directory by
symlink, imports it, and compares the value exports the type checker can see in
each resolution mode — a question that needs no knowledge of any package's API,
and so keeps working as they change. It detects a single reverted specifier
(167 exports where 170 are expected) and names the file and line that caused it.

node10 is expected for package roots always, and for a subpath only where the
package ships a redirect directory — with `@rebasepro/server/functions` named
explicitly, since the backend `rebase init` scaffolds compiles with
`moduleResolution: "node"` and deleting that redirect would otherwise reduce
coverage silently rather than fail.

Co-Authored-By: Claude Opus 5 <[email protected]>
Building the fourteen packages this worktree had never built turned the gate
green across all 21 — and then a mutation test on `@rebasepro/admin` walked
straight past it. Reverting one specifier in its `dist/index.d.ts`, exactly the
defect the gate exists for, was not caught.

The discriminator was value exports: functions, consts, classes. That is the
right signal for a package whose surface is mostly values, and blind for one
whose surface is mostly types. `admin`'s broken re-export was `./types/index`,
which carries no values at all, so nothing it exported could go missing from a
count of values. `@rebasepro/types` — the package most consumers feel first —
was blind for the same reason along its whole surface.

Three changes:

- Read the diagnostics off the package's own declarations directly, rather than
  inferring damage from the export surface afterwards. TS2834/2835 is the exact
  nodenext rule being broken; it needs no inference and no export to be lost.
  This meant turning `skipLibCheck` off, because it suppresses precisely the
  errors under test.
- Compare *all* exports across resolution modes, not only the value ones.
- Stage every workspace package into the throwaway consumer, not just the one
  under test, so its layout matches an installed tree.

Turning declaration checking on surfaced a false positive immediately: a
sibling `@rebasepro/*` import inside a dependency's own `.d.ts` reported
TS2307 under node10. That is the probe's fault, not the package's — symlinking
means TypeScript resolves from the real repository path, so an upward lookup
never reaches the staged node_modules, while a real install has the whole
closure flat and resolves it without trouble. TS2307 now counts only for a
*relative* specifier, which is an emission defect; for a bare one it is a
question the staging cannot honestly answer.

Verified by mutation on three shapes it previously could not distinguish: a
value-heavy package (server), a pure-type package (types), and the type-only
re-export that started this (admin). Plus the node10 redirect deletion. All 21
packages now build and pass; the full run takes ~75s.

Co-Authored-By: Claude Opus 5 <[email protected]>
…osed

Both scripts were verified by running them and reading the output, which checks
that they work on today's input and nothing about the cases they were written
to handle. The gate had already stopped gating once within hours of being
written, so that is not a hypothetical standard.

Writing the fixtures found two more defects in the gate, neither visible by
inspection and both of which made it inert rather than wrong:

- The diagnostic filter was scoped to `/packages/` — the repository's own
  directory shape — so it silently exempted any package outside that path.
  Every fixture is outside it, which is why the first run of the new suite had
  four failures against a gate that passes the real packages. Scoped to the
  package under test now, which also makes the earlier cross-package false
  positive (a sibling's diagnostics reported under `@rebasepro/admin`)
  impossible by construction rather than by filtering.
- The prefix comparison used the literal path. TypeScript reports resolved
  paths, and on macOS `/var/folders/…` is a symlink to `/private/var/…`, so the
  comparison matched nothing for anything under the temp directory. Real
  arguments happened to match; fixtures never could.

The suites encode the shapes each script must tell apart. For the rewrite: a
directory specifier becoming `<dir>/index.js` rather than `<dir>.js` (guessing
dangles the re-export and restores the `any`), a string-literal type and an
ambient `declare module` name left alone (claims that lived in a comment and
nowhere else), idempotency, the symlinked-dist refusal, and a dangling
specifier failing loudly. For the gate: healthy, values-broken, types-broken,
a package with no values at all, subpaths with and without a node10 redirect,
and a `.css` export that is not a module.

Mutation-tested both suites. A naive `+ ".js"` breaks the directory test; a
regex-instead-of-AST collector breaks exactly the two tests guarding syntactic
position — and getting that mutation to be live took two attempts, because the
first one was mis-escaped and passed vacuously.

Wired into `test:gates`, which verify.yml already runs.

Co-Authored-By: Claude Opus 5 <[email protected]>
Portable @rebasepro/server/functions entry point, plus the .d.ts
resolution gates that keep it honest.
CLI prices resources by dial, with no plan left to name.
`frameworkVersion` meant the framework the runtime IMAGE ships in
`cloud status`, and the framework a BUNDLE installed in `cloud
deployments`. The image supplies the server and the bundle supplies the
driver, so the two are routinely different — printed under one name they
read as the control plane disagreeing with itself about a single number,
which is how it was reported. Now `imageFrameworkVersion` and
`builtAgainst`, spelled out where they print so neither can be misread.

Co-Authored-By: Claude Opus 5 <[email protected]>
…nning a version

The security table still named 0.10.x long after 0.10 stopped being the
latest minor, so it documented the opposite of the policy it meant. The
rule now sits above the table and the table only illustrates it.

Co-Authored-By: Claude Opus 5 <[email protected]>
…nto the site

copy_changelog.js only ever moved one file; copy_repo_docs.js mirrors any
repo-root document, copying rather than moving so existing references keep
resolving. check:generated gates the copies so they cannot drift.

Co-Authored-By: Claude Opus 5 <[email protected]>
The dropdown panels were tall enough to cover the hero: 558px for Product,
410px for Developers at 1440x900. Two of that height came from shape, not
content — a two-column grid capped at max-w-3xl, plus a full-width footer
row below it holding the overview/docs links.

Fold that footer into a third headed column (Explore, Resources), let the
grid span the panel's inner width, and tighten the row rhythm. Wider columns
also stop most descriptions wrapping to a second line, which pays again in
height: Product is 380px now, Developers 298px.

Mobile flattens columns into one list, so those links still appear there.

Co-Authored-By: Claude Opus 5 <[email protected]>
Ports the wall from the FireCMS site into this file's own structure:
INTRINSIC sizing, the shared class constants and the `product` field all
stay, and the new entries feed into them rather than around them.

Every new entry is tagged `product: "firecms"`. Unlike the existing
seventeen this is not a guess: each is a FireCMS Cloud customer verified
from signup and project activity, which is the evidence the `product`
comment asks for. The tally moves from 1 known / 17 unknown to 1 rebase /
26 firecms / 16 unknown, so the caption still needs its qualifier.

INTRINSIC values were read back with `new Image()` as the comment
instructs, and that mattered: a viewBox-only SVG reports a 300px natural
width, not its viewBox width, so seven entries would have carried numbers
2-6x too large had they been parsed from markup.

Also: eight marks were too dark once grayscale and opacity-60 composited
over the near-black ground (Team Global Express measured 21 against 153
for white ink); they were dark-coloured marks wrongly flagged
`invert: false`. MedicalMotion moves to the white asset already here.
withu.png was 84% transparent padding and overflowed its cell. Adds a
"companies" type, an optional textClass, matching brightness for text
fallbacks, and two-up logos on mobile.

Co-Authored-By: Claude Opus 5 <[email protected]>
Three-column mega-nav and the 26-logo client wall.

Co-Authored-By: Claude Opus 5 <[email protected]>
The checked-in files predate three generator changes: the users read
policy compares `id = rebase.uid()::uuid` rather than casting the column
to text, `orders` gained its `order` column, and the search block now
emits the immutability guard that refuses to re-apply when a generated
column's expression changed underneath it.

Regenerating twice produces identical output.

Co-Authored-By: Claude Opus 5 <[email protected]>
…write

The skills had drifted from the API they describe: `@rebasepro/ui` was
said to export `AddIcon`/`DeleteIcon`, which do not exist — it re-exports
lucide-react under its own names (`PlusIcon`, `Trash2Icon`); the studio
skill named `sideEntityController` rather than `sidePanelController`; and
the project-structure tree omitted `backend/functions/`. An agent
following any of these writes code that does not compile.

Co-Authored-By: Claude Opus 5 <[email protected]>
The first thing a new project could not do was log in. `POST /auth/magic-link`
and `POST /auth/forgot-password` both answered `503 EMAIL_NOT_CONFIGURED` until
someone went and found an SMTP host — and the token was never the problem. It is
minted, stored and valid. Only delivery was missing.

Delivery is now the terminal. The message is captured and its links are printed,
so the flow completes end to end on minute one with no account anywhere.

`sendEmail` was already the extension point, so this needs no new service and no
new branch in the routes: the sink is an `EmailConfig.sendEmail`, and everything
downstream — templates, link bases, `isConfigured()` — behaves as it does with a
real transport.

Three conditions, all required, none configurable:

  - no `SMTP_HOST`, so a configured mail server always wins;
  - `NODE_ENV` is not `production`. A captured password-reset mail carries a
    working reset token, which makes the buffer a credential store; there is
    deliberately no setting that turns this on in production;
  - an absolute `FRONTEND_URL`. Without one the emailed link has no base and is
    dead in every mail client — the same condition `assertEmailLinkBases`
    already fails the boot on, so enabling the sink there would turn a working
    no-email boot into a broken one.

When any of them does not hold, `resolveEmailOptions` returns `undefined` exactly
as before and the routes report the missing service themselves.

The buffer is capped, in-process and unexported over HTTP. Showing captured mail
in the panel would need a route that serves live reset tokens; that is worth
doing carefully and separately.
@fgatti675 fgatti675 mentioned this pull request Aug 21, 2026
2 of 5 tasks
…r the build

Every pull request has been failing since the portable functions entry point
landed:

    FAIL baas
      backend/functions/hello.ts(7,8): error TS2307:
      Cannot find module '@rebasepro/server/functions'

`check:templates` and `check:eject` compile a *scaffolded project*, which
resolves `@rebasepro/*` through node_modules and its `exports` map. `./functions`
points at `dist/functions/index.d.ts`, so before `pnpm run build` it resolves to
nothing and the baas preset — whose `hello.ts` now imports it — fails to compile.
Both checks ran before the build step.

Nothing caught it locally because a developer's checkout has a `dist` lying
around from the last build; CI installs and has none. Reproduced by deleting
`packages/server/dist/functions` and running the check, which fails identically.

Moved both after `Build packages`, where `check:api-surface` already sits for
exactly this reason — its comment says "Reads dist/index.d.ts, hence after the
build". The cost is that a broken template is reported a few minutes later; the
alternative is a gate that cannot pass on a clean checkout.

Verified the rest of the lane separately: core-types, types-headless, baas-types,
test-scripts, control-chars, untranslated, hooks, unused, api-surface, dts,
deps, headless, names, derived-names and verify:docs all pass on this commit, so
this is the only thing standing between main and a green run.
@fgatti675

Copy link
Copy Markdown
Member Author

Merge-order note: this conflicts with #19 (bot protection) in three files — boot/options.ts and init.ts import blocks, and a new ### section at the same anchor in backend/authentication.md.

All additive; the resolution is keep both sides. Verified together on integration/tonight: 151 suites / 2279 tests and every gate clean. Whichever lands second needs that one resolution.

`check:api-surface` reads `dist/index.d.ts`, so it only sees a new export after
a build — and CI builds before it runs. The baseline had not been regenerated,
so this branch failed that step while passing every gate that reads source.

Additions only: createDevEmailSink, extractLinks, CapturedEmail, DevEmailSink.
@fgatti675
fgatti675 merged commit 7f3574b into main Aug 22, 2026
2 checks passed
@fgatti675
fgatti675 deleted the feat/email-dev-sink branch August 22, 2026 10:41
fgatti675 added a commit that referenced this pull request Oct 6, 2026
…s it can attribute, read as you

The result table's row actions named the collection the rows came from by
reading the script's text, comments included. A script that read
`authors` and returned `posts` got "Open Authors #12" on a post row,
which opened the author with that id. A collection mentioned only in a
comment was enough to trigger it. Detection also read the tab as it was
at render time, not the code that ran. And the entity editor those
actions open works as the signed-in administrator, including for rows
fetched as the user picked in "Run as".

The row actions, and the "Collections:" bar that goes with them, now
appear only when the code that ran names exactly one collection outside
its comments and ran as the signed-in user.

Findings F8, F9 of the Studio sweep.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant