Skip to content

refactor(server): QuotaSlot brand + shared CompleteAuthRoute factory#66

Merged
allisson merged 1 commit into
mainfrom
improve-codebase
May 22, 2026
Merged

refactor(server): QuotaSlot brand + shared CompleteAuthRoute factory#66
allisson merged 1 commit into
mainfrom
improve-codebase

Conversation

@allisson
Copy link
Copy Markdown
Owner

Summary

  • QuotaSlot brand: reserveItemQuota(tx, vaultId, adding) mints an opaque QuotaSlot carrying vaultId; items.createWithVersion and items.batchCreateWithVersion now require one. Same brand-as-obligation pattern as ProofOfSession / TxDb — item inserts can no longer skip the lock + count + limit assertion at the type level. Vault-count enforcement (assertVaultQuota) stays a throw-or-pass primitive since it has a single caller.
  • registerCompleteAuthRoute factory: the three auth ceremonies that end in a SessionIssuance (completeLogin, completeRegistration, completeRecovery) shared the same asTx → service → sendAuthFailure → session.attachCookie → 200 reply shape. Hoist that into routes/auth/complete-route.ts; each route file shrinks to its variance (path, schema, rate limit, service-call shape).
  • ADR 0009: documents why uniformly-shaped thin vault-resource services (FoldersService etc.) are kept rather than dissolved into routes — the seam holds the access-check-inside-tx ceremony, and the uniformity is the AI-navigability payoff. Closes the recurring "why is this one so thin?" review thread.
  • CONTEXT.md: new sections for QuotaSlot, CompleteAuthRoute, and EncryptedVaultItemMapper.

Test plan

  • make ci green (lint + tsc + format + tests)
  • make test:server:unit — quota and auth-route unit tests pass
  • make test:server:integration — end-to-end login / register / recovery still issue session cookies; item create + batchCreate still enforce quota under concurrent writes

🤖 Generated with Claude Code

Promote two repeated conventions into function-signature obligations,
matching the existing ProofOfSession/TxDb pattern:

- QuotaSlot brand: reserveItemQuota mints a slot carrying vaultId;
  items.createWithVersion / batchCreateWithVersion require one. Item
  inserts can no longer skip the lock-count-limit assertion.
- registerCompleteAuthRoute: factor the asTx → service → sendAuthFailure
  → session.attachCookie → 200 reply seam shared by completeLogin,
  completeRegistration, completeRecovery into one helper.

Also adds ADR 0009 documenting why uniformly-shaped thin vault-resource
services (e.g. FoldersService) are kept rather than dissolved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@allisson allisson merged commit 27d4f96 into main May 22, 2026
1 check passed
@allisson allisson deleted the improve-codebase branch May 22, 2026 14:08
@allisson allisson mentioned this pull request May 22, 2026
3 tasks
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