@nauth-toolkit/email-console 0.1.14 → 0.1.18
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/console-email.provider.d.ts +73 -1
- package/dist/console-email.provider.d.ts.map +1 -1
- package/dist/console-email.provider.js +85 -4
- package/dist/console-email.provider.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,12 +1,84 @@
|
|
|
1
1
|
import { EmailProvider, LoggerService } from '@nauth-toolkit/core';
|
|
2
|
+
/**
|
|
3
|
+
* Console Email Provider (Platform-Agnostic)
|
|
4
|
+
*
|
|
5
|
+
* Mock email provider that logs emails to console.
|
|
6
|
+
* Perfect for development and testing without external SMTP dependencies.
|
|
7
|
+
*
|
|
8
|
+
* This simply logs email details to the console for debugging purposes.
|
|
9
|
+
* No actual emails are sent, no templates are rendered.
|
|
10
|
+
*
|
|
11
|
+
* This is a plain TypeScript class with no framework dependencies.
|
|
12
|
+
* Works with any framework (NestJS, Express, Fastify, etc.)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // With custom logger
|
|
17
|
+
* const emailProvider = new ConsoleEmailProvider(myLogger);
|
|
18
|
+
*
|
|
19
|
+
* // With console logger (default)
|
|
20
|
+
* const emailProvider = new ConsoleEmailProvider();
|
|
21
|
+
*
|
|
22
|
+
* AuthModule.forRoot({
|
|
23
|
+
* emailProvider: new ConsoleEmailProvider(),
|
|
24
|
+
* })
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
2
27
|
export declare class ConsoleEmailProvider implements EmailProvider {
|
|
3
28
|
private logger;
|
|
4
29
|
constructor(logger?: LoggerService);
|
|
30
|
+
/**
|
|
31
|
+
* Set logger instance (called by AuthModule to inject NAuthLogger)
|
|
32
|
+
* @param logger - Logger instance to use
|
|
33
|
+
*/
|
|
5
34
|
setLogger(logger: LoggerService): void;
|
|
6
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Send verification email with code and/or link
|
|
37
|
+
*
|
|
38
|
+
* Logs email details to console for debugging.
|
|
39
|
+
*
|
|
40
|
+
* @param to - Recipient email address
|
|
41
|
+
* @param code - Verification code (e.g., "123456")
|
|
42
|
+
* @param link - Optional verification link (only logged if provided)
|
|
43
|
+
*/
|
|
44
|
+
sendVerificationEmail(to: string, code: string, link?: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Send password reset email with token and link
|
|
47
|
+
*
|
|
48
|
+
* Logs email details to console for debugging.
|
|
49
|
+
*
|
|
50
|
+
* @param to - Recipient email address
|
|
51
|
+
* @param token - Password reset token
|
|
52
|
+
* @param link - Password reset link (e.g., "https://example.com/reset?token=xxx")
|
|
53
|
+
*/
|
|
7
54
|
sendPasswordResetEmail(to: string, _token: string, _link: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Send welcome email to new users
|
|
57
|
+
*
|
|
58
|
+
* Logs email details to console for debugging.
|
|
59
|
+
*
|
|
60
|
+
* @param to - Recipient email address
|
|
61
|
+
* @param name - User's name
|
|
62
|
+
*/
|
|
8
63
|
sendWelcomeEmail(to: string, name: string): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Send account lockout notification
|
|
66
|
+
*
|
|
67
|
+
* Logs email details to console for debugging.
|
|
68
|
+
*
|
|
69
|
+
* @param to - Recipient email address
|
|
70
|
+
* @param reason - Lockout reason
|
|
71
|
+
* @param duration - Lockout duration in seconds
|
|
72
|
+
*/
|
|
9
73
|
sendLockoutEmail(to: string, reason: string, duration: number): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Send new device login notification
|
|
76
|
+
*
|
|
77
|
+
* Logs email details to console for debugging.
|
|
78
|
+
*
|
|
79
|
+
* @param to - Recipient email address
|
|
80
|
+
* @param deviceInfo - Device information (name, type, IP, location)
|
|
81
|
+
*/
|
|
10
82
|
sendNewDeviceEmail(to: string, deviceInfo: {
|
|
11
83
|
name?: string;
|
|
12
84
|
type?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-email.provider.d.ts","sourceRoot":"","sources":["../src/console-email.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"console-email.provider.d.ts","sourceRoot":"","sources":["../src/console-email.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IACxD,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,CAAC,EAAE,aAAa;IAIlC;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI;IAItC;;;;;;;;OAQG;IACG,qBAAqB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgBnF;;;;;;;;OAQG;IACG,sBAAsB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtF;;;;;;;OAOG;IACG,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ/D;;;;;;;;OAQG;IACG,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASnF;;;;;;;OAOG;IACG,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,UAAU,EAAE;QACV,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GACA,OAAO,CAAC,IAAI,CAAC;CAUjB"}
|
|
@@ -1,26 +1,90 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ConsoleEmailProvider = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Console Email Provider (Platform-Agnostic)
|
|
6
|
+
*
|
|
7
|
+
* Mock email provider that logs emails to console.
|
|
8
|
+
* Perfect for development and testing without external SMTP dependencies.
|
|
9
|
+
*
|
|
10
|
+
* This simply logs email details to the console for debugging purposes.
|
|
11
|
+
* No actual emails are sent, no templates are rendered.
|
|
12
|
+
*
|
|
13
|
+
* This is a plain TypeScript class with no framework dependencies.
|
|
14
|
+
* Works with any framework (NestJS, Express, Fastify, etc.)
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* // With custom logger
|
|
19
|
+
* const emailProvider = new ConsoleEmailProvider(myLogger);
|
|
20
|
+
*
|
|
21
|
+
* // With console logger (default)
|
|
22
|
+
* const emailProvider = new ConsoleEmailProvider();
|
|
23
|
+
*
|
|
24
|
+
* AuthModule.forRoot({
|
|
25
|
+
* emailProvider: new ConsoleEmailProvider(),
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
4
29
|
class ConsoleEmailProvider {
|
|
5
30
|
logger;
|
|
6
31
|
constructor(logger) {
|
|
7
32
|
this.logger = logger || console;
|
|
8
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Set logger instance (called by AuthModule to inject NAuthLogger)
|
|
36
|
+
* @param logger - Logger instance to use
|
|
37
|
+
*/
|
|
9
38
|
setLogger(logger) {
|
|
10
39
|
this.logger = logger;
|
|
11
40
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Send verification email with code and/or link
|
|
43
|
+
*
|
|
44
|
+
* Logs email details to console for debugging.
|
|
45
|
+
*
|
|
46
|
+
* @param to - Recipient email address
|
|
47
|
+
* @param code - Verification code (e.g., "123456")
|
|
48
|
+
* @param link - Optional verification link (only logged if provided)
|
|
49
|
+
*/
|
|
50
|
+
async sendVerificationEmail(to, code, link) {
|
|
51
|
+
// Build message similar to SMS format
|
|
52
|
+
let message = `Your verification code is: ${code}`;
|
|
53
|
+
if (link) {
|
|
54
|
+
message += `\nOr use this link: ${link}`;
|
|
55
|
+
}
|
|
56
|
+
// Log email content in a visually distinct format (matching SMS format)
|
|
57
|
+
this.logger.log(`\n${'='.repeat(60)}`);
|
|
58
|
+
this.logger.log('EMAIL MESSAGE');
|
|
59
|
+
this.logger.log('='.repeat(60));
|
|
15
60
|
this.logger.log(`To: ${to}`);
|
|
16
|
-
this.logger.log(
|
|
61
|
+
this.logger.log(`Message: ${message}`);
|
|
62
|
+
this.logger.log(`${'='.repeat(60)}\n`);
|
|
17
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Send password reset email with token and link
|
|
66
|
+
*
|
|
67
|
+
* Logs email details to console for debugging.
|
|
68
|
+
*
|
|
69
|
+
* @param to - Recipient email address
|
|
70
|
+
* @param token - Password reset token
|
|
71
|
+
* @param link - Password reset link (e.g., "https://example.com/reset?token=xxx")
|
|
72
|
+
*/
|
|
18
73
|
async sendPasswordResetEmail(to, _token, _link) {
|
|
74
|
+
// NOTE: Do not log secrets (tokens/links) to console.
|
|
19
75
|
this.logger.log('----------------------------------------------');
|
|
20
76
|
this.logger.log('EMAIL: Password reset email sent (simulated)');
|
|
21
77
|
this.logger.log(`To: ${to}`);
|
|
22
78
|
this.logger.log('----------------------------------------------');
|
|
23
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Send welcome email to new users
|
|
82
|
+
*
|
|
83
|
+
* Logs email details to console for debugging.
|
|
84
|
+
*
|
|
85
|
+
* @param to - Recipient email address
|
|
86
|
+
* @param name - User's name
|
|
87
|
+
*/
|
|
24
88
|
async sendWelcomeEmail(to, name) {
|
|
25
89
|
this.logger.log('----------------------------------------------');
|
|
26
90
|
this.logger.log('EMAIL: Welcome email sent (simulated)');
|
|
@@ -28,6 +92,15 @@ class ConsoleEmailProvider {
|
|
|
28
92
|
this.logger.log(`Name: ${name}`);
|
|
29
93
|
this.logger.log('----------------------------------------------');
|
|
30
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Send account lockout notification
|
|
97
|
+
*
|
|
98
|
+
* Logs email details to console for debugging.
|
|
99
|
+
*
|
|
100
|
+
* @param to - Recipient email address
|
|
101
|
+
* @param reason - Lockout reason
|
|
102
|
+
* @param duration - Lockout duration in seconds
|
|
103
|
+
*/
|
|
31
104
|
async sendLockoutEmail(to, reason, duration) {
|
|
32
105
|
this.logger.warn('----------------------------------------------');
|
|
33
106
|
this.logger.warn('EMAIL: Account lockout notification (simulated)');
|
|
@@ -36,6 +109,14 @@ class ConsoleEmailProvider {
|
|
|
36
109
|
this.logger.warn(`Duration: ${Math.round(duration / 60)} minutes`);
|
|
37
110
|
this.logger.warn('----------------------------------------------');
|
|
38
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Send new device login notification
|
|
114
|
+
*
|
|
115
|
+
* Logs email details to console for debugging.
|
|
116
|
+
*
|
|
117
|
+
* @param to - Recipient email address
|
|
118
|
+
* @param deviceInfo - Device information (name, type, IP, location)
|
|
119
|
+
*/
|
|
39
120
|
async sendNewDeviceEmail(to, deviceInfo) {
|
|
40
121
|
this.logger.log('----------------------------------------------');
|
|
41
122
|
this.logger.log('EMAIL: New device login notification (simulated)');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"console-email.provider.js","sourceRoot":"","sources":["../src/console-email.provider.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"console-email.provider.js","sourceRoot":"","sources":["../src/console-email.provider.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;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AAC,MAAM,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,UAAU,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,SAAS,UAAU,CAAC,IAAI,IAAI,SAAS,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,UAAU,CAAC,EAAE,IAAI,SAAS,EAAE,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,UAAU,CAAC,QAAQ,IAAI,SAAS,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;CACF;AArHD,oDAqHC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @nauth-toolkit/email-console
|
|
4
|
+
*
|
|
5
|
+
* Console email provider for nauth-toolkit.
|
|
6
|
+
* Logs emails to console for development and testing.
|
|
7
|
+
*/
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.ConsoleEmailProvider = void 0;
|
|
4
10
|
var console_email_provider_1 = require("./console-email.provider");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nauth-toolkit/email-console",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Console email provider for nauth-toolkit (dev/test)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@nauth-toolkit/core": "^0.1.
|
|
30
|
+
"@nauth-toolkit/core": "^0.1.18"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/jest": "^29.5.0",
|