Lint: fix all ESLint errors (391 -> 0), lint and typecheck tests

Mostly perfectionist import/key sorting and curly braces from --fix, plus:
- spread instead of .apply() in the Meta Pixel stub
- non-capturing group in the locale-code pattern
- React 19 use(Context) / <Context value> in TurnstileProvider
- email regex rewritten without super-linear backtracking (covered by a test)
- console.warn/error allowed (deliberate server diagnostics)
- test/tsconfig.json so the project service and tsc see test files

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-15 23:56:18 +02:00
co-authored by Claude Opus 5.5
parent ce0a390351
commit 4544cac69c
48 changed files with 642 additions and 589 deletions
+11 -10
View File
@@ -1,13 +1,14 @@
import type { Payload } from 'payload'
import type { IntegrationStatus } from './status.js'
type Props = {
/** Injected by Payload into admin server components. */
payload?: Payload
/** Status groups to check: field name → label. */
checks?: Record<string, string>
/** Admin route, for the link. Default '/admin'. */
adminRoute?: string
/** Status groups to check: field name → label. */
checks?: Record<string, string>
/** Injected by Payload into admin server components. */
payload?: Payload
}
/**
@@ -15,8 +16,8 @@ type Props = {
* are currently failing, with a link to Site Integrations. Renders nothing when
* everything is fine — and never throws (DB not ready → nothing).
*/
export async function IntegrationAlerts({ payload, checks = { turnstileStatus: 'Turnstile', emailStatus: 'Email' }, adminRoute = '/admin' }: Props) {
if (!payload) return null
export async function IntegrationAlerts({ adminRoute = '/admin', checks = { emailStatus: 'Email', turnstileStatus: 'Turnstile' }, payload }: Props) {
if (!payload) {return null}
let doc: Record<string, unknown>
try {
doc = (await payload.findGlobal({ slug: 'site-integrations' as never, depth: 0 })) as Record<string, unknown>
@@ -26,17 +27,17 @@ export async function IntegrationAlerts({ payload, checks = { turnstileStatus: '
const failing = Object.entries(checks)
.map(([field, label]) => ({ label, status: doc?.[field] as IntegrationStatus | undefined }))
.filter((x) => x.status?.state === 'degraded')
if (!failing.length) return null
if (!failing.length) {return null}
return (
<div
role="alert"
style={{
background: 'var(--theme-error-50, rgba(229, 72, 77, 0.08))',
border: '1px solid var(--theme-error-400, #e5484d)',
borderRadius: 4,
marginBottom: '1.5rem',
padding: '1rem 1.25rem',
borderRadius: 4,
border: '1px solid var(--theme-error-400, #e5484d)',
background: 'var(--theme-error-50, rgba(229, 72, 77, 0.08))',
}}
>
<strong>Integration problem — the site still works, but something needs attention.</strong>
@@ -2,14 +2,14 @@
import { useFormFields } from '@payloadcms/ui'
type Props = {
/** Name of the hidden status group (buildIntegrationStatusField). */
statusField: string
/** Integration name shown in the banner, e.g. 'Turnstile'. */
label: string
/** Name of the hidden status group (buildIntegrationStatusField). */
statusField: string
}
const fmt = (iso: unknown) => {
if (typeof iso !== 'string' || !iso) return ''
if (typeof iso !== 'string' || !iso) {return ''}
const d = new Date(iso)
return Number.isNaN(d.getTime()) ? '' : d.toLocaleString()
}
@@ -19,18 +19,18 @@ const fmt = (iso: unknown) => {
* the integration has been used once; a red box while it's failing; a short
* green line once it works again.
*/
export function IntegrationStatusBanner({ statusField, label }: Props) {
export function IntegrationStatusBanner({ label, statusField }: Props) {
const state = useFormFields(([f]) => f[`${statusField}.state`]?.value) as string | undefined
const message = useFormFields(([f]) => f[`${statusField}.message`]?.value) as string | undefined
const code = useFormFields(([f]) => f[`${statusField}.code`]?.value) as string | undefined
const since = useFormFields(([f]) => f[`${statusField}.since`]?.value)
const checkedAt = useFormFields(([f]) => f[`${statusField}.checkedAt`]?.value)
if (!state) return null
if (!state) {return null}
if (state === 'ok') {
return (
<div style={{ marginBottom: '1.5rem', fontSize: '0.85rem', opacity: 0.75 }}>
<div style={{ fontSize: '0.85rem', marginBottom: '1.5rem', opacity: 0.75 }}>
✓ {label} working{since ? ` since ${fmt(since)}` : ''}.
</div>
)
@@ -40,21 +40,21 @@ export function IntegrationStatusBanner({ statusField, label }: Props) {
<div
role="alert"
style={{
background: 'var(--theme-error-50, rgba(229, 72, 77, 0.08))',
border: '1px solid var(--theme-error-400, #e5484d)',
borderRadius: 4,
marginBottom: '1.5rem',
padding: '0.9rem 1rem',
borderRadius: 4,
border: '1px solid var(--theme-error-400, #e5484d)',
background: 'var(--theme-error-50, rgba(229, 72, 77, 0.08))',
}}
>
<strong>{label} is not working — forms are accepted without this check.</strong>
{message ? <div style={{ marginTop: '0.35rem' }}>{message}</div> : null}
<div style={{ marginTop: '0.35rem', fontSize: '0.8rem', opacity: 0.75 }}>
<div style={{ fontSize: '0.8rem', marginTop: '0.35rem', opacity: 0.75 }}>
{code ? `Code: ${code}. ` : ''}
{since ? `Since ${fmt(since)}. ` : ''}
{checkedAt ? `Last seen ${fmt(checkedAt)}.` : ''}
</div>
<div style={{ marginTop: '0.35rem', fontSize: '0.8rem', opacity: 0.75 }}>
<div style={{ fontSize: '0.8rem', marginTop: '0.35rem', opacity: 0.75 }}>
Fix the keys below and save — the status is checked again on the next form submission.
</div>
</div>
+3 -3
View File
@@ -1,6 +1,6 @@
export {
recordIntegrationStatus,
buildIntegrationStatusField,
buildIntegrationStatusBanner,
buildIntegrationStatusField,
recordIntegrationStatus,
} from './status.js'
export type { IntegrationStatus, IntegrationState } from './status.js'
export type { IntegrationState, IntegrationStatus } from './status.js'
+16 -16
View File
@@ -12,18 +12,18 @@ import type { BasePayload, Field } from 'payload'
* busy form doesn't turn every submission into a DB write.
*/
export type IntegrationState = 'ok' | 'degraded'
export type IntegrationState = 'degraded' | 'ok'
export type IntegrationStatus = {
state?: IntegrationState | null
/** Machine code from the provider or the plugin, e.g. 'invalid-input-secret', 'missing-secret'. */
code?: string | null
/** Human explanation shown in the panel (English — panel language). */
message?: string | null
/** When the current state started. */
since?: string | null
/** Last time the integration was used (refreshed at most every REFRESH_MS). */
checkedAt?: string | null
checkedAt?: null | string
/** Machine code from the provider or the plugin, e.g. 'invalid-input-secret', 'missing-secret'. */
code?: null | string
/** Human explanation shown in the panel (English — panel language). */
message?: null | string
/** When the current state started. */
since?: null | string
state?: IntegrationState | null
}
const REFRESH_MS = 10 * 60_000
@@ -53,8 +53,8 @@ export function buildIntegrationStatusBanner(statusField: string, label: string)
admin: {
components: {
Field: {
clientProps: { label, statusField },
path: '@intecion/ipal-kit/client#IntegrationStatusBanner',
clientProps: { statusField, label },
},
},
},
@@ -69,7 +69,7 @@ export async function recordIntegrationStatus(
payload: BasePayload,
field: string,
previous: IntegrationStatus | null | undefined,
next: { state: IntegrationState; code?: string; message?: string },
next: { code?: string; message?: string; state: IntegrationState },
): Promise<void> {
const now = new Date()
const changed = previous?.state !== next.state || (next.state === 'degraded' && previous?.code !== next.code)
@@ -78,22 +78,22 @@ export async function recordIntegrationStatus(
(!previous?.checkedAt || now.getTime() - new Date(previous.checkedAt).getTime() > REFRESH_MS)
// Healthy and already recorded as healthy (or never recorded) → nothing to do.
if (!changed && !stale) return
if (next.state === 'ok' && !previous?.state) return
if (!changed && !stale) {return}
if (next.state === 'ok' && !previous?.state) {return}
const status: IntegrationStatus = {
state: next.state,
checkedAt: now.toISOString(),
code: next.code ?? null,
message: next.message ?? null,
since: changed ? now.toISOString() : (previous?.since ?? now.toISOString()),
checkedAt: now.toISOString(),
state: next.state,
}
try {
await payload.updateGlobal({
slug: SITE_INTEGRATIONS as never,
context: { ipalIntegrationStatus: true },
data: { [field]: status } as never,
depth: 0,
context: { ipalIntegrationStatus: true },
})
} catch (err) {
console.warn(`[ipal] could not record ${field}:`, err instanceof Error ? err.message : err)