Skip to content

fix: restore booking flow + remember last to-Jerusalem station#3

Open
yomach wants to merge 1 commit into
idshklein:mainfrom
yomach:fix/api-2026-05
Open

fix: restore booking flow + remember last to-Jerusalem station#3
yomach wants to merge 1 commit into
idshklein:mainfrom
yomach:fix/api-2026-05

Conversation

@yomach
Copy link
Copy Markdown

@yomach yomach commented May 9, 2026

Summary

The booking flow has been broken since rail.co.il rotated its API a few days ago. This PR restores it and adds a small UX win.

Fix — frontend (app.js)

Three things changed upstream:

Before After
OTP send path /TripReservation/SendOtp /Otp/Send
OTP verify path /TripReservation/VerifyOtp /Otp/Verify
Order body — sourceChannel: "web" required gone
Order body — systemTypeId: "2" required
Order body — type "" "phone"
All bodies — languageId "Hebrew" required
Order response success data.result.result (string) data.result.data.confirmationCode + data.result.success (bool)

Both call-sites (handleSubmit, handleOtpConfirm) updated to read the new envelope.

Fix — proxy (cloudflare-worker/worker.js)

  • UPSTREAM trimmed to /common/api/v1 so the FE can address /Otp/* and /TripReservation/* under one base.
  • Set-Cookie rewrite to strip Domain=rail.co.il. The upstream now (or always?) emits cookies with Domain=rail.co.il, which browsers reject on the proxy host (*.workers.dev). Without the rewrite, the authToken cookie set by Otp/Verify never persists on the proxy origin and the subsequent OrderSeatForTrip falls back to a 401 loop.

Feature — remember last "אל ירושלים" station

Most riders use the same home station every time. When direction is to-jerusalem, the picked station is stored in a 1-year cookie (lastToJerusalemStation) and used as the default on the next visit. The remembered value beats the previously-shown dropdown value (which after a direction toggle is usually the from-jerusalem destination — that would otherwise mask the saved preference). Not applied to from-jerusalem since destinations vary much more there.

Misc

  • .wrangler/ added to .gitignore (wrangler dev's local state cache).

Test plan

  • npm test (7/7 pass — no test changes; existing tests still cover booking-helpers and the worker status page).
  • End-to-end: npx wrangler dev + a static server, full booking flow with a real phone, OTP sent, code verified, confirmationCode rendered as QR.
  • Direction toggle: pick a station with direction "אל ירושלים", reload, toggle back to "אל ירושלים" → station is restored. Toggle to "מירושלים" first → remembered station does not leak as the from-jerusalem default.

🤖 Generated with Claude Code

@yomach
Copy link
Copy Markdown
Author

yomach commented May 9, 2026

@idshklein
I saw you wrote you're not maintaining it, but it is very useful, and it broke a week ago, so...

yomach added a commit to yomach/train_ticket that referenced this pull request May 9, 2026
…L_DEV.md

Personal-fork dev helpers that aren't part of the upstream PR
(idshklein#3). Lets the FE on http://localhost:8000 talk to a
wrangler-dev worker on http://localhost:8787 without touching the
production code path.

- app.js: API_BASE reads from localStorage("apiBase"), falling back to
  the production worker URL. No-op for prod users.
- worker.js: ALLOWED_ORIGINS expanded with localhost:8000 / 127.0.0.1:8000;
  added Vary: Origin since the allowed list is now multi-valued.
- LOCAL_DEV.md: architecture, run-locally recipe, diagnosis guide for
  the next time rail.co.il rotates its API.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@yomach yomach force-pushed the fix/api-2026-05 branch from e411ea7 to efd3f00 Compare May 10, 2026 06:59
The upstream rail.co.il API rotated routes, request bodies, and the
response envelope, breaking the entire booking flow.

API changes (frontend):
- POST /TripReservation/SendOtp        → /Otp/Send
- POST /TripReservation/VerifyOtp      → /Otp/Verify
- /TripReservation/OrderSeatForTrip stays, but its body now requires
  systemTypeId:"2" (replaces sourceChannel:"web"), type:"phone"
  (replaces type:""), and languageId:"Hebrew".
- All three OTP/order bodies now require languageId:"Hebrew".
- Response envelope changed: result.result (string) →
  result.data.confirmationCode, with a sibling result.success boolean.
  Both call-sites (handleSubmit + handleOtpConfirm) updated.

Proxy:
- UPSTREAM trimmed to /common/api/v1 so the FE can address both /Otp/*
  and /TripReservation/* under one base path.
- Strip Domain=rail.co.il from Set-Cookie headers before forwarding.
  Browsers reject foreign-domain cookies on the proxy host, which
  silently broke the authToken round-trip.

Misc:
- .wrangler/ added to .gitignore (wrangler dev local state cache).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@yomach yomach force-pushed the fix/api-2026-05 branch from efd3f00 to cf88d12 Compare May 10, 2026 07:02
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