import { Cache, CacheKey } from '../../lib/cache'; import { category } from '../urls'; import { GetCategoryResponse, SearchParams } from '../../types'; import { generateCommerceSearchParams } from '../../utils'; import appFetch from '../../utils/app-fetch'; import { ServerVariables } from '../../utils/server-variables'; const getSpecialPageDataHandler = ( pk: number, locale: string, currency: string, searchParams: SearchParams, headers?: Record ) => { return async function () { const params = generateCommerceSearchParams(searchParams); const data: GetCategoryResponse = await appFetch({ url: `${category.getSpecialPageByPk(pk)}${params}`, locale, currency, init: { headers: { Accept: 'application/json', 'Content-Type': 'application/json', ...(headers ?? {}) } } }); return data; }; }; export const getSpecialPageData = async ({ pk, locale = ServerVariables.locale, currency = ServerVariables.currency, searchParams, headers }: { pk: number; locale?: string; currency?: string; searchParams: SearchParams; headers?: Record; }) => { return Cache.wrap( CacheKey.SpecialPage(pk, searchParams, headers), locale, getSpecialPageDataHandler(pk, locale, currency, searchParams, headers), { expire: 300, compressed: true } ); };