@trstudios/discord-notify 1.0.1 → 1.1.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 CHANGED
@@ -47,6 +47,7 @@ const result = await sendMail(
47
47
  {
48
48
  from: { address: "noreply@example.com", name: "Example" },
49
49
  to: [{ address: "someone@example.com" }],
50
+ bcc: [{ address: "audit@example.com" }], // optional, as is cc
50
51
  replyTo: { address: "help@example.com" },
51
52
  subject: "Your report is ready",
52
53
  html: "<p>…</p>",
package/dist/notify.d.ts CHANGED
@@ -42,6 +42,8 @@ export interface Address {
42
42
  export interface Mail {
43
43
  from: Address;
44
44
  to: Address[];
45
+ cc?: Address[];
46
+ bcc?: Address[];
45
47
  replyTo?: Address;
46
48
  subject: string;
47
49
  text?: string;
package/dist/notify.js CHANGED
@@ -73,10 +73,13 @@ export function maskEmail(address) {
73
73
  return `${address[0]}***${address.slice(at)}`;
74
74
  }
75
75
  const formatAddress = (a) => (a.name ? `${a.name} <${a.address}>` : a.address);
76
+ const recipients = (list) => list.map((a) => ({ email_address: { address: a.address, name: a.name } }));
76
77
  function zeptoBody(mail) {
77
78
  return {
78
79
  from: { address: mail.from.address, name: mail.from.name },
79
- to: mail.to.map((a) => ({ email_address: { address: a.address, name: a.name } })),
80
+ to: recipients(mail.to),
81
+ cc: mail.cc?.length ? recipients(mail.cc) : undefined,
82
+ bcc: mail.bcc?.length ? recipients(mail.bcc) : undefined,
80
83
  reply_to: mail.replyTo ? [{ address: mail.replyTo.address, name: mail.replyTo.name }] : undefined,
81
84
  subject: mail.subject,
82
85
  textbody: mail.text,
@@ -102,10 +105,18 @@ export function failureAlert(mail, error, level, source) {
102
105
  const fields = { Source: source, Error: error };
103
106
  if (level === "none") {
104
107
  fields.To = mail.to.map((a) => maskEmail(a.address)).join(", ");
108
+ if (mail.cc?.length)
109
+ fields.Cc = mail.cc.map((a) => maskEmail(a.address)).join(", ");
110
+ if (mail.bcc?.length)
111
+ fields.Bcc = mail.bcc.map((a) => maskEmail(a.address)).join(", ");
105
112
  return { title: "Email failed to send", fields };
106
113
  }
107
114
  fields.From = formatAddress(mail.from);
108
115
  fields.To = mail.to.map(formatAddress).join(", ");
116
+ if (mail.cc?.length)
117
+ fields.Cc = mail.cc.map(formatAddress).join(", ");
118
+ if (mail.bcc?.length)
119
+ fields.Bcc = mail.bcc.map(formatAddress).join(", ");
109
120
  fields["Reply-To"] = mail.replyTo && formatAddress(mail.replyTo);
110
121
  fields.Subject = mail.subject;
111
122
  if (level === "summary")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trstudios/discord-notify",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Discord alerts for server-side failures, with a ZeptoMail sender that reports failed sends. No dependencies.",
5
5
  "keywords": [
6
6
  "discord",