@trstudios/discord-notify 1.2.1 → 1.3.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.
- package/README.md +2 -1
- package/dist/notify.d.ts +9 -0
- package/dist/notify.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,6 +48,7 @@ const result = await sendMail(
|
|
|
48
48
|
from: { address: "noreply@example.com", name: "Example" },
|
|
49
49
|
to: [{ address: "someone@example.com" }],
|
|
50
50
|
bcc: [{ address: "audit@example.com" }], // optional, as is cc
|
|
51
|
+
attachments: [{ filename: "report.pdf", content: pdfBytes, contentType: "application/pdf" }], // optional
|
|
51
52
|
replyTo: { address: "help@example.com" },
|
|
52
53
|
subject: "Your report is ready",
|
|
53
54
|
html: "<p>…</p>",
|
|
@@ -101,7 +102,7 @@ export async function POST(request: Request) {
|
|
|
101
102
|
source: "example.com",
|
|
102
103
|
fail: new URL(request.url).searchParams.get("fail") === "1",
|
|
103
104
|
});
|
|
104
|
-
return Response.json(result, { status: result.ok ? 200 :
|
|
105
|
+
return Response.json(result, { status: result.ok ? 200 : 500 });
|
|
105
106
|
}
|
|
106
107
|
```
|
|
107
108
|
|
package/dist/notify.d.ts
CHANGED
|
@@ -39,6 +39,14 @@ export interface Address {
|
|
|
39
39
|
address: string;
|
|
40
40
|
name?: string;
|
|
41
41
|
}
|
|
42
|
+
export interface Attachment {
|
|
43
|
+
/** File name shown to the recipient, e.g. "report.pdf". */
|
|
44
|
+
filename: string;
|
|
45
|
+
/** The file's bytes. Strings are taken as already base64-encoded. */
|
|
46
|
+
content: Uint8Array | string;
|
|
47
|
+
/** MIME type, e.g. "application/pdf". */
|
|
48
|
+
contentType: string;
|
|
49
|
+
}
|
|
42
50
|
export interface Mail {
|
|
43
51
|
from: Address;
|
|
44
52
|
to: Address[];
|
|
@@ -48,6 +56,7 @@ export interface Mail {
|
|
|
48
56
|
subject: string;
|
|
49
57
|
text?: string;
|
|
50
58
|
html?: string;
|
|
59
|
+
attachments?: Attachment[];
|
|
51
60
|
}
|
|
52
61
|
/**
|
|
53
62
|
* How much of a failed message goes into the alert.
|
package/dist/notify.js
CHANGED
|
@@ -74,6 +74,7 @@ export function maskEmail(address) {
|
|
|
74
74
|
return `${address[0]}***${address.slice(at)}`;
|
|
75
75
|
}
|
|
76
76
|
const formatAddress = (a) => (a.name ? `${a.name} <${a.address}>` : a.address);
|
|
77
|
+
const base64 = (content) => typeof content === "string" ? content : Buffer.from(content).toString("base64");
|
|
77
78
|
const recipients = (list) => list.map((a) => ({ email_address: { address: a.address, name: a.name } }));
|
|
78
79
|
function zeptoBody(mail) {
|
|
79
80
|
return {
|
|
@@ -85,6 +86,9 @@ function zeptoBody(mail) {
|
|
|
85
86
|
subject: mail.subject,
|
|
86
87
|
textbody: mail.text,
|
|
87
88
|
htmlbody: mail.html,
|
|
89
|
+
attachments: mail.attachments?.length
|
|
90
|
+
? mail.attachments.map((a) => ({ name: a.filename, mime_type: a.contentType, content: base64(a.content) }))
|
|
91
|
+
: undefined,
|
|
88
92
|
};
|
|
89
93
|
}
|
|
90
94
|
/** Turns HTML into readable text for the alert when there is no text version. */
|
|
@@ -120,6 +124,9 @@ export function failureAlert(mail, error, level, source) {
|
|
|
120
124
|
fields.Bcc = mail.bcc.map(formatAddress).join(", ");
|
|
121
125
|
fields["Reply-To"] = mail.replyTo && formatAddress(mail.replyTo);
|
|
122
126
|
fields.Subject = mail.subject;
|
|
127
|
+
if (mail.attachments?.length) {
|
|
128
|
+
fields.Attachments = mail.attachments.map((a) => `${a.filename} (${a.contentType})`).join(", ");
|
|
129
|
+
}
|
|
123
130
|
if (level === "summary")
|
|
124
131
|
return { title: "Email failed to send", fields };
|
|
125
132
|
const body = mail.text ?? (mail.html ? htmlToText(mail.html) : undefined);
|
package/package.json
CHANGED