1.18.0 performance items: reference 404 placeholder and heading font without preload, lazy form and Turnstile code (eager entry /client/eager), Turnstile space kept, background video paused for reduced motion, card hover on opacity, metadata stripped on upload, MongoDB TTL indexes for the consent log and statistics, unused-media notice, version limit for the plugin's entities

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 15:38:38 +01:00
co-authored by Claude Opus 5.5
parent 076b3ef707
commit d628839235
47 changed files with 2546 additions and 78 deletions
+51 -3
View File
@@ -26,7 +26,7 @@ import { SIGN_IN_LOOK } from './modules/branding/signIn/brand.js'
import { lockBrandFields } from './modules/branding/signIn/brandAccess.js'
import { buildAdminLanguageEndpoint } from './modules/branding/signIn/languageEndpoint.js'
import { resolveSignInLook } from './modules/branding/signIn/options.js'
import { buildConsentLogCollection, buildConsentLogEndpoint } from './modules/consent/consentLog.js'
import { buildConsentLogCollection, buildConsentLogEndpoint, CONSENT_LOG_SLUG } from './modules/consent/consentLog.js'
import { addCookieScannerTabs } from './modules/consent/scanner/adminTabs.js'
import { buildCookieApprovalEndpoints, COOKIE_APPROVAL_VIEW_PATH } from './modules/consent/scanner/approval.js'
import { buildCookieReviewCollection } from './modules/consent/scanner/collection.js'
@@ -77,6 +77,8 @@ import { migrateTitleSeparator } from './modules/seo/titleSeparator.js'
import { applyCollectionOverride } from './modules/shared/collectionOverride.js'
import { assertDevelopmentHosts } from './modules/shared/developmentHosts.js'
import { withRetention } from './modules/shared/retention.js'
import { isMongo, syncTtlIndex, ttlField } from './modules/shared/ttl.js'
import { withVersionLimit } from './modules/shared/versionLimit.js'
import { assertPluginSwitches } from './modules/shared/switches.js'
import { buildStatsCollection, buildStatsEndpoint } from './modules/stats/index.js'
import { visitorCookieFor } from './modules/stats/visitorCookie.js'
@@ -133,6 +135,10 @@ export const iapl = (options: IaplOptions): Plugin => {
}
async function transform(incomingConfig: Config): Promise<Config> {
/** MongoDB TTL indexes to set at start (consent log, statistics): shared/ttl.ts. */
const ttlSyncs: Array<{ days: number; enabled: boolean; from: string; slug: string }> = []
/** Slugs of the plugin's own collections and globals (their versions get a limit: shared/versionLimit.ts). */
const pluginEntities = new Set<string>()
let config = { ...incomingConfig }
/** The project's own endpoints: the panel-action origin rule (adminSameOrigin) is for the plugin's only. */
@@ -811,6 +817,7 @@ export const iapl = (options: IaplOptions): Plugin => {
: pluginGlobals
// The project's globalOverrides win (access, admin, hooks merged; a function = full control).
config.globals = [...(config.globals ?? []), ...applyGlobalOverrides(withRevalidate, options.globalOverrides)]
for (const g of pluginGlobals) {pluginEntities.add(g.slug)}
// The brand the sign-in screens show (name, logo, icon) is changed by admins only — with the sign-in look,
// unless the project says `brandAccess: 'editor'`; without the look only when it says `'admin'`.
const brandWl = options.whiteLabel === true ? {} : options.whiteLabel
@@ -873,7 +880,11 @@ export const iapl = (options: IaplOptions): Plugin => {
// --- consent log: proof of consent (on by default since 1.17.0; `consentLog: false` turns it off) ---
if (options.consentLog !== false) {
const logOptions = options.consentLog === true || options.consentLog === undefined ? {} : options.consentLog
config.collections = [...(config.collections ?? []), applyCollectionOverride(buildConsentLogCollection(), logOptions.collectionOverrides)]
const consentCollection = buildConsentLogCollection()
// MongoDB: the hidden date the TTL index counts from (shared/ttl.ts); SQL keeps its schema as it was
if (isMongo(config)) {consentCollection.fields = [...consentCollection.fields, ttlField()]}
config.collections = [...(config.collections ?? []), applyCollectionOverride(consentCollection, logOptions.collectionOverrides)]
ttlSyncs.push({ days: logOptions.retentionDays ?? 1095, enabled: logOptions.ttlIndex !== false, from: 'createdAt', slug: CONSENT_LOG_SLUG })
config.endpoints = [...(config.endpoints ?? []), buildConsentLogEndpoint(logOptions)]
config = withRetention(config, 'consent-records', logOptions.retentionDays ?? 1095)
}
@@ -955,7 +966,10 @@ export const iapl = (options: IaplOptions): Plugin => {
const statsOptions = options.stats === true ? {} : options.stats
const adminRoute = options.adminRoute ?? '/admin'
const viewProps = { adminRoute, ...(statsOptions.timeZone ? { timeZone: statsOptions.timeZone } : {}) }
config.collections = [...(config.collections ?? []), applyCollectionOverride(buildStatsCollection(), statsOptions.collectionOverrides)]
const statsCollection = buildStatsCollection()
if (isMongo(config)) {statsCollection.fields = [...statsCollection.fields, ttlField()]}
config.collections = [...(config.collections ?? []), applyCollectionOverride(statsCollection, statsOptions.collectionOverrides)]
ttlSyncs.push({ days: statsOptions.retentionDays ?? 90, enabled: statsOptions.ttlIndex !== false, from: 'lastAt', slug: 'stats-visits' })
config.endpoints = [...(config.endpoints ?? []), buildStatsEndpoint(statsOptions)]
config = withRetention(config, 'stats-visits', statsOptions.retentionDays ?? 90)
config.admin = {
@@ -1018,6 +1032,26 @@ export const iapl = (options: IaplOptions): Plugin => {
},
}
// --- unused media above the upload lists (opt-in; the notice only links, deleting stays manual) ---
if (options.unusedMedia && options.enabled !== false) {
const only = options.unusedMedia === true ? null : options.unusedMedia.collections
const adminRoute = options.adminRoute ?? '/admin'
config.collections = (config.collections ?? []).map((c) =>
c.upload && (!only || only.includes(c.slug))
? {
...c,
admin: {
...c.admin,
components: {
...c.admin?.components,
beforeListTable: [...(c.admin?.components?.beforeListTable ?? []), { path: '@intecion/ipal-kit/admin#UnusedMediaNotice', serverProps: { adminRoute, collection: c.slug } }],
},
},
}
: c,
)
}
// --- Payload's job queue over HTTP: an admin or the cron secret, unless the project wrote its own rule
config = withJobsRunAccess(config, options.jobsRunAccess ?? {})
@@ -1132,10 +1166,24 @@ export const iapl = (options: IaplOptions): Plugin => {
}
await migrateCookieSettingsSaveButton(payload)
await migrateTitleSeparator(payload, settingsSlug)
// MongoDB TTL indexes of the plugin's logs: created, kept at the current retention, or dropped when turned off
for (const { slug, ...ttl } of ttlSyncs) {
try {
const done = await syncTtlIndex(payload, slug, ttl)
if (done !== 'none') {payload.logger.info(`[iapl] ${slug}: TTL index ${done} (${ttl.enabled ? `${ttl.days} days` : 'off'})`)}
} catch (err) {
payload.logger.error(`[iapl] ${slug}: the TTL index could not be set (${err instanceof Error ? err.message : String(err)}); the purge after a new record still runs`)
}
}
if (adminMeta) {await syncAdminMeta(payload, adminMeta, { nameField: brandFields.nameField, settingsSlug })}
payload.logger.info('[iapl] Plugin initialized.')
}
// The plugin's own entities whose versions a project turned on: at most 20 per document unless it set a limit
for (const slug of ['consent-records', 'cookie-review', 'cookie-crawl', 'stats-visits', 'forms', 'form-submissions']) {pluginEntities.add(slug)}
config.collections = (config.collections ?? []).map((c) => (pluginEntities.has(c.slug) ? withVersionLimit(c, 'collection') : c))
config.globals = (config.globals ?? []).map((g) => (pluginEntities.has(g.slug) ? withVersionLimit(g, 'global') : g))
// readVersions: readPublished() asks for `version._status` on version history (readPublishedVersions).
config.collections = withVersionReadRules(config.collections)
config.globals = withVersionReadRules(config.globals)