@numoteq/emdash-plugin-jetemail 0.0.0-stage → 0.2.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 NUMOTEQ s.r.o.
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,56 @@
1
- # Temporary Holding Version
1
+ # `@numoteq/emdash-plugin-jetemail`
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
+ Sandbox-compatible [JetEmail](https://jetemail.com) transport provider for EmDash.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ pnpm add @numoteq/emdash-plugin-jetemail
9
+ ```
10
+
11
+ Register the package in the site's sandboxed plugin configuration, activate it, then select **JetEmail** under **Settings > Email**. Open the plugin settings and enter:
12
+
13
+ - A JetEmail transactional API key (`transactional_…`) allowed to send from the sender's domain.
14
+ - The sender name and email. The sender domain must be verified in JetEmail.
15
+
16
+ If the domain publishes JetEmail Domain Security (`_jm` TXT), add the API key's UUID to it, otherwise JetEmail rejects the message.
17
+
18
+ The key is stored in the plugin-scoped KV store and is sent only to `https://api.jetemail.com/email`. The plugin requests only the fixed-host network and email transport registration capabilities. Recipients, CC and reply-to are passed through; EmDash email has no attachments.
19
+
20
+ ## Native use (Cloudflare Workers sites)
21
+
22
+ Sites that configure EmDash in code can register the transport in `astro.config.mjs` instead; the API key then lives in a Worker secret and nothing is set in the admin:
23
+
24
+ ```js
25
+ import { jetEmail } from "@numoteq/emdash-plugin-jetemail/native";
26
+
27
+ emdash({
28
+ plugins: [jetEmail({ from: { email: "noreply@example.com", name: "Example" } })],
29
+ });
30
+ ```
31
+
32
+ ```sh
33
+ wrangler secret put JETEMAIL_API_KEY
34
+ ```
35
+
36
+ Activate it under **Admin > Extensions** and select it under **Settings > Email**. Site code (contact forms) can send through the same client:
37
+
38
+ ```ts
39
+ import { deliverWithJetEmail } from "@numoteq/emdash-plugin-jetemail/client";
40
+
41
+ await deliverWithJetEmail(
42
+ fetch,
43
+ { apiToken, fromName: "Example", fromEmail: "noreply@example.com" },
44
+ message,
45
+ );
46
+ ```
47
+
48
+ ## Development
49
+
50
+ ```sh
51
+ pnpm test
52
+ pnpm typecheck
53
+ pnpm build
54
+ ```
55
+
56
+ `emdash-plugin build` creates the npm descriptor and sandbox bundle in `dist/`.
@@ -0,0 +1,21 @@
1
+ //#region src/client.d.ts
2
+ interface JetEmailSender {
3
+ apiToken: string;
4
+ fromName: string;
5
+ fromEmail: string;
6
+ }
7
+ interface JetEmailMessage {
8
+ to: string | string[];
9
+ cc?: string[];
10
+ replyTo?: string;
11
+ subject: string;
12
+ text?: string;
13
+ html?: string;
14
+ }
15
+ type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
16
+ declare function formatSender(name: string, email: string): string;
17
+ declare function deliverWithJetEmail(fetchFn: FetchFn, sender: JetEmailSender, message: JetEmailMessage): Promise<{
18
+ id?: string;
19
+ }>;
20
+ //#endregion
21
+ export { FetchFn, JetEmailMessage, JetEmailSender, deliverWithJetEmail, formatSender };
@@ -0,0 +1,33 @@
1
+ //#region src/client.ts
2
+ const API_URL = "https://api.jetemail.com/email";
3
+ function formatSender(name, email) {
4
+ return `${name.replace(/[<>"\r\n]/g, "").trim()} <${email}>`;
5
+ }
6
+ async function deliverWithJetEmail(fetchFn, sender, message) {
7
+ const body = {
8
+ from: formatSender(sender.fromName, sender.fromEmail),
9
+ to: message.to,
10
+ subject: message.subject
11
+ };
12
+ if (message.text) body.text = message.text;
13
+ if (message.html) body.html = message.html;
14
+ if (message.cc?.length) body.cc = message.cc;
15
+ if (message.replyTo) body.reply_to = message.replyTo;
16
+ const response = await fetchFn(API_URL, {
17
+ method: "POST",
18
+ headers: {
19
+ Authorization: `Bearer ${sender.apiToken}`,
20
+ "Content-Type": "application/json"
21
+ },
22
+ body: JSON.stringify(body)
23
+ });
24
+ if (!response.ok) {
25
+ const detail = (await response.text()).slice(0, 500);
26
+ throw new Error(`JetEmail rejected the message with HTTP ${response.status}${detail ? `: ${detail}` : ""}`);
27
+ }
28
+ const result = await response.json().catch(() => ({}));
29
+ return typeof result.id === "string" ? { id: result.id } : {};
30
+ }
31
+
32
+ //#endregion
33
+ export { deliverWithJetEmail, formatSender };
@@ -0,0 +1,9 @@
1
+ //#region src/native/config.ts
2
+ const PLUGIN_ID = "jetemail";
3
+ const PLUGIN_VERSION = "1.0.0";
4
+ function assertValidConfig(config) {
5
+ if (!config.from?.email?.includes("@") || !config.from.name?.trim()) throw new Error("[jetemail] config.from needs an email and a name, e.g. { from: { email: \"noreply@example.com\", name: \"Example\" } }");
6
+ }
7
+
8
+ //#endregion
9
+ export { PLUGIN_VERSION as n, assertValidConfig as r, PLUGIN_ID as t };
@@ -0,0 +1,14 @@
1
+ //#region src/native/config.d.ts
2
+ interface JetEmailConfig {
3
+ /** Sender. The domain must be verified in JetEmail and allowed for the API key. */
4
+ from: {
5
+ email: string;
6
+ name: string;
7
+ };
8
+ /** Reply-To used when the message sets none. */
9
+ replyTo?: string;
10
+ /** Name of the Worker secret that holds the transactional API key. @default "JETEMAIL_API_KEY" */
11
+ secret?: string;
12
+ }
13
+ //#endregion
14
+ export { JetEmailConfig as t };
@@ -0,0 +1,3 @@
1
+ import { env } from "cloudflare:workers";
2
+
3
+ export { env };
@@ -0,0 +1,5 @@
1
+ // Auto-generated by emdash-plugin build. Do not edit.
2
+ import type { PluginDescriptor } from "emdash";
3
+
4
+ declare const descriptor: PluginDescriptor;
5
+ export default descriptor;
package/dist/index.mjs ADDED
@@ -0,0 +1,40 @@
1
+ // Auto-generated by emdash-plugin build. Do not edit.
2
+ // Source: emdash-plugin.jsonc + package.json
3
+ //
4
+ // Default-exports a sandboxed plugin descriptor. Pass it directly into
5
+ // emdash's `plugins:` or `sandboxed:` array — no factory call needed.
6
+
7
+ /** @type {import("emdash").PluginDescriptor} */
8
+ const descriptor = Object.freeze({
9
+ "id": "jetemail",
10
+ "version": "0.2.0",
11
+ "format": "standard",
12
+ "entrypoint": "@numoteq/emdash-plugin-jetemail/sandbox",
13
+ "capabilities": [
14
+ "network:request",
15
+ "hooks.email-transport:register"
16
+ ],
17
+ "allowedHosts": [
18
+ "api.jetemail.com"
19
+ ],
20
+ "storage": {},
21
+ "hooks": [
22
+ {
23
+ "name": "email:deliver",
24
+ "exclusive": true,
25
+ "timeout": 30000
26
+ }
27
+ ],
28
+ "routes": [
29
+ "admin"
30
+ ],
31
+ "adminPages": [
32
+ {
33
+ "path": "/settings",
34
+ "label": "JetEmail",
35
+ "icon": "mail"
36
+ }
37
+ ]
38
+ });
39
+
40
+ export default descriptor;
@@ -0,0 +1,44 @@
1
+ {
2
+ "id": "jetemail",
3
+ "version": "0.2.0",
4
+ "declaredAccess": {
5
+ "network": {
6
+ "request": {
7
+ "allowedHosts": [
8
+ "api.jetemail.com"
9
+ ]
10
+ }
11
+ },
12
+ "email": {
13
+ "transport": {}
14
+ }
15
+ },
16
+ "capabilities": [
17
+ "network:request",
18
+ "hooks.email-transport:register"
19
+ ],
20
+ "allowedHosts": [
21
+ "api.jetemail.com"
22
+ ],
23
+ "storage": {},
24
+ "hooks": [
25
+ {
26
+ "name": "email:deliver",
27
+ "exclusive": true,
28
+ "timeout": 30000
29
+ }
30
+ ],
31
+ "routes": [
32
+ "admin"
33
+ ],
34
+ "admin": {
35
+ "pages": [
36
+ {
37
+ "path": "/settings",
38
+ "label": "JetEmail",
39
+ "icon": "mail"
40
+ }
41
+ ],
42
+ "widgets": []
43
+ }
44
+ }
@@ -0,0 +1,11 @@
1
+ import { t as JetEmailConfig } from "../config-DcMo9a49.mjs";
2
+ import { PluginDescriptor } from "emdash";
3
+
4
+ //#region src/native/index.d.ts
5
+ /**
6
+ * JetEmail transport for the emdash() integration's `plugins` array. The API key is read at
7
+ * delivery time from a Worker secret (default `JETEMAIL_API_KEY`), so nothing is configured in the admin.
8
+ */
9
+ declare function jetEmail(config: JetEmailConfig): PluginDescriptor<JetEmailConfig>;
10
+ //#endregion
11
+ export { type JetEmailConfig, jetEmail as default, jetEmail };
@@ -0,0 +1,21 @@
1
+ import { n as PLUGIN_VERSION, r as assertValidConfig, t as PLUGIN_ID } from "../config-Bdqx5Bs6.mjs";
2
+
3
+ //#region src/native/index.ts
4
+ /**
5
+ * JetEmail transport for the emdash() integration's `plugins` array. The API key is read at
6
+ * delivery time from a Worker secret (default `JETEMAIL_API_KEY`), so nothing is configured in the admin.
7
+ */
8
+ function jetEmail(config) {
9
+ assertValidConfig(config);
10
+ return {
11
+ id: PLUGIN_ID,
12
+ version: PLUGIN_VERSION,
13
+ entrypoint: "@numoteq/emdash-plugin-jetemail/native/plugin",
14
+ format: "native",
15
+ options: config,
16
+ capabilities: ["hooks.email-transport:register"]
17
+ };
18
+ }
19
+
20
+ //#endregion
21
+ export { jetEmail as default, jetEmail };
@@ -0,0 +1,12 @@
1
+ import { t as JetEmailConfig } from "../config-DcMo9a49.mjs";
2
+ import * as emdash from "emdash";
3
+ import { EmailDeliverEvent, PluginContext } from "emdash/plugin";
4
+
5
+ //#region src/native/plugin.d.ts
6
+ type LoadEnv = () => Promise<Record<string, unknown>>;
7
+ /** @internal Exported for tests. */
8
+ declare function createJetEmailDeliver(config: JetEmailConfig, loadEnv?: LoadEnv): (event: EmailDeliverEvent, ctx: PluginContext) => Promise<void>;
9
+ /** Called by EmDash with the options of the {@link jetEmail} descriptor. */
10
+ declare function createPlugin(config: JetEmailConfig): emdash.ResolvedPlugin<emdash.PluginStorageConfig>;
11
+ //#endregion
12
+ export { createJetEmailDeliver, createPlugin };
@@ -0,0 +1,51 @@
1
+ import { deliverWithJetEmail } from "../client.mjs";
2
+ import { n as PLUGIN_VERSION, r as assertValidConfig, t as PLUGIN_ID } from "../config-Bdqx5Bs6.mjs";
3
+ import { definePlugin } from "emdash";
4
+
5
+ //#region src/native/plugin.ts
6
+ async function loadWorkerEnv() {
7
+ try {
8
+ const { env } = await import("../env-DnAfk4Vp.mjs");
9
+ return env;
10
+ } catch {
11
+ throw new Error("[jetemail] cloudflare:workers is not available; this provider runs only on Cloudflare Workers.");
12
+ }
13
+ }
14
+ /** @internal Exported for tests. */
15
+ function createJetEmailDeliver(config, loadEnv = loadWorkerEnv) {
16
+ const secret = config.secret ?? "JETEMAIL_API_KEY";
17
+ return async (event, ctx) => {
18
+ const apiToken = (await loadEnv())[secret];
19
+ if (typeof apiToken !== "string" || !apiToken) throw new Error(`[jetemail] Worker secret "${secret}" is not set (wrangler secret put ${secret}).`);
20
+ const { message } = event;
21
+ const result = await deliverWithJetEmail(fetch, {
22
+ apiToken,
23
+ fromName: config.from.name,
24
+ fromEmail: config.from.email
25
+ }, {
26
+ ...message,
27
+ replyTo: message.replyTo ?? config.replyTo
28
+ });
29
+ ctx.log.info("Email delivered via JetEmail", {
30
+ to: message.to,
31
+ subject: message.subject,
32
+ id: result.id
33
+ });
34
+ };
35
+ }
36
+ /** Called by EmDash with the options of the {@link jetEmail} descriptor. */
37
+ function createPlugin(config) {
38
+ assertValidConfig(config);
39
+ return definePlugin({
40
+ id: PLUGIN_ID,
41
+ version: PLUGIN_VERSION,
42
+ capabilities: ["hooks.email-transport:register"],
43
+ hooks: { "email:deliver": {
44
+ exclusive: true,
45
+ handler: createJetEmailDeliver(config)
46
+ } }
47
+ });
48
+ }
49
+
50
+ //#endregion
51
+ export { createJetEmailDeliver, createPlugin };
@@ -0,0 +1,26 @@
1
+ import { SandboxedPlugin } from "emdash/plugin";
2
+
3
+ //#region src/client.d.ts
4
+ interface JetEmailSender {
5
+ apiToken: string;
6
+ fromName: string;
7
+ fromEmail: string;
8
+ }
9
+ interface JetEmailMessage {
10
+ to: string | string[];
11
+ cc?: string[];
12
+ replyTo?: string;
13
+ subject: string;
14
+ text?: string;
15
+ html?: string;
16
+ }
17
+ type FetchFn = (url: string, init?: RequestInit) => Promise<Response>;
18
+ declare function formatSender(name: string, email: string): string;
19
+ declare function deliverWithJetEmail(fetchFn: FetchFn, sender: JetEmailSender, message: JetEmailMessage): Promise<{
20
+ id?: string;
21
+ }>;
22
+ //#endregion
23
+ //#region src/plugin.d.ts
24
+ declare const plugin: SandboxedPlugin;
25
+ //#endregion
26
+ export { plugin as default, deliverWithJetEmail, formatSender };
@@ -0,0 +1 @@
1
+ function e(e,t){return`${e.replace(/[<>"\r\n]/g,``).trim()} <${t}>`}async function t(t,n,r){let i={from:e(n.fromName,n.fromEmail),to:r.to,subject:r.subject};r.text&&(i.text=r.text),r.html&&(i.html=r.html),r.cc?.length&&(i.cc=r.cc),r.replyTo&&(i.reply_to=r.replyTo);let a=await t(`https://api.jetemail.com/email`,{method:`POST`,headers:{Authorization:`Bearer ${n.apiToken}`,"Content-Type":`application/json`},body:JSON.stringify(i)});if(!a.ok){let e=(await a.text()).slice(0,500);throw Error(`JetEmail rejected the message with HTTP ${a.status}${e?`: ${e}`:``}`)}let o=await a.json().catch(()=>({}));return typeof o.id==`string`?{id:o.id}:{}}async function n(e){let t=await e.kv.get(`settings:apiToken`),n=await e.kv.get(`settings:fromName`),r=await e.kv.get(`settings:fromEmail`);if(!t||!n||!r)throw Error(`JetEmail is not configured. Set the API key, sender name and sender email.`);return{apiToken:t,fromName:n,fromEmail:r}}async function r(e){let t=await e.kv.get(`settings:fromName`)??``,n=await e.kv.get(`settings:fromEmail`)??``,r=!!await e.kv.get(`settings:apiToken`);return{blocks:[{type:`header`,text:`JetEmail`},{type:`section`,text:`Deliver EmDash transactional email through the JetEmail API. The sender domain must be verified in JetEmail and allowed for the API key.`},{type:`form`,block_id:`jetemail-settings`,fields:[{type:`text_input`,action_id:`fromName`,label:`Sender name`,initial_value:t},{type:`text_input`,action_id:`fromEmail`,label:`Sender email`,initial_value:n},{type:`secret_input`,action_id:`apiToken`,label:r?`Transactional API key (leave blank to keep current)`:`Transactional API key`}],submit:{label:`Save settings`,action_id:`save_settings`}}]}}function i(e){return{blocks:[{type:`banner`,style:`error`,text:e}],toast:{message:e,type:`error`}}}async function a(e,t){let n=typeof t.fromName==`string`?t.fromName.trim():``,a=typeof t.fromEmail==`string`?t.fromEmail.trim():``,o=typeof t.apiToken==`string`?t.apiToken.trim():``;return n.replace(/[<>"\r\n]/g,``).trim()?/^[^\s@<>]+@[^\s@<>]+$/.test(a)?o&&!o.startsWith(`transactional_`)?i(`Use a JetEmail transactional API key (transactional_…).`):(await e.kv.set(`settings:fromName`,n),await e.kv.set(`settings:fromEmail`,a),o&&await e.kv.set(`settings:apiToken`,o),{...await r(e),toast:{message:`JetEmail settings saved`,type:`success`}}):i(`Enter a valid sender email.`):i(`Enter a sender name.`)}const o={hooks:{"email:deliver":{exclusive:!0,timeout:3e4,handler:async(e,r)=>{if(!r.http)throw Error(`JetEmail requires network access.`);let i=await n(r);await t(r.http.fetch.bind(r.http),i,e.message),r.log.info(`Email delivered via JetEmail`,{to:e.message.to,subject:e.message.subject})}}},routes:{admin:{handler:async(e,t)=>{let n=e.input;return n.type===`page_load`&&n.page===`/settings`?r(t):n.type===`form_submit`&&n.action_id===`save_settings`?a(t,n.values??{}):{blocks:[]}}}}};export{o as default,t as deliverWithJetEmail,e as formatSender};
@@ -0,0 +1,22 @@
1
+ {
2
+ "$schema": "./node_modules/@emdash-cms/plugin-cli/schemas/emdash-plugin.schema.json",
3
+ "slug": "jetemail",
4
+ "publisher": "did:plc:nna4pfpnegfsgaym44xqhawf", // numoteq.com
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "NUMOTEQ s.r.o.",
8
+ "url": "https://www.numoteq.com",
9
+ "email": "info@numoteq.com",
10
+ },
11
+ "security": { "email": "info@numoteq.com" },
12
+ "name": "JetEmail",
13
+ "description": "Delivers EmDash transactional email through the JetEmail API.",
14
+ "keywords": ["email", "transactional", "jetemail"],
15
+ "repo": "https://github.com/numoteq/emdash-plugins",
16
+ "capabilities": ["network:request", "hooks.email-transport:register"],
17
+ "allowedHosts": ["api.jetemail.com"],
18
+ "storage": {},
19
+ "admin": {
20
+ "pages": [{ "path": "/settings", "label": "JetEmail", "icon": "mail" }],
21
+ },
22
+ }
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
- "name": "@numoteq/emdash-plugin-jetemail",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@numoteq/emdash-plugin-jetemail",
3
+ "version": "0.2.0",
4
+ "description": "JetEmail transport provider for EmDash",
5
+ "keywords": [
6
+ "email",
7
+ "emdash",
8
+ "emdash-plugin",
9
+ "jetemail"
10
+ ],
11
+ "homepage": "https://github.com/numoteq/emdash-plugins/tree/main/packages/jetemail#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/numoteq/emdash-plugins/issues"
14
+ },
15
+ "license": "MIT",
16
+ "author": {
17
+ "name": "NUMOTEQ s.r.o.",
18
+ "email": "info@numoteq.com",
19
+ "url": "https://www.numoteq.com"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/numoteq/emdash-plugins.git",
24
+ "directory": "packages/jetemail"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "emdash-plugin.jsonc",
29
+ "README.md",
30
+ "LICENSE"
31
+ ],
32
+ "type": "module",
33
+ "sideEffects": false,
34
+ "main": "dist/index.mjs",
35
+ "exports": {
36
+ ".": {
37
+ "import": "./dist/index.mjs",
38
+ "types": "./dist/index.d.mts"
39
+ },
40
+ "./sandbox": "./dist/plugin.mjs",
41
+ "./native": {
42
+ "import": "./dist/native/index.mjs",
43
+ "types": "./dist/native/index.d.mts"
44
+ },
45
+ "./native/plugin": {
46
+ "import": "./dist/native/plugin.mjs",
47
+ "types": "./dist/native/plugin.d.mts"
48
+ },
49
+ "./client": {
50
+ "import": "./dist/client.mjs",
51
+ "types": "./dist/client.d.mts"
52
+ }
53
+ },
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "scripts": {
58
+ "build": "emdash-plugin validate && emdash-plugin build && tsdown",
59
+ "dev": "emdash-plugin dev",
60
+ "test": "vitest run",
61
+ "typecheck": "tsc --noEmit"
62
+ },
63
+ "devDependencies": {
64
+ "@emdash-cms/plugin-cli": "0.13.2",
65
+ "emdash": "1.1.0",
66
+ "tsdown": "0.20.3",
67
+ "typescript": "6.0.3",
68
+ "vitest": "5.0.2"
69
+ },
70
+ "peerDependencies": {
71
+ "emdash": ">=1.0.0"
72
+ }
73
+ }