Skip to content

refactor(geocoder): converge the 3 forward-geocode paths onto one shared createGeocoder client#59

Merged
tompscanlan merged 3 commits into
flo-bit:mainfrom
tompscanlan:fix/om-qp3y-geocoder-convergence
Jul 7, 2026
Merged

refactor(geocoder): converge the 3 forward-geocode paths onto one shared createGeocoder client#59
tompscanlan merged 3 commits into
flo-bit:mainfrom
tompscanlan:fix/om-qp3y-geocoder-convergence

Conversation

@tompscanlan

@tompscanlan tompscanlan commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Converges the three server-side forward-geocode paths onto the one shared createGeocoder client so there's a single source of truth for the endpoint URL, User-Agent, key handling, and error handling.

Before

Three separate forward-geocoders had drifted apart:

  1. Event-editor endpoint (/api/geocoding) — its own hardcoded Nominatim URL + UA, returned the raw upstream object, logged every request via a stray console.error.
  2. Near-me search (geocode.ts) — public Nominatim, format=jsonv2, own result shape, deliberately skipped GEOCODER_URL.
  3. Bulk drip (createGeocoder) — the only path with LocationIQ key handling, 404-as-no-match, and WGS84/limit safety.

After

  • All three call sites use one createGeocoder client — no path defines its own /search URL or UA literal.
  • GeoPoint gained optional label (display_name), address (addressdetails), osmType, osmId, so each caller gets what it needs without a second client.
  • /api/geocoding returns a normalized {lat, lng, label, address, osmType, osmId} shape (no more raw-object leak), 404 on no-match, auth gate kept, stray happy-path console.error removed.
  • One env-driven User-Agent everywhere (resolveGeocoderUserAgent).
  • Decision: Nominatim by default, env-overridable to keyed LocationIQ via existing GEOCODER_URL/GEOCODER_KEY — applied to all three call sites. The key stays server-side only; the client only ever receives coords/label.

Verification

  • apps/web pnpm test: 175 passed / 4 skipped (21 files).
  • apps/web pnpm check: 0 errors.
  • New/updated tests cover each call site through the shared client (normalized shape, no-raw-leak, shared URL+UA, key appended when configured, 404 no-match, auth gate).

Follow-up to the earlier near-me geocode dedup, which converged only geocode.ts.

Extend the shared createGeocoder result so interactive callers get a display
label and structured address parts without a second client, and request
addressdetails=1. Prep for converging the three forward-geocode paths (om-qp3y).
Near-me forward geocode now delegates to the one shared client, so it honors a
configured GEOCODER_URL/GEOCODER_KEY (key appended server-side) instead of a
hardcoded public-Nominatim URL. Drops the duplicate fetch/parse and the stale
'does not honor GEOCODER_URL' comment (om-qp3y).
… shape

/api/geocoding now calls createGeocoder (one URL + User-Agent + key handling)
and returns a normalized {lat,lng,label,address,...} shape instead of the raw
Nominatim object; drops the stray console.error, keeps the auth gate. Updates
the two consumers (resolveGeoLocation, LocationSection) to the normalized keys
(om-qp3y).
@tompscanlan tompscanlan marked this pull request as ready for review July 4, 2026 23:19
@tompscanlan tompscanlan merged commit e84d0af into flo-bit:main Jul 7, 2026
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