Files
ipal-kit/src/modules/consent/scanner/crawl/global.ts
T
Radosław SmolińskiandClaude Opus 5.5 6b46bc0c14 Admin panel in English and Polish, reworded per docs/dev/admin-ux.md
- admin-i18n module: AdminText { en, pl }, component texts under the ipal
  namespace (project translations win), en + pl admin languages when the
  project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
  explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
  messages, Privacy group, Search engines, Maintenance, Spam protection,
  E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
  validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
  env var names out of editor messages; stats numbers/dates in the admin
  language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 15:46:25 +01:00

74 lines
3.3 KiB
TypeScript

import type { GlobalConfig } from 'payload'
import type { CookieScanLabels } from '../labels.js'
import { userMeetsRole } from '../../../access/predicates.js'
import { labelFor, labelRecord } from '../labels.js'
import { COOKIE_CRAWL_SLUG } from './config.js'
/**
* The latest crawl only (no history): status, counts, violations, third-party
* hosts, and the e-mail recipients for warnings (the only editable field —
* opt-in per site). Written by the crawl endpoints through the Local API.
*/
export function buildCookieCrawlGlobal(labels: Record<string, CookieScanLabels>): GlobalConfig {
const L = (key: keyof CookieScanLabels) => labelRecord(labels, key)
const ro = { readOnly: true }
return {
slug: COOKIE_CRAWL_SLUG,
access: {
read: ({ req }) => userMeetsRole(req, 'editor'),
update: ({ req }) => userMeetsRole(req, 'admin'),
},
admin: { description: L('crawlGlobalDescription'), group: { en: 'Privacy', pl: 'Prywatność' } },
fields: [
{
name: 'notifyEmails',
type: 'text',
admin: { description: L('notifyEmailsDescription') },
label: L('notifyEmails'),
validate: (value: null | string | undefined, { req }: { req: { i18n?: { language?: string } } }) => {
const list = (value ?? '').split(',').map((v) => v.trim()).filter(Boolean)
return list.every((v) => /^[^\s@]+@[^\s@][^\s.@]*\.[^\s@]+$/.test(v)) || labelFor(labels, req?.i18n?.language, 'notifyEmailsInvalid')
},
},
{
name: 'status',
type: 'select',
admin: { ...ro, position: 'sidebar' },
defaultValue: 'idle',
label: L('crawlStatus'),
options: [
{ label: L('crawlIdle'), value: 'idle' },
{ label: L('crawlStateRunning'), value: 'running' },
{ label: L('crawlStateDone'), value: 'done' },
{ label: L('crawlStateFailed'), value: 'failed' },
],
},
{ name: 'startedAt', type: 'date', admin: { ...ro, date: { pickerAppearance: 'dayAndTime' }, position: 'sidebar' }, label: L('startedAt') },
{ name: 'finishedAt', type: 'date', admin: { ...ro, date: { pickerAppearance: 'dayAndTime' }, position: 'sidebar' }, label: L('finishedAt') },
{ name: 'startedBy', type: 'text', admin: { ...ro, position: 'sidebar' }, label: L('startedBy') },
{ name: 'error', type: 'textarea', admin: ro, label: L('crawlError') },
{
name: 'summary',
type: 'group',
admin: ro,
fields: [
{ name: 'pages', type: 'number', admin: ro, label: L('crawlPages') },
{ name: 'violations', type: 'number', admin: ro, label: L('crawlViolations') },
{ name: 'newUnknown', type: 'number', admin: ro, label: L('crawlNewUnknown') },
{ name: 'created', type: 'number', admin: ro, label: L('crawlCreated') },
{ name: 'updated', type: 'number', admin: ro, label: L('crawlUpdated') },
],
label: false,
},
{ name: 'violations', type: 'json', admin: ro, label: L('crawlViolations') },
{ name: 'requests', type: 'json', admin: ro, label: L('crawlRequests') },
{ name: 'pages', type: 'json', admin: ro, label: L('crawlPages') },
// One-time id of the running crawl; a result with another id is refused.
{ name: 'jobId', type: 'text', admin: { hidden: true } },
],
label: L('crawlGlobal'),
}
}