feat(search): compose Google and Photon through an explicit provider service

This commit is contained in:
Sameh Khamis committed 2026-09-12 15:38:43 -07:00
commit 57d7f9fc23
30 files changed
+1621 -151

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import {
createPlaceSearch,
createGoogleGeocoder,
createPhotonGeocoder,
} from '../search/index.js';
/** Google first when configured, then keyless Photon; transport stays local to setup. */
export function createStandalonePlaceSearch({
resolveApiKey,
fetchImpl = (...args) => fetch(...args),
signal,
} = {}) {
return createPlaceSearch({
signal,
providers: [
createGoogleGeocoder({
request(query, { bias, signal }) {
const key = resolveApiKey?.();
if (!key) return null;
const url = new URL(
'https://maps.googleapis.com/maps/api/geocode/json',
);
url.searchParams.set('address', query);
url.searchParams.set('key', key);
if (bias) url.searchParams.set('bounds', bias);
return fetchImpl(url.toString(), { signal });
},
}),
createPhotonGeocoder({ fetchImpl }),
],
});
}