chore: clean up types, remove logMockEmailCredentials
This commit is contained in:
@@ -6,18 +6,14 @@ import type { EmailAdapter } from 'payload/types'
|
|||||||
import nodemailer from 'nodemailer'
|
import nodemailer from 'nodemailer'
|
||||||
import { InvalidConfiguration } from 'payload/errors'
|
import { InvalidConfiguration } from 'payload/errors'
|
||||||
|
|
||||||
type Email = {
|
export type NodemailerAdapterArgs = {
|
||||||
defaultFromAddress: string
|
defaultFromAddress: string
|
||||||
defaultFromName: string
|
defaultFromName: string
|
||||||
logMockCredentials?: boolean
|
skipVerify?: boolean
|
||||||
}
|
|
||||||
|
|
||||||
type EmailTransportOptions = Email & {
|
|
||||||
transport?: Transporter
|
transport?: Transporter
|
||||||
transportOptions: SMTPConnection.Options
|
transportOptions?: SMTPConnection.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NodemailerAdapterArgs = Email | EmailTransportOptions
|
|
||||||
export type NodemailerAdapter = EmailAdapter<SendMailOptions, unknown>
|
export type NodemailerAdapter = EmailAdapter<SendMailOptions, unknown>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,8 +54,6 @@ async function buildEmail(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureConfigHasFrom(emailConfig)
|
|
||||||
|
|
||||||
// Create or extract transport
|
// Create or extract transport
|
||||||
let transport: Transporter
|
let transport: Transporter
|
||||||
if ('transport' in emailConfig && emailConfig.transport) {
|
if ('transport' in emailConfig && emailConfig.transport) {
|
||||||
@@ -70,7 +64,10 @@ async function buildEmail(
|
|||||||
transport = await createMockAccount(emailConfig)
|
transport = await createMockAccount(emailConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
await verifyTransport(transport)
|
if (emailConfig.skipVerify !== false) {
|
||||||
|
await verifyTransport(transport)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaultFromAddress: emailConfig.defaultFromAddress,
|
defaultFromAddress: emailConfig.defaultFromAddress,
|
||||||
defaultFromName: emailConfig.defaultFromName,
|
defaultFromName: emailConfig.defaultFromName,
|
||||||
@@ -86,14 +83,6 @@ async function verifyTransport(transport: Transporter) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const ensureConfigHasFrom = (emailConfig: NodemailerAdapterArgs) => {
|
|
||||||
if (!emailConfig?.defaultFromName || !emailConfig?.defaultFromAddress) {
|
|
||||||
throw new InvalidConfiguration(
|
|
||||||
'Email fromName and fromAddress must be configured when transport is configured',
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use ethereal.email to create a mock email account
|
* Use ethereal.email to create a mock email account
|
||||||
*/
|
*/
|
||||||
@@ -116,12 +105,10 @@ async function createMockAccount(emailConfig?: NodemailerAdapterArgs) {
|
|||||||
const transport = nodemailer.createTransport(smtpOptions)
|
const transport = nodemailer.createTransport(smtpOptions)
|
||||||
const { pass, user, web } = etherealAccount
|
const { pass, user, web } = etherealAccount
|
||||||
|
|
||||||
if (emailConfig?.logMockCredentials) {
|
console.info('E-mail configured with ethereal.email test account. ')
|
||||||
console.info('E-mail configured with mock configuration')
|
console.info(`Log into mock email provider at ${web}`)
|
||||||
console.info(`Log into mock email provider at ${web}`)
|
console.info(`Mock email account username: ${user}`)
|
||||||
console.info(`Mock email account username: ${user}`)
|
console.info(`Mock email account password: ${pass}`)
|
||||||
console.info(`Mock email account password: ${pass}`)
|
|
||||||
}
|
|
||||||
return transport
|
return transport
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user