Files
myeasycms-v2/packages/mailers/src/index.ts
giancarlo 9fca45c2de Replace Logger with getLogger and update next version
This commit replaces the use of Logger with getLogger in various parts of the code to handle logging. The Logger has been replaced with getLogger, which assists in getting logs in an asynchronous manner. In addition to this, it updates the next version in pnpm-lock.yaml from next@14.2.0-canary.61 to next@14.2.0-canary.62 and various other dependencies. Also made minor annotations and comments to the function 'isBrowser' and 'formatCurrency' in the 'utils.ts' file.
2024-04-08 12:23:15 +08:00

29 lines
652 B
TypeScript

import { z } from 'zod';
const MAILER_PROVIDER = z
.enum(['nodemailer', 'cloudflare'])
.default('nodemailer')
.parse(process.env.MAILER_PROVIDER);
/**
* @description Get the mailer based on the environment variable.
*/
export async function getMailer() {
switch (MAILER_PROVIDER) {
case 'nodemailer': {
const { Nodemailer } = await import('./impl/nodemailer');
return new Nodemailer();
}
case 'cloudflare': {
const { CloudflareMailer } = await import('./impl/cloudflare');
return new CloudflareMailer();
}
default:
throw new Error(`Invalid mailer: ${MAILER_PROVIDER as string}`);
}
}