B2B-88: add starter kit structure and elements
This commit is contained in:
3
packages/mailers/resend/eslint.config.mjs
Normal file
3
packages/mailers/resend/eslint.config.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
import eslintConfigBase from '@kit/eslint-config/base.js';
|
||||
|
||||
export default eslintConfigBase;
|
||||
1
packages/mailers/resend/node_modules/@kit/eslint-config
generated
vendored
Symbolic link
1
packages/mailers/resend/node_modules/@kit/eslint-config
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../../tooling/eslint
|
||||
1
packages/mailers/resend/node_modules/@kit/mailers-shared
generated
vendored
Symbolic link
1
packages/mailers/resend/node_modules/@kit/mailers-shared
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../shared
|
||||
1
packages/mailers/resend/node_modules/@kit/prettier-config
generated
vendored
Symbolic link
1
packages/mailers/resend/node_modules/@kit/prettier-config
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../../tooling/prettier
|
||||
1
packages/mailers/resend/node_modules/@kit/tsconfig
generated
vendored
Symbolic link
1
packages/mailers/resend/node_modules/@kit/tsconfig
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../../tooling/typescript
|
||||
1
packages/mailers/resend/node_modules/@types/node
generated
vendored
Symbolic link
1
packages/mailers/resend/node_modules/@types/node
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../../node_modules/.pnpm/@types+node@22.15.30/node_modules/@types/node
|
||||
1
packages/mailers/resend/node_modules/zod
generated
vendored
Symbolic link
1
packages/mailers/resend/node_modules/zod
generated
vendored
Symbolic link
@@ -0,0 +1 @@
|
||||
../../../../node_modules/.pnpm/zod@3.25.56/node_modules/zod
|
||||
30
packages/mailers/resend/package.json
Normal file
30
packages/mailers/resend/package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"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/tsconfig": "workspace:*",
|
||||
"@types/node": "^22.15.18",
|
||||
"zod": "^3.24.4"
|
||||
},
|
||||
"typesVersions": {
|
||||
"*": {
|
||||
"*": [
|
||||
"src/*"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
53
packages/mailers/resend/src/index.ts
Normal file
53
packages/mailers/resend/src/index.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'server-only';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { Mailer, MailerSchema } from '@kit/mailers-shared';
|
||||
|
||||
type Config = z.infer<typeof MailerSchema>;
|
||||
|
||||
const RESEND_API_KEY = z
|
||||
.string({
|
||||
description: 'The API key for the Resend API',
|
||||
required_error: 'Please provide the API key for the Resend API',
|
||||
})
|
||||
.parse(process.env.RESEND_API_KEY);
|
||||
|
||||
export function createResendMailer() {
|
||||
return new ResendMailer();
|
||||
}
|
||||
|
||||
/**
|
||||
* A class representing a mailer using the Resend HTTP API.
|
||||
* @implements {Mailer}
|
||||
*/
|
||||
class ResendMailer implements Mailer {
|
||||
async sendEmail(config: Config) {
|
||||
const contentObject =
|
||||
'text' in config
|
||||
? {
|
||||
text: config.text,
|
||||
}
|
||||
: {
|
||||
html: config.html,
|
||||
};
|
||||
|
||||
const res = await fetch('https://api.resend.com/emails', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${RESEND_API_KEY}`,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
from: config.from,
|
||||
to: [config.to],
|
||||
subject: config.subject,
|
||||
...contentObject,
|
||||
}),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(`Failed to send email: ${res.statusText}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
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"]
|
||||
}
|
||||
Reference in New Issue
Block a user