- Q3: the integration status (emailStatus, turnstileStatus) is written alone through the database adapter (writeGlobalFields, exported): a visitor's form submit no longer puts back an admin's SMTP or Turnstile change saved at the same moment. addToCookieList reads the list again right before writing and works the change out again when an editor's save changed it (up to 5 times). Both races reproduced exactly in test/statusWrites.test.ts, on the three adapters. - Q4: cookieScanner.access and the doctor's access go through accessAllowed: any truthy answer still allows, an answer that is not a boolean is reported once per option; strict (only true) is announced for 1.19.0. - Q5: related documents that are drafts are left out of what the public helpers answer (resolveRoute, getSettings, getArchiveEntries, the 404 page, llms-full; Markdown and MCP through resolveRoute): null alone, removed from a list, value null in a polymorphic one. A preview keeps them; draftRelations: 'keep' keeps the old behaviour. withoutDraftRelations, applyDraftRelations exported. - Docs: content.md, frontend.md, integrations.md, cookie-scanner.md, security.md, AGENT.md; iapl-nav and iapl-doctor skills. Co-Authored-By: Claude Opus 5.5 <[email protected]>
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import type { BasePayload } from 'payload'
|
|
|
|
import { applyDraftRelations, type DraftRelations } from './draftRelations.js'
|
|
import { isPublishedDoc } from './resolveRoute.js'
|
|
|
|
type ResolveNotFoundPageArgs = {
|
|
/** Related documents that are drafts: `'hide'` (default since 1.18.0) leaves them out, `'keep'` as before. */
|
|
draftRelations?: DraftRelations
|
|
locale: string
|
|
/** Client's Pages collection slug. Defaults to 'pages'. */
|
|
pagesSlug?: string
|
|
payload: BasePayload
|
|
/** SiteSettings global slug. Defaults to 'site-settings'. */
|
|
settingsSlug?: string
|
|
}
|
|
|
|
/**
|
|
* Returns the page the editor assigned as **404 (Not Found)** in System Pages,
|
|
* fully populated (depth 2, same shape as resolveRoute's pages), or null when
|
|
* the role is unassigned.
|
|
*
|
|
* Used by the project's `not-found.tsx`. The editor decides what a 404 looks
|
|
* like: a dedicated "Not found" page, or simply the homepage. Null means
|
|
* "render the project's built-in fallback view".
|
|
*
|
|
* Never throws — a missing DB (container build prerendering not-found) or a
|
|
* deleted page just yields null, so the 404 view can't crash the build.
|
|
*/
|
|
export async function resolveNotFoundPage({
|
|
draftRelations,
|
|
locale,
|
|
pagesSlug = 'pages',
|
|
payload,
|
|
settingsSlug = 'site-settings',
|
|
}: ResolveNotFoundPageArgs): Promise<null | Record<string, unknown>> {
|
|
try {
|
|
const settings = (await payload.findGlobal({
|
|
slug: settingsSlug as never,
|
|
depth: 0,
|
|
locale: locale as never,
|
|
})) as Record<string, unknown>
|
|
|
|
const rel = settings.notFound
|
|
const id =
|
|
typeof rel === 'string' || typeof rel === 'number'
|
|
? rel
|
|
: rel && typeof rel === 'object'
|
|
? (rel as { id?: number | string }).id
|
|
: undefined
|
|
if (id === undefined) {return null}
|
|
|
|
const doc = await payload.findByID({
|
|
id,
|
|
collection: pagesSlug as never,
|
|
depth: 2,
|
|
locale: locale as never,
|
|
})
|
|
// a page never published (or unpublished) is a draft: the built-in view, not its text (IAWL idea 23)
|
|
return isPublishedDoc(doc) ? applyDraftRelations(doc as Record<string, unknown>, { draftRelations }) : null
|
|
} catch (error) {
|
|
console.warn('[iapl] resolveNotFoundPage: falling back to built-in 404 view:', error)
|
|
return null
|
|
}
|
|
}
|