Cars: create a car from a manufacturer service, with a per-car data tab

A car can now be imported straight from the account its owner already has
with the manufacturer, and every reading that service exposes shows up on
the car's own tab. MyToyota is the first provider.

API Server — internal/api/vehicleproviders.go adds a generic layer over a
plugin that can enumerate vehicles and read data about them. Adding the
next manufacturer is one vehicleSource adapter plus a line in
vehicleSources(): no new endpoints, no Web App changes.

  GET  /api/vehicle-providers                     providers + connect state
  GET  /api/vehicle-providers/{p}/vehicles        the caller's vehicles
  POST /api/vehicle-providers/{p}/import          create a car from one
  GET  /api/cars/{id}/provider                    live snapshot for the tab
  POST /api/cars/{id}/provider                    link / unlink a car
  POST /api/cars/{id}/provider/sync               re-apply provider data

Two properties shape it. Credentials are always the caller's own, resolved
through the same global -> org -> user cascade as the integration settings,
so a shared car shows provider data only when that vehicle is on the
viewer's account — the owner's credentials are never borrowed. And upstream
shapes are not modelled: these are unofficial APIs, so the layer searches
payloads by key name for the readings worth promoting (odometer, fuel,
battery, range) and flattens the rest to dotted key/value pairs alongside
the raw JSON. A renamed field costs one blank value, not a broken page.

The Toyota gate and its wording now live in toyotaSource, so the older
/api/integrations/toyota/vehicles endpoint and the new ones cannot drift.

Manager.InvokeBatchWith shares one transient plugin instance across a batch
of actions. The tab pulls seven capabilities, and InvokeWith builds a fresh
instance per call — which for a connector that authenticates lazily means a
fresh OAuth login per call. Batching logs in once.

cars gains provider + provider_vehicle_id (schema.go and
setup-pocketbase.mjs both). carPayload deliberately omits them, so an
ordinary car edit can neither reassign the car nor break its link;
carProviderPayload writes the link on its own.

Web App — Dashboard grows an "import from service" button beside "add car",
shown only once an account is connected, opening CarImportModal: pick the
vehicle, choose what to pull (identity / fuel type / dates / odometer, all
on by default), import. ProviderPanel becomes the car's first tab, ahead of
Information, labelled with the service: headline readings, the vehicle
record, one card per capability with its raw response, and an offer to take
the provider's odometer when it is ahead of the stored one. On an unlinked
car the tab instead offers to link it, VIN-matched. Info stays the default
selection — landing on the provider tab would fire a login on every car
page view. Full en/pl/da translations.

Tests cover the payload walking, Toyota normalization, import-selection
defaults, and — through the real handler chain against a stand-in
PocketBase — that every route is registered and that a closed gate is soft
on a listing (200 + a reason the UI can show) but hard on a write (4xx, so
a caller cannot read the reply as a created car).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
tajniak81andClaude Opus 5 committed 2026-08-17 14:13:11 +02:00
1 parent 47a9aef466
commit 358ee68f94
23 files changed
+2983 -43

No files matched your search

+70
View File
@@ -11,6 +11,7 @@
"saved": "Zapisano ✓",
"loading": "Ładowanie…",
"edit": "Edytuj",
"open": "Otwórz",
"remove": "Usuń",
"delete": "Usuń",
"done": "Gotowe",
@@ -89,6 +90,7 @@
"title": "Twoje samochody",
"subtitle": "Przegląd serwisowy i historia napraw.",
"addCar": "Dodaj samochód",
"importCar": "Importuj z serwisu",
"empty": "Nie masz jeszcze samochodów. Kliknij {action}, aby zacząć.",
"shared": "Udostępniony",
"sharedReadOnly": "Udostępniony · tylko do odczytu",
@@ -246,6 +248,7 @@
"sharedReadOnly": "Udostępniony · tylko do odczytu",
"tabs": {
"connected": "Połączona usługa",
"info": "Informacje",
"services": "Historia serwisowa",
"technical": "Historia przeglądów",
@@ -256,6 +259,50 @@
"reminders": "Przypomnienia"
},
"provider": {
"subtitle": "Dane na żywo z Twojego konta {label}.",
"refresh": "Odśwież",
"refreshing": "Odświeżanie…",
"updated": "Zaktualizowano {time}",
"vehicle": "Pojazd",
"readings": "Aktualne odczyty",
"noData": "{label} nie zwróciło żadnych danych dla tego samochodu.",
"raw": "Surowa odpowiedź",
"allFields": "Wszystkie zgłoszone pola",
"truncated": "Wypisano tylko pierwsze {n} pól — pozostałe znajdziesz w surowej odpowiedzi poniżej.",
"sectionEmpty": "Brak danych.",
"own": "Używane jest wyłącznie Twoje własne konto, więc dane logowania nigdy nie są udostępniane wraz z samochodem.",
"odometerSuggest": "{label} podaje {km}, czyli więcej niż zapisany przebieg tego samochodu.",
"updateOdometer": "Zaktualizuj przebieg",
"updatingOdometer": "Aktualizowanie…",
"unlink": "Odłącz",
"unlinkConfirm": "Odłączyć ten samochód od {label}? Żadne zapisane dane nie zostaną usunięte.",
"connectTitle": "Połącz ten samochód z usługą",
"connectHint": "Wybierz pojazd ze swojego konta, który odpowiada temu samochodowi. Jego dane pojawią się tutaj.",
"connectSubmit": "Połącz pojazd",
"connecting": "Łączenie…",
"noProviders": "Nie połączono żadnego konta producenta. Dodaj je w Ustawieniach › Integracje.",
"settingsLink": "Otwórz Ustawienia",
"sections": {
"telemetry": "Przebieg i zasięg",
"electric": "Akumulator i ładowanie",
"status": "Drzwi, szyby i światła",
"health": "Stan pojazdu",
"location": "Ostatnia znana lokalizacja",
"serviceHistory": "Historia serwisowa u dealera",
"notifications": "Powiadomienia"
},
"metrics": {
"odometer": "Przebieg",
"fuelLevel": "Poziom paliwa",
"fuelRange": "Zasięg",
"batteryLevel": "Akumulator",
"evRange": "Zasięg elektryczny",
"chargingStatus": "Ładowanie",
"location": "Pozycja"
}
},
"info": {
"oilSpec": "Specyfikacja oleju silnikowego",
"transmissionOil": "Olej przekładniowy",
@@ -468,6 +515,29 @@
"submit": "Dodaj samochód"
},
"import": {
"title": "Importuj samochód",
"subtitle": "Utwórz samochód na podstawie pojazdu z Twojego konta u producenta. Wszystko, co da się odczytać, zostanie wypełnione automatycznie.",
"service": "Usługa",
"loadingVehicles": "Wczytywanie Twoich pojazdów…",
"noVehicles": "Brak pojazdów na tym koncie.",
"notConnected": "Nie połączono",
"noProviders": "Nie połączono żadnego konta producenta. Dodaj je w Ustawieniach › Integracje.",
"alreadyInGarage": "Już w Twoim garażu",
"selectVehicle": "Pojazd",
"dataTitle": "Co zaimportować",
"dataHint": "Odznacz to, co wolisz wpisać samodzielnie.",
"includeIdentity": "Marka, model, rok, rejestracja i VIN",
"includeFuelType": "Rodzaj paliwa",
"includeDates": "Data produkcji i pierwszej rejestracji",
"includeOdometer": "Aktualny przebieg",
"name": "Nazwa samochodu",
"submit": "Importuj samochód",
"importing": "Importowanie…",
"warningOdometer": "Usługa nie podała przebiegu — wpisz go samodzielnie w samochodzie.",
"moreData": "Pozostałe dane z tej usługi pozostają dostępne w karcie {label} samochodu."
},
"service": {
"addTitle": "Dodaj wpis serwisowy",
"editTitle": "Edytuj wpis serwisowy",