Admin follow-ups: localised stats tab title, scanner names, close label, favicon hint

- Statistics view: the browser-tab title follows the admin language.
  Payload's custom-view meta.title is one plain string and its custom-view
  metadata ignores i18n, so the view renders <DocumentTitle> (/admin) with the
  translated title; it re-applies the title while the view is open because
  Next streams the English metadata in after hydration. adminDocumentTitle()
  adds admin.meta.titleSuffix the way Payload does.
- Cookie scanner: CookieIntegration.label may be { en, pl, ... }. The built-in
  names without a product name come from the shared admin texts
  (cookieIntegration*, cookieSourceProject); the scan endpoint answers in the
  request's admin language and stored source names use the scanning editor's.
- Maintenance notice: getConstructionMode(locale) returns `locale`; the "x"
  close button gets a screen-reader name "Close" / "Zamknij" (locale and
  closeLabel props; constructionCloseLabel exported).
- Favicon: FaviconCheck (/admin, afterInput on Site settings -> Site icon)
  warns in the admin language when the image is under 48x48 or not square,
  without blocking the save; validateFaviconField shares faviconProblems().
- Docs, AGENT.md and skills: the above, plus Next.js 16.4.1 or later as the
  minimum safe version (AGENT.md 4.11, ipal-setup, ipal-upgrade).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-27 16:31:46 +01:00
co-authored by Claude Opus 5.5
parent 6f32ea4cdb
commit 546806fe39
35 changed files with 428 additions and 70 deletions
+7 -5
View File
@@ -1,9 +1,9 @@
import type { Endpoint, PayloadRequest } from 'payload'
import type { CookieScanContext, CookieScannerOptions } from './types.js'
import type { CookieIntegration, CookieScanContext, CookieScannerOptions } from './types.js'
import { userMeetsRole } from '../../access/predicates.js'
import { DEFAULT_COOKIE_INTEGRATIONS } from './integrations.js'
import { DEFAULT_COOKIE_INTEGRATIONS, integrationLabel } from './integrations.js'
import { cookieScanContext, enabledCookieIntegrations, parseCookieNames, runCookieScan } from './scan.js'
export const COOKIE_SCAN_PATH = '/ipal/cookie-scan'
@@ -18,14 +18,16 @@ export function buildCookieScanEndpoints(options: CookieScannerOptions, plugin:
const allowed = async (req: PayloadRequest) =>
options.access ? Boolean(await options.access({ req })) : userMeetsRole(req, 'editor')
const integrations = options.integrations ? options.integrations(DEFAULT_COOKIE_INTEGRATIONS) : DEFAULT_COOKIE_INTEGRATIONS
const list = (items: { key: string; label: string }[]) => items.map(({ key, label }) => ({ key, label }))
// Names in the admin language of the editor who asks.
const list = (items: CookieIntegration[], req: PayloadRequest) =>
items.map((i) => ({ key: i.key, label: integrationLabel(i, req.i18n?.language) }))
return [
{
handler: async (req) => {
if (!(await allowed(req))) {return Response.json({ ok: false }, { status: 403 })}
const enabled = await enabledCookieIntegrations(integrations, await cookieScanContext(req.payload, plugin, req))
return Response.json({ integrations: list(enabled), ok: true })
return Response.json({ integrations: list(enabled, req), ok: true })
},
method: 'get',
path: COOKIE_SCAN_PATH,
@@ -41,7 +43,7 @@ export function buildCookieScanEndpoints(options: CookieScannerOptions, plugin:
}
try {
const { enabled, summary } = await runCookieScan({ names: parseCookieNames(body.names), options, payload: req.payload, plugin, req })
return Response.json({ integrations: list(enabled), ok: true, summary })
return Response.json({ integrations: list(enabled, req), ok: true, summary })
} catch (err) {
req.payload.logger.error(`[ipal] cookie scan failed: ${err instanceof Error ? err.message : String(err)}`)
return Response.json({ ok: false }, { status: 500 })
+17 -4
View File
@@ -1,9 +1,12 @@
import type { AdminTextKey } from '../../admin-i18n/texts/index.js'
import type { CookieDeclaration, CookieIntegration, CookieScanContext } from './types.js'
import { adminTexts } from '../../admin-i18n/texts/index.js'
import { validAnalyticsId } from '../../analytics/idFormats.js'
import { LOCALE_COOKIE_NAME } from '../../i18n/negotiateLocale.js'
import { getTurnstileConfig } from '../../turnstile/config.js'
import { CONSENT_COOKIE } from '../storage.js'
import { textFor } from './merge.js'
/** A tag ID from Site Integrations is filled in and valid. */
const hasId = (field: string) => (ctx: CookieScanContext) =>
@@ -16,6 +19,11 @@ 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'
/** 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] })
/** Source name of the project's own `cookieScanner.declarations`. */
export const PROJECT_SOURCE = A('cookieSourceProject')
/**
* Cookies of everything the plugin itself injects — one place per integration.
@@ -37,7 +45,7 @@ export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
],
isEnabled: () => true,
key: 'consent',
label: 'Cookie banner',
label: A('cookieIntegrationConsent'),
},
{
declarations: (ctx) => [
@@ -52,7 +60,7 @@ export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
],
isEnabled: () => true,
key: 'admin',
label: 'Admin panel login',
label: A('cookieIntegrationAdmin'),
},
{
declarations: [
@@ -67,7 +75,7 @@ export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
],
isEnabled: (ctx) => ctx.plugin.localeCount > 1,
key: 'locale',
label: 'Language choice',
label: A('cookieIntegrationLocale'),
},
{
declarations: [
@@ -85,7 +93,7 @@ export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
],
isEnabled: (ctx) => ctx.plugin.stats,
key: 'stats',
label: 'Built-in statistics',
label: A('cookieIntegrationStats'),
},
{
declarations: [
@@ -281,6 +289,11 @@ export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
},
]
/** An integration's name in one admin language (English when that language is missing). */
export function integrationLabel(integration: Pick<CookieIntegration, 'label'>, language = 'en'): string {
return textFor(integration.label, language) ?? ''
}
/** An integration's declarations for this project. */
export function declarationsOf(integration: CookieIntegration, ctx: CookieScanContext): CookieDeclaration[] {
return typeof integration.declarations === 'function' ? integration.declarations(ctx) : integration.declarations
+10 -6
View File
@@ -13,7 +13,7 @@ import type {
import { COOKIE_REVIEW_SLUG } from './collection.js'
import { loadCookieDatabase, lookupCookie } from './cookieDatabase.js'
import { cookieNameMatches, declarationsOf, DEFAULT_COOKIE_INTEGRATIONS } from './integrations.js'
import { cookieNameMatches, declarationsOf, DEFAULT_COOKIE_INTEGRATIONS, integrationLabel, PROJECT_SOURCE } from './integrations.js'
import { mergeCookieReview, suggestionFor } from './merge.js'
/** Most names one scan looks up — the panel field is for a handful, not a dump. */
@@ -102,14 +102,18 @@ export async function collectCookieFindings({
if (!found.has(key)) {found.set(key, f)}
return key
}
for (const d of declarations) {add(fromDeclaration(d, 'project', 'Project'))}
// Source names are stored in the admin language of whoever runs the scan.
const project = integrationLabel({ label: PROJECT_SOURCE }, ctx.language)
for (const d of declarations) {add(fromDeclaration(d, 'project', project))}
for (const integration of enabled) {
for (const d of declarationsOf(integration, ctx)) {add(fromDeclaration(d, 'integration', integration.label))}
for (const d of declarationsOf(integration, ctx)) {add(fromDeclaration(d, 'integration', integrationLabel(integration, ctx.language)))}
}
const known = [
...declarations.map((d) => ({ d, detail: 'Project', source: 'project' as const })),
...integrations.flatMap((i) => declarationsOf(i, ctx).map((d) => ({ d, detail: i.label, source: 'integration' as const }))),
...declarations.map((d) => ({ d, detail: project, source: 'project' as const })),
...integrations.flatMap((i) =>
declarationsOf(i, ctx).map((d) => ({ d, detail: integrationLabel(i, ctx.language), source: 'integration' as const })),
),
]
const index = database ? await loadCookieDatabase() : null
for (const raw of names) {
@@ -247,7 +251,7 @@ export async function cookieScanContext(
} catch {
// No such global (project replaced it) — integrations keyed on its IDs count as off.
}
return { integrations, payload, plugin }
return { integrations, language: req?.i18n?.language ?? 'en', payload, plugin }
}
/**
+4 -2
View File
@@ -34,6 +34,8 @@ export type CookieDeclaration = {
export type CookieScanContext = {
/** SiteIntegrations (depth 0); `{}` when it can't be read. */
integrations: Record<string, unknown>
/** Admin language of the request (`req.i18n.language`); names stored by a scan use it. Default `'en'`. */
language?: string
payload: BasePayload
/** Plugin options that switch modules on. */
plugin: { localeCount: number; stats: boolean }
@@ -50,8 +52,8 @@ export type CookieIntegration = {
isEnabled: (ctx: CookieScanContext) => boolean | Promise<boolean>
/** Stable id, e.g. `ga4`. */
key: string
/** Shown in the panel, e.g. `Google Analytics 4`. */
label: string
/** Shown in the panel, e.g. `Google Analytics 4`, or per admin language: `{ en: 'Chat', pl: 'Czat' }`. */
label: LocalizedText
}
/** Where a review entry's suggestion came from. `manual` = added by hand in the panel. */