nuxt-mail 6.0.0 → 6.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/dist/index.js CHANGED
@@ -1,29 +1,18 @@
1
1
  import { some } from '@dword-design/functions';
2
- import { addImports, addServerHandler, addTemplate, createResolver, isNuxt3 as isNuxt3Try } from '@nuxt/kit';
3
- import express from 'express';
2
+ import { addImports, addServerHandler, addTemplate, createResolver } from '@nuxt/kit';
4
3
  import fs from 'fs-extra';
5
- import nodemailer from 'nodemailer';
6
4
  import nuxtAliasPath from 'nuxt-alias-path';
7
5
  import nuxtPushPlugins from 'nuxt-push-plugins';
8
6
  import parsePackagejsonName from 'parse-packagejson-name';
9
7
  import P from 'path';
10
- import send from "./send.js";
11
8
  const resolver = createResolver(import.meta.url);
12
9
  const packageConfig = fs.readJsonSync(resolver.resolve('../package.json'));
13
10
  const moduleName = parsePackagejsonName(packageConfig.name).fullName;
14
- export default function (moduleOptions, nuxt) {
15
- nuxt = nuxt || this;
16
- let isNuxt3 = true;
17
- try {
18
- isNuxt3 = isNuxt3Try();
19
- } catch {
20
- isNuxt3 = false;
21
- }
22
- const runtimeConfig = nuxt.options[isNuxt3 ? 'runtimeConfig' : 'privateRuntimeConfig'];
23
- const options = {
24
- ...runtimeConfig.mail,
11
+ export default (options, nuxt) => {
12
+ options = {
13
+ ...nuxt.options.runtimeConfig.mail,
25
14
  ...nuxt.options.mail,
26
- ...moduleOptions
15
+ ...options
27
16
  };
28
17
  if (!options.smtp) {
29
18
  throw new Error('SMTP config is missing.');
@@ -37,42 +26,24 @@ export default function (moduleOptions, nuxt) {
37
26
  if (some(c => !c.to && !c.cc && !c.bcc)(options.message)) {
38
27
  throw new Error('You have to provide to/cc/bcc in all configs.');
39
28
  }
40
- if (isNuxt3) {
41
- addTemplate({
42
- filename: P.join(moduleName, 'options.mjs'),
43
- getContents: () => `export default ${JSON.stringify(options, undefined, 2)}`,
44
- write: true
45
- });
46
- addTemplate({
47
- filename: P.join(moduleName, 'send.mjs'),
48
- getContents: () => fs.readFile(resolver.resolve('./send.js'), 'utf8'),
49
- write: true
50
- });
51
- nuxt.options.alias['#mail'] = nuxtAliasPath(moduleName, nuxt);
52
- addServerHandler({
53
- handler: resolver.resolve('./server-handler.post.js'),
54
- route: '/mail/send'
55
- });
56
- addImports([{
57
- from: resolver.resolve('./composable.js'),
58
- name: 'useMail'
59
- }]);
60
- } else {
61
- const app = express();
62
- const transport = nodemailer.createTransport(options.smtp);
63
- app.use(express.json());
64
- app.post('/send', async (req, res) => {
65
- try {
66
- await send(req.body, options, transport);
67
- } catch (error) {
68
- return res.status(500).send(error.message);
69
- }
70
- return res.sendStatus(200);
71
- });
72
- nuxt.addServerMiddleware({
73
- handler: app,
74
- path: '/mail'
75
- });
76
- }
77
- nuxtPushPlugins(nuxt, resolver.resolve(`./plugin-nuxt${isNuxt3 ? 3 : 2}.js`));
78
- }
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-mail",
3
- "version": "6.0.0",
3
+ "version": "6.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",
@@ -42,7 +42,6 @@
42
42
  "dependencies": {
43
43
  "@dword-design/functions": "^6.0.2",
44
44
  "@nuxt/kit": "^3.16.2",
45
- "express": "^4.21.2",
46
45
  "fs-extra": "^11.3.0",
47
46
  "h3": "^1.15.1",
48
47
  "nodemailer": "^6.10.1",
@@ -1,9 +0,0 @@
1
- export default (context, inject) => inject('mail', {
2
- send: async config => {
3
- try {
4
- await context.app.$axios.$post('/mail/send', config);
5
- } catch (error) {
6
- throw new Error(error.response.data);
7
- }
8
- }
9
- });
File without changes