refactor: dedupe infra lowercase helpers

This commit is contained in:
Peter Steinberger
2026-04-07 12:45:04 +01:00
parent 8e4eaec394
commit 9716f970a3
15 changed files with 48 additions and 31 deletions

View File

@@ -1,3 +1,5 @@
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
/** Read loose boolean params from tool input that may arrive as booleans or "true"/"false" strings. */
export function readBooleanParam(
params: Record<string, unknown>,
@@ -7,14 +9,12 @@ export function readBooleanParam(
if (typeof raw === "boolean") {
return raw;
}
if (typeof raw === "string") {
const trimmed = raw.trim().toLowerCase();
if (trimmed === "true") {
return true;
}
if (trimmed === "false") {
return false;
}
const normalized = normalizeOptionalLowercaseString(raw);
if (normalized === "true") {
return true;
}
if (normalized === "false") {
return false;
}
return undefined;
}

View File

@@ -8,6 +8,7 @@ import {
requestBodyErrorToText,
} from "../infra/http-body.js";
import { pruneMapToMaxSize } from "../infra/map-size.js";
import { normalizeOptionalLowercaseString } from "../shared/string-coerce.js";
import type { FixedWindowRateLimiter } from "./webhook-memory-guards.js";
export type WebhookBodyReadProfile = "pre-auth" | "post-auth";
@@ -144,7 +145,7 @@ export function isJsonContentType(value: string | string[] | undefined): boolean
if (!first) {
return false;
}
const mediaType = first.split(";", 1)[0]?.trim().toLowerCase();
const mediaType = normalizeOptionalLowercaseString(first.split(";", 1)[0]);
return mediaType === "application/json" || Boolean(mediaType?.endsWith("+json"));
}