@proteinjs/email-server 1.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/.eslintrc.js ADDED
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended', 'prettier'],
3
+ parser: '@typescript-eslint/parser',
4
+ plugins: ['@typescript-eslint', 'prettier'],
5
+ root: true,
6
+ ignorePatterns: ['**/dist/*', '**/node_modules/*', 'build-workspace.js', '*.md'],
7
+
8
+ rules: {
9
+ 'prettier/prettier': ['warn'],
10
+ curly: ['warn'],
11
+ 'eol-last': ['warn', 'always'],
12
+ 'keyword-spacing': ['warn', { before: true }],
13
+ 'no-undef': 'off',
14
+ '@typescript-eslint/no-unused-vars': 'off',
15
+ '@typescript-eslint/no-var-requires': 'off',
16
+ '@typescript-eslint/no-explicit-any': 'off',
17
+ '@typescript-eslint/prefer-as-const': 'off',
18
+ '@typescript-eslint/ban-types': 'off',
19
+ },
20
+ };
@@ -0,0 +1,5 @@
1
+ node_modules/
2
+ dist/
3
+ .DS_Store
4
+ build-workspace.js
5
+ *.md
package/.prettierrc ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "trailingComma": "es5",
3
+ "tabWidth": 2,
4
+ "semi": true,
5
+ "singleQuote": true,
6
+ "jsxSingleQuote": true,
7
+ "printWidth": 120
8
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 1.0.1 (2024-07-12)
7
+
8
+ **Note:** Version bump only for package @proteinjs/email-server
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Brent Bahry
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ /** Load Dependency Source Graphs */
2
+ import '@proteinjs/util';
3
+ import '@proteinjs/reflection';
4
+ import 'nodemailer';
5
+ export * from '../index';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,iBAAiB,CAAC;AACzB,OAAO,uBAAuB,CAAC;AAC/B,OAAO,YAAY,CAAC;AAqBpB,cAAc,UAAU,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /** Load Dependency Source Graphs */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ require("@proteinjs/util");
19
+ require("@proteinjs/reflection");
20
+ require("nodemailer");
21
+ /** Generate Source Graph */
22
+ var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/email-server/DefaultPasswordResetEmailConfigFactory\",\"value\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"DefaultPasswordResetEmailConfigFactory\",\"filePath\":\"/home/runner/work/notifications/notifications/packages/email/server/src/EmailConfigs.ts\",\"qualifiedName\":\"@proteinjs/email-server/DefaultPasswordResetEmailConfigFactory\",\"properties\":[],\"methods\":[{\"name\":\"getConfig\",\"returnType\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"PasswordResetEmailConfig\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/email-server/PasswordResetEmailConfig\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"@proteinjs/email-server/DefaultEmailConfigFactory\",\"value\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"DefaultEmailConfigFactory\",\"filePath\":\"/home/runner/work/notifications/notifications/packages/email/server/src/EmailSender.ts\",\"qualifiedName\":\"@proteinjs/email-server/DefaultEmailConfigFactory\",\"properties\":[],\"methods\":[{\"name\":\"getEmailConfig\",\"returnType\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"EmailConfig\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/email-server/EmailConfig\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}}],\"edges\":[{\"v\":\"@proteinjs/email-server/DefaultPasswordResetEmailConfigFactory\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/email-server/DefaultEmailConfigFactory\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"}]}";
23
+ /** Generate Source Links */
24
+ var sourceLinks = {};
25
+ /** Load Source Graph and Links */
26
+ var reflection_1 = require("@proteinjs/reflection");
27
+ reflection_1.SourceRepository.merge(sourceGraph, sourceLinks);
28
+ __exportStar(require("../index"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,2BAAyB;AACzB,iCAA+B;AAC/B,sBAAoB;AAGpB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,k7EAAk7E,CAAC;AAGv8E,4BAA4B;AAG5B,IAAM,WAAW,GAAG,EACnB,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
@@ -0,0 +1,3 @@
1
+ export * from './src/EmailConfigs';
2
+ export * from './src/EmailSender';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
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("./src/EmailConfigs"), exports);
18
+ __exportStar(require("./src/EmailSender"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,oDAAkC"}
@@ -0,0 +1,14 @@
1
+ import { Loadable } from '@proteinjs/reflection';
2
+ import Mail from 'nodemailer/lib/mailer';
3
+ export declare const getDefaultPasswordResetEmailConfigFactory: () => DefaultPasswordResetEmailConfigFactory;
4
+ export interface PasswordResetEmailConfig {
5
+ options?: Mail.Options;
6
+ getEmailContent: (token: string) => {
7
+ text: string;
8
+ html?: string;
9
+ };
10
+ }
11
+ export interface DefaultPasswordResetEmailConfigFactory extends Loadable {
12
+ getConfig(): PasswordResetEmailConfig;
13
+ }
14
+ //# sourceMappingURL=EmailConfigs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailConfigs.d.ts","sourceRoot":"","sources":["../../src/EmailConfigs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AACnE,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAEzC,eAAO,MAAM,yCAAyC,8CAGnD,CAAC;AAEJ,MAAM,WAAW,wBAAwB;IACvC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC;IACvB,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK;QAClC,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH;AAED,MAAM,WAAW,sCAAuC,SAAQ,QAAQ;IACtE,SAAS,IAAI,wBAAwB,CAAC;CACvC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDefaultPasswordResetEmailConfigFactory = void 0;
4
+ var reflection_1 = require("@proteinjs/reflection");
5
+ var getDefaultPasswordResetEmailConfigFactory = function () {
6
+ return reflection_1.SourceRepository.get().object('@proteinjs/user-server/DefaultPasswordResetEmailConfigFactory');
7
+ };
8
+ exports.getDefaultPasswordResetEmailConfigFactory = getDefaultPasswordResetEmailConfigFactory;
9
+ //# sourceMappingURL=EmailConfigs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailConfigs.js","sourceRoot":"","sources":["../../src/EmailConfigs.ts"],"names":[],"mappings":";;;AAAA,oDAAmE;AAG5D,IAAM,yCAAyC,GAAG;IACvD,OAAA,6BAAgB,CAAC,GAAG,EAAE,CAAC,MAAM,CAC3B,+DAA+D,CAChE;AAFD,CAEC,CAAC;AAHS,QAAA,yCAAyC,6CAGlD"}
@@ -0,0 +1,30 @@
1
+ import { Loadable } from '@proteinjs/reflection';
2
+ import Mail from 'nodemailer/lib/mailer';
3
+ export interface EmailConfig {
4
+ host: string;
5
+ port: number;
6
+ /** Defines if the connection should use SSL (if true) or not (if false) */
7
+ secure: boolean;
8
+ /** Authentication details for the email account used to send emails */
9
+ auth: {
10
+ user: string;
11
+ pass: string;
12
+ };
13
+ /** Use the format `Display Name <email@address.com>` */
14
+ from: string;
15
+ }
16
+ export interface DefaultEmailConfigFactory extends Loadable {
17
+ getEmailConfig(): EmailConfig;
18
+ }
19
+ export declare class EmailSender {
20
+ private static defaultEmailConfig;
21
+ private config;
22
+ private transporter;
23
+ private fromAddress;
24
+ private logger;
25
+ constructor(config?: EmailConfig);
26
+ private getDefaultEmailConfig;
27
+ sendEmail(mailOptions: Mail.Options): Promise<void>;
28
+ }
29
+ export declare function createEmailSender(config: EmailConfig): EmailSender;
30
+ //# sourceMappingURL=EmailSender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailSender.d.ts","sourceRoot":"","sources":["../../src/EmailSender.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAoB,MAAM,uBAAuB,CAAC;AACnE,OAAO,IAAI,MAAM,uBAAuB,CAAC;AAEzC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,2EAA2E;IAC3E,MAAM,EAAE,OAAO,CAAC;IAChB,uEAAuE;IACvE,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,yBAA0B,SAAQ,QAAQ;IACzD,cAAc,IAAI,WAAW,CAAC;CAC/B;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAc;IAC/C,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,CAAC,EAAE,WAAW;IAYhC,OAAO,CAAC,qBAAqB;IAiBvB,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAc1D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,CAElE"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.createEmailSender = exports.EmailSender = void 0;
54
+ var nodemailer_1 = __importDefault(require("nodemailer"));
55
+ var util_1 = require("@proteinjs/util");
56
+ var reflection_1 = require("@proteinjs/reflection");
57
+ var EmailSender = /** @class */ (function () {
58
+ function EmailSender(config) {
59
+ this.config = config ? config : this.getDefaultEmailConfig();
60
+ this.transporter = nodemailer_1.default.createTransport({
61
+ host: this.config.host,
62
+ port: this.config.port,
63
+ secure: this.config.secure,
64
+ auth: this.config.auth,
65
+ });
66
+ this.fromAddress = this.config.from;
67
+ this.logger = new util_1.Logger('EmailSender');
68
+ }
69
+ EmailSender.prototype.getDefaultEmailConfig = function () {
70
+ if (!EmailSender.defaultEmailConfig) {
71
+ var defaultEmailConfigFactory = reflection_1.SourceRepository.get().object('@proteinjs/user-server/DefaultEmailConfigFactory');
72
+ if (!defaultEmailConfigFactory) {
73
+ throw new Error("Unable to find a @proteinjs/user-server/DefaultEmailConfigFactory implementation. Either implement DefaultEmailConfigFactory or pass in an email config when instantiating EmailSender.");
74
+ }
75
+ EmailSender.defaultEmailConfig = defaultEmailConfigFactory.getEmailConfig();
76
+ }
77
+ return EmailSender.defaultEmailConfig;
78
+ };
79
+ EmailSender.prototype.sendEmail = function (mailOptions) {
80
+ return __awaiter(this, void 0, void 0, function () {
81
+ var finalMailOptions, error_1;
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ finalMailOptions = __assign({ from: this.fromAddress }, mailOptions);
86
+ _a.label = 1;
87
+ case 1:
88
+ _a.trys.push([1, 3, , 4]);
89
+ return [4 /*yield*/, this.transporter.sendMail(finalMailOptions)];
90
+ case 2:
91
+ _a.sent();
92
+ this.logger.info("Email sent successfully to ".concat(mailOptions.to));
93
+ return [3 /*break*/, 4];
94
+ case 3:
95
+ error_1 = _a.sent();
96
+ this.logger.error('Error sending email:', error_1);
97
+ throw new Error('Failed to send email');
98
+ case 4: return [2 /*return*/];
99
+ }
100
+ });
101
+ });
102
+ };
103
+ return EmailSender;
104
+ }());
105
+ exports.EmailSender = EmailSender;
106
+ function createEmailSender(config) {
107
+ return new EmailSender(config);
108
+ }
109
+ exports.createEmailSender = createEmailSender;
110
+ //# sourceMappingURL=EmailSender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmailSender.js","sourceRoot":"","sources":["../../src/EmailSender.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAoC;AACpC,wCAAyC;AACzC,oDAAmE;AAqBnE;IAOE,qBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC7D,IAAI,CAAC,WAAW,GAAG,oBAAU,CAAC,eAAe,CAAC;YAC5C,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;YACtB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;YAC1B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI;SACvB,CAAC,CAAC;QACH,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,IAAI,aAAM,CAAC,aAAa,CAAC,CAAC;IAC1C,CAAC;IAEO,2CAAqB,GAA7B;QACE,IAAI,CAAC,WAAW,CAAC,kBAAkB,EAAE;YACnC,IAAM,yBAAyB,GAAG,6BAAgB,CAAC,GAAG,EAAE,CAAC,MAAM,CAC7D,kDAAkD,CACnD,CAAC;YACF,IAAI,CAAC,yBAAyB,EAAE;gBAC9B,MAAM,IAAI,KAAK,CACb,yLAAyL,CAC1L,CAAC;aACH;YAED,WAAW,CAAC,kBAAkB,GAAG,yBAAyB,CAAC,cAAc,EAAE,CAAC;SAC7E;QAED,OAAO,WAAW,CAAC,kBAAkB,CAAC;IACxC,CAAC;IAEK,+BAAS,GAAf,UAAgB,WAAyB;;;;;;wBACjC,gBAAgB,cACpB,IAAI,EAAE,IAAI,CAAC,WAAW,IACnB,WAAW,CACf,CAAC;;;;wBAGA,qBAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAA;;wBAAjD,SAAiD,CAAC;wBAClD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,qCAA8B,WAAW,CAAC,EAAE,CAAE,CAAC,CAAC;;;;wBAEjE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,OAAK,CAAC,CAAC;wBACjD,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;;;;;KAE3C;IACH,kBAAC;AAAD,CAAC,AAlDD,IAkDC;AAlDY,kCAAW;AAoDxB,SAAgB,iBAAiB,CAAC,MAAmB;IACnD,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAFD,8CAEC"}
@@ -0,0 +1,26 @@
1
+ /** Load Dependency Source Graphs */
2
+
3
+ import '@proteinjs/util';
4
+ import '@proteinjs/reflection';
5
+ import 'nodemailer';
6
+
7
+
8
+ /** Generate Source Graph */
9
+
10
+ const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/email-server/DefaultPasswordResetEmailConfigFactory\",\"value\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"DefaultPasswordResetEmailConfigFactory\",\"filePath\":\"/home/runner/work/notifications/notifications/packages/email/server/src/EmailConfigs.ts\",\"qualifiedName\":\"@proteinjs/email-server/DefaultPasswordResetEmailConfigFactory\",\"properties\":[],\"methods\":[{\"name\":\"getConfig\",\"returnType\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"PasswordResetEmailConfig\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/email-server/PasswordResetEmailConfig\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"@proteinjs/email-server/DefaultEmailConfigFactory\",\"value\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"DefaultEmailConfigFactory\",\"filePath\":\"/home/runner/work/notifications/notifications/packages/email/server/src/EmailSender.ts\",\"qualifiedName\":\"@proteinjs/email-server/DefaultEmailConfigFactory\",\"properties\":[],\"methods\":[{\"name\":\"getEmailConfig\",\"returnType\":{\"packageName\":\"@proteinjs/email-server\",\"name\":\"EmailConfig\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/email-server/EmailConfig\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":false,\"isOptional\":false,\"isAbstract\":true,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[]}],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}}],\"edges\":[{\"v\":\"@proteinjs/email-server/DefaultPasswordResetEmailConfigFactory\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/email-server/DefaultEmailConfigFactory\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"}]}";
11
+
12
+
13
+ /** Generate Source Links */
14
+
15
+
16
+ const sourceLinks = {
17
+ };
18
+
19
+
20
+ /** Load Source Graph and Links */
21
+
22
+ import { SourceRepository } from '@proteinjs/reflection';
23
+ SourceRepository.merge(sourceGraph, sourceLinks);
24
+
25
+
26
+ export * from '../index';
package/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './src/EmailConfigs';
2
+ export * from './src/EmailSender';
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ roots: ['<rootDir>/test'],
3
+ transform: {
4
+ '^.+\\.tsx?$': 'ts-jest',
5
+ },
6
+ testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
7
+ moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
8
+ testEnvironment: 'node',
9
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@proteinjs/email-server",
3
+ "version": "1.0.1",
4
+ "description": "Email server libraries",
5
+ "main": "./dist/generated/index.js",
6
+ "types": "./dist/generated/index.d.ts",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/proteinjs/notifications.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/proteinjs/notifications/issues"
16
+ },
17
+ "homepage": "https://github.com/proteinjs/notifications#readme",
18
+ "author": "Brent Bahry",
19
+ "license": "MIT",
20
+ "scripts": {
21
+ "clean": "rm -rf dist/ generated/ node_modules/",
22
+ "build": "reflection-build && tsc",
23
+ "watch": "reflection-watch"
24
+ },
25
+ "dependencies": {
26
+ "@proteinjs/reflection": "1.1.6",
27
+ "@proteinjs/util": "1.2.0",
28
+ "nodemailer": "6.9.14"
29
+ },
30
+ "devDependencies": {
31
+ "@proteinjs/reflection-build": "1.0.21",
32
+ "@types/jest": "29.5.5",
33
+ "@types/node": "20.3.1",
34
+ "@types/nodemailer": "6.4.15",
35
+ "@typescript-eslint/eslint-plugin": "7.8.0",
36
+ "@typescript-eslint/parser": "7.8.0",
37
+ "eslint": "8.57.0",
38
+ "eslint-config-prettier": "9.1.0",
39
+ "eslint-plugin-prettier": "5.1.3",
40
+ "jest": "29.7.0",
41
+ "ts-jest": "29.1.1",
42
+ "typescript": "5.2.2"
43
+ },
44
+ "gitHead": "fb083f030cced657b131af60dc7e4f5934911aa1"
45
+ }
@@ -0,0 +1,19 @@
1
+ import { Loadable, SourceRepository } from '@proteinjs/reflection';
2
+ import Mail from 'nodemailer/lib/mailer';
3
+
4
+ export const getDefaultPasswordResetEmailConfigFactory = () =>
5
+ SourceRepository.get().object<DefaultPasswordResetEmailConfigFactory>(
6
+ '@proteinjs/user-server/DefaultPasswordResetEmailConfigFactory'
7
+ );
8
+
9
+ export interface PasswordResetEmailConfig {
10
+ options?: Mail.Options;
11
+ getEmailContent: (token: string) => {
12
+ text: string;
13
+ html?: string;
14
+ };
15
+ }
16
+
17
+ export interface DefaultPasswordResetEmailConfigFactory extends Loadable {
18
+ getConfig(): PasswordResetEmailConfig;
19
+ }
@@ -0,0 +1,78 @@
1
+ import nodemailer from 'nodemailer';
2
+ import { Logger } from '@proteinjs/util';
3
+ import { Loadable, SourceRepository } from '@proteinjs/reflection';
4
+ import Mail from 'nodemailer/lib/mailer';
5
+
6
+ export interface EmailConfig {
7
+ host: string;
8
+ port: number;
9
+ /** Defines if the connection should use SSL (if true) or not (if false) */
10
+ secure: boolean;
11
+ /** Authentication details for the email account used to send emails */
12
+ auth: {
13
+ user: string;
14
+ pass: string;
15
+ };
16
+ /** Use the format `Display Name <email@address.com>` */
17
+ from: string;
18
+ }
19
+
20
+ export interface DefaultEmailConfigFactory extends Loadable {
21
+ getEmailConfig(): EmailConfig;
22
+ }
23
+
24
+ export class EmailSender {
25
+ private static defaultEmailConfig: EmailConfig;
26
+ private config: EmailConfig;
27
+ private transporter: nodemailer.Transporter;
28
+ private fromAddress: string;
29
+ private logger: Logger;
30
+
31
+ constructor(config?: EmailConfig) {
32
+ this.config = config ? config : this.getDefaultEmailConfig();
33
+ this.transporter = nodemailer.createTransport({
34
+ host: this.config.host,
35
+ port: this.config.port,
36
+ secure: this.config.secure,
37
+ auth: this.config.auth,
38
+ });
39
+ this.fromAddress = this.config.from;
40
+ this.logger = new Logger('EmailSender');
41
+ }
42
+
43
+ private getDefaultEmailConfig(): EmailConfig {
44
+ if (!EmailSender.defaultEmailConfig) {
45
+ const defaultEmailConfigFactory = SourceRepository.get().object<DefaultEmailConfigFactory>(
46
+ '@proteinjs/user-server/DefaultEmailConfigFactory'
47
+ );
48
+ if (!defaultEmailConfigFactory) {
49
+ throw new Error(
50
+ `Unable to find a @proteinjs/user-server/DefaultEmailConfigFactory implementation. Either implement DefaultEmailConfigFactory or pass in an email config when instantiating EmailSender.`
51
+ );
52
+ }
53
+
54
+ EmailSender.defaultEmailConfig = defaultEmailConfigFactory.getEmailConfig();
55
+ }
56
+
57
+ return EmailSender.defaultEmailConfig;
58
+ }
59
+
60
+ async sendEmail(mailOptions: Mail.Options): Promise<void> {
61
+ const finalMailOptions = {
62
+ from: this.fromAddress,
63
+ ...mailOptions,
64
+ };
65
+
66
+ try {
67
+ await this.transporter.sendMail(finalMailOptions);
68
+ this.logger.info(`Email sent successfully to ${mailOptions.to}`);
69
+ } catch (error: any) {
70
+ this.logger.error('Error sending email:', error);
71
+ throw new Error('Failed to send email');
72
+ }
73
+ }
74
+ }
75
+
76
+ export function createEmailSender(config: EmailConfig): EmailSender {
77
+ return new EmailSender(config);
78
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "./",
4
+ "target": "es5",
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "./dist/",
10
+ "strict": true,
11
+ "noImplicitAny": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "resolveJsonModule": true,
16
+ "typeRoots": ["./node_modules/@types"],
17
+ "types": ["node", "jest"]
18
+ }
19
+ }