Theme key 'theme', storage keys in the cookie scanner, type in the cookie list
- Theme choice in localStorage under 'theme' (next-themes' key and values)
instead of 'ipal-theme'. ThemeScript moves an old choice before the first
paint and removes the old key; useTheme / ThemeSwitcher do the same
without the script. ipalKit({ theme: { storageKey } }) sets an own key,
which reaches ThemeScript through getSiteShell().theme and <html
data-theme-storage>.
- The cookie scanner declares the theme key (Theme choice: local storage,
necessary, until changed or site data is cleared) when the theme switch
is on, so Scan cookies finds it without a crawl.
- Cookies -> Cookie list rows get a Type (cookie / local storage / session
storage, default cookie, shared by every language), filled by scan, review
and approval. The detailed settings window and <CookieTable> show it with
English and Polish defaults; the approval page marks storage entries.
- Migration: adds cookie_settings_cookies.storage (DEFAULT 'cookie') and
cookie_settings_locales.detail_labels_storage, nothing else.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6998b44431
commit
b5368cdc61
@@ -337,6 +337,12 @@ export function CookieBanner({
|
||||
<dd>{row.duration}</dd>
|
||||
</>
|
||||
)}
|
||||
{row.storage && row.storage !== 'cookie' && labels.storage && (
|
||||
<>
|
||||
<dt>{labels.storage}</dt>
|
||||
<dd>{labels.storageTypes?.[row.storage] ?? row.storage}</dd>
|
||||
</>
|
||||
)}
|
||||
</dl>
|
||||
</li>
|
||||
))}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { CookieTableRow } from './getConsentTexts.js'
|
||||
import type { ConsentTexts } from './texts.js'
|
||||
import type { ConsentStorage, ConsentTexts } from './texts.js'
|
||||
|
||||
export type CookieTableLabels = {
|
||||
category: string
|
||||
@@ -7,12 +7,20 @@ export type CookieTableLabels = {
|
||||
name: string
|
||||
provider: string
|
||||
purpose: string
|
||||
/** "Type" column (cookie / local storage / session storage). */
|
||||
storage: string
|
||||
}
|
||||
|
||||
/** Default column headings, per language. */
|
||||
export const COOKIE_TABLE_LABELS: { en: CookieTableLabels; pl: CookieTableLabels } = {
|
||||
en: { name: 'Cookie', category: 'Category', duration: 'Duration', provider: 'Provider', purpose: 'Purpose' },
|
||||
pl: { name: 'Plik cookie', category: 'Kategoria', duration: 'Okres', provider: 'Dostawca', purpose: 'Cel' },
|
||||
en: { name: 'Cookie', category: 'Category', duration: 'Duration', provider: 'Provider', purpose: 'Purpose', storage: 'Type' },
|
||||
pl: { name: 'Plik cookie', category: 'Kategoria', duration: 'Okres', provider: 'Dostawca', purpose: 'Cel', storage: 'Rodzaj' },
|
||||
}
|
||||
|
||||
/** Default names of the storage types, per language. */
|
||||
export const COOKIE_STORAGE_LABELS: { en: Record<ConsentStorage, string>; pl: Record<ConsentStorage, string> } = {
|
||||
en: { cookie: 'Cookie', localStorage: 'Local storage', sessionStorage: 'Session storage' },
|
||||
pl: { cookie: 'Plik cookie', localStorage: 'Pamięć lokalna', sessionStorage: 'Pamięć sesji' },
|
||||
}
|
||||
|
||||
type CookieTableProps = {
|
||||
@@ -31,6 +39,13 @@ type CookieTableProps = {
|
||||
locale?: string
|
||||
/** From getCookieTable({ payload, locale }) — Cookie Settings → Cookies. */
|
||||
rows: CookieTableRow[]
|
||||
/**
|
||||
* The "Type" column. Default `'auto'`: shown when the list has an entry that is
|
||||
* not a cookie (local / session storage). `true` always, `false` never.
|
||||
*/
|
||||
storageColumn?: 'auto' | boolean
|
||||
/** Names of the types — default per `locale` (e.g. `texts.details.storageTypes`). */
|
||||
storageTypes?: Partial<Record<ConsentStorage, string>>
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,15 +57,19 @@ type CookieTableProps = {
|
||||
* const rows = await getCookieTable({ payload, locale })
|
||||
* <CookieTable rows={rows} locale={locale} categories={texts.categories} /> // labels={…} to change the headings
|
||||
*/
|
||||
export function CookieTable({ caption, categories, classNames = {}, labels: given, locale, rows }: CookieTableProps) {
|
||||
export function CookieTable({ caption, categories, classNames = {}, labels: given, locale, rows, storageColumn = 'auto', storageTypes }: CookieTableProps) {
|
||||
if (rows.length === 0) {return null}
|
||||
const labels = { ...(locale?.toLowerCase().startsWith('pl') ? COOKIE_TABLE_LABELS.pl : COOKIE_TABLE_LABELS.en), ...Object.fromEntries(Object.entries(given ?? {}).filter(([, v]) => v)) }
|
||||
const pl = locale?.toLowerCase().startsWith('pl')
|
||||
const labels = { ...(pl ? COOKIE_TABLE_LABELS.pl : COOKIE_TABLE_LABELS.en), ...Object.fromEntries(Object.entries(given ?? {}).filter(([, v]) => v)) }
|
||||
const types = { ...(pl ? COOKIE_STORAGE_LABELS.pl : COOKIE_STORAGE_LABELS.en), ...storageTypes }
|
||||
const showStorage = storageColumn === 'auto' ? rows.some((r) => r.storage && r.storage !== 'cookie') : storageColumn
|
||||
return (
|
||||
<table className={classNames.table}>
|
||||
{caption ? <caption className={classNames.caption}>{caption}</caption> : null}
|
||||
<thead>
|
||||
<tr className={classNames.tr}>
|
||||
<th className={classNames.th} scope="col">{labels.name}</th>
|
||||
{showStorage ? <th className={classNames.th} scope="col">{labels.storage}</th> : null}
|
||||
<th className={classNames.th} scope="col">{labels.provider}</th>
|
||||
<th className={classNames.th} scope="col">{labels.category}</th>
|
||||
<th className={classNames.th} scope="col">{labels.purpose}</th>
|
||||
@@ -61,6 +80,7 @@ export function CookieTable({ caption, categories, classNames = {}, labels: give
|
||||
{rows.map((row) => (
|
||||
<tr className={classNames.tr} key={`${row.category}:${row.name}`}>
|
||||
<td className={classNames.td}><code>{row.name}</code></td>
|
||||
{showStorage ? <td className={classNames.td}>{types[row.storage ?? 'cookie']}</td> : null}
|
||||
<td className={classNames.td}>{row.provider ?? ''}</td>
|
||||
<td className={classNames.td}>{categories?.[row.category]?.title ?? row.category}</td>
|
||||
<td className={classNames.td}>{row.purpose ?? ''}</td>
|
||||
|
||||
@@ -28,7 +28,14 @@ export const CONSENT_FALLBACK: ConsentTexts = {
|
||||
title: 'Necessary',
|
||||
},
|
||||
},
|
||||
details: { cookies: 'Cookies used', duration: 'Duration', provider: 'Provider', purpose: 'Purpose' },
|
||||
details: {
|
||||
cookies: 'Cookies used',
|
||||
duration: 'Duration',
|
||||
provider: 'Provider',
|
||||
purpose: 'Purpose',
|
||||
storage: 'Type',
|
||||
storageTypes: { cookie: 'Cookie', localStorage: 'Local storage', sessionStorage: 'Session storage' },
|
||||
},
|
||||
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,
|
||||
@@ -54,7 +61,14 @@ export const CONSENT_FALLBACK_PL: ConsentTexts = {
|
||||
title: 'Niezbędne',
|
||||
},
|
||||
},
|
||||
details: { cookies: 'Używane cookies', duration: 'Okres', provider: 'Dostawca', purpose: 'Cel' },
|
||||
details: {
|
||||
cookies: 'Używane cookies',
|
||||
duration: 'Okres',
|
||||
provider: 'Dostawca',
|
||||
purpose: 'Cel',
|
||||
storage: 'Rodzaj',
|
||||
storageTypes: { cookie: 'Plik cookie', localStorage: 'Pamięć lokalna', sessionStorage: 'Pamięć sesji' },
|
||||
},
|
||||
message:
|
||||
'Używamy plików cookies, aby witryna działała, aby analizować ruch i ulepszać witrynę. Można zaakceptować wszystkie, odrzucić te, które nie są niezbędne, lub wybrać je samodzielnie.',
|
||||
privacyLink: null,
|
||||
@@ -79,8 +93,8 @@ type CookieSettingsData = {
|
||||
savePreferences?: null | string
|
||||
} & Partial<Omit<ConsentTexts['buttons'], 'save'>>) | null
|
||||
categories?: Array<{ description?: null | string; key: string; title?: null | string }> | null
|
||||
cookies?: Array<{ category?: null | string; duration?: null | string; name?: null | string; provider?: null | string; purpose?: null | string }> | null
|
||||
detailLabels?: null | Partial<Record<keyof NonNullable<ConsentTexts['details']>, null | string>>
|
||||
cookies?: Array<{ category?: null | string; duration?: null | string; name?: null | string; provider?: null | string; purpose?: null | string; storage?: null | string }> | null
|
||||
detailLabels?: null | Partial<Record<Exclude<keyof NonNullable<ConsentTexts['details']>, 'storageTypes'>, null | string>>
|
||||
eyebrow?: null | string
|
||||
message?: null | string
|
||||
policyVersion?: null | number
|
||||
@@ -192,6 +206,8 @@ export async function getConsentTexts({
|
||||
duration: g.detailLabels?.duration?.trim() || FALLBACK.details!.duration,
|
||||
provider: g.detailLabels?.provider?.trim() || FALLBACK.details!.provider,
|
||||
purpose: g.detailLabels?.purpose?.trim() || FALLBACK.details!.purpose,
|
||||
storage: g.detailLabels?.storage?.trim() || FALLBACK.details!.storage,
|
||||
storageTypes: FALLBACK.details!.storageTypes,
|
||||
},
|
||||
message: g.message || FALLBACK.message,
|
||||
privacyLink,
|
||||
@@ -217,6 +233,7 @@ function toCookieRows(cookies: CookieSettingsData['cookies']): CookieTableRow[]
|
||||
...(c.provider?.trim() ? { provider: c.provider.trim() } : {}),
|
||||
...(c.purpose?.trim() ? { purpose: c.purpose.trim() } : {}),
|
||||
...(c.duration?.trim() ? { duration: c.duration.trim() } : {}),
|
||||
...(c.storage === 'localStorage' || c.storage === 'sessionStorage' ? { storage: c.storage } : { storage: 'cookie' as const }),
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
@@ -23,4 +23,4 @@ export {
|
||||
readConsentRecord,
|
||||
serializeConsent,
|
||||
} from './storage.js'
|
||||
export type { ConsentTexts } from './texts.js'
|
||||
export type { ConsentStorage, ConsentTexts } from './texts.js'
|
||||
|
||||
@@ -124,6 +124,7 @@ export function CookieApprovalForm({
|
||||
{p.change === 'new' ? <span className="ipal-badge ipal-badge--new">{t.markerNew}</span> : null}
|
||||
{p.change === 'changed' ? <span className="ipal-badge ipal-badge--changed">{t.markerChanged}</span> : null}
|
||||
{p.unknown ? <span className="ipal-badge ipal-badge--unknown">{t.markerUnknown}</span> : null}
|
||||
{p.storage && p.storage !== 'cookie' ? <span className="ipal-badge">{t[p.storage]}</span> : null}
|
||||
</div>
|
||||
</td>
|
||||
<td>{p.vendor ?? ''}</td>
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { BasePayload, Endpoint, PayloadRequest, Where } from 'payload'
|
||||
import type { ConsentCategory } from '../categories.js'
|
||||
import type { CookieReviewValues } from './merge.js'
|
||||
import type { CookieChange } from './scan.js'
|
||||
import type { CookieScannerOptions } from './types.js'
|
||||
import type { CookieScannerOptions, CookieStorage } from './types.js'
|
||||
|
||||
import { userMeetsRole } from '../../access/predicates.js'
|
||||
import { CONSENT_CATEGORIES } from '../categories.js'
|
||||
@@ -30,6 +30,8 @@ export type CookieApprovalItem = {
|
||||
name: string
|
||||
purpose: null | string
|
||||
retention: null | string
|
||||
/** Cookie, or a key in the browser's local / session storage. */
|
||||
storage: CookieStorage
|
||||
/** Nothing knew it: no category or no purpose yet. */
|
||||
unknown: boolean
|
||||
vendor: null | string
|
||||
@@ -53,6 +55,7 @@ type Doc = {
|
||||
retention?: null | Record<string, null | string> | string
|
||||
source?: null | string
|
||||
status?: 'accepted' | 'draft' | 'rejected' | null
|
||||
storage?: CookieStorage | null
|
||||
vendor?: null | string
|
||||
}
|
||||
|
||||
@@ -73,6 +76,7 @@ function item(doc: Doc, locale: string): CookieApprovalItem {
|
||||
change: doc.change ?? null,
|
||||
purpose,
|
||||
retention: asText(doc.retention, locale),
|
||||
storage: doc.storage ?? 'cookie',
|
||||
unknown: !doc.category || !purpose || doc.source === 'unknown',
|
||||
vendor: doc.vendor ?? null,
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { CookieDeclaration, CookieIntegration, CookieScanContext } from './
|
||||
import { adminTexts } from '../../admin-i18n/texts/index.js'
|
||||
import { validAnalyticsId } from '../../analytics/idFormats.js'
|
||||
import { LOCALE_COOKIE_NAME } from '../../i18n/negotiateLocale.js'
|
||||
import { THEME_STORAGE_KEY } from '../../theme/theme.js'
|
||||
import { getTurnstileConfig } from '../../turnstile/config.js'
|
||||
import { CONSENT_COOKIE } from '../storage.js'
|
||||
import { textFor } from './merge.js'
|
||||
@@ -19,6 +20,17 @@ const months = (n: number) => T(`${n} months`, `${n} mies.`)
|
||||
const YEAR = T('1 year', '1 rok')
|
||||
const TWO_YEARS = T('2 years', '2 lata')
|
||||
const SITE = 'This site'
|
||||
const UNTIL_CHANGED = T('Until changed or site data is cleared', 'Do zmiany lub wyczyszczenia danych witryny')
|
||||
|
||||
/** Site Settings → Theme → visitors may switch: only then is the choice stored. */
|
||||
async function themeToggleOn(ctx: CookieScanContext): Promise<boolean> {
|
||||
try {
|
||||
const settings = (await ctx.payload.findGlobal({ slug: 'site-settings' as never, depth: 0 })) as { allowThemeToggle?: boolean }
|
||||
return settings.allowThemeToggle === true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
/** A name from the shared admin texts, in every admin language the plugin ships. */
|
||||
const A = (key: AdminTextKey) => ({ en: adminTexts.en[key], pl: adminTexts.pl[key] })
|
||||
|
||||
@@ -47,6 +59,24 @@ export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
|
||||
key: 'consent',
|
||||
label: A('cookieIntegrationConsent'),
|
||||
},
|
||||
{
|
||||
// Browser storage, not a cookie: the light / dark choice the visitor made themselves —
|
||||
// a preference they asked for, so necessary (no separate consent); editable in review.
|
||||
declarations: (ctx) => [
|
||||
{
|
||||
name: ctx.plugin.themeStorageKey || THEME_STORAGE_KEY,
|
||||
category: 'necessary',
|
||||
purpose: T('Remembers the light or dark theme you chose.', 'Zapamiętuje wybrany motyw: jasny lub ciemny.'),
|
||||
retention: UNTIL_CHANGED,
|
||||
setBeforeConsent: true,
|
||||
storage: 'localStorage',
|
||||
vendor: SITE,
|
||||
},
|
||||
],
|
||||
isEnabled: themeToggleOn,
|
||||
key: 'theme',
|
||||
label: A('cookieIntegrationTheme'),
|
||||
},
|
||||
{
|
||||
declarations: (ctx) => [
|
||||
{
|
||||
|
||||
@@ -11,9 +11,10 @@ type Row = {
|
||||
name?: null | string
|
||||
provider?: null | string
|
||||
purpose?: null | string
|
||||
storage?: null | string
|
||||
}
|
||||
|
||||
type Entry = { name: string } & CookieReviewValues
|
||||
type Entry = { name: string; storage?: null | string } & CookieReviewValues
|
||||
|
||||
const empty = (v: unknown) => v === undefined || v === null || (typeof v === 'string' && !v.trim())
|
||||
|
||||
@@ -64,6 +65,7 @@ export async function addToCookieList({
|
||||
duration: text(entry.retention, locale),
|
||||
provider: entry.vendor ?? null,
|
||||
purpose: text(entry.purpose, locale),
|
||||
storage: entry.storage ?? 'cookie',
|
||||
})
|
||||
changed = true
|
||||
result = 'added'
|
||||
@@ -74,7 +76,14 @@ export async function addToCookieList({
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if (i === 0) {fill('provider', entry.vendor)}
|
||||
if (i === 0) {
|
||||
fill('provider', entry.vendor)
|
||||
// A row from before the type existed has none; the type is shared by every language.
|
||||
if (empty(row.storage) && entry.storage) {
|
||||
row.storage = entry.storage
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
fill('purpose', text(entry.purpose, locale))
|
||||
fill('duration', text(entry.retention, locale))
|
||||
if (changed && result === 'unchanged') {result = 'filled'}
|
||||
|
||||
@@ -38,7 +38,8 @@ export type CookieScanContext = {
|
||||
language?: string
|
||||
payload: BasePayload
|
||||
/** Plugin options that switch modules on. */
|
||||
plugin: { localeCount: number; stats: boolean }
|
||||
/** Plugin options that switch modules on; `themeStorageKey` = `ipalKit({ theme: { storageKey } })`. */
|
||||
plugin: { localeCount: number; stats: boolean; themeStorageKey?: string }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import type { ConsentCategory } from './categories.js'
|
||||
|
||||
/** Where an entry of the cookie list is kept in the browser. */
|
||||
export type ConsentStorage = 'cookie' | 'localStorage' | 'sessionStorage'
|
||||
|
||||
export type ConsentTexts = {
|
||||
/** Badge next to the necessary category (e.g. "Always active"). Empty = no badge. */
|
||||
alwaysActiveLabel?: string
|
||||
@@ -26,6 +29,10 @@ export type ConsentTexts = {
|
||||
duration: string
|
||||
provider: string
|
||||
purpose: string
|
||||
/** Label of the type line, e.g. "Type" — shown for entries that are not cookies. */
|
||||
storage?: string
|
||||
/** Names of the types, e.g. { cookie: 'Cookie', localStorage: 'Local storage', … }. */
|
||||
storageTypes?: Record<ConsentStorage, string>
|
||||
}
|
||||
/** Small label above the banner title (e.g. "Privacy & cookies"). Empty = not shown. */
|
||||
eyebrow?: string
|
||||
@@ -48,4 +55,6 @@ export type CookieTableRow = {
|
||||
name: string
|
||||
provider?: string
|
||||
purpose?: string
|
||||
/** Cookie (default) or a browser-storage key. */
|
||||
storage?: ConsentStorage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user