@easy-cms/plugin-email 0.0.0-stage → 1.42.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kanawoot K.
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,18 @@
1
- # Temporary Holding Version
1
+ # @easy-cms/plugin-email
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Email providers for [Easy CMS](https://easycms.dev): **Resend**, **Postmark** and **Brevo** (and
4
+ **SMTP** with `@easy-cms/email-smtp`), connected and chosen in Settings → Integrations → Email.
5
+ The config's `email`, if any, stays the default. Webhooks say what happened to each email, and
6
+ bounces and spam reports keep an address off the suppression list.
7
+
8
+ ```ts
9
+ import { emailPlugin, emailProviders } from '@easy-cms/plugin-email'
10
+ import { smtp, smtpProvider } from '@easy-cms/email-smtp'
11
+
12
+ export default defineConfig({
13
+ email: smtp(), // the default until an admin chooses a provider (optional)
14
+ plugins: [emailPlugin({ providers: [...emailProviders, smtpProvider] })],
15
+ })
16
+ ```
17
+
18
+ See the [email guide](https://easycms.dev/docs/email#providers).
@@ -0,0 +1,37 @@
1
+ import * as _easy_cms_core from '@easy-cms/core';
2
+ import { IntegrationConfig, EmailWebhookRequest } from '@easy-cms/core';
3
+ export { EmailEvent, EmailProvider, defineEmailProvider } from '@easy-cms/core';
4
+
5
+ /** Brevo (brevo.com, formerly Sendinblue): an API key, and a webhook for deliveries, bounces and spam. */
6
+ declare const brevo: _easy_cms_core.IntegrationConfig;
7
+
8
+ /** The providers `emailPlugin()` offers by default. */
9
+ declare const emailProviders: readonly IntegrationConfig[];
10
+ interface EmailPluginOptions {
11
+ /**
12
+ * The providers offered in Integrations → Email. Default: Resend, Postmark and Brevo. Add
13
+ * `smtpProvider` from `@easy-cms/email-smtp` for any mail server, or your own with
14
+ * `defineEmailProvider()`.
15
+ */
16
+ readonly providers?: readonly IntegrationConfig[];
17
+ }
18
+ /**
19
+ * Email providers an admin connects and chooses in Integrations → Email (#404): the config's
20
+ * `email`, if any, stays the default. Their webhooks say what happened to each email, and
21
+ * bounces and spam reports keep an address off the suppression list.
22
+ */
23
+ declare function emailPlugin(options?: EmailPluginOptions): _easy_cms_core.TypedPlugin<Record<never, never>>;
24
+
25
+ /** Postmark (postmarkapp.com): a server token, and a webhook for deliveries, bounces and spam. */
26
+ declare const postmark: _easy_cms_core.IntegrationConfig;
27
+
28
+ /**
29
+ * Checks a Svix signature (Resend's webhooks): `svix-signature` lists `v1,<base64>` signatures of
30
+ * `<id>.<timestamp>.<body>` with the secret after `whsec_`.
31
+ */
32
+ declare function verifySvix(request: EmailWebhookRequest, secret: string, now?: number): void;
33
+ /** Resend (resend.com): an API key, and a webhook for deliveries, bounces and spam reports. */
34
+ declare const resend: _easy_cms_core.IntegrationConfig;
35
+
36
+ export { brevo, emailPlugin, emailProviders, postmark, resend, verifySvix };
37
+ export type { EmailPluginOptions };
package/dist/index.js ADDED
@@ -0,0 +1,394 @@
1
+ // src/index.ts
2
+ import { defineEmailProvider as defineEmailProvider4 } from "@easy-cms/core";
3
+
4
+ // src/brevo.ts
5
+ import { defineEmailProvider } from "@easy-cms/core";
6
+
7
+ // ../../node_modules/.pnpm/simple-icons@16.36.0/node_modules/simple-icons/index.mjs
8
+ var c = '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>';
9
+ var t = '</title><path d="';
10
+ var a = '"/></svg>';
11
+ var siBrevo = { title: "Brevo", slug: "brevo", get svg() {
12
+ return c + "Brevo" + t + this.path + a;
13
+ }, path: "M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zM7.2 4.8h5.747c2.34 0 3.895 1.406 3.895 3.516 0 1.022-.348 1.862-1.09 2.588C17.189 11.812 18 13.22 18 14.785c0 2.86-2.64 5.016-6.164 5.016H7.199v-15zm2.085 1.952v5.537h.07c.233-.432.858-.796 2.249-1.226 2.039-.659 3.037-1.52 3.037-2.655 0-.998-.766-1.656-1.924-1.656H9.285zm4.87 5.266c-.766.385-1.67.748-2.76 1.11-1.229.387-2.11 1.386-2.11 2.407v2.315h2.365c2.387 0 4.149-1.34 4.149-3.155 0-1.067-.625-2.087-1.645-2.677z", source: "https://www.brevo.com", hex: "0B996E" };
14
+ var siResend = { title: "Resend", slug: "resend", get svg() {
15
+ return c + "Resend" + t + this.path + a;
16
+ }, path: "M14.679 0c4.648 0 7.413 2.765 7.413 6.434s-2.765 6.434-7.413 6.434H12.33L24 24h-8.245l-8.88-8.44c-.636-.588-.93-1.273-.93-1.86 0-.831.587-1.565 1.713-1.883l4.574-1.224c1.737-.465 2.936-1.81 2.936-3.572 0-2.153-1.761-3.4-3.939-3.4H0V0z", source: "https://resend.com/brand", hex: "000000", guidelines: "https://resend.com/brand" };
17
+
18
+ // src/logos.ts
19
+ var RESEND = { paths: [{ d: siResend.path }] };
20
+ var BREVO = { paths: [{ d: siBrevo.path }], color: `#${siBrevo.hex}` };
21
+
22
+ // src/shared.ts
23
+ var list = (value) => value === void 0 ? [] : [value].flat();
24
+ function parseAddress(value) {
25
+ const match = /^\s*(.*?)\s*<([^<>]+)>\s*$/.exec(value);
26
+ if (!match) return { email: value.trim() };
27
+ const name = (match[1] ?? "").replace(/^"|"$/g, "").trim();
28
+ return { email: (match[2] ?? "").trim(), ...name ? { name } : {} };
29
+ }
30
+ async function json(response) {
31
+ try {
32
+ const body = await response.json();
33
+ return body && typeof body === "object" ? body : {};
34
+ } catch {
35
+ return {};
36
+ }
37
+ }
38
+ function failure(provider, response, body) {
39
+ const text = body.message ?? body.Message ?? body.error ?? body.code;
40
+ return new Error(`${provider}: ${typeof text === "string" ? text : `HTTP ${response.status}`}`);
41
+ }
42
+ function parseBody(body) {
43
+ try {
44
+ return JSON.parse(body);
45
+ } catch {
46
+ throw new Error("the body is not JSON");
47
+ }
48
+ }
49
+
50
+ // src/brevo.ts
51
+ var api = () => process.env.BREVO_API_URL ?? "https://api.brevo.com/v3";
52
+ var EVENTS = {
53
+ delivered: { type: "delivered" },
54
+ hard_bounce: { type: "bounced", permanent: true },
55
+ invalid_email: { type: "bounced", permanent: true },
56
+ soft_bounce: { type: "bounced", permanent: false },
57
+ spam: { type: "complained" },
58
+ complaint: { type: "complained" }
59
+ };
60
+ var brevo = defineEmailProvider({
61
+ id: "brevo",
62
+ label: "Brevo",
63
+ description: {
64
+ en: "Email with a generous free plan (300 a day)",
65
+ th: "\u0E1A\u0E23\u0E34\u0E01\u0E32\u0E23\u0E2A\u0E48\u0E07\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E17\u0E35\u0E48\u0E21\u0E35\u0E41\u0E1E\u0E47\u0E01\u0E40\u0E01\u0E08\u0E1F\u0E23\u0E35\u0E27\u0E31\u0E19\u0E25\u0E30 300 \u0E09\u0E1A\u0E31\u0E1A"
66
+ },
67
+ icon: BREVO,
68
+ docs: "https://easycms.dev/docs/email#brevo",
69
+ plugin: "@easy-cms/plugin-email",
70
+ fields: [
71
+ {
72
+ name: "apiKey",
73
+ label: "API key",
74
+ description: {
75
+ en: "Brevo \u2192 SMTP & API \u2192 API Keys (xkeysib-\u2026)",
76
+ th: "Brevo \u2192 SMTP & API \u2192 API Keys (xkeysib-\u2026)"
77
+ },
78
+ placeholder: "xkeysib-\u2026",
79
+ required: true,
80
+ secret: true
81
+ }
82
+ ],
83
+ create: (values) => ({
84
+ name: "brevo",
85
+ apiVersion: 1,
86
+ from: values.from,
87
+ async send(message) {
88
+ const people = (value) => list(value).map(parseAddress);
89
+ const response = await fetch(`${api()}/smtp/email`, {
90
+ method: "POST",
91
+ headers: {
92
+ accept: "application/json",
93
+ "content-type": "application/json",
94
+ "api-key": values.apiKey ?? ""
95
+ },
96
+ body: JSON.stringify({
97
+ sender: parseAddress(message.from),
98
+ to: people(message.to),
99
+ ...message.cc ? { cc: people(message.cc) } : {},
100
+ ...message.bcc ? { bcc: people(message.bcc) } : {},
101
+ ...message.replyTo ? { replyTo: parseAddress(message.replyTo) } : {},
102
+ subject: message.subject,
103
+ ...message.html ? { htmlContent: message.html } : {},
104
+ ...message.text ? { textContent: message.text } : {}
105
+ })
106
+ });
107
+ const body = await json(response);
108
+ if (!response.ok) throw failure("Brevo", response, body);
109
+ return typeof body.messageId === "string" ? { id: body.messageId } : void 0;
110
+ }
111
+ }),
112
+ async test(values) {
113
+ const response = await fetch(`${api()}/account`, {
114
+ headers: { accept: "application/json", "api-key": values.apiKey ?? "" }
115
+ });
116
+ const body = await json(response);
117
+ if (!response.ok) return { ok: false, message: failure("Brevo", response, body).message };
118
+ const account = body.companyName ?? body.email;
119
+ return { ok: true, ...typeof account === "string" ? { account } : {} };
120
+ },
121
+ events(request) {
122
+ const event = parseBody(request.body);
123
+ const meaning = EVENTS[event.event ?? ""];
124
+ const id = event["message-id"];
125
+ if (!meaning || !id || !event.email) return [];
126
+ return [
127
+ {
128
+ id,
129
+ type: meaning.type,
130
+ address: event.email,
131
+ ...meaning.permanent !== void 0 ? { permanent: meaning.permanent } : {},
132
+ ...event.reason ? { detail: event.reason } : {},
133
+ ...event.date ? { at: event.date } : {}
134
+ }
135
+ ];
136
+ },
137
+ webhookSetup: {
138
+ en: "In Brevo \u2192 Transactional \u2192 Settings \u2192 Webhook, add this URL with Delivered, Hard bounce, Soft bounce and Complaint.",
139
+ th: "\u0E43\u0E19 Brevo \u2192 Transactional \u2192 Settings \u2192 Webhook \u0E40\u0E1E\u0E34\u0E48\u0E21 URL \u0E19\u0E35\u0E49 \u0E41\u0E25\u0E49\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01 Delivered, Hard bounce, Soft bounce \u0E41\u0E25\u0E30 Complaint"
140
+ }
141
+ });
142
+
143
+ // src/plugin.ts
144
+ import { definePlugin } from "@easy-cms/core";
145
+
146
+ // src/info.ts
147
+ var INFO = {
148
+ name: "@easy-cms/plugin-email",
149
+ // The plugin API it is written for (`PLUGIN_API_VERSION` of @easy-cms/core).
150
+ apiVersion: 1,
151
+ ...true ? { version: "1.42.0" } : {}
152
+ };
153
+
154
+ // src/postmark.ts
155
+ import { defineEmailProvider as defineEmailProvider2 } from "@easy-cms/core";
156
+ var api2 = () => process.env.POSTMARK_API_URL ?? "https://api.postmarkapp.com";
157
+ var postmark = defineEmailProvider2({
158
+ id: "postmark",
159
+ label: "Postmark",
160
+ description: {
161
+ en: "Transactional email known for reaching the inbox",
162
+ th: "\u0E1A\u0E23\u0E34\u0E01\u0E32\u0E23\u0E2A\u0E48\u0E07\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E23\u0E30\u0E1A\u0E1A\u0E17\u0E35\u0E48\u0E02\u0E36\u0E49\u0E19\u0E0A\u0E37\u0E48\u0E2D\u0E40\u0E23\u0E37\u0E48\u0E2D\u0E07\u0E2A\u0E48\u0E07\u0E16\u0E36\u0E07\u0E01\u0E25\u0E48\u0E2D\u0E07\u0E08\u0E14\u0E2B\u0E21\u0E32\u0E22"
163
+ },
164
+ icon: "mail",
165
+ docs: "https://easycms.dev/docs/email#postmark",
166
+ plugin: "@easy-cms/plugin-email",
167
+ fields: [
168
+ {
169
+ name: "serverToken",
170
+ label: "Server API token",
171
+ description: {
172
+ en: "Postmark \u2192 your server \u2192 API Tokens",
173
+ th: "Postmark \u2192 \u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13 \u2192 API Tokens"
174
+ },
175
+ required: true,
176
+ secret: true
177
+ },
178
+ {
179
+ name: "messageStream",
180
+ label: "Message stream",
181
+ description: { en: "Default: outbound", th: "\u0E04\u0E48\u0E32\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19: outbound" },
182
+ placeholder: "outbound"
183
+ }
184
+ ],
185
+ create: (values) => ({
186
+ name: "postmark",
187
+ apiVersion: 1,
188
+ from: values.from,
189
+ async send(message) {
190
+ const response = await fetch(`${api2()}/email`, {
191
+ method: "POST",
192
+ headers: {
193
+ accept: "application/json",
194
+ "content-type": "application/json",
195
+ "x-postmark-server-token": values.serverToken ?? ""
196
+ },
197
+ body: JSON.stringify({
198
+ From: message.from,
199
+ To: list(message.to).join(", "),
200
+ ...message.cc ? { Cc: list(message.cc).join(", ") } : {},
201
+ ...message.bcc ? { Bcc: list(message.bcc).join(", ") } : {},
202
+ ...message.replyTo ? { ReplyTo: message.replyTo } : {},
203
+ Subject: message.subject,
204
+ ...message.html ? { HtmlBody: message.html } : {},
205
+ ...message.text ? { TextBody: message.text } : {},
206
+ MessageStream: values.messageStream || "outbound"
207
+ })
208
+ });
209
+ const body = await json(response);
210
+ if (!response.ok || typeof body.ErrorCode === "number" && body.ErrorCode !== 0)
211
+ throw failure("Postmark", response, body);
212
+ return typeof body.MessageID === "string" ? { id: body.MessageID } : void 0;
213
+ }
214
+ }),
215
+ async test(values) {
216
+ const response = await fetch(`${api2()}/server`, {
217
+ headers: { accept: "application/json", "x-postmark-server-token": values.serverToken ?? "" }
218
+ });
219
+ const body = await json(response);
220
+ if (!response.ok) return { ok: false, message: failure("Postmark", response, body).message };
221
+ return { ok: true, ...typeof body.Name === "string" ? { account: body.Name } : {} };
222
+ },
223
+ events(request) {
224
+ const record = parseBody(request.body);
225
+ const id = record.MessageID;
226
+ if (!id) return [];
227
+ const out = (type, address, extra) => address ? [{ id, type, address, ...extra }] : [];
228
+ switch (record.RecordType) {
229
+ case "Delivery":
230
+ return out(
231
+ "delivered",
232
+ record.Recipient,
233
+ record.DeliveredAt ? { at: record.DeliveredAt } : {}
234
+ );
235
+ case "Bounce":
236
+ return out("bounced", record.Email, {
237
+ permanent: record.Inactive === true || record.Type === "HardBounce",
238
+ ...record.Description ? { detail: record.Description } : {},
239
+ ...record.BouncedAt ? { at: record.BouncedAt } : {}
240
+ });
241
+ case "SpamComplaint":
242
+ return out("complained", record.Email, record.BouncedAt ? { at: record.BouncedAt } : {});
243
+ default:
244
+ return [];
245
+ }
246
+ },
247
+ webhookSetup: {
248
+ en: "In Postmark \u2192 your server \u2192 Webhooks, add this URL with Delivery, Bounce and Spam Complaint.",
249
+ th: "\u0E43\u0E19 Postmark \u2192 \u0E40\u0E0B\u0E34\u0E23\u0E4C\u0E1F\u0E40\u0E27\u0E2D\u0E23\u0E4C\u0E02\u0E2D\u0E07\u0E04\u0E38\u0E13 \u2192 Webhooks \u0E40\u0E1E\u0E34\u0E48\u0E21 URL \u0E19\u0E35\u0E49 \u0E41\u0E25\u0E49\u0E27\u0E40\u0E25\u0E37\u0E2D\u0E01 Delivery, Bounce \u0E41\u0E25\u0E30 Spam Complaint"
250
+ }
251
+ });
252
+
253
+ // src/resend.ts
254
+ import { createHmac, timingSafeEqual } from "crypto";
255
+ import { defineEmailProvider as defineEmailProvider3 } from "@easy-cms/core";
256
+ var api3 = () => process.env.RESEND_API_URL ?? "https://api.resend.com";
257
+ var TOLERANCE_S = 5 * 60;
258
+ function verifySvix(request, secret, now = Date.now()) {
259
+ const id = request.headers.get("svix-id");
260
+ const timestamp = request.headers.get("svix-timestamp");
261
+ const signatures = request.headers.get("svix-signature");
262
+ if (!id || !timestamp || !signatures) throw new Error("the request is not signed");
263
+ const seconds = Number(timestamp);
264
+ if (!Number.isFinite(seconds) || Math.abs(now / 1e3 - seconds) > TOLERANCE_S)
265
+ throw new Error("the signature is too old");
266
+ const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
267
+ const expected = createHmac("sha256", key).update(`${id}.${timestamp}.${request.body}`).digest();
268
+ for (const part of signatures.split(" ")) {
269
+ const [version, value] = part.split(",");
270
+ if (version !== "v1" || !value) continue;
271
+ const given = Buffer.from(value, "base64");
272
+ if (given.length === expected.length && timingSafeEqual(given, expected)) return;
273
+ }
274
+ throw new Error("the signature does not match");
275
+ }
276
+ var TYPES = {
277
+ "email.delivered": "delivered",
278
+ "email.bounced": "bounced",
279
+ "email.complained": "complained"
280
+ };
281
+ var resend = defineEmailProvider3({
282
+ id: "resend",
283
+ label: "Resend",
284
+ description: {
285
+ en: "Email API for developers, with a free plan",
286
+ th: "\u0E1A\u0E23\u0E34\u0E01\u0E32\u0E23\u0E2A\u0E48\u0E07\u0E2D\u0E35\u0E40\u0E21\u0E25\u0E1C\u0E48\u0E32\u0E19 API \u0E2A\u0E33\u0E2B\u0E23\u0E31\u0E1A\u0E19\u0E31\u0E01\u0E1E\u0E31\u0E12\u0E19\u0E32 \u0E21\u0E35\u0E41\u0E1E\u0E47\u0E01\u0E40\u0E01\u0E08\u0E1F\u0E23\u0E35"
287
+ },
288
+ icon: RESEND,
289
+ docs: "https://easycms.dev/docs/email#resend",
290
+ plugin: "@easy-cms/plugin-email",
291
+ fields: [
292
+ {
293
+ name: "apiKey",
294
+ label: "API key",
295
+ description: { en: "Resend \u2192 API Keys (re_\u2026)", th: "Resend \u2192 API Keys (re_\u2026)" },
296
+ placeholder: "re_\u2026",
297
+ required: true,
298
+ secret: true
299
+ },
300
+ {
301
+ name: "webhookSecret",
302
+ label: { en: "Webhook signing secret", th: "Signing secret \u0E02\u0E2D\u0E07 webhook" },
303
+ description: {
304
+ en: "Optional: from Resend \u2192 Webhooks (whsec_\u2026), to check its requests are Resend\u2019s",
305
+ th: "\u0E44\u0E21\u0E48\u0E1A\u0E31\u0E07\u0E04\u0E31\u0E1A: \u0E08\u0E32\u0E01 Resend \u2192 Webhooks (whsec_\u2026) \u0E43\u0E0A\u0E49\u0E15\u0E23\u0E27\u0E08\u0E27\u0E48\u0E32\u0E04\u0E33\u0E02\u0E2D\u0E21\u0E32\u0E08\u0E32\u0E01 Resend \u0E08\u0E23\u0E34\u0E07"
306
+ },
307
+ placeholder: "whsec_\u2026",
308
+ secret: true
309
+ }
310
+ ],
311
+ create: (values) => ({
312
+ name: "resend",
313
+ apiVersion: 1,
314
+ from: values.from,
315
+ async send(message) {
316
+ const response = await fetch(`${api3()}/emails`, {
317
+ method: "POST",
318
+ headers: {
319
+ authorization: `Bearer ${values.apiKey}`,
320
+ "content-type": "application/json"
321
+ },
322
+ body: JSON.stringify({
323
+ from: message.from,
324
+ to: list(message.to),
325
+ ...message.cc ? { cc: list(message.cc) } : {},
326
+ ...message.bcc ? { bcc: list(message.bcc) } : {},
327
+ ...message.replyTo ? { reply_to: message.replyTo } : {},
328
+ subject: message.subject,
329
+ ...message.html ? { html: message.html } : {},
330
+ ...message.text ? { text: message.text } : {}
331
+ })
332
+ });
333
+ const body = await json(response);
334
+ if (!response.ok) throw failure("Resend", response, body);
335
+ return typeof body.id === "string" ? { id: body.id } : void 0;
336
+ }
337
+ }),
338
+ async test(values) {
339
+ const response = await fetch(`${api3()}/domains`, {
340
+ headers: { authorization: `Bearer ${values.apiKey}` }
341
+ });
342
+ const body = await json(response);
343
+ if (body.name === "restricted_api_key") return { ok: true };
344
+ if (!response.ok) return { ok: false, message: failure("Resend", response, body).message };
345
+ const names = Array.isArray(body.data) ? body.data.map((d) => d.name).filter((n) => typeof n === "string") : [];
346
+ return { ok: true, ...names.length ? { account: names.join(", ") } : {} };
347
+ },
348
+ events(request, values) {
349
+ if (values.webhookSecret) verifySvix(request, values.webhookSecret);
350
+ const event = parseBody(request.body);
351
+ const type = TYPES[event.type ?? ""];
352
+ const id = event.data?.email_id;
353
+ if (!type || !id) return [];
354
+ return (event.data?.to ?? []).map((address) => ({
355
+ id,
356
+ type,
357
+ address,
358
+ ...event.created_at ? { at: event.created_at } : {},
359
+ ...type === "bounced" ? {
360
+ permanent: event.data?.bounce?.type !== "Transient",
361
+ ...event.data?.bounce?.message ? { detail: event.data.bounce.message } : {}
362
+ } : {}
363
+ }));
364
+ },
365
+ webhookSetup: {
366
+ en: "In Resend \u2192 Webhooks, add this URL with the events email.delivered, email.bounced and email.complained, then paste its signing secret above.",
367
+ th: "\u0E43\u0E19 Resend \u2192 Webhooks \u0E40\u0E1E\u0E34\u0E48\u0E21 URL \u0E19\u0E35\u0E49 \u0E40\u0E25\u0E37\u0E2D\u0E01 event email.delivered, email.bounced \u0E41\u0E25\u0E30 email.complained \u0E41\u0E25\u0E49\u0E27\u0E19\u0E33 signing secret \u0E21\u0E32\u0E27\u0E32\u0E07\u0E43\u0E19\u0E0A\u0E48\u0E2D\u0E07\u0E14\u0E49\u0E32\u0E19\u0E1A\u0E19"
368
+ }
369
+ });
370
+
371
+ // src/plugin.ts
372
+ var emailProviders = [resend, postmark, brevo];
373
+ function emailPlugin(options = {}) {
374
+ const providers = options.providers ?? emailProviders;
375
+ for (const provider of providers)
376
+ if (!provider.email)
377
+ throw new Error(`emailPlugin: "${provider.id}" doesn't send email (use defineEmailProvider)`);
378
+ return definePlugin(
379
+ (config) => ({
380
+ ...config,
381
+ integrations: [...config.integrations ?? [], ...providers]
382
+ }),
383
+ INFO
384
+ );
385
+ }
386
+ export {
387
+ brevo,
388
+ defineEmailProvider4 as defineEmailProvider,
389
+ emailPlugin,
390
+ emailProviders,
391
+ postmark,
392
+ resend,
393
+ verifySvix
394
+ };
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@easy-cms/plugin-email",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.42.0",
4
+ "description": "Email providers for Easy CMS: Resend, Postmark and Brevo (or SMTP), connected and chosen in the admin, with delivery events and a suppression list",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "peerDependencies": {
19
+ "@easy-cms/core": "^1.42.0"
20
+ },
21
+ "devDependencies": {
22
+ "simple-icons": "16.36.0",
23
+ "@easy-cms/core": "^1.42.0",
24
+ "@easy-cms/db-sqlite": "^1.42.0"
25
+ },
26
+ "engines": {
27
+ "node": ">=22.12"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/maritonx/easy-cms.git",
35
+ "directory": "packages/plugin-email"
36
+ },
37
+ "keywords": [
38
+ "easy-cms",
39
+ "easy-cms-plugin",
40
+ "email",
41
+ "resend",
42
+ "postmark",
43
+ "brevo"
44
+ ],
45
+ "scripts": {
46
+ "build": "tsup",
47
+ "typecheck": "tsc --noEmit",
48
+ "test": "vitest run"
49
+ }
6
50
  }