@brilab-mailer/provider-mailtrap 0.0.1-beta.47
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 +69 -0
- package/index.d.ts +2 -0
- package/index.d.ts.map +1 -0
- package/index.js +1 -0
- package/lib/mailtrap-api.provider.d.ts +12 -0
- package/lib/mailtrap-api.provider.d.ts.map +1 -0
- package/lib/mailtrap-api.provider.js +50 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @brilab-mailer/provider-mailtrap
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
A production-ready Mailtrap email provider for Brilab Mailer.
|
|
5
|
+
Supports both API and SMTP versions (API mode recommended).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Configuration
|
|
10
|
+
|
|
11
|
+
### Environment Variables
|
|
12
|
+
```
|
|
13
|
+
MAILTRAP_API_TOKEN=xxxx
|
|
14
|
+
MAILTRAP_INBOX_ID=12345
|
|
15
|
+
MAILTRAP_SENDER=no-reply@example.com
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @brilab-mailer/provider-mailtrap
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
MailerModule.register({
|
|
32
|
+
providerClass: MailtrapApiProvider,
|
|
33
|
+
templateEngineClass: HandlebarsTemplateEngine,
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Provider Implementation
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
@Injectable()
|
|
43
|
+
export class MailtrapApiProvider implements MailerProvider {
|
|
44
|
+
async send(options: MailerSendOptions) {
|
|
45
|
+
await this.client.send({
|
|
46
|
+
from: { email: this.sender },
|
|
47
|
+
to: [{ email: options.to }],
|
|
48
|
+
subject: options.subject,
|
|
49
|
+
html: options.html,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Debugging
|
|
58
|
+
|
|
59
|
+
- Invalid token → 401
|
|
60
|
+
- Invalid inbox → 404
|
|
61
|
+
- Rate limit → auto-retry recommended in mailer-core
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Best Practices
|
|
66
|
+
- Use per-environment inbox IDs
|
|
67
|
+
- Never store token in repository
|
|
68
|
+
- Use template engine instead of raw HTML
|
|
69
|
+
|
package/index.d.ts
ADDED
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC"}
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/mailtrap-api.provider.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MailtrapClient, type MailtrapClientConfig } from 'mailtrap';
|
|
2
|
+
import { MailerProvider, type MailerMessagesResolved } from '@brilab-mailer/contracts';
|
|
3
|
+
import { Mail } from "mailtrap/dist/types/mailtrap.js";
|
|
4
|
+
export declare class MailtrapApiProvider implements MailerProvider<MailtrapClientConfig, MailtrapClient, Mail> {
|
|
5
|
+
private readonly options;
|
|
6
|
+
private _client;
|
|
7
|
+
constructor(options: MailtrapClientConfig);
|
|
8
|
+
getClient(): MailtrapClient;
|
|
9
|
+
createPayload(resolved: MailerMessagesResolved): Mail;
|
|
10
|
+
send(payload: Mail): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=mailtrap-api.provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mailtrap-api.provider.d.ts","sourceRoot":"","sources":["../../src/lib/mailtrap-api.provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EACN,cAAc,EAEd,KAAK,sBAAsB,EAC3B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAEvD,qBACa,mBAAoB,YAAW,cAAc,CAAC,oBAAoB,EAAE,cAAc,EAAE,IAAI,CAAC;IAKpG,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJzB,OAAO,CAAC,OAAO,CAAiB;gBAId,OAAO,EAAE,oBAAoB;IAYxC,SAAS,IAAI,cAAc;IAI3B,aAAa,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAqB/C,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAG/C"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { Inject, Injectable } from '@nestjs/common';
|
|
3
|
+
import { MailtrapClient } from 'mailtrap';
|
|
4
|
+
import { MAILER_PROVIDER_OPTIONS, } from '@brilab-mailer/contracts';
|
|
5
|
+
let MailtrapApiProvider = class MailtrapApiProvider {
|
|
6
|
+
options;
|
|
7
|
+
_client;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.options = options;
|
|
10
|
+
const token = this.options?.token;
|
|
11
|
+
if (!token)
|
|
12
|
+
throw new Error('[MailtrapApiProvider] mailtrap token is not set');
|
|
13
|
+
this._client = new MailtrapClient({
|
|
14
|
+
token,
|
|
15
|
+
testInboxId: this.options?.testInboxId,
|
|
16
|
+
accountId: this.options?.accountId
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
getClient() {
|
|
20
|
+
return this._client;
|
|
21
|
+
}
|
|
22
|
+
createPayload(resolved) {
|
|
23
|
+
const base = {
|
|
24
|
+
from: resolved.from,
|
|
25
|
+
to: resolved.to,
|
|
26
|
+
subject: resolved.subject || '',
|
|
27
|
+
};
|
|
28
|
+
switch (resolved.content.kind) {
|
|
29
|
+
case 'text': return { ...base, text: resolved.content.text };
|
|
30
|
+
case 'html': return { ...base, html: resolved.content.html };
|
|
31
|
+
case 'mixed':
|
|
32
|
+
return {
|
|
33
|
+
...base,
|
|
34
|
+
text: resolved.content.text || '',
|
|
35
|
+
html: resolved.content.html || ''
|
|
36
|
+
};
|
|
37
|
+
default:
|
|
38
|
+
return { ...base, text: '', html: '' };
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async send(payload) {
|
|
42
|
+
await this._client.testing.send(payload);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
MailtrapApiProvider = __decorate([
|
|
46
|
+
Injectable(),
|
|
47
|
+
__param(0, Inject(MAILER_PROVIDER_OPTIONS)),
|
|
48
|
+
__metadata("design:paramtypes", [Object])
|
|
49
|
+
], MailtrapApiProvider);
|
|
50
|
+
export { MailtrapApiProvider };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brilab-mailer/provider-mailtrap",
|
|
3
|
+
"version": "0.0.1-beta.47",
|
|
4
|
+
"author": "Bohdan Radchenko <radchenkobs@gmail.com>",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./index.js",
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
"./package.json": "./package.json",
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./index.d.ts",
|
|
13
|
+
"import": "./index.js",
|
|
14
|
+
"default": "./index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"**/*",
|
|
19
|
+
"!**/*.tsbuildinfo"
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public",
|
|
24
|
+
"directory": "dist"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@nestjs/common": "^10.0.0",
|
|
28
|
+
"@nestjs/config": "^3.0.0",
|
|
29
|
+
"@brilab-mailer/contracts": "^0.0.1",
|
|
30
|
+
"@brilab-mailer/core": "^0.0.1"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"@brilab-mailer/contracts": {
|
|
34
|
+
"optional": false
|
|
35
|
+
},
|
|
36
|
+
"@brilab-mailer/core": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"mailtrap": "^3.0.0"
|
|
42
|
+
}
|
|
43
|
+
}
|