nuxt-workmailer 1.1.4 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,6 +10,8 @@
10
10
  > Adds nodemailer to the Nuxt 3 and 4
11
11
  >
12
12
  > This module can be used to send emails only from the server-side in Nuxt 3 and 4.
13
+ >
14
+ > This fork of `nuxt-nodemailer` adds support for Cloudflare workers
13
15
 
14
16
  ## Features
15
17
  - Auto import server composable `useNodeMailer()`
@@ -100,14 +102,14 @@ export default defineEventHandler(() => {
100
102
  })
101
103
  ```
102
104
 
103
- [npm-version-src]: https://img.shields.io/npm/v/nuxt-nodemailer/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
104
- [npm-version-href]: https://npmjs.com/package/nuxt-nodemailer
105
+ [npm-version-src]: https://img.shields.io/npm/v/nuxt-workmailer/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
106
+ [npm-version-href]: https://npmjs.com/package/nuxt-workmailer
105
107
 
106
- [npm-downloads-src]: https://img.shields.io/npm/dt/nuxt-nodemailer.svg?style=flat&colorA=18181B&colorB=28CF8D
107
- [npm-downloads-href]: https://npmjs.com/package/nuxt-nodemailer
108
+ [npm-downloads-src]: https://img.shields.io/npm/dt/nuxt-workmailer.svg?style=flat&colorA=18181B&colorB=28CF8D
109
+ [npm-downloads-href]: https://npmjs.com/package/nuxt-workmailer
108
110
 
109
- [license-src]: https://img.shields.io/npm/l/nuxt-nodemailer.svg?style=flat&colorA=18181B&colorB=28CF8D
110
- [license-href]: https://npmjs.com/package/nuxt-nodemailer
111
+ [license-src]: https://img.shields.io/npm/l/nuxt-workmailer.svg?style=flat&colorA=18181B&colorB=28CF8D
112
+ [license-href]: https://npmjs.com/package/nuxt-workmailer
111
113
 
112
114
  [nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
113
115
  [nuxt-href]: https://nuxt.com
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-workmailer",
3
3
  "configKey": "nodemailer",
4
- "version": "1.1.4",
4
+ "version": "1.3.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -1,4 +1,18 @@
1
1
  import { useRuntimeConfig } from "#imports";
2
+ function toUser(address) {
3
+ if (typeof address !== "string") {
4
+ return { name: address.name, email: address.address };
5
+ }
6
+ const open = address.lastIndexOf("<");
7
+ const close = address.lastIndexOf(">");
8
+ if (open === -1 || close < open) return { email: address.trim() };
9
+ const name = address.slice(0, open).trim().replace(/^"|"$/g, "");
10
+ return { name: name || void 0, email: address.slice(open + 1, close).trim() };
11
+ }
12
+ function toUsers(addresses) {
13
+ if (!addresses) return void 0;
14
+ return (Array.isArray(addresses) ? addresses : [addresses]).map(toUser);
15
+ }
2
16
  export const useNodeMailer = () => {
3
17
  const { nodemailer } = useRuntimeConfig();
4
18
  const sendMail = async (options) => {
@@ -13,6 +27,11 @@ export const useNodeMailer = () => {
13
27
  return res;
14
28
  } else {
15
29
  const { WorkerMailer } = await import("worker-mailer");
30
+ const { from = nodemailer.from, to, cc, bcc, replyTo, ...rest } = options;
31
+ const [reply, ...extraReplies] = toUsers(replyTo) ?? [];
32
+ if (extraReplies.length) {
33
+ throw new Error("worker-mailer accepts a single replyTo address");
34
+ }
16
35
  await WorkerMailer.send(
17
36
  {
18
37
  credentials: {
@@ -25,8 +44,12 @@ export const useNodeMailer = () => {
25
44
  secure: nodemailer.secure
26
45
  },
27
46
  {
28
- from: nodemailer.from,
29
- ...options
47
+ ...rest,
48
+ from: toUser(from),
49
+ to: toUsers(to) ?? [],
50
+ reply,
51
+ cc: toUsers(cc),
52
+ bcc: toUsers(bcc)
30
53
  }
31
54
  );
32
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-workmailer",
3
- "version": "1.1.4",
3
+ "version": "1.3.0",
4
4
  "description": "nodemailer Nuxt Module with Worker support",
5
5
  "repository": "twinkelmann/nuxt-workmailer",
6
6
  "license": "MIT",