There is a tariff signature calculation module for server rendering. It runs in Node.js 22 as an ESM module, is built with TypeScript 5.8 in strict=true mode, and does not use third-party dependencies.
Contract:
buildRateLabel(loader, req) accepts a loader and parameters { region, currency }.region and currency are user input; for the cache, variants that differ only in case and surrounding spaces must be treated as the same request.loader call must be executed."<NAME> — <amount> <CURRENCY>", where NAME is taken from the response and converted to uppercase.Loader API:
loader(input) returns Promise<unknown>.{ planName: string, monthly: number }.buildRateLabel must throw Error("Invalid tariff payload").What needs to be done in the review task:
buildRateLabel signature.Environment and run:
module/moduleResolution: NodeNext, target: ES2022, strict: truenode --loader ts-node/esm src/demo.ts or any equivalent TypeScript ESM runnerReproduction steps:
{ planName: "Starter", monthly: 19 }.buildRateLabel in parallel with { region: " eu ", currency: "eur" } and { region: "EU", currency: "EUR" }.loader should be called once.buildRateLabel with the same logical request again after the first two calls complete.loader throws once, and the next call for the same key succeeds.Assumptions:
loader: trim() + toUpperCase() for both fields.monthly may be 0, and this is valid.TypeScript 5.8.x (strict=true), Node.js 22.11.0, ES modules (module/moduleResolution: NodeNext), no external libraries. For local runs, an ESM TypeScript runner is required, for example ts-node in loader mode.
Use line comments to explain the problem, its impact, the fix and how to test it.