feat(geocoding): add server-side geocoding for AI agents / API usage#73
Closed
feat(geocoding): add server-side geocoding for AI agents / API usage#73
Conversation
…hook for agent/API usage
The geocoding plugin was purely UI-driven, requiring browser-based Google Places
autocomplete. This made it unusable for AI agents and API consumers.
Adds:
- GET /api/geocoding/search?q=<address> authenticated endpoint with custom access function support
- beforeChange hook that auto-geocodes a `{field}_address` text string server-side
- geocodeAddress() service using Google Geocoding HTTP API
- 24 unit tests covering service, endpoint, hook, plugin, and field integration
https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
Explains the two server-side geocoding mechanisms (search endpoint and beforeChange hook) with example requests so agents and API consumers know how to populate geocoding fields without the browser UI. https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
…fig, hide address field
- Remove `serverGeocoding` field config — the address field and
beforeChange hook are now always included on every geocodingField
- Remove duplicate API key from hook — reads it from the plugin config
via `req.payload.config.custom` instead
- Hide `{field}_address` text field from the admin UI (`admin.hidden: true`)
since it's only for API/agent usage
- Update README to reflect the simpler setup (no extra config needed)
- Add test for missing API key error
https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
…tion signature
- Endpoint path: /geocoding/search → /geocoding-plugin/search
(matches alt-text-plugin/ and translator/ conventions)
- Access function signature: (req) → ({ req }) to match other plugins
- Remove redundant sentence from README
https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
…v project + SQLite Major changes: - Set up dev project test infrastructure (vitest, SQLite adapter, vite.config) - Add Articles collection with Lexical editor block containing geocoding field - Write 10 integration tests against a real Payload instance: - Field structure: point/geodata in top-level, group, and array fields - Server-side geocoding: auto-geocode via location_address on create/update - Lexical block: geocoding field inside a Lexical editor block - Endpoint: verify geocoding-plugin/search is registered - Fix parallel field processing bug: use req.context to share a cached geocoding promise between geodata and point field beforeChange hooks (Payload processes row fields concurrently via Promise.all) - Remove old mongoose-based plugin.spec.ts https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
- Add test-geocoding job to CI workflow (SQLite only) - Add test/test:sqlite scripts to geocoding package.json - Apply lint:fix and prettier formatting to all source files https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
- Remove duplicate GeocodingEndpointAccess type from geocodingSearch.ts, import from GeoCodingPluginConfig.ts instead - Add virtual: true to the address field so no DB column is created - Keep beforeChange hook as fallback for contexts where virtual doesn't apply (Lexical blocks store fields as JSON) https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
…ual field bug The address field uses virtual: true which correctly prevents DB persistence for regular fields. Inside Lexical blocks, the virtual flag is ignored because blocks serialize all fields as JSON — this is a Payload bug, not something to work around with a hook. https://claude.ai/code/session_01Ja3JVC48ozET22Z7yJkyY6
Contributor
Author
|
Closing in favor of #78 — the server-side geocoding features (endpoint, beforeChange hooks, tests, CI) have been merged into the 0.3 branch ( Generated by Claude Code |
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
The geocoding plugin was purely UI-driven (browser-based Google Places autocomplete), making it unusable for AI agents and API consumers. This PR adds two server-side geocoding mechanisms:
GET /api/geocoding-plugin/search?q=<address>— Authenticated endpoint for server-side geocoding with custom access function support{field}_addressbeforeChange hook — EverygeocodingFieldnow includes a hidden_addresstext field; submitting an address string via the API auto-geocodes it and populates the point + geodata fieldsgeocodeAddress()exported service — Can be used directly in custom server-side codeKey implementation details
req.user(authenticated), supportsgeocodingEndpoint.access: ({ req }) => booleanfor custom access controlreq.payload.config.custom) — no duplicate config neededadmin.hidden: true) and cleared on save (beforeChange: [() => null])req.contextto cache geocoding promises so the geodata and point field hooks share a single API call (Payload processes row fields in parallel viaPromise.all)Files added/changed
src/services/googleGeocoding.ts— Server-side Google Geocoding HTTP API clientsrc/endpoints/geocodingSearch.ts— Authenticated search endpointsrc/hooks/geocodeBeforeChange.ts— Geodata + point field beforeChange hooks with shared cachingsrc/fields/geocodingField.ts— Always includes address field + hookssrc/plugin.ts— Registers endpoint, passes custom access functionsrc/types/— Updated config types withGeocodingEndpointAccessdev/— Full integration test setup with SQLite, Articles collection with Lexical block.github/workflows/ci.yml— Addedtest-geocodingCI jobREADME.md— New "Usage with AI Agents / API" sectionTest plan
_addresson create and updatetsc --noEmit)test-geocodingjob passes