Added shared mailer package to remove circular dependencies between packages. (#63)
This commit is contained in:
committed by
GitHub
parent
d18f810c6e
commit
4c7a3354b9
3
packages/mailers/core/README.md
Normal file
3
packages/mailers/core/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Nodemailer - @kit/nodemailer
|
||||
|
||||
This package provides a simple and easy to use mailer for sending emails using nodemailer.
|
||||
39
packages/mailers/core/package.json
Normal file
39
packages/mailers/core/package.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "@kit/mailers",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"clean": "git clean -xdf .turbo node_modules",
|
||||
"format": "prettier --check \"**/*.{ts,tsx}\"",
|
||||
"lint": "eslint .",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
"prettier": "@kit/prettier-config",
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kit/eslint-config": "workspace:*",
|
||||
"@kit/nodemailer": "workspace:^",
|
||||
"@kit/prettier-config": "workspace:*",
|
||||
"@kit/resend": "workspace:^",
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"@types/node": "^22.5.2",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"extends": [
|
||||
"@kit/eslint-config/base",
|
||||
"@kit/eslint-config/react"
|
||||
]
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
37
packages/mailers/core/src/index.ts
Normal file
37
packages/mailers/core/src/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const MAILER_PROVIDER = z
|
||||
.enum(['nodemailer', 'resend'])
|
||||
.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':
|
||||
return getNodemailer();
|
||||
|
||||
case 'resend': {
|
||||
const { createResendMailer } = await import('@kit/resend');
|
||||
|
||||
return createResendMailer();
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`Invalid mailer: ${MAILER_PROVIDER as string}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function getNodemailer() {
|
||||
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
||||
const { createNodemailerService } = await import('@kit/nodemailer');
|
||||
|
||||
return createNodemailerService();
|
||||
} else {
|
||||
throw new Error(
|
||||
'Nodemailer is not available on the edge runtime. Please use another mailer.',
|
||||
);
|
||||
}
|
||||
}
|
||||
8
packages/mailers/core/tsconfig.json
Normal file
8
packages/mailers/core/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@kit/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
|
||||
},
|
||||
"include": ["*.ts", "src"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user