mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
feat(plugins): instance-wide settings editor in the admin UI (#2170)
* chore: bump version to 4.1.0 [skip ci] * fix(collections): stop findDuplicateCollectionPlace merging places by coordinates alone Three places answered "is this a place the trip already has?", not two: PlacesService.findDuplicatePlace and isPlaceDuplicate got the shared strategy list in #2130; CollectionsService.findDuplicateCollectionPlace was missed and kept its own hand-rolled copy of the pre-#2130 order. Unlike findDuplicatePlace, this one had no isPlaceDuplicate() guard in front of it — savePlace calls it directly — so the coordinate fallback for a NAMED candidate was live, not latent: two distinct places sharing an address (a restaurant and the bar upstairs) would report each other as duplicates the moment their coordinates round to the same ~11 m box, regardless of name. It also never read google_place_id/google_ftid/osm_id at all, even though every collection_places row stores them, so a place renamed since it was saved could be saved again instead of being recognised by its provider id. Now walks placeMatchStrategies() from @trek/shared, same as findMatchingPlaceId: provider id, then name, then coordinates only when there is no name. savePlace passes the provider id fields through since they are already on the request body; the two bulk call sites (importablePlaces, saveFromTripPlaces) are unchanged, since their source rows don't carry provider ids to pass. Closes #2137 * fix(collections): ask the same question at all three call sites savePlace was not the only caller of findDuplicateCollectionPlace. The bulk copy already carries google_place_id/google_ftid/osm_id into the row it writes but asked without them, and the import picker never selected them at all, so a renamed place was recognised on one path and not on the other two. The picker answering differently from the import is the drift the method exists to prevent: a row shown as new would come back refused. COLLECTIONS-SVC-102 and -103 cover the bulk copy and the picker. * fix(map): give the Leaflet map its own zoom ceiling, so a vector basemap cannot take the planner down Opening a trip on 4.1.0 could land on the error boundary with "Map has no maxZoom specified", and so could the map settings tab, which left no screen from which to pick a different basemap. Leaflet answers getMaxZoom() from the map options first and otherwise from a layer that brought one, and only a GridLayer ever contributes via its beforeAdd hook. A vector basemap is a GL canvas on a plain L.Layer, so it contributes nothing, and MapContainer set no ceiling of its own. MarkerClusterGroup.onAdd refuses an infinite one by throwing, before any clustering, so an empty trip hit it too. That path opened when the default basemap became a MapLibre style. It reaches further than an operator choosing OpenFreeMap: resolveTileUrl sends a keyless CARTO template to the app default, which is now a vector style, so every instance still carrying the old CARTO basemap fell into it on upgrade. The ceiling belongs on the map rather than on the base layer, because it has to hold whichever of the three branches renders. 19 matches what the raster and satellite layers already carried, so nothing changes for the maps that worked. SharedTripPage gets the same treatment: it has no cluster to throw, but it draws the same vector basemap and its fitBounds asks for a ceiling. mapZoomCeiling.test.ts pins Leaflet's own semantics against the real library rather than a mock, since a mocked react-leaflet would have kept passing through all of this. * fix(map): put the CARTO key back on the template the settings preview draws The map settings fields hold what the user is editing rather than what useTileUrl already resolved, so the preview received a bare template with no key on it. resolveTileUrl then read it as a keyless CARTO url and did what it is meant to do with one: fall back to the app default. The preview drew OpenFreeMap while the fields said CARTO, whether or not a key was saved. Same reason the tab crashed for anyone on a CARTO basemap even after entering a key, which is the loop that made this hard to escape: the key is entered on the page the fallback had taken down. FE-COMP-MAP-033b pins the template the preview is handed, with and without a key. * fix(admin): put the CARTO key back on the default-settings map preview too Same shape as the user-facing map tab, and reported alongside it: the field holds what the admin is editing, so the preview resolved a keyless CARTO template and drew the app default instead of the basemap being set. * fix(mobile): put the CARTO key back on the phone map settings preview too The third preview with the same shape, and the one that matters most while the crash is live: the phone layout is where someone would go to change the basemap when the desktop tab will not open. * fix(calendar): a fully timed stay is its two hand-overs, not a week-long bar Closes #2136 A stay was always exported as an all-day block across its whole range, and the check-in and check-out markers came on top of it. When the stay records both ends of its clock the markers already say everything the block does, and the block is the half nobody can act on: it takes a week of calendar to repeat what two one-hour events state precisely. Same shape as the parking and rental windows in #2068. Only where the markers actually stand in for the booking, though. They are emitted once per stay and titled from its lowest-id reservation, so a second room on the same stay would otherwise be left with nothing at all. A stay that knows only one end keeps its block too, since nothing else carries the other end's date. CAL-025b covers the drop, -025c the one-sided stay, -025d the second room. * fix(mobile): the phone admin map preview needs the CARTO key too The fourth preview with the same shape, missed when the other three were fixed. Sonar pointed at it: the desktop and phone admin pages are near-identical, so the duplication report named the file the change had not reached. * chore: bump version to 4.1.1 [skip ci] * feat(plugins): admin editor for instance-wide plugin settings The scope:'instance' settings a plugin declares had API endpoints but no UI. - shared: plugins.schema.ts — the settings-field descriptor and the admin instance-config GET/PUT wire contracts, imported by both sides - server: GET /api/admin/plugins/:id/config now returns the declared fields alongside the (masked) values; PUT re-spawns an ACTIVE plugin (its child reads config once, at init) and reports it via 'restarted'; the admin list carries instanceSettingsCount so the UI gates its menu item without a fetch - client: 'Instance settings' row action opening a form modal (desktop) / MSheet (phone) in both admin shells — checkbox/select/secret rendering as in the user settings form; an untouched secret mask is never sent back - i18n: three new admin.plugins.* keys in every locale * refactor(plugins): move the admin body contracts to @trek/shared The remaining plugin DTO schemas (install, link, activate, uninstall, retrust, update, egress-hosts, user-settings update, route) now live in shared/src/plugins/plugins.schema.ts with their inferred types, alongside the instance-config contracts. The journey-contract doctrine notes (#1842) moved with them — each body stays deliberately loose so the handlers keep the rejections and fallbacks they already own, and new spec tests pin that looseness so a well-meant tightening breaks a test that explains itself. plugins.dto.ts is now thin createZodDto wrappers over the shared schemas (same class names, no controller changes), and the client's pluginInstall types its options and body against PluginInstallRequest. * fix(admin): offer Allowed hosts only to plugins that declared operatorEgress The row's egress chip was already gated on the declaration, but the kebab menu (desktop) and row action sheet (phone) offered Allowed hosts on every installed plugin — inviting the admin to widen egress for plugins that never asked for it. Both entries now render only when the plugin declares operatorEgress; the dialog's unsupported-notice fallback stays as the truth-teller for stale list data. * test(admin): close the Sonar gaps on the instance-settings form The PR gate flagged new-code coverage (76.4%) and duplication (10.9%). - The two identical 39-line handler blocks were logic, not markup — they move into one shared useInstanceSettings hook; each shell keeps its own markup (the deliberate desktop/phone divergence stays) - New tests per shell cover the untested branches: every field type renders and round-trips into the save payload (select, checkbox/MToggle, number, hint, no-label key fallback), a failed fetch is a toast, a rejected save shows the server reason and keeps the edits, and the dialog/sheet closes without saving - INS-009 covers the controller's no-body '|| {}' fallback --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: michael-bohr <263459669+michael-bohr@users.noreply.github.com> Co-authored-by: Maurice <mauriceboe@icloud.com>
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@trek/shared",
|
||||
"version": "4.0.0",
|
||||
"version": "4.1.1",
|
||||
"private": true,
|
||||
"description": "Shared API contracts (Zod schemas) — single source of truth for TREK server and client.",
|
||||
"type": "module",
|
||||
|
||||
@@ -451,6 +451,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'لا توجد إضافات في السجل تطابق بحثك.',
|
||||
'admin.plugins.restart': 'إعادة التشغيل',
|
||||
'admin.plugins.restarted': 'تمت إعادة تشغيل الإضافة',
|
||||
'admin.plugins.instanceSettings': 'إعدادات مستوى الخادم',
|
||||
'admin.plugins.settingsSaved': 'تم حفظ الإعدادات',
|
||||
'admin.plugins.settingsSavedRestarted': 'تم حفظ الإعدادات — تمت إعادة تشغيل الإضافة',
|
||||
'admin.plugins.cap.readsTrips': 'يقرأ رحلاتك',
|
||||
'admin.plugins.cap.readsUsers': 'يقرأ الملفات الشخصية الأساسية',
|
||||
'admin.plugins.cap.readsCosts': 'يقرأ مصروفاتك',
|
||||
|
||||
@@ -440,6 +440,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Nenhum plugin no registro corresponde à sua busca.',
|
||||
'admin.plugins.restart': 'Reiniciar',
|
||||
'admin.plugins.restarted': 'Plugin reiniciado',
|
||||
'admin.plugins.instanceSettings': 'Configurações da instância',
|
||||
'admin.plugins.settingsSaved': 'Configurações salvas',
|
||||
'admin.plugins.settingsSavedRestarted': 'Configurações salvas — plugin reiniciado',
|
||||
'admin.plugins.cap.readsTrips': 'Lê suas viagens',
|
||||
'admin.plugins.cap.readsUsers': 'Lê perfis básicos',
|
||||
'admin.plugins.cap.readsCosts': 'Lê suas despesas',
|
||||
|
||||
@@ -568,6 +568,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Cap connector del registre coincideix amb la teva cerca.',
|
||||
'admin.plugins.restart': 'Reinicia',
|
||||
'admin.plugins.restarted': 'Connector reiniciat',
|
||||
'admin.plugins.instanceSettings': 'Configuració de la instància',
|
||||
'admin.plugins.settingsSaved': 'Configuració desada',
|
||||
'admin.plugins.settingsSavedRestarted': 'Configuració desada — connector reiniciat',
|
||||
'admin.plugins.cap.readsTrips': 'Llegeix els teus viatges',
|
||||
'admin.plugins.cap.readsUsers': 'Llegeix els perfils bàsics',
|
||||
'admin.plugins.cap.readsCosts': 'Llegeix les teves despeses',
|
||||
|
||||
@@ -438,6 +438,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Žádné pluginy v registru neodpovídají vašemu hledání.',
|
||||
'admin.plugins.restart': 'Restartovat',
|
||||
'admin.plugins.restarted': 'Plugin restartován',
|
||||
'admin.plugins.instanceSettings': 'Nastavení instance',
|
||||
'admin.plugins.settingsSaved': 'Nastavení uloženo',
|
||||
'admin.plugins.settingsSavedRestarted': 'Nastavení uloženo — plugin restartován',
|
||||
'admin.plugins.cap.readsTrips': 'Čte vaše cesty',
|
||||
'admin.plugins.cap.readsUsers': 'Čte základní profily',
|
||||
'admin.plugins.cap.readsCosts': 'Čte vaše výdaje',
|
||||
|
||||
@@ -447,6 +447,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Keine Plugins in der Registry passen zu deiner Suche.',
|
||||
'admin.plugins.restart': 'Neu starten',
|
||||
'admin.plugins.restarted': 'Plugin neu gestartet',
|
||||
'admin.plugins.instanceSettings': 'Instanz-Einstellungen',
|
||||
'admin.plugins.settingsSaved': 'Einstellungen gespeichert',
|
||||
'admin.plugins.settingsSavedRestarted': 'Einstellungen gespeichert — Plugin neu gestartet',
|
||||
'admin.plugins.cap.readsTrips': 'Liest deine Reisen',
|
||||
'admin.plugins.cap.readsUsers': 'Liest Basis-Profile',
|
||||
'admin.plugins.cap.readsCosts': 'Liest deine Ausgaben',
|
||||
|
||||
@@ -485,6 +485,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'No plugins in the registry match your search.',
|
||||
'admin.plugins.restart': 'Restart',
|
||||
'admin.plugins.restarted': 'Plugin restarted',
|
||||
'admin.plugins.instanceSettings': 'Instance settings',
|
||||
'admin.plugins.settingsSaved': 'Settings saved',
|
||||
'admin.plugins.settingsSavedRestarted': 'Settings saved — plugin restarted',
|
||||
'admin.plugins.cap.readsTrips': 'Reads your trips',
|
||||
'admin.plugins.cap.readsUsers': 'Reads basic profiles',
|
||||
'admin.plugins.cap.readsCosts': 'Reads your costs',
|
||||
|
||||
@@ -449,6 +449,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Ningún plugin del registro coincide con tu búsqueda.',
|
||||
'admin.plugins.restart': 'Reiniciar',
|
||||
'admin.plugins.restarted': 'Plugin reiniciado',
|
||||
'admin.plugins.instanceSettings': 'Ajustes de la instancia',
|
||||
'admin.plugins.settingsSaved': 'Ajustes guardados',
|
||||
'admin.plugins.settingsSavedRestarted': 'Ajustes guardados — plugin reiniciado',
|
||||
'admin.plugins.cap.readsTrips': 'Lee tus viajes',
|
||||
'admin.plugins.cap.readsUsers': 'Lee perfiles básicos',
|
||||
'admin.plugins.cap.readsCosts': 'Lee tus gastos',
|
||||
|
||||
@@ -452,6 +452,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Aucun plugin du registre ne correspond à votre recherche.',
|
||||
'admin.plugins.restart': 'Redémarrer',
|
||||
'admin.plugins.restarted': 'Plugin redémarré',
|
||||
'admin.plugins.instanceSettings': 'Paramètres de l’instance',
|
||||
'admin.plugins.settingsSaved': 'Paramètres enregistrés',
|
||||
'admin.plugins.settingsSavedRestarted': 'Paramètres enregistrés — plugin redémarré',
|
||||
'admin.plugins.cap.readsTrips': 'Lit vos voyages',
|
||||
'admin.plugins.cap.readsUsers': 'Lit les profils de base',
|
||||
'admin.plugins.cap.readsCosts': 'Lit vos dépenses',
|
||||
|
||||
@@ -500,6 +500,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Κανένα plugin στο μητρώο δεν ταιριάζει με την αναζήτησή σας.',
|
||||
'admin.plugins.restart': 'Επανεκκίνηση',
|
||||
'admin.plugins.restarted': 'Το plugin επανεκκινήθηκε',
|
||||
'admin.plugins.instanceSettings': 'Ρυθμίσεις εγκατάστασης',
|
||||
'admin.plugins.settingsSaved': 'Οι ρυθμίσεις αποθηκεύτηκαν',
|
||||
'admin.plugins.settingsSavedRestarted': 'Οι ρυθμίσεις αποθηκεύτηκαν — το plugin επανεκκινήθηκε',
|
||||
'admin.plugins.cap.readsTrips': 'Διαβάζει τα ταξίδια σας',
|
||||
'admin.plugins.cap.readsUsers': 'Διαβάζει βασικά προφίλ',
|
||||
'admin.plugins.cap.readsCosts': 'Διαβάζει τα έξοδά σας',
|
||||
|
||||
@@ -452,6 +452,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Nincs a keresésnek megfelelő plugin a tárban.',
|
||||
'admin.plugins.restart': 'Újraindítás',
|
||||
'admin.plugins.restarted': 'Plugin újraindítva',
|
||||
'admin.plugins.instanceSettings': 'Példányszintű beállítások',
|
||||
'admin.plugins.settingsSaved': 'Beállítások elmentve',
|
||||
'admin.plugins.settingsSavedRestarted': 'Beállítások elmentve — plugin újraindítva',
|
||||
'admin.plugins.cap.readsTrips': 'Olvassa az utazásaidat',
|
||||
'admin.plugins.cap.readsUsers': 'Olvassa az alapprofilokat',
|
||||
'admin.plugins.cap.readsCosts': 'Olvassa a költségeidet',
|
||||
|
||||
@@ -494,6 +494,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Tidak ada plugin di registri yang cocok dengan pencarianmu.',
|
||||
'admin.plugins.restart': 'Mulai ulang',
|
||||
'admin.plugins.restarted': 'Plugin dimulai ulang',
|
||||
'admin.plugins.instanceSettings': 'Pengaturan instans',
|
||||
'admin.plugins.settingsSaved': 'Pengaturan disimpan',
|
||||
'admin.plugins.settingsSavedRestarted': 'Pengaturan disimpan — plugin dimulai ulang',
|
||||
'admin.plugins.cap.readsTrips': 'Membaca perjalananmu',
|
||||
'admin.plugins.cap.readsUsers': 'Membaca profil dasar',
|
||||
'admin.plugins.cap.readsCosts': 'Membaca pengeluaranmu',
|
||||
|
||||
@@ -447,6 +447,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Nessun plugin nel registro corrisponde alla tua ricerca.',
|
||||
'admin.plugins.restart': 'Riavvia',
|
||||
'admin.plugins.restarted': 'Plugin riavviato',
|
||||
'admin.plugins.instanceSettings': 'Impostazioni dell’istanza',
|
||||
'admin.plugins.settingsSaved': 'Impostazioni salvate',
|
||||
'admin.plugins.settingsSavedRestarted': 'Impostazioni salvate — plugin riavviato',
|
||||
'admin.plugins.cap.readsTrips': 'Legge i tuoi viaggi',
|
||||
'admin.plugins.cap.readsUsers': 'Legge i profili di base',
|
||||
'admin.plugins.cap.readsCosts': 'Legge le tue spese',
|
||||
|
||||
@@ -459,6 +459,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': '検索条件に一致するプラグインはレジストリにありません。',
|
||||
'admin.plugins.restart': '再起動',
|
||||
'admin.plugins.restarted': 'プラグインを再起動しました',
|
||||
'admin.plugins.instanceSettings': 'インスタンス設定',
|
||||
'admin.plugins.settingsSaved': '設定を保存しました',
|
||||
'admin.plugins.settingsSavedRestarted': '設定を保存しました — プラグインを再起動しました',
|
||||
'admin.plugins.cap.readsTrips': '旅行を読み取り',
|
||||
'admin.plugins.cap.readsUsers': '基本プロフィールを読み取り',
|
||||
'admin.plugins.cap.readsCosts': '支出を読み取り',
|
||||
|
||||
@@ -459,6 +459,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': '레지스트리에 검색과 일치하는 플러그인이 없습니다.',
|
||||
'admin.plugins.restart': '다시 시작',
|
||||
'admin.plugins.restarted': '플러그인이 다시 시작되었습니다',
|
||||
'admin.plugins.instanceSettings': '인스턴스 설정',
|
||||
'admin.plugins.settingsSaved': '설정이 저장되었습니다',
|
||||
'admin.plugins.settingsSavedRestarted': '설정이 저장되었습니다 — 플러그인이 다시 시작되었습니다',
|
||||
'admin.plugins.cap.readsTrips': '여행 읽기',
|
||||
'admin.plugins.cap.readsUsers': '기본 프로필 읽기',
|
||||
'admin.plugins.cap.readsCosts': '지출 읽기',
|
||||
|
||||
@@ -446,6 +446,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Geen plugins in het register komen overeen met je zoekopdracht.',
|
||||
'admin.plugins.restart': 'Opnieuw starten',
|
||||
'admin.plugins.restarted': 'Plugin opnieuw gestart',
|
||||
'admin.plugins.instanceSettings': 'Instantie-instellingen',
|
||||
'admin.plugins.settingsSaved': 'Instellingen opgeslagen',
|
||||
'admin.plugins.settingsSavedRestarted': 'Instellingen opgeslagen — plugin opnieuw gestart',
|
||||
'admin.plugins.cap.readsTrips': 'Leest je reizen',
|
||||
'admin.plugins.cap.readsUsers': 'Leest basisprofielen',
|
||||
'admin.plugins.cap.readsCosts': 'Leest je uitgaven',
|
||||
|
||||
@@ -444,6 +444,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Żadna wtyczka w rejestrze nie pasuje do wyszukiwania.',
|
||||
'admin.plugins.restart': 'Uruchom ponownie',
|
||||
'admin.plugins.restarted': 'Wtyczka została uruchomiona ponownie',
|
||||
'admin.plugins.instanceSettings': 'Ustawienia instancji',
|
||||
'admin.plugins.settingsSaved': 'Ustawienia zapisane',
|
||||
'admin.plugins.settingsSavedRestarted': 'Ustawienia zapisane — wtyczka została uruchomiona ponownie',
|
||||
'admin.plugins.cap.readsTrips': 'Odczytuje Twoje podróże',
|
||||
'admin.plugins.cap.readsUsers': 'Odczytuje podstawowe profile',
|
||||
'admin.plugins.cap.readsCosts': 'Odczytuje Twoje wydatki',
|
||||
|
||||
@@ -448,6 +448,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'В реестре нет плагинов по вашему запросу.',
|
||||
'admin.plugins.restart': 'Перезапустить',
|
||||
'admin.plugins.restarted': 'Плагин перезапущен',
|
||||
'admin.plugins.instanceSettings': 'Настройки экземпляра',
|
||||
'admin.plugins.settingsSaved': 'Настройки сохранены',
|
||||
'admin.plugins.settingsSavedRestarted': 'Настройки сохранены — плагин перезапущен',
|
||||
'admin.plugins.cap.readsTrips': 'Читает ваши поездки',
|
||||
'admin.plugins.cap.readsUsers': 'Читает основные профили',
|
||||
'admin.plugins.cap.readsCosts': 'Читает ваши расходы',
|
||||
|
||||
@@ -505,6 +505,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Inga plugins i registret matchar din sökning.',
|
||||
'admin.plugins.restart': 'Starta om',
|
||||
'admin.plugins.restarted': 'Pluginet har startats om',
|
||||
'admin.plugins.instanceSettings': 'Instansinställningar',
|
||||
'admin.plugins.settingsSaved': 'Inställningarna har sparats',
|
||||
'admin.plugins.settingsSavedRestarted': 'Inställningarna har sparats — pluginet har startats om',
|
||||
'admin.plugins.cap.readsTrips': 'Läser dina resor',
|
||||
'admin.plugins.cap.readsUsers': 'Läser grundläggande profiler',
|
||||
'admin.plugins.cap.readsCosts': 'Läser dina kostnader',
|
||||
|
||||
@@ -491,6 +491,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Dizinde aramanızla eşleşen eklenti yok.',
|
||||
'admin.plugins.restart': 'Yeniden başlat',
|
||||
'admin.plugins.restarted': 'Eklenti yeniden başlatıldı',
|
||||
'admin.plugins.instanceSettings': 'Örnek ayarları',
|
||||
'admin.plugins.settingsSaved': 'Ayarlar kaydedildi',
|
||||
'admin.plugins.settingsSavedRestarted': 'Ayarlar kaydedildi — eklenti yeniden başlatıldı',
|
||||
'admin.plugins.cap.readsTrips': 'Seyahatlerinizi okur',
|
||||
'admin.plugins.cap.readsUsers': 'Temel profilleri okur',
|
||||
'admin.plugins.cap.readsCosts': 'Harcamalarınızı okur',
|
||||
|
||||
@@ -445,6 +445,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Жоден плагін у реєстрі не відповідає вашому запиту.',
|
||||
'admin.plugins.restart': 'Перезапустити',
|
||||
'admin.plugins.restarted': 'Плагін перезапущено',
|
||||
'admin.plugins.instanceSettings': 'Налаштування інстансу',
|
||||
'admin.plugins.settingsSaved': 'Налаштування збережено',
|
||||
'admin.plugins.settingsSavedRestarted': 'Налаштування збережено — плагін перезапущено',
|
||||
'admin.plugins.cap.readsTrips': 'Читає ваші подорожі',
|
||||
'admin.plugins.cap.readsUsers': 'Читає базові профілі',
|
||||
'admin.plugins.cap.readsCosts': 'Читає ваші витрати',
|
||||
|
||||
@@ -447,6 +447,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': 'Không có plugin nào trong kho đăng ký khớp với tìm kiếm của bạn.',
|
||||
'admin.plugins.restart': 'Khởi động lại',
|
||||
'admin.plugins.restarted': 'Đã khởi động lại plugin',
|
||||
'admin.plugins.instanceSettings': 'Cài đặt toàn hệ thống',
|
||||
'admin.plugins.settingsSaved': 'Đã lưu cài đặt',
|
||||
'admin.plugins.settingsSavedRestarted': 'Đã lưu cài đặt — đã khởi động lại plugin',
|
||||
'admin.plugins.cap.readsTrips': 'Đọc chuyến đi của bạn',
|
||||
'admin.plugins.cap.readsUsers': 'Đọc hồ sơ cơ bản',
|
||||
'admin.plugins.cap.readsCosts': 'Đọc chi phí của bạn',
|
||||
|
||||
@@ -441,6 +441,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': '外掛庫中沒有符合搜尋條件的外掛。',
|
||||
'admin.plugins.restart': '重新啟動',
|
||||
'admin.plugins.restarted': '外掛已重新啟動',
|
||||
'admin.plugins.instanceSettings': '執行個體設定',
|
||||
'admin.plugins.settingsSaved': '設定已儲存',
|
||||
'admin.plugins.settingsSavedRestarted': '設定已儲存 — 外掛已重新啟動',
|
||||
'admin.plugins.cap.readsTrips': '讀取你的行程',
|
||||
'admin.plugins.cap.readsUsers': '讀取基本個人資料',
|
||||
'admin.plugins.cap.readsCosts': '讀取你的支出',
|
||||
|
||||
@@ -401,6 +401,9 @@ const admin: TranslationStrings = {
|
||||
'admin.plugins.noMatchRegistry': '插件库中没有与你的搜索匹配的插件。',
|
||||
'admin.plugins.restart': '重启',
|
||||
'admin.plugins.restarted': '插件已重启',
|
||||
'admin.plugins.instanceSettings': '实例设置',
|
||||
'admin.plugins.settingsSaved': '设置已保存',
|
||||
'admin.plugins.settingsSavedRestarted': '设置已保存 — 插件已重启',
|
||||
'admin.plugins.cap.readsTrips': '读取你的旅行',
|
||||
'admin.plugins.cap.readsUsers': '读取基本个人资料',
|
||||
'admin.plugins.cap.readsCosts': '读取你的支出',
|
||||
|
||||
@@ -69,3 +69,5 @@ export * from './i18n/languages';
|
||||
// Plugin permission list, generated from the host's protocol/envelope.ts
|
||||
// (server/scripts/gen-plugin-facts.ts). The admin consent screens render from it.
|
||||
export * from './plugin-permissions';
|
||||
// Plugin settings contracts: the settings-field descriptor + admin instance-config wire shapes.
|
||||
export * from './plugins/plugins.schema';
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
import {
|
||||
pluginSettingsFieldSchema,
|
||||
pluginInstanceConfigResponseSchema,
|
||||
pluginInstanceConfigUpdateSchema,
|
||||
pluginInstanceConfigUpdatedSchema,
|
||||
pluginInstallRequestSchema,
|
||||
pluginLinkRequestSchema,
|
||||
pluginActivateRequestSchema,
|
||||
pluginUninstallRequestSchema,
|
||||
pluginRetrustRequestSchema,
|
||||
pluginUpdateRequestSchema,
|
||||
pluginEgressHostsRequestSchema,
|
||||
pluginUserSettingsUpdateRequestSchema,
|
||||
pluginRouteRequestSchema,
|
||||
} from './plugins.schema';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
/**
|
||||
* The instance-config contract (#plugins): the settings-field descriptor both
|
||||
* settings forms render from, and the admin config GET/PUT wire shapes. These
|
||||
* pin the SHAPE the server emits — which keys are nullable vs optional matters,
|
||||
* because the client forms branch on them (`f.label || f.key`, `f.secret`).
|
||||
*/
|
||||
describe('pluginSettingsFieldSchema', () => {
|
||||
it('accepts a fully-populated field as the server emits it (nulls, not absences)', () => {
|
||||
const field = {
|
||||
key: 'apiKey',
|
||||
label: 'API key',
|
||||
input_type: 'text',
|
||||
placeholder: null,
|
||||
hint: null,
|
||||
required: false,
|
||||
secret: true,
|
||||
options: undefined,
|
||||
};
|
||||
expect(pluginSettingsFieldSchema.parse(field)).toMatchObject({ key: 'apiKey', secret: true });
|
||||
});
|
||||
|
||||
it('accepts a select field with {value,label} options (the manifest-validated shape)', () => {
|
||||
const field = { key: 'mode', options: [{ value: 'fast', label: 'Fast' }] };
|
||||
expect(pluginSettingsFieldSchema.parse(field).options).toEqual([{ value: 'fast', label: 'Fast' }]);
|
||||
});
|
||||
|
||||
it('requires key — a field without one cannot be rendered or saved', () => {
|
||||
expect(pluginSettingsFieldSchema.safeParse({ label: 'orphan' }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('instance-config wire shapes', () => {
|
||||
it('GET response carries the form fields alongside the (masked) values', () => {
|
||||
const res = {
|
||||
fields: [
|
||||
{
|
||||
key: 'apiUrl',
|
||||
label: null,
|
||||
input_type: 'text',
|
||||
placeholder: null,
|
||||
hint: null,
|
||||
required: true,
|
||||
secret: false,
|
||||
},
|
||||
],
|
||||
config: { apiUrl: 'https://x.example', apiKey: '••••••••' },
|
||||
};
|
||||
expect(pluginInstanceConfigResponseSchema.parse(res).fields).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('PUT body is the config record itself — any keys, unknown values', () => {
|
||||
expect(pluginInstanceConfigUpdateSchema.parse({ apiUrl: 'x', retries: 3, on: true })).toEqual({
|
||||
apiUrl: 'x',
|
||||
retries: 3,
|
||||
on: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('PUT body refuses a non-object (the handler never sees garbage shapes)', () => {
|
||||
expect(pluginInstanceConfigUpdateSchema.safeParse('not a config').success).toBe(false);
|
||||
expect(pluginInstanceConfigUpdateSchema.safeParse([1, 2]).success).toBe(false);
|
||||
});
|
||||
|
||||
it('PUT response reports whether the save restarted a running plugin', () => {
|
||||
expect(pluginInstanceConfigUpdatedSchema.parse({ config: {}, restarted: true }).restarted).toBe(true);
|
||||
expect(pluginInstanceConfigUpdatedSchema.safeParse({ config: {} }).success).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* The admin body contracts, written to DESCRIBE rather than to tighten (the
|
||||
* journey-contract doctrine, #1842): fields optional, objects loose, so every
|
||||
* handler keeps the rejection it already owns ('id is required', 503-before-body,
|
||||
* hosts-clears-on-non-array). These pin exactly that looseness — a "helpful"
|
||||
* tightening of one of these schemas is a behavior change on the wire.
|
||||
*/
|
||||
describe('admin body contracts stay loose by doctrine', () => {
|
||||
it("install: an empty body parses — `id is required` stays the HANDLER's answer", () => {
|
||||
expect(pluginInstallRequestSchema.safeParse({}).success).toBe(true);
|
||||
expect(
|
||||
pluginInstallRequestSchema.parse({ id: 'p', version: '1.0.0', constraint: '^1', withDependencies: true }),
|
||||
).toMatchObject({ id: 'p', withDependencies: true });
|
||||
});
|
||||
|
||||
it('install: declared fields still pin their TYPES', () => {
|
||||
expect(pluginInstallRequestSchema.safeParse({ withDependencies: 'yes' }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('link / activate / uninstall / retrust / update: empty bodies parse', () => {
|
||||
for (const s of [
|
||||
pluginLinkRequestSchema,
|
||||
pluginActivateRequestSchema,
|
||||
pluginUninstallRequestSchema,
|
||||
pluginRetrustRequestSchema,
|
||||
pluginUpdateRequestSchema,
|
||||
]) {
|
||||
expect(s.safeParse({}).success).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it('egress hosts: a non-array `hosts` parses — that is the documented clear/reset path', () => {
|
||||
expect(pluginEgressHostsRequestSchema.safeParse({}).success).toBe(true);
|
||||
expect(pluginEgressHostsRequestSchema.safeParse({ hosts: null }).success).toBe(true);
|
||||
expect(pluginEgressHostsRequestSchema.safeParse({ hosts: ['a.example'] }).success).toBe(true);
|
||||
});
|
||||
|
||||
it('user settings update: a non-object `config` parses — the handler answers 200, not 400', () => {
|
||||
expect(pluginUserSettingsUpdateRequestSchema.safeParse({ config: 'garbage' }).success).toBe(true);
|
||||
expect(pluginUserSettingsUpdateRequestSchema.safeParse({}).success).toBe(true);
|
||||
});
|
||||
|
||||
it('route: any object parses — the handler answers { route: null }, never a 400', () => {
|
||||
expect(pluginRouteRequestSchema.safeParse({ anything: [1, 2, 3] }).success).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Plugin settings contracts (#plugins).
|
||||
*
|
||||
* A plugin declares its settings fields in its manifest (validated at install,
|
||||
* stored in plugin_settings_fields); the server serves them back as form
|
||||
* metadata and both settings forms — the user Settings tab (`scope:'user'`)
|
||||
* and the admin instance-settings dialog (`scope:'instance'`) — render from
|
||||
* this ONE descriptor shape. Nullable-vs-optional is deliberate: the server
|
||||
* emits SQL NULLs for absent labels/placeholders/hints, and the forms branch
|
||||
* on them (`f.label || f.key`).
|
||||
*
|
||||
* Shared Zod pins SHAPE only. Which keys a plugin may store, secret
|
||||
* encryption, and the mask sentinel stay server-side (plugins.service.ts) —
|
||||
* the settled two-layer pattern.
|
||||
*/
|
||||
export const pluginSettingsFieldSchema = z.object({
|
||||
key: z.string(),
|
||||
label: z.string().nullish(),
|
||||
/** 'text' | 'number' | 'checkbox' | 'select' | … — server defaults absent to 'text'. */
|
||||
input_type: z.string().optional(),
|
||||
placeholder: z.string().nullish(),
|
||||
hint: z.string().nullish(),
|
||||
required: z.boolean().optional(),
|
||||
secret: z.boolean().optional(),
|
||||
options: z.array(z.object({ value: z.string(), label: z.string() })).optional(),
|
||||
});
|
||||
export type PluginSettingsField = z.infer<typeof pluginSettingsFieldSchema>;
|
||||
|
||||
/** GET /api/admin/plugins/:id/config — the declared `scope:'instance'` fields
|
||||
* plus the stored values, secrets masked. */
|
||||
export const pluginInstanceConfigResponseSchema = z.object({
|
||||
fields: z.array(pluginSettingsFieldSchema),
|
||||
config: z.record(z.string(), z.unknown()),
|
||||
});
|
||||
export type PluginInstanceConfigResponse = z.infer<typeof pluginInstanceConfigResponseSchema>;
|
||||
|
||||
/** PUT /api/admin/plugins/:id/config body — the config record itself. Loose on
|
||||
* purpose (journey-contract doctrine): the service drops undeclared keys and
|
||||
* keeps every decision it already makes, so the schema only refuses non-objects. */
|
||||
export const pluginInstanceConfigUpdateSchema = z.record(z.string(), z.unknown());
|
||||
export type PluginInstanceConfigUpdate = z.infer<typeof pluginInstanceConfigUpdateSchema>;
|
||||
|
||||
/** PUT /api/admin/plugins/:id/config response — the saved (masked) config, and
|
||||
* whether the save re-spawned a RUNNING plugin (its child reads config once, at init). */
|
||||
export const pluginInstanceConfigUpdatedSchema = z.object({
|
||||
config: z.record(z.string(), z.unknown()),
|
||||
restarted: z.boolean(),
|
||||
});
|
||||
export type PluginInstanceConfigUpdated = z.infer<typeof pluginInstanceConfigUpdatedSchema>;
|
||||
|
||||
/**
|
||||
* Body contracts for the admin plugin surfaces, written to DESCRIBE rather than
|
||||
* to tighten (the journey-contract doctrine, #1842).
|
||||
*
|
||||
* Every one of these handlers already owns its own rejection, and several of
|
||||
* them answer something other than 400 for a body they dislike: activate and
|
||||
* install answer 503 when plugins are disabled, and they check that BEFORE
|
||||
* looking at the body. A schema that rejected first would move a 503 to a 400
|
||||
* for an operator whose server has plugins off. So the fields stay optional and
|
||||
* the objects stay loose: the schema pins the wire TYPES, and the handler keeps
|
||||
* every decision it already made, in the order it already made it.
|
||||
*/
|
||||
|
||||
/** POST /api/admin/plugins/install — `id is required` stays the handler's answer. */
|
||||
export const pluginInstallRequestSchema = z.looseObject({
|
||||
id: z.string().optional(),
|
||||
version: z.string().optional(),
|
||||
constraint: z.string().optional(),
|
||||
withDependencies: z.boolean().optional(),
|
||||
});
|
||||
export type PluginInstallRequest = z.infer<typeof pluginInstallRequestSchema>;
|
||||
|
||||
/** POST /api/admin/plugins/link — `path is required` likewise, and dev-link answers 403 before reading it. */
|
||||
export const pluginLinkRequestSchema = z.looseObject({ path: z.string().optional() });
|
||||
export type PluginLinkRequest = z.infer<typeof pluginLinkRequestSchema>;
|
||||
|
||||
/** POST /api/admin/plugins/:id/activate */
|
||||
export const pluginActivateRequestSchema = z.looseObject({ consent: z.boolean().optional() });
|
||||
export type PluginActivateRequest = z.infer<typeof pluginActivateRequestSchema>;
|
||||
|
||||
/** POST /api/admin/plugins/:id/uninstall */
|
||||
export const pluginUninstallRequestSchema = z.looseObject({ deleteData: z.boolean().optional() });
|
||||
export type PluginUninstallRequest = z.infer<typeof pluginUninstallRequestSchema>;
|
||||
|
||||
/** POST /api/admin/plugins/:id/retrust */
|
||||
export const pluginRetrustRequestSchema = z.looseObject({
|
||||
version: z.string().optional(),
|
||||
publicKey: z.string().optional(),
|
||||
});
|
||||
export type PluginRetrustRequest = z.infer<typeof pluginRetrustRequestSchema>;
|
||||
|
||||
/**
|
||||
* POST /api/admin/plugins/:id/update — `version` pins the exact version to
|
||||
* install (the rollback path). Omitted, the runtime resolves the newest
|
||||
* TREK-compatible version itself (the classic update).
|
||||
*/
|
||||
export const pluginUpdateRequestSchema = z.looseObject({ version: z.string().optional() });
|
||||
export type PluginUpdateRequest = z.infer<typeof pluginUpdateRequestSchema>;
|
||||
|
||||
/**
|
||||
* PUT /api/admin/plugins/:id/egress-hosts — `hosts` is deliberately unknown,
|
||||
* not `string[]`.
|
||||
*
|
||||
* The handler reads `Array.isArray(body.hosts) ? body.hosts.map(String) : []`,
|
||||
* which means an omitted or non-array `hosts` CLEARS the operator egress list.
|
||||
* That is the documented way to reset it, so a schema demanding an array would
|
||||
* not tighten validation, it would remove a working admin action.
|
||||
*/
|
||||
export const pluginEgressHostsRequestSchema = z.looseObject({ hosts: z.unknown().optional() });
|
||||
export type PluginEgressHostsRequest = z.infer<typeof pluginEgressHostsRequestSchema>;
|
||||
|
||||
/**
|
||||
* POST /api/plugin-settings/:id — `config` is unknown rather than a record: the
|
||||
* handler answers 200 with the stored config for anything it cannot use,
|
||||
* including a non-object, and a schema that rejected first would turn that
|
||||
* into a 400.
|
||||
*/
|
||||
export const pluginUserSettingsUpdateRequestSchema = z.looseObject({ config: z.unknown().optional() });
|
||||
export type PluginUserSettingsUpdateRequest = z.infer<typeof pluginUserSettingsUpdateRequestSchema>;
|
||||
|
||||
/**
|
||||
* POST /api/plugins/:id/route — the route hook answers `{ route: null }` at 200
|
||||
* for every input it dislikes: a missing trip, a bad profile, unusable
|
||||
* waypoints, a slow provider. The client draws straight lines on a null and
|
||||
* shows nothing on a 400, so a schema that rejected a malformed body would turn
|
||||
* a graceful fallback into a visible error. Loose and fully optional on purpose.
|
||||
*/
|
||||
export const pluginRouteRequestSchema = z.looseObject({});
|
||||
export type PluginRouteRequest = z.infer<typeof pluginRouteRequestSchema>;
|
||||
Reference in New Issue
Block a user