Conversation
- auth middleware: fix HTTP method casing ("post" -> "POST") so POST /users
is correctly treated as a public route
- users route: add missing badRequest import (was causing a runtime
ReferenceError on invalid POST bodies)
- shared types: rename User.userName -> username to match the API and test
contract
- shared pagination: implement the paginate() stub (1-indexed pages, correct
slice/total/totalPages, empty-array yields totalPages 0) and guard against
non-finite page/size
- tsconfig: add "types": ["bun-types"] so bun:test and process resolve under
typecheck (no new dependencies added)
All 22 tests pass and tsc --noEmit is clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all failing tests and type errors in the multi-package TypeScript HTTP API repo.
bun test→ 22 pass / 0 fail.bunx tsc --noEmit→ clean (exit 0).Root causes fixed
packages/api/src/middleware/auth.ts)"post", soPOSTrequests never matched and fell through to the token check["GET", "post"]→["GET", "POST"](RFC 7231 uppercase methods)packages/api/src/routes/users.ts)badRequestimport → runtimeReferenceErroron invalid POST bodiesbadRequestto the../lib/errorsimport (matchingposts.ts)packages/shared/src/types.ts)User.userNameinconsistent with the API/test contract, which usesusernameuserName→username(only non-comment occurrence in the repo)packages/shared/src/utils/pagination.ts)paginate()was an unimplemented stub (throw "not implemented")total/totalPages, empty array →totalPages 0; hardened against non-finitepage/sizetsconfig.json)typesarray, sobun:testmodule andprocessglobal didn't resolve undertsc"types": ["bun-types"](already-installed package; no new dependencies)Constraints honoured
bun-typeswas already present; only wired into tsconfig)Assumptions
usernamerather than renaming the route touserName, because the tests readbody[0].usernameoff the response — renaming the route would satisfy tsc but break runtime assertions.BUG:/TODO:source comments that would misdescribe the corrected code were removed.Notes for follow-up (out of scope)
POST /usersis now public per the documented policy/tests — an unauthenticated write accepting an email address. If intended as self-service registration, usual mitigations (rate limiting, APP 5 collection notice, server-side email validation) apply.paginate()has no production callers yet; boundary validation ofNumber(query)params (reject malformed with 400) is still needed at the route layer.Verification