{p.name}
+ {t.approvalIntro}
+ {groups.map((g) => ( +{g.note}
: null} +{t.approvalEmpty}
+ )} + {done ? ( ++ ✓ {fill(t.approvalDone, { ...done })} {t.openCookieBanner} +
+ ) : null} + {gone.length ? ( +{t.goneNote}
+{t('approvalNoAccess')}
+ )} +{fill(t('alertFailed'), { error: doc.error ?? '' })}
: null} + {findings ? ( <> - {fill(t('alertTitle'), { newUnknown, violations })} +{fill(t('alertTitle'), { newUnknown, violations })}
{t('alertBody')}
+ + {t('alertLink')} + > - )} - - {t('alertLink')} - + ) : null} + {pending ? ( ++ {fill(t('approvalPending'), { count: pending })}{' '} + {t('approvalLink')} +
+ ) : null} + {failed && !findings && !pending ? ( + + {t('alertLink')} + + ) : null}${esc(v.name)} (${esc(v.kind)}${v.category ? `, ${esc(v.category)}` : ''}) — ${esc(fill(t('beforeConsentOn'), { pages: v.pages.join(', ') }))}${esc(fill(t('emailIntro'), values))}
-${esc(fill(t('alertTitle'), values))}
+${problems ? `${esc(fill(t('alertTitle'), values))}
` : ''} ${items ? `${esc(t('alertBody'))}
-` +${problems ? `${esc(t('alertBody'))}
\n` : ''} +${pending ? `${esc(fill(t('emailPending'), { count: pending }))}
\n` : ''}` try { - await payload.sendEmail({ html, subject: fill(t('emailSubject'), values), to }) + const subject = problems || !pending ? fill(t('emailSubject'), values) : fill(t('emailSubjectPending'), { count: pending, site }) + await payload.sendEmail({ html, subject, to }) return true } catch (err) { payload.logger.error(`[ipal] cookie crawl warning e-mail failed: ${err instanceof Error ? err.message : String(err)}`) diff --git a/src/modules/consent/scanner/index.ts b/src/modules/consent/scanner/index.ts index 6e2c8f2..9688189 100644 --- a/src/modules/consent/scanner/index.ts +++ b/src/modules/consent/scanner/index.ts @@ -1,4 +1,15 @@ // Cookie scanner — server-safe building blocks. The admin button is in /admin. +export { + approveCookies, + buildCookieApprovalEndpoints, + COOKIE_APPROVAL_PATH, + COOKIE_APPROVAL_VIEW_PATH, + countPendingCookies, + DEFAULT_UNKNOWN_CATEGORY, + loadCookieApproval, + PENDING_WHERE, +} from './approval.js' +export type { CookieApprovalItem, CookieApprovalList, CookieApprovalResult } from './approval.js' export { buildCookieReviewCollection, COOKIE_REVIEW_SLUG } from './collection.js' export { DEFAULT_DATABASE_CATEGORIES, indexCookieDatabase, loadCookieDatabase, lookupCookie } from './cookieDatabase.js' export type { CookieDatabaseIndex } from './cookieDatabase.js' @@ -26,10 +37,11 @@ export { COOKIE_SCAN_LABELS, mergeCookieScanLabels } from './labels.js' export type { CookieScanLabels } from './labels.js' export { mergeCookieReview, suggestionFor } from './merge.js' export type { CookieReviewValues } from './merge.js' -export { applyCookieFindings, collectCookieFindings, cookieScanContext, parseCookieNames, runCookieScan } from './scan.js' -export type { CookieObservation, CookieReviewEntryRef } from './scan.js' -export { addToCookieList } from './sync.js' +export { applyCookieFindings, collectCookieFindings, cookieScanContext, flagGoneEntries, nextChange, parseCookieNames, runCookieScan } from './scan.js' +export type { CookieChange, CookieObservation, CookieReviewEntryRef } from './scan.js' +export { addToCookieList, sameCookie } from './sync.js' export type { + CookieApprovalOptions, CookieCrawlOptions, CookieDeclaration, CookieFinding, diff --git a/src/modules/consent/scanner/labels.ts b/src/modules/consent/scanner/labels.ts index 3b7992b..4851e54 100644 --- a/src/modules/consent/scanner/labels.ts +++ b/src/modules/consent/scanner/labels.ts @@ -10,9 +10,25 @@ export type CookieScanLabels = { alertLink: string alertTitle: string analytics: string + approvalButton: string + approvalDone: string + approvalEmpty: string + approvalError: string + approvalIntro: string + approvalLink: string + approvalNoAccess: string + approvalPending: string + approvalSelected: string + approvalTitle: string + approving: string beforeConsentOn: string category: string categoryRequired: string + change: string + changeChanged: string + changeDescription: string + changeGone: string + changeNew: string collectionDescription: string cookie: string crawlButton: string @@ -38,10 +54,16 @@ export type CookieScanLabels = { database: string domain: string draft: string + edit: string emailIntro: string + emailPending: string emailSubject: string + emailSubjectPending: string finishedAt: string functional: string + goneNote: string + goneTitle: string + include: string integration: string integrationsFound: string integrationsNone: string @@ -50,14 +72,20 @@ export type CookieScanLabels = { listedDescription: string localStorage: string manual: string + markerChanged: string + markerNew: string + markerUnknown: string marketing: string name: string namesHint: string namesLabel: string necessary: string + needsDescription: string + needsDescriptionDescription: string notifyEmails: string notifyEmailsDescription: string notifyEmailsInvalid: string + openCookieBanner: string plural: string project: string purpose: string @@ -81,6 +109,8 @@ export type CookieScanLabels = { status: string statusDescription: string storage: string + uncategorized: string + uncategorizedNote: string unknown: string vendor: string violation: string @@ -97,10 +127,26 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { alertLink: 'Open cookie review', alertTitle: 'Cookie check: violations: {violations}, new unknown cookies: {newUnknown}.', analytics: 'Analytics', + approvalButton: 'Approve and add', + approvalDone: 'Added: {added}, completed: {filled}, need a description: {needsDescription}.', + approvalEmpty: 'Nothing is waiting for approval. Scan cookies to look for new ones.', + approvalError: 'Approval failed. Please try again.', + approvalIntro: 'Check the cookies found, untick any you do not want, then add them to the cookie banner and the cookie policy.', + approvalLink: 'Review and approve', + approvalNoAccess: 'You cannot approve cookies. Ask your administrator.', + approvalPending: 'Waiting for approval: {count}.', + approvalSelected: 'Selected: {count}', + approvalTitle: 'Approve cookies', + approving: 'Adding…', beforeConsentOn: 'before consent on {pages}', category: 'Category', categoryRequired: 'Choose a category before accepting.', - collectionDescription: 'Accept a cookie to add it to the cookie list; a new scan never overwrites your edits.', + change: 'Latest scan', + changeChanged: 'Changed', + changeDescription: 'What the latest scan found; approving clears it.', + changeGone: 'No longer found', + changeNew: 'New', + collectionDescription: 'Cookies found by scans; approve them to add them to the cookie banner, your edits are kept.', cookie: 'Cookie', crawlButton: 'Check site', crawlCreated: 'New drafts', @@ -125,10 +171,16 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { database: 'Open Cookie Database', domain: 'Domain', draft: 'Draft', + edit: 'Edit', emailIntro: 'The latest cookie check of {site} found:', + emailPending: 'Cookies waiting for approval: {count}. Nothing is added to the cookie banner until you approve them.', emailSubject: 'Cookie check of {site}: violations: {violations}, new unknown cookies: {newUnknown}', + emailSubjectPending: 'Cookie check of {site}: cookies waiting for approval: {count}', finishedAt: 'Finished', functional: 'Functional', + goneNote: 'They stay in the cookie banner; remove them there if the site no longer uses them.', + goneTitle: 'No longer found', + include: 'Include', integration: 'Built-in integration', integrationsFound: 'Integrations in use', integrationsNone: 'No integration that uses cookies is on.', @@ -137,13 +189,19 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { listedDescription: 'Already in the cookie list of the cookie banner.', localStorage: 'Local storage', manual: 'Added by hand', + markerChanged: 'Changed', + markerNew: 'New', + markerUnknown: 'Needs description', marketing: 'Marketing', namesHint: 'Optional. Other cookie names, one per line. They are looked up in the Open Cookie Database.', namesLabel: 'More cookie names', necessary: 'Necessary', + needsDescription: 'Needs description', + needsDescriptionDescription: 'Write the purpose so visitors know what this cookie does.', notifyEmails: 'Warning e-mails to', notifyEmailsDescription: 'Comma-separated addresses that get a warning when a check finds problems; leave empty for none.', notifyEmailsInvalid: 'Enter e-mail addresses separated by commas, e.g. anna@example.com, jan@example.com.', + openCookieBanner: 'Open cookie banner', plural: 'Cookie review', project: 'Site configuration', purpose: 'Purpose', @@ -151,7 +209,7 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { retention: 'Duration', scanButton: 'Scan cookies', scanError: 'The scan failed. Please try again.', - scanIntro: 'Adds the cookies of the integrations in use as drafts to review.', + scanIntro: 'Finds the cookies of the integrations in use; nothing is added to the cookie banner until you approve.', scanning: 'Scanning…', scanResult: 'New: {created}, updated: {updated}, unchanged: {unchanged}, unknown: {unknown}.', seenBeforeConsent: 'Seen before consent', @@ -166,6 +224,8 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { status: 'Status', statusDescription: 'Accepted cookies are added to the cookie list; rejecting never removes them from it.', storage: 'Stored in', + uncategorized: 'Not yet described', + uncategorizedNote: 'Nothing is known about these yet; they are added as {category} until you describe them.', unknown: 'Unknown', vendor: 'Provider', violation: 'Violation', @@ -180,10 +240,26 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { alertLink: 'Otwórz przegląd cookies', alertTitle: 'Kontrola cookies: naruszenia: {violations}, nowe nieznane cookies: {newUnknown}.', analytics: 'Analityczne', + approvalButton: 'Zatwierdź i dodaj', + approvalDone: 'Dodano: {added}, uzupełniono: {filled}, wymaga opisu: {needsDescription}.', + approvalEmpty: 'Nic nie czeka na zatwierdzenie. Zeskanuj cookies, aby znaleźć nowe.', + approvalError: 'Zatwierdzenie się nie powiodło. Spróbuj ponownie.', + approvalIntro: 'Sprawdź znalezione cookies, odznacz niepotrzebne i dodaj je do banera cookies oraz polityki cookies.', + approvalLink: 'Przejrzyj i zatwierdź', + approvalNoAccess: 'Brak uprawnień do zatwierdzania cookies. Zapytaj administratora.', + approvalPending: 'Czeka na zatwierdzenie: {count}.', + approvalSelected: 'Zaznaczone: {count}', + approvalTitle: 'Zatwierdzanie cookies', + approving: 'Dodawanie…', beforeConsentOn: 'przed zgodą na {pages}', category: 'Kategoria', categoryRequired: 'Wybierz kategorię przed akceptacją.', - collectionDescription: 'Zaakceptuj plik cookie, aby dodać go do listy cookies; kolejny skan nie nadpisze zmian.', + change: 'Ostatni skan', + changeChanged: 'Zmieniony', + changeDescription: 'Co wykrył ostatni skan; zatwierdzenie to czyści.', + changeGone: 'Już nie występuje', + changeNew: 'Nowy', + collectionDescription: 'Cookies znalezione przez skany; zatwierdź je, aby dodać do banera cookies, wprowadzone zmiany zostają.', cookie: 'Cookie', crawlButton: 'Sprawdź witrynę', crawlCreated: 'Nowe szkice', @@ -208,10 +284,16 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { database: 'Open Cookie Database', domain: 'Domena', draft: 'Szkic', + edit: 'Edytuj', emailIntro: 'Ostatnia kontrola cookies witryny {site} wykazała:', + emailPending: 'Cookies czekające na zatwierdzenie: {count}. Nic nie trafi do banera cookies bez zatwierdzenia.', emailSubject: 'Kontrola cookies {site}: naruszenia: {violations}, nowe nieznane cookies: {newUnknown}', + emailSubjectPending: 'Skan cookies {site}: cookies czekające na zatwierdzenie: {count}', finishedAt: 'Zakończono', functional: 'Funkcjonalne', + goneNote: 'Zostają w banerze cookies; usuń je tam, jeśli witryna już ich nie używa.', + goneTitle: 'Już nie występują', + include: 'Uwzględnij', integration: 'Wbudowana integracja', integrationsFound: 'Używane integracje', integrationsNone: 'Żadna integracja używająca cookies nie jest włączona.', @@ -220,13 +302,19 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { listedDescription: 'Już jest na liście cookies banera.', localStorage: 'Local storage', manual: 'Dodany ręcznie', + markerChanged: 'Zmieniony', + markerNew: 'Nowy', + markerUnknown: 'Wymaga opisu', marketing: 'Marketingowe', namesHint: 'Opcjonalnie. Inne nazwy cookies, po jednej w wierszu. Zostaną wyszukane w Open Cookie Database.', namesLabel: 'Dodatkowe nazwy cookies', necessary: 'Niezbędne', + needsDescription: 'Wymaga opisu', + needsDescriptionDescription: 'Wpisz cel, aby odwiedzający wiedzieli, do czego służy to cookie.', notifyEmails: 'Ostrzeżenia e-mail do', notifyEmailsDescription: 'Adresy po przecinku, na które trafi ostrzeżenie, gdy kontrola wykryje problemy; zostaw puste, aby nie wysyłać.', notifyEmailsInvalid: 'Wpisz adresy e-mail oddzielone przecinkami, np. anna@example.com, jan@example.com.', + openCookieBanner: 'Otwórz baner cookies', plural: 'Przegląd cookies', project: 'Konfiguracja witryny', purpose: 'Cel', @@ -234,7 +322,7 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { retention: 'Okres', scanButton: 'Skanuj cookies', scanError: 'Skanowanie nie powiodło się. Spróbuj ponownie.', - scanIntro: 'Dodaje cookies używanych integracji jako szkice do przejrzenia.', + scanIntro: 'Wyszukuje cookies używanych integracji; nic nie trafi do banera cookies bez zatwierdzenia.', scanning: 'Skanowanie…', scanResult: 'Nowe: {created}, zaktualizowane: {updated}, bez zmian: {unchanged}, nieznane: {unknown}.', seenBeforeConsent: 'Widoczny przed zgodą', @@ -249,6 +337,8 @@ export const COOKIE_SCAN_LABELS: Record<'en' | 'pl', CookieScanLabels> = { status: 'Status', statusDescription: 'Zaakceptowane cookies trafiają na listę cookies; odrzucenie nigdy ich z niej nie usuwa.', storage: 'Miejsce zapisu', + uncategorized: 'Jeszcze bez opisu', + uncategorizedNote: 'Nic o nich jeszcze nie wiadomo; zostaną dodane jako {category} do czasu uzupełnienia opisu.', unknown: 'Nieznane', vendor: 'Dostawca', violation: 'Naruszenie', diff --git a/src/modules/consent/scanner/scan.ts b/src/modules/consent/scanner/scan.ts index 3f4e596..537e922 100644 --- a/src/modules/consent/scanner/scan.ts +++ b/src/modules/consent/scanner/scan.ts @@ -1,4 +1,4 @@ -import type { BasePayload, PayloadRequest } from 'payload' +import type { BasePayload, PayloadRequest, Where } from 'payload' import type { CookieReviewValues } from './merge.js' import type { @@ -15,6 +15,7 @@ import { COOKIE_REVIEW_SLUG } from './collection.js' import { loadCookieDatabase, lookupCookie } from './cookieDatabase.js' import { cookieNameMatches, declarationsOf, DEFAULT_COOKIE_INTEGRATIONS, integrationLabel, PROJECT_SOURCE } from './integrations.js' import { mergeCookieReview, suggestionFor } from './merge.js' +import { sameCookie } from './sync.js' /** Most names one scan looks up — the panel field is for a handful, not a dump. */ export const MAX_SCAN_NAMES = 200 @@ -142,12 +143,30 @@ export async function collectCookieFindings({ /** A review entry a scan wrote: its id, category (after the merge) and whether it is new. */ export type CookieReviewEntryRef = { category: null | string; created: boolean; id: number | string } +/** What the latest scan or crawl noticed about an entry (shown on the approval page). */ +export type CookieChange = 'changed' | 'gone' | 'new' + type ReviewDoc = { + change?: CookieChange | null id: number | string + key?: string listed?: boolean | null + status?: 'accepted' | 'draft' | 'rejected' | null suggested?: CookieReviewValues | null } & CookieReviewValues +/** + * The marker after a scan: new entries are `new`; a scan that changed an entry's + * suggested values marks it `changed` (a still-unapproved `new` stays `new`); + * finding a `gone` entry again clears it. Rejected entries are never flagged. + */ +export function nextChange(existing: Pick