@brilab-mailer/provider-mailtrap 0.0.5-5 → 0.2.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,12 +1,12 @@
|
|
|
1
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";
|
|
2
|
+
import { MailerProvider, type MailerMessagesResolved, type MailerSendResult } from '@brilab-mailer/contracts';
|
|
3
|
+
import type { Mail } from "mailtrap/dist/types/mailtrap.js";
|
|
4
4
|
export declare class MailtrapApiProvider implements MailerProvider<MailtrapClientConfig, MailtrapClient, Mail> {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private readonly _client;
|
|
7
7
|
constructor(options: MailtrapClientConfig);
|
|
8
8
|
getClient(): MailtrapClient;
|
|
9
9
|
createPayload(resolved: MailerMessagesResolved): Mail;
|
|
10
|
-
send(payload: Mail): Promise<
|
|
10
|
+
send(payload: Mail): Promise<MailerSendResult>;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=mailtrap-api.provider.d.ts.map
|
|
@@ -1 +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,
|
|
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,EAGd,KAAK,sBAAsB,EAC3B,KAAK,gBAAgB,EAGrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iCAAiC,CAAC;AAI5D,qBACa,mBAAoB,YAAW,cAAc,CAAC,oBAAoB,EAAE,cAAc,EAAE,IAAI,CAAC;IAKpG,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;gBAIvB,OAAO,EAAE,oBAAoB;IAcxC,SAAS,IAAI,cAAc;IAI3B,aAAa,CAAC,QAAQ,EAAE,sBAAsB,GAAG,IAAI;IAe/C,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAW3D"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { __decorate, __metadata, __param } from "tslib";
|
|
2
2
|
import { Inject, Injectable } from '@nestjs/common';
|
|
3
3
|
import { MailtrapClient } from 'mailtrap';
|
|
4
|
-
import { MAILER_PROVIDER_OPTIONS, } from '@brilab-mailer/contracts';
|
|
4
|
+
import { MAILER_PROVIDER_OPTIONS, toMailerSendError, resolveBodies, } from '@brilab-mailer/contracts';
|
|
5
|
+
const toAddress = (a) => ({ email: a.email, name: a.name });
|
|
5
6
|
let MailtrapApiProvider = class MailtrapApiProvider {
|
|
6
7
|
options;
|
|
7
8
|
_client;
|
|
@@ -13,33 +14,39 @@ let MailtrapApiProvider = class MailtrapApiProvider {
|
|
|
13
14
|
this._client = new MailtrapClient({
|
|
14
15
|
token,
|
|
15
16
|
testInboxId: this.options?.testInboxId,
|
|
16
|
-
accountId: this.options?.accountId
|
|
17
|
+
accountId: this.options?.accountId,
|
|
18
|
+
sandbox: this.options?.sandbox,
|
|
19
|
+
bulk: this.options?.bulk,
|
|
17
20
|
});
|
|
18
21
|
}
|
|
19
22
|
getClient() {
|
|
20
23
|
return this._client;
|
|
21
24
|
}
|
|
22
25
|
createPayload(resolved) {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
const { text, html } = resolveBodies(resolved);
|
|
27
|
+
return {
|
|
28
|
+
from: toAddress(resolved.from),
|
|
29
|
+
to: resolved.to.map(toAddress),
|
|
30
|
+
cc: resolved.cc?.map(toAddress),
|
|
31
|
+
bcc: resolved.bcc?.map(toAddress),
|
|
32
|
+
reply_to: resolved.replyTo ? toAddress(resolved.replyTo) : undefined,
|
|
33
|
+
subject: resolved.subject,
|
|
34
|
+
headers: resolved.headers,
|
|
35
|
+
text: text ?? '',
|
|
36
|
+
html,
|
|
27
37
|
};
|
|
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
38
|
}
|
|
41
39
|
async send(payload) {
|
|
42
|
-
|
|
40
|
+
try {
|
|
41
|
+
const res = await this._client.send(payload);
|
|
42
|
+
return {
|
|
43
|
+
messageId: res.message_ids?.[0],
|
|
44
|
+
raw: res,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
throw toMailerSendError('MailtrapApiProvider', err);
|
|
49
|
+
}
|
|
43
50
|
}
|
|
44
51
|
};
|
|
45
52
|
MailtrapApiProvider = __decorate([
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brilab-mailer/provider-mailtrap",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"author": "Bohdan Radchenko <radchenkobs@gmail.com>",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@nestjs/common": "^10.0.0",
|
|
28
28
|
"@nestjs/config": "^3.0.0",
|
|
29
|
-
"@brilab-mailer/contracts": "^0.0
|
|
30
|
-
"@brilab-mailer/core": "^0.0
|
|
29
|
+
"@brilab-mailer/contracts": "^0.2.0",
|
|
30
|
+
"@brilab-mailer/core": "^0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
"@brilab-mailer/contracts": {
|
|
@@ -38,6 +38,6 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"mailtrap": "^
|
|
41
|
+
"mailtrap": "^4.6.0"
|
|
42
42
|
}
|
|
43
43
|
}
|