- 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]>
57 lines
2.6 KiB
TypeScript
57 lines
2.6 KiB
TypeScript
import type { Endpoint, PayloadRequest } from 'payload'
|
|
|
|
import type { CookieIntegration, CookieScanContext, CookieScannerOptions } from './types.js'
|
|
|
|
import { userMeetsRole } from '../../access/predicates.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'
|
|
|
|
/**
|
|
* GET /api/ipal/cookie-scan → `{ integrations: [{ key, label }] }` — what a scan would cover.
|
|
* POST /api/ipal/cookie-scan, body `{ names?: string[] | string }` → runs a scan,
|
|
* `{ ok, summary: { created, updated, unchanged, unknown }, integrations }`.
|
|
* Editors and up by default (`cookieScanner.access`).
|
|
*/
|
|
export function buildCookieScanEndpoints(options: CookieScannerOptions, plugin: CookieScanContext['plugin']): Endpoint[] {
|
|
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
|
|
// 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, req), ok: true })
|
|
},
|
|
method: 'get',
|
|
path: COOKIE_SCAN_PATH,
|
|
},
|
|
{
|
|
handler: async (req) => {
|
|
if (!(await allowed(req))) {return Response.json({ ok: false }, { status: 403 })}
|
|
let body: { names?: unknown } = {}
|
|
try {
|
|
body = ((await (req as unknown as Request).json()) ?? {}) as { names?: unknown }
|
|
} catch {
|
|
// empty body = scan without extra names
|
|
}
|
|
try {
|
|
const { enabled, summary } = await runCookieScan({ names: parseCookieNames(body.names), options, payload: req.payload, plugin, req })
|
|
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 })
|
|
}
|
|
},
|
|
method: 'post',
|
|
path: COOKIE_SCAN_PATH,
|
|
},
|
|
]
|
|
}
|