We need to inspect a small TypeScript module that loads an offer theme by market key and locale, then returns a snapshot for a preview screen. After a recent change the behavior became unstable: different variants sometimes receive the same theme, and local edits suddenly affect subsequent reads from the cache.
loadOfferTheme(input, fetchTheme) must:
market and locale fields;trim() and toLowerCase();market::locale;fetchTheme(normalized) only on a cache miss.palette.primary and palette.accent are non-empty strings;badges is an array of strings.Error with text Invalid theme payload must be thrown.import { loadOfferTheme, resetThemeCache } from './offerThemeCache.ts';
resetThemeCache();
const fetchTheme = async ({ market, locale }) => ({
id: `${market}/${locale}`,
palette: { primary: '#111111', accent: '#ff9900' },
badges: [market, locale]
});
const a = await loadOfferTheme({ market: ' DE ', locale: 'de-DE' }, fetchTheme);
const b = await loadOfferTheme({ market: 'DE', locale: 'en-GB' }, fetchTheme);
a.badges.push('edited');
const c = await loadOfferTheme({ market: 'de', locale: 'de-de' }, fetchTheme);
a.id, b.id and c.badges.DE/de-DE and DE/en-GB must go to different cache entries.badges array in the returned value must not alter the data that is later read from the cache.22.x5.8ES modulesstrict=truenpx tsc --noEmitfetchTheme returns Promise<unknown> and can be replaced by a testUse line comments to explain the problem, its impact, the fix and how to test it.