mikromail 0.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.
@@ -0,0 +1,121 @@
1
+ import {
2
+ ValidationError
3
+ } from "./chunk-47VXJTWV.mjs";
4
+
5
+ // src/Configuration.ts
6
+ import { existsSync, readFileSync } from "node:fs";
7
+ var Configuration = class {
8
+ config;
9
+ defaults = {
10
+ configFilePath: "mikromail.config.json",
11
+ args: []
12
+ };
13
+ /**
14
+ * @description Creates a new Configuration instance
15
+ * @param configFilePath Path to the configuration file (e.g., 'mikromail.config.json')
16
+ * @param args Command line arguments array from process.argv
17
+ */
18
+ constructor(options) {
19
+ const configuration = options?.config || {};
20
+ const configFilePath = options?.configFilePath || this.defaults.configFilePath;
21
+ const args = options?.args || this.defaults.args;
22
+ this.config = this.create(configFilePath, args, configuration);
23
+ }
24
+ /**
25
+ * @description Creates a configuration object by merging defaults, config file settings,
26
+ * and CLI arguments (in order of increasing precedence)
27
+ * @param configFilePath Path to the configuration file
28
+ * @param args Command line arguments array
29
+ * @returns The merged configuration object
30
+ */
31
+ create(configFilePath, args, configuration) {
32
+ const defaults = {
33
+ host: "",
34
+ user: "",
35
+ password: "",
36
+ port: 465,
37
+ secure: true,
38
+ debug: false,
39
+ maxRetries: 2
40
+ };
41
+ let fileConfig = {};
42
+ if (existsSync(configFilePath)) {
43
+ try {
44
+ const fileContent = readFileSync(configFilePath, "utf8");
45
+ fileConfig = JSON.parse(fileContent);
46
+ console.log(`Loaded configuration from ${configFilePath}`);
47
+ } catch (error) {
48
+ console.error(
49
+ `Error reading config file: ${error instanceof Error ? error.message : String(error)}`
50
+ );
51
+ }
52
+ }
53
+ const cliConfig = this.parseCliArgs(args);
54
+ return {
55
+ ...defaults,
56
+ ...configuration,
57
+ ...fileConfig,
58
+ ...cliConfig
59
+ };
60
+ }
61
+ /**
62
+ * @description Parses command line arguments into a configuration object
63
+ * @param args Command line arguments array
64
+ * @returns Parsed CLI configuration
65
+ */
66
+ parseCliArgs(args) {
67
+ const cliConfig = {};
68
+ for (let i = 2; i < args.length; i++) {
69
+ const arg = args[i];
70
+ switch (arg) {
71
+ case "--host":
72
+ if (i + 1 < args.length) cliConfig.host = args[++i];
73
+ break;
74
+ case "--user":
75
+ if (i + 1 < args.length) cliConfig.user = args[++i];
76
+ break;
77
+ case "--password":
78
+ if (i + 1 < args.length) cliConfig.password = args[++i];
79
+ break;
80
+ case "--port":
81
+ if (i + 1 < args.length) {
82
+ const value = Number.parseInt(args[++i], 10);
83
+ if (!Number.isNaN(value)) cliConfig.port = value;
84
+ }
85
+ break;
86
+ case "--secure":
87
+ cliConfig.secure = true;
88
+ break;
89
+ case "--debug":
90
+ cliConfig.debug = true;
91
+ break;
92
+ case "--retries":
93
+ if (i + 1 < args.length) {
94
+ const value = Number.parseInt(args[++i], 10);
95
+ if (!Number.isNaN(value)) cliConfig.maxRetries = value;
96
+ }
97
+ break;
98
+ }
99
+ }
100
+ return cliConfig;
101
+ }
102
+ /**
103
+ * @description Validates the configuration
104
+ * @throws Error if the configuration is invalid
105
+ */
106
+ validate() {
107
+ if (!this.config.host) throw new ValidationError("Host value not found");
108
+ }
109
+ /**
110
+ * @description Returns the complete configuration
111
+ * @returns The configuration object
112
+ */
113
+ get() {
114
+ this.validate();
115
+ return this.config;
116
+ }
117
+ };
118
+
119
+ export {
120
+ Configuration
121
+ };
@@ -0,0 +1,42 @@
1
+ import {
2
+ Configuration
3
+ } from "./chunk-V2NYOKWA.mjs";
4
+ import {
5
+ SMTPClient
6
+ } from "./chunk-TCYL3UFZ.mjs";
7
+ import {
8
+ verifyEmailDomain
9
+ } from "./chunk-UDLJWUFN.mjs";
10
+
11
+ // src/MikroMail.ts
12
+ var MikroMail = class {
13
+ smtpClient;
14
+ constructor(options) {
15
+ const config = new Configuration(options).get();
16
+ const smtpClient = new SMTPClient(config);
17
+ this.smtpClient = smtpClient;
18
+ }
19
+ /**
20
+ * Sends an email to valid domains.
21
+ */
22
+ async send(emailOptions) {
23
+ try {
24
+ const hasMXRecords = await verifyEmailDomain(emailOptions.to);
25
+ if (!hasMXRecords)
26
+ console.error("Warning: No MX records found for recipient domain");
27
+ const result = await this.smtpClient.sendEmail(emailOptions);
28
+ if (result.success) console.log(`Message ID: ${result.messageId}`);
29
+ else console.error(`Failed to send email: ${result.error}`);
30
+ await this.smtpClient.close();
31
+ } catch (error) {
32
+ console.error(
33
+ "Error in email sending process:",
34
+ error.message
35
+ );
36
+ }
37
+ }
38
+ };
39
+
40
+ export {
41
+ MikroMail
42
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @description The error is used when something was deemed invalid.
3
+ */
4
+ declare class ValidationError extends Error {
5
+ constructor(message: string);
6
+ }
7
+
8
+ export { ValidationError };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @description The error is used when something was deemed invalid.
3
+ */
4
+ declare class ValidationError extends Error {
5
+ constructor(message: string);
6
+ }
7
+
8
+ export { ValidationError };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/errors/index.ts
21
+ var errors_exports = {};
22
+ __export(errors_exports, {
23
+ ValidationError: () => ValidationError
24
+ });
25
+ module.exports = __toCommonJS(errors_exports);
26
+ var ValidationError = class extends Error {
27
+ constructor(message) {
28
+ super();
29
+ this.name = "ValidationError";
30
+ this.message = message;
31
+ this.cause = { statusCode: 400 };
32
+ }
33
+ };
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ ValidationError
37
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ ValidationError
3
+ } from "../chunk-47VXJTWV.mjs";
4
+ export {
5
+ ValidationError
6
+ };
@@ -0,0 +1,2 @@
1
+ export { MikroMail } from './MikroMail.mjs';
2
+ import './interfaces/index.mjs';
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { MikroMail } from './MikroMail.js';
2
+ import './interfaces/index.js';