@breadstone/archipel-platform-mailing 0.0.20 → 0.0.22
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/README.md +24 -0
- package/package.json +31 -6
- package/src/errors/MailDeliveryError.d.ts +10 -0
- package/src/errors/MailDeliveryError.js +21 -0
- package/src/errors/index.d.ts +1 -0
- package/src/errors/index.js +6 -0
- package/src/index.d.ts +2 -5
- package/src/index.js +2 -5
- package/src/logger/index.d.ts +1 -0
- package/src/logger/index.js +6 -0
- package/src/services/strategies/MailgunDeliveryStrategy.js +3 -2
- package/src/services/strategies/PostmarkDeliveryStrategy.js +3 -2
- package/src/services/strategies/ResendDeliveryStrategy.js +3 -2
- package/src/services/strategies/SendGridDeliveryStrategy.js +3 -2
- package/src/services/strategies/SmtpDeliveryStrategy.js +3 -2
- package/src/smtp/env.d.ts +13 -0
- package/src/smtp/env.js +31 -0
- package/src/smtp/index.d.ts +2 -0
- package/src/smtp/index.js +13 -0
- package/src/templating/strategies/FileTemplateFetchStrategy.d.ts +1 -1
- package/src/templating/strategies/FileTemplateFetchStrategy.js +2 -2
- package/src/terminus/MailHealthIndicator.d.ts +1 -1
- package/src/{MailModule.js → tokens/MailModule.js} +23 -21
- /package/src/{MailModule.d.ts → tokens/MailModule.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -73,6 +73,30 @@ Set `MAIL_DELIVERY_STRATEGY` to one of: `smtp`, `postmark`, `resend`, `sendgrid`
|
|
|
73
73
|
- **Attachment support**: Send file attachments with MIME-type validation and size limits (25 MB max)
|
|
74
74
|
- **Header injection prevention**: Subject lines are automatically sanitized against SMTP header injection
|
|
75
75
|
|
|
76
|
+
## Error Handling
|
|
77
|
+
|
|
78
|
+
All delivery strategies throw a `MailDeliveryError` when email sending fails. This domain error wraps the underlying provider error and exposes structured metadata:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { MailDeliveryError } from '@breadstone/archipel-platform-mailing';
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
await mailService.send(options, content, true);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof MailDeliveryError) {
|
|
87
|
+
console.error(error.provider); // 'postmark', 'smtp', 'resend', etc.
|
|
88
|
+
console.error(error.code); // 'MAIL_DELIVERY'
|
|
89
|
+
console.error(error.cause); // Original provider SDK error
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
| Property | Type | Description |
|
|
95
|
+
| ---------- | --------- | ----------------------------------------------- |
|
|
96
|
+
| `code` | `string` | Always `'MAIL_DELIVERY'` |
|
|
97
|
+
| `provider` | `string` | Provider that failed (`smtp`, `postmark`, etc.) |
|
|
98
|
+
| `cause` | `unknown` | Original error from the provider SDK |
|
|
99
|
+
|
|
76
100
|
## Available Providers
|
|
77
101
|
|
|
78
102
|
| Subpath | Class | SDK |
|
package/package.json
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breadstone/archipel-platform-mailing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "Email delivery with strategy-based transport and template engines for NestJS applications.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
8
8
|
"typesVersions": {
|
|
9
9
|
"*": {
|
|
10
|
+
"log": [
|
|
11
|
+
"./src/log/index.d.ts"
|
|
12
|
+
],
|
|
13
|
+
"smtp": [
|
|
14
|
+
"./src/smtp/index.d.ts"
|
|
15
|
+
],
|
|
10
16
|
"mailgun": [
|
|
11
17
|
"./src/mailgun/index.d.ts"
|
|
12
18
|
],
|
|
@@ -26,6 +32,14 @@
|
|
|
26
32
|
"types": "./src/index.d.ts",
|
|
27
33
|
"default": "./src/index.js"
|
|
28
34
|
},
|
|
35
|
+
"./log": {
|
|
36
|
+
"types": "./src/log/index.d.ts",
|
|
37
|
+
"default": "./src/log/index.js"
|
|
38
|
+
},
|
|
39
|
+
"./smtp": {
|
|
40
|
+
"types": "./src/smtp/index.d.ts",
|
|
41
|
+
"default": "./src/smtp/index.js"
|
|
42
|
+
},
|
|
29
43
|
"./mailgun": {
|
|
30
44
|
"types": "./src/mailgun/index.d.ts",
|
|
31
45
|
"default": "./src/mailgun/index.js"
|
|
@@ -43,6 +57,7 @@
|
|
|
43
57
|
"default": "./src/sendgrid/index.js"
|
|
44
58
|
},
|
|
45
59
|
"./package.json": "./package.json",
|
|
60
|
+
"./smtp/index": "./src/smtp/index.js",
|
|
46
61
|
"./postmark/index": "./src/postmark/index.js",
|
|
47
62
|
"./resend/index": "./src/resend/index.js",
|
|
48
63
|
"./sendgrid/index": "./src/sendgrid/index.js",
|
|
@@ -58,6 +73,7 @@
|
|
|
58
73
|
"nestjs",
|
|
59
74
|
"email",
|
|
60
75
|
"mailing",
|
|
76
|
+
"log",
|
|
61
77
|
"smtp",
|
|
62
78
|
"postmark",
|
|
63
79
|
"resend",
|
|
@@ -75,18 +91,20 @@
|
|
|
75
91
|
"README.md"
|
|
76
92
|
],
|
|
77
93
|
"dependencies": {
|
|
78
|
-
"@breadstone/archipel-platform-blob-storage": "0.0.
|
|
79
|
-
"@breadstone/archipel-platform-configuration": "0.0.
|
|
80
|
-
"@breadstone/archipel-platform-core": "0.0.
|
|
81
|
-
"
|
|
82
|
-
"
|
|
94
|
+
"@breadstone/archipel-platform-blob-storage": "0.0.22",
|
|
95
|
+
"@breadstone/archipel-platform-configuration": "0.0.22",
|
|
96
|
+
"@breadstone/archipel-platform-core": "0.0.22",
|
|
97
|
+
"@breadstone/archipel-platform-health": "0.0.22",
|
|
98
|
+
"@breadstone/archipel-platform-resources": "0.0.22",
|
|
83
99
|
"tslib": "2.8.1"
|
|
84
100
|
},
|
|
85
101
|
"peerDependencies": {
|
|
86
102
|
"@nestjs/common": ">=11.0.0",
|
|
87
103
|
"@nestjs/terminus": ">=11.0.0",
|
|
88
104
|
"@sendgrid/mail": ">=8.0.0",
|
|
105
|
+
"form-data": ">=4.0.0",
|
|
89
106
|
"mailgun.js": ">=10.0.0",
|
|
107
|
+
"nodemailer": ">=8.0.0",
|
|
90
108
|
"postmark": ">=4.0.0",
|
|
91
109
|
"resend": ">=4.0.0",
|
|
92
110
|
"rxjs": ">=7.0.0"
|
|
@@ -95,9 +113,15 @@
|
|
|
95
113
|
"@sendgrid/mail": {
|
|
96
114
|
"optional": true
|
|
97
115
|
},
|
|
116
|
+
"form-data": {
|
|
117
|
+
"optional": true
|
|
118
|
+
},
|
|
98
119
|
"mailgun.js": {
|
|
99
120
|
"optional": true
|
|
100
121
|
},
|
|
122
|
+
"nodemailer": {
|
|
123
|
+
"optional": true
|
|
124
|
+
},
|
|
101
125
|
"postmark": {
|
|
102
126
|
"optional": true
|
|
103
127
|
},
|
|
@@ -111,6 +135,7 @@
|
|
|
111
135
|
"@sendgrid/mail": "8.1.6",
|
|
112
136
|
"form-data": "4.0.5",
|
|
113
137
|
"mailgun.js": "13.0.0",
|
|
138
|
+
"nodemailer": "8.0.5",
|
|
114
139
|
"postmark": "4.0.7",
|
|
115
140
|
"resend": "6.12.2",
|
|
116
141
|
"rxjs": "7.8.2",
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain error thrown when email delivery fails.
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export declare class MailDeliveryError extends Error {
|
|
7
|
+
readonly code = "MAIL_DELIVERY";
|
|
8
|
+
readonly provider: string;
|
|
9
|
+
constructor(provider: string, message: string, cause?: unknown);
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MailDeliveryError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Domain error thrown when email delivery fails.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
class MailDeliveryError extends Error {
|
|
10
|
+
// #endregion
|
|
11
|
+
// #region Ctor
|
|
12
|
+
constructor(provider, message, cause) {
|
|
13
|
+
super(message, { cause });
|
|
14
|
+
// #region Fields
|
|
15
|
+
this.code = 'MAIL_DELIVERY';
|
|
16
|
+
this.name = 'MailDeliveryError';
|
|
17
|
+
this.provider = provider;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.MailDeliveryError = MailDeliveryError;
|
|
21
|
+
//# sourceMappingURL=MailDeliveryError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MailDeliveryError } from './MailDeliveryError';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MailDeliveryError = void 0;
|
|
4
|
+
var MailDeliveryError_1 = require("./MailDeliveryError");
|
|
5
|
+
Object.defineProperty(exports, "MailDeliveryError", { enumerable: true, get: function () { return MailDeliveryError_1.MailDeliveryError; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
export * from './env';
|
|
2
|
+
export * from './errors/MailDeliveryError';
|
|
2
3
|
export * from './events';
|
|
3
|
-
export * from './MailModule';
|
|
4
4
|
export * from './MailTokens';
|
|
5
5
|
export * from './models/IMailAttachment';
|
|
6
6
|
export * from './services/MailService';
|
|
7
7
|
export * from './services/MailVerificationService';
|
|
8
8
|
export * from './services/strategies/abstracts/DeliveryStrategyBase';
|
|
9
|
-
export * from './services/strategies/LogDeliveryStrategy';
|
|
10
|
-
export * from './services/strategies/SmtpDeliveryStrategy';
|
|
11
9
|
export * from './templating/MailTemplateEngine';
|
|
12
10
|
export * from './templating/strategies/abstracts/TemplateFetchStrategyBase';
|
|
13
|
-
export * from './templating/strategies/BlobTemplateFetchStrategy';
|
|
14
|
-
export * from './templating/strategies/FileTemplateFetchStrategy';
|
|
15
11
|
export * from './terminus/MailHealthIndicator';
|
|
12
|
+
export * from './tokens/MailModule';
|
package/src/index.js
CHANGED
|
@@ -2,18 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./env"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./errors/MailDeliveryError"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./events"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./MailModule"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./MailTokens"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./models/IMailAttachment"), exports);
|
|
9
9
|
tslib_1.__exportStar(require("./services/MailService"), exports);
|
|
10
10
|
tslib_1.__exportStar(require("./services/MailVerificationService"), exports);
|
|
11
11
|
tslib_1.__exportStar(require("./services/strategies/abstracts/DeliveryStrategyBase"), exports);
|
|
12
|
-
tslib_1.__exportStar(require("./services/strategies/LogDeliveryStrategy"), exports);
|
|
13
|
-
tslib_1.__exportStar(require("./services/strategies/SmtpDeliveryStrategy"), exports);
|
|
14
12
|
tslib_1.__exportStar(require("./templating/MailTemplateEngine"), exports);
|
|
15
13
|
tslib_1.__exportStar(require("./templating/strategies/abstracts/TemplateFetchStrategyBase"), exports);
|
|
16
|
-
tslib_1.__exportStar(require("./templating/strategies/BlobTemplateFetchStrategy"), exports);
|
|
17
|
-
tslib_1.__exportStar(require("./templating/strategies/FileTemplateFetchStrategy"), exports);
|
|
18
14
|
tslib_1.__exportStar(require("./terminus/MailHealthIndicator"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./tokens/MailModule"), exports);
|
|
19
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { LogDeliveryStrategy } from '../services/strategies/LogDeliveryStrategy';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LogDeliveryStrategy = void 0;
|
|
4
|
+
var LogDeliveryStrategy_1 = require("../services/strategies/LogDeliveryStrategy");
|
|
5
|
+
Object.defineProperty(exports, "LogDeliveryStrategy", { enumerable: true, get: function () { return LogDeliveryStrategy_1.LogDeliveryStrategy; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -7,6 +7,7 @@ const common_1 = require("@nestjs/common");
|
|
|
7
7
|
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
8
8
|
const mailgun_js_1 = tslib_1.__importDefault(require("mailgun.js"));
|
|
9
9
|
const env_1 = require("../../env");
|
|
10
|
+
const MailDeliveryError_1 = require("../../errors/MailDeliveryError");
|
|
10
11
|
const DeliveryStrategyBase_1 = require("./abstracts/DeliveryStrategyBase");
|
|
11
12
|
// #endregion
|
|
12
13
|
/**
|
|
@@ -54,14 +55,14 @@ class MailgunDeliveryStrategy extends DeliveryStrategyBase_1.DeliveryStrategyBas
|
|
|
54
55
|
...(isHtml ? { html: content } : { text: content }),
|
|
55
56
|
});
|
|
56
57
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
57
|
-
setTimeout(() => reject(new Error('Mailgun send timed out after
|
|
58
|
+
setTimeout(() => reject(new Error('Mailgun send timed out after 5000ms')), 5_000);
|
|
58
59
|
});
|
|
59
60
|
await Promise.race([sendPromise, timeoutPromise]);
|
|
60
61
|
this._logger.log('Email sent successfully', 'Mail');
|
|
61
62
|
}
|
|
62
63
|
catch (error) {
|
|
63
64
|
this._logger.error('Error sending email:', error);
|
|
64
|
-
throw error;
|
|
65
|
+
throw new MailDeliveryError_1.MailDeliveryError('mailgun', 'Failed to send email via Mailgun', error);
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -5,6 +5,7 @@ exports.PostmarkDeliveryStrategy = void 0;
|
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const postmark_1 = require("postmark");
|
|
7
7
|
const env_1 = require("../../env");
|
|
8
|
+
const MailDeliveryError_1 = require("../../errors/MailDeliveryError");
|
|
8
9
|
const DeliveryStrategyBase_1 = require("./abstracts/DeliveryStrategyBase");
|
|
9
10
|
// #endregion
|
|
10
11
|
/**
|
|
@@ -47,14 +48,14 @@ class PostmarkDeliveryStrategy extends DeliveryStrategyBase_1.DeliveryStrategyBa
|
|
|
47
48
|
...(isHtml ? { HtmlBody: content } : { TextBody: content }),
|
|
48
49
|
});
|
|
49
50
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
50
|
-
setTimeout(() => reject(new Error('Postmark send timed out after
|
|
51
|
+
setTimeout(() => reject(new Error('Postmark send timed out after 5000ms')), 5_000);
|
|
51
52
|
});
|
|
52
53
|
await Promise.race([sendPromise, timeoutPromise]);
|
|
53
54
|
this._logger.log('Email sent successfully', 'Mail');
|
|
54
55
|
}
|
|
55
56
|
catch (error) {
|
|
56
57
|
this._logger.error('Error sending email:', error);
|
|
57
|
-
throw error;
|
|
58
|
+
throw new MailDeliveryError_1.MailDeliveryError('postmark', 'Failed to send email via Postmark', error);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -5,6 +5,7 @@ exports.ResendDeliveryStrategy = void 0;
|
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const resend_1 = require("resend");
|
|
7
7
|
const env_1 = require("../../env");
|
|
8
|
+
const MailDeliveryError_1 = require("../../errors/MailDeliveryError");
|
|
8
9
|
const DeliveryStrategyBase_1 = require("./abstracts/DeliveryStrategyBase");
|
|
9
10
|
// #endregion
|
|
10
11
|
/**
|
|
@@ -47,14 +48,14 @@ class ResendDeliveryStrategy extends DeliveryStrategyBase_1.DeliveryStrategyBase
|
|
|
47
48
|
...(isHtml ? { html: content } : { text: content }),
|
|
48
49
|
});
|
|
49
50
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
50
|
-
setTimeout(() => reject(new Error('Resend send timed out after
|
|
51
|
+
setTimeout(() => reject(new Error('Resend send timed out after 5000ms')), 5_000);
|
|
51
52
|
});
|
|
52
53
|
await Promise.race([sendPromise, timeoutPromise]);
|
|
53
54
|
this._logger.log('Email sent successfully', 'Mail');
|
|
54
55
|
}
|
|
55
56
|
catch (error) {
|
|
56
57
|
this._logger.error('Error sending email:', error);
|
|
57
|
-
throw error;
|
|
58
|
+
throw new MailDeliveryError_1.MailDeliveryError('resend', 'Failed to send email via Resend', error);
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -6,6 +6,7 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const common_1 = require("@nestjs/common");
|
|
7
7
|
const mail_1 = tslib_1.__importDefault(require("@sendgrid/mail"));
|
|
8
8
|
const env_1 = require("../../env");
|
|
9
|
+
const MailDeliveryError_1 = require("../../errors/MailDeliveryError");
|
|
9
10
|
const DeliveryStrategyBase_1 = require("./abstracts/DeliveryStrategyBase");
|
|
10
11
|
// #endregion
|
|
11
12
|
/**
|
|
@@ -48,14 +49,14 @@ class SendGridDeliveryStrategy extends DeliveryStrategyBase_1.DeliveryStrategyBa
|
|
|
48
49
|
...(isHtml ? { html: content } : { text: content }),
|
|
49
50
|
});
|
|
50
51
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
51
|
-
setTimeout(() => reject(new Error('SendGrid send timed out after
|
|
52
|
+
setTimeout(() => reject(new Error('SendGrid send timed out after 5000ms')), 5_000);
|
|
52
53
|
});
|
|
53
54
|
await Promise.race([sendPromise, timeoutPromise]);
|
|
54
55
|
this._logger.log('Email sent successfully', 'Mail');
|
|
55
56
|
}
|
|
56
57
|
catch (error) {
|
|
57
58
|
this._logger.error('Error sending email:', error);
|
|
58
|
-
throw error;
|
|
59
|
+
throw new MailDeliveryError_1.MailDeliveryError('sendgrid', 'Failed to send email via SendGrid', error);
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -5,6 +5,7 @@ exports.SmtpDeliveryStrategy = void 0;
|
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
6
|
const nodemailer_1 = require("nodemailer");
|
|
7
7
|
const env_1 = require("../../env");
|
|
8
|
+
const MailDeliveryError_1 = require("../../errors/MailDeliveryError");
|
|
8
9
|
const DeliveryStrategyBase_1 = require("./abstracts/DeliveryStrategyBase");
|
|
9
10
|
// #endregion
|
|
10
11
|
/**
|
|
@@ -56,14 +57,14 @@ class SmtpDeliveryStrategy extends DeliveryStrategyBase_1.DeliveryStrategyBase {
|
|
|
56
57
|
...(isHtml ? { html: content } : { text: content }),
|
|
57
58
|
});
|
|
58
59
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
59
|
-
setTimeout(() => reject(new Error('SMTP send timed out after
|
|
60
|
+
setTimeout(() => reject(new Error('SMTP send timed out after 5000ms')), 5_000);
|
|
60
61
|
});
|
|
61
62
|
await Promise.race([sendPromise, timeoutPromise]);
|
|
62
63
|
this._logger.log('Email sent successfully', 'Mail');
|
|
63
64
|
}
|
|
64
65
|
catch (error) {
|
|
65
66
|
this._logger.error('Error sending email:', error);
|
|
66
|
-
throw error;
|
|
67
|
+
throw new MailDeliveryError_1.MailDeliveryError('smtp', 'Failed to send email via SMTP', error);
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { IConfigRegistryEntry } from '@breadstone/archipel-platform-configuration';
|
|
2
|
+
/** SMTP server host. */
|
|
3
|
+
export declare const SMTP_HOST: import("@breadstone/archipel-platform-configuration").IConfigKey<string>;
|
|
4
|
+
/** SMTP server port. */
|
|
5
|
+
export declare const SMTP_PORT: import("@breadstone/archipel-platform-configuration").IConfigKey<number>;
|
|
6
|
+
/** Whether the SMTP connection uses TLS. */
|
|
7
|
+
export declare const SMTP_SECURE: import("@breadstone/archipel-platform-configuration").IConfigKey<boolean>;
|
|
8
|
+
/** SMTP authentication username. */
|
|
9
|
+
export declare const SMTP_USER: import("@breadstone/archipel-platform-configuration").IConfigKey<string>;
|
|
10
|
+
/** SMTP authentication password. */
|
|
11
|
+
export declare const SMTP_PASSWORD: import("@breadstone/archipel-platform-configuration").IConfigKey<string>;
|
|
12
|
+
/** Configuration entries required by the SMTP delivery provider. */
|
|
13
|
+
export declare const SMTP_CONFIG_ENTRIES: ReadonlyArray<Omit<IConfigRegistryEntry, 'module'>>;
|
package/src/smtp/env.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// #region Imports
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SMTP_CONFIG_ENTRIES = exports.SMTP_PASSWORD = exports.SMTP_USER = exports.SMTP_SECURE = exports.SMTP_PORT = exports.SMTP_HOST = void 0;
|
|
5
|
+
const archipel_platform_configuration_1 = require("@breadstone/archipel-platform-configuration");
|
|
6
|
+
// #endregion
|
|
7
|
+
// ──────────────────────────────────────────────────────────────
|
|
8
|
+
// SMTP
|
|
9
|
+
// ──────────────────────────────────────────────────────────────
|
|
10
|
+
/** SMTP server host. */
|
|
11
|
+
exports.SMTP_HOST = (0, archipel_platform_configuration_1.createConfigKey)('MAIL_SMTP_HOST');
|
|
12
|
+
/** SMTP server port. */
|
|
13
|
+
exports.SMTP_PORT = (0, archipel_platform_configuration_1.createConfigKey)('MAIL_SMTP_PORT');
|
|
14
|
+
/** Whether the SMTP connection uses TLS. */
|
|
15
|
+
exports.SMTP_SECURE = (0, archipel_platform_configuration_1.createConfigKey)('MAIL_SMTP_SECURE');
|
|
16
|
+
/** SMTP authentication username. */
|
|
17
|
+
exports.SMTP_USER = (0, archipel_platform_configuration_1.createConfigKey)('MAIL_SMTP_USER');
|
|
18
|
+
/** SMTP authentication password. */
|
|
19
|
+
exports.SMTP_PASSWORD = (0, archipel_platform_configuration_1.createConfigKey)('MAIL_SMTP_PASSWORD');
|
|
20
|
+
// ──────────────────────────────────────────────────────────────
|
|
21
|
+
// Registry entries
|
|
22
|
+
// ──────────────────────────────────────────────────────────────
|
|
23
|
+
/** Configuration entries required by the SMTP delivery provider. */
|
|
24
|
+
exports.SMTP_CONFIG_ENTRIES = [
|
|
25
|
+
{ key: exports.SMTP_HOST, required: true, defaultValue: 'localhost', description: 'SMTP server host.' },
|
|
26
|
+
{ key: exports.SMTP_PORT, required: true, defaultValue: 587, description: 'SMTP server port.' },
|
|
27
|
+
{ key: exports.SMTP_SECURE, required: false, defaultValue: true, description: 'Whether SMTP uses TLS.' },
|
|
28
|
+
{ key: exports.SMTP_USER, required: false, defaultValue: '', description: 'SMTP authentication username.' },
|
|
29
|
+
{ key: exports.SMTP_PASSWORD, required: false, defaultValue: '', description: 'SMTP authentication password.' },
|
|
30
|
+
];
|
|
31
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SMTP_USER = exports.SMTP_SECURE = exports.SMTP_PORT = exports.SMTP_PASSWORD = exports.SMTP_HOST = exports.SMTP_CONFIG_ENTRIES = exports.SmtpDeliveryStrategy = void 0;
|
|
4
|
+
var SmtpDeliveryStrategy_1 = require("../services/strategies/SmtpDeliveryStrategy");
|
|
5
|
+
Object.defineProperty(exports, "SmtpDeliveryStrategy", { enumerable: true, get: function () { return SmtpDeliveryStrategy_1.SmtpDeliveryStrategy; } });
|
|
6
|
+
var env_1 = require("./env");
|
|
7
|
+
Object.defineProperty(exports, "SMTP_CONFIG_ENTRIES", { enumerable: true, get: function () { return env_1.SMTP_CONFIG_ENTRIES; } });
|
|
8
|
+
Object.defineProperty(exports, "SMTP_HOST", { enumerable: true, get: function () { return env_1.SMTP_HOST; } });
|
|
9
|
+
Object.defineProperty(exports, "SMTP_PASSWORD", { enumerable: true, get: function () { return env_1.SMTP_PASSWORD; } });
|
|
10
|
+
Object.defineProperty(exports, "SMTP_PORT", { enumerable: true, get: function () { return env_1.SMTP_PORT; } });
|
|
11
|
+
Object.defineProperty(exports, "SMTP_SECURE", { enumerable: true, get: function () { return env_1.SMTP_SECURE; } });
|
|
12
|
+
Object.defineProperty(exports, "SMTP_USER", { enumerable: true, get: function () { return env_1.SMTP_USER; } });
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ResourceManager } from '@breadstone/archipel-platform-
|
|
1
|
+
import { ResourceManager } from '@breadstone/archipel-platform-resources';
|
|
2
2
|
import { TemplateFetchStrategyBase } from './abstracts/TemplateFetchStrategyBase';
|
|
3
3
|
import { IMailTemplateVariants } from '../../MailTokens';
|
|
4
4
|
/**
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.FileTemplateFetchStrategy = void 0;
|
|
6
6
|
const tslib_1 = require("tslib");
|
|
7
7
|
const common_1 = require("@nestjs/common");
|
|
8
|
-
const
|
|
8
|
+
const archipel_platform_resources_1 = require("@breadstone/archipel-platform-resources");
|
|
9
9
|
const TemplateFetchStrategyBase_1 = require("./abstracts/TemplateFetchStrategyBase");
|
|
10
10
|
// #endregion
|
|
11
11
|
/**
|
|
@@ -66,6 +66,6 @@ let FileTemplateFetchStrategy = FileTemplateFetchStrategy_1 = class FileTemplate
|
|
|
66
66
|
exports.FileTemplateFetchStrategy = FileTemplateFetchStrategy;
|
|
67
67
|
exports.FileTemplateFetchStrategy = FileTemplateFetchStrategy = FileTemplateFetchStrategy_1 = tslib_1.__decorate([
|
|
68
68
|
(0, common_1.Injectable)(),
|
|
69
|
-
tslib_1.__metadata("design:paramtypes", [
|
|
69
|
+
tslib_1.__metadata("design:paramtypes", [archipel_platform_resources_1.ResourceManager])
|
|
70
70
|
], FileTemplateFetchStrategy);
|
|
71
71
|
//# sourceMappingURL=FileTemplateFetchStrategy.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ConfigService } from '@breadstone/archipel-platform-configuration';
|
|
2
|
-
import { IHealthIndicator } from '@breadstone/archipel-platform-
|
|
2
|
+
import { IHealthIndicator } from '@breadstone/archipel-platform-health';
|
|
3
3
|
import { HealthIndicatorResult } from '@nestjs/terminus';
|
|
4
4
|
/**
|
|
5
5
|
* Health indicator for mail service.
|
|
@@ -6,16 +6,16 @@ const tslib_1 = require("tslib");
|
|
|
6
6
|
const archipel_platform_blob_storage_1 = require("@breadstone/archipel-platform-blob-storage");
|
|
7
7
|
const archipel_platform_configuration_1 = require("@breadstone/archipel-platform-configuration");
|
|
8
8
|
const archipel_platform_core_1 = require("@breadstone/archipel-platform-core");
|
|
9
|
+
const archipel_platform_health_1 = require("@breadstone/archipel-platform-health");
|
|
10
|
+
const archipel_platform_resources_1 = require("@breadstone/archipel-platform-resources");
|
|
9
11
|
const common_1 = require("@nestjs/common");
|
|
10
|
-
const env_1 = require("
|
|
11
|
-
const MailEventSubscriber_1 = require("
|
|
12
|
-
const MailTokens_1 = require("
|
|
13
|
-
const MailService_1 = require("
|
|
14
|
-
const MailVerificationService_1 = require("
|
|
15
|
-
const MailTemplateEngine_1 = require("
|
|
16
|
-
const
|
|
17
|
-
const FileTemplateFetchStrategy_1 = require("./templating/strategies/FileTemplateFetchStrategy");
|
|
18
|
-
const MailHealthIndicator_1 = require("./terminus/MailHealthIndicator");
|
|
12
|
+
const env_1 = require("../env");
|
|
13
|
+
const MailEventSubscriber_1 = require("../events/listeners/MailEventSubscriber");
|
|
14
|
+
const MailTokens_1 = require("../MailTokens");
|
|
15
|
+
const MailService_1 = require("../services/MailService");
|
|
16
|
+
const MailVerificationService_1 = require("../services/MailVerificationService");
|
|
17
|
+
const MailTemplateEngine_1 = require("../templating/MailTemplateEngine");
|
|
18
|
+
const MailHealthIndicator_1 = require("../terminus/MailHealthIndicator");
|
|
19
19
|
// #endregion
|
|
20
20
|
/**
|
|
21
21
|
* Represents the mail module.
|
|
@@ -32,49 +32,51 @@ exports.MailModule = MailModule = tslib_1.__decorate([
|
|
|
32
32
|
archipel_platform_configuration_1.ConfigModule.register('platform-mailing', env_1.PLATFORM_MAILING_CONFIG_ENTRIES),
|
|
33
33
|
archipel_platform_blob_storage_1.BlobModule,
|
|
34
34
|
archipel_platform_core_1.EventModule,
|
|
35
|
-
|
|
35
|
+
archipel_platform_health_1.HealthModule,
|
|
36
36
|
],
|
|
37
37
|
providers: [
|
|
38
38
|
{
|
|
39
39
|
provide: MailTokens_1.MAIL_TEMPLATE_FETCH_STRATEGY_TOKEN,
|
|
40
|
-
useFactory: (configService, blobService, resourceManager) => {
|
|
40
|
+
useFactory: async (configService, blobService, resourceManager) => {
|
|
41
41
|
const templateStrategy = configService.get(env_1.MAIL_TEMPLATE_STRATEGY.key);
|
|
42
42
|
if (templateStrategy === 'file') {
|
|
43
|
-
|
|
43
|
+
const { FileTemplateFetchStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../templating/strategies/FileTemplateFetchStrategy')));
|
|
44
|
+
return new FileTemplateFetchStrategy(resourceManager);
|
|
44
45
|
}
|
|
45
46
|
if (templateStrategy === 'blob') {
|
|
46
|
-
|
|
47
|
+
const { BlobTemplateFetchStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../templating/strategies/BlobTemplateFetchStrategy')));
|
|
48
|
+
return new BlobTemplateFetchStrategy(blobService);
|
|
47
49
|
}
|
|
48
50
|
throw new Error(`Unknown template strategy: ${templateStrategy}`);
|
|
49
51
|
},
|
|
50
|
-
inject: [archipel_platform_configuration_1.ConfigService, archipel_platform_blob_storage_1.BlobService,
|
|
52
|
+
inject: [archipel_platform_configuration_1.ConfigService, archipel_platform_blob_storage_1.BlobService, archipel_platform_resources_1.ResourceManager],
|
|
51
53
|
},
|
|
52
54
|
{
|
|
53
55
|
provide: MailTokens_1.MAIL_DELIVERY_STRATEGY_TOKEN,
|
|
54
56
|
useFactory: async (configService) => {
|
|
55
57
|
const deliveryStrategy = configService.get(env_1.MAIL_DELIVERY_STRATEGY.key);
|
|
56
58
|
if (deliveryStrategy === 'log') {
|
|
57
|
-
const { LogDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('
|
|
59
|
+
const { LogDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../services/strategies/LogDeliveryStrategy')));
|
|
58
60
|
return new LogDeliveryStrategy();
|
|
59
61
|
}
|
|
60
62
|
if (deliveryStrategy === 'smtp') {
|
|
61
|
-
const { SmtpDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('
|
|
63
|
+
const { SmtpDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../services/strategies/SmtpDeliveryStrategy')));
|
|
62
64
|
return new SmtpDeliveryStrategy(configService);
|
|
63
65
|
}
|
|
64
66
|
if (deliveryStrategy === 'postmark') {
|
|
65
|
-
const { PostmarkDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('
|
|
67
|
+
const { PostmarkDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../services/strategies/PostmarkDeliveryStrategy')));
|
|
66
68
|
return new PostmarkDeliveryStrategy(configService);
|
|
67
69
|
}
|
|
68
70
|
if (deliveryStrategy === 'resend') {
|
|
69
|
-
const { ResendDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('
|
|
71
|
+
const { ResendDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../services/strategies/ResendDeliveryStrategy')));
|
|
70
72
|
return new ResendDeliveryStrategy(configService);
|
|
71
73
|
}
|
|
72
74
|
if (deliveryStrategy === 'sendgrid') {
|
|
73
|
-
const { SendGridDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('
|
|
75
|
+
const { SendGridDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../services/strategies/SendGridDeliveryStrategy')));
|
|
74
76
|
return new SendGridDeliveryStrategy(configService);
|
|
75
77
|
}
|
|
76
78
|
if (deliveryStrategy === 'mailgun') {
|
|
77
|
-
const { MailgunDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('
|
|
79
|
+
const { MailgunDeliveryStrategy } = await Promise.resolve().then(() => tslib_1.__importStar(require('../services/strategies/MailgunDeliveryStrategy')));
|
|
78
80
|
return new MailgunDeliveryStrategy(configService);
|
|
79
81
|
}
|
|
80
82
|
throw new Error(`Unknown delivery strategy: ${deliveryStrategy}`);
|
|
@@ -93,7 +95,7 @@ exports.MailModule = MailModule = tslib_1.__decorate([
|
|
|
93
95
|
orchestrator.registerIndicator(indicator);
|
|
94
96
|
return true;
|
|
95
97
|
},
|
|
96
|
-
inject: [
|
|
98
|
+
inject: [archipel_platform_health_1.HealthOrchestrator, MailHealthIndicator_1.MailHealthIndicator],
|
|
97
99
|
},
|
|
98
100
|
],
|
|
99
101
|
exports: [MailService_1.MailService, MailVerificationService_1.MailVerificationService, MailHealthIndicator_1.MailHealthIndicator],
|
|
File without changes
|