@email-kit/runtime 1.0.0 → 1.0.1
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 +107 -36
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,54 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# email-kit
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
email-
|
|
5
|
-
`
|
|
3
|
+
Type-safe email templates for TypeScript backends. Write the emails your app sends in TSX with
|
|
4
|
+
themed, email-safe components. `email-kit compile` turns them into a small typed module your server
|
|
5
|
+
imports, and `email-kit check` checks every one for email clients, dark mode, accessibility and
|
|
6
|
+
copy.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
**[Documentation](https://email-kit.dev)** · [Getting started](https://email-kit.dev/guide/getting-started/) · [GitHub](https://github.com/email-kit/email-kit)
|
|
9
|
+
|
|
10
|
+
## Get started
|
|
11
|
+
|
|
12
|
+
In the project that sends email (in a monorepo, the app's folder), run:
|
|
9
13
|
|
|
10
14
|
```sh
|
|
11
|
-
npm
|
|
15
|
+
npm create email-kit
|
|
12
16
|
```
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
It detects your package manager, TypeScript setup and framework, installs the packages below, adds
|
|
19
|
+
a config and a welcome template, and compiles once. It asks before changing any file you already
|
|
20
|
+
have; `npm create email-kit -- --yes` accepts every default, as in CI. `npx @email-kit/cli init`
|
|
21
|
+
does the same.
|
|
22
|
+
|
|
23
|
+
Then render the welcome email from your server, with the import `init` prints for your project:
|
|
16
24
|
|
|
17
25
|
```ts
|
|
18
|
-
import { emails } from "
|
|
26
|
+
import { emails } from "./email-kit"
|
|
19
27
|
|
|
20
|
-
const { subject, html, text } = emails.welcome.render({
|
|
28
|
+
const { subject, html, text } = emails.welcome.render({
|
|
29
|
+
name: "Ada",
|
|
30
|
+
plan: "pro",
|
|
31
|
+
startUrl: "https://example.com/start",
|
|
32
|
+
})
|
|
21
33
|
```
|
|
22
34
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
The compiler parses every template and writes it into the generated module in a compact form, so
|
|
26
|
-
nothing is parsed when an email is sent. What's left to do at send time is here, and the optional
|
|
27
|
-
parts have their own entry points, which the generated module imports only when your templates
|
|
28
|
-
use them:
|
|
29
|
-
|
|
30
|
-
| Entry point | Imported when | Min + gzip |
|
|
31
|
-
|---|---|---|
|
|
32
|
-
| `@email-kit/runtime` | always: filling the templates, keeping only the schema's fields | about 1.4 KB |
|
|
33
|
-
| `@email-kit/runtime/validate` | `validate` is on (the default) | about 1.1 KB |
|
|
34
|
-
| `@email-kit/runtime/plural` | a message has `{n, plural, …}` or `{x, select, …}` | about 0.5 KB |
|
|
35
|
-
| `@email-kit/runtime/locale` | the project compiles more than one locale | about 0.5 KB |
|
|
36
|
-
| `@email-kit/runtime/context` | the config has sender values passed at send time | about 0.5 KB |
|
|
35
|
+
email-kit doesn't send email: hand `subject`, `html` and `text` to any provider's API.
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
While you work:
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
```sh
|
|
40
|
+
npx email-kit compile # after changing a template or message; --watch keeps it running
|
|
41
|
+
npx email-kit check # the checks; exits 1 on errors, for CI
|
|
42
|
+
npx email-kit new <id> # another template, with messages in every locale
|
|
43
|
+
```
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
The [getting started guide](https://email-kit.dev/guide/getting-started/) goes through it step by
|
|
46
|
+
step, and [your first email](https://email-kit.dev/guide/first-email/) builds one from scratch.
|
|
47
|
+
|
|
48
|
+
## A template
|
|
49
|
+
|
|
50
|
+
Each template is a folder with `template.tsx` and a `messages.<locale>.json` per language:
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { Button, Heading, Text } from "@email-kit/components"
|
|
54
|
+
import { defineEmail, url } from "@email-kit/core"
|
|
55
|
+
import { z } from "zod"
|
|
56
|
+
|
|
57
|
+
export default defineEmail({
|
|
58
|
+
id: "welcome",
|
|
59
|
+
purpose: "transactional",
|
|
60
|
+
schema: z.object({ name: z.string().min(1), startUrl: z.string().meta(url) }),
|
|
61
|
+
subject: (data, t) => t("subject", { name: data.name }),
|
|
62
|
+
fixtures: { default: { name: "Ada", startUrl: "https://example.com/start" } },
|
|
63
|
+
component: ({ data, t }) => (
|
|
64
|
+
<>
|
|
65
|
+
<Heading>{t("heading", { name: data.name })}</Heading>
|
|
66
|
+
<Text>{t("body")}</Text>
|
|
67
|
+
<Button href={data.startUrl}>{t("cta")}</Button>
|
|
68
|
+
</>
|
|
69
|
+
),
|
|
70
|
+
})
|
|
71
|
+
```
|
|
44
72
|
|
|
45
|
-
|
|
46
|
-
|
|
73
|
+
Templates run when you compile, not when you send: your server imports the generated module, which
|
|
74
|
+
needs only `@email-kit/runtime`.
|
|
47
75
|
|
|
48
|
-
##
|
|
76
|
+
## The packages
|
|
49
77
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
rendering it wrong. `email-kit check` fails when the runtime is missing or a devDependency.
|
|
78
|
+
They work together and are released together: install the same version of each.
|
|
79
|
+
`npm create email-kit` installs them for you.
|
|
53
80
|
|
|
54
|
-
|
|
81
|
+
| Package | What it is | Install as |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| [`create-email-kit`](https://www.npmjs.com/package/create-email-kit) | `npm create email-kit`: runs `email-kit init` in the folder you're in | not installed |
|
|
84
|
+
| [`@email-kit/cli`](https://www.npmjs.com/package/@email-kit/cli) | The `email-kit` command: `init`, `new`, `compile`, `check` and `tokens` | devDependency |
|
|
85
|
+
| [`@email-kit/core`](https://www.npmjs.com/package/@email-kit/core) | What templates are written with: `defineEmail`, the JSX runtime, `If`/`Each`/`Unless`, field markers (`url`, `secret`, `formatted`), `defineConfig` and `defineCheck` | devDependency |
|
|
86
|
+
| [`@email-kit/components`](https://www.npmjs.com/package/@email-kit/components) | Email-safe components themed from your shadcn CSS or design tokens: `Text`, `Heading`, `Link`, `Button`, `Image`, `Divider`, `Spacer`, `Section`, `List`, `KeyValue`, `Callout`, `OtpCode`, `DataTable`, `LineItems` and `Footer` | devDependency |
|
|
87
|
+
| [`@email-kit/runtime`](https://www.npmjs.com/package/@email-kit/runtime) | Renders the compiled emails. The only one your app needs when it runs | **dependency** |
|
|
88
|
+
|
|
89
|
+
### The runtime
|
|
90
|
+
|
|
91
|
+
`@email-kit/runtime` has no dependencies and uses only web-standard APIs, so it runs in Node 22+,
|
|
92
|
+
Bun, Deno, Cloudflare Workers, AWS Lambda and Next.js server code. You don't import it yourself:
|
|
93
|
+
the generated module does, and only the entry points your templates use, from about 1.4 KB to 3 KB
|
|
94
|
+
min+gzip:
|
|
95
|
+
|
|
96
|
+
| Entry point | Imported when |
|
|
97
|
+
|---|---|
|
|
98
|
+
| `@email-kit/runtime` | always |
|
|
99
|
+
| `@email-kit/runtime/validate` | `validate` is on (the default) |
|
|
100
|
+
| `@email-kit/runtime/plural` | a message has a plural or a select |
|
|
101
|
+
| `@email-kit/runtime/locale` | the project compiles more than one locale |
|
|
102
|
+
| `@email-kit/runtime/context` | the config has sender values passed at send time |
|
|
103
|
+
|
|
104
|
+
Rendering problems throw an `EmailRenderError` with a `code`; see the
|
|
105
|
+
[error reference](https://email-kit.dev/reference/errors/). A module compiled by another version of
|
|
106
|
+
the CLI fails with `incompatible-module` rather than rendering wrong.
|
|
107
|
+
|
|
108
|
+
## Status
|
|
109
|
+
|
|
110
|
+
**1.0.** Stable for transactional email; breaking changes come only in a major release. Not yet:
|
|
111
|
+
marketing email (unsubscribe links, multi-column layouts), testing in real email clients (classic
|
|
112
|
+
Outlook especially), and the preview studio.
|
|
113
|
+
|
|
114
|
+
## More
|
|
115
|
+
|
|
116
|
+
- [Guide](https://email-kit.dev/guide/): templates, components, messages and locales, theme and dark
|
|
117
|
+
mode, checks and CI, rendering and sending.
|
|
118
|
+
- Reference: [CLI](https://email-kit.dev/reference/cli/),
|
|
119
|
+
[configuration](https://email-kit.dev/reference/configuration/),
|
|
120
|
+
[checks](https://email-kit.dev/reference/checks/), [errors](https://email-kit.dev/reference/errors/).
|
|
121
|
+
- [Issues](https://github.com/email-kit/email-kit/issues) and
|
|
122
|
+
[changelog](https://github.com/email-kit/email-kit/blob/main/packages/cli/CHANGELOG.md).
|
|
123
|
+
|
|
124
|
+
The CLI requires Node.js 22.12 or later. MIT licensed; the CLI's third-party notices are in its
|
|
125
|
+
`THIRD_PARTY_NOTICES.md`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@email-kit/runtime",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "email-kit runtime: renders the emails `email-kit compile` generates. The only email-kit package an app needs at runtime; zero dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"email",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"mustache",
|
|
10
10
|
"runtime"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://email-kit.dev",
|
|
13
13
|
"bugs": "https://github.com/email-kit/email-kit/issues",
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|