mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 09:54:14 +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:
@@ -0,0 +1,73 @@
|
||||
import { createZodDto } from 'nestjs-zod';
|
||||
import { z } from 'zod';
|
||||
|
||||
/**
|
||||
* Body contracts for the 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 DTO pins the wire TYPES, and the handler keeps
|
||||
* every decision it already made, in the order it already made it.
|
||||
*/
|
||||
|
||||
/** `id is required` stays the handler's answer, so id is optional here. */
|
||||
export class PluginInstallDto extends createZodDto(
|
||||
z.looseObject({
|
||||
id: z.string().optional(),
|
||||
version: z.string().optional(),
|
||||
constraint: z.string().optional(),
|
||||
withDependencies: z.boolean().optional(),
|
||||
}),
|
||||
) {}
|
||||
|
||||
/** `path is required` likewise, and dev-link answers 403 before reading it. */
|
||||
export class PluginLinkDto extends createZodDto(
|
||||
z.looseObject({ path: z.string().optional() }),
|
||||
) {}
|
||||
|
||||
export class PluginActivateDto extends createZodDto(
|
||||
z.looseObject({ consent: z.boolean().optional() }),
|
||||
) {}
|
||||
|
||||
export class PluginUninstallDto extends createZodDto(
|
||||
z.looseObject({ deleteData: z.boolean().optional() }),
|
||||
) {}
|
||||
|
||||
export class PluginRetrustDto extends createZodDto(
|
||||
z.looseObject({ version: z.string().optional(), publicKey: z.string().optional() }),
|
||||
) {}
|
||||
|
||||
/**
|
||||
* `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 class PluginEgressHostsDto extends createZodDto(
|
||||
z.looseObject({ hosts: z.unknown().optional() }),
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Plugin instance config is defined by the plugin's own manifest, not by TREK,
|
||||
* so there is no shape to assert here beyond "a JSON object".
|
||||
*/
|
||||
export class PluginConfigDto extends createZodDto(z.looseObject({})) {}
|
||||
|
||||
export class PluginUserSettingsUpdateDto extends createZodDto(
|
||||
z.looseObject({ config: z.record(z.string(), z.unknown()).optional() }),
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 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 class PluginRouteDto extends createZodDto(z.looseObject({})) {}
|
||||
Reference in New Issue
Block a user