feat(offline): cache the trip's area so place search works with no network

An offline instance had the trip's own places and nothing else, so "find
a pharmacy near the hotel" had nothing to answer from: every lookup went
to a server.

The index can hand over a bounding box in one request, so it does, once,
next to the map tiles. A trip to Rostock is roughly a megabyte, refreshed
only when the trip's area actually moves. Search and autocomplete fall
back to it at the API layer, which is why all ten call sites got the
offline path without any of them learning about it, and the answer says
`source: 'offline-cache'` rather than pretending to be live.

Country packages stay what they were: a SQLite file for anyone who would
rather run their own copy of the service. A browser cannot query one
without shipping a WASM SQLite, and Germany alone would not fit in
IndexedDB, so that door stays where it belongs. /v1/packages lists them,
because "you can leave" only means something if the door is visible.
This commit is contained in:
Maurice
2026-09-06 00:36:53 +02:00
committed by Maurice
parent 715993feaf
commit 87a765b763
10 changed files with 710 additions and 2 deletions
@@ -74,6 +74,40 @@ describe('MapsController (parity with the legacy /api/maps route)', () => {
});
});
describe('GET /area', () => {
const BOX = { minLat: 54, minLng: 12, maxLat: 54.2, maxLng: 12.3 };
it('delegates a valid box with parsed numbers', async () => {
const placesInArea = vi.fn().mockResolvedValue({ results: [{ name: 'x' }], truncated: false });
const res = await makeController({ placesInArea }).area('54', '12', '54.2', '12.3');
expect(res).toEqual({ results: [{ name: 'x' }], truncated: false });
expect(placesInArea).toHaveBeenCalledWith(BOX, 2000);
});
it('400 when the box has a non-finite value', async () => {
const placesInArea = vi.fn();
expect(await thrown(() => makeController({ placesInArea }).area('x', '12', '54.2', '12.3'))).toEqual({
status: 400,
body: { error: 'A valid bbox (minLat, minLng, maxLat, maxLng) is required' },
});
expect(placesInArea).not.toHaveBeenCalled();
});
it('caps the limit rather than passing a caller number straight through', async () => {
const placesInArea = vi.fn().mockResolvedValue({ results: [], truncated: false });
await makeController({ placesInArea }).area('54', '12', '54.2', '12.3', '999999');
expect(placesInArea).toHaveBeenCalledWith(BOX, 5000);
});
it('says the index is unavailable instead of failing the caller', async () => {
// This runs inside an offline sync. A null here means the index is off or
// unreachable, and the client caches nothing and carries on.
const placesInArea = vi.fn().mockResolvedValue(null);
const res = await makeController({ placesInArea }).area('54', '12', '54.2', '12.3');
expect(res).toEqual({ results: [], truncated: false, unavailable: true });
});
});
describe('GET /pois', () => {
it('400 when category is missing', async () => {
const pois = vi.fn();