@nauth-toolkit/email-nodemailer 0.1.21 → 0.1.23
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,15 +1,17 @@
|
|
|
1
|
-
import { EmailProvider, TemplateVariables, LoggerService } from '@nauth-toolkit/core';
|
|
1
|
+
import { EmailProvider, TemplateVariables, LoggerService, TemplateEngine } from '@nauth-toolkit/core';
|
|
2
|
+
import type { Transporter, TransportOptions } from 'nodemailer';
|
|
2
3
|
/**
|
|
3
4
|
* Nodemailer Transport Configuration
|
|
4
5
|
*
|
|
5
6
|
* Supports various transport types:
|
|
6
7
|
* - SMTP (generic)
|
|
7
|
-
* - AWS SES
|
|
8
|
+
* - AWS SES (via SDK)
|
|
8
9
|
* - SendGrid
|
|
9
10
|
* - Mailgun
|
|
10
11
|
* - Postmark
|
|
11
12
|
* - Gmail (with OAuth2)
|
|
12
13
|
* - Outlook/Office365
|
|
14
|
+
* - Custom transports
|
|
13
15
|
*/
|
|
14
16
|
export interface NodemailerTransportConfig {
|
|
15
17
|
/**
|
|
@@ -43,29 +45,74 @@ export interface NodemailerTransportConfig {
|
|
|
43
45
|
*/
|
|
44
46
|
service?: string;
|
|
45
47
|
/**
|
|
46
|
-
* AWS region (for SES)
|
|
48
|
+
* AWS region (for SES SMTP)
|
|
47
49
|
*/
|
|
48
50
|
region?: string;
|
|
51
|
+
/**
|
|
52
|
+
* AWS SES SDK transport configuration
|
|
53
|
+
* Requires @aws-sdk/client-sesv2 package
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
|
|
58
|
+
*
|
|
59
|
+
* SES: {
|
|
60
|
+
* sesClient: new SESv2Client({ region: 'us-east-1' }),
|
|
61
|
+
* SendEmailCommand,
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
SES?: {
|
|
66
|
+
sesClient: unknown;
|
|
67
|
+
SendEmailCommand: unknown;
|
|
68
|
+
};
|
|
49
69
|
/**
|
|
50
70
|
* Additional transport options
|
|
51
71
|
*/
|
|
52
|
-
[key: string]:
|
|
72
|
+
[key: string]: unknown;
|
|
53
73
|
}
|
|
54
74
|
/**
|
|
55
75
|
* Nodemailer Provider Configuration
|
|
56
76
|
*/
|
|
57
77
|
export interface NodemailerProviderConfig {
|
|
58
78
|
/**
|
|
59
|
-
* Nodemailer transport configuration
|
|
79
|
+
* Nodemailer transport configuration or pre-configured transporter
|
|
80
|
+
*
|
|
81
|
+
* Can be:
|
|
82
|
+
* - NodemailerTransportConfig (SMTP-style config)
|
|
83
|
+
* - Raw nodemailer transport config (for AWS SES SDK, custom transports, etc.)
|
|
84
|
+
* - Pre-configured Transporter instance
|
|
85
|
+
*
|
|
86
|
+
* @example AWS SES with SDK (IAM roles)
|
|
87
|
+
* ```typescript
|
|
88
|
+
* import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
|
|
89
|
+
*
|
|
90
|
+
* new NodemailerProvider({
|
|
91
|
+
* transport: {
|
|
92
|
+
* SES: {
|
|
93
|
+
* sesClient: new SESv2Client({ region: 'us-east-1' }), // Uses IAM role automatically
|
|
94
|
+
* SendEmailCommand,
|
|
95
|
+
* },
|
|
96
|
+
* },
|
|
97
|
+
* })
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* @example Pre-configured transporter
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const transporter = nodemailer.createTransport({ ... });
|
|
103
|
+
* new NodemailerProvider({
|
|
104
|
+
* transport: transporter,
|
|
105
|
+
* })
|
|
106
|
+
* ```
|
|
60
107
|
*/
|
|
61
|
-
transport: NodemailerTransportConfig;
|
|
108
|
+
transport: NodemailerTransportConfig | TransportOptions | Transporter;
|
|
62
109
|
/**
|
|
63
110
|
* Default email options (from, replyTo, etc.)
|
|
64
111
|
*/
|
|
65
112
|
defaults?: {
|
|
66
113
|
from?: string;
|
|
67
114
|
replyTo?: string;
|
|
68
|
-
[key: string]:
|
|
115
|
+
[key: string]: unknown;
|
|
69
116
|
};
|
|
70
117
|
/**
|
|
71
118
|
* Enable template engine (default: true)
|
|
@@ -74,11 +121,17 @@ export interface NodemailerProviderConfig {
|
|
|
74
121
|
/**
|
|
75
122
|
* Custom template engine (default: HandlebarsTemplateEngine with MJML templates)
|
|
76
123
|
*/
|
|
77
|
-
templateEngine?:
|
|
124
|
+
templateEngine?: TemplateEngine;
|
|
78
125
|
/**
|
|
79
126
|
* Enable preview URL in development (default: false)
|
|
80
127
|
*/
|
|
81
128
|
preview?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Skip connection verification (optional, for transports that don't support verify)
|
|
131
|
+
* Note: AWS SES SDK transport DOES support verify() according to nodemailer docs
|
|
132
|
+
* @default false
|
|
133
|
+
*/
|
|
134
|
+
skipVerification?: boolean;
|
|
82
135
|
}
|
|
83
136
|
/**
|
|
84
137
|
* Nodemailer Email Provider
|
|
@@ -93,8 +146,7 @@ export interface NodemailerProviderConfig {
|
|
|
93
146
|
* - Connection pooling
|
|
94
147
|
* - Retry logic
|
|
95
148
|
* - Preview URLs in development
|
|
96
|
-
*
|
|
97
|
-
* **Phase 2c Implementation**
|
|
149
|
+
* - AWS SES SDK support with IAM roles
|
|
98
150
|
*
|
|
99
151
|
* @example SMTP Configuration
|
|
100
152
|
* ```typescript
|
|
@@ -118,20 +170,40 @@ export interface NodemailerProviderConfig {
|
|
|
118
170
|
* })
|
|
119
171
|
* ```
|
|
120
172
|
*
|
|
121
|
-
* @example AWS SES
|
|
173
|
+
* @example AWS SES with SDK (IAM roles) - Recommended
|
|
122
174
|
* ```typescript
|
|
175
|
+
* import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
|
|
176
|
+
*
|
|
123
177
|
* new NodemailerProvider({
|
|
124
178
|
* transport: {
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
* pass: process.env.AWS_SECRET_ACCESS_KEY,
|
|
179
|
+
* SES: {
|
|
180
|
+
* sesClient: new SESv2Client({ region: 'us-east-1' }), // Uses IAM role automatically
|
|
181
|
+
* SendEmailCommand,
|
|
129
182
|
* },
|
|
130
|
-
*
|
|
183
|
+
* },
|
|
184
|
+
* defaults: {
|
|
185
|
+
* from: '"My App" <noreply@example.com>',
|
|
131
186
|
* },
|
|
132
187
|
* })
|
|
133
188
|
* ```
|
|
134
189
|
*
|
|
190
|
+
* @example Pre-configured transporter
|
|
191
|
+
* ```typescript
|
|
192
|
+
* import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
|
|
193
|
+
* import * as nodemailer from 'nodemailer';
|
|
194
|
+
*
|
|
195
|
+
* const transporter = nodemailer.createTransport({
|
|
196
|
+
* SES: {
|
|
197
|
+
* sesClient: new SESv2Client({ region: 'us-east-1' }),
|
|
198
|
+
* SendEmailCommand,
|
|
199
|
+
* },
|
|
200
|
+
* });
|
|
201
|
+
*
|
|
202
|
+
* new NodemailerProvider({
|
|
203
|
+
* transport: transporter,
|
|
204
|
+
* })
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
135
207
|
* @example SendGrid Configuration
|
|
136
208
|
* ```typescript
|
|
137
209
|
* new NodemailerProvider({
|
|
@@ -185,7 +257,27 @@ export declare class NodemailerProvider implements EmailProvider {
|
|
|
185
257
|
*/
|
|
186
258
|
constructor(config: NodemailerProviderConfig);
|
|
187
259
|
/**
|
|
188
|
-
*
|
|
260
|
+
* Check if transport config uses AWS SES SDK
|
|
261
|
+
*
|
|
262
|
+
* @param transport - Transport configuration to check
|
|
263
|
+
* @returns True if transport uses AWS SES SDK
|
|
264
|
+
* @private
|
|
265
|
+
*/
|
|
266
|
+
private isSESTransport;
|
|
267
|
+
/**
|
|
268
|
+
* Check if transport is a pre-configured Transporter instance
|
|
269
|
+
*
|
|
270
|
+
* @param transport - Transport to check
|
|
271
|
+
* @returns True if transport is a Transporter instance
|
|
272
|
+
* @private
|
|
273
|
+
*/
|
|
274
|
+
private isTransporterInstance;
|
|
275
|
+
/**
|
|
276
|
+
* Verify email transport connection
|
|
277
|
+
*
|
|
278
|
+
* For SMTP: Tests actual connection
|
|
279
|
+
* For SES SDK: Attempts to send invalid test message to validate credentials
|
|
280
|
+
*
|
|
189
281
|
* @private
|
|
190
282
|
*/
|
|
191
283
|
private verifyConnection;
|
|
@@ -224,9 +316,14 @@ export declare class NodemailerProvider implements EmailProvider {
|
|
|
224
316
|
* Send new device login notification
|
|
225
317
|
*
|
|
226
318
|
* @param to - Recipient email address
|
|
227
|
-
* @param deviceInfo - Device information
|
|
319
|
+
* @param deviceInfo - Device information object with optional properties: name, type, ipAddress, location
|
|
228
320
|
*/
|
|
229
|
-
sendNewDeviceEmail(to: string, deviceInfo:
|
|
321
|
+
sendNewDeviceEmail(to: string, deviceInfo: {
|
|
322
|
+
name?: string;
|
|
323
|
+
type?: string;
|
|
324
|
+
ipAddress?: string;
|
|
325
|
+
location?: string;
|
|
326
|
+
}, variables?: TemplateVariables): Promise<void>;
|
|
230
327
|
/**
|
|
231
328
|
* Send email using Nodemailer
|
|
232
329
|
* @private
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodemailer-email.provider.d.ts","sourceRoot":"","sources":["../src/nodemailer-email.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgB,iBAAiB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"nodemailer-email.provider.d.ts","sourceRoot":"","sources":["../src/nodemailer-email.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgB,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGpH,OAAO,KAAK,EAAE,WAAW,EAAmB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEjF;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH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;;;;;;OAMG;IACG,gBAAgB,CACpB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,iBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC;IAoBhB;;;;;OAKG;IACG,kBAAkB,CACtB,EAAE,EAAE,MAAM,EACV,UAAU,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,EACnF,SAAS,GAAE,iBAAsB,GAChC,OAAO,CAAC,IAAI,CAAC;IAuBhB;;;OAGG;YACW,QAAQ;IA0CtB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
|
@@ -50,8 +50,7 @@ const nodemailer = __importStar(require("nodemailer"));
|
|
|
50
50
|
* - Connection pooling
|
|
51
51
|
* - Retry logic
|
|
52
52
|
* - Preview URLs in development
|
|
53
|
-
*
|
|
54
|
-
* **Phase 2c Implementation**
|
|
53
|
+
* - AWS SES SDK support with IAM roles
|
|
55
54
|
*
|
|
56
55
|
* @example SMTP Configuration
|
|
57
56
|
* ```typescript
|
|
@@ -75,20 +74,40 @@ const nodemailer = __importStar(require("nodemailer"));
|
|
|
75
74
|
* })
|
|
76
75
|
* ```
|
|
77
76
|
*
|
|
78
|
-
* @example AWS SES
|
|
77
|
+
* @example AWS SES with SDK (IAM roles) - Recommended
|
|
79
78
|
* ```typescript
|
|
79
|
+
* import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
|
|
80
|
+
*
|
|
80
81
|
* new NodemailerProvider({
|
|
81
82
|
* transport: {
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
* pass: process.env.AWS_SECRET_ACCESS_KEY,
|
|
83
|
+
* SES: {
|
|
84
|
+
* sesClient: new SESv2Client({ region: 'us-east-1' }), // Uses IAM role automatically
|
|
85
|
+
* SendEmailCommand,
|
|
86
86
|
* },
|
|
87
|
-
*
|
|
87
|
+
* },
|
|
88
|
+
* defaults: {
|
|
89
|
+
* from: '"My App" <noreply@example.com>',
|
|
88
90
|
* },
|
|
89
91
|
* })
|
|
90
92
|
* ```
|
|
91
93
|
*
|
|
94
|
+
* @example Pre-configured transporter
|
|
95
|
+
* ```typescript
|
|
96
|
+
* import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
|
|
97
|
+
* import * as nodemailer from 'nodemailer';
|
|
98
|
+
*
|
|
99
|
+
* const transporter = nodemailer.createTransport({
|
|
100
|
+
* SES: {
|
|
101
|
+
* sesClient: new SESv2Client({ region: 'us-east-1' }),
|
|
102
|
+
* SendEmailCommand,
|
|
103
|
+
* },
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* new NodemailerProvider({
|
|
107
|
+
* transport: transporter,
|
|
108
|
+
* })
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
92
111
|
* @example SendGrid Configuration
|
|
93
112
|
* ```typescript
|
|
94
113
|
* new NodemailerProvider({
|
|
@@ -146,43 +165,107 @@ class NodemailerProvider {
|
|
|
146
165
|
*/
|
|
147
166
|
constructor(config) {
|
|
148
167
|
// Log configuration (sanitized)
|
|
168
|
+
const isSES = this.isSESTransport(config.transport);
|
|
169
|
+
const transportType = isSES
|
|
170
|
+
? 'AWS SES SDK'
|
|
171
|
+
: this.isTransporterInstance(config.transport)
|
|
172
|
+
? 'Pre-configured'
|
|
173
|
+
: 'Config-based';
|
|
149
174
|
this.logger?.debug?.('Initializing NodemailerProvider', {
|
|
150
|
-
|
|
151
|
-
port: config.transport.port,
|
|
152
|
-
secure: config.transport.secure,
|
|
175
|
+
transportType,
|
|
153
176
|
from: config.defaults?.from,
|
|
154
177
|
});
|
|
155
|
-
// Create
|
|
156
|
-
this.
|
|
178
|
+
// Create or use provided transporter
|
|
179
|
+
if (this.isTransporterInstance(config.transport)) {
|
|
180
|
+
// Pre-configured transporter instance
|
|
181
|
+
this.transporter = config.transport;
|
|
182
|
+
this.logger?.debug?.('Using pre-configured transporter');
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
// Create transporter from config
|
|
186
|
+
// nodemailer.createTransport accepts any transport config, including SES SDK config
|
|
187
|
+
this.transporter = nodemailer.createTransport(config.transport);
|
|
188
|
+
this.logger?.debug?.('Created transporter from config');
|
|
189
|
+
}
|
|
157
190
|
// Initialize template engine
|
|
158
|
-
this.templateEngine =
|
|
191
|
+
this.templateEngine =
|
|
192
|
+
config.templateEngine || new handlebars_template_engine_1.HandlebarsTemplateEngine();
|
|
159
193
|
// Set defaults
|
|
160
194
|
this.defaults = config.defaults || {};
|
|
161
195
|
this.preview = config.preview || false;
|
|
162
|
-
// Verify connection
|
|
163
|
-
|
|
196
|
+
// Verify connection (skip if configured)
|
|
197
|
+
if (!config.skipVerification) {
|
|
198
|
+
this.verifyConnection();
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.logger?.debug?.('Skipping connection verification');
|
|
202
|
+
}
|
|
164
203
|
}
|
|
165
204
|
/**
|
|
166
|
-
*
|
|
205
|
+
* Check if transport config uses AWS SES SDK
|
|
206
|
+
*
|
|
207
|
+
* @param transport - Transport configuration to check
|
|
208
|
+
* @returns True if transport uses AWS SES SDK
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
isSESTransport(transport) {
|
|
212
|
+
if (!transport || typeof transport !== 'object') {
|
|
213
|
+
return false;
|
|
214
|
+
}
|
|
215
|
+
if (this.isTransporterInstance(transport)) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
const transportObj = transport;
|
|
219
|
+
return 'SES' in transportObj && !!transportObj.SES?.sesClient && !!transportObj.SES?.SendEmailCommand;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Check if transport is a pre-configured Transporter instance
|
|
223
|
+
*
|
|
224
|
+
* @param transport - Transport to check
|
|
225
|
+
* @returns True if transport is a Transporter instance
|
|
226
|
+
* @private
|
|
227
|
+
*/
|
|
228
|
+
isTransporterInstance(transport) {
|
|
229
|
+
if (!transport || typeof transport !== 'object') {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
const transporter = transport;
|
|
233
|
+
return typeof transporter.sendMail === 'function' && typeof transporter.verify === 'function';
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Verify email transport connection
|
|
237
|
+
*
|
|
238
|
+
* For SMTP: Tests actual connection
|
|
239
|
+
* For SES SDK: Attempts to send invalid test message to validate credentials
|
|
240
|
+
*
|
|
167
241
|
* @private
|
|
168
242
|
*/
|
|
169
243
|
async verifyConnection() {
|
|
170
244
|
try {
|
|
171
|
-
this.logger?.debug?.('Verifying
|
|
172
|
-
|
|
173
|
-
this.
|
|
245
|
+
this.logger?.debug?.('Verifying email transport connection...');
|
|
246
|
+
// Check if transporter supports verify (all standard transports do)
|
|
247
|
+
if (typeof this.transporter.verify === 'function') {
|
|
248
|
+
await this.transporter.verify();
|
|
249
|
+
this.logger?.log?.('Nodemailer connection verified successfully');
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
this.logger?.debug?.('Transporter does not support verify(), skipping verification');
|
|
253
|
+
}
|
|
174
254
|
}
|
|
175
255
|
catch (error) {
|
|
176
|
-
this.logger?.error?.('Nodemailer connection failed');
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
256
|
+
this.logger?.error?.('Nodemailer connection verification failed');
|
|
257
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
258
|
+
this.logger?.error?.(`Error details: ${errorMessage}`);
|
|
259
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
260
|
+
this.logger?.error?.(`Error code: ${String(error.code)}`);
|
|
180
261
|
}
|
|
181
|
-
if (error
|
|
182
|
-
this.logger?.error?.(`Failed at command: ${error.command}`);
|
|
262
|
+
if (error && typeof error === 'object' && 'command' in error) {
|
|
263
|
+
this.logger?.error?.(`Failed at command: ${String(error.command)}`);
|
|
183
264
|
}
|
|
184
265
|
// Log full error for debugging
|
|
185
266
|
this.logger?.debug?.('Full error object:', error);
|
|
267
|
+
// Don't throw - allow provider to be used even if verification fails
|
|
268
|
+
// Verification is best-effort and shouldn't block initialization
|
|
186
269
|
}
|
|
187
270
|
}
|
|
188
271
|
/**
|
|
@@ -286,7 +369,7 @@ class NodemailerProvider {
|
|
|
286
369
|
* Send new device login notification
|
|
287
370
|
*
|
|
288
371
|
* @param to - Recipient email address
|
|
289
|
-
* @param deviceInfo - Device information
|
|
372
|
+
* @param deviceInfo - Device information object with optional properties: name, type, ipAddress, location
|
|
290
373
|
*/
|
|
291
374
|
async sendNewDeviceEmail(to, deviceInfo, variables = {}) {
|
|
292
375
|
const templateVariables = {
|
|
@@ -341,9 +424,10 @@ class NodemailerProvider {
|
|
|
341
424
|
catch (error) {
|
|
342
425
|
this.logger?.error?.('Failed to send email');
|
|
343
426
|
this.logger?.error?.(`To: ${mailOptions.to}`);
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
427
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
428
|
+
this.logger?.error?.(`Error: ${errorMessage}`);
|
|
429
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
430
|
+
this.logger?.error?.(`Error code: ${String(error.code)}`);
|
|
347
431
|
}
|
|
348
432
|
this.logger?.debug?.('Full error object:', error);
|
|
349
433
|
throw error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodemailer-email.provider.js","sourceRoot":"","sources":["../src/nodemailer-email.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"nodemailer-email.provider.js","sourceRoot":"","sources":["../src/nodemailer-email.provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAA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I,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,EAAE,CAAC;gBAC1D,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,eAAe,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC5D,CAAC;YACD,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;YAClD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,+BAA+B,CAAC,CAAC;IACtD,CAAC;CACF;AAhWD,gDAgWC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nauth-toolkit/email-nodemailer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"description": "Nodemailer email provider for nauth-toolkit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"nodemailer": "^7.0.11"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@nauth-toolkit/core": "^0.1.
|
|
29
|
+
"@nauth-toolkit/core": "^0.1.23"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/handlebars": "^4.1.0",
|