chore(email): strict true

This commit is contained in:
Elliot DeNolf
2024-04-18 00:01:57 -04:00
parent fb7925f272
commit b297c5499d
2 changed files with 19 additions and 5 deletions

View File

@@ -48,10 +48,13 @@ async function buildEmail(
emailConfig?: NodemailerAdapterArgs, emailConfig?: NodemailerAdapterArgs,
): Promise<{ defaultFromAddress: string; defaultFromName: string; transport: Transporter }> { ): Promise<{ defaultFromAddress: string; defaultFromName: string; transport: Transporter }> {
if (!emailConfig) { if (!emailConfig) {
const transport = await createMockAccount(emailConfig)
if (!transport) throw new InvalidConfiguration('Unable to create Nodemailer test account.')
return { return {
defaultFromAddress: 'info@payloadcms.com', defaultFromAddress: 'info@payloadcms.com',
defaultFromName: 'Payload', defaultFromName: 'Payload',
transport: await createMockAccount(emailConfig), transport,
} }
} }
@@ -94,12 +97,12 @@ const ensureConfigHasFrom = (emailConfig: NodemailerAdapterArgs) => {
/** /**
* Use ethereal.email to create a mock email account * Use ethereal.email to create a mock email account
*/ */
async function createMockAccount(emailConfig: NodemailerAdapterArgs) { async function createMockAccount(emailConfig?: NodemailerAdapterArgs) {
try { try {
const etherealAccount = await nodemailer.createTestAccount() const etherealAccount = await nodemailer.createTestAccount()
const smtpOptions = { const smtpOptions = {
...emailConfig, ...(emailConfig || {}),
auth: { auth: {
pass: etherealAccount.pass, pass: etherealAccount.pass,
user: etherealAccount.user, user: etherealAccount.user,
@@ -120,7 +123,13 @@ async function createMockAccount(emailConfig: NodemailerAdapterArgs) {
console.info(`Mock email account password: ${pass}`) console.info(`Mock email account password: ${pass}`)
} }
return transport return transport
} catch (err) { } catch (err: unknown) {
console.error({ err, msg: 'There was a problem setting up the mock email handler' }) if (err instanceof Error) {
console.error({ err, msg: 'There was a problem setting up the mock email handler' })
throw new InvalidConfiguration(
`Unable to create Nodemailer test account. Error: ${err.message}`,
)
}
throw new InvalidConfiguration('Unable to create Nodemailer test account.')
} }
} }

View File

@@ -6,13 +6,18 @@
"emitDeclarationOnly": true, "emitDeclarationOnly": true,
"outDir": "./dist" /* Specify an output folder for all emitted files. */, "outDir": "./dist" /* Specify an output folder for all emitted files. */,
"rootDir": "./src" /* Specify the root folder within your source files. */, "rootDir": "./src" /* Specify the root folder within your source files. */,
"strict": true,
}, },
"exclude": [ "exclude": [
"dist", "dist",
"node_modules",
"src/**/*.spec.js", "src/**/*.spec.js",
"src/**/*.spec.jsx", "src/**/*.spec.jsx",
"src/**/*.spec.ts", "src/**/*.spec.ts",
"src/**/*.spec.tsx" "src/**/*.spec.tsx"
], ],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"], "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.d.ts", "src/**/*.json"],
"references": [
{ "path": "../payload" },
]
} }