mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
Finish the contract ratchet, the upload bridge and the client leftovers
BODY_CONTRACT_ALLOW_LIST is empty. The last seventeen handlers type their
body with a createZodDto class, so the fail-closed boot gate has nothing left
to forgive; it still refuses a boot for a new handler that reads @Body()
without one.
Several of those contracts describe rather than constrain, and that is the
whole care in this change. The pipe runs before the handler, so a schema
stricter than the handler moves a user-visible answer:
- TagsController.create answers { error: 'Tag name is required' }, pinned
byte-for-byte in two tests, and the pipe formats as `field: message`. The
DTO leaves name optional and the handler keeps the check that owns the
message. Same shape for the booking-import confirm body, which additionally
gains per-item validation the handler never did.
- PluginsController.activate and install answer 503 when plugins are disabled,
and check that BEFORE looking at the body. A schema that rejected first
would turn that into a 400 for an operator whose server has plugins off.
- setEgressHosts reads a non-array `hosts` as "clear the list", which is the
documented reset. Typing it as string[] would have removed a working admin
action rather than tightened anything.
- PluginRoutesController.route answers { route: null } at 200 for everything
it dislikes, so the client falls back to straight lines. A 400 there would
turn a graceful degradation into a visible error.
files.bridge is gone. The multer options are built by
MulterModule.registerAsync from an AllowedFileTypesService leaf, so the
fileFilter reads the operator's extension list from the container instead of
from a second FilesService built outside it. Nest injects
MULTER_MODULE_OPTIONS with @Optional(), so a token that fails to resolve is
not a boot error: it silently falls back to defaults, with no filter and no
size cap. FILE-020 already proved that for trip files by uploading an .svg
over HTTP and expecting 400; journey uploads had no such case, and now do.
VIDEO_UPLOAD is untouched, including the filename callback that forces .jpg
regardless of what the client sends, which guards the public share proxy.
PluginFrame gets an onError. A frame whose document fails to load left a
blank element at full height, which reads as a hung app rather than as a
plugin that is gone.
typecheck:tests runs in CI now, with the test tree at zero errors. tz-lookup
is left as it is: the build puts it in a lazy helpers chunk, not the entry
chunk, and the remaining split would trade a synchronous render for an async
one to move 172 kB that is already off the critical path.
This commit is contained in:
@@ -219,7 +219,7 @@ export default function PluginFrame({ pluginId, tripId = null, placeId = null, d
|
||||
// ids the plugin already had; never the httpOnly cookie); fully closing it
|
||||
// would require not running plugin client JS at all.
|
||||
const loadsRef = useRef(0)
|
||||
const { locale } = useTranslation()
|
||||
const { locale, t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const toast = useToast()
|
||||
// useToast returns a fresh object every render; keep it out of the effect deps
|
||||
@@ -243,6 +243,11 @@ export default function PluginFrame({ pluginId, tripId = null, placeId = null, d
|
||||
// The ref mirrors the state so the message handler can gate + answer without
|
||||
// side effects inside a setState updater (StrictMode runs updaters twice).
|
||||
const [confirmReq, setConfirmReq] = useState<ConfirmRequest | null>(null)
|
||||
// The iframe document can fail to load on its own: a plugin uninstalled in
|
||||
// another tab, a frame route the host no longer serves, a network blip on a
|
||||
// lazily loaded frame. Without an onError the element just stays blank at full
|
||||
// height, which reads as a hung app rather than as a plugin that is gone.
|
||||
const [loadFailed, setLoadFailed] = useState(false)
|
||||
const confirmReqRef = useRef<ConfirmRequest | null>(null)
|
||||
// geolocation:read gate — the feed only flags plugins whose grant is recorded.
|
||||
// Read via ref (like toastRef) so the bridge effect doesn't re-run on store churn.
|
||||
@@ -593,14 +598,24 @@ export default function PluginFrame({ pluginId, tripId = null, placeId = null, d
|
||||
// Deliver the context as soon as the document is parsed (the plugin sets up its
|
||||
// message listener during parse), closing the trek:ready race so the theme is
|
||||
// right on first paint. A 2nd load is a self-navigation — don't bridge to it.
|
||||
onLoad={() => { loadsRef.current += 1; if (loadsRef.current === 1) postFrame(buildContext()) }}
|
||||
onLoad={() => { setLoadFailed(false); loadsRef.current += 1; if (loadsRef.current === 1) postFrame(buildContext()) }}
|
||||
onError={() => setLoadFailed(true)}
|
||||
sandbox="allow-scripts allow-forms"
|
||||
referrerPolicy="no-referrer"
|
||||
loading="lazy"
|
||||
title={title || pluginId}
|
||||
className={className}
|
||||
style={{ width: '100%', height: fill ? '100%' : height ?? '100%', border: 0 }}
|
||||
style={{ width: '100%', height: fill ? '100%' : height ?? '100%', border: 0, display: loadFailed ? 'none' : undefined }}
|
||||
/>
|
||||
{loadFailed && (
|
||||
<div
|
||||
role="alert"
|
||||
className="flex items-center justify-center rounded-xl border border-edge bg-surface-2 p-6 text-caption text-content-2"
|
||||
style={{ width: '100%', height: fill ? '100%' : height ?? '100%' }}
|
||||
>
|
||||
{t('plugins.frameLoadFailed')}
|
||||
</div>
|
||||
)}
|
||||
<ConfirmDialog
|
||||
isOpen={confirmReq != null}
|
||||
onClose={() => answerConfirm(false)}
|
||||
|
||||
Reference in New Issue
Block a user