nuxt-mail 6.0.2 → 7.0.1

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
@@ -3,49 +3,49 @@
3
3
  <!-- /TITLE -->
4
4
 
5
5
  <!-- BADGES/ -->
6
- <p>
7
- <a href="https://npmjs.org/package/nuxt-mail">
8
- <img
9
- src="https://img.shields.io/npm/v/nuxt-mail.svg"
10
- alt="npm version"
11
- >
12
- </a><img src="https://img.shields.io/badge/os-linux%20%7C%C2%A0macos%20%7C%C2%A0windows-blue" alt="Linux macOS Windows compatible"><a href="https://github.com/dword-design/nuxt-mail/actions">
13
- <img
14
- src="https://github.com/dword-design/nuxt-mail/workflows/build/badge.svg"
15
- alt="Build status"
16
- >
17
- </a><a href="https://codecov.io/gh/dword-design/nuxt-mail">
18
- <img
19
- src="https://codecov.io/gh/dword-design/nuxt-mail/branch/master/graph/badge.svg"
20
- alt="Coverage status"
21
- >
22
- </a><a href="https://david-dm.org/dword-design/nuxt-mail">
23
- <img src="https://img.shields.io/david/dword-design/nuxt-mail" alt="Dependency status">
24
- </a><img src="https://img.shields.io/badge/renovate-enabled-brightgreen" alt="Renovate enabled"><br/><a href="https://gitpod.io/#https://github.com/dword-design/nuxt-mail">
25
- <img
26
- src="https://gitpod.io/button/open-in-gitpod.svg"
27
- alt="Open in Gitpod"
28
- width="114"
29
- >
30
- </a><a href="https://www.buymeacoffee.com/dword">
31
- <img
32
- src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg"
33
- alt="Buy Me a Coffee"
34
- width="114"
35
- >
36
- </a><a href="https://paypal.me/SebastianLandwehr">
37
- <img
38
- src="https://sebastianlandwehr.com/images/paypal.svg"
39
- alt="PayPal"
40
- width="163"
41
- >
42
- </a><a href="https://www.patreon.com/dworddesign">
43
- <img
44
- src="https://sebastianlandwehr.com/images/patreon.svg"
45
- alt="Patreon"
46
- width="163"
47
- >
48
- </a>
6
+ <p>
7
+ <a href="https://npmjs.org/package/nuxt-mail">
8
+ <img
9
+ src="https://img.shields.io/npm/v/nuxt-mail.svg"
10
+ alt="npm version"
11
+ >
12
+ </a><img src="https://img.shields.io/badge/os-linux%20%7C%C2%A0macos%20%7C%C2%A0windows-blue" alt="Linux macOS Windows compatible"><a href="https://github.com/dword-design/nuxt-mail/actions">
13
+ <img
14
+ src="https://github.com/dword-design/nuxt-mail/workflows/build/badge.svg"
15
+ alt="Build status"
16
+ >
17
+ </a><a href="https://codecov.io/gh/dword-design/nuxt-mail">
18
+ <img
19
+ src="https://codecov.io/gh/dword-design/nuxt-mail/branch/master/graph/badge.svg"
20
+ alt="Coverage status"
21
+ >
22
+ </a><a href="https://david-dm.org/dword-design/nuxt-mail">
23
+ <img src="https://img.shields.io/david/dword-design/nuxt-mail" alt="Dependency status">
24
+ </a><img src="https://img.shields.io/badge/renovate-enabled-brightgreen" alt="Renovate enabled"><br/><a href="https://gitpod.io/#https://github.com/dword-design/nuxt-mail">
25
+ <img
26
+ src="https://gitpod.io/button/open-in-gitpod.svg"
27
+ alt="Open in Gitpod"
28
+ width="114"
29
+ >
30
+ </a><a href="https://www.buymeacoffee.com/dword">
31
+ <img
32
+ src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg"
33
+ alt="Buy Me a Coffee"
34
+ width="114"
35
+ >
36
+ </a><a href="https://paypal.me/SebastianLandwehr">
37
+ <img
38
+ src="https://sebastianlandwehr.com/images/paypal.svg"
39
+ alt="PayPal"
40
+ width="163"
41
+ >
42
+ </a><a href="https://www.patreon.com/dworddesign">
43
+ <img
44
+ src="https://sebastianlandwehr.com/images/patreon.svg"
45
+ alt="Patreon"
46
+ width="163"
47
+ >
48
+ </a>
49
49
  </p>
50
50
  <!-- /BADGES -->
51
51
 
@@ -164,53 +164,6 @@ export default {
164
164
  </script>
165
165
  ```
166
166
 
167
- ## Nuxt 2
168
-
169
- For Nuxt 2, you need to install [@nuxtjs/axios](https://www.npmjs.com/package/@nuxtjs/axios) and add it to your module list before `nuxt-mail`:
170
-
171
- ```js
172
- // nuxt.config.js
173
- export default {
174
- modules: [
175
- [
176
- '@nuxtjs/axios',
177
- ['nuxt-mail', { /* ... */ }],
178
- }],
179
- ],
180
- }
181
- ```
182
-
183
- Then you can use the injected variable like so:
184
-
185
- ```html
186
- <script>
187
- export default {
188
- methods: {
189
- sendEmail() {
190
- this.$mail.send({
191
- from: 'John Doe',
192
- subject: 'Incredible',
193
- text: 'This is an incredible test message',
194
- })
195
- },
196
- },
197
- }
198
- </script>
199
- ```
200
-
201
- ### Note about production use
202
-
203
- When you use `nuxt-mail` in production and you configured a reverse proxy that hides your localhost behind a domain, you need to tell `@nuxt/axios` which base URL you are using. Otherwise `nuxt-mail` won't find the send route. Refer to [@nuxt/axios options](https://axios.nuxtjs.org/options) on how to do that. The easiest option is to set the `API_URL` environment variable, or set something else in your `nuxt.config.js`:
204
-
205
- ```js
206
- // nuxt.config.js
207
- export default {
208
- axios: {
209
- baseURL: process.env.BASE_URL,
210
- },
211
- }
212
- ```
213
-
214
167
  ## Multiple message configs
215
168
 
216
169
  It is also possible to provide multiple message configurations by changing the `message` config into an array.
@@ -0,0 +1 @@
1
+ export declare const useMail: () => any;
@@ -1,2 +1,2 @@
1
- import { useNuxtApp } from '#imports';
1
+ import { useNuxtApp } from "#imports";
2
2
  export const useMail = () => useNuxtApp().$mail;
@@ -0,0 +1,21 @@
1
+ import type { SendMailOptions, TransportOptions } from 'nodemailer';
2
+ type Message = SendMailOptions & {
3
+ name?: string;
4
+ };
5
+ type MailOptions = {
6
+ message?: Message | Message[];
7
+ smtp: TransportOptions;
8
+ };
9
+ declare const _default: import("@nuxt/schema").NuxtModule<import("@nuxt/schema").ModuleOptions, import("@nuxt/schema").ModuleOptions, false>;
10
+ export default _default;
11
+ declare module '@nuxt/schema' {
12
+ interface NuxtConfig {
13
+ ['mail']?: MailOptions;
14
+ }
15
+ interface NuxtOptions {
16
+ ['mail']?: MailOptions;
17
+ }
18
+ interface RuntimeConfig {
19
+ mail?: MailOptions;
20
+ }
21
+ }
package/dist/module.js ADDED
@@ -0,0 +1,53 @@
1
+ import P from "node:path";
2
+ import { addImports, addPlugin, addServerHandler, addTemplate, createResolver, defineNuxtModule } from "@nuxt/kit";
3
+ import fs from "fs-extra";
4
+ import nuxtAliasPath from "nuxt-alias-path";
5
+ import parsePackagejsonName from "parse-packagejson-name";
6
+ const resolver = createResolver(import.meta.url);
7
+ const packageConfig = fs.readJsonSync(resolver.resolve("../package.json"));
8
+ const moduleName = parsePackagejsonName(packageConfig.name).fullName;
9
+ export default defineNuxtModule({
10
+ setup: async (options, nuxt) => {
11
+ options = {
12
+ ...nuxt.options.runtimeConfig.mail,
13
+ ...nuxt.options.mail,
14
+ ...options
15
+ };
16
+ if (!nuxt.options._prepare) {
17
+ if (!options.smtp) {
18
+ throw new Error("SMTP config is missing.");
19
+ }
20
+ if (Array.isArray(options.message) && options.message.length === 0 || !options.message) {
21
+ throw new Error("You have to provide at least one config.");
22
+ }
23
+ }
24
+ if (!Array.isArray(options.message)) {
25
+ options.message = [options.message];
26
+ }
27
+ if (!nuxt.options._prepare && options.message.some(c => !c.to && !c.cc && !c.bcc)) {
28
+ throw new Error("You have to provide to/cc/bcc in all configs.");
29
+ }
30
+ addTemplate({
31
+ filename: P.join(moduleName, "options.mjs"),
32
+ getContents: () => `export default ${JSON.stringify(options, void 0, 2)}`,
33
+ write: true
34
+ });
35
+ const sendTemplatePathWithoutExt = resolver.resolve("./send");
36
+ const sendTemplatePath = (await fs.exists(`${sendTemplatePathWithoutExt}.ts`)) ? `${sendTemplatePathWithoutExt}.ts` : `${sendTemplatePathWithoutExt}.js`;
37
+ addTemplate({
38
+ filename: P.join(moduleName, "send.mjs"),
39
+ getContents: () => fs.readFile(sendTemplatePath, "utf8"),
40
+ write: true
41
+ });
42
+ nuxt.options.alias["#mail"] = nuxtAliasPath(moduleName, nuxt);
43
+ addServerHandler({
44
+ handler: resolver.resolve("./server-handler.post"),
45
+ route: "/mail/send"
46
+ });
47
+ addImports([{
48
+ from: resolver.resolve("./composable"),
49
+ name: "useMail"
50
+ }]);
51
+ addPlugin(resolver.resolve(`./plugin`));
52
+ }
53
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
package/dist/plugin.js CHANGED
@@ -1,12 +1,12 @@
1
- import { defineNuxtPlugin } from '#imports';
1
+ import { defineNuxtPlugin } from "#imports";
2
2
  export default defineNuxtPlugin(() => ({
3
3
  provide: {
4
4
  mail: {
5
5
  send: async config => {
6
6
  try {
7
- await $fetch('/mail/send', {
7
+ await $fetch("/mail/send", {
8
8
  body: config,
9
- method: 'POST'
9
+ method: "POST"
10
10
  });
11
11
  } catch (error) {
12
12
  throw new Error(error.response._data.statusMessage);
package/dist/send.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ declare const _default: (body: any, options: any, transport: any) => Promise<void>;
2
+ export default _default;
package/dist/send.js CHANGED
@@ -1,11 +1,11 @@
1
- import { findIndex, omit } from '@dword-design/functions';
1
+ import { omit } from "lodash-es";
2
2
  export default async (body, options, transport) => {
3
3
  body = {
4
4
  config: 0,
5
5
  ...body
6
6
  };
7
- if (typeof body.config === 'string') {
8
- const configIndex = findIndex(_ => _.name === body.config)(options.message);
7
+ if (typeof body.config === "string") {
8
+ const configIndex = options.message.findIndex(_ => _.name === body.config);
9
9
  if (configIndex === -1) {
10
10
  throw new Error(`Message config with name '${body.config}' not found.`);
11
11
  }
@@ -14,7 +14,7 @@ export default async (body, options, transport) => {
14
14
  throw new Error(`Message config not found at index ${body.config}.`);
15
15
  }
16
16
  await transport.sendMail({
17
- ...omit(['config', 'to', 'cc', 'bcc'])(body),
18
- ...omit(['name'])(options.message[body.config])
17
+ ...omit(body, ["config", "to", "cc", "bcc"]),
18
+ ...omit(options.message[body.config], ["name"])
19
19
  });
20
20
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string>>;
2
+ export default _default;
@@ -1,7 +1,7 @@
1
- import { createError, defineEventHandler, readBody } from 'h3';
2
- import nodemailer from 'nodemailer';
3
- import options from '#mail/options.mjs';
4
- import send from '#mail/send.mjs';
1
+ import { createError, defineEventHandler, readBody } from "h3";
2
+ import nodemailer from "nodemailer";
3
+ import options from "#mail/options.mjs";
4
+ import send from "#mail/send.mjs";
5
5
  const transport = nodemailer.createTransport(options.smtp);
6
6
  export default defineEventHandler(async event => {
7
7
  try {
@@ -12,5 +12,5 @@ export default defineEventHandler(async event => {
12
12
  statusMessage: error.message
13
13
  });
14
14
  }
15
- return '';
15
+ return "";
16
16
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-mail",
3
- "version": "6.0.2",
3
+ "version": "7.0.1",
4
4
  "description": "Adds email sending capability to a Nuxt.js app. Adds a server route, an injected variable, and uses nodemailer to send emails.",
5
5
  "keywords": [
6
6
  "email",
@@ -24,8 +24,15 @@
24
24
  "license": "MIT",
25
25
  "author": "Sebastian Landwehr <info@sebastianlandwehr.com>",
26
26
  "type": "module",
27
- "exports": "./dist/index.js",
28
- "main": "dist/index.js",
27
+ "exports": {
28
+ ".": {
29
+ "import": {
30
+ "default": "./dist/module.js",
31
+ "types": "./dist/module.d.ts"
32
+ }
33
+ }
34
+ },
35
+ "main": "dist/module.js",
29
36
  "files": [
30
37
  "dist"
31
38
  ],
@@ -37,37 +44,39 @@
37
44
  "lint": "base lint",
38
45
  "prepare": "base prepare",
39
46
  "prepublishOnly": "base prepublishOnly",
40
- "test": "base test"
47
+ "test": "base test",
48
+ "typecheck": "base typecheck",
49
+ "verify": "base verify"
41
50
  },
42
51
  "dependencies": {
43
- "@dword-design/functions": "^6.0.2",
44
52
  "@nuxt/kit": "^3.17.4",
45
53
  "fs-extra": "^11.3.0",
46
54
  "h3": "^1.15.3",
55
+ "lodash-es": "^4.17.21",
47
56
  "nodemailer": "^7.0.3",
48
57
  "nuxt-alias-path": "^2.0.0",
49
- "nuxt-push-plugins": "^2.1.34",
50
58
  "parse-packagejson-name": "^1.0.1"
51
59
  },
52
60
  "devDependencies": {
53
- "@dword-design/base": "^12.0.5",
54
- "@dword-design/base-config-nuxt-module": "^1.0.3",
61
+ "@dword-design/base": "^15.1.2",
62
+ "@dword-design/base-config-nuxt-module": "^3.0.0",
63
+ "@playwright/browser-chromium": "^1.54.1",
64
+ "@playwright/test": "^1.54.1",
65
+ "@types/nodemailer": "^6.4.17",
55
66
  "axios": "^1.9.0",
67
+ "endent": "npm:@dword-design/endent@^1.4.7",
56
68
  "execa": "^9.6.0",
57
69
  "get-port": "^7.1.0",
58
70
  "nuxt": "^3.17.4",
59
- "nuxt-dev-ready": "^3.0.0",
60
- "output-files": "^2.0.32",
61
- "playwright": "^1.52.0",
62
- "playwright-chromium": "^1.52.0",
71
+ "nuxt-dev-ready": "^5.0.1",
72
+ "output-files": "^3.0.0",
63
73
  "port-ready": "^0.1.0",
64
- "smtp-tester": "^2.1.0",
65
- "tree-kill-promise": "^3.0.14",
66
- "with-local-tmp-dir": "^5.1.1"
74
+ "smtp-tester": "npm:@dword-design/smtp-tester-fork@^0.0.1",
75
+ "tree-kill-promise": "^4.0.0"
67
76
  },
68
- "packageManager": "pnpm@10.8.1+sha512.c50088ba998c67b8ca8c99df8a5e02fd2ae2e2b29aaf238feaa9e124248d3f48f9fb6db2424949ff901cffbb5e0f0cc1ad6aedb602cd29450751d11c35023677",
77
+ "packageManager": "pnpm@10.13.1+sha512.37ebf1a5c7a30d5fabe0c5df44ee8da4c965ca0c5af3dbab28c3a1681b70a256218d05c81c9c0dcf767ef6b8551eb5b960042b9ed4300c59242336377e01cfad",
69
78
  "engines": {
70
- "node": ">=18"
79
+ "node": ">=20"
71
80
  },
72
81
  "publishConfig": {
73
82
  "access": "public"
package/dist/index.js DELETED
@@ -1,49 +0,0 @@
1
- import P from 'node:path';
2
- import { some } from '@dword-design/functions';
3
- import { addImports, addServerHandler, addTemplate, createResolver } from '@nuxt/kit';
4
- import fs from 'fs-extra';
5
- import nuxtAliasPath from 'nuxt-alias-path';
6
- import nuxtPushPlugins from 'nuxt-push-plugins';
7
- import parsePackagejsonName from 'parse-packagejson-name';
8
- const resolver = createResolver(import.meta.url);
9
- const packageConfig = fs.readJsonSync(resolver.resolve('../package.json'));
10
- const moduleName = parsePackagejsonName(packageConfig.name).fullName;
11
- export default (options, nuxt) => {
12
- options = {
13
- ...nuxt.options.runtimeConfig.mail,
14
- ...nuxt.options.mail,
15
- ...options
16
- };
17
- if (!options.smtp) {
18
- throw new Error('SMTP config is missing.');
19
- }
20
- if (Array.isArray(options.message) && options.message.length === 0 || !options.message) {
21
- throw new Error('You have to provide at least one config.');
22
- }
23
- if (!Array.isArray(options.message)) {
24
- options.message = [options.message];
25
- }
26
- if (some(c => !c.to && !c.cc && !c.bcc)(options.message)) {
27
- throw new Error('You have to provide to/cc/bcc in all configs.');
28
- }
29
- addTemplate({
30
- filename: P.join(moduleName, 'options.mjs'),
31
- getContents: () => `export default ${JSON.stringify(options, undefined, 2)}`,
32
- write: true
33
- });
34
- addTemplate({
35
- filename: P.join(moduleName, 'send.mjs'),
36
- getContents: () => fs.readFile(resolver.resolve('./send.js'), 'utf8'),
37
- write: true
38
- });
39
- nuxt.options.alias['#mail'] = nuxtAliasPath(moduleName, nuxt);
40
- addServerHandler({
41
- handler: resolver.resolve('./server-handler.post.js'),
42
- route: '/mail/send'
43
- });
44
- addImports([{
45
- from: resolver.resolve('./composable.js'),
46
- name: 'useMail'
47
- }]);
48
- nuxtPushPlugins(nuxt, resolver.resolve(`./plugin.js`));
49
- };