irismail 0.1.0 → 0.5.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.
@@ -1,110 +1,50 @@
1
- interface EmailConfig {
2
- transport: {
3
- host: string;
4
- port: number;
5
- secure?: boolean;
6
- auth: {
7
- user: string;
8
- pass: string;
9
- };
10
- };
11
- defaults?: {
12
- from?: {
13
- name: string;
14
- address: string;
15
- };
1
+ interface IrisMailConfig {
2
+ auth: {
3
+ user: string;
4
+ pass: string;
16
5
  };
17
6
  }
18
- interface SendEmailOptions {
7
+ interface SendMailOptions {
8
+ from: string;
19
9
  to: string;
20
10
  subject: string;
21
11
  html: string;
22
- text?: string;
23
- from?: {
24
- name: string;
25
- address: string;
26
- };
27
12
  }
28
- declare class EmailService {
13
+ interface SendMailResult {
14
+ success: boolean;
15
+ messageId: string;
16
+ }
17
+ /**
18
+ * IrisMail - Simple Gmail email sending service
19
+ *
20
+ * Automatically configured for Gmail SMTP. Only requires your Gmail credentials.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const mail = new IrisMail({
25
+ * auth: {
26
+ * user: process.env.GMAIL_USERNAME,
27
+ * pass: process.env.GMAIL_PASSWORD
28
+ * }
29
+ * });
30
+ *
31
+ * await mail.sendMail({
32
+ * from: process.env.GMAIL_USERNAME,
33
+ * to: 'friend@example.com',
34
+ * subject: 'Hello!',
35
+ * html: '<h1>Welcome</h1><p>Thanks for signing up!</p>'
36
+ * });
37
+ * ```
38
+ */
39
+ declare class IrisMail {
29
40
  private transporter;
30
- private config;
31
- constructor(config: EmailConfig);
32
- /**
33
- * Verify SMTP connection configuration
34
- */
35
- verifyConnection(): Promise<boolean>;
41
+ constructor(config: IrisMailConfig);
36
42
  /**
37
43
  * Send an email
38
- * @param options - Email options (to, subject, html, text, from)
39
- * @returns - Result of the send operation
40
- */
41
- sendEmail(options: SendEmailOptions): Promise<{
42
- success: boolean;
43
- messageId: any;
44
- }>;
45
- }
46
-
47
- interface OTPData {
48
- otp: string;
49
- timestamp: number;
50
- }
51
- declare class OTPService {
52
- private secretKey;
53
- constructor(secretKey: string);
54
- /**
55
- * Generate a numeric OTP of specified length
56
- * @param length - Length of the OTP (default: 6)
57
- * @returns - The generated OTP string
58
- */
59
- generateOTP(length?: number): string;
60
- /**
61
- * Encrypt OTP data for secure storage/transmission
62
- * @param otp - The OTP string
63
- * @param timestamp - The timestamp when OTP was generated (default: now)
64
- * @returns - Encrypted OTP data string
65
- */
66
- encryptOTP(otp: string, timestamp?: number): string;
67
- /**
68
- * Decrypt OTP data
69
- * @param encryptedData - The encrypted OTP string
70
- * @returns - Decrypted OTP data object or null if failed
44
+ * @param options - Email options (from, to, subject, html)
45
+ * @returns Promise with success status and messageId
71
46
  */
72
- decryptOTP(encryptedData: string): OTPData | null;
73
- /**
74
- * Verify an OTP against encrypted data
75
- * @param inputOtp - The OTP provided by the user
76
- * @param encryptedData - The encrypted OTP data
77
- * @param expiryMinutes - Expiry time in minutes (default: 5)
78
- * @returns - Object containing valid status and message
79
- */
80
- verifyOTP(inputOtp: string, encryptedData: string, expiryMinutes?: number): {
81
- valid: boolean;
82
- message: string;
83
- };
84
- }
85
-
86
- /**
87
- * Encrypts a string using AES-256-CBC
88
- * @param text - The text to encrypt
89
- * @param secretKey - The 32-character secret key
90
- * @returns - The encrypted value with IV and encrypted data, base64 encoded
91
- */
92
- declare function encrypt(text: string, secretKey: string): string;
93
- /**
94
- * Decrypts a string that was encrypted using the encrypt function
95
- * @param encryptedText - The encrypted text (IV:EncryptedData format)
96
- * @param secretKey - The 32-character secret key
97
- * @returns - The decrypted string
98
- */
99
- declare function decrypt(encryptedText: string, secretKey: string): string;
100
-
101
- declare class IrisMailService {
102
- email: EmailService;
103
- otp: OTPService;
104
- constructor(config: {
105
- email: EmailConfig;
106
- secretKey: string;
107
- });
47
+ sendMail(options: SendMailOptions): Promise<SendMailResult>;
108
48
  }
109
49
 
110
- export { type EmailConfig, EmailService, IrisMailService, type OTPData, OTPService, type SendEmailOptions, decrypt, encrypt };
50
+ export { IrisMail, type IrisMailConfig, type SendMailOptions, type SendMailResult };
@@ -1,110 +1,50 @@
1
- interface EmailConfig {
2
- transport: {
3
- host: string;
4
- port: number;
5
- secure?: boolean;
6
- auth: {
7
- user: string;
8
- pass: string;
9
- };
10
- };
11
- defaults?: {
12
- from?: {
13
- name: string;
14
- address: string;
15
- };
1
+ interface IrisMailConfig {
2
+ auth: {
3
+ user: string;
4
+ pass: string;
16
5
  };
17
6
  }
18
- interface SendEmailOptions {
7
+ interface SendMailOptions {
8
+ from: string;
19
9
  to: string;
20
10
  subject: string;
21
11
  html: string;
22
- text?: string;
23
- from?: {
24
- name: string;
25
- address: string;
26
- };
27
12
  }
28
- declare class EmailService {
13
+ interface SendMailResult {
14
+ success: boolean;
15
+ messageId: string;
16
+ }
17
+ /**
18
+ * IrisMail - Simple Gmail email sending service
19
+ *
20
+ * Automatically configured for Gmail SMTP. Only requires your Gmail credentials.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const mail = new IrisMail({
25
+ * auth: {
26
+ * user: process.env.GMAIL_USERNAME,
27
+ * pass: process.env.GMAIL_PASSWORD
28
+ * }
29
+ * });
30
+ *
31
+ * await mail.sendMail({
32
+ * from: process.env.GMAIL_USERNAME,
33
+ * to: 'friend@example.com',
34
+ * subject: 'Hello!',
35
+ * html: '<h1>Welcome</h1><p>Thanks for signing up!</p>'
36
+ * });
37
+ * ```
38
+ */
39
+ declare class IrisMail {
29
40
  private transporter;
30
- private config;
31
- constructor(config: EmailConfig);
32
- /**
33
- * Verify SMTP connection configuration
34
- */
35
- verifyConnection(): Promise<boolean>;
41
+ constructor(config: IrisMailConfig);
36
42
  /**
37
43
  * Send an email
38
- * @param options - Email options (to, subject, html, text, from)
39
- * @returns - Result of the send operation
40
- */
41
- sendEmail(options: SendEmailOptions): Promise<{
42
- success: boolean;
43
- messageId: any;
44
- }>;
45
- }
46
-
47
- interface OTPData {
48
- otp: string;
49
- timestamp: number;
50
- }
51
- declare class OTPService {
52
- private secretKey;
53
- constructor(secretKey: string);
54
- /**
55
- * Generate a numeric OTP of specified length
56
- * @param length - Length of the OTP (default: 6)
57
- * @returns - The generated OTP string
58
- */
59
- generateOTP(length?: number): string;
60
- /**
61
- * Encrypt OTP data for secure storage/transmission
62
- * @param otp - The OTP string
63
- * @param timestamp - The timestamp when OTP was generated (default: now)
64
- * @returns - Encrypted OTP data string
65
- */
66
- encryptOTP(otp: string, timestamp?: number): string;
67
- /**
68
- * Decrypt OTP data
69
- * @param encryptedData - The encrypted OTP string
70
- * @returns - Decrypted OTP data object or null if failed
44
+ * @param options - Email options (from, to, subject, html)
45
+ * @returns Promise with success status and messageId
71
46
  */
72
- decryptOTP(encryptedData: string): OTPData | null;
73
- /**
74
- * Verify an OTP against encrypted data
75
- * @param inputOtp - The OTP provided by the user
76
- * @param encryptedData - The encrypted OTP data
77
- * @param expiryMinutes - Expiry time in minutes (default: 5)
78
- * @returns - Object containing valid status and message
79
- */
80
- verifyOTP(inputOtp: string, encryptedData: string, expiryMinutes?: number): {
81
- valid: boolean;
82
- message: string;
83
- };
84
- }
85
-
86
- /**
87
- * Encrypts a string using AES-256-CBC
88
- * @param text - The text to encrypt
89
- * @param secretKey - The 32-character secret key
90
- * @returns - The encrypted value with IV and encrypted data, base64 encoded
91
- */
92
- declare function encrypt(text: string, secretKey: string): string;
93
- /**
94
- * Decrypts a string that was encrypted using the encrypt function
95
- * @param encryptedText - The encrypted text (IV:EncryptedData format)
96
- * @param secretKey - The 32-character secret key
97
- * @returns - The decrypted string
98
- */
99
- declare function decrypt(encryptedText: string, secretKey: string): string;
100
-
101
- declare class IrisMailService {
102
- email: EmailService;
103
- otp: OTPService;
104
- constructor(config: {
105
- email: EmailConfig;
106
- secretKey: string;
107
- });
47
+ sendMail(options: SendMailOptions): Promise<SendMailResult>;
108
48
  }
109
49
 
110
- export { type EmailConfig, EmailService, IrisMailService, type OTPData, OTPService, type SendEmailOptions, decrypt, encrypt };
50
+ export { IrisMail, type IrisMailConfig, type SendMailOptions, type SendMailResult };
@@ -32,187 +32,45 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
32
32
  // src/server/index.ts
33
33
  var server_exports = {};
34
34
  __export(server_exports, {
35
- EmailService: () => EmailService,
36
- IrisMailService: () => IrisMailService,
37
- OTPService: () => OTPService,
38
- decrypt: () => decrypt,
39
- encrypt: () => encrypt
35
+ IrisMail: () => IrisMail
40
36
  });
41
37
  module.exports = __toCommonJS(server_exports);
42
38
 
43
39
  // src/server/email.ts
44
40
  var import_nodemailer = __toESM(require("nodemailer"));
45
- var EmailService = class {
41
+ var IrisMail = class {
46
42
  constructor(config) {
47
43
  __publicField(this, "transporter");
48
- __publicField(this, "config");
49
- this.config = config;
50
- this.transporter = import_nodemailer.default.createTransport(config.transport);
51
- }
52
- /**
53
- * Verify SMTP connection configuration
54
- */
55
- async verifyConnection() {
56
- try {
57
- await this.transporter.verify();
58
- return true;
59
- } catch (error) {
60
- console.error("SMTP connection verification failed:", error);
61
- return false;
62
- }
44
+ this.transporter = import_nodemailer.default.createTransport({
45
+ host: "smtp.gmail.com",
46
+ port: 587,
47
+ secure: false,
48
+ // true for 465, false for other ports
49
+ auth: config.auth
50
+ });
63
51
  }
64
52
  /**
65
53
  * Send an email
66
- * @param options - Email options (to, subject, html, text, from)
67
- * @returns - Result of the send operation
54
+ * @param options - Email options (from, to, subject, html)
55
+ * @returns Promise with success status and messageId
68
56
  */
69
- async sendEmail(options) {
70
- const from = options.from || this.config.defaults?.from;
71
- if (!from) {
72
- throw new Error("From address is required either in options or config defaults");
73
- }
74
- const mailOptions = {
75
- from: {
76
- name: from.name,
77
- address: from.address
78
- },
79
- to: options.to,
80
- subject: options.subject,
81
- html: options.html,
82
- text: options.text || options.html.replace(/<[^>]*>/g, "")
83
- // Simple HTML to text fallback
57
+ async sendMail(options) {
58
+ const { from, to, subject, html } = options;
59
+ const text = html.replace(/<[^>]*>/g, "");
60
+ const info = await this.transporter.sendMail({
61
+ from,
62
+ to,
63
+ subject,
64
+ html,
65
+ text
66
+ });
67
+ return {
68
+ success: true,
69
+ messageId: info.messageId
84
70
  };
85
- try {
86
- const info = await this.transporter.sendMail(mailOptions);
87
- return {
88
- success: true,
89
- messageId: info.messageId
90
- };
91
- } catch (error) {
92
- console.error("Error sending email:", error);
93
- throw error;
94
- }
95
- }
96
- };
97
-
98
- // src/server/crypto.ts
99
- var import_crypto = __toESM(require("crypto"));
100
- var ALGORITHM = "aes-256-cbc";
101
- function encrypt(text, secretKey) {
102
- try {
103
- const key = Buffer.from(secretKey.padEnd(32).slice(0, 32));
104
- const iv = import_crypto.default.randomBytes(16);
105
- const cipher = import_crypto.default.createCipheriv(ALGORITHM, key, iv);
106
- let encrypted = cipher.update(text, "utf8", "base64");
107
- encrypted += cipher.final("base64");
108
- return iv.toString("hex") + ":" + encrypted;
109
- } catch (error) {
110
- console.error("Encryption error:", error);
111
- throw new Error("Failed to encrypt data");
112
- }
113
- }
114
- function decrypt(encryptedText, secretKey) {
115
- try {
116
- const key = Buffer.from(secretKey.padEnd(32).slice(0, 32));
117
- const parts = encryptedText.split(":");
118
- if (parts.length !== 2) {
119
- throw new Error("Invalid encrypted text format");
120
- }
121
- const iv = Buffer.from(parts[0], "hex");
122
- const encrypted = parts[1];
123
- const decipher = import_crypto.default.createDecipheriv(ALGORITHM, key, iv);
124
- let decrypted = decipher.update(encrypted, "base64", "utf8");
125
- decrypted += decipher.final("utf8");
126
- return decrypted;
127
- } catch (error) {
128
- console.error("Decryption error:", error);
129
- throw new Error("Failed to decrypt data");
130
- }
131
- }
132
-
133
- // src/server/otp.ts
134
- var OTPService = class {
135
- constructor(secretKey) {
136
- __publicField(this, "secretKey");
137
- if (!secretKey) {
138
- throw new Error("OTPService: secretKey is required");
139
- }
140
- this.secretKey = secretKey;
141
- }
142
- /**
143
- * Generate a numeric OTP of specified length
144
- * @param length - Length of the OTP (default: 6)
145
- * @returns - The generated OTP string
146
- */
147
- generateOTP(length = 6) {
148
- const min = Math.pow(10, length - 1);
149
- const max = Math.pow(10, length) - 1;
150
- return Math.floor(min + Math.random() * (max - min + 1)).toString();
151
- }
152
- /**
153
- * Encrypt OTP data for secure storage/transmission
154
- * @param otp - The OTP string
155
- * @param timestamp - The timestamp when OTP was generated (default: now)
156
- * @returns - Encrypted OTP data string
157
- */
158
- encryptOTP(otp, timestamp = Date.now()) {
159
- const data = JSON.stringify({ otp, timestamp });
160
- return encrypt(data, this.secretKey);
161
- }
162
- /**
163
- * Decrypt OTP data
164
- * @param encryptedData - The encrypted OTP string
165
- * @returns - Decrypted OTP data object or null if failed
166
- */
167
- decryptOTP(encryptedData) {
168
- try {
169
- const decryptedData = decrypt(encryptedData, this.secretKey);
170
- return JSON.parse(decryptedData);
171
- } catch (error) {
172
- console.error("Error decrypting OTP data:", error);
173
- return null;
174
- }
175
- }
176
- /**
177
- * Verify an OTP against encrypted data
178
- * @param inputOtp - The OTP provided by the user
179
- * @param encryptedData - The encrypted OTP data
180
- * @param expiryMinutes - Expiry time in minutes (default: 5)
181
- * @returns - Object containing valid status and message
182
- */
183
- verifyOTP(inputOtp, encryptedData, expiryMinutes = 5) {
184
- const data = this.decryptOTP(encryptedData);
185
- if (!data) {
186
- return { valid: false, message: "Invalid OTP data" };
187
- }
188
- const { otp, timestamp } = data;
189
- const currentTime = Date.now();
190
- const otpAge = currentTime - timestamp;
191
- const expiryTime = expiryMinutes * 60 * 1e3;
192
- if (otpAge > expiryTime) {
193
- return { valid: false, message: "OTP has expired" };
194
- }
195
- if (otp !== inputOtp) {
196
- return { valid: false, message: "Incorrect OTP" };
197
- }
198
- return { valid: true, message: "OTP verified successfully" };
199
- }
200
- };
201
-
202
- // src/server/index.ts
203
- var IrisMailService = class {
204
- constructor(config) {
205
- __publicField(this, "email");
206
- __publicField(this, "otp");
207
- this.email = new EmailService(config.email);
208
- this.otp = new OTPService(config.secretKey);
209
71
  }
210
72
  };
211
73
  // Annotate the CommonJS export names for ESM import in node:
212
74
  0 && (module.exports = {
213
- EmailService,
214
- IrisMailService,
215
- OTPService,
216
- decrypt,
217
- encrypt
75
+ IrisMail
218
76
  });
@@ -1,15 +1,7 @@
1
1
  import {
2
- EmailService,
3
- IrisMailService,
4
- OTPService,
5
- decrypt,
6
- encrypt
7
- } from "../chunk-XGASTZZ6.mjs";
2
+ IrisMail
3
+ } from "../chunk-64MVNASE.mjs";
8
4
  import "../chunk-QZ7TP4HQ.mjs";
9
5
  export {
10
- EmailService,
11
- IrisMailService,
12
- OTPService,
13
- decrypt,
14
- encrypt
6
+ IrisMail
15
7
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "irismail",
3
- "version": "0.1.0",
4
- "description": "A modular email and OTP service with Shadcn UI support",
3
+ "version": "0.5.0",
4
+ "description": "Simple email sending service and beautiful OTP input components for React",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {
@@ -28,14 +28,24 @@
28
28
  "build": "tsup src/index.ts src/server/index.ts src/react/index.ts --format cjs,esm --dts --clean",
29
29
  "dev": "tsup src/index.ts src/server/index.ts src/react/index.ts --format cjs,esm --dts --watch",
30
30
  "lint": "eslint src/**",
31
- "test": "echo \"Error: no test specified\" && exit 1"
31
+ "test": "echo \"Error: no test specified\" && exit 1",
32
+ "site": "npm --prefix site run dev",
33
+ "site:build": "npm --prefix site run build",
34
+ "site:start": "npm --prefix site run start",
35
+ "prepublishOnly": "npm run build",
36
+ "postpublish": "git push origin --tags",
37
+ "release:patch": "npm version patch && npm publish",
38
+ "release:minor": "npm version minor && npm publish",
39
+ "release:major": "npm version major && npm publish"
32
40
  },
33
41
  "keywords": [
34
42
  "email",
35
43
  "otp",
44
+ "otp-input",
36
45
  "shadcn",
37
46
  "react",
38
- "authentication"
47
+ "nodemailer",
48
+ "smtp"
39
49
  ],
40
50
  "author": "",
41
51
  "license": "ISC",
@@ -43,8 +53,7 @@
43
53
  "clsx": "^2.1.1",
44
54
  "input-otp": "^1.4.2",
45
55
  "nodemailer": "^7.0.10",
46
- "tailwind-merge": "^2.3.0",
47
- "zod": "^3.23.8"
56
+ "tailwind-merge": "^2.3.0"
48
57
  },
49
58
  "devDependencies": {
50
59
  "@types/node": "^20.12.12",