Files
ipal-kit/src/types.ts
T
Radosław SmolińskiandClaude Opus 5.5 b10c2dc0e3 Cookies: fill empty languages, and one Cookies entry in the admin
Every language filled (fillEmptyLocales, default on): text saved in one
language goes to every language where the same field is still empty, never
over a language's own text. Applies to the cookie list (purpose, duration)
and the cookie review (purpose, duration). Scanner and approval writes give
a language without its own text the default language's text. Building
blocks: buildFillEmptyLocalesGlobalHook / CollectionHook, fillEmptyLocales,
withFillLocales.

One Cookies entry (cookieScanner.adminLayout, default combined): the
Cookie banner global is now labelled Cookies and gets Review and approve
(scan box and approval list inline) and Site check tabs, built from ui
fields. Cookie review and Cookie check leave the navigation
(admin.group false) but keep their pages, data and API. This is
presentation only: no schema change and no migration, only
generate:importmap. adminLayout separate keeps the old layout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 22:55:11 +01:00

263 lines
11 KiB
TypeScript

import type { CollectionSlug, Field, PayloadComponent, Plugin } from 'payload'
/**
* Factory shape of @clocklimited/payload-2fa's `payloadTotp` export — injected
* so the plugin never imports the optional peer itself. `collection` is
* `CollectionSlug` (not `string`): payloadTotp requires it, and in a project
* with generated payload-types it's a narrowed union — `string` would make
* `plugin: payloadTotp` fail to type-check.
*/
export type TotpPluginFactory = (options: {
collection: CollectionSlug
forceSetup: boolean
totp: { issuer: string }
}) => Plugin
import type { GlobalOverrides } from './globals/overrides.js'
import type { AccessOption } from './modules/access/types.js'
import type { ConsentLogOptions } from './modules/consent/consentLog.js'
import type { CookieScannerOptions } from './modules/consent/scanner/types.js'
import type { ContentOption } from './modules/content/types.js'
import type { FormsOption } from './modules/forms/types.js'
import type { RevalidatePathFn } from './modules/hooks/buildRevalidateHook.js'
import type { I18nConfig } from './modules/i18n/types.js'
import type { PagesOption } from './modules/pages/types.js'
import type { SeoOption } from './modules/seo/types.js'
import type { StatsOptions } from './modules/stats/collection.js'
/**
* Configuration options for the IPAL plugin.
* Passed by the client project in payload.config.ts.
*/
export type IpalOptions = {
/**
* Role-based access control. Injects a fixed `roles` field
* (admin > editor > user) into the client's auth collection.
*/
access?: AccessOption
/**
* Custom admin panel route, e.g. '/its' instead of the default '/admin'.
* The plugin sets config.routes.admin. IMPORTANT: this alone isn't enough —
* the project must ALSO move its panel folder to match:
* app/(payload)/its/[[...segments]]/page.tsx (and the not-found). The plugin
* can't create files in the project's app/. See docs/security.md.
*
* This is obscurity, not security: it hides the panel from dumb bots scanning
* /admin, but real protection is strong auth + 2FA + rate limiting.
*/
adminRoute?: string
/** Internationalization — locales, default locale, fallback behavior */
/**
* Consent log (proof of consent, GDPR Art. 7(1)): adds the `consent-records`
* collection and POST /api/ipal/consent. Pass `<ConsentProvider logEndpoint="/api/ipal/consent">`.
* Stores a random id, choices, policy version and time — no personal data.
* `true` or `{ retentionDays, collectionOverrides }` (default 1095 days). Default off.
*/
consentLog?: boolean | ConsentLogOptions
/**
* Collections whose entries live under an archive page — blog posts, case
* studies, anything with a listing. Adds an "archive page" assignment per
* collection in SiteSettings; the assigned page's localized slug becomes the
* URL segment (/pl/artykuly/moj-post, /en/articles/my-post). Requires `pages`.
*/
content?: ContentOption
/**
* Cookie scanner (docs/cookie-scanner.md): the `cookie-review` collection, a
* "Scan cookies" action above its list and GET/POST /api/ipal/cookie-scan. A
* scan lists the cookies of the integrations this project switches on, plus
* names looked up in the bundled Open Cookie Database, as drafts an editor
* accepts (→ Cookie Settings → Cookies), edits or rejects. Never deletes,
* never overwrites edited text, never publishes by itself.
* `true` or CookieScannerOptions. Default off.
*/
cookieScanner?: boolean | CookieScannerOptions
/**
* `false` = plugin off without uninstalling: its collections, globals and
* fields stay (DB schema and migrations unchanged), but it adds no endpoints,
* onInit work or admin components.
*/
enabled?: boolean
/**
* Text written in one language fills the same field in every language that is
* still empty; a language with its own text is never overwritten. Default on
* for the cookie list (`cookie-settings`: `cookies.purpose`, `cookies.duration`)
* and the cookie review (`cookie-review`: `purpose`, `retention`). `false` turns
* it off; an object sets the fields per slug (`[]` = off for that slug).
* Building blocks: buildFillEmptyLocalesGlobalHook / …CollectionHook.
*/
fillEmptyLocales?: { 'cookie-review'?: string[]; 'cookie-settings'?: string[] } | boolean
/**
* Forms — form-builder collections (forms, form-submissions) plus the
* callable submitForm (Turnstile + persistence + SMTP-from-panel email).
*/
forms?: FormsOption
/**
* Change any of the plugin's globals (site-settings, site-integrations,
* cookie-settings, notifications): an object merges over the plugin's
* (`access` / `admin` / `hooks` key by key, your keys win), a function gets
* the global and returns the one to use. E.g. let any logged-in user edit
* Notifications: `{ notifications: { access: { update: authenticated } } }`.
*/
globalOverrides?: GlobalOverrides
i18n: I18nConfig
/**
* IndexNow (seo/indexNow.ts): on publish, submit the page's URLs in every
* language to Bing & co. (feeds ChatGPT Search / Copilot). Adds the hook to the
* pages collection and every `content` collection. Production only. Needs the
* key file route createIndexNowKeyRoute. Default false.
*/
indexNow?: boolean
/** Additional fields injected into SiteIntegrations global */
integrationsFields?: Field[]
/**
* Image lightbox labels in the Notifications global (a "Lightbox" group:
* close, previous, next, counter, dialog name, trigger name), localized per
* language and read with getNotificationTexts(...).lightbox. Off by default —
* the components work without it on English fallbacks and the `texts` prop;
* turn it on so editors translate the labels. Adds columns: run a migration
* on Postgres. See docs/lightbox.md.
*/
lightbox?: boolean
/**
* System-page assignments (homepage, privacy, cookies) in SiteSettings.
* Provide the slug of the client's Pages collection to enable.
*/
pages?: PagesOption
/**
* next/cache `revalidatePath`, INJECTED (the plugin never imports next/cache).
* When given, saving any of the plugin's globals (Site Settings, Site
* Integrations, Cookie Settings, Notifications) revalidates the whole site
* layout, so logo, menu, consent texts and analytics IDs change at once
* instead of after the ISR window. See buildGlobalRevalidateHook.
*/
revalidatePath?: RevalidatePathFn
/**
* Site Settings → "Search & AI" tab (verification codes, AI crawler policy,
* llms.txt intro). On by default; `false` removes it; a function gets the
* plugin's fields and returns the tab's fields. Works without `seo`; wins
* over `seo.searchSettings`.
*/
searchSettings?: ((defaults: Field[]) => Field[]) | false
/**
* SEO — adds meta fields to chosen collections (via @payloadcms/plugin-seo)
* and enables locale-aware metadata helpers.
*/
seo?: SeoOption
/** Additional fields injected into SiteSettings global */
siteSettingsFields?: Field[]
/**
* Built-in statistics (docs/stats.md): the `stats-visits` collection,
* POST /api/ipal/hit, the /admin/stats view and a 30-day chart on the
* dashboard. The site mounts <PageStats> inside <ConsentProvider>.
* Cookieless and IP-free for everyone; visitors who accept analytics cookies
* also get a history across days. `true` or `{ retentionDays, timeZone,
* dashboard }`. Default off.
*/
stats?: boolean | StatsOptions
/**
* Two-factor authentication (TOTP), ENFORCED for every user. Wires
* @clocklimited/payload-2fa with forceSetup — no per-project opt-out. Every
* user must configure an authenticator app after login; TOTP is checked before
* data access (not just the admin UI). Requires the peer dep installed and an
* issuer name (shown in the authenticator app).
*
* Pass `false` ONLY for a project that genuinely can't use 2FA (rare, discouraged)
* — default is enforced. See docs/security.md.
*/
twoFactor?:
| {
/**
* Let `collectionSlug` differ from the panel's login collection
* (admin.user). Off by default: a mismatch means panel users skip 2FA,
* so the plugin refuses to start. Set true only when you protect a
* second auth collection on purpose.
*/
allowCollectionMismatch?: boolean
/**
* Auth collection TOTP wraps. Default: the panel's login collection —
* admin.user, else the first auth collection (with the one the plugin
* injects). Must be an auth collection.
*/
collectionSlug?: CollectionSlug
/** Name shown in the authenticator app (e.g. company/site name). */
issuer: string
/**
* The 2FA plugin factory, INJECTED from the project:
* `import { payloadTotp } from '@clocklimited/payload-2fa'`. Injecting it
* (the same pattern as NextResponse / revalidatePath) means ipal-kit never
* imports the optional peer itself — Next can't bundle such an import
* ("Cannot find module '@clocklimited/payload-2fa'", even on public
* pages), and serverExternalPackages is no fix (the package imports its
* own .css). The payload CLI loads the same config, so it gets the
* injected factory too. See docs/security.md.
*/
plugin: TotpPluginFactory
/**
* Admin provider that sends users to the TOTP setup / verify screens.
* Default: ipal-kit's `@intecion/ipal-kit/admin#TotpRedirectProvider`
* (reads the path in the browser). The package's own provider needs an
* `x-pathname` request header on every /admin request; without it the
* setup screen redirects to itself (`setup-totp?back=null`). Pass your
* own component path (it gets clientProps `forceSetup` and the package's
* serverProps `pluginOptions`), or `false` to keep the package's provider
* (then set `x-pathname` on /admin yourself). Run generate:importmap.
*/
provider?: false | PayloadComponent
}
| false
/**
* White-label the admin panel: show the CLIENT's brand (logo + name) in the
* admin — login screen and nav — pulled from SiteSettings, set by the editor
* in the panel (no brand hardcoded in code). `true` wires it with defaults
* (SiteSettings `logo`/`favicon`/`siteName`); the object form overrides the
* global slug, field names, or the browser-tab title suffix.
*
* Injects admin.components.graphics.Logo/Icon pointing at
* `@intecion/ipal-kit/admin`. After enabling, run `pnpm generate:importmap`
* so Payload can resolve the components. See docs/white-label.md.
*/
whiteLabel?:
| {
/**
* Vendor credit ("Technology by Intecion.com") at the bottom of the
* admin nav. Default on; `false` hides it, or override text/url.
*/
credit?:
| {
text?: string
url?: string
}
| boolean
/** Upload field for the small nav icon. Default 'favicon'. */
iconField?: string
/** Upload field for the login/nav logo. Default 'logo'. */
logoField?: string
/** Field with the site name. Default 'siteName'. */
nameField?: string
/** SiteSettings global slug. Default 'site-settings'. */
settingsSlug?: string
/** Static browser-tab title suffix (e.g. ' · Acme Admin'). */
titleSuffix?: string
}
| boolean
}