@frigear-nu/notify 0.2.7 → 0.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/dist/module.d.mts +8 -0
- package/dist/module.json +1 -1
- package/dist/runtime/drivers/email/cloudflare.js +3 -2
- package/dist/runtime/drivers/email/resend.js +3 -2
- package/dist/runtime/drivers/email/ses.js +3 -2
- package/dist/runtime/drivers/email/shared.d.ts +2 -0
- package/dist/runtime/drivers/email/shared.js +1 -0
- package/dist/runtime/server/utils/notify-user.js +2 -1
- package/package.json +2 -2
package/dist/module.d.mts
CHANGED
|
@@ -75,6 +75,13 @@ interface EmailNotification<M = NotificationMeta> {
|
|
|
75
75
|
* on. A custom driver whose transport has no cc may ignore them, and should say so where it is documented.
|
|
76
76
|
*/
|
|
77
77
|
cc?: string | string[];
|
|
78
|
+
/**
|
|
79
|
+
* Extra headers, such as `List-Unsubscribe` and `List-Unsubscribe-Post` (RFC 8058). The built-in `resend`, `ses` and
|
|
80
|
+
* `cloudflare` drivers pass them on, and `log` logs them. Headers the provider sets itself (`From`, `To`, `Subject`,
|
|
81
|
+
* `Message-ID`, `Date`) cannot be set; Cloudflare accepts only its allowlisted headers and `X-` headers and rejects the
|
|
82
|
+
* whole send otherwise. A custom driver whose transport has no headers may ignore them.
|
|
83
|
+
*/
|
|
84
|
+
headers?: Record<string, string>;
|
|
78
85
|
/**
|
|
79
86
|
* Template to render this email from instead of `subject`/`body`/`text`, when a renderer is
|
|
80
87
|
* installed (`@frigear-nu/email-templates` listens on the `notify:email` hook). Without one,
|
|
@@ -205,6 +212,7 @@ type NotifyUserInput = {
|
|
|
205
212
|
body: string;
|
|
206
213
|
text?: string;
|
|
207
214
|
replyTo?: string;
|
|
215
|
+
headers?: Record<string, string>;
|
|
208
216
|
template?: EmailTemplateRef;
|
|
209
217
|
meta?: Record<string, unknown>;
|
|
210
218
|
};
|
package/dist/module.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertOk, requireConfig, resolveFrom, toArray } from "./shared.js";
|
|
1
|
+
import { assertOk, hasHeaders, requireConfig, resolveFrom, toArray } from "./shared.js";
|
|
2
2
|
export const createCloudflareDriver = (config) => async (n) => {
|
|
3
3
|
const accountId = requireConfig(config.accountId, "NUXT_NOTIFY_EMAIL_CLOUDFLARE_ACCOUNT_ID");
|
|
4
4
|
const response = await fetch(`https://api.cloudflare.com/client/v4/accounts/${encodeURIComponent(accountId)}/email/sending/send`, {
|
|
@@ -14,7 +14,8 @@ export const createCloudflareDriver = (config) => async (n) => {
|
|
|
14
14
|
subject: n.subject,
|
|
15
15
|
html: n.body,
|
|
16
16
|
text: n.text,
|
|
17
|
-
reply_to: n.replyTo
|
|
17
|
+
reply_to: n.replyTo,
|
|
18
|
+
headers: hasHeaders(n.headers) ? n.headers : void 0
|
|
18
19
|
})
|
|
19
20
|
});
|
|
20
21
|
await assertOk("Cloudflare", response);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertOk, requireConfig, resolveFrom, toArray } from "./shared.js";
|
|
1
|
+
import { assertOk, hasHeaders, requireConfig, resolveFrom, toArray } from "./shared.js";
|
|
2
2
|
export const createResendDriver = (config) => async (n) => {
|
|
3
3
|
const response = await fetch("https://api.resend.com/emails", {
|
|
4
4
|
method: "POST",
|
|
@@ -13,7 +13,8 @@ export const createResendDriver = (config) => async (n) => {
|
|
|
13
13
|
subject: n.subject,
|
|
14
14
|
html: n.body,
|
|
15
15
|
text: n.text,
|
|
16
|
-
reply_to: n.replyTo
|
|
16
|
+
reply_to: n.replyTo,
|
|
17
|
+
headers: hasHeaders(n.headers) ? n.headers : void 0
|
|
17
18
|
})
|
|
18
19
|
});
|
|
19
20
|
await assertOk("Resend", response);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertOk, requireConfig, resolveFrom, toArray } from "./shared.js";
|
|
1
|
+
import { assertOk, hasHeaders, requireConfig, resolveFrom, toArray } from "./shared.js";
|
|
2
2
|
import { signRequest } from "./sigv4.js";
|
|
3
3
|
export const createSesDriver = (config) => async (n) => {
|
|
4
4
|
const region = requireConfig(config.region, "NUXT_NOTIFY_EMAIL_SES_REGION");
|
|
@@ -15,7 +15,8 @@ export const createSesDriver = (config) => async (n) => {
|
|
|
15
15
|
Body: {
|
|
16
16
|
Html: { Data: n.body, Charset: "UTF-8" },
|
|
17
17
|
...n.text ? { Text: { Data: n.text, Charset: "UTF-8" } } : {}
|
|
18
|
-
}
|
|
18
|
+
},
|
|
19
|
+
...hasHeaders(n.headers) ? { Headers: Object.entries(n.headers).map(([Name, Value]) => ({ Name, Value })) } : {}
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
});
|
|
@@ -2,6 +2,8 @@ import type { EmailNotification } from '../../../types.js';
|
|
|
2
2
|
export interface EmailConfig {
|
|
3
3
|
from?: string;
|
|
4
4
|
}
|
|
5
|
+
/** True when `headers` has at least one entry, so a driver leaves an empty object out of the request. */
|
|
6
|
+
export declare const hasHeaders: (headers: Record<string, string> | undefined) => headers is Record<string, string>;
|
|
5
7
|
export declare const toArray: (value: string | string[]) => string[];
|
|
6
8
|
/** Throws a config error naming the env var an operator needs to set. */
|
|
7
9
|
export declare function requireConfig(value: string | undefined, envVar: string): string;
|
|
@@ -82,13 +82,14 @@ export async function notifyUser(userId, input) {
|
|
|
82
82
|
};
|
|
83
83
|
await run("email", async () => {
|
|
84
84
|
if (!recipient?.email || !input.email) return false;
|
|
85
|
-
const { subject, body, text, replyTo, template, meta } = input.email;
|
|
85
|
+
const { subject, body, text, replyTo, headers, template, meta } = input.email;
|
|
86
86
|
await dispatchEmailNotification({
|
|
87
87
|
to: recipient.email,
|
|
88
88
|
subject,
|
|
89
89
|
body,
|
|
90
90
|
...text !== void 0 ? { text } : {},
|
|
91
91
|
...replyTo !== void 0 ? { replyTo } : {},
|
|
92
|
+
...headers !== void 0 ? { headers } : {},
|
|
92
93
|
...template !== void 0 ? { template: template.locale || !recipient.locale ? template : { ...template, locale: recipient.locale } } : {},
|
|
93
94
|
...meta !== void 0 ? { meta } : {}
|
|
94
95
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frigear-nu/notify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Email, SMS, push and generic notification dispatch (pluggable drivers), and notifyUser: per-user channel choices over a topic registry. Shared across Frigear modules.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@nuxt/kit": "^4.6.4",
|
|
33
|
-
"@frigear-nu/module-kit": "^1.3.
|
|
33
|
+
"@frigear-nu/module-kit": "^1.3.11",
|
|
34
34
|
"defu": "^6.1.7",
|
|
35
35
|
"ufo": "^1.6.4"
|
|
36
36
|
},
|