@vroskus/library-email 1.0.1 → 1.0.3

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.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Transporter } from 'nodemailer';
1
2
  import type { $Config as Config } from './types';
2
3
  type $SendMailParams = {
3
4
  bcc?: string | Array<string>;
@@ -15,7 +16,7 @@ type $SendEmailResponse = {
15
16
  rejected: Array<string>;
16
17
  response: string;
17
18
  };
18
- type $Transporter = {
19
+ type $Transporter = Transporter | {
19
20
  sendMail: (arg0: $SendMailParams) => Promise<$SendEmailResponse>;
20
21
  };
21
22
  export type $Config = Config;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AACA,4DAAoC;AACpC,+CAEsB;AA+BtB,MAAM,YAAY;IAKhB,YAAY,EACV,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,QAAQ,GACN;;QACF,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,MAAM,KAAK,GAAG,CAAC;QAEnC,uBAAA,IAAI,+DAAkB,MAAtB,IAAI,EAAmB;YACrB,IAAI;YACJ,QAAQ;YACR,IAAI,EAAE,IAAI,IAAI,IAAI;YAClB,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAgEK,QAAQ,CAAC,EACb,GAAG,EACH,OAAO,EACP,OAAO,EACP,OAAO,EACP,EAAE,GAOH;;YACC,MAAM,MAAM,GAAG;gBACb,GAAG;gBACH,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,IAAI,EAAE,OAAO;gBACb,OAAO;gBACP,OAAO;gBACP,IAAI,EAAE,IAAA,yBAAU,EAAC,OAAO,CAAC;gBACzB,EAAE;aACH,CAAC;YAEF,MAAM,IAAI,GAAuB,MAAM,IAAI,CAAC,WAAW,CAAC,QA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CAAC,IAAI,CAAC,CACrB,CAAC;YAEF,OAAO;gBACL,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvC,SAAS,EAAE,GAAG;gBACd,OAAO,EAAE,EAAE;gBACX,QAAQ,EAAE,EAAE;gBACZ,QAAQ,EAAE,6BAA6B;aACxC,CAAC;QACJ,CAAC,CAAA;KACF,CAAC;IAEF,IAAI,IAAI,KAAK,EAAE,EAAE;QACf,IAAI,IAAI,CAAC;QAET,IAAI,QAAQ,IAAI,QAAQ,EAAE;YACxB,IAAI,GAAG;gBACL,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,QAAQ;aACf,CAAC;SACH;QAED,MAAM,MAAM,GAAuB;YACjC,IAAI;YACJ,IAAI;YACJ,IAAI;YACJ,MAAM,EAAE,KAAK;SACd,CAAC;QAEF,IAAI,CAAC,WAAW,GAAG,oBAAU,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;KACvD;AACH,CAAC;AAqCH,kBAAe,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vroskus/library-email",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Email",
5
5
  "author": "Vilius Roškus <vilius@regattas.eu>",
6
6
  "license": "MIT",
@@ -9,6 +9,10 @@
9
9
  "url": "git+https://github.com/vroskus/library-email.git"
10
10
  },
11
11
  "main": "dist/index.js",
12
+ "types": "dist/index.d.ts",
13
+ "files": [
14
+ "dist/"
15
+ ],
12
16
  "scripts": {
13
17
  "postinstall": "npm run build",
14
18
  "build": "tsc",
@@ -17,24 +21,24 @@
17
21
  "test:e2e": "echo 'No tests'"
18
22
  },
19
23
  "dependencies": {
20
- "@types/lodash": "4.14.192",
21
24
  "@types/nodemailer": "6.4.7",
22
- "html-to-text": "9.0.4",
25
+ "html-to-text": "9.0.5",
23
26
  "lodash": "4.17.21",
24
27
  "nodemailer": "6.9.1"
25
28
  },
26
29
  "devDependencies": {
27
30
  "@types/jest": "29.5.0",
31
+ "@types/lodash": "4.14.192",
28
32
  "@types/node": "18.15.11",
29
- "@typescript-eslint/eslint-plugin": "5.53.0",
30
- "@typescript-eslint/parser": "5.53.0",
31
- "eslint": "8.34.0",
33
+ "@typescript-eslint/eslint-plugin": "5.58.0",
34
+ "@typescript-eslint/parser": "5.58.0",
35
+ "eslint": "8.38.0",
32
36
  "eslint-config-airbnb-base": "15.0.0",
33
37
  "eslint-config-airbnb-typescript": "17.0.0",
34
38
  "eslint-plugin-import": "2.27.5",
35
39
  "eslint-plugin-import-newlines": "1.3.1",
36
40
  "eslint-plugin-react": "7.32.2",
37
- "eslint-plugin-sort": "2.4.0",
41
+ "eslint-plugin-sort": "2.7.1",
38
42
  "npm-check": "6.0.1",
39
43
  "typescript": "4.9.5"
40
44
  }
package/.eslintrc DELETED
@@ -1,76 +0,0 @@
1
- {
2
- "root": true,
3
- "parser": "@typescript-eslint/parser",
4
- "parserOptions": {
5
- "requireConfigFile": false,
6
- "project": ["tsconfig.json"]
7
- },
8
- "extends": [
9
- "airbnb-base",
10
- "airbnb-typescript",
11
- "plugin:import/recommended",
12
- "plugin:@typescript-eslint/eslint-recommended",
13
- "plugin:@typescript-eslint/recommended",
14
- "plugin:sort/recommended"
15
- ],
16
- "plugins": [
17
- "@typescript-eslint",
18
- "import",
19
- "import-newlines",
20
- "react",
21
- "sort"
22
- ],
23
- "rules": {
24
- "complexity": ["error", 5],
25
- "@typescript-eslint/ban-ts-comment": [1],
26
- "@typescript-eslint/no-unused-vars": [2],
27
- "curly": ["error", "all"],
28
- "import/no-cycle": [0],
29
- "no-await-in-loop": 0,
30
- "no-console": "error",
31
- "no-duplicate-imports": [0],
32
- "no-loss-of-precision": [0],
33
- "no-restricted-syntax": 0,
34
- "no-unreachable-loop": [0],
35
- "no-useless-backreference": [0],
36
- "no-unused-private-class-members": [2],
37
- "padding-line-between-statements": ["error", {
38
- "blankLine": "always",
39
- "prev": ["const", "let"],
40
- "next": "*"
41
- }, {
42
- "blankLine": "any",
43
- "prev": ["const", "let"],
44
- "next": ["const", "let"]
45
- }, {
46
- "blankLine": "always",
47
- "prev": ["if", "function", "for"],
48
- "next": "*"
49
- }, {
50
- "blankLine": "always",
51
- "prev": "*",
52
- "next": "return"
53
- }],
54
- "object-curly-newline": ["error", {
55
- "ObjectExpression": "always",
56
- "ObjectPattern": "always",
57
- "ImportDeclaration": "always",
58
- "ExportDeclaration": "always"
59
- }],
60
- "function-call-argument-newline": ["error", "always"],
61
- "object-property-newline": ["error", {
62
- "allowMultiplePropertiesPerLine": false
63
- }],
64
- "import-newlines/enforce": ["error", {
65
- "items": 1,
66
- "forceSingleLine": false
67
- }],
68
- "sort/imports": [0],
69
- "sort/exports": [0]
70
- },
71
- "env": {
72
- "node": true,
73
- "jest": true,
74
- "es6": true
75
- }
76
- }
package/src/index.ts DELETED
@@ -1,156 +0,0 @@
1
- // Helpers
2
- import nodemailer from 'nodemailer';
3
- import {
4
- htmlToText,
5
- } from 'html-to-text';
6
-
7
- // Types
8
- import type {
9
- $Config as Config,
10
- } from './types';
11
-
12
- type $SendMailParams = {
13
- bcc?: string | Array<string>;
14
- from: string;
15
- html: string;
16
- replyTo?: string;
17
- subject: string;
18
- text: string;
19
- to: string | Array<string>;
20
- };
21
-
22
- type $SendEmailResponse = {
23
- accepted: Array<string>;
24
- messageId: string;
25
- pending: Array<string>;
26
- rejected: Array<string>;
27
- response: string;
28
- };
29
-
30
- type $Transporter = {
31
- sendMail: (arg0: $SendMailParams) => Promise<$SendEmailResponse>;
32
- };
33
-
34
- export type $Config = Config;
35
-
36
- class EmailService<C extends Config> {
37
- from: string;
38
-
39
- transporter: $Transporter;
40
-
41
- constructor({
42
- email,
43
- from,
44
- host,
45
- password,
46
- port,
47
- username,
48
- }: C) {
49
- this.from = `"${from}" <${email}>`;
50
-
51
- this.#setupTransporter({
52
- host,
53
- password,
54
- port: port || '25',
55
- username,
56
- });
57
- }
58
-
59
- #setupTransporter({
60
- host,
61
- password,
62
- port,
63
- username,
64
- }: {
65
- host: string;
66
- password?: string;
67
- port: string;
68
- username?: string;
69
- }): void {
70
- this.transporter = {
71
- sendMail: async ({
72
- bcc,
73
- html,
74
- subject,
75
- text,
76
- to,
77
- }) => {
78
- // eslint-disable-next-line no-console
79
- console.log(
80
- '\x1b[33m',
81
- 'EmailService.sendEmail',
82
- '\x1b[0m\x1b[90m',
83
- to,
84
- bcc,
85
- subject,
86
- JSON.stringify(html),
87
- JSON.stringify(text),
88
- );
89
-
90
- return {
91
- accepted: Array.isArray(to) ? to : [to],
92
- messageId: '0',
93
- pending: [],
94
- rejected: [],
95
- response: 'Email sent by dummy service',
96
- };
97
- },
98
- };
99
-
100
- if (host !== '') {
101
- let auth;
102
-
103
- if (username && password) {
104
- auth = {
105
- pass: password,
106
- user: username,
107
- };
108
- }
109
-
110
- const params = {
111
- auth,
112
- host,
113
- port,
114
- secure: false,
115
- };
116
-
117
- this.transporter = nodemailer.createTransport(params);
118
- }
119
- }
120
-
121
- async sendMail({
122
- bcc,
123
- content,
124
- replyTo,
125
- subject,
126
- to,
127
- }: {
128
- bcc?: string | Array<string>;
129
- content: string;
130
- replyTo?: string;
131
- subject: string;
132
- to: string | Array<string>;
133
- }): Promise<string> {
134
- const params = {
135
- bcc,
136
- from: this.from,
137
- html: content,
138
- replyTo,
139
- subject,
140
- text: htmlToText(content),
141
- to,
142
- };
143
-
144
- const info: $SendEmailResponse = await this.transporter.sendMail(params);
145
-
146
- // eslint-disable-next-line no-console
147
- console.log(
148
- 'info',
149
- info,
150
- );
151
-
152
- return info.messageId;
153
- }
154
- }
155
-
156
- export default EmailService;
package/src/types.ts DELETED
@@ -1,8 +0,0 @@
1
- export type $Config = {
2
- email: string;
3
- from: string;
4
- host: string;
5
- password: string;
6
- port: string;
7
- username: string;
8
- };
package/tsconfig.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist/",
4
- "types": ["node", "jest"],
5
- "module": "commonjs",
6
- "esModuleInterop": true,
7
- "declaration": true,
8
- "noImplicitAny": false,
9
- "removeComments": true,
10
- "noLib": false,
11
- "emitDecoratorMetadata": true,
12
- "experimentalDecorators": true,
13
- "target": "es6",
14
- "sourceMap": true,
15
- "lib": [
16
- "es6"
17
- ]
18
- },
19
- "exclude": [
20
- "node_modules",
21
- "./dist/**/*"
22
- ],
23
- "include": [
24
- "./src"
25
- ]
26
- }