@mysetup/nodemailer 1.0.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.
@@ -0,0 +1,2 @@
1
+ export * from "./nodemailer";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./nodemailer"), exports);
@@ -0,0 +1,3 @@
1
+ import { type SendEmailInput } from "./types";
2
+ export declare const connectNodeMailer: (data: SendEmailInput) => Promise<string | undefined>;
3
+ //# sourceMappingURL=nodemailer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodemailer.d.ts","sourceRoot":"","sources":["../nodemailer.ts"],"names":[],"mappings":"AAOA,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,SAAS,CAAC;AAqCjE,eAAO,MAAM,iBAAiB,SAAgB,cAAc,gCA+B3D,CAAC"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.connectNodeMailer = void 0;
43
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
44
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
45
+ var node_path_1 = __importDefault(require("node:path"));
46
+ var ejs_1 = __importDefault(require("ejs"));
47
+ var logger_1 = require("@mysetup/logger");
48
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-var-requires
49
+ var nodemailer = require("nodemailer");
50
+ var sendMail = function (mailOptions, env) {
51
+ return new Promise(function (resolve, reject) {
52
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
53
+ var transporter = nodemailer.createTransport({
54
+ service: "gmail",
55
+ auth: {
56
+ user: env.user,
57
+ pass: env.pass,
58
+ },
59
+ }, {
60
+ from: env.from,
61
+ });
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ transporter.sendMail(mailOptions, function (error, info) {
64
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
65
+ if (error) {
66
+ logger_1.logger.error(error);
67
+ reject(error);
68
+ }
69
+ else {
70
+ resolve("Email sent: ".concat(info.response));
71
+ logger_1.logger.info("Email sent: ".concat(info.response));
72
+ }
73
+ });
74
+ });
75
+ };
76
+ var connectNodeMailer = function (data) { return __awaiter(void 0, void 0, void 0, function () {
77
+ var templatePath, htmlTemplate, mailOptions, env, error_1;
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ _a.trys.push([0, 3, , 4]);
82
+ templatePath = node_path_1.default.join(__dirname, "views", "".concat(data.template, ".ejs"));
83
+ return [4 /*yield*/, ejs_1.default.renderFile(templatePath, data.value)];
84
+ case 1:
85
+ htmlTemplate = _a.sent();
86
+ mailOptions = {
87
+ to: data.toEmail,
88
+ subject: data.subject,
89
+ html: htmlTemplate,
90
+ };
91
+ env = {
92
+ user: data.user,
93
+ pass: data.pass,
94
+ from: data.from,
95
+ };
96
+ return [4 /*yield*/, sendMail(mailOptions, env)];
97
+ case 2:
98
+ // Send email
99
+ return [2 /*return*/, _a.sent()];
100
+ case 3:
101
+ error_1 = _a.sent();
102
+ logger_1.logger.error(error_1);
103
+ return [3 /*break*/, 4];
104
+ case 4: return [2 /*return*/];
105
+ }
106
+ });
107
+ }); };
108
+ exports.connectNodeMailer = connectNodeMailer;
@@ -0,0 +1,12 @@
1
+ export interface SendEmailEnv {
2
+ user: string;
3
+ pass: string;
4
+ from: string;
5
+ }
6
+ export interface SendEmailInput extends SendEmailEnv {
7
+ subject: string;
8
+ toEmail: string;
9
+ template: string;
10
+ value: JSON;
11
+ }
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAe,SAAQ,YAAY;IAChD,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,IAAI,CAAC;CACf"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@mysetup/nodemailer",
3
+ "version": "1.0.0",
4
+ "license": "MIT",
5
+ "main": "dist/index.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "scripts": {
18
+ "lint": "eslint .",
19
+ "typecheck": "tsc --noEmit",
20
+ "build": "rm -rf ./dist && tsc",
21
+ "format": "prettier --write \"**/*.{ts,tsx,md,js}\"",
22
+ "checks": "pnpm typecheck && pnpm lint",
23
+ "clean": "rm -rf node_modules .swc dist pnpm-lock.yaml && echo \"✅ Successfully removed \""
24
+ },
25
+ "dependencies": {
26
+ "ejs": "3.1.10",
27
+ "nodemailer": "^6.9.16"
28
+ },
29
+ "devDependencies": {
30
+ "@mysetup/eslint-config": "latest",
31
+ "@mysetup/logger": "latest",
32
+ "@mysetup/prettier-config": "latest",
33
+ "@mysetup/tsconfig": "latest",
34
+ "@types/ejs": "^3.1.5",
35
+ "@types/node": "^22.8.6",
36
+ "@types/nodemailer": "^6.4.16",
37
+ "eslint": "8.57.0",
38
+ "typescript": "^5.6.3"
39
+ },
40
+ "prettier": "@mysetup/prettier-config",
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ },
44
+ "packageManager": "pnpm@9.9.0"
45
+ }