79 lines
2.8 KiB
JavaScript
79 lines
2.8 KiB
JavaScript
import { getSystemPagePath } from '../pages/index.js';
|
|
import { getGlobal } from '../payload/index.js';
|
|
import { CONSENT_CATEGORIES } from './categories.js';
|
|
/** English fallback used when the global has no value for a field. */ const FALLBACK = {
|
|
buttons: {
|
|
acceptAll: 'Accept all',
|
|
back: 'Back',
|
|
reject: 'Reject',
|
|
save: 'Save preferences',
|
|
settings: 'Settings'
|
|
},
|
|
categories: {
|
|
analytics: {
|
|
description: 'Help us understand usage.',
|
|
title: 'Analytics'
|
|
},
|
|
functional: {
|
|
description: 'Remember preferences.',
|
|
title: 'Functional'
|
|
},
|
|
marketing: {
|
|
description: 'Used to show relevant ads.',
|
|
title: 'Marketing'
|
|
},
|
|
necessary: {
|
|
description: 'Required for the site to work, including your language and theme preferences. Always on.',
|
|
title: 'Necessary'
|
|
}
|
|
},
|
|
message: 'We use cookies to run the site, analyze traffic, and improve your experience. You can accept all, reject non-essential, or choose which to allow.',
|
|
privacyLink: null,
|
|
settingsTitle: 'Cookie settings'
|
|
};
|
|
/**
|
|
* Resolves consent banner texts from the CookieSettings global, falling back to
|
|
* English defaults per field. The privacy-policy link is built from the pages
|
|
* module (system page role), not stored in CookieSettings — one source of truth.
|
|
*/ export async function getConsentTexts({ config, locale, payload, privacyPolicy }) {
|
|
const g = await getGlobal(payload, 'cookie-settings', {
|
|
locale
|
|
});
|
|
const categories = {};
|
|
for (const cat of CONSENT_CATEGORIES){
|
|
const entry = g.categories?.find((c)=>c.key === cat);
|
|
categories[cat] = {
|
|
description: entry?.description || FALLBACK.categories[cat].description,
|
|
title: entry?.title || FALLBACK.categories[cat].title
|
|
};
|
|
}
|
|
let privacyLink = null;
|
|
if (privacyPolicy?.page && locale) {
|
|
const href = getSystemPagePath({
|
|
config,
|
|
locale,
|
|
page: privacyPolicy.page
|
|
});
|
|
if (href) {
|
|
privacyLink = {
|
|
href,
|
|
label: privacyPolicy.label
|
|
};
|
|
}
|
|
}
|
|
return {
|
|
buttons: {
|
|
acceptAll: g.buttons?.acceptAll || FALLBACK.buttons.acceptAll,
|
|
back: g.buttons?.back || FALLBACK.buttons.back,
|
|
reject: g.buttons?.reject || FALLBACK.buttons.reject,
|
|
save: g.buttons?.save || FALLBACK.buttons.save,
|
|
settings: g.buttons?.settings || FALLBACK.buttons.settings
|
|
},
|
|
categories,
|
|
message: g.message || FALLBACK.message,
|
|
privacyLink,
|
|
settingsTitle: g.settingsTitle || FALLBACK.settingsTitle
|
|
};
|
|
}
|
|
|
|
//# sourceMappingURL=getConsentTexts.js.map
|