@upyo/mailgun 0.1.0-dev.14 → 0.1.0-dev.9
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 +12 -33
- package/dist/index.cjs +13 -15
- package/dist/index.d.cts +1 -5
- package/dist/index.d.ts +1 -5
- package/dist/index.js +13 -15
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,17 +3,9 @@
|
|
|
3
3
|
@upyo/mailgun
|
|
4
4
|
=============
|
|
5
5
|
|
|
6
|
-
[
|
|
7
|
-
[![npm][npm badge]][npm]
|
|
6
|
+
[Mailgun] transport for Upyo email library.
|
|
8
7
|
|
|
9
|
-
[Mailgun] transport for the [Upyo] email library.
|
|
10
|
-
|
|
11
|
-
[JSR]: https://jsr.io/@upyo/mailgun
|
|
12
|
-
[JSR badge]: https://jsr.io/badges/@upyo/mailgun
|
|
13
|
-
[npm]: https://www.npmjs.com/package/@upyo/mailgun
|
|
14
|
-
[npm badge]: https://img.shields.io/npm/v/@upyo/mailgun?logo=npm
|
|
15
8
|
[Mailgun]: https://www.mailgun.com/
|
|
16
|
-
[Upyo]: https://upyo.org/
|
|
17
9
|
|
|
18
10
|
|
|
19
11
|
Installation
|
|
@@ -32,35 +24,22 @@ Usage
|
|
|
32
24
|
-----
|
|
33
25
|
|
|
34
26
|
~~~~ typescript
|
|
35
|
-
import {
|
|
36
|
-
import { MailgunTransport } from "@upyo/mailgun";
|
|
37
|
-
import fs from "node:fs/promises";
|
|
38
|
-
import process from "node:process";
|
|
39
|
-
|
|
40
|
-
const message = createMessage({
|
|
41
|
-
from: "sender@example.com",
|
|
42
|
-
to: "recipient@example.net",
|
|
43
|
-
subject: "Hello from Upyo!",
|
|
44
|
-
content: { text: "This is a test email." },
|
|
45
|
-
attachments: [
|
|
46
|
-
new File(
|
|
47
|
-
[await fs.readFile("image.jpg"), "image.jpg", { type: "image/jpeg" }]
|
|
48
|
-
)
|
|
49
|
-
],
|
|
50
|
-
});
|
|
27
|
+
import { MailgunTransport } from '@upyo/mailgun';
|
|
51
28
|
|
|
52
29
|
const transport = new MailgunTransport({
|
|
53
|
-
apiKey:
|
|
54
|
-
domain:
|
|
55
|
-
region: process.env.MAILGUN_REGION as "us" | "eu",
|
|
30
|
+
apiKey: 'your-api-key',
|
|
31
|
+
domain: 'your-domain.com'
|
|
56
32
|
});
|
|
57
33
|
|
|
34
|
+
const message = {
|
|
35
|
+
sender: { address: 'sender@example.com' },
|
|
36
|
+
recipients: [{ address: 'recipient@example.com' }],
|
|
37
|
+
subject: 'Hello from Mailgun!',
|
|
38
|
+
content: { text: 'Hello, World!' }
|
|
39
|
+
};
|
|
40
|
+
|
|
58
41
|
const receipt = await transport.send(message);
|
|
59
|
-
|
|
60
|
-
console.log("Message sent with ID:", receipt.messageId);
|
|
61
|
-
} else {
|
|
62
|
-
console.error("Send failed:", receipt.errorMessages.join(", "));
|
|
63
|
-
}
|
|
42
|
+
console.log('Message sent:', receipt.messageId);
|
|
64
43
|
~~~~
|
|
65
44
|
|
|
66
45
|
|
package/dist/index.cjs
CHANGED
|
@@ -162,11 +162,11 @@ var MailgunApiError = class extends Error {
|
|
|
162
162
|
*
|
|
163
163
|
* @example
|
|
164
164
|
* ```typescript
|
|
165
|
-
* const formData =
|
|
165
|
+
* const formData = convertMessage(message, config);
|
|
166
166
|
* const response = await fetch(url, { method: 'POST', body: formData });
|
|
167
167
|
* ```
|
|
168
168
|
*/
|
|
169
|
-
|
|
169
|
+
function convertMessage(message, config) {
|
|
170
170
|
const formData = new FormData();
|
|
171
171
|
formData.append("from", formatAddress(message.sender));
|
|
172
172
|
for (const recipient of message.recipients) formData.append("to", formatAddress(recipient));
|
|
@@ -191,7 +191,7 @@ async function convertMessage(message, config) {
|
|
|
191
191
|
}
|
|
192
192
|
for (const tag of message.tags) formData.append("o:tag", tag);
|
|
193
193
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) formData.append(`h:${key}`, value);
|
|
194
|
-
for (const attachment of message.attachments)
|
|
194
|
+
for (const attachment of message.attachments) appendAttachment(formData, attachment);
|
|
195
195
|
if (config.tracking !== void 0) formData.append("o:tracking", config.tracking ? "yes" : "no");
|
|
196
196
|
if (config.clickTracking !== void 0) formData.append("o:tracking-clicks", config.clickTracking ? "yes" : "no");
|
|
197
197
|
if (config.openTracking !== void 0) formData.append("o:tracking-opens", config.openTracking ? "yes" : "no");
|
|
@@ -216,8 +216,8 @@ function formatAddress(address) {
|
|
|
216
216
|
* @param formData - The FormData to append to
|
|
217
217
|
* @param attachment - The attachment to append
|
|
218
218
|
*/
|
|
219
|
-
|
|
220
|
-
const blob = new Blob([
|
|
219
|
+
function appendAttachment(formData, attachment) {
|
|
220
|
+
const blob = new Blob([attachment.content], { type: attachment.contentType });
|
|
221
221
|
if (attachment.contentId) formData.append("inline", blob, attachment.filename);
|
|
222
222
|
else formData.append("attachment", blob, attachment.filename);
|
|
223
223
|
}
|
|
@@ -263,11 +263,7 @@ function isStandardHeader(headerName) {
|
|
|
263
263
|
* });
|
|
264
264
|
*
|
|
265
265
|
* const receipt = await transport.send(message);
|
|
266
|
-
*
|
|
267
|
-
* console.log('Message sent with ID:', receipt.messageId);
|
|
268
|
-
* } else {
|
|
269
|
-
* console.error('Send failed:', receipt.errorMessages.join(', '));
|
|
270
|
-
* }
|
|
266
|
+
* console.log('Message sent:', receipt.messageId);
|
|
271
267
|
* ```
|
|
272
268
|
*/
|
|
273
269
|
var MailgunTransport = class {
|
|
@@ -318,18 +314,20 @@ var MailgunTransport = class {
|
|
|
318
314
|
async send(message, options) {
|
|
319
315
|
options?.signal?.throwIfAborted();
|
|
320
316
|
try {
|
|
321
|
-
const formData =
|
|
317
|
+
const formData = convertMessage(message, this.config);
|
|
322
318
|
options?.signal?.throwIfAborted();
|
|
323
319
|
const response = await this.httpClient.sendMessage(formData, options?.signal);
|
|
324
320
|
return {
|
|
325
|
-
|
|
326
|
-
|
|
321
|
+
messageId: response.id,
|
|
322
|
+
errorMessages: [],
|
|
323
|
+
successful: true
|
|
327
324
|
};
|
|
328
325
|
} catch (error) {
|
|
329
326
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
330
327
|
return {
|
|
331
|
-
|
|
332
|
-
errorMessages: [errorMessage]
|
|
328
|
+
messageId: "",
|
|
329
|
+
errorMessages: [errorMessage],
|
|
330
|
+
successful: false
|
|
333
331
|
};
|
|
334
332
|
}
|
|
335
333
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -196,11 +196,7 @@ declare class MailgunApiError extends Error {
|
|
|
196
196
|
* });
|
|
197
197
|
*
|
|
198
198
|
* const receipt = await transport.send(message);
|
|
199
|
-
*
|
|
200
|
-
* console.log('Message sent with ID:', receipt.messageId);
|
|
201
|
-
* } else {
|
|
202
|
-
* console.error('Send failed:', receipt.errorMessages.join(', '));
|
|
203
|
-
* }
|
|
199
|
+
* console.log('Message sent:', receipt.messageId);
|
|
204
200
|
* ```
|
|
205
201
|
*/
|
|
206
202
|
declare class MailgunTransport implements Transport {
|
package/dist/index.d.ts
CHANGED
|
@@ -196,11 +196,7 @@ declare class MailgunApiError extends Error {
|
|
|
196
196
|
* });
|
|
197
197
|
*
|
|
198
198
|
* const receipt = await transport.send(message);
|
|
199
|
-
*
|
|
200
|
-
* console.log('Message sent with ID:', receipt.messageId);
|
|
201
|
-
* } else {
|
|
202
|
-
* console.error('Send failed:', receipt.errorMessages.join(', '));
|
|
203
|
-
* }
|
|
199
|
+
* console.log('Message sent:', receipt.messageId);
|
|
204
200
|
* ```
|
|
205
201
|
*/
|
|
206
202
|
declare class MailgunTransport implements Transport {
|
package/dist/index.js
CHANGED
|
@@ -161,11 +161,11 @@ var MailgunApiError = class extends Error {
|
|
|
161
161
|
*
|
|
162
162
|
* @example
|
|
163
163
|
* ```typescript
|
|
164
|
-
* const formData =
|
|
164
|
+
* const formData = convertMessage(message, config);
|
|
165
165
|
* const response = await fetch(url, { method: 'POST', body: formData });
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
|
-
|
|
168
|
+
function convertMessage(message, config) {
|
|
169
169
|
const formData = new FormData();
|
|
170
170
|
formData.append("from", formatAddress(message.sender));
|
|
171
171
|
for (const recipient of message.recipients) formData.append("to", formatAddress(recipient));
|
|
@@ -190,7 +190,7 @@ async function convertMessage(message, config) {
|
|
|
190
190
|
}
|
|
191
191
|
for (const tag of message.tags) formData.append("o:tag", tag);
|
|
192
192
|
for (const [key, value] of message.headers.entries()) if (!isStandardHeader(key)) formData.append(`h:${key}`, value);
|
|
193
|
-
for (const attachment of message.attachments)
|
|
193
|
+
for (const attachment of message.attachments) appendAttachment(formData, attachment);
|
|
194
194
|
if (config.tracking !== void 0) formData.append("o:tracking", config.tracking ? "yes" : "no");
|
|
195
195
|
if (config.clickTracking !== void 0) formData.append("o:tracking-clicks", config.clickTracking ? "yes" : "no");
|
|
196
196
|
if (config.openTracking !== void 0) formData.append("o:tracking-opens", config.openTracking ? "yes" : "no");
|
|
@@ -215,8 +215,8 @@ function formatAddress(address) {
|
|
|
215
215
|
* @param formData - The FormData to append to
|
|
216
216
|
* @param attachment - The attachment to append
|
|
217
217
|
*/
|
|
218
|
-
|
|
219
|
-
const blob = new Blob([
|
|
218
|
+
function appendAttachment(formData, attachment) {
|
|
219
|
+
const blob = new Blob([attachment.content], { type: attachment.contentType });
|
|
220
220
|
if (attachment.contentId) formData.append("inline", blob, attachment.filename);
|
|
221
221
|
else formData.append("attachment", blob, attachment.filename);
|
|
222
222
|
}
|
|
@@ -262,11 +262,7 @@ function isStandardHeader(headerName) {
|
|
|
262
262
|
* });
|
|
263
263
|
*
|
|
264
264
|
* const receipt = await transport.send(message);
|
|
265
|
-
*
|
|
266
|
-
* console.log('Message sent with ID:', receipt.messageId);
|
|
267
|
-
* } else {
|
|
268
|
-
* console.error('Send failed:', receipt.errorMessages.join(', '));
|
|
269
|
-
* }
|
|
265
|
+
* console.log('Message sent:', receipt.messageId);
|
|
270
266
|
* ```
|
|
271
267
|
*/
|
|
272
268
|
var MailgunTransport = class {
|
|
@@ -317,18 +313,20 @@ var MailgunTransport = class {
|
|
|
317
313
|
async send(message, options) {
|
|
318
314
|
options?.signal?.throwIfAborted();
|
|
319
315
|
try {
|
|
320
|
-
const formData =
|
|
316
|
+
const formData = convertMessage(message, this.config);
|
|
321
317
|
options?.signal?.throwIfAborted();
|
|
322
318
|
const response = await this.httpClient.sendMessage(formData, options?.signal);
|
|
323
319
|
return {
|
|
324
|
-
|
|
325
|
-
|
|
320
|
+
messageId: response.id,
|
|
321
|
+
errorMessages: [],
|
|
322
|
+
successful: true
|
|
326
323
|
};
|
|
327
324
|
} catch (error) {
|
|
328
325
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
329
326
|
return {
|
|
330
|
-
|
|
331
|
-
errorMessages: [errorMessage]
|
|
327
|
+
messageId: "",
|
|
328
|
+
errorMessages: [errorMessage],
|
|
329
|
+
successful: false
|
|
332
330
|
};
|
|
333
331
|
}
|
|
334
332
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upyo/mailgun",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.9+a57dde18",
|
|
4
4
|
"description": "Mailgun transport for Upyo email library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -53,12 +53,12 @@
|
|
|
53
53
|
},
|
|
54
54
|
"sideEffects": false,
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@upyo/core": "0.1.0-dev.
|
|
56
|
+
"@upyo/core": "0.1.0-dev.9+a57dde18"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@dotenvx/dotenvx": "^1.47.3",
|
|
60
60
|
"tsdown": "^0.12.7",
|
|
61
|
-
"typescript": "5.8.3"
|
|
61
|
+
"typescript": "^5.8.3"
|
|
62
62
|
},
|
|
63
63
|
"scripts": {
|
|
64
64
|
"build": "tsdown",
|