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