HomeChallengesRepsProblemsLeaderboardTake a challenge

Middleware that adds to the request

Anyone can change any order, and the audit line reaches for a vendor nothing ever attached, through (req as any). Write requireVendor: check the key, attach the vendor to the request through Express’s own types, and gate only the routes that change things.

Advanced10 min on the clock5 graded checks · 100 pointsTyped Express
Graded by running your code against real cases.

What you build

  • Read the x-vendor-key header; 401 if it is missing or unknown
  • Attach the vendor as req.vendor, declared by module augmentation
  • Apply requireVendor to POST and PATCH only
  • Narrow req.vendor in the handler without !
  • Write the audit line with the vendor’s name

Done means

The gate works both ways, reads stay open, the type is extended rather than escaped, and the audit line names the vendor.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. No key or a wrong key is a 401; a valid key continues+25Authentication and tokens
  2. GET stays open; POST needs a key+15Authentication and tokens
  3. Request is extended, not escaped+20TypeScript basics
  4. req.vendor is narrowed without !+20TypeScript basics
  5. The audit line names the vendor+20Authentication and tokens

What it teaches

The rest of Typed Express