@tansy/email-mailgun 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +12 -2
- package/index.d.ts +4 -0
- package/index.js +51 -0
- package/package.json +26 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohamed Salah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- Generated by scripts/package-metadata.mjs. Change that script, not this file. -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @tansy/email-mailgun
|
|
4
|
+
|
|
5
|
+
Mailgun for @tansy/email.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tansy/email-mailgun
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Add it to `tansy.config.ts`. See [the email plugin documentation](https://github.com/mhmdsalahsebai/tansy/blob/main/docs/plugins/email.md) for what it adds and the options it takes.
|
|
12
|
+
|
|
13
|
+
A first-party plugin for [tansy](https://github.com/mhmdsalahsebai/tansy), a self-hosted, runtime-schema CMS for Next.js. MIT licensed.
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { callProvider, defineEmailProvider, idOf, mailbox, str } from "@tansy/email/provider";
|
|
2
|
+
const key = (settings) => str(settings.mailgunApiKey);
|
|
3
|
+
/** A domain name, and nothing that could change the request's path. */
|
|
4
|
+
export const MAILGUN_DOMAIN = /^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
|
|
5
|
+
const HOSTS = { us: "https://api.mailgun.net", eu: "https://api.eu.mailgun.net" };
|
|
6
|
+
const domain = (settings) => str(settings.mailgunDomain).toLowerCase();
|
|
7
|
+
/** Mailgun, through its Messages API. */
|
|
8
|
+
export const mailgun = (fetcher = fetch) => defineEmailProvider({
|
|
9
|
+
id: "mailgun",
|
|
10
|
+
label: "Mailgun",
|
|
11
|
+
// Its settings in other interface languages. English is each setting's own label and description.
|
|
12
|
+
messages: {
|
|
13
|
+
ar: {
|
|
14
|
+
settings: {
|
|
15
|
+
mailgunApiKey: {
|
|
16
|
+
label: "مفتاح API لـ Mailgun",
|
|
17
|
+
description: "مفتاح إرسال من Mailgun ← Sending ← Domain settings ← Sending API keys، أو المفتاح الخاص بحسابك."
|
|
18
|
+
},
|
|
19
|
+
mailgunDomain: {
|
|
20
|
+
label: "نطاق الإرسال في Mailgun",
|
|
21
|
+
description: "كما وُثّق في Mailgun، مثل mg.example.com."
|
|
22
|
+
},
|
|
23
|
+
mailgunRegion: {
|
|
24
|
+
label: "منطقة Mailgun",
|
|
25
|
+
description: "حيث أُنشئ النطاق.",
|
|
26
|
+
options: { us: "الولايات المتحدة", eu: "الاتحاد الأوروبي" }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
settings: () => [
|
|
32
|
+
{ name: "mailgunApiKey", type: "secret", env: "MAILGUN_API_KEY", label: "Mailgun API key", description: "A sending key from Mailgun → Sending → Domain settings → Sending API keys, or your account's private key." },
|
|
33
|
+
{ name: "mailgunDomain", type: "text", default: "", maxLength: 253, label: "Mailgun sending domain", description: "As verified in Mailgun, such as mg.example.com." },
|
|
34
|
+
{ name: "mailgunRegion", type: "select", default: "us", label: "Mailgun region", description: "Where the domain was created.", options: [{ value: "us", label: "US" }, { value: "eu", label: "EU" }] },
|
|
35
|
+
],
|
|
36
|
+
ready: (settings) => Boolean(key(settings)) && MAILGUN_DOMAIN.test(domain(settings)),
|
|
37
|
+
async send(email, settings) {
|
|
38
|
+
const host = HOSTS[str(settings.mailgunRegion)] ?? HOSTS.us;
|
|
39
|
+
const form = new URLSearchParams({ from: mailbox(email.from), to: email.to, subject: email.subject, text: email.text, html: email.html });
|
|
40
|
+
if (email.replyTo)
|
|
41
|
+
form.set("h:Reply-To", email.replyTo);
|
|
42
|
+
for (const [name, value] of Object.entries(email.headers))
|
|
43
|
+
form.set(`h:${name}`, value);
|
|
44
|
+
const answer = await callProvider("Mailgun", `${host}/v3/${domain(settings)}/messages`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { authorization: `Basic ${Buffer.from(`api:${key(settings)}`).toString("base64")}` },
|
|
47
|
+
body: form,
|
|
48
|
+
}, fetcher);
|
|
49
|
+
return { id: idOf(answer.id) };
|
|
50
|
+
},
|
|
51
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tansy/email-mailgun",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Mailgun for @tansy/email.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tansy",
|
|
7
|
+
"tansy-email-provider"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Mohamed Salah <mohamedsalahsebai@gmail.com>",
|
|
11
|
+
"homepage": "https://github.com/mhmdsalahsebai/tansy",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/mhmdsalahsebai/tansy.git",
|
|
15
|
+
"directory": "plugins/email-mailgun"
|
|
16
|
+
},
|
|
17
|
+
"bugs": "https://github.com/mhmdsalahsebai/tansy/issues",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@tansy/email": "^0.1.0",
|
|
26
|
+
"tansy": "^0.1.0"
|
|
27
|
+
}
|
|
28
|
+
}
|