Add 'vercel-email' package and update Cloudflare mailer implementation

The 'vercel-email' package was added as a dependency to facilitate sending emails using Cloudflare workers. The CloudflareMailer class has been updated to leverage 'vercel-email' for sending emails. Instructions for setting up the 'vercel-email' package with the Cloudflare provider were added to the README.md file. The
This commit is contained in:
giancarlo
2024-04-09 17:39:54 +08:00
parent a9eaaafd3d
commit d275d993bd
4 changed files with 28 additions and 18 deletions

View File

@@ -40,4 +40,6 @@ async function sendEmail() {
text: 'Hello, World!' text: 'Hello, World!'
}); });
} }
``` ```
If you're using the `cloudflare` provider, please also read the instructions of the package [Vercel Email](https://github.com/Sh4yy/vercel-email) to setup your Workers.

View File

@@ -13,7 +13,8 @@
".": "./src/index.ts" ".": "./src/index.ts"
}, },
"dependencies": { "dependencies": {
"nodemailer": "^6.9.13" "nodemailer": "^6.9.13",
"vercel-email": "0.0.6"
}, },
"devDependencies": { "devDependencies": {
"@kit/eslint-config": "workspace:*", "@kit/eslint-config": "workspace:*",

View File

@@ -1,5 +1,5 @@
import 'server-only'; import 'server-only';
import Email from 'vercel-email';
import { z } from 'zod'; import { z } from 'zod';
import { Mailer } from '../../mailer'; import { Mailer } from '../../mailer';
@@ -8,15 +8,23 @@ import { MailerSchema } from '../../schema/mailer.schema';
type Config = z.infer<typeof MailerSchema>; type Config = z.infer<typeof MailerSchema>;
/** /**
* A class representing a mailer using Cloudflare's Workers. * A class representing a mailer using Cloudflare's Workers thanks to the 'vercel-email' package.
* @implements {Mailer} * @implements {Mailer}
*/ */
export class CloudflareMailer implements Mailer { export class CloudflareMailer implements Mailer {
async sendEmail(config: Config) { async sendEmail(config: Config) {
// make lint happy for now const schema = {
await Promise.resolve(); to: config.to,
from: config.from,
subject: config.subject,
};
console.log('Sending email with Cloudflare Workers', config); const content =
throw new Error('Not implemented'); 'text' in config ? { text: config.text } : { html: config.html };
return Email.send({
...schema,
...content,
});
} }
} }

19
pnpm-lock.yaml generated
View File

@@ -712,6 +712,9 @@ importers:
nodemailer: nodemailer:
specifier: ^6.9.13 specifier: ^6.9.13
version: 6.9.13 version: 6.9.13
vercel-email:
specifier: 0.0.6
version: 0.0.6
devDependencies: devDependencies:
'@kit/eslint-config': '@kit/eslint-config':
specifier: workspace:* specifier: workspace:*
@@ -967,8 +970,8 @@ importers:
specifier: ^8.57.0 specifier: ^8.57.0
version: 8.57.0 version: 8.57.0
lucide-react: lucide-react:
specifier: ^0.366.0 specifier: ^0.363.0
version: 0.366.0(react@18.2.0) version: 0.363.0(react@18.2.0)
prettier: prettier:
specifier: ^3.2.5 specifier: ^3.2.5
version: 3.2.5 version: 3.2.5
@@ -9721,14 +9724,6 @@ packages:
dependencies: dependencies:
react: 18.2.0 react: 18.2.0
/lucide-react@0.366.0(react@18.2.0):
resolution: {integrity: sha512-iUOsp/35wOkrgEzigZlZI/OhVxQZ8CmxjebdIjfSDzNBmrNYjQfKSpeKderaEFfGt3OycF1BE+wLlaqWRuoh4w==}
peerDependencies:
react: ^16.5.1 || ^17.0.0 || ^18.0.0
dependencies:
react: 18.2.0
dev: true
/magic-string@0.27.0: /magic-string@0.27.0:
resolution: {integrity: sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==} resolution: {integrity: sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==}
engines: {node: '>=12'} engines: {node: '>=12'}
@@ -13165,6 +13160,10 @@ packages:
engines: {node: '>= 0.8'} engines: {node: '>= 0.8'}
dev: false dev: false
/vercel-email@0.0.6:
resolution: {integrity: sha512-lpELZ8/B6qyLMUOzmvZiU5evo1Hv5jfSpI/rrzny5UYfOAUKFYycraXNT+fT/cC6ewUKQVJDg8/v3LwyX3cCzA==}
dev: false
/vfile-location@4.1.0: /vfile-location@4.1.0:
resolution: {integrity: sha512-YF23YMyASIIJXpktBa4vIGLJ5Gs88UB/XePgqPmTa7cDA+JeO3yclbpheQYCHjVHBn/yePzrXuygIL+xbvRYHw==} resolution: {integrity: sha512-YF23YMyASIIJXpktBa4vIGLJ5Gs88UB/XePgqPmTa7cDA+JeO3yclbpheQYCHjVHBn/yePzrXuygIL+xbvRYHw==}
dependencies: dependencies: