In TypeScript 5.8 (strict=true) for Node.js 22 and ES modules, the profile template preview module needs to be checked. The exported function accepts raw input, validates it, normalizes the cache key, and returns the final snapshot. Behavior requirements: 1) empty or whitespace-only strings are considered invalid and must result in a safe error; 2) the cache must distinguish the logical template key from the raw query text; 3) calls must not gain access to shared mutable nested data through returned values; 4) on an error, the response must preserve the correct status and reason. The repository has 2 files. Run with: node --enable-source-maps --input-type=module for quick checks and tsc -p tsconfig.json with no additional dependencies. Assumption: the network layer is replaced by test promises, and no external HTTP client is used.
TypeScript 5.8, strict=true, Node.js 22, ES modules; no additional packages; run with tsc -p tsconfig.json and via Node.js 22 with ESM imports.
Use line comments to explain the problem, its impact, the fix and how to test it.