import { flatpage } from '../urls'; import { FlatPage } from '../../types'; import appFetch from '../../utils/app-fetch'; import { Cache, CacheKey } from '../../lib/cache'; import { ServerVariables } from '../../utils/server-variables'; const getFlatPageDataHandler = ( pk: number, locale: string, currency: string, headers?: Record ) => { return async function () { const data = await appFetch({ url: flatpage.getFlatPageByPk(pk), locale, currency, init: { headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...(headers ?? {}) } } }); return data; }; }; export const getFlatPageData = ({ pk, locale = ServerVariables.locale, currency = ServerVariables.currency, headers }: { pk: number; locale?: string; currency?: string; headers?: Record; }) => { return Cache.wrap( CacheKey.FlatPage(pk), locale, getFlatPageDataHandler(pk, locale, currency, headers), { compressed: true } ); };