- ipalKit({ searchSettings }): switches off / reshapes Site Settings → Search & AI
without `seo`; read as options.searchSettings ?? options.seo?.searchSettings.
- shouldLoadGoogle moved to a pure module (analytics/shouldLoadGoogle.ts) and
exported from @intecion/ipal-kit and /client.
- consentLog.collectionOverrides and stats.collectionOverrides (object merges
access/admin/hooks key by key, function takes over), via the new exported
applyCollectionOverride / CollectionOverride. The stats view and dashboard
chart now follow the stats-visits read access, so overrides narrow them too.
All additive; defaults unchanged. Docs: AGENT.md, ipal-reference, consent,
stats, seo, analytics, ipal-setup.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import type { CollectionConfig } from 'payload'
|
|
|
|
/**
|
|
* A project's change to a collection the plugin adds (consent records, stats):
|
|
* - an object is merged over the plugin's: `access`, `admin` and `hooks` key by
|
|
* key (your access rules win, your hooks run after the plugin's), anything
|
|
* else (labels, fields, …) replaces the plugin's value;
|
|
* - a function gets the plugin's collection and returns the one to use — full
|
|
* control. Keep the slug: the plugin's endpoints and views write and read it.
|
|
*
|
|
* Same rules as `globalOverrides`.
|
|
*/
|
|
export type CollectionOverride = ((collection: CollectionConfig) => CollectionConfig) | Partial<CollectionConfig>
|
|
|
|
type Hooks = NonNullable<CollectionConfig['hooks']>
|
|
|
|
/** Applies one CollectionOverride to a plugin collection. */
|
|
export function applyCollectionOverride(collection: CollectionConfig, override: CollectionOverride | undefined): CollectionConfig {
|
|
if (!override) {return collection}
|
|
if (typeof override === 'function') {return override(collection)}
|
|
const hooks: Record<string, unknown[]> = { ...(collection.hooks as Record<string, unknown[]>) }
|
|
for (const [key, list] of Object.entries(override.hooks ?? {})) {
|
|
hooks[key] = [...(hooks[key] ?? []), ...((list as unknown[]) ?? [])]
|
|
}
|
|
return {
|
|
...collection,
|
|
...override,
|
|
access: { ...collection.access, ...override.access },
|
|
admin: { ...collection.admin, ...override.admin },
|
|
hooks: hooks as Hooks,
|
|
}
|
|
}
|