Scenario
The checkout service for a small storefront intermittently creates duplicate orders. Customers on flaky connections retry their checkout request — sometimes by tapping the button again, sometimes because a client library retries automatically — and each retry produces a new order and a new charge.
Clients already send an Idempotency-Key header on POST /orders. The contract they expect:
- Two requests with the same
Idempotency-Keymust result in exactly one order. The second request returns the same order as the first. - This must hold even when the requests arrive concurrently.
- Requests with different keys (or no key) create independent orders.
- The returned order for a replayed key is the original order — its amount and items do not change, whatever the replay contains.
Your task
Fix the idempotency defect in src/orders.js and src/store.js. Keep the existing request and response behavior for POST /orders.
The workspace starts the checkout service on port 8080 before the assessment begins.