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:
@@ -1,13 +1,14 @@
|
||||
import type { PayloadEmailAdapter, SendEmailOptions } from 'payload'
|
||||
|
||||
import { type IntegrationStatus, recordIntegrationStatus } from '../integrations/status.js'
|
||||
import { getSiteIntegrations } from '../payload/index.js'
|
||||
import { recordIntegrationStatus, type IntegrationStatus } from '../integrations/status.js'
|
||||
import { panelSmtpAdapter, type PanelSmtpAdapterArgs } from './panelSmtpAdapter.js'
|
||||
import { graphAdapter, type GraphAdapterArgs } from './graphAdapter.js'
|
||||
import { panelSmtpAdapter, type PanelSmtpAdapterArgs } from './panelSmtpAdapter.js'
|
||||
|
||||
type TransportIntegrations = {
|
||||
/** 'smtp' | 'graph' — chosen by the editor in SiteIntegrations. */
|
||||
emailTransport?: 'smtp' | 'graph' | null
|
||||
emailStatus?: IntegrationStatus | null
|
||||
/** 'smtp' | 'graph' — chosen by the editor in SiteIntegrations. */
|
||||
emailTransport?: 'graph' | 'smtp' | null
|
||||
}
|
||||
|
||||
const STATUS_FIELD = 'emailStatus'
|
||||
@@ -16,10 +17,10 @@ const describe = (err: unknown) =>
|
||||
(err instanceof Error ? err.message : String(err)).split('\n')[0].slice(0, 200)
|
||||
|
||||
export type MailAdapterArgs = {
|
||||
smtp?: PanelSmtpAdapterArgs
|
||||
graph?: GraphAdapterArgs
|
||||
fallbackFromAddress?: string
|
||||
fallbackFromName?: string
|
||||
graph?: GraphAdapterArgs
|
||||
smtp?: PanelSmtpAdapterArgs
|
||||
}
|
||||
|
||||
/** True when the agency Graph credentials are present in the environment. */
|
||||
@@ -94,21 +95,21 @@ export const mailAdapter =
|
||||
result = await (useGraph ? graph : smtp).sendEmail(message)
|
||||
} catch (err) {
|
||||
await recordIntegrationStatus(payload, STATUS_FIELD, previous, {
|
||||
state: 'degraded',
|
||||
code,
|
||||
message: `${transport}: ${describe(err)}`,
|
||||
state: 'degraded',
|
||||
})
|
||||
throw err // callers (form-builder, Send test) still see the failure
|
||||
}
|
||||
|
||||
// The delegates report failure as { sent: false, error, detail? } instead
|
||||
// of throwing (a broken mailbox must not crash a form submission).
|
||||
const failed = result as { sent?: boolean; error?: string; detail?: string } | null
|
||||
const failed = result as { detail?: string; error?: string; sent?: boolean } | null
|
||||
if (failed && typeof failed === 'object' && failed.sent === false) {
|
||||
await recordIntegrationStatus(payload, STATUS_FIELD, previous, {
|
||||
state: 'degraded',
|
||||
code,
|
||||
message: `${transport}: ${describe(failed.detail ?? failed.error ?? 'not sent')}`,
|
||||
state: 'degraded',
|
||||
})
|
||||
return result
|
||||
}
|
||||
@@ -120,9 +121,9 @@ export const mailAdapter =
|
||||
previous,
|
||||
graphFallback
|
||||
? {
|
||||
state: 'degraded',
|
||||
code: 'graph-unavailable',
|
||||
message: 'Microsoft Graph is selected but not configured on the server — e-mails are sent over SMTP.',
|
||||
state: 'degraded',
|
||||
}
|
||||
: { state: 'ok' },
|
||||
)
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
import type { PayloadEmailAdapter, SendEmailOptions } from 'payload'
|
||||
|
||||
import { getSiteIntegrations } from '../payload/index.js'
|
||||
|
||||
/** SMTP fields the adapter reads from SiteIntegrations. */
|
||||
type SmtpIntegrations = {
|
||||
smtpHost?: string | null
|
||||
smtpPort?: number | null
|
||||
smtpUser?: string | null
|
||||
smtpPassword?: string | null
|
||||
smtpFromAddress?: string | null
|
||||
smtpFromName?: string | null
|
||||
smtpFromAddress?: null | string
|
||||
smtpFromName?: null | string
|
||||
smtpHost?: null | string
|
||||
smtpPassword?: null | string
|
||||
smtpPort?: null | number
|
||||
smtpUser?: null | string
|
||||
}
|
||||
|
||||
export type PanelSmtpAdapterArgs = {
|
||||
@@ -61,7 +62,7 @@ export const panelSmtpAdapter =
|
||||
payload.logger.error(
|
||||
'[ipal] Email not sent: SMTP is not configured in Site Integrations.',
|
||||
)
|
||||
return { sent: false, error: 'SMTP is not configured in Site Integrations.' }
|
||||
return { error: 'SMTP is not configured in Site Integrations.', sent: false }
|
||||
}
|
||||
|
||||
// The panel is the source of truth for the sender; fall back to whatever
|
||||
@@ -83,10 +84,10 @@ export const panelSmtpAdapter =
|
||||
const { default: nodemailer } = await import('nodemailer')
|
||||
|
||||
const transporter = nodemailer.createTransport({
|
||||
auth: { pass, user },
|
||||
host,
|
||||
port,
|
||||
secure: port === 465, // implicit TLS on 465, STARTTLS otherwise
|
||||
auth: { user, pass },
|
||||
})
|
||||
|
||||
try {
|
||||
@@ -95,13 +96,13 @@ export const panelSmtpAdapter =
|
||||
from,
|
||||
...(message.subject ? { subject: stripCRLF(message.subject) } : {}),
|
||||
})
|
||||
return { sent: true, messageId: info.messageId }
|
||||
return { messageId: info.messageId, sent: true }
|
||||
} catch (err) {
|
||||
// Never surface SMTP internals to the caller — a form submission
|
||||
// shouldn't fail loudly because the mailbox is misconfigured.
|
||||
payload.logger.error(`[ipal] Email send failed: ${(err as Error).message}`)
|
||||
// `detail` is for the panel status (mailAdapter), not for end users.
|
||||
return { sent: false, error: 'Failed to send email.', detail: (err as Error).message }
|
||||
return { detail: (err as Error).message, error: 'Failed to send email.', sent: false }
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user