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/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,11 @@ export async function getMailer() {
|
||||
case 'nodemailer':
|
||||
return getNodemailer();
|
||||
|
||||
case 'resend':
|
||||
return getResendMailer();
|
||||
case 'resend': {
|
||||
const { createResendMailer } = await import('@kit/resend');
|
||||
|
||||
return createResendMailer();
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error(`Invalid mailer: ${MAILER_PROVIDER as string}`);
|
||||
@@ -23,18 +26,12 @@ export async function getMailer() {
|
||||
|
||||
async function getNodemailer() {
|
||||
if (process.env.NEXT_RUNTIME === 'nodejs') {
|
||||
const { Nodemailer } = await import('./impl/nodemailer');
|
||||
const { createNodemailerService } = await import('@kit/nodemailer');
|
||||
|
||||
return new Nodemailer();
|
||||
return createNodemailerService();
|
||||
} else {
|
||||
throw new Error(
|
||||
'Nodemailer is not available on the edge runtime. Please use another mailer.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function getResendMailer() {
|
||||
const { ResendMailer } = await import('./impl/resend');
|
||||
|
||||
return new ResendMailer();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@kit/mailers",
|
||||
"name": "@kit/nodemailer",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
@@ -13,11 +13,11 @@
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"nodemailer": "^6.9.15",
|
||||
"vercel-email": "0.0.6"
|
||||
"nodemailer": "^6.9.15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@kit/eslint-config": "workspace:*",
|
||||
"@kit/mailers-shared": "workspace:^",
|
||||
"@kit/prettier-config": "workspace:*",
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
@@ -2,17 +2,21 @@ import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Mailer } from '../../mailer';
|
||||
import type { MailerSchema } from '../../schema/mailer.schema';
|
||||
import { getSMTPConfiguration } from '../../smtp-configuration';
|
||||
import { Mailer, MailerSchema } from '@kit/mailers-shared';
|
||||
|
||||
import { getSMTPConfiguration } from './smtp-configuration';
|
||||
|
||||
type Config = z.infer<typeof MailerSchema>;
|
||||
|
||||
export function createNodemailerService() {
|
||||
return new Nodemailer();
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representing a mailer using Nodemailer library.
|
||||
* @implements {Mailer}
|
||||
*/
|
||||
export class Nodemailer implements Mailer {
|
||||
class Nodemailer implements Mailer {
|
||||
async sendEmail(config: Config) {
|
||||
const { createTransport } = await import('nodemailer');
|
||||
const transporter = createTransport(getSMTPConfiguration());
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SmtpConfigSchema } from './schema/smtp-config.schema';
|
||||
import { SmtpConfigSchema } from '@kit/mailers-shared';
|
||||
|
||||
export function getSMTPConfiguration() {
|
||||
const data = SmtpConfigSchema.parse({
|
||||
8
packages/mailers/nodemailer/tsconfig.json
Normal file
8
packages/mailers/nodemailer/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"]
|
||||
}
|
||||
3
packages/mailers/resend/README.md
Normal file
3
packages/mailers/resend/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.
|
||||
38
packages/mailers/resend/package.json
Normal file
38
packages/mailers/resend/package.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@kit/resend",
|
||||
"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/mailers-shared": "workspace:^",
|
||||
"@kit/prettier-config": "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/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,7 @@ import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Mailer } from '../../mailer';
|
||||
import type { MailerSchema } from '../../schema/mailer.schema';
|
||||
import { Mailer, MailerSchema } from '@kit/mailers-shared';
|
||||
|
||||
type Config = z.infer<typeof MailerSchema>;
|
||||
|
||||
@@ -14,11 +13,15 @@ const RESEND_API_KEY = z
|
||||
})
|
||||
.parse(process.env.RESEND_API_KEY);
|
||||
|
||||
export function createResendMailer() {
|
||||
return new ResendMailer();
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representing a mailer using the Resend HTTP API.
|
||||
* @implements {Mailer}
|
||||
*/
|
||||
export class ResendMailer implements Mailer {
|
||||
class ResendMailer implements Mailer {
|
||||
async sendEmail(config: Config) {
|
||||
const contentObject =
|
||||
'text' in config
|
||||
8
packages/mailers/resend/tsconfig.json
Normal file
8
packages/mailers/resend/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"]
|
||||
}
|
||||
3
packages/mailers/shared/README.md
Normal file
3
packages/mailers/shared/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# Mailers Shared - @kit/mailers-shared
|
||||
|
||||
This package provides shared utilities for mailers.
|
||||
37
packages/mailers/shared/package.json
Normal file
37
packages/mailers/shared/package.json
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@kit/mailers-shared",
|
||||
"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"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@kit/eslint-config": "workspace:*",
|
||||
"@kit/prettier-config": "workspace:*",
|
||||
"@kit/tailwind-config": "workspace:*",
|
||||
"@kit/tsconfig": "workspace:*",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"root": true,
|
||||
"extends": [
|
||||
"@kit/eslint-config/base",
|
||||
"@kit/eslint-config/react"
|
||||
]
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
3
packages/mailers/shared/src/index.ts
Normal file
3
packages/mailers/shared/src/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './schema/mailer.schema';
|
||||
export * from './schema/smtp-config.schema';
|
||||
export * from './mailer';
|
||||
8
packages/mailers/shared/tsconfig.json
Normal file
8
packages/mailers/shared/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